How to use the @0x/json-schemas.schemas.ordersSchema function in @0x/json-schemas

To help you get started, we’ve selected a few @0x/json-schemas 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 / order-utils / src / market_utils.ts View on Github external
function findOrdersThatCoverAssetFillAmount(
    orders: T[],
    assetFillAmount: BigNumber,
    operation: MarketOperation,
    opts?: FindOrdersThatCoverTakerAssetFillAmountOpts | FindOrdersThatCoverMakerAssetFillAmountOpts,
): OrdersAndRemainingTakerFillAmount | OrdersAndRemainingMakerFillAmount {
    const variablePrefix = operation === MarketOperation.Buy ? 'Maker' : 'Taker';
    assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
    assert.isValidBaseUnitAmount('assetFillAmount', assetFillAmount);
    // try to get remainingFillableTakerAssetAmounts from opts, if it's not there, use takerAssetAmount values from orders
    const remainingFillableAssetAmounts = _.get(
        opts,
        `remainingFillable${variablePrefix}AssetAmounts`,
        _.map(orders, order => (operation === MarketOperation.Buy ? order.makerAssetAmount : order.takerAssetAmount)),
    ) as BigNumber[];
    _.forEach(remainingFillableAssetAmounts, (amount, index) =>
        assert.isValidBaseUnitAmount(`remainingFillable${variablePrefix}AssetAmount[${index}]`, amount),
    );
    assert.assert(
        orders.length === remainingFillableAssetAmounts.length,
        `Expected orders.length to equal opts.remainingFillable${variablePrefix}AssetAmounts.length`,
    );
    // try to get slippageBufferAmount from opts, if it's not there, default to 0
    const slippageBufferAmount = _.get(opts, 'slippageBufferAmount', constants.ZERO_AMOUNT) as BigNumber;
github 0xProject / 0x-monorepo / contracts / coordinator / src / client / index.ts View on Github external
private async _batchFillAsync(
        exchangeFn: ExchangeFunctionName,
        orders: Order[],
        takerAssetFillAmounts: BigNumber[],
        signatures: string[],
        txData: TxData,
        sendTxOpts: SendTransactionOpts = { shouldValidate: true },
    ): Promise {
        assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
        takerAssetFillAmounts.forEach(takerAssetFillAmount =>
            assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount),
        );
        return this._executeTxThroughCoordinatorAsync(
            exchangeFn,
            txData,
            sendTxOpts,
            orders,
            orders,
            takerAssetFillAmounts,
            signatures,
        );
    }
github 0xProject / 0x-monorepo / packages / order-utils / src / sorting_utils.ts View on Github external
sortFeeOrdersByFeeAdjustedRate(feeOrders: T[]): T[] {
        assert.doesConformToSchema('feeOrders', feeOrders, schemas.ordersSchema);
        const rateCalculator = rateUtils.getFeeAdjustedRateOfFeeOrder.bind(rateUtils);
        const sortedOrders = sortOrders(feeOrders, rateCalculator);
        return sortedOrders;
    },
};
github 0xProject / 0x-monorepo / packages / order-utils / src / sorting_utils.ts View on Github external
sortOrdersByFeeAdjustedRate(orders: T[], feeRate: BigNumber = constants.ZERO_AMOUNT): T[] {
        assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
        assert.isBigNumber('feeRate', feeRate);
        const rateCalculator = (order: Order) => rateUtils.getFeeAdjustedRateOfOrder(order, feeRate);
        const sortedOrders = sortOrders(orders, rateCalculator);
        return sortedOrders;
    },
    /**
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
public async batchCancelOrdersAsync(
        orders: Array,
        orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
    ): Promise {
        assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
        assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
        const makerAddresses = _.map(orders, order => order.makerAddress);
        const makerAddress = makerAddresses[0];
        await assert.isSenderAddressAsync('makerAddress', makerAddress, this._web3Wrapper);
        const normalizedMakerAddress = makerAddress.toLowerCase();

        if (orderTransactionOpts.shouldValidate) {
            await this._exchangeContract.batchCancelOrders.callAsync(orders, {
                from: normalizedMakerAddress,
                gas: orderTransactionOpts.gasLimit,
                gasPrice: orderTransactionOpts.gasPrice,
                nonce: orderTransactionOpts.nonce,
            });
        }
        const txHash = await this._exchangeContract.batchCancelOrders.sendTransactionAsync(orders, {
            from: normalizedMakerAddress,