diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-09-15 20:53:04 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-09-15 20:53:04 +0800 |
commit | 9ec2b5a2d53bad2820b297f90bd16528f87537eb (patch) | |
tree | 4e4a9a232aa6abcc0fad01cabfe1ade4e18afc81 | |
parent | af40989f5f6b606172370d8e878c51ce2e7382eb (diff) | |
download | dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar.gz dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar.bz2 dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar.lz dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar.xz dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.tar.zst dexon-sol-tools-9ec2b5a2d53bad2820b297f90bd16528f87537eb.zip |
Add factory method on AssetBuyer for specific token address
-rw-r--r-- | packages/asset-buyer/src/asset_buyer.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index a68658d22..bb3d6d77c 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -7,6 +7,8 @@ import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; import { constants } from './constants'; +import { ProvidedOrderFetcher } from './order_fetchers/provided_order_fetcher'; +import { StandardRelayerAPIOrderFetcher } from './order_fetchers/standard_relayer_api_order_fetcher'; import { AssetBuyerError, AssetBuyerOrdersAndFillableAmounts, @@ -14,7 +16,7 @@ import { OrderFetcher, OrderFetcherResponse, } from './types'; -import { ProvidedOrderFetcher } from './order_fetchers/provided_order_fetcher'; + import { assert } from './utils/assert'; import { buyQuoteCalculator } from './utils/buy_quote_calculator'; import { orderFetcherResponseProcessor } from './utils/order_fetcher_response_processor'; @@ -53,6 +55,23 @@ export class AssetBuyer { const assetBuyer = new AssetBuyer(provider, assetData, orderFetcher, networkId, orderRefreshIntervalMs); return assetBuyer; } + public static getAssetBuyerForERC20TokenAddress( + provider: Provider, + tokenAddress: string, + sraApiUrl: string, + networkId: number = constants.MAINNET_NETWORK_ID, + orderRefreshIntervalMs: number = DEFAULT_ORDER_REFRESH_INTERVAL_MS, + ): AssetBuyer { + assert.isWeb3Provider('provider', provider); + assert.isETHAddressHex('tokenAddress', tokenAddress); + assert.isWebUri('sraApiUrl', sraApiUrl); + assert.isNumber('networkId', networkId); + assert.isNumber('orderRefreshIntervalMs', orderRefreshIntervalMs); + const assetData = assetDataUtils.encodeERC20AssetData(tokenAddress); + const orderFetcher = new StandardRelayerAPIOrderFetcher(sraApiUrl); + const assetBuyer = new AssetBuyer(provider, assetData, orderFetcher, networkId, orderRefreshIntervalMs); + return assetBuyer; + } /** * Instantiates a new AssetBuyer instance * @param provider The Provider instance you would like to use for interacting with the Ethereum network. |