diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-20 00:38:50 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-20 00:38:50 +0800 |
commit | a44f77a83811146ad68ee6f56bcda94e56d6a634 (patch) | |
tree | a3d586c9ad3203ba580367f0392fe00758fea18f /packages/asset-buyer/src/utils | |
parent | a03b1d4d6cc5548f4c2f07a933a4c2cc6be3b053 (diff) | |
download | dexon-sol-tools-a44f77a83811146ad68ee6f56bcda94e56d6a634.tar.gz dexon-sol-tools-a44f77a83811146ad68ee6f56bcda94e56d6a634.tar.zst dexon-sol-tools-a44f77a83811146ad68ee6f56bcda94e56d6a634.zip |
Implement StandardRelayerAPIAssetBuyerManager
Diffstat (limited to 'packages/asset-buyer/src/utils')
-rw-r--r-- | packages/asset-buyer/src/utils/asset_data_utils.ts | 26 | ||||
-rw-r--r-- | packages/asset-buyer/src/utils/buy_quote_calculator.ts | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/packages/asset-buyer/src/utils/asset_data_utils.ts b/packages/asset-buyer/src/utils/asset_data_utils.ts new file mode 100644 index 000000000..10ff31057 --- /dev/null +++ b/packages/asset-buyer/src/utils/asset_data_utils.ts @@ -0,0 +1,26 @@ +import { ContractWrappers } from '@0xproject/contract-wrappers'; +import { assetDataUtils as sharedAssetDataUtils } from '@0xproject/order-utils'; +import * as _ from 'lodash'; + +import { AssetBuyerError } from '../types'; + +export const assetDataUtils = { + ...sharedAssetDataUtils, + getEtherTokenAssetData(contractWrappers: ContractWrappers): string { + const etherTokenAddressIfExists = contractWrappers.etherToken.getContractAddressIfExists(); + if (_.isUndefined(etherTokenAddressIfExists)) { + throw new Error(AssetBuyerError.NoEtherTokenContractFound); + } + const etherTokenAssetData = sharedAssetDataUtils.encodeERC20AssetData(etherTokenAddressIfExists); + return etherTokenAssetData; + }, + getZrxTokenAssetData(contractWrappers: ContractWrappers): string { + let zrxTokenAssetData: string; + try { + zrxTokenAssetData = contractWrappers.exchange.getZRXAssetData(); + } catch (err) { + throw new Error(AssetBuyerError.NoZrxTokenContractFound); + } + return zrxTokenAssetData; + }, +}; diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index 52cecf8ad..31823cc02 100644 --- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts @@ -59,6 +59,7 @@ export const buyQuoteCalculator = { let maxEthAmount = constants.ZERO_AMOUNT; let cumulativeMakerAmount = constants.ZERO_AMOUNT; _.forEach(allOrders, (order, index) => { + // TODO: Move this logic to order_utils const remainingFillableMakerAssetAmount = allRemainingAmounts[index]; const orderRate = order.takerAssetAmount.div(order.makerAssetAmount); const claimableTakerAssetAmount = orderRate.mul(remainingFillableMakerAssetAmount); |