当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript 0x.js.ZeroEx类代码示例

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


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

示例1: before

 before(async () => {
     const accounts = await web3Wrapper.getAvailableAddressesAsync();
     [maker, feeRecipient] = accounts;
     const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
     const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
     const [rep, dgd, zrx] = await Promise.all([
         deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
         deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
         deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
     ]);
     const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
         zrx.address,
         tokenTransferProxy.address,
     ]);
     const exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
     await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
     const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
     exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
     const defaultOrderParams = {
         exchangeContractAddress: exchange.address,
         maker,
         feeRecipient,
         makerTokenAddress: rep.address,
         takerTokenAddress: dgd.address,
         makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
         takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
         makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
         takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
     };
     orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
     signedOrder = await orderFactory.newSignedOrderAsync();
 });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:32,代码来源:helpers.ts

示例2: it

 it('should return true with a valid signature', async () => {
     const success = await exchangeWrapper.isValidSignatureAsync(signedOrder);
     const orderHashHex = ZeroEx.getOrderHashHex(signedOrder);
     const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker);
     expect(isValidSignature).to.be.true();
     expect(success).to.be.true();
 });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:7,代码来源:helpers.ts

示例3: it

        it('should create an unfillable order', async () => {
            signedOrder = await orderFactory.newSignedOrderAsync({
                makerTokenAmount: new BigNumber(1001),
                takerTokenAmount: new BigNumber(3),
            });

            const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
                ZeroEx.getOrderHashHex(signedOrder),
            );
            expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);

            const fillTakerTokenAmount1 = new BigNumber(2);
            await exWrapper.fillOrderAsync(signedOrder, taker, {
                fillTakerTokenAmount: fillTakerTokenAmount1,
            });

            const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
                ZeroEx.getOrderHashHex(signedOrder),
            );
            expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);

            const fillTakerTokenAmount2 = new BigNumber(1);
            await exWrapper.fillOrderAsync(signedOrder, taker, {
                fillTakerTokenAmount: fillTakerTokenAmount2,
            });

            const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
                ZeroEx.getOrderHashHex(signedOrder),
            );
            expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
        });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:31,代码来源:core.ts

示例4: async

 return async () => {
     logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`);
     const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN);
     const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(tokenSymbol);
     if (_.isUndefined(token)) {
         throw new Error(`Unsupported asset type: ${tokenSymbol}`);
     }
     const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals);
     const userBalanceBaseUnits = await zeroEx.token.getBalanceAsync(token.address, recipientAddress);
     const maxAmountBaseUnits = ZeroEx.toBaseUnitAmount(
         new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN),
         token.decimals,
     );
     if (userBalanceBaseUnits.greaterThanOrEqualTo(maxAmountBaseUnits)) {
         logUtils.log(
             `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
         );
         return;
     }
     const txHash = await zeroEx.token.transferAsync(
         token.address,
         configs.DISPENSER_ADDRESS,
         recipientAddress,
         baseUnitAmount,
     );
     logUtils.log(`Sent ${amountToDispense} ZRX to ${recipientAddress} tx: ${txHash}`);
 };
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:27,代码来源:dispense_asset_tasks.ts

示例5: providerTypeUpdatedFireAndForgetAsync

    public async providerTypeUpdatedFireAndForgetAsync(providerType: ProviderType) {
        utils.assert(!_.isUndefined(this.zeroEx), 'ZeroEx must be instantiated.');
        // Should actually be Web3.Provider|ProviderEngine union type but it causes issues
        // later on in the logic.
        let provider;
        switch (providerType) {
            case ProviderType.LEDGER: {
                const isU2FSupported = await utils.isU2FSupportedAsync();
                if (!isU2FSupported) {
                    throw new Error('Cannot update providerType to LEDGER without U2F support');
                }

                // Cache injected provider so that we can switch the user back to it easily
                this.cachedProvider = this.web3Wrapper.getProviderObj();

                this.dispatcher.updateUserAddress(''); // Clear old userAddress

                provider = new ProviderEngine();
                this.ledgerSubProvider = ledgerWalletSubproviderFactory(this.getBlockchainNetworkId.bind(this));
                provider.addProvider(this.ledgerSubProvider);
                provider.addProvider(new FilterSubprovider());
                const networkId = configs.isMainnetEnabled ?
                    constants.MAINNET_NETWORK_ID :
                    constants.TESTNET_NETWORK_ID;
                provider.addProvider(new RedundantRPCSubprovider(
                    constants.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId],
                ));
                provider.start();
                this.web3Wrapper.destroy();
                const shouldPollUserAddress = false;
                this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, this.networkId, shouldPollUserAddress);
                await this.zeroEx.setProviderAsync(provider);
                await this.postInstantiationOrUpdatingProviderZeroExAsync();
                break;
            }

            case ProviderType.INJECTED: {
                if (_.isUndefined(this.cachedProvider)) {
                    return; // Going from injected to injected, so we noop
                }
                provider = this.cachedProvider;
                const shouldPollUserAddress = true;
                this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, this.networkId, shouldPollUserAddress);
                await this.zeroEx.setProviderAsync(provider);
                await this.postInstantiationOrUpdatingProviderZeroExAsync();
                delete this.ledgerSubProvider;
                delete this.cachedProvider;
                break;
            }

            default:
                throw utils.spawnSwitchErr('providerType', providerType);
        }

        await this.fetchTokenInformationAsync();
    }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:56,代码来源:blockchain.ts

示例6: it

            it('should set confirmation time with enough confirmations', 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] });
                const res = await zeroEx.awaitTransactionMinedAsync(txHash);
                expect(res.logs).to.have.length(2);

                const blockNum = await web3Wrapper.getBlockNumberAsync();
                const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
                const timestamp = new BigNumber(blockInfo.timestamp);
                const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.callAsync(txId));

                expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum);
            });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:26,代码来源:multi_sig_with_time_lock.ts

示例7: before

            before('deploy a walet', async () => {
                const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
                    owners,
                    SIGNATURES_REQUIRED,
                    SECONDS_TIME_LOCKED,
                ]);
                multiSig = new MultiSigWalletWithTimeLockContract(
                    web3Wrapper,
                    multiSigInstance.abi,
                    multiSigInstance.address,
                );
                multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);

                const secondsTimeLocked = await multiSig.secondsTimeLocked.callAsync();
                initialSecondsTimeLocked = secondsTimeLocked.toNumber();
                const destination = multiSig.address;
                const from = owners[0];
                const dataParams = {
                    name: 'changeTimeLock',
                    abi: MULTI_SIG_ABI,
                    args: [newSecondsTimeLocked],
                };
                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],
                });
                const confRes = await zeroEx.awaitTransactionMinedAsync(txHash);
                expect(confRes.logs).to.have.length(2);
            });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:34,代码来源:multi_sig_with_time_lock.ts


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