How to use the @0x/order-utils.orderCalculationUtils.getMakerFillAmount 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 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / order_provider_response_processor.ts View on Github external
(accOrders, order, index) => {
            // get corresponding on-chain state for the order
            const { orderInfo, traderInfo } = ordersAndTradersInfo[index];
            // if the order IS NOT fillable, do not add anything to the accumulations and continue iterating
            if (orderInfo.orderStatus !== OrderStatus.Fillable) {
                return accOrders;
            }
            // if the order IS fillable, add the order and calculate the remaining fillable amount
            const transferrableAssetAmount = BigNumber.min(traderInfo.makerAllowance, traderInfo.makerBalance);
            const transferrableFeeAssetAmount = BigNumber.min(traderInfo.makerZrxAllowance, traderInfo.makerZrxBalance);
            const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
            const remainingMakerAssetAmount = orderCalculationUtils.getMakerFillAmount(
                order,
                remainingTakerAssetAmount,
            );
            const remainingFillableCalculator = new RemainingFillableCalculator(
                order.makerFee,
                order.makerAssetAmount,
                isMakerAssetZrxToken,
                transferrableAssetAmount,
                transferrableFeeAssetAmount,
                remainingMakerAssetAmount,
            );
            const remainingFillableAmount = remainingFillableCalculator.computeRemainingFillable();
            // if the order does not have any remaining fillable makerAsset, do not add anything to the accumulations and continue iterating
            if (remainingFillableAmount.lte(constants.ZERO_AMOUNT)) {
                return accOrders;
            }
github 0xProject / 0x-monorepo / packages / asset-buyer / src / order_providers / standard_relayer_api_order_provider.ts View on Github external
const result = _.map(apiOrders, apiOrder => {
            const { order, metaData } = apiOrder;
            // The contents of metaData is not explicity defined in the spec
            // We check for remainingTakerAssetAmount as a string and use this value if populated
            const metaDataRemainingTakerAssetAmount = _.get(metaData, 'remainingTakerAssetAmount') as
                | string
                | undefined;
            const remainingFillableTakerAssetAmount = metaDataRemainingTakerAssetAmount
                ? new BigNumber(metaDataRemainingTakerAssetAmount)
                : order.takerAssetAmount;
            const remainingFillableMakerAssetAmount = orderCalculationUtils.getMakerFillAmount(
                order,
                remainingFillableTakerAssetAmount,
            );
            const newOrder = {
                ...order,
                remainingFillableMakerAssetAmount,
            };
            return newOrder;
        });
        return result;
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / order_provider_response_processor.ts View on Github external
(accOrders, order, index) => {
            // get corresponding on-chain state for the order
            const { orderInfo, traderInfo } = ordersAndTradersInfo[index];
            // if the order IS NOT fillable, do not add anything to the accumulations and continue iterating
            if (orderInfo.orderStatus !== OrderStatus.Fillable) {
                return accOrders;
            }
            // if the order IS fillable, add the order and calculate the remaining fillable amount
            const transferrableAssetAmount = BigNumber.min(traderInfo.makerAllowance, traderInfo.makerBalance);
            const transferrableFeeAssetAmount = BigNumber.min(traderInfo.makerZrxAllowance, traderInfo.makerZrxBalance);
            const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
            const remainingMakerAssetAmount = orderCalculationUtils.getMakerFillAmount(
                order,
                remainingTakerAssetAmount,
            );
            const remainingFillableCalculator = new RemainingFillableCalculator(
                order.makerFee,
                order.makerAssetAmount,
                isMakerAssetZrxToken,
                transferrableAssetAmount,
                transferrableFeeAssetAmount,
                remainingMakerAssetAmount,
            );
            const remainingFillableAmount = remainingFillableCalculator.computeRemainingFillable();
            // if the order does not have any remaining fillable makerAsset, do not add anything to the accumulations and continue iterating
            if (remainingFillableAmount.lte(constants.ZERO_AMOUNT)) {
                return accOrders;
            }
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / order_provider_response_processor.ts View on Github external
(accOrders, order, index) => {
            // get corresponding on-chain state for the order
            const { orderInfo, traderInfo } = ordersAndTradersInfo[index];
            // if the order IS NOT fillable, do not add anything to the accumulations and continue iterating
            if (orderInfo.orderStatus !== OrderStatus.Fillable) {
                return accOrders;
            }
            // if the order IS fillable, add the order and calculate the remaining fillable amount
            const transferrableAssetAmount = BigNumber.min(traderInfo.makerAllowance, traderInfo.makerBalance);
            const transferrableFeeAssetAmount = BigNumber.min(traderInfo.makerZrxAllowance, traderInfo.makerZrxBalance);
            const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
            const remainingMakerAssetAmount = orderCalculationUtils.getMakerFillAmount(
                order,
                remainingTakerAssetAmount,
            );
            const remainingFillableCalculator = new RemainingFillableCalculator(
                order.makerFee,
                order.makerAssetAmount,
                isMakerAssetZrxToken,
                transferrableAssetAmount,
                transferrableFeeAssetAmount,
                remainingMakerAssetAmount,
            );
            const remainingFillableAmount = remainingFillableCalculator.computeRemainingFillable();
            // if the order does not have any remaining fillable makerAsset, do not add anything to the accumulations and continue iterating
            if (remainingFillableAmount.lte(constants.ZERO_AMOUNT)) {
                return accOrders;
            }
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
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,
        );
        const makerTransferAmount = orderCalculationUtils.getMakerFillAmount(signedOrder, fillableTakerAssetAmount);
        await this.validateMakerTransferThrowIfInvalidAsync(
            signedOrder,
            makerTransferAmount,
            opts.simulationTakerAddress,
        );
    }
    /**
github 0xProject / 0x-coordinator-server / ts / src / handlers.ts View on Github external
const remainingFillableTakerAssetAmount = Handlers._calculateRemainingFillableTakerAssetAmount(
                signedOrder,
                orderAndTraderInfo,
            );
            const totalTakerAssetAmountAtOrderExchangeRate = orderCalculationUtils.getTakerFillAmount(
                signedOrder,
                totalMakerAssetAmount,
            );
            const takerAssetFillAmount = totalTakerAssetAmountAtOrderExchangeRate.isLessThan(
                remainingFillableTakerAssetAmount,
            )
                ? totalTakerAssetAmountAtOrderExchangeRate
                : remainingFillableTakerAssetAmount;

            const remainingTotalTakerAssetAmount = totalTakerAssetAmountAtOrderExchangeRate.minus(takerAssetFillAmount);
            totalMakerAssetAmount = orderCalculationUtils.getMakerFillAmount(
                signedOrder,
                remainingTotalTakerAssetAmount,
            );
            takerAssetFillAmounts.push(takerAssetFillAmount);
        });
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / swap_quote_calculator.ts View on Github external
const adjustedTakerAssetAmount = order.takerAssetAmount.plus(order.takerFee);
        const filledRatio = takerAssetAmountWithFees.div(adjustedTakerAssetAmount);
        const takerAssetAmount = filledRatio.multipliedBy(order.takerAssetAmount).integerValue(BigNumber.ROUND_CEIL);
        return {
            takerAssetAmount,
            feeTakerAssetAmount: takerAssetAmountWithFees.minus(takerAssetAmount),
        };
    } else if (utils.isOrderTakerFeePayableWithMakerAsset(order)) {
        if (takerAssetAmountWithFees.isZero()) {
            return {
                takerAssetAmount: constants.ZERO_AMOUNT,
                feeTakerAssetAmount: constants.ZERO_AMOUNT,
            };
        }
        const takerFeeAmount = orderCalculationUtils.getTakerFeeAmount(order, takerAssetAmountWithFees);
        const makerAssetFillAmount = orderCalculationUtils.getMakerFillAmount(order, takerAssetAmountWithFees);
        const takerAssetAmount = takerFeeAmount
            .div(makerAssetFillAmount)
            .multipliedBy(takerAssetAmountWithFees)
            .integerValue(BigNumber.ROUND_CEIL);
        return {
            takerAssetAmount,
            feeTakerAssetAmount: takerAssetAmountWithFees.minus(takerAssetAmount),
        };
    }
    return {
        feeTakerAssetAmount: constants.ZERO_AMOUNT,
        takerAssetAmount: takerAssetAmountWithFees,
    };
}
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / market_operation_utils / index.ts View on Github external
(order: SignedOrder, i: number): SignedOrderWithFillableAmounts => {
                const fillableAmount = fillableAmounts[i];
                const fillableMakerAssetAmount =
                    operation === MarketOperation.Buy
                        ? fillableAmount
                        : orderCalculationUtils.getMakerFillAmount(order, fillableAmount);
                const fillableTakerAssetAmount =
                    operation === MarketOperation.Sell
                        ? fillableAmount
                        : orderCalculationUtils.getTakerFillAmount(order, fillableAmount);
                const fillableTakerFeeAmount = orderCalculationUtils.getTakerFeeAmount(order, fillableTakerAssetAmount);
                return {
                    fillableMakerAssetAmount,
                    fillableTakerAssetAmount,
                    fillableTakerFeeAmount,
                    ...order,
                };
            },
        )