Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.callAsync();
const fromTokens = _.get(this.balances.erc721, [fromAddress, tokenAddress], []);
const toTokens = _.get(this.balances.erc721, [toAddress, tokenAddress], []);
if (amount.gte(1)) {
const tokenIndex = _.findIndex(fromTokens as BigNumber[], t => t.eq(tokenId));
if (tokenIndex !== -1) {
fromTokens.splice(tokenIndex, 1);
toTokens.push(tokenId);
toTokens.sort();
}
}
_.set(this.balances.erc721, [fromAddress, tokenAddress], fromTokens);
_.set(this.balances.erc721, [toAddress, tokenAddress], toTokens);
break;
}
case AssetProxyId.ERC1155: {
const [
_proxyId, // tslint:disable-line:no-unused-variable
tokenAddress,
tokenIds,
tokenValues,
] = await this._devUtils.decodeERC1155AssetData(assetData).callAsync();
const fromBalances = {
// tslint:disable-next-line:no-inferred-empty-object-type
fungible: _.get(this.balances.erc1155, [fromAddress, tokenAddress, 'fungible'], {}),
nonFungible: _.get(this.balances.erc1155, [fromAddress, tokenAddress, 'nonFungible'], []),
};
const toBalances = {
// tslint:disable-next-line:no-inferred-empty-object-type
fungible: _.get(this.balances.erc1155, [toAddress, tokenAddress, 'fungible'], {}),
nonFungible: _.get(this.balances.erc1155, [toAddress, tokenAddress, 'nonFungible'], []),
};
public async transferFromAsync(
assetData: string,
from: string,
to: string,
amountInBaseUnits: BigNumber,
tradeSide: TradeSide,
transferType: TransferType,
): Promise {
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC1155:
case AssetProxyId.ERC20:
case AssetProxyId.ERC721: {
// HACK: When simulating an open order (e.g taker is NULL_ADDRESS), we don't want to adjust balances/
// allowances for the taker. We do however, want to increase the balance of the maker since the maker
// might be relying on those funds to fill subsequent orders or pay the order's fees.
if (from === constants.NULL_ADDRESS && tradeSide === TradeSide.Taker) {
await this._increaseBalanceAsync(assetData, to, amountInBaseUnits);
return;
}
const balance = await this._store.getBalanceAsync(assetData, from);
const proxyAllowance = await this._store.getProxyAllowanceAsync(assetData, from);
if (proxyAllowance.isLessThan(amountInBaseUnits)) {
ExchangeTransferSimulator._throwValidationError(
FailureReason.ProxyAllowance,
tradeSide,
transferType,
const registeredERC20ProxyInMAP = await multiAssetProxy.getAssetProxy(AssetProxyId.ERC20).callAsync();
warnIfMismatch(
registeredERC20ProxyInMAP,
erc20Proxy.address,
'Unexpected ERC20Proxy registered in MultiAssetProxy',
);
const registeredERC721ProxyInMAP = await multiAssetProxy.getAssetProxy(AssetProxyId.ERC721).callAsync();
warnIfMismatch(
registeredERC721ProxyInMAP,
erc721Proxy.address,
'Unexpected ERC721Proxy registered in MultiAssetProxy',
);
const registeredERC1155ProxyInMAP = await multiAssetProxy.getAssetProxy(AssetProxyId.ERC1155).callAsync();
warnIfMismatch(
registeredERC1155ProxyInMAP,
erc1155Proxy.address,
'Unexpected ERC1155Proxy registered in MultiAssetProxy',
);
const registeredStaticCallProxyInMAP = await multiAssetProxy.getAssetProxy(AssetProxyId.StaticCall).callAsync();
warnIfMismatch(
registeredStaticCallProxyInMAP,
addresses.staticCallProxy,
'Unexpected StaticCallProxy registered in MultiAssetProxy',
);
const registeredERC20BridgeProxyInMAP = await multiAssetProxy
.getAssetProxy(AssetProxyId.ERC20Bridge)
.callAsync();
async function verifyExchangeV2ConfigsAsync(): Promise {
const exchangeOwner = await exchangeV2.owner().callAsync();
warnIfMismatch(exchangeOwner, governor.address, 'Unexpected ExchangeV2 owner');
const registeredERC20Proxy = await exchangeV2.getAssetProxy(AssetProxyId.ERC20).callAsync();
warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in ExchangeV2');
const registeredERC721Proxy = await exchangeV2.getAssetProxy(AssetProxyId.ERC721).callAsync();
warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in ExchangeV2');
const registeredERC1155Proxy = await exchangeV2.getAssetProxy(AssetProxyId.ERC1155).callAsync();
warnIfMismatch(
registeredERC1155Proxy,
erc1155Proxy.address,
'Unexpected ERC1155Proxy registered in ExchangeV2',
);
const registeredMultiAssetProxy = await exchangeV2.getAssetProxy(AssetProxyId.MultiAsset).callAsync();
warnIfMismatch(
registeredMultiAssetProxy,
multiAssetProxy.address,
'Unexpected MultiAssetProxy registered in ExchangeV2',
);
const registeredStaticCallProxy = await exchangeV2.getAssetProxy(AssetProxyId.StaticCall).callAsync();
warnIfMismatch(
registeredStaticCallProxy,
bridgeAddress,
bridgeData,
};
}
case AssetProxyId.ERC721: {
const [tokenAddress, tokenId] = assetDataEncoder.getABIDecodedTransactionData<[string, BigNumber]>(
'ERC721Token',
assetData,
);
return {
assetProxyId,
tokenAddress,
tokenId,
};
}
case AssetProxyId.ERC1155: {
const [
tokenAddress,
tokenIds,
tokenValues,
callbackData,
] = assetDataEncoder.getABIDecodedTransactionData<[string, BigNumber[], BigNumber[], string]>(
'ERC1155Assets',
assetData,
);
return {
assetProxyId,
tokenAddress,
tokenIds,
tokenValues,
callbackData,
};