aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-21 01:14:04 +0800
committerFabio Berger <me@fabioberger.com>2018-06-21 01:14:04 +0800
commit5bfdffda1155e306b17eee0a4e60320c3433d5c4 (patch)
tree10beed3fe27c6027378e9ef347fb8de59ed6d3df /packages/contracts
parent247f8c8557a501ea5081615d9b031c9e4b7aeec7 (diff)
downloaddexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar.gz
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar.bz2
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar.lz
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar.xz
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.tar.zst
dexon-sol-tools-5bfdffda1155e306b17eee0a4e60320c3433d5c4.zip
Add support for approveAll in assetWrapper and fillOrderScenarios
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/utils/asset_wrapper.ts12
-rw-r--r--packages/contracts/src/utils/core_combinatorial_utils.ts32
-rw-r--r--packages/contracts/src/utils/types.ts1
-rw-r--r--packages/contracts/test/exchange/fill_order.ts40
4 files changed, 80 insertions, 5 deletions
diff --git a/packages/contracts/src/utils/asset_wrapper.ts b/packages/contracts/src/utils/asset_wrapper.ts
index fd543621f..9c683054d 100644
--- a/packages/contracts/src/utils/asset_wrapper.ts
+++ b/packages/contracts/src/utils/asset_wrapper.ts
@@ -110,16 +110,20 @@ export class AssetWrapper {
case constants.ERC721_PROXY_ID: {
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
- const isProxyApproved = await assetWrapper.isProxyApprovedAsync(
+ const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
+ userAddress,
erc721ProxyData.tokenAddress,
erc721ProxyData.tokenId,
);
- const isProxyApprovedForAllAsync = await assetWrapper.isProxyApprovedForAllAsync(
- userAddress,
+ if (isProxyApprovedForAll) {
+ return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
+ }
+
+ const isProxyApproved = await assetWrapper.isProxyApprovedAsync(
erc721ProxyData.tokenAddress,
erc721ProxyData.tokenId,
);
- const allowance = isProxyApproved || isProxyApprovedForAllAsync ? new BigNumber(1) : new BigNumber(0);
+ const allowance = isProxyApproved ? new BigNumber(1) : new BigNumber(0);
return allowance;
}
default:
diff --git a/packages/contracts/src/utils/core_combinatorial_utils.ts b/packages/contracts/src/utils/core_combinatorial_utils.ts
index f1a5599ef..7e9d18e46 100644
--- a/packages/contracts/src/utils/core_combinatorial_utils.ts
+++ b/packages/contracts/src/utils/core_combinatorial_utils.ts
@@ -630,6 +630,14 @@ export class CoreCombinatorialUtils {
);
break;
+ case AllowanceAmountScenario.Unlimited:
+ await this.assetWrapper.setProxyAllowanceAsync(
+ signedOrder.makerAddress,
+ signedOrder.makerAssetData,
+ constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ );
+ break;
+
default:
throw errorUtils.spawnSwitchErr(
'makerStateScenario.traderAssetAllowance',
@@ -659,6 +667,14 @@ export class CoreCombinatorialUtils {
);
break;
+ case AllowanceAmountScenario.Unlimited:
+ await this.assetWrapper.setProxyAllowanceAsync(
+ signedOrder.makerAddress,
+ this.zrxAssetData,
+ constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ );
+ break;
+
default:
throw errorUtils.spawnSwitchErr(
'makerStateScenario.zrxFeeAllowance',
@@ -738,6 +754,14 @@ export class CoreCombinatorialUtils {
);
break;
+ case AllowanceAmountScenario.Unlimited:
+ await this.assetWrapper.setProxyAllowanceAsync(
+ this.takerAddress,
+ signedOrder.takerAssetData,
+ constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ );
+ break;
+
default:
throw errorUtils.spawnSwitchErr(
'takerStateScenario.traderAssetAllowance',
@@ -767,6 +791,14 @@ export class CoreCombinatorialUtils {
);
break;
+ case AllowanceAmountScenario.Unlimited:
+ await this.assetWrapper.setProxyAllowanceAsync(
+ signedOrder.takerAddress,
+ this.zrxAssetData,
+ constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ );
+ break;
+
default:
throw errorUtils.spawnSwitchErr(
'takerStateScenario.zrxFeeAllowance',
diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts
index 0b419d672..7d9217c50 100644
--- a/packages/contracts/src/utils/types.ts
+++ b/packages/contracts/src/utils/types.ts
@@ -211,6 +211,7 @@ export enum AllowanceAmountScenario {
Exact = 'EXACT',
TooLow = 'TOO_LOW',
Higher = 'HIGHER',
+ Unlimited = 'UNLIMITED',
}
export interface TraderStateScenario {
diff --git a/packages/contracts/test/exchange/fill_order.ts b/packages/contracts/test/exchange/fill_order.ts
index dc1dee91f..56d7510f4 100644
--- a/packages/contracts/test/exchange/fill_order.ts
+++ b/packages/contracts/test/exchange/fill_order.ts
@@ -228,7 +228,7 @@ describe('FillOrder Tests', () => {
},
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount,
};
- await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario);
+ await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario, true);
});
it('should successfully fill order when makerAsset is ERC20 and takerAsset is ERC721', async () => {
@@ -243,5 +243,43 @@ describe('FillOrder Tests', () => {
};
await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario);
});
+
+ it('should successfully fill order when makerAsset is ERC721 and approveAll is set for it', async () => {
+ const fillScenario = {
+ ...defaultFillScenario,
+ orderScenario: {
+ ...defaultFillScenario.orderScenario,
+ makerAssetDataScenario: AssetDataScenario.ERC721,
+ takerAssetDataScenario: AssetDataScenario.ERC20NonZRXEighteenDecimals,
+ },
+ takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount,
+ makerStateScenario: {
+ ...defaultFillScenario.makerStateScenario,
+ traderAssetAllowance: AllowanceAmountScenario.Unlimited,
+ },
+ };
+ await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario);
+ });
+
+ it('should successfully fill order when makerAsset and takerAsset are ERC721 and approveAll is set for them', async () => {
+ const fillScenario = {
+ ...defaultFillScenario,
+ orderScenario: {
+ ...defaultFillScenario.orderScenario,
+ makerAssetDataScenario: AssetDataScenario.ERC721,
+ takerAssetDataScenario: AssetDataScenario.ERC721,
+ },
+ takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount,
+ makerStateScenario: {
+ ...defaultFillScenario.makerStateScenario,
+ traderAssetAllowance: AllowanceAmountScenario.Unlimited,
+ },
+ takerStateScenario: {
+ ...defaultFillScenario.takerStateScenario,
+ traderAssetAllowance: AllowanceAmountScenario.Unlimited,
+ },
+ };
+ await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario);
+ });
});
});