How to use the @0x/utils.BigNumber.ROUND_CEIL function in @0x/utils

To help you get started, we’ve selected a few @0x/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_utils.ts View on Github external
getTakerFillAmountForFeeOrder(order: SignedOrder, makerFillAmount: BigNumber): [BigNumber, BigNumber] {
        // For each unit of TakerAsset we buy (MakerAsset - TakerFee)
        const adjustedTakerFillAmount = makerFillAmount
            .multipliedBy(order.takerAssetAmount)
            .div(order.makerAssetAmount.minus(order.takerFee))
            .integerValue(BigNumber.ROUND_CEIL);
        // The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees.
        const adjustedMakerFillAmount = orderUtils.getMakerFillAmount(order, adjustedTakerFillAmount);
        return [adjustedTakerFillAmount, adjustedMakerFillAmount];
    },
};
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / order_utils.ts View on Github external
getTakerFillAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber {
        // Round up because exchange rate favors Maker
        const takerFillAmount = makerFillAmount
            .multipliedBy(order.takerAssetAmount)
            .div(order.makerAssetAmount)
            .integerValue(BigNumber.ROUND_CEIL);
        return takerFillAmount;
    },
    // given a desired amount of takerAsset to fill, calculate how much fee is required by the taker to fill that amount
github 0xProject / 0x-monorepo / packages / order-utils / src / order_calculation_utils.ts View on Github external
getTakerFillAmount(order: Order, makerFillAmount: BigNumber): BigNumber {
        // Round up because exchange rate favors Maker
        const takerFillAmount = makerFillAmount
            .multipliedBy(order.takerAssetAmount)
            .div(order.makerAssetAmount)
            .integerValue(BigNumber.ROUND_CEIL);
        return takerFillAmount;
    },
    /**
github 0xProject / 0x-monorepo / packages / order-utils / src / order_calculation_utils.ts View on Github external
getTakerFillAmountForFeeOrder(order: Order, makerFillAmount: BigNumber): [BigNumber, BigNumber] {
        // For each unit of TakerAsset we buy (MakerAsset - TakerFee)
        const adjustedTakerFillAmount = makerFillAmount
            .multipliedBy(order.takerAssetAmount)
            .div(order.makerAssetAmount.minus(order.takerFee))
            .integerValue(BigNumber.ROUND_CEIL);
        // The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees.
        const adjustedMakerFillAmount = orderCalculationUtils.getMakerFillAmount(order, adjustedTakerFillAmount);
        return [adjustedTakerFillAmount, adjustedMakerFillAmount];
    },
};
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / swap_quote_calculator.ts View on Github external
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 / instant / src / components / order_details.tsx View on Github external
private _pricePerTokenWei(): BigNumber | undefined {
        const swapQuoteAccessor = oc(this.props.swapQuoteInfo);
        const assetTotalInWei = swapQuoteAccessor.totalTakerAssetAmount();
        const selectedAssetUnitAmount = this.props.selectedAssetUnitAmount;
        return assetTotalInWei !== undefined &&
            selectedAssetUnitAmount !== undefined &&
            !selectedAssetUnitAmount.eq(BIG_NUMBER_ZERO)
            ? assetTotalInWei.div(selectedAssetUnitAmount).integerValue(BigNumber.ROUND_CEIL)
            : undefined;
    }
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / swap_quote_calculator.ts View on Github external
);
                const adjustedFillableTakerAssetAmount = fillableAmountsUtils.getTakerAssetAmountSwappedAfterFees(
                    order,
                );
                const takerAssetAmountWithFees = BigNumber.min(
                    remainingTakerAssetFillAmount,
                    adjustedFillableTakerAssetAmount,
                );
                const { takerAssetAmount, feeTakerAssetAmount } = getTakerAssetAmountBreakDown(
                    order,
                    takerAssetAmountWithFees,
                );
                const makerAssetAmount = takerAssetAmountWithFees
                    .div(adjustedFillableTakerAssetAmount)
                    .multipliedBy(adjustedFillableMakerAssetAmount)
                    .integerValue(BigNumber.ROUND_CEIL);
                return {
                    totalMakerAssetAmount: totalMakerAssetAmount.plus(makerAssetAmount),
                    totalTakerAssetAmount: totalTakerAssetAmount.plus(takerAssetAmount),
                    totalFeeTakerAssetAmount: totalFeeTakerAssetAmount.plus(feeTakerAssetAmount),
                    remainingTakerAssetFillAmount: BigNumber.max(
                        constants.ZERO_AMOUNT,
                        remainingTakerAssetFillAmount.minus(takerAssetAmountWithFees),
                    ),
                };
            },
            {