@@ -2,7 +2,12 @@ import { latest as latestAppData } from '@cowprotocol/app-data'
22import { OrderKind } from '@cowprotocol/contracts'
33import { JsonRpcProvider } from '@ethersproject/providers'
44import { SupportedChainId , TargetChainId } from '../../../chains'
5- import { DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION , DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION } from '../../const'
5+ import {
6+ COW_SHED_PROXY_CREATION_GAS ,
7+ DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION ,
8+ DEFAULT_EXTRA_GAS_PROXY_CREATION ,
9+ DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION ,
10+ } from '../../const'
611import { BridgeStatus , QuoteBridgeRequest } from '../../types'
712import { BungeeApi } from './BungeeApi'
813import {
@@ -33,6 +38,8 @@ class BungeeBridgeProviderTest extends BungeeBridgeProvider {
3338 }
3439}
3540
41+ const mockGetCode = jest . fn ( )
42+
3643describe ( 'BungeeBridgeProvider' , ( ) => {
3744 let provider : BungeeBridgeProviderTest
3845
@@ -41,7 +48,7 @@ describe('BungeeBridgeProvider', () => {
4148 apiOptions : { } ,
4249 getRpcProvider ( ) {
4350 return {
44- getCode : jest . fn ( ) . mockResolvedValue ( '0x1234567890' ) ,
51+ getCode : mockGetCode ,
4552 } as unknown as JsonRpcProvider
4653 } ,
4754 }
@@ -396,7 +403,9 @@ describe('BungeeBridgeProvider', () => {
396403 } )
397404
398405 describe ( 'getGasLimitEstimationForHook' , ( ) => {
399- it ( 'should return default gas limit estimation for non-Mainnet to Gnosis' , async ( ) => {
406+ it ( 'should return default gas limit estimation for Mainnet to Polygon' , async ( ) => {
407+ mockGetCode . mockResolvedValue ( '0x1234567890' )
408+
400409 const request : QuoteBridgeRequest = {
401410 kind : OrderKind . SELL ,
402411 sellTokenAddress : '0x123' ,
@@ -417,7 +426,32 @@ describe('BungeeBridgeProvider', () => {
417426 expect ( gasLimit ) . toEqual ( DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION )
418427 } )
419428
429+ it ( 'should return default gas limit estimation for Mainnet to Polygon and deploy proxy account' , async ( ) => {
430+ mockGetCode . mockResolvedValue ( undefined )
431+
432+ const request : QuoteBridgeRequest = {
433+ kind : OrderKind . SELL ,
434+ sellTokenAddress : '0x123' ,
435+ sellTokenChainId : SupportedChainId . MAINNET ,
436+ buyTokenChainId : SupportedChainId . POLYGON ,
437+ amount : 1000000000000000000n ,
438+ receiver : '0x789' ,
439+ account : '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' , // need to find cowshed account address
440+ sellTokenDecimals : 18 ,
441+ buyTokenAddress : '0x456' ,
442+ buyTokenDecimals : 6 ,
443+ appCode : '0x123' ,
444+ signer : '0xa43ccc40ff785560dab6cb0f13b399d050073e8a54114621362f69444e1421ca' ,
445+ }
446+
447+ const gasLimit = await provider . getGasLimitEstimationForHook ( request )
448+
449+ expect ( gasLimit ) . toEqual ( DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS )
450+ } )
451+
420452 it ( 'should return default gas limit estimation for Mainnet to Gnosis' , async ( ) => {
453+ mockGetCode . mockResolvedValue ( '0x1234567890' )
454+
421455 const request : QuoteBridgeRequest = {
422456 kind : OrderKind . SELL ,
423457 sellTokenAddress : '0x123' ,
@@ -437,5 +471,30 @@ describe('BungeeBridgeProvider', () => {
437471
438472 expect ( gasLimit ) . toEqual ( DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION )
439473 } )
474+
475+ it ( 'should return default gas limit estimation for Mainnet to Gnosis and deploy proxy account' , async ( ) => {
476+ mockGetCode . mockResolvedValue ( '0x' )
477+
478+ const request : QuoteBridgeRequest = {
479+ kind : OrderKind . SELL ,
480+ sellTokenAddress : '0x123' ,
481+ sellTokenChainId : SupportedChainId . MAINNET ,
482+ buyTokenChainId : SupportedChainId . GNOSIS_CHAIN ,
483+ amount : 1000000000000000000n ,
484+ receiver : '0x789' ,
485+ account : '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' , // need to find cowshed account address
486+ sellTokenDecimals : 18 ,
487+ buyTokenAddress : '0x456' ,
488+ buyTokenDecimals : 6 ,
489+ appCode : '0x123' ,
490+ signer : '0xa43ccc40ff785560dab6cb0f13b399d050073e8a54114621362f69444e1421ca' ,
491+ }
492+
493+ const gasLimit = await provider . getGasLimitEstimationForHook ( request )
494+
495+ expect ( gasLimit ) . toEqual (
496+ DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS + DEFAULT_EXTRA_GAS_PROXY_CREATION ,
497+ )
498+ } )
440499 } )
441500} )
0 commit comments