aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src/asset_buyer.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-09-15 20:47:44 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-09-15 20:47:44 +0800
commitaf40989f5f6b606172370d8e878c51ce2e7382eb (patch)
tree129b0d3d54d1b803a49d7119aa9fb5ec6b47e34c /packages/asset-buyer/src/asset_buyer.ts
parentd57619b5db8d4b5a8d31f095d8dfef04faef44c9 (diff)
downloaddexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.gz
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.bz2
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.lz
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.xz
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.zst
dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.zip
Add factory method on AssetBuyer for provided orders
Diffstat (limited to 'packages/asset-buyer/src/asset_buyer.ts')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index 3b603d929..a68658d22 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -1,5 +1,6 @@
import { ContractWrappers } from '@0xproject/contract-wrappers';
-import { assetDataUtils } from '@0xproject/order-utils';
+import { schemas } from '@0xproject/json-schemas';
+import { assetDataUtils, SignedOrder } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
@@ -13,6 +14,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';
@@ -31,6 +33,26 @@ export class AssetBuyer {
private readonly _contractWrappers: ContractWrappers;
private _lastRefreshTimeIfExists?: number;
private _currentOrdersAndFillableAmountsIfExists?: AssetBuyerOrdersAndFillableAmounts;
+ public static getAssetBuyerForProvidedOrders(
+ provider: Provider,
+ orders: SignedOrder[],
+ feeOrders: SignedOrder[] = [],
+ networkId: number = constants.MAINNET_NETWORK_ID,
+ orderRefreshIntervalMs: number = DEFAULT_ORDER_REFRESH_INTERVAL_MS,
+ ): AssetBuyer {
+ assert.isWeb3Provider('provider', provider);
+ assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
+ assert.doesConformToSchema('feeOrders', feeOrders, schemas.signedOrdersSchema);
+ assert.isNumber('networkId', networkId);
+ assert.isNumber('orderRefreshIntervalMs', orderRefreshIntervalMs);
+ assert.areValidProvidedOrders('orders', orders);
+ assert.areValidProvidedOrders('feeOrders', feeOrders);
+ assert.assert(orders.length !== 0, `Expected orders to contain at least one order`);
+ const assetData = orders[0].makerAssetData;
+ const orderFetcher = new ProvidedOrderFetcher(_.concat(orders, feeOrders));
+ 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.