當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript BigNumber.min方法代碼示例

本文整理匯總了TypeScript中@0xproject/utils.BigNumber.min方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BigNumber.min方法的具體用法?TypeScript BigNumber.min怎麽用?TypeScript BigNumber.min使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@0xproject/utils.BigNumber的用法示例。


在下文中一共展示了BigNumber.min方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _calculatePartiallyFillableMakerTokenAmount

 private _calculatePartiallyFillableMakerTokenAmount(): BigNumber {
     // Given an order for 200 wei for 2 ZRXwei fee, find 100 wei for 1 ZRXwei. Order ratio is then 100:1
     const orderToFeeRatio = this._signedOrder.makerTokenAmount.dividedBy(this._signedOrder.makerFee);
     // The number of times the maker can fill the order, if each fill only required the transfer of a single
     // baseUnit of fee tokens.
     // Given 2 ZRXwei, the maximum amount of times Maker can fill this order, in terms of fees, is 2
     const fillableTimesInFeeTokenBaseUnits = BigNumber.min(
         this._transferrableMakerFeeTokenAmount,
         this._remainingMakerFeeAmount,
     );
     // The number of times the Maker can fill the order, given the Maker Token Balance
     // Assuming a balance of 150 wei, and an orderToFeeRatio of 100:1, maker can fill this order 1 time.
     let fillableTimesInMakerTokenUnits = this._transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
     if (this._isMakerTokenZRX) {
         // If ZRX is the maker token, the Fee and the Maker amount need to be removed from the same pool;
         // 200 ZRXwei for 2ZRXwei fee can only be filled once (need 202 ZRXwei)
         const totalZRXTokenPooled = this._transferrableMakerTokenAmount;
         // The purchasing power here is less as the tokens are taken from the same Pool
         // For every one number of fills, we have to take an extra ZRX out of the pool
         fillableTimesInMakerTokenUnits = totalZRXTokenPooled.dividedBy(orderToFeeRatio.plus(new BigNumber(1)));
     }
     // When Ratio is not fully divisible there can be remainders which cannot be represented, so they are floored.
     // This can result in a RoundingError being thrown by the Exchange Contract.
     const partiallyFillableMakerTokenAmount = fillableTimesInMakerTokenUnits
         .times(this._signedOrder.makerTokenAmount)
         .dividedToIntegerBy(this._signedOrder.makerFee);
     const partiallyFillableFeeTokenAmount = fillableTimesInFeeTokenBaseUnits
         .times(this._signedOrder.makerTokenAmount)
         .dividedToIntegerBy(this._signedOrder.makerFee);
     const partiallyFillableAmount = BigNumber.min(
         partiallyFillableMakerTokenAmount,
         partiallyFillableFeeTokenAmount,
     );
     return partiallyFillableAmount;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:35,代碼來源:remaining_fillable_calculator.ts

示例2: getOrderRelevantStateAsync

    public async getOrderRelevantStateAsync(signedOrder: SignedOrder): Promise<OrderRelevantState> {
        // HACK: We access the private property here but otherwise the interface will be less nice.
        // If we pass it from the instantiator - there is no opportunity to get it there
        // because JS doesn't support async constructors.
        // Moreover - it's cached under the hood so it's equivalent to an async constructor.
        const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
        const zrxTokenAddress = exchange.getZRXTokenAddress();
        const orderHash = ZeroEx.getOrderHashHex(signedOrder);
        const makerBalance = await this._balanceAndProxyAllowanceLazyStore.getBalanceAsync(
            signedOrder.makerTokenAddress,
            signedOrder.maker,
        );
        const makerProxyAllowance = await this._balanceAndProxyAllowanceLazyStore.getProxyAllowanceAsync(
            signedOrder.makerTokenAddress,
            signedOrder.maker,
        );
        const makerFeeBalance = await this._balanceAndProxyAllowanceLazyStore.getBalanceAsync(
            zrxTokenAddress,
            signedOrder.maker,
        );
        const makerFeeProxyAllowance = await this._balanceAndProxyAllowanceLazyStore.getProxyAllowanceAsync(
            zrxTokenAddress,
            signedOrder.maker,
        );
        const filledTakerTokenAmount = await this._orderFilledCancelledLazyStore.getFilledTakerAmountAsync(orderHash);
        const cancelledTakerTokenAmount = await this._orderFilledCancelledLazyStore.getCancelledTakerAmountAsync(
            orderHash,
        );
        const unavailableTakerTokenAmount = await exchange.getUnavailableTakerAmountAsync(orderHash);
        const totalMakerTokenAmount = signedOrder.makerTokenAmount;
        const totalTakerTokenAmount = signedOrder.takerTokenAmount;
        const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount);
        const remainingMakerTokenAmount = remainingTakerTokenAmount
            .times(totalMakerTokenAmount)
            .dividedToIntegerBy(totalTakerTokenAmount);
        const transferrableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
        const transferrableFeeTokenAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]);

        const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress;
        const remainingFillableCalculator = new RemainingFillableCalculator(
            signedOrder,
            isMakerTokenZRX,
            transferrableMakerTokenAmount,
            transferrableFeeTokenAmount,
            remainingMakerTokenAmount,
        );
        const remainingFillableMakerTokenAmount = remainingFillableCalculator.computeRemainingMakerFillable();
        const remainingFillableTakerTokenAmount = remainingFillableCalculator.computeRemainingTakerFillable();
        const orderRelevantState = {
            makerBalance,
            makerProxyAllowance,
            makerFeeBalance,
            makerFeeProxyAllowance,
            filledTakerTokenAmount,
            cancelledTakerTokenAmount,
            remainingFillableMakerTokenAmount,
            remainingFillableTakerTokenAmount,
        };
        return orderRelevantState;
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:60,代碼來源:order_state_utils.ts

示例3: computeRemainingMakerFillable

 public computeRemainingMakerFillable(): BigNumber {
     if (this._hasSufficientFundsForFeeAndTransferAmount()) {
         return this._remainingMakerTokenAmount;
     }
     if (this._signedOrder.makerFee.isZero()) {
         return BigNumber.min(this._remainingMakerTokenAmount, this._transferrableMakerTokenAmount);
     }
     return this._calculatePartiallyFillableMakerTokenAmount();
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:9,代碼來源:remaining_fillable_calculator.ts


注:本文中的@0xproject/utils.BigNumber.min方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。