diff --git a/packages/asset-swapper/CHANGELOG.json b/packages/asset-swapper/CHANGELOG.json index e255344a00..ab6efa68d0 100644 --- a/packages/asset-swapper/CHANGELOG.json +++ b/packages/asset-swapper/CHANGELOG.json @@ -9,6 +9,10 @@ { "note": "Return the maker/taker token decimals from the sampler as part of the `SwapQuote`", "pr": 34 + }, + { + "note": "Disable off-chain sampling for Balancer and CREAM", + "pr": 41 } ] }, 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 0927e71ea6..27f3bb9178 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 @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { ERC20BridgeSamplerContract } from '../../wrappers'; -import { BalancerPoolsCache, computeBalancerBuyQuote, computeBalancerSellQuote } from './balancer_utils'; +import { BalancerPoolsCache } from './balancer_utils'; import { BancorService } from './bancor_service'; import { LIQUIDITY_PROVIDER_REGISTRY, MAINNET_SUSHI_SWAP_ROUTER, MAX_UINT256, ZERO_AMOUNT } from './constants'; import { CreamPoolsCache } from './cream_utils'; @@ -480,65 +480,74 @@ export class SamplerOperations { public async getBalancerSellQuotesOffChainAsync( makerToken: string, takerToken: string, - takerFillAmounts: BigNumber[], + _takerFillAmounts: BigNumber[], ): Promise>>> { - const pools = await this.balancerPoolsCache.getPoolsForPairAsync(takerToken, makerToken); - return pools.map(pool => - takerFillAmounts.map(amount => ({ - source: ERC20BridgeSource.Balancer, - output: computeBalancerSellQuote(pool, amount), - input: amount, - fillData: { poolAddress: pool.id }, - })), - ); + // Prime the cache but do not sample off chain + await this.balancerPoolsCache.getPoolsForPairAsync(takerToken, makerToken); + return []; + // return pools.map(pool => + // takerFillAmounts.map(amount => ({ + // source: ERC20BridgeSource.Balancer, + // output: computeBalancerSellQuote(pool, amount), + // input: amount, + // fillData: { poolAddress: pool.id }, + // })), + // ); } public async getBalancerBuyQuotesOffChainAsync( makerToken: string, takerToken: string, - makerFillAmounts: BigNumber[], + _makerFillAmounts: BigNumber[], ): Promise>>> { - const pools = await this.balancerPoolsCache.getPoolsForPairAsync(takerToken, makerToken); - return pools.map(pool => - makerFillAmounts.map(amount => ({ - source: ERC20BridgeSource.Balancer, - output: computeBalancerBuyQuote(pool, amount), - input: amount, - fillData: { poolAddress: pool.id }, - })), - ); + // Prime the pools but do not sample off chain + // Prime the cache but do not sample off chain + await this.balancerPoolsCache.getPoolsForPairAsync(takerToken, makerToken); + return []; + // return pools.map(pool => + // makerFillAmounts.map(amount => ({ + // source: ERC20BridgeSource.Balancer, + // output: computeBalancerBuyQuote(pool, amount), + // input: amount, + // fillData: { poolAddress: pool.id }, + // })), + // ); } public async getCreamSellQuotesOffChainAsync( makerToken: string, takerToken: string, - takerFillAmounts: BigNumber[], + _takerFillAmounts: BigNumber[], ): Promise>>> { - const pools = await this.creamPoolsCache.getPoolsForPairAsync(takerToken, makerToken); - return pools.map(pool => - takerFillAmounts.map(amount => ({ - source: ERC20BridgeSource.Cream, - output: computeBalancerSellQuote(pool, amount), - input: amount, - fillData: { poolAddress: pool.id }, - })), - ); + // Prime the cache but do not sample off chain + await this.creamPoolsCache.getPoolsForPairAsync(takerToken, makerToken); + return []; + // return pools.map(pool => + // takerFillAmounts.map(amount => ({ + // source: ERC20BridgeSource.Cream, + // output: computeBalancerSellQuote(pool, amount), + // input: amount, + // fillData: { poolAddress: pool.id }, + // })), + // ); } public async getCreamBuyQuotesOffChainAsync( makerToken: string, takerToken: string, - makerFillAmounts: BigNumber[], + _makerFillAmounts: BigNumber[], ): Promise>>> { - const pools = await this.creamPoolsCache.getPoolsForPairAsync(takerToken, makerToken); - return pools.map(pool => - makerFillAmounts.map(amount => ({ - source: ERC20BridgeSource.Cream, - output: computeBalancerBuyQuote(pool, amount), - input: amount, - fillData: { poolAddress: pool.id }, - })), - ); + // Prime the cache but do not sample off chain + await this.creamPoolsCache.getPoolsForPairAsync(takerToken, makerToken); + return []; + // return pools.map(pool => + // makerFillAmounts.map(amount => ({ + // source: ERC20BridgeSource.Cream, + // output: computeBalancerBuyQuote(pool, amount), + // input: amount, + // fillData: { poolAddress: pool.id }, + // })), + // ); } public getMStableSellQuotes( diff --git a/packages/asset-swapper/test/dex_sampler_test.ts b/packages/asset-swapper/test/dex_sampler_test.ts index 6a18b562ea..1e65ac341a 100644 --- a/packages/asset-swapper/test/dex_sampler_test.ts +++ b/packages/asset-swapper/test/dex_sampler_test.ts @@ -12,11 +12,7 @@ import { SignedOrder } from '@0x/types'; import { BigNumber, hexUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { - BalancerPool, - computeBalancerBuyQuote, - computeBalancerSellQuote, -} from '../src/utils/market_operation_utils/balancer_utils'; +import { BalancerPool } from '../src/utils/market_operation_utils/balancer_utils'; import { DexOrderSampler, getSampleAmounts } from '../src/utils/market_operation_utils/sampler'; import { ERC20BridgeSource, TokenAdjacencyGraph } from '../src/utils/market_operation_utils/types'; @@ -425,7 +421,10 @@ describe('DexSampler tests', () => { expect(quotes).to.have.lengthOf(sources.length + additionalSourceCount); expect(quotes).to.deep.eq(expectedQuotes.concat(uniswapV2ETHQuotes)); }); - it('getSellQuotes() uses samples from Balancer', async () => { + it('getSellQuotes() fetches pools but not samples from Balancer', async () => { + // HACK + // We disabled the off-chain sampling due to incorrect data observed between + // on-chain and off-chain sampling const expectedTakerToken = randomAddress(); const expectedMakerToken = randomAddress(); const expectedTakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 3); @@ -448,16 +447,7 @@ describe('DexSampler tests', () => { expectedTakerToken, expectedTakerFillAmounts, ); - const expectedQuotes = pools.map(p => - expectedTakerFillAmounts.map(a => ({ - source: ERC20BridgeSource.Balancer, - input: a, - output: computeBalancerSellQuote(p, a), - fillData: { poolAddress: p.id }, - })), - ); - expect(quotes).to.have.lengthOf(2); // one array per pool - expect(quotes).to.deep.eq(expectedQuotes); + expect(quotes).to.have.lengthOf(0); }); it('getSellQuotes() uses samples from Bancor', async () => { const expectedTakerToken = randomAddress(); @@ -593,16 +583,7 @@ describe('DexSampler tests', () => { expectedTakerToken, expectedMakerFillAmounts, ); - const expectedQuotes = pools.map(p => - expectedMakerFillAmounts.map(a => ({ - source: ERC20BridgeSource.Balancer, - input: a, - output: computeBalancerBuyQuote(p, a), - fillData: { poolAddress: p.id }, - })), - ); - expect(quotes).to.have.lengthOf(2); // one set per pool - expect(quotes).to.deep.eq(expectedQuotes); + expect(quotes).to.have.lengthOf(0); }); });