Cherry-pick changes from feat/dev-utils/dydx-bridge-validation
This commit is contained in:
@@ -54,7 +54,7 @@ export function FeeRecipientMixin<TBase extends Constructor>(Base: TBase): TBase
|
||||
if (this.approvalFactory === undefined) {
|
||||
throw new Error('No verifying contract provided in FeeRecipient constructor');
|
||||
}
|
||||
return this.approvalFactory.newSignedApprovalAsync(transaction, txOrigin, signatureType);
|
||||
return this.approvalFactory.newSignedApproval(transaction, txOrigin, signatureType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { encodeERC20AssetData } from '@0x/contracts-asset-proxy';
|
||||
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { constants, OrderFactory } from '@0x/contracts-test-utils';
|
||||
import { Order, SignedOrder } from '@0x/types';
|
||||
@@ -121,9 +122,7 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
||||
makerFeeToken,
|
||||
takerToken,
|
||||
takerFeeToken,
|
||||
].map(token =>
|
||||
this.actor.deployment.assetDataEncoder.ERC20Token(token.address).getABIEncodedTransactionData(),
|
||||
);
|
||||
].map(token => encodeERC20AssetData(token.address));
|
||||
|
||||
// Maker signs the order
|
||||
return this.signOrderAsync({
|
||||
@@ -192,8 +191,7 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
||||
makerFeeAssetData,
|
||||
takerFeeAssetData,
|
||||
] = [leftMakerToken, leftTakerToken, rightMakerToken, rightTakerToken, makerFeeToken, takerFeeToken].map(
|
||||
token =>
|
||||
this.actor.deployment.assetDataEncoder.ERC20Token(token.address).getABIEncodedTransactionData(),
|
||||
token => encodeERC20AssetData(token.address),
|
||||
);
|
||||
|
||||
// Construct and sign the left order
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { encodeERC20AssetData } from '@0x/contracts-asset-proxy';
|
||||
import { increaseCurrentAndNextBalance, OwnerStakeByStatus, StakeStatus } from '@0x/contracts-staking';
|
||||
import { expect } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
@@ -33,7 +34,7 @@ export function validStakeAssertion(
|
||||
txData.from as string,
|
||||
zrxVault.address,
|
||||
amount,
|
||||
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
||||
encodeERC20AssetData(deployment.tokens.zrx.address),
|
||||
);
|
||||
return expectedBalances;
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { encodeERC20AssetData } from '@0x/contracts-asset-proxy';
|
||||
import {
|
||||
decreaseCurrentAndNextBalance,
|
||||
OwnerStakeByStatus,
|
||||
@@ -38,7 +39,7 @@ export function validUnstakeAssertion(
|
||||
zrxVault.address,
|
||||
txData.from as string,
|
||||
amount,
|
||||
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
||||
encodeERC20AssetData(deployment.tokens.zrx.address),
|
||||
);
|
||||
return expectedBalances;
|
||||
},
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
|
||||
import {
|
||||
decodeERC1155AssetData,
|
||||
decodeERC20AssetData,
|
||||
decodeERC20BridgeAssetData,
|
||||
decodeERC721AssetData,
|
||||
decodeMultiAssetData,
|
||||
encodeERC20AssetData,
|
||||
} from '@0x/contracts-asset-proxy';
|
||||
import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||
import { constants, Numberish, provider } from '@0x/contracts-test-utils';
|
||||
import { constants, Numberish } from '@0x/contracts-test-utils';
|
||||
import { AssetProxyId, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, hexUtils } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
@@ -12,8 +19,6 @@ import { BalanceStore } from './balance_store';
|
||||
import { TokenContractsByName, TokenOwnersByName } from './types';
|
||||
|
||||
export class LocalBalanceStore extends BalanceStore {
|
||||
private readonly _assetDataDecoder: IAssetDataContract;
|
||||
|
||||
/**
|
||||
* Creates a new balance store based on an existing one.
|
||||
* @param sourceBalanceStore Existing balance store whose values should be copied.
|
||||
@@ -36,7 +41,6 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
tokenContractsByName: Partial<TokenContractsByName> = {},
|
||||
) {
|
||||
super(tokenOwnersByName, tokenContractsByName);
|
||||
this._assetDataDecoder = new IAssetDataContract(constants.NULL_ADDRESS, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,10 +100,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
const assetProxyId = hexUtils.slice(assetData, 0, 4);
|
||||
switch (assetProxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
const tokenAddress = this._assetDataDecoder.getABIDecodedTransactionData<string>(
|
||||
'ERC20Token',
|
||||
assetData,
|
||||
);
|
||||
const tokenAddress = decodeERC20AssetData(assetData);
|
||||
_.update(this.balances.erc20, [fromAddress, tokenAddress], balance => balance.minus(amount));
|
||||
_.update(this.balances.erc20, [toAddress, tokenAddress], balance =>
|
||||
(balance || constants.ZERO_AMOUNT).plus(amount),
|
||||
@@ -107,10 +108,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
break;
|
||||
}
|
||||
case AssetProxyId.ERC20Bridge: {
|
||||
const [tokenAddress] = this._assetDataDecoder.getABIDecodedTransactionData<[string]>(
|
||||
'ERC20Bridge',
|
||||
assetData,
|
||||
);
|
||||
const [tokenAddress] = decodeERC20BridgeAssetData(assetData);
|
||||
// The test bridge contract (TestEth2DaiBridge or TestUniswapBridge) will be the
|
||||
// fromAddress in this case, and it simply mints the amount of token it needs to transfer.
|
||||
_.update(this.balances.erc20, [fromAddress, tokenAddress], balance =>
|
||||
@@ -122,9 +120,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
break;
|
||||
}
|
||||
case AssetProxyId.ERC721: {
|
||||
const [tokenAddress, tokenId] = this._assetDataDecoder.getABIDecodedTransactionData<
|
||||
[string, BigNumber]
|
||||
>('ERC721Token', assetData);
|
||||
const [tokenAddress, tokenId] = decodeERC721AssetData(assetData);
|
||||
const fromTokens = _.get(this.balances.erc721, [fromAddress, tokenAddress], []);
|
||||
const toTokens = _.get(this.balances.erc721, [toAddress, tokenAddress], []);
|
||||
if (amount.gte(1)) {
|
||||
@@ -140,9 +136,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
break;
|
||||
}
|
||||
case AssetProxyId.ERC1155: {
|
||||
const [tokenAddress, tokenIds, tokenValues] = this._assetDataDecoder.getABIDecodedTransactionData<
|
||||
[string, BigNumber[], BigNumber[]]
|
||||
>('ERC1155Assets', assetData);
|
||||
const [tokenAddress, tokenIds, tokenValues] = decodeERC1155AssetData(assetData);
|
||||
const fromBalances = {
|
||||
// tslint:disable-next-line:no-inferred-empty-object-type
|
||||
fungible: _.get(this.balances.erc1155, [fromAddress, tokenAddress, 'fungible'], {}),
|
||||
@@ -179,9 +173,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
break;
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
const [amounts, nestedAssetData] = this._assetDataDecoder.getABIDecodedTransactionData<
|
||||
[BigNumber[], string[]]
|
||||
>('MultiAsset', assetData);
|
||||
const [amounts, nestedAssetData] = decodeMultiAssetData(assetData);
|
||||
for (const [i, amt] of amounts.entries()) {
|
||||
const nestedAmount = amount.times(amt);
|
||||
this.transferAsset(fromAddress, toAddress, nestedAmount, nestedAssetData[i]);
|
||||
@@ -255,9 +247,7 @@ export class LocalBalanceStore extends BalanceStore {
|
||||
takerAddress,
|
||||
deployment.staking.stakingProxy.address,
|
||||
fillResults.protocolFeePaid,
|
||||
deployment.assetDataEncoder
|
||||
.ERC20Token(deployment.tokens.weth.address)
|
||||
.getABIEncodedTransactionData(),
|
||||
encodeERC20AssetData(deployment.tokens.weth.address),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
ERC20BridgeProxyContract,
|
||||
ERC20ProxyContract,
|
||||
ERC721ProxyContract,
|
||||
IAssetDataContract,
|
||||
MultiAssetProxyContract,
|
||||
StaticCallProxyContract,
|
||||
} from '@0x/contracts-asset-proxy';
|
||||
@@ -204,7 +203,6 @@ export class DeploymentManager {
|
||||
exchange.address,
|
||||
constants.NULL_ADDRESS,
|
||||
);
|
||||
const assetDataEncoder = new IAssetDataContract(constants.NULL_ADDRESS, environment.provider);
|
||||
|
||||
// Construct the new instance and return it.
|
||||
return new DeploymentManager(
|
||||
@@ -218,7 +216,6 @@ export class DeploymentManager {
|
||||
accounts,
|
||||
txDefaults,
|
||||
devUtils,
|
||||
assetDataEncoder,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -534,7 +531,6 @@ export class DeploymentManager {
|
||||
public accounts: string[],
|
||||
public txDefaults: Partial<TxData>,
|
||||
public devUtils: DevUtilsContract,
|
||||
public assetDataEncoder: IAssetDataContract,
|
||||
) {}
|
||||
}
|
||||
// tslint:disable:max-file-line-count
|
||||
|
||||
Reference in New Issue
Block a user