• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utils.BigNumber类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@0xproject/utils.BigNumber的典型用法代码示例。如果您正苦于以下问题:TypeScript BigNumber类的具体用法?TypeScript BigNumber怎么用?TypeScript BigNumber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BigNumber类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

 it('should correctly round the makerFeeAmount', async () => {
     const makerFee = new BigNumber(2);
     const takerFee = new BigNumber(4);
     const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
         makerTokenAddress,
         takerTokenAddress,
         makerFee,
         takerFee,
         makerAddress,
         takerAddress,
         fillableAmount,
         ZeroEx.NULL_ADDRESS,
     );
     const fillTakerTokenAmount = fillableAmount.div(2).round(0);
     await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
         exchangeTransferSimulator,
         signedOrder,
         fillTakerTokenAmount,
         takerAddress,
         zrxTokenAddress,
     );
     const makerPartialFee = makerFee.div(2);
     const takerPartialFee = takerFee.div(2);
     expect(transferFromAsync.callCount).to.be.equal(4);
     const partialMakerFee = transferFromAsync.getCall(2).args[3];
     expect(partialMakerFee).to.be.bignumber.equal(makerPartialFee);
     const partialTakerFee = transferFromAsync.getCall(3).args[3];
     expect(partialTakerFee).to.be.bignumber.equal(takerPartialFee);
 });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:29,代码来源:order_validation_test.ts


示例2: _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


示例3: 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


示例4: _updateDefaultGasPriceAsync

 private async _updateDefaultGasPriceAsync() {
     const endpoint = `${configs.BACKEND_BASE_URL}/eth_gas_station`;
     const response = await fetch(endpoint);
     if (response.status !== 200) {
         return; // noop and we keep hard-coded default
     }
     const gasInfo = await response.json();
     const gasPriceInGwei = new BigNumber(gasInfo.average / 10);
     const gasPriceInWei = gasPriceInGwei.mul(1000000000);
     this._defaultGasPrice = gasPriceInWei;
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:11,代码来源:blockchain.ts


示例5: it

        it('should convert deposited Ether to wrapped Ether tokens', async () => {
            const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
            const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);

            const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));

            const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
            const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);

            const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
            const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
            const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);

            expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
            expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
        });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:16,代码来源:ether_token.ts


示例6: _getPartialAmount

 private static _getPartialAmount(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
     const fillMakerTokenAmount = numerator
         .mul(target)
         .div(denominator)
         .round(0);
     return fillMakerTokenAmount;
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:7,代码来源:order_validation_utils.ts


示例7: it

            it('should be executable with enough confirmations and secondsTimeLocked of 0', async () => {
                const destination = multiSig.address;
                const from = owners[0];
                const dataParams = {
                    name: 'changeTimeLock',
                    abi: MULTI_SIG_ABI,
                    args: [SECONDS_TIME_LOCKED.toNumber()],
                };
                let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
                const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
                const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
                    SubmissionContractEventArgs
                >;

                txId = log.args.transactionId;
                txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });

                expect(initialSecondsTimeLocked).to.be.equal(0);

                txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
                const res = await zeroEx.awaitTransactionMinedAsync(txHash);
                expect(res.logs).to.have.length(2);

                const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
                expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
            });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:26,代码来源:multi_sig_with_time_lock.ts


示例8: _validateRemainingFillAmountNotZeroOrThrow

 private static _validateRemainingFillAmountNotZeroOrThrow(
     takerTokenAmount: BigNumber,
     unavailableTakerTokenAmount: BigNumber,
 ) {
     if (takerTokenAmount.eq(unavailableTakerTokenAmount)) {
         throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
     }
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:8,代码来源:order_validation_utils.ts



注:本文中的@0xproject/utils.BigNumber类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils.intervalUtils类代码示例发布时间:2022-05-28
下一篇:
TypeScript utils.AbiDecoder类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap