Skip to content

Commit 97bc9b6

Browse files
committed
chore: increase extra gas for hook to 200k and for proxy to 400k
1 parent 998a48f commit 97bc9b6

File tree

7 files changed

+43
-20
lines changed

7 files changed

+43
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cowprotocol/cow-sdk",
3-
"version": "6.3.2-RC.0",
3+
"version": "6.3.2-RC.1",
44
"license": "(MIT OR Apache-2.0)",
55
"files": [
66
"/dist"

src/bridging/PROVIDER_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ import { getGasLimitEstimationForHook } from '../utils/getGasLimitEstimationForH
381381

382382
export class YourBridgeProvider implements BridgeProvider<YourBridgeQuoteResult> {
383383
async getGasLimitEstimationForHook(
384-
request: Omit<QuoteBridgeRequest, 'amount'> & { extraGas?: number },
384+
request: Omit<QuoteBridgeRequest, 'amount'> & { extraGas?: number; extraGasProxyCreation?: number },
385385
): Promise<number> {
386386
// Use utility function or implement custom gas estimation
387387
return getGasLimitEstimationForHook(

src/bridging/const.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { RAW_FILES_PATH } from '../common/consts/path'
33
export const RAW_PROVIDERS_FILES_PATH = `${RAW_FILES_PATH}/src/bridging/providers`
44
// Based on https://dashboard.tenderly.co/shoom/project/simulator/a5e29dac-d0f2-407f-9e3d-d1b916da595b
55
export const DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION = 240_000
6-
export const DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 150_000
6+
export const DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 200_000
77
// Based on https://dashboard.tenderly.co/shoom/project/tx/0x2971aee9aa7237d24b254da8ccd4345ff77410c8829c8e825e9a02cb2cece5e6/gas-usage
88
export const COW_SHED_PROXY_CREATION_GAS = 360_000
9+
export const DEFAULT_EXTRA_GAS_PROXY_CREATION = 400_000
910
export const HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = 'cow-sdk://bridging/providers'

src/bridging/providers/across/AcrossBridgeProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult> {
145145
}
146146

147147
async getGasLimitEstimationForHook(request: QuoteBridgeRequest): Promise<number> {
148-
return getGasLimitEstimationForHook(this.cowShedSdk, request, this.getRpcProvider(request.sellTokenChainId))
148+
return getGasLimitEstimationForHook({
149+
cowShedSdk: this.cowShedSdk,
150+
request,
151+
provider: this.getRpcProvider(request.sellTokenChainId),
152+
})
149153
}
150154

151155
async getSignedHook(

src/bridging/providers/bungee/BungeeBridgeProvider.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
GetProviderBuyTokens,
1414
QuoteBridgeRequest,
1515
} from '../../types'
16-
import { DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, RAW_PROVIDERS_FILES_PATH } from '../../const'
16+
import {
17+
DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION,
18+
DEFAULT_EXTRA_GAS_PROXY_CREATION,
19+
RAW_PROVIDERS_FILES_PATH,
20+
} from '../../const'
1721
import { ChainId, ChainInfo, SupportedChainId } from '../../../chains'
1822
import { EvmCall, TokenInfo } from '../../../common'
1923
import { mainnet } from '../../../chains/details/mainnet'
@@ -150,14 +154,17 @@ export class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult> {
150154
}
151155

152156
async getGasLimitEstimationForHook(request: QuoteBridgeRequest): Promise<number> {
153-
const extraGas = this.isExtraGasRequired(request) ? DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION : undefined
157+
const isExtraGasRequired = this.isExtraGasRequired(request)
158+
const extraGas = isExtraGasRequired ? DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION : undefined
159+
const extraGasProxyCreation = isExtraGasRequired ? DEFAULT_EXTRA_GAS_PROXY_CREATION : undefined
154160

155-
return getGasLimitEstimationForHook(
156-
this.cowShedSdk,
161+
return getGasLimitEstimationForHook({
162+
cowShedSdk: this.cowShedSdk,
157163
request,
158-
this.getRpcProvider(request.sellTokenChainId),
164+
provider: this.getRpcProvider(request.sellTokenChainId),
159165
extraGas,
160-
)
166+
extraGasProxyCreation,
167+
})
161168
}
162169

163170
async getSignedHook(

src/bridging/providers/utils/getGasLimitEstimationForHook.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@ import type { JsonRpcProvider } from '@ethersproject/providers'
33
import { COW_SHED_PROXY_CREATION_GAS, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION } from '../../const'
44
import { CowShedSdk } from '../../../cow-shed'
55

6-
export async function getGasLimitEstimationForHook(
7-
cowShedSdk: CowShedSdk,
8-
request: QuoteBridgeRequest,
9-
provider: JsonRpcProvider,
10-
extraGas?: number,
11-
): Promise<number> {
6+
export async function getGasLimitEstimationForHook({
7+
cowShedSdk,
8+
request,
9+
provider,
10+
extraGas,
11+
extraGasProxyCreation,
12+
}: {
13+
cowShedSdk: CowShedSdk
14+
request: QuoteBridgeRequest
15+
provider: JsonRpcProvider
16+
extraGas?: number
17+
extraGasProxyCreation?: number
18+
}): Promise<number> {
1219
const proxyAddress = cowShedSdk.getCowShedAccount(request.sellTokenChainId, request.owner || request.account)
1320
const proxyCode = await provider.getCode(proxyAddress)
1421

1522
// Proxy is not deployed
1623
if (!proxyCode || proxyCode === '0x') {
17-
return DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS
24+
const baseGas = DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS
25+
return baseGas + (extraGasProxyCreation ? extraGasProxyCreation : 0)
1826
}
1927

2028
// Some bridges require extra gas to be added to the hook.

src/bridging/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,13 @@ export interface BridgeProvider<Q extends BridgeQuoteResult> {
209209
* 2. The final amount could affect hook gas costs
210210
*
211211
* By estimating gas costs independently, we can resolve this dependency cycle.
212-
* For some providers, the `extraGas` flag adds a 100,000 gas‐unit buffer to the hook
213-
* (see DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION).
212+
* For some providers, the `extraGas` flag adds a 150,000 gas‐unit buffer to the hook
213+
* and `extraGasProxyCreation` adds 360,000 gas‐unit buffer for the proxy creation
214+
* (see DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION and DEFAULT_EXTRA_GAS_PROXY_CREATION).
214215
*/
215-
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'> & { extraGas?: number }): Promise<number>
216+
getGasLimitEstimationForHook(
217+
request: Omit<QuoteBridgeRequest, 'amount'> & { extraGas?: number; extraGasProxyCreation?: number },
218+
): Promise<number>
216219

217220
/**
218221
* Get a pre-authorized hook for initiating a bridge.

0 commit comments

Comments
 (0)