diff --git a/packages/asset-swapper/contracts/src/BancorV3Sampler.sol b/packages/asset-swapper/contracts/src/BancorV3Sampler.sol index b9a81150c2..821795ad68 100644 --- a/packages/asset-swapper/contracts/src/BancorV3Sampler.sol +++ b/packages/asset-swapper/contracts/src/BancorV3Sampler.sol @@ -28,6 +28,8 @@ contract BancorV3Sampler /// @dev Gas limit for BancorV3 calls. uint256 constant private BancorV3_CALL_GAS = 150e3; // 150k + address constant public ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + /// @dev Sample sell quotes from BancorV3. /// @param router Router to look up tokens and amounts /// @param path Token route. Should be takerToken -> makerToken @@ -35,6 +37,7 @@ contract BancorV3Sampler /// @return makerTokenAmounts Maker amounts bought at each taker token /// amount. function sampleSellsFromBancorV3( + address weth, address router, address[] memory path, uint256[] memory takerTokenAmounts @@ -45,6 +48,14 @@ contract BancorV3Sampler { uint256 numSamples = takerTokenAmounts.length; makerTokenAmounts = new uint256[](numSamples); + + if(path[0] == weth){ + path[0] = ETH; + } + if(path[1] == weth){ + path[1] = ETH; + } + for (uint256 i = 0; i < numSamples; i++) { try IBancorV3(router).tradeOutputBySourceAmount(path[0], path[1], takerTokenAmounts[i]) @@ -69,6 +80,7 @@ contract BancorV3Sampler /// @return takerTokenAmounts Taker amounts sold at each maker token /// amount. function sampleBuysFromBancorV3( + address weth, address router, address[] memory path, uint256[] memory makerTokenAmounts @@ -79,6 +91,14 @@ contract BancorV3Sampler { uint256 numSamples = makerTokenAmounts.length; takerTokenAmounts = new uint256[](numSamples); + + if(path[0] == weth){ + path[0] = ETH; + } + if(path[1] == weth){ + path[1] = ETH; + } + for (uint256 i = 0; i < numSamples; i++) { try IBancorV3(router).tradeInputByTargetAmount(path[0], path[1], makerTokenAmounts[i]) diff --git a/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts b/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts index 2d2adc990b..ddb96f08b2 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts @@ -47,6 +47,7 @@ import { SELL_SOURCE_FILTER_BY_CHAIN_ID, UNISWAPV1_ROUTER_BY_CHAIN_ID, UNISWAPV3_CONFIG_BY_CHAIN_ID, + MAINNET_TOKENS, ZERO_AMOUNT, } from './constants'; import { getGeistInfoForPair } from './geist_utils'; @@ -722,7 +723,7 @@ export class SamplerOperations { fillData: { networkAddress, path}, contract: this._samplerContract, function: this._samplerContract.sampleBuysFromBancorV3, - params: [networkInfoAddress, path, takerFillAmounts], + params: [MAINNET_TOKENS.WETH, networkInfoAddress, path, takerFillAmounts], }); } @@ -738,7 +739,7 @@ export class SamplerOperations { fillData: { networkAddress, path}, contract: this._samplerContract, function: this._samplerContract.sampleBuysFromBancorV3, - params: [networkInfoAddress, path, makerFillAmounts], + params: [MAINNET_TOKENS.WETH, networkInfoAddress, path, makerFillAmounts], }); }