當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。