How to use the @0x/json-schemas.schemas.orderSchema 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 / signature_utils.ts View on Github external
async ecSignOrderAsync(
        supportedProvider: SupportedProvider,
        order: Order,
        signerAddress: string,
    ): Promise {
        assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
        try {
            const signedOrder = await signatureUtils.ecSignTypedDataOrderAsync(supportedProvider, order, signerAddress);
            return signedOrder;
        } catch (err) {
            // HACK: We are unable to handle specific errors thrown since provider is not an object
            //       under our control. It could be Metamask Web3, Ethers, or any general RPC provider.
            //       We check for a user denying the signature request in a way that supports Metamask and
            //       Coinbase Wallet. Unfortunately for signers with a different error message,
            //       they will receive two signature requests.
            if (err.message.includes('User denied message signature')) {
                throw err;
            }
            const orderHash = await orderHashUtils.getOrderHashAsync(order);
            const signatureHex = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, signerAddress);
            const signedOrder = {
                ...order,
github 0xProject / 0x-monorepo / contracts / test-utils / src / order_hash.ts View on Github external
getOrderHashHex(order: SignedOrder | Order): string {
        try {
            assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
        } catch (error) {
            if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
                const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${NULL_ADDRESS}`;
                throw new Error(errMsg);
            }
            throw error;
        }

        const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
        const orderHashHex = `0x${orderHashBuff.toString('hex')}`;
        return orderHashHex;
    },
    /**
github 0xProject / 0x-monorepo / packages / order-utils / src / rate_utils.ts View on Github external
getFeeAdjustedRateOfFeeOrder(feeOrder: Order): BigNumber {
        assert.doesConformToSchema('feeOrder', feeOrder, schemas.orderSchema);
        const zrxAmountAfterFees = feeOrder.makerAssetAmount.minus(feeOrder.takerFee);
        assert.assert(
            zrxAmountAfterFees.isGreaterThan(constants.ZERO_AMOUNT),
            `Expected takerFee: ${JSON.stringify(feeOrder.takerFee)} to be less than makerAssetAmount: ${JSON.stringify(
                feeOrder.makerAssetAmount,
            )}`,
        );
        const rate = feeOrder.takerAssetAmount.div(zrxAmountAfterFees);
        return rate;
    },
};
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / utils / transaction_encoder.ts View on Github external
public cancelOrderTx(order: Order | SignedOrder): string {
        assert.doesConformToSchema('order', order, schemas.orderSchema);
        const abiEncodedData = this._getExchangeContract().cancelOrder.getABIEncodedTransactionData(order);
        return abiEncodedData;
    }
    /**
github 0xProject / 0x-monorepo / contracts / coordinator / src / client / index.ts View on Github external
public async fillOrKillOrderAsync(
        order: Order,
        takerAssetFillAmount: BigNumber,
        signature: string,
        txData: TxData,
        sendTxOpts: Partial = { shouldValidate: true },
    ): Promise {
        assert.doesConformToSchema('order', order, schemas.orderSchema);
        assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
        return this._executeTxThroughCoordinatorAsync(
            ExchangeFunctionName.FillOrKillOrder,
            txData,
            sendTxOpts,
            [order],
            order,
            takerAssetFillAmount,
            signature,
        );
    }
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / utils / transaction_encoder.ts View on Github external
public matchOrdersTx(leftOrder: SignedOrder, rightOrder: SignedOrder): string {
        assert.doesConformToSchema('leftOrder', leftOrder, schemas.orderSchema);
        assert.doesConformToSchema('rightOrder', rightOrder, schemas.orderSchema);
        const abiEncodedData = this._getExchangeContract().matchOrders.getABIEncodedTransactionData(
            leftOrder,
            rightOrder,
            leftOrder.signature,
            rightOrder.signature,
        );
        return abiEncodedData;
    }
    /**
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
public async cancelOrderAsync(
        order: Order | SignedOrder,
        orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
    ): Promise {
        assert.doesConformToSchema('order', order, schemas.orderSchema);
        await assert.isSenderAddressAsync('order.maker', order.makerAddress, this._web3Wrapper);
        assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
        const normalizedMakerAddress = order.makerAddress.toLowerCase();

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