How to use the @0x/utils.AbiEncoder.create function in @0x/utils

To help you get started, we’ve selected a few @0x/utils 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 / migrations / src / testnet_migrations.ts View on Github external
},
        {
            destination: deployedAddresses.erc1155Proxy,
            data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
        },
        {
            destination: deployedAddresses.multiAssetProxy,
            data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
        },
        {
            destination: deployedAddresses.multiAssetProxy,
            data: exchange.registerAssetProxy(erc20BridgeProxy.address).getABIEncodedTransactionData(),
        },
    ];

    const batchTransactionEncoder = AbiEncoder.create('(bytes[],address[],uint256[])');
    const batchTransactionData = batchTransactionEncoder.encode([
        functionCalls.map(item => item.data),
        functionCalls.map(item => item.destination),
        functionCalls.map(() => constants.ZERO_AMOUNT),
    ]);
    await submitAndExecuteTransactionAsync(governor, governor.address, batchTransactionData);

    await DevUtilsContract.deployFrom0xArtifactAsync(
        devUtilsArtifacts.DevUtils,
        provider,
        txDefaults,
        devUtilsArtifacts,
        exchange.address,
    );

    await CoordinatorContract.deployFrom0xArtifactAsync(
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / market_operation_utils / create_order.ts View on Github external
function createBridgeData(tokenAddress: string): string {
    const encoder = AbiEncoder.create([{ name: 'tokenAddress', type: 'address' }]);
    return encoder.encode({ tokenAddress });
}
github 0xProject / 0x-monorepo / contracts / asset-proxy / src / dydx_bridge_encoder.ts View on Github external
}

export interface DydxBrigeAction {
    actionType: DydxBridgeActionType;
    accountId: BigNumber;
    marketId: BigNumber;
    conversionRateNumerator: BigNumber;
    conversionRateDenominator: BigNumber;
}

export interface DydxBridgeData {
    accountNumbers: BigNumber[];
    actions: DydxBrigeAction[];
}

export const dydxBridgeDataEncoder = AbiEncoder.create([
    {
        name: 'bridgeData',
        type: 'tuple',
        components: [
            { name: 'accountNumbers', type: 'uint256[]' },
            {
                name: 'actions',
                type: 'tuple[]',
                components: [
                    { name: 'actionType', type: 'uint8' },
                    { name: 'accountId', type: 'uint256' },
                    { name: 'marketId', type: 'uint256' },
                    { name: 'conversionRateNumerator', type: 'uint256' },
                    { name: 'conversionRateDenominator', type: 'uint256' },
                ],
            },
github 0xProject / 0x-monorepo / packages / base-contract / src / index.ts View on Github external
public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): string {
        const abiEncoder = AbiEncoder.create(inputAbi);
        const params = abiUtils.parseEthersParams(inputAbi);
        const rawEncoded = abiEncoder.encode(args);
        const rawDecoded = abiEncoder.decodeAsArray(rawEncoded);
        for (let i = 0; i < rawDecoded.length; i++) {
            const original = args[i];
            const decoded = rawDecoded[i];
            if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) {
                throw new Error(
                    `Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
                        params.types[i]
                    }. (Possible type overflow or other encoding error)`,
                );
            }
        }
        return rawEncoded;
    }