diff --git a/packages/asset-swapper/src/quote_consumers/exchange_proxy_swap_quote_consumer.ts b/packages/asset-swapper/src/quote_consumers/exchange_proxy_swap_quote_consumer.ts index 921b18b11f..dc88874b58 100644 --- a/packages/asset-swapper/src/quote_consumers/exchange_proxy_swap_quote_consumer.ts +++ b/packages/asset-swapper/src/quote_consumers/exchange_proxy_swap_quote_consumer.ts @@ -9,11 +9,11 @@ import { ERC20AssetData, ETH_TOKEN_ADDRESS, FillQuoteTransformerSide, + findTransformerNonce, } from '@0x/order-utils'; import { AssetProxyId } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { SupportedProvider, ZeroExProvider } from '@0x/web3-wrapper'; -import * as ethjs from 'ethereumjs-util'; import * as _ from 'lodash'; import { constants } from '../constants'; @@ -34,7 +34,6 @@ import { assert } from '../utils/assert'; // tslint:disable-next-line:custom-no-magic-numbers const MAX_UINT256 = new BigNumber(2).pow(256).minus(1); const { NULL_ADDRESS } = constants; -const MAX_NONCE_GUESSES = 2048; export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase { public readonly provider: ZeroExProvider; @@ -210,32 +209,3 @@ function getTokenFromAssetData(assetData: string): string { // tslint:disable-next-line:no-unnecessary-type-assertion return (data as ERC20AssetData).tokenAddress; } - -/** - * Find the nonce for a transformer given its deployer. - * If `deployer` is the null address, zero will always be returned. - */ -export function findTransformerNonce(transformer: string, deployer: string = NULL_ADDRESS): number { - if (deployer === NULL_ADDRESS) { - return 0; - } - const lowercaseTransformer = transformer.toLowerCase(); - // Try to guess the nonce. - for (let nonce = 0; nonce < MAX_NONCE_GUESSES; ++nonce) { - const deployedAddress = getTransformerAddress(deployer, nonce); - if (deployedAddress === lowercaseTransformer) { - return nonce; - } - } - throw new Error(`${deployer} did not deploy ${transformer}!`); -} - -/** - * Compute the deployed address for a transformer given a deployer and nonce. - */ -export function getTransformerAddress(deployer: string, nonce: number): string { - return ethjs.bufferToHex( - // tslint:disable-next-line: custom-no-magic-numbers - ethjs.rlphash([deployer, nonce] as any).slice(12), - ); -} diff --git a/packages/asset-swapper/test/exchange_proxy_swap_quote_consumer_test.ts b/packages/asset-swapper/test/exchange_proxy_swap_quote_consumer_test.ts index 03052506fc..7f5ce6780d 100644 --- a/packages/asset-swapper/test/exchange_proxy_swap_quote_consumer_test.ts +++ b/packages/asset-swapper/test/exchange_proxy_swap_quote_consumer_test.ts @@ -8,6 +8,7 @@ import { decodeWethTransformerData, ETH_TOKEN_ADDRESS, FillQuoteTransformerSide, + getTransformerAddress, } from '@0x/order-utils'; import { Order } from '@0x/types'; import { AbiEncoder, BigNumber, hexUtils } from '@0x/utils'; @@ -16,10 +17,7 @@ import * as _ from 'lodash'; import 'mocha'; import { constants } from '../src/constants'; -import { - ExchangeProxySwapQuoteConsumer, - getTransformerAddress, -} from '../src/quote_consumers/exchange_proxy_swap_quote_consumer'; +import { ExchangeProxySwapQuoteConsumer } from '../src/quote_consumers/exchange_proxy_swap_quote_consumer'; import { MarketBuySwapQuote, MarketOperation, MarketSellSwapQuote } from '../src/types'; import { OptimizedMarketOrder } from '../src/utils/market_operation_utils/types';