diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-13 22:01:01 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-13 22:01:01 +0800 |
commit | fe75660e88ed0c37c4f3d461a644bd9305bf6183 (patch) | |
tree | 5c4ec25bc6ef5c0b5573cf4e4f9fe34428394a49 /packages/contracts/src/utils/asset_wrapper.ts | |
parent | 946e6c16442ce434e160fa47a87cd705c5274038 (diff) | |
download | dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar.gz dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar.bz2 dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar.lz dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar.xz dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.tar.zst dexon-sol-tools-fe75660e88ed0c37c4f3d461a644bd9305bf6183.zip |
Refactor ERC20 and ERC721 wrappers for V2 and introduce the assetWrapper superset
Diffstat (limited to 'packages/contracts/src/utils/asset_wrapper.ts')
-rw-r--r-- | packages/contracts/src/utils/asset_wrapper.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/contracts/src/utils/asset_wrapper.ts b/packages/contracts/src/utils/asset_wrapper.ts new file mode 100644 index 000000000..4c345aa30 --- /dev/null +++ b/packages/contracts/src/utils/asset_wrapper.ts @@ -0,0 +1,32 @@ +import { assetProxyUtils } from '@0xproject/order-utils'; +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +import { AbstractAssetWrapper } from '../abstract/abstract_asset_wrapper'; + +interface ProxyIdToAssetWrappers { + [proxyId: number]: AbstractAssetWrapper; +} + +export class AssetWrapper { + private _proxyIdToAssetWrappers: ProxyIdToAssetWrappers; + constructor(assetWrappers: AbstractAssetWrapper[]) { + this._proxyIdToAssetWrappers = {}; + _.each(assetWrappers, assetWrapper => { + const proxyId = assetWrapper.getProxyId(); + this._proxyIdToAssetWrappers[proxyId] = assetWrapper; + }); + } + public async getBalanceAsync(owner: string, assetData: string): Promise<BigNumber> { + const proxyId = assetProxyUtils.decodeAssetDataId(assetData); + const assetWrapper = this._proxyIdToAssetWrappers[proxyId]; + const balance = await assetWrapper.getBalanceAsync(owner, assetData); + return balance; + } + public async getProxyAllowanceAsync(owner: string, assetData: string): Promise<BigNumber> { + const proxyId = assetProxyUtils.decodeAssetDataId(assetData); + const assetWrapper = this._proxyIdToAssetWrappers[proxyId]; + const balance = await assetWrapper.getProxyAllowanceAsync(owner, assetData); + return balance; + } +} |