diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/contract-wrappers/src/fetchers | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/contract-wrappers/src/fetchers')
-rw-r--r-- | packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts | 91 | ||||
-rw-r--r-- | packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts | 39 |
2 files changed, 0 insertions, 130 deletions
diff --git a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts deleted file mode 100644 index c35b24664..000000000 --- a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { AbstractBalanceAndProxyAllowanceFetcher, assetDataUtils } from '@0x/order-utils'; -import { BigNumber } from '@0x/utils'; -import { BlockParamLiteral } from 'ethereum-types'; -import * as _ from 'lodash'; - -import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper'; -import { ERC721TokenWrapper } from '../contract_wrappers/erc721_token_wrapper'; - -export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndProxyAllowanceFetcher { - private readonly _erc20Token: ERC20TokenWrapper; - private readonly _erc721Token: ERC721TokenWrapper; - private readonly _stateLayer: BlockParamLiteral; - constructor(erc20Token: ERC20TokenWrapper, erc721Token: ERC721TokenWrapper, stateLayer: BlockParamLiteral) { - this._erc20Token = erc20Token; - this._erc721Token = erc721Token; - this._stateLayer = stateLayer; - } - public async getBalanceAsync(assetData: string, userAddress: string): Promise<BigNumber> { - const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); - let balance: BigNumber | undefined; - if (assetDataUtils.isERC20AssetData(decodedAssetData)) { - balance = await this._erc20Token.getBalanceAsync(decodedAssetData.tokenAddress, userAddress, { - defaultBlock: this._stateLayer, - }); - } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) { - const tokenOwner = await this._erc721Token.getOwnerOfAsync( - decodedAssetData.tokenAddress, - decodedAssetData.tokenId, - { - defaultBlock: this._stateLayer, - }, - ); - balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0); - } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { - // The `balance` for MultiAssetData is the total units of the entire `assetData` that are held by the `userAddress`. - for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) { - const nestedAmountElement = decodedAssetData.amounts[index]; - const nestedAssetBalance = (await this.getBalanceAsync( - nestedAssetDataElement, - userAddress, - )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(balance) || nestedAssetBalance.isLessThan(balance)) { - balance = nestedAssetBalance; - } - } - } - return balance as BigNumber; - } - public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise<BigNumber> { - const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); - let proxyAllowance: BigNumber | undefined; - if (assetDataUtils.isERC20AssetData(decodedAssetData)) { - proxyAllowance = await this._erc20Token.getProxyAllowanceAsync(decodedAssetData.tokenAddress, userAddress, { - defaultBlock: this._stateLayer, - }); - } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) { - const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync( - decodedAssetData.tokenAddress, - userAddress, - { - defaultBlock: this._stateLayer, - }, - ); - if (isApprovedForAll) { - return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); - } else { - const isApproved = await this._erc721Token.isProxyApprovedAsync( - decodedAssetData.tokenAddress, - decodedAssetData.tokenId, - { - defaultBlock: this._stateLayer, - }, - ); - proxyAllowance = isApproved ? new BigNumber(1) : new BigNumber(0); - } - } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { - // The `proxyAllowance` for MultiAssetData is the total units of the entire `assetData` that the proxies have been approved to spend by the `userAddress`. - for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) { - const nestedAmountElement = decodedAssetData.amounts[index]; - const nestedAssetAllowance = (await this.getProxyAllowanceAsync( - nestedAssetDataElement, - userAddress, - )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.isLessThan(proxyAllowance)) { - proxyAllowance = nestedAssetAllowance; - } - } - } - return proxyAllowance as BigNumber; - } -} diff --git a/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts b/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts deleted file mode 100644 index 5d350916c..000000000 --- a/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts +++ /dev/null @@ -1,39 +0,0 @@ -// tslint:disable:no-unnecessary-type-assertion -import { AbstractOrderFilledCancelledFetcher, orderHashUtils } from '@0x/order-utils'; -import { SignedOrder } from '@0x/types'; -import { BigNumber } from '@0x/utils'; -import { BlockParamLiteral } from 'ethereum-types'; - -import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; - -export class OrderFilledCancelledFetcher implements AbstractOrderFilledCancelledFetcher { - private readonly _exchange: ExchangeWrapper; - private readonly _stateLayer: BlockParamLiteral; - constructor(exchange: ExchangeWrapper, stateLayer: BlockParamLiteral) { - this._exchange = exchange; - this._stateLayer = stateLayer; - } - public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { - const filledTakerAmount = this._exchange.getFilledTakerAssetAmountAsync(orderHash, { - defaultBlock: this._stateLayer, - }); - return filledTakerAmount; - } - public async isOrderCancelledAsync(signedOrder: SignedOrder): Promise<boolean> { - const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - const isCancelled = await this._exchange.isCancelledAsync(orderHash); - const orderEpoch = await this._exchange.getOrderEpochAsync( - signedOrder.makerAddress, - signedOrder.senderAddress, - { - defaultBlock: this._stateLayer, - }, - ); - const isCancelledByOrderEpoch = orderEpoch > signedOrder.salt; - return isCancelled || isCancelledByOrderEpoch; - } - public getZRXAssetData(): string { - const zrxAssetData = this._exchange.getZRXAssetData(); - return zrxAssetData; - } -} |