Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makerTokenIfExists = _.get(TOKENS_BY_CHAIN, [chainConfig.chainId, requestedAssetType]);
if (makerTokenIfExists === undefined) {
throw new Error(`Unsupported asset type: ${requestedAssetType}`);
}
const takerTokenSymbol =
requestedAssetType === RequestedAssetType.WETH ? RequestedAssetType.ZRX : RequestedAssetType.WETH;
const takerTokenIfExists = _.get(TOKENS_BY_CHAIN, [chainConfig.chainId, takerTokenSymbol]);
if (takerTokenIfExists === undefined) {
throw new Error(`Unsupported asset type: ${takerTokenSymbol}`);
}
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(ASSET_AMOUNT, makerTokenIfExists.decimals);
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(ASSET_AMOUNT, takerTokenIfExists.decimals);
const makerAssetData = assetDataUtils.encodeERC20AssetData(makerTokenIfExists.address);
const takerAssetData = assetDataUtils.encodeERC20AssetData(takerTokenIfExists.address);
const contractAddresses = getContractAddressesForChainOrThrow(chainConfig.chainId);
const order: Order = {
makerAddress: configs.DISPENSER_ADDRESS,
takerAddress: req.params.recipient as string,
makerFee: ZERO,
takerFee: ZERO,
makerAssetAmount,
takerAssetAmount,
makerAssetData,
takerAssetData,
salt: generatePseudoRandomSalt(),
makerFeeAssetData: makerAssetData,
takerFeeAssetData: takerAssetData,
feeRecipientAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
expirationTimeSeconds: new BigNumber(Date.now() + FIVE_DAYS_IN_MS)
// tslint:disable-next-line:custom-no-magic-numbers
export async function runMigrationsAsync(supportedProvider: SupportedProvider, txDefaults: TxData): Promise {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const chainId = new BigNumber(await providerUtils.getChainIdAsync(provider));
const deployedAddresses = getContractAddressesForChainOrThrow(chainId.toNumber());
const configs = getConfigsByChainId(chainId.toNumber());
// NOTE: This must be deployed before running these migrations, since its address is hard coded in the
// staking logic contract.
const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults);
const stakingLogic = await StakingContract.deployFrom0xArtifactAsync(
stakingArtifacts.Staking,
provider,
txDefaults,
stakingArtifacts,
);
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
exchangeArtifacts.Exchange,
provider,
export async function getTimelockRegistrationsAsync(provider: SupportedProvider): Promise {
const web3Wrapper = new Web3Wrapper(provider);
const chainId = await web3Wrapper.getChainIdAsync();
const deployedAddresses = getContractAddressesForChainOrThrow(chainId);
const authorizableInterface = new IAuthorizableContract(constants.NULL_ADDRESS, provider);
const ownableInterface = new IOwnableContract(constants.NULL_ADDRESS, provider);
const zrxVault = new ZrxVaultContract(constants.NULL_ADDRESS, provider);
const stakingProxy = new StakingProxyContract(constants.NULL_ADDRESS, provider);
const exchange = new ExchangeContract(constants.NULL_ADDRESS, provider);
const stakingLogic = new StakingContract(constants.NULL_ADDRESS, provider);
const noTimelockRegistrations = [
// AssetProxy timelocks
{
destination: deployedAddresses.erc20Proxy,
functionSelector: authorizableInterface.getSelector('removeAuthorizedAddress'),
secondsTimeLocked: constants.ZERO_AMOUNT,
},
{
async function testContractConfigsAsync(provider: SupportedProvider): Promise {
const web3Wrapper = new Web3Wrapper(provider);
const chainId = await web3Wrapper.getChainIdAsync();
const addresses = getContractAddressesForChainOrThrow(chainId);
const configs = getConfigsByChainId(chainId);
function warnIfMismatch(actual: any, expected: any, message: string): void {
if (actual !== expected) {
logUtils.warn(`${message}: actual: ${actual}, expected: ${expected}, chainId: ${chainId}`);
}
}
const exchange = new ExchangeContract(addresses.exchange, provider);
const exchangeV2 = new ExchangeContract(addresses.exchangeV2, provider);
const erc20Proxy = new ERC20ProxyContract(addresses.erc20Proxy, provider);
const erc721Proxy = new ERC721ProxyContract(addresses.erc721Proxy, provider);
const erc1155Proxy = new ERC1155ProxyContract(addresses.erc1155Proxy, provider);
const multiAssetProxy = new MultiAssetProxyContract(addresses.multiAssetProxy, provider);
const erc20BridgeProxy = new ERC20ProxyContract(addresses.erc20BridgeProxy, provider);
const governor = new ZeroExGovernorContract(addresses.zeroExGovernor, provider);
private async _extractTakerAssetFillAmountsFromMarketSellOrdersAsync(
decodedCalldata: DecodedCalldata,
takerAddress: string,
chainId: number,
): Promise {
const takerAssetFillAmounts: BigNumber[] = [];
const contractAddresses = getContractAddressesForChainOrThrow(chainId);
const signedOrders = utils.getSignedOrdersFromOrderWithoutExchangeAddresses(
decodedCalldata.functionArguments.orders,
decodedCalldata.functionArguments.signatures,
contractAddresses.exchange,
);
const batchOrderAndTraderInfo = await this._getBatchOrderAndTraderInfoAsync(
signedOrders,
takerAddress,
chainId,
);
let totalTakerAssetAmount: BigNumber = decodedCalldata.functionArguments.takerAssetFillAmount;
_.each(batchOrderAndTraderInfo, (orderAndTraderInfo: OrderAndTraderInfo, i: number) => {
const remainingFillableTakerAssetAmount = Handlers._calculateRemainingFillableTakerAssetAmount(
signedOrders[i],
orderAndTraderInfo,
);
export function _getDefaultContractAddresses(chainId: number): ContractAddresses {
if (!(chainId in ChainId)) {
throw new Error(
`No default contract addresses found for the given chain id (${chainId}). If you want to use ContractWrappers on this chain, you must manually pass in the contract address(es) to the constructor.`,
);
}
return getContractAddressesForChainOrThrow(chainId);
}
private static _getOrdersFromDecodedCalldata(decodedCalldata: DecodedCalldata, chainId: number): Order[] {
const contractAddresses = getContractAddressesForChainOrThrow(chainId);
switch (decodedCalldata.functionName) {
case ExchangeMethods.FillOrder:
case ExchangeMethods.FillOrKillOrder:
case ExchangeMethods.CancelOrder: {
const orderWithoutExchangeAddress = decodedCalldata.functionArguments.order;
const order = {
...orderWithoutExchangeAddress,
exchangeAddress: contractAddresses.exchange,
chainId,
};
return [order];
}
case ExchangeMethods.BatchFillOrders:
case ExchangeMethods.BatchFillOrKillOrders: