aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-09-15 21:05:27 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-09-15 21:05:27 +0800
commita22d2dc7ee3a1f354074009f3ff117b14050f5c6 (patch)
tree384beaf48b523951730e56e829287ea52b924d23 /packages
parent9ec2b5a2d53bad2820b297f90bd16528f87537eb (diff)
downloaddexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar.gz
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar.bz2
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar.lz
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar.xz
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.tar.zst
dexon-sol-tools-a22d2dc7ee3a1f354074009f3ff117b14050f5c6.zip
Add factory method for specific assetData to buy and add comments
Diffstat (limited to 'packages')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts55
-rw-r--r--packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts2
2 files changed, 54 insertions, 3 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index bb3d6d77c..fa1118e18 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -35,6 +35,16 @@ export class AssetBuyer {
private readonly _contractWrappers: ContractWrappers;
private _lastRefreshTimeIfExists?: number;
private _currentOrdersAndFillableAmountsIfExists?: AssetBuyerOrdersAndFillableAmounts;
+ /**
+ * Instantiates a new AssetBuyer instance
+ * @param provider The Provider instance you would like to use for interacting with the Ethereum network.
+ * @param orders A non-empty array of objects that conform to SignedOrder. All orders must have the same makerAssetData and takerAssetData (WETH).
+ * @param feeOrders A array of objects that conform to SignedOrder. All orders must have the same makerAssetData (ZRX) and takerAssetData (WETH). Defaults to an empty array.
+ * @param networkId The ethereum network id. Defaults to 1 (mainnet).
+ * @param orderRefreshIntervalMs The interval in ms that getBuyQuoteAsync should trigger an refresh of orders and order states.
+ * Defaults to 10000ms (10s).
+ * @return An instance of AssetBuyer
+ */
public static getAssetBuyerForProvidedOrders(
provider: Provider,
orders: SignedOrder[],
@@ -55,6 +65,42 @@ export class AssetBuyer {
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.
+ * @param assetData The assetData that identifies the desired asset to buy.
+ * @param sraApiUrl The standard relayer API base HTTP url you would like to source orders from.
+ * @param networkId The ethereum network id. Defaults to 1 (mainnet).
+ * @param orderRefreshIntervalMs The interval in ms that getBuyQuoteAsync should trigger an refresh of orders and order states.
+ * Defaults to 10000ms (10s).
+ * @return An instance of AssetBuyer
+ */
+ public static getAssetBuyerForAssetData(
+ provider: Provider,
+ assetData: string,
+ sraApiUrl: string,
+ networkId: number = constants.MAINNET_NETWORK_ID,
+ orderRefreshIntervalMs: number = DEFAULT_ORDER_REFRESH_INTERVAL_MS,
+ ): AssetBuyer {
+ assert.isWeb3Provider('provider', provider);
+ assert.isHexString('assetData', assetData);
+ assert.isWebUri('sraApiUrl', sraApiUrl);
+ assert.isNumber('networkId', networkId);
+ assert.isNumber('orderRefreshIntervalMs', orderRefreshIntervalMs);
+ 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.
+ * @param tokenAddress The ERC20 token address that identifies the desired asset to buy.
+ * @param sraApiUrl The standard relayer API base HTTP url you would like to source orders from.
+ * @param networkId The ethereum network id. Defaults to 1 (mainnet).
+ * @param orderRefreshIntervalMs The interval in ms that getBuyQuoteAsync should trigger an refresh of orders and order states.
+ * Defaults to 10000ms (10s).
+ * @return An instance of AssetBuyer
+ */
public static getAssetBuyerForERC20TokenAddress(
provider: Provider,
tokenAddress: string,
@@ -68,8 +114,13 @@ export class AssetBuyer {
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);
+ const assetBuyer = AssetBuyer.getAssetBuyerForAssetData(
+ provider,
+ assetData,
+ sraApiUrl,
+ networkId,
+ orderRefreshIntervalMs,
+ );
return assetBuyer;
}
/**
diff --git a/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts b/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts
index 9fcd16ca1..3b082b68d 100644
--- a/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts
+++ b/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts
@@ -43,7 +43,7 @@ export class StandardRelayerAPIOrderFetcher implements OrderFetcher {
}
/**
* Instantiates a new StandardRelayerAPIOrderFetcher instance
- * @param apiUrl The relayer API base HTTP url you would like to interact with.
+ * @param apiUrl The standard relayer API base HTTP url you would like to source orders from.
* @return An instance of StandardRelayerAPIOrderFetcher
*/
constructor(apiUrl: string) {