Add support for approveAll in assetWrapper and fillOrderScenarios
This commit is contained in:
		@@ -110,16 +110,20 @@ export class AssetWrapper {
 | 
				
			|||||||
            case constants.ERC721_PROXY_ID: {
 | 
					            case constants.ERC721_PROXY_ID: {
 | 
				
			||||||
                const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
 | 
					                const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
 | 
				
			||||||
                const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
 | 
					                const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
 | 
				
			||||||
                const isProxyApproved = await assetWrapper.isProxyApprovedAsync(
 | 
					                const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
 | 
				
			||||||
                    erc721ProxyData.tokenAddress,
 | 
					 | 
				
			||||||
                    erc721ProxyData.tokenId,
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
                const isProxyApprovedForAllAsync = await assetWrapper.isProxyApprovedForAllAsync(
 | 
					 | 
				
			||||||
                    userAddress,
 | 
					                    userAddress,
 | 
				
			||||||
                    erc721ProxyData.tokenAddress,
 | 
					                    erc721ProxyData.tokenAddress,
 | 
				
			||||||
                    erc721ProxyData.tokenId,
 | 
					                    erc721ProxyData.tokenId,
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
                const allowance = isProxyApproved || isProxyApprovedForAllAsync ? new BigNumber(1) : new BigNumber(0);
 | 
					                if (isProxyApprovedForAll) {
 | 
				
			||||||
 | 
					                    return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                const isProxyApproved = await assetWrapper.isProxyApprovedAsync(
 | 
				
			||||||
 | 
					                    erc721ProxyData.tokenAddress,
 | 
				
			||||||
 | 
					                    erc721ProxyData.tokenId,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                const allowance = isProxyApproved ? new BigNumber(1) : new BigNumber(0);
 | 
				
			||||||
                return allowance;
 | 
					                return allowance;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -630,6 +630,14 @@ export class CoreCombinatorialUtils {
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case AllowanceAmountScenario.Unlimited:
 | 
				
			||||||
 | 
					                await this.assetWrapper.setProxyAllowanceAsync(
 | 
				
			||||||
 | 
					                    signedOrder.makerAddress,
 | 
				
			||||||
 | 
					                    signedOrder.makerAssetData,
 | 
				
			||||||
 | 
					                    constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                throw errorUtils.spawnSwitchErr(
 | 
					                throw errorUtils.spawnSwitchErr(
 | 
				
			||||||
                    'makerStateScenario.traderAssetAllowance',
 | 
					                    'makerStateScenario.traderAssetAllowance',
 | 
				
			||||||
@@ -659,6 +667,14 @@ export class CoreCombinatorialUtils {
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case AllowanceAmountScenario.Unlimited:
 | 
				
			||||||
 | 
					                await this.assetWrapper.setProxyAllowanceAsync(
 | 
				
			||||||
 | 
					                    signedOrder.makerAddress,
 | 
				
			||||||
 | 
					                    this.zrxAssetData,
 | 
				
			||||||
 | 
					                    constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                throw errorUtils.spawnSwitchErr(
 | 
					                throw errorUtils.spawnSwitchErr(
 | 
				
			||||||
                    'makerStateScenario.zrxFeeAllowance',
 | 
					                    'makerStateScenario.zrxFeeAllowance',
 | 
				
			||||||
@@ -738,6 +754,14 @@ export class CoreCombinatorialUtils {
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case AllowanceAmountScenario.Unlimited:
 | 
				
			||||||
 | 
					                await this.assetWrapper.setProxyAllowanceAsync(
 | 
				
			||||||
 | 
					                    this.takerAddress,
 | 
				
			||||||
 | 
					                    signedOrder.takerAssetData,
 | 
				
			||||||
 | 
					                    constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                throw errorUtils.spawnSwitchErr(
 | 
					                throw errorUtils.spawnSwitchErr(
 | 
				
			||||||
                    'takerStateScenario.traderAssetAllowance',
 | 
					                    'takerStateScenario.traderAssetAllowance',
 | 
				
			||||||
@@ -767,6 +791,14 @@ export class CoreCombinatorialUtils {
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case AllowanceAmountScenario.Unlimited:
 | 
				
			||||||
 | 
					                await this.assetWrapper.setProxyAllowanceAsync(
 | 
				
			||||||
 | 
					                    signedOrder.takerAddress,
 | 
				
			||||||
 | 
					                    this.zrxAssetData,
 | 
				
			||||||
 | 
					                    constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                throw errorUtils.spawnSwitchErr(
 | 
					                throw errorUtils.spawnSwitchErr(
 | 
				
			||||||
                    'takerStateScenario.zrxFeeAllowance',
 | 
					                    'takerStateScenario.zrxFeeAllowance',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -211,6 +211,7 @@ export enum AllowanceAmountScenario {
 | 
				
			|||||||
    Exact = 'EXACT',
 | 
					    Exact = 'EXACT',
 | 
				
			||||||
    TooLow = 'TOO_LOW',
 | 
					    TooLow = 'TOO_LOW',
 | 
				
			||||||
    Higher = 'HIGHER',
 | 
					    Higher = 'HIGHER',
 | 
				
			||||||
 | 
					    Unlimited = 'UNLIMITED',
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface TraderStateScenario {
 | 
					export interface TraderStateScenario {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -228,7 +228,7 @@ describe('FillOrder Tests', () => {
 | 
				
			|||||||
                },
 | 
					                },
 | 
				
			||||||
                takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount,
 | 
					                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 () => {
 | 
					        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);
 | 
					            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);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user