How to use the @0x/order-utils.orderHashUtils.getOrderHashHex function in @0x/order-utils

To help you get started, we’ve selected a few @0x/order-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 veilco / veil-js / src / 0x.ts View on Github external
export async function signOrder(
  provider: Provider,
  zeroExOrder: Order
): Promise {
  const orderHash = orderHashUtils.getOrderHashHex({
    ...zeroExOrder,
    expirationTimeSeconds: new BigNumber(zeroExOrder.expirationTimeSeconds),
    makerFee: new BigNumber(zeroExOrder.makerFee),
    makerAssetAmount: new BigNumber(zeroExOrder.makerAssetAmount),
    salt: new BigNumber(zeroExOrder.salt),
    takerFee: new BigNumber(zeroExOrder.takerFee),
    takerAssetAmount: new BigNumber(zeroExOrder.takerAssetAmount)
  });
  const signature = await signatureUtils.ecSignHashAsync(
    provider,
    orderHash,
    zeroExOrder.makerAddress
  );

  // Append signature to order
  const signedOrder = {
github 0xProject / 0x-monorepo / packages / website / ts / components / fill_order.tsx View on Github external
private async _validateFillOrderFireAndForgetAsync(orderJSON: string): Promise {
        let orderJSONErrMsg = '';
        let parsedOrder: PortalOrder;
        let orderHash: string;
        try {
            const order = orderParser.parseJsonString(orderJSON);
            const validationResult = validator.validate(order, portalOrderSchema);
            if (validationResult.errors.length > 0) {
                orderJSONErrMsg = 'Submitted order JSON is not a valid order';
                logUtils.log(`Unexpected order JSON validation error: ${validationResult.errors.join(', ')}`);
                return;
            }
            parsedOrder = order;
            const signedOrder = parsedOrder.signedOrder;
            orderHash = orderHashUtils.getOrderHashHex(signedOrder);
            const exchangeContractAddr = this.props.blockchain.getExchangeContractAddressIfExists();
            const signature = signedOrder.signature;
            const isSignatureValid = await this.props.blockchain.isValidSignatureAsync(
                orderHash,
                signature,
                signedOrder.makerAddress,
            );
            if (exchangeContractAddr !== signedOrder.exchangeAddress) {
                orderJSONErrMsg = 'This order was made on another network or using a deprecated Exchange contract';
                parsedOrder = undefined;
            } else if (!isSignatureValid) {
                orderJSONErrMsg = 'Order signature is invalid';
                parsedOrder = undefined;
            } else {
                // Update user supplied order cache so that if they navigate away from fill view
                // e.g to set a token allowance, when they come back, the fill order persists
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
        const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
        const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);

        let fillableTakerAssetAmount;
        const shouldValidateRemainingOrderAmountIsFillable =
            opts.validateRemainingOrderAmountIsFillable === undefined
                ? true
                : opts.validateRemainingOrderAmountIsFillable;
        if (opts.expectedFillTakerTokenAmount) {
            // If the caller has specified a taker fill amount, we use this for all validation
            fillableTakerAssetAmount = opts.expectedFillTakerTokenAmount;
        } else if (shouldValidateRemainingOrderAmountIsFillable) {
            // Default behaviour is to validate the amount left on the order.
            const filledTakerTokenAmount = await this.getFilledTakerAssetAmountAsync(
                orderHashUtils.getOrderHashHex(signedOrder),
            );
            fillableTakerAssetAmount = signedOrder.takerAssetAmount.minus(filledTakerTokenAmount);
        } else {
            const orderStateUtils = new OrderStateUtils(balanceAllowanceStore, filledCancelledFetcher);
            // Calculate the taker amount fillable given the maker balance and allowance
            const orderRelevantState = await orderStateUtils.getOpenOrderRelevantStateAsync(signedOrder);
            fillableTakerAssetAmount = orderRelevantState.remainingFillableTakerAssetAmount;
        }

        const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher, this._web3Wrapper.getProvider());
        await orderValidationUtils.validateOrderFillableOrThrowAsync(
            exchangeTradeSimulator,
            signedOrder,
            this.getZRXAssetData(),
            fillableTakerAssetAmount,
        );
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _removeFromMakerDependentOrderhashes(signedOrder: SignedOrder): void {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        this._orderHashesByMakerAddress[signedOrder.makerAddress].delete(orderHash);

        if (_.isEmpty(this._orderHashesByMakerAddress[signedOrder.makerAddress])) {
            delete this._orderHashesByMakerAddress[signedOrder.makerAddress];
        }
    }
}
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _addToERC721DependentOrderHashes(
        signedOrder: SignedOrder,
        erc721TokenAddress: string,
        tokenId: BigNumber,
    ): void {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        if (_.isUndefined(this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress])) {
            this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress] = {};
        }

        if (
            _.isUndefined(
                this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][erc721TokenAddress],
            )
        ) {
            this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][erc721TokenAddress] = {};
        }

        if (
            _.isUndefined(
                this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][erc721TokenAddress][
                    tokenId.toString()
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _addToMakerDependentOrderHashes(signedOrder: SignedOrder): void {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        if (_.isUndefined(this._orderHashesByMakerAddress[signedOrder.makerAddress])) {
            this._orderHashesByMakerAddress[signedOrder.makerAddress] = new Set();
        }
        this._orderHashesByMakerAddress[signedOrder.makerAddress].add(orderHash);
    }
    private _removeFromERC20DependentOrderhashes(signedOrder: SignedOrder, erc20TokenAddress: string): void {
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _addToERC20DependentOrderHashes(signedOrder: SignedOrder, erc20TokenAddress: string): void {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        if (_.isUndefined(this._orderHashesByERC20ByMakerAddress[signedOrder.makerAddress])) {
            this._orderHashesByERC20ByMakerAddress[signedOrder.makerAddress] = {};
        }
        if (_.isUndefined(this._orderHashesByERC20ByMakerAddress[signedOrder.makerAddress][erc20TokenAddress])) {
            this._orderHashesByERC20ByMakerAddress[signedOrder.makerAddress][erc20TokenAddress] = new Set();
        }
        this._orderHashesByERC20ByMakerAddress[signedOrder.makerAddress][erc20TokenAddress].add(orderHash);
    }
    private _addToERC721DependentOrderHashes(
github 0xProject / 0x-monorepo / packages / website / ts / components / inputs / hash_input.tsx View on Github external
const order: Order = {
            senderAddress: constants.NULL_ADDRESS,
            exchangeAddress,
            expirationTimeSeconds: hashData.orderExpiryTimestamp,
            feeRecipientAddress: hashData.feeRecipientAddress,
            makerAddress: _.isEmpty(hashData.orderMakerAddress) ? constants.NULL_ADDRESS : hashData.orderMakerAddress,
            makerFee: hashData.makerFee,
            makerAssetData,
            makerAssetAmount: hashData.depositAmount,
            salt: hashData.orderSalt,
            takerAddress: hashData.orderTakerAddress,
            takerFee: hashData.takerFee,
            takerAssetData,
            takerAssetAmount: hashData.receiveAmount,
        };
        const orderHash = orderHashUtils.getOrderHashHex(order);
        return orderHash;
    }
}
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _removeFromERC721DependentOrderhashes(
        signedOrder: SignedOrder,
        erc721TokenAddress: string,
        tokenId: BigNumber,
    ): void {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][erc721TokenAddress][
            tokenId.toString()
        ].delete(orderHash);

        if (
            _.isEmpty(
                this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][erc721TokenAddress][
                    tokenId.toString()
                ],
            )
        ) {
            delete this._orderHashesByERC721AddressByTokenIdByMakerAddress[signedOrder.makerAddress][
                erc721TokenAddress
            ][tokenId.toString()];
        }