Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): Promise {
if (fromAddress === toAddress) {
return;
}
const assetProxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
switch (assetProxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unused-variable
const [_proxyId, tokenAddress] = await this._devUtils.decodeERC20AssetData(assetData).callAsync();
_.update(this.balances.erc20, [fromAddress, tokenAddress], balance => balance.minus(amount));
_.update(this.balances.erc20, [toAddress, tokenAddress], balance =>
(balance || constants.ZERO_AMOUNT).plus(amount),
);
break;
}
case AssetProxyId.ERC721: {
// tslint:disable-next-line:no-unused-variable
const [_proxyId, tokenAddress, tokenId] = await this._devUtils
.decodeERC721AssetData(assetData)
.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);
if (newState && newState.zeroExInstantShowing) {
// We have returned to a history state that expects instant to be rendered.
if (!isInstantRendered()) {
removeInstant = renderInstant(coercedConfig, selector);
}
} else {
// History has changed to a different state.
if (isInstantRendered()) {
removeInstant();
}
}
};
window.onpopstate = onPopStateHandler;
};
export const ERC721_PROXY_ID = AssetProxyId.ERC721;
export const ERC20_PROXY_ID = AssetProxyId.ERC20;
export const assetDataForERC20TokenAddress = (tokenAddress: string): string => {
assert.isETHAddressHex('tokenAddress', tokenAddress);
return assetDataEncoder.ERC20Token(tokenAddress).getABIEncodedTransactionData();
};
export const assetDataForERC721TokenAddress = (tokenAddress: string, tokenId: string | number): string => {
assert.isETHAddressHex('tokenAddress', tokenAddress);
return assetDataEncoder.ERC721Token(tokenAddress, new BigNumber(tokenId)).getABIEncodedTransactionData();
};
export const hasMetaDataForAssetData = (assetData: string): boolean => {
assert.isHexString('assetData', assetData);
return assetMetaDataMap[assetData] !== undefined;
async function verifyExchangeV3ConfigsAsync(): Promise {
const exchangeOwner = await exchange.owner().callAsync();
warnIfMismatch(exchangeOwner, governor.address, 'Unexpected Exchange owner');
const registeredERC20Proxy = await exchange.getAssetProxy(AssetProxyId.ERC20).callAsync();
warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in Exchange');
const registeredERC721Proxy = await exchange.getAssetProxy(AssetProxyId.ERC721).callAsync();
warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in Exchange');
const registeredERC1155Proxy = await exchange.getAssetProxy(AssetProxyId.ERC1155).callAsync();
warnIfMismatch(registeredERC1155Proxy, erc1155Proxy.address, 'Unexpected ERC1155Proxy registered in Exchange');
const registeredMultiAssetProxy = await exchange.getAssetProxy(AssetProxyId.MultiAsset).callAsync();
warnIfMismatch(
registeredMultiAssetProxy,
multiAssetProxy.address,
'Unexpected MultiAssetProxy registered in Exchange',
);
const registeredStaticCallProxy = await exchange.getAssetProxy(AssetProxyId.StaticCall).callAsync();
warnIfMismatch(
registeredStaticCallProxy,
addresses.staticCallProxy,
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',
);
bestNameForAsset: (asset?: Asset, defaultName: string = DEFAULT_UNKOWN_ASSET_NAME): string => {
if (asset === undefined) {
return defaultName;
}
const metaData = asset.metaData;
switch (metaData.assetProxyId) {
case AssetProxyId.ERC20:
return metaData.symbol.toUpperCase();
case AssetProxyId.ERC721:
return metaData.name;
}
},
formattedSymbolForAsset: (asset?: ERC20Asset, defaultName: string = '???'): string => {
isValidAssetMetaData(variableName: string, metaData: AssetMetaData): void {
assert.isHexString(`${variableName}.assetProxyId`, metaData.assetProxyId);
if (metaData.primaryColor !== undefined) {
assert.isString(`${variableName}.primaryColor`, metaData.primaryColor);
}
if (metaData.assetProxyId === AssetProxyId.ERC20) {
assert.isNumber(`${variableName}.decimals`, metaData.decimals);
assert.isString(`${variableName}.symbol`, metaData.symbol);
} else if (metaData.assetProxyId === AssetProxyId.ERC721) {
assert.isString(`${variableName}.name`, metaData.name);
assert.isUri(`${variableName}.imageUrl`, metaData.imageUrl);
}
},
isValidAffiliateInfo(variableName: string, affiliateInfo: AffiliateInfo): void {
private _deleteLazyStoreBalance(assetData: string, userAddress: string): void {
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
case AssetProxyId.ERC721:
this._balanceAndProxyAllowanceLazyStore.deleteBalance(assetData, userAddress);
break;
case AssetProxyId.MultiAsset:
const decodedAssetData = assetDataUtils.decodeMultiAssetData(assetData);
_.each(decodedAssetData.nestedAssetData, nestedAssetDataElement =>
this._deleteLazyStoreBalance(nestedAssetDataElement, userAddress),
);
break;
default:
break;
}
}
private _deleteLazyStoreProxyAllowance(assetData: string, userAddress: string): void {
assertIsERC721AssetData(assetData: string): void {
if (assetData.length < constants.ERC721_ASSET_DATA_MIN_CHAR_LENGTH_WITH_PREFIX) {
throw new Error(
`Could not decode ERC721 assetData. Expected length of encoded data to be at least ${
constants.ERC721_ASSET_DATA_MIN_CHAR_LENGTH_WITH_PREFIX
}. Got ${assetData.length}`,
);
}
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
if (assetProxyId !== AssetProxyId.ERC721) {
throw new Error(
`Could not decode ERC721 assetData. Expected assetProxyId to be ERC721 (${
AssetProxyId.ERC721
}), but got ${assetProxyId}`,
);
}
},
/**
assetProxyId,
tokenAddress,
};
}
case AssetProxyId.ERC20Bridge: {
const [tokenAddress, bridgeAddress, bridgeData] = assetDataEncoder.getABIDecodedTransactionData<
[string, string, string]
>('ERC20Bridge', assetData);
return {
assetProxyId,
tokenAddress,
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,
export function convertAssetProxyIdToType(assetProxyId: AssetProxyId): AssetType {
switch (assetProxyId) {
case AssetProxyId.ERC20:
return AssetType.ERC20;
case AssetProxyId.ERC721:
return AssetType.ERC721;
case AssetProxyId.MultiAsset:
return AssetType.MultiAsset;
default:
throw new Error(`${assetProxyId} not a supported assetProxyId`);
}
}