How to use the @0x/order-utils.orderCalculationUtils.getTakerFillAmount 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-coordinator-server / ts / src / handlers.ts View on Github external
const traderInfo = orderAndTraderInfo.traderInfo;

        const minSet = [];

        // Calculate min of balance & allowance of taker's takerAsset
        if (signedOrder.takerAddress !== NULL_ADDRESS) {
            const maxTakerAssetFillAmountGivenTakerConstraints = BigNumber.min(
                traderInfo.takerBalance,
                traderInfo.takerAllowance,
            );
            minSet.push(maxTakerAssetFillAmountGivenTakerConstraints);
        }

        // Calculate min of balance & allowance of maker's makerAsset -> translate into takerAsset amount
        const maxMakerAssetFillAmount = BigNumber.min(traderInfo.makerBalance, traderInfo.makerAllowance);
        const maxTakerAssetFillAmountGivenMakerConstraints = orderCalculationUtils.getTakerFillAmount(
            signedOrder,
            maxMakerAssetFillAmount,
        );
        minSet.push(maxTakerAssetFillAmountGivenMakerConstraints);

        // Calculate min of balance & allowance of taker's Fee -> translate into takerAsset amount
        if (!signedOrder.takerFee.eq(0)) {
            const takerFeeAvailable = BigNumber.min(traderInfo.takerFeeBalance, traderInfo.takerFeeAllowance);
            const maxTakerAssetFillAmountGivenTakerFeeConstraints = takerFeeAvailable
                .multipliedBy(signedOrder.takerAssetAmount)
                .div(signedOrder.takerFee)
                .integerValue(BigNumber.ROUND_FLOOR);
            minSet.push(maxTakerAssetFillAmountGivenTakerFeeConstraints);
        }

        // Calculate min of balance & allowance of maker's Fee -> translate into takerAsset amount
github 0xProject / 0x-coordinator-server / ts / src / handlers.ts View on Github external
_.each(batchOrderAndTraderInfo, (orderAndTraderInfo: OrderAndTraderInfo, i: number) => {
            const signedOrder = signedOrders[i];
            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-buyer / src / utils / calculate_liquidity.ts View on Github external
(acc, order, curIndex) => {
            const availableMakerAssetAmount = remainingFillableMakerAssetAmounts[curIndex];
            if (availableMakerAssetAmount === undefined) {
                throw new Error(`No corresponding fillableMakerAssetAmounts at index ${curIndex}`);
            }

            const makerTokensAvailableForCurrentOrder = availableMakerAssetAmount;
            const takerTokensAvailableForCurrentOrder = orderCalculationUtils.getTakerFillAmount(
                order,
                makerTokensAvailableForCurrentOrder,
            );
            return {
                makerTokensAvailableInBaseUnits: acc.makerTokensAvailableInBaseUnits.plus(
                    makerTokensAvailableForCurrentOrder,
                ),
                takerTokensAvailableInBaseUnits: acc.takerTokensAvailableInBaseUnits.plus(
                    takerTokensAvailableForCurrentOrder,
                ),
            };
        },
        {
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,
                };
            },
        )