aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/tutorials
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
commit9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a (patch)
treef72aae5170b6f1f6d3d70ebf6c03ed171680ff50 /packages/contracts/test/tutorials
parent9744b1906a111aa0c65c8fafb4db66aef32a5a23 (diff)
parent6aed4fb1ae27dabed027c855f2cbdc0bfb4f3b6b (diff)
downloaddexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.gz
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.zst
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.zip
Merge branch 'development' into v2-prototype
Diffstat (limited to 'packages/contracts/test/tutorials')
-rw-r--r--packages/contracts/test/tutorials/arbitrage.ts191
1 files changed, 113 insertions, 78 deletions
diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts
index 95bc421e1..c65e050ad 100644
--- a/packages/contracts/test/tutorials/arbitrage.ts
+++ b/packages/contracts/test/tutorials/arbitrage.ts
@@ -1,23 +1,28 @@
// import { ECSignature, SignedOrder, ZeroEx } from '0x.js';
// import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+// import { ExchangeContractErrs } from '@0xproject/types';
// import { BigNumber } from '@0xproject/utils';
// import { Web3Wrapper } from '@0xproject/web3-wrapper';
// import * as chai from 'chai';
// import ethUtil = require('ethereumjs-util');
// import * as Web3 from 'web3';
+// import { AccountLevelsContract } from '../../src/contract_wrappers/generated/account_levels';
// import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
+// import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
// import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
// import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
-// import { Balances } from '../../src/utils/balances';
-// import { constants } from '../../src/utils/constants';
-// import { crypto } from '../../src/utils/crypto';
-// import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
-// import { OrderFactory } from '../../src/utils/order_factory';
-// import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../src/utils/types';
+// import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
+// import { artifacts } from '../../util/artifacts';
+// import { Balances } from '../../util/balances';
+// import { constants } from '../../util/constants';
+// import { crypto } from '../../util/crypto';
+// import { ExchangeWrapper } from '../../util/exchange_wrapper';
+// import { OrderFactory } from '../../util/order_factory';
+// import { BalancesByOwner, ContractName } from '../../util/types';
// import { chaiSetup } from '../utils/chai_setup';
-// import { deployer } from '../utils/deployer';
-// import { provider, web3Wrapper } from '../utils/web3_wrapper';
+
+// import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
// chaiSetup.configure();
// const expect = chai.expect;
@@ -36,8 +41,8 @@
// const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
// const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
-// let weth: Web3.ContractInstance;
-// let zrx: Web3.ContractInstance;
+// let weth: DummyTokenContract;
+// let zrx: DummyTokenContract;
// let arbitrage: ArbitrageContract;
// let etherDelta: EtherDeltaContract;
@@ -47,87 +52,117 @@
// let zeroEx: ZeroEx;
-// From a bird's eye view - we create two orders.
-// 0x order of 1 ZRX (maker) for 1 WETH (taker)
-// ED order of 2 WETH (tokenGive) for 1 ZRX (tokenGet)
-// And then we do an atomic arbitrage between them which gives us 1 WETH.
-// before(async () => {
-// const accounts = await web3Wrapper.getAvailableAddressesAsync();
-// [coinbase, maker, edMaker, edFrontRunner] = accounts;
-// weth = await deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS);
-// zrx = await deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS);
-// const accountLevels = await deployer.deployAsync(ContractName.AccountLevels);
-// const edAdminAddress = accounts[0];
-// const edMakerFee = 0;
-// const edTakerFee = 0;
-// const edFeeRebate = 0;
-// const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [
-// edAdminAddress,
-// feeRecipient,
-// accountLevels.address,
-// edMakerFee,
-// edTakerFee,
-// edFeeRebate,
-// ]);
-// etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider);
-// const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
-// const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
-// zrx.address,
-// tokenTransferProxy.address,
-// ]);
-// await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] });
-// zeroEx = new ZeroEx(provider, {
-// exchangeContractAddress: exchangeInstance.address,
-// networkId: constants.TESTRPC_NETWORK_ID,
-// });
-// const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
-// exWrapper = new ExchangeWrapper(exchange, zeroEx);
+// // From a bird's eye view - we create two orders.
+// // 0x order of 1 ZRX (maker) for 1 WETH (taker)
+// // ED order of 2 WETH (tokenGive) for 1 ZRX (tokenGet)
+// // And then we do an atomic arbitrage between them which gives us 1 WETH.
+// before(async () => {
+// const accounts = await web3Wrapper.getAvailableAddressesAsync();
+// [coinbase, maker, edMaker, edFrontRunner] = accounts;
+// weth = await DummyTokenContract.deployFrom0xArtifactAsync(
+// artifacts.DummyToken,
+// provider,
+// txDefaults,
+// constants.DUMMY_TOKEN_NAME,
+// constants.DUMMY_TOKEN_SYMBOL,
+// constants.DUMMY_TOKEN_DECIMALS,
+// constants.DUMMY_TOKEN_TOTAL_SUPPLY,
+// );
+// zrx = await DummyTokenContract.deployFrom0xArtifactAsync(
+// artifacts.DummyToken,
+// provider,
+// txDefaults,
+// constants.DUMMY_TOKEN_NAME,
+// constants.DUMMY_TOKEN_SYMBOL,
+// constants.DUMMY_TOKEN_DECIMALS,
+// constants.DUMMY_TOKEN_TOTAL_SUPPLY,
+// );
+// const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync(
+// artifacts.AccountLevels,
+// provider,
+// txDefaults,
+// );
+// const edAdminAddress = accounts[0];
+// const edMakerFee = new BigNumber(0);
+// const edTakerFee = new BigNumber(0);
+// const edFeeRebate = new BigNumber(0);
+// etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync(
+// artifacts.EtherDelta,
+// provider,
+// txDefaults,
+// edAdminAddress,
+// feeRecipient,
+// accountLevels.address,
+// edMakerFee,
+// edTakerFee,
+// edFeeRebate,
+// );
+// const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync(
+// artifacts.TokenTransferProxy,
+// provider,
+// txDefaults,
+// );
+// const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
+// artifacts.Exchange,
+// provider,
+// txDefaults,
+// zrx.address,
+// tokenTransferProxy.address,
+// );
+// await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
+// zeroEx = new ZeroEx(provider, {
+// exchangeContractAddress: exchange.address,
+// networkId: constants.TESTRPC_NETWORK_ID,
+// });
+// exWrapper = new ExchangeWrapper(exchange, zeroEx);
-// makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
-// takerTokenAmount = makerTokenAmount;
-// const defaultOrderParams = {
-// exchangeContractAddress: exchange.address,
-// maker,
-// feeRecipient,
-// makerTokenAddress: zrx.address,
-// takerTokenAddress: weth.address,
-// makerTokenAmount,
-// takerTokenAmount,
-// makerFee: new BigNumber(0),
-// takerFee: new BigNumber(0),
-// };
-// orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
-// const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [
-// exchange.address,
-// etherDelta.address,
-// tokenTransferProxy.address,
-// ]);
-// arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider);
-// // Enable arbitrage and withdrawals of tokens
-// await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
-// await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
+// makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
+// takerTokenAmount = makerTokenAmount;
+// const defaultOrderParams = {
+// exchangeContractAddress: exchange.address,
+// maker,
+// feeRecipient,
+// makerTokenAddress: zrx.address,
+// takerTokenAddress: weth.address,
+// makerTokenAmount,
+// takerTokenAmount,
+// makerFee: new BigNumber(0),
+// takerFee: new BigNumber(0),
+// };
+// orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
+// arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync(
+// artifacts.Arbitrage,
+// provider,
+// txDefaults,
+// exchange.address,
+// etherDelta.address,
+// tokenTransferProxy.address,
+// );
+// // Enable arbitrage and withdrawals of tokens
+// await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
+// await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
// // Give some tokens to arbitrage contract
-// await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase });
+// await weth.setBalance.sendTransactionAsync(arbitrage.address, takerTokenAmount, { from: coinbase });
// // Fund the maker on exchange side
-// await zrx.setBalance(maker, makerTokenAmount, { from: coinbase });
+// await zrx.setBalance.sendTransactionAsync(maker, makerTokenAmount, { from: coinbase });
// // Set the allowance for the maker on Exchange side
-// await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker });
+// await zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker });
// amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18);
// // Fund the maker on EtherDelta side
-// await weth.setBalance(edMaker, amountGive, { from: coinbase });
+// await weth.setBalance.sendTransactionAsync(edMaker, amountGive, { from: coinbase });
// // Set the allowance for the maker on EtherDelta side
-// await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker });
+// await weth.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker });
// // Deposit maker funds into EtherDelta
// await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker });
// amountGet = makerTokenAmount;
// // Fund the front runner on EtherDelta side
-// await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase });
+// await zrx.setBalance.sendTransactionAsync(edFrontRunner, amountGet, { from: coinbase });
// // Set the allowance for the front-runner on EtherDelta side
-// await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner });
+// await zrx.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner });
// // Deposit front runner funds into EtherDelta
// await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner });
// });
@@ -194,11 +229,11 @@
// from: coinbase,
// });
// const res = await zeroEx.awaitTransactionMinedAsync(txHash);
-// const postBalance = await weth.balanceOf(arbitrage.address);
+// const postBalance = await weth.balanceOf.callAsync(arbitrage.address);
// expect(postBalance).to.be.bignumber.equal(amountGive);
// });
// it('should fail and revert if front-runned', async () => {
-// const preBalance = await weth.balanceOf(arbitrage.address);
+// const preBalance = await weth.balanceOf.callAsync(arbitrage.address);
// // Front-running transaction
// await etherDelta.trade.sendTransactionAsync(
// tokenGet,
@@ -218,7 +253,7 @@
// await expect(
// arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }),
// ).to.be.rejectedWith(constants.REVERT);
-// const postBalance = await weth.balanceOf(arbitrage.address);
+// const postBalance = await weth.balanceOf.callAsync(arbitrage.address);
// expect(preBalance).to.be.bignumber.equal(postBalance);
// });
// });