aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/asset_wrapper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/utils/asset_wrapper.ts')
-rw-r--r--packages/contracts/src/utils/asset_wrapper.ts32
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;
+ }
+}