How to use @0x/contract-addresses - 10 common examples

To help you get started, we’ve selected a few @0x/contract-addresses examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / testnet-faucets / src / ts / handler.ts View on Github external
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
github 0xProject / 0x-monorepo / packages / migrations / src / testnet_migrations.ts View on Github external
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,
github 0xProject / 0x-monorepo / packages / migrations / src / utils / timelocks.ts View on Github external
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,
        },
        {
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_erc20_events.ts View on Github external
interface Token {
    // name is used for logging only.
    name: string;
    address: string;
    defaultStartBlock: number;
}

const tokensToGetApprovalEvents: Token[] = [
    {
        name: 'WETH',
        address: getContractAddressesForNetworkOrThrow(NETWORK_ID).etherToken,
        defaultStartBlock: 4719568, // Block when the WETH contract was deployed.
    },
    {
        name: 'ZRX',
        address: getContractAddressesForNetworkOrThrow(NETWORK_ID).zrxToken,
        defaultStartBlock: 4145415, // Block when the ZRX contract was deployed.
    },
    {
        name: 'DAI',
        address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
        defaultStartBlock: 4752008, // Block when the DAI contract was deployed.
    },
];

(async () => {
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: INFURA_ROOT_URL,
    });
    const endBlock = await calculateEndBlockAsync(provider);
    for (const token of tokensToGetApprovalEvents) {
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / utils / zeroex_transaction_decoder.ts View on Github external
_.each(NetworkId, (networkId: any) => {
            if (typeof networkId !== 'number') {
                return;
            }
            const contractAddressesForNetwork = getContractAddressesForNetworkOrThrow(networkId);
            _.each(contractAddressesForNetwork, (contractAddress: string, contractName: string) => {
                const contractNameLowercase = _.toLower(contractName);
                if (_.isUndefined(deployedContractInfoByName[contractNameLowercase])) {
                    deployedContractInfoByName[contractNameLowercase] = [];
                }
                deployedContractInfoByName[contractNameLowercase].push({
                    contractAddress,
                    networkId,
                });
            });
        });
        // Load contract artifacts
github 0xProject / 0x-monorepo / packages / migrations / src / test_contract_configs.ts View on Github external
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);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_exchange_transactions_from_etherscan.ts View on Github external
(async () => {
    const apiKey = process.env.ETHERSCAN_API_KEY;
    if (apiKey === undefined) {
        throw new Error('Missing required env var: ETHERSCAN_API_KEY');
    }
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: INFURA_ROOT_URL,
    });
    const EtherscanTransactionRepository = connection.getRepository(EtherscanTransaction);
    const startBlock = await getStartBlockAsync(EtherscanTransactionRepository);
    logUtils.log(`Start block: ${startBlock}`);
    const endBlock = await calculateEndBlockAsync(provider);
    logUtils.log(`End block: ${endBlock}`);
    const etherscanSource = new EtherscanSource(apiKey, startBlock, endBlock);
    const exchangeContractAddress = getContractAddressesForNetworkOrThrow(NetworkId.Mainnet).exchange;
    logUtils.log('Fetching exchange transactions from Etherscan...');
    const rawTransactions = await etherscanSource.getEtherscanTransactionsForAddressAsync(exchangeContractAddress);
    const transactions = parseEtherscanTransactions(rawTransactions);
    logUtils.log(`Saving ${transactions.length} records to database`);
    await EtherscanTransactionRepository.save(transactions, {
        chunk: Math.ceil(transactions.length / BATCH_SAVE_SIZE),
    });
    logUtils.log('Done');
    process.exit(0);
})().catch(handleError);
github 0xProject / 0x-coordinator-server / ts / src / handlers.ts View on Github external
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,
            );
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / utils / contract_addresses.ts View on Github external
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);
}
github 0xProject / 0x-coordinator-server / ts / src / handlers.ts View on Github external
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:

@0x/contract-addresses

Used to get known addresses of deployed 0x contracts

Apache-2.0
Latest version published 6 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages