How to use the @0x/utils.BigNumber.ROUND_FLOOR 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 / order-utils / src / order_calculation_utils.ts View on Github external
getMakerFeeAmount(order: Order, makerFillAmount: BigNumber): BigNumber {
        // Round down because Maker fee rate favors Maker
        const makerFeeAmount = makerFillAmount
            .multipliedBy(order.makerFee)
            .div(order.makerAssetAmount)
            .integerValue(BigNumber.ROUND_FLOOR);
        return makerFeeAmount;
    },
    /**
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / order_utils.ts View on Github external
getRemainingMakerAmount(order: SignedOrder, remainingTakerAmount: BigNumber): BigNumber {
        const remainingMakerAmount = remainingTakerAmount
            .times(order.makerAssetAmount)
            .div(order.takerAssetAmount)
            .integerValue(BigNumber.ROUND_FLOOR);
        return remainingMakerAmount;
    },
    // given a desired amount of makerAsset, calculate how much takerAsset is required to fill that amount
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / order_utils.ts View on Github external
getMakerFillAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber {
        // Round down because exchange rate favors Maker
        const makerFillAmount = takerFillAmount
            .multipliedBy(order.makerAssetAmount)
            .div(order.takerAssetAmount)
            .integerValue(BigNumber.ROUND_FLOOR);
        return makerFillAmount;
    },
    // given a desired amount of makerAsset, calculate how much fee is required by the maker to fill that amount
github 0xProject / 0x-monorepo / packages / order-utils / src / order_calculation_utils.ts View on Github external
getMakerFillAmount(order: Order, takerFillAmount: BigNumber): BigNumber {
        // Round down because exchange rate favors Maker
        const makerFillAmount = takerFillAmount
            .multipliedBy(order.makerAssetAmount)
            .div(order.takerAssetAmount)
            .integerValue(BigNumber.ROUND_FLOOR);
        return makerFillAmount;
    },
    /**
github 0xProject / 0x-coordinator-server / ts / src / handlers.ts View on Github external
// 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
        if (!signedOrder.makerFee.eq(0)) {
            const makerFeeAvailable = BigNumber.min(traderInfo.makerFeeBalance, traderInfo.makerFeeAllowance);
            const maxTakerAssetFillAmountGivenMakerFeeConstraints = makerFeeAvailable
                .multipliedBy(signedOrder.takerAssetAmount)
                .div(signedOrder.makerFee)
                .integerValue(BigNumber.ROUND_FLOOR);
            minSet.push(maxTakerAssetFillAmountGivenMakerFeeConstraints);
        }

        const remainingTakerAssetFillAmount = signedOrder.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
        minSet.push(remainingTakerAssetFillAmount);
github 0xProject / 0x-monorepo / contracts / test-utils / src / order_utils.ts View on Github external
getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
        const partialAmount = numerator
            .multipliedBy(target)
            .div(denominator)
            .integerValue(BigNumber.ROUND_FLOOR);
        return partialAmount;
    },
    createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
github 0xProject / 0x-monorepo / packages / website / ts / pages / governance / vote_stats.tsx View on Github external
export const getTotalBalancesString = (tally: TallyInterface = ZERO_TALLY): string => {
    const bigNumberFormat = {
        decimalSeparator: '.',
        groupSeparator: ',',
        groupSize: 3,
        secondaryGroupSize: 0,
        fractionGroupSeparator: ' ',
        fractionGroupSize: 0,
    };
    const { yes, no } = tally;
    const totalBalance = yes.plus(no);
    const totalBalanceString = Web3Wrapper.toUnitAmount(totalBalance, constants.DECIMAL_PLACES_ETH).toFormat(
        0,
        BigNumber.ROUND_FLOOR,
        bigNumberFormat,
    );
    return totalBalanceString;
};
github 0xProject / 0x-monorepo / packages / website / ts / pages / governance / modal_vote.tsx View on Github external
public render(): React.ReactNode {
        const { isOpen, onDismiss, zeipId } = this.props;
        const { isSuccessful, selectedAddress, currentBalance, isErrorModalOpen, errorMessage } = this.state;
        const bigNumberFormat = {
            decimalSeparator: '.',
            groupSeparator: ',',
            groupSize: 3,
            secondaryGroupSize: 0,
            fractionGroupSeparator: ' ',
            fractionGroupSize: 0,
        };
        const formattedBalance = Web3Wrapper.toUnitAmount(currentBalance, constants.DECIMAL_PLACES_ETH).toFormat(
            0,
            BigNumber.ROUND_FLOOR,
            bigNumberFormat,
        );
        return (
            <>
                
                    
                        {this._renderFormContent()}
                        
                            
                            
                                Vote Received!
github 0xProject / 0x-monorepo / packages / website / ts / pages / governance / vote_form.tsx View on Github external
public render(): React.ReactNode {
        const { votePreference, errors, isSuccessful, isAwaitingLedgerSignature } = this.state;
        const { currentBalance, selectedAddress, zeipId } = this.props;
        const bigNumberFormat = {
            decimalSeparator: '.',
            groupSeparator: ',',
            groupSize: 3,
            secondaryGroupSize: 0,
            fractionGroupSeparator: ' ',
            fractionGroupSize: 0,
        };
        const formattedBalance = Web3Wrapper.toUnitAmount(currentBalance, constants.DECIMAL_PLACES_ETH).toFormat(
            0,
            BigNumber.ROUND_FLOOR,
            bigNumberFormat,
        );
        return (
            <form>
                
                    ZEIP-{zeipId} Vote
                
                
                    Make sure you are informed to the best of your ability before casting your vote. It will have
                    lasting implications for the 0x ecosystem.
                
                
                    </form>
github 0xProject / 0x-monorepo / packages / website / ts / components / fill_order.tsx View on Github external
const takerToken = this.props.tokenByAddress[takerTokenAddress];
        const orderTakerAmount = this.state.parsedOrder.signedOrder.takerAssetAmount;
        const orderMakerAmount = this.state.parsedOrder.signedOrder.makerAssetAmount;
        const takerAssetToken = {
            amount: orderTakerAmount.minus(this.state.unavailableTakerAmount),
            symbol: takerToken.symbol,
        };
        const fillToken = this.props.tokenByAddress[takerTokenAddress];
        const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
            .tokenAddress;
        const makerToken = this.props.tokenByAddress[makerTokenAddress];
        const makerAssetToken = {
            amount: orderMakerAmount
                .times(takerAssetToken.amount)
                .div(orderTakerAmount)
                .integerValue(BigNumber.ROUND_FLOOR),
            symbol: makerToken.symbol,
        };
        const fillAssetToken = {
            amount: this.props.orderFillAmount,
            symbol: takerToken.symbol,
        };
        const parsedOrderExpiration = this.state.parsedOrder.signedOrder.expirationTimeSeconds;

        let orderReceiveAmount = 0;
        if (this.props.orderFillAmount !== undefined) {
            const orderReceiveAmountBigNumber = orderMakerAmount
                .times(this.props.orderFillAmount)
                .dividedBy(orderTakerAmount)
                .integerValue(BigNumber.ROUND_FLOOR);
            orderReceiveAmount = this._formatCurrencyAmount(orderReceiveAmountBigNumber, makerToken.decimals);
        }