aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 21:53:38 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 21:53:38 +0800
commit9ed05f56d360d9566d3f749fc5335768e67a87c1 (patch)
treef72c3454bf1d0902d3539e718a6187aabb1b25eb /packages
parent455f74d449738d43abb5caee3aa02ea86286866c (diff)
downloaddexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar.gz
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar.bz2
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar.lz
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar.xz
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.tar.zst
dexon-sol-tools-9ed05f56d360d9566d3f749fc5335768e67a87c1.zip
Replace our EtherTokens with WETH9 from maker
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/contracts/tokens/EtherToken.sol57
-rw-r--r--packages/contracts/contracts/tokens/EtherToken_v2.sol60
-rw-r--r--packages/contracts/deploy/migrations/migrate.ts15
-rw-r--r--packages/contracts/migrations/2_deploy_independent_contracts.ts3
-rw-r--r--packages/contracts/test/ts/ether_token_v2.ts166
-rw-r--r--packages/contracts/util/artifacts.ts4
6 files changed, 2 insertions, 303 deletions
diff --git a/packages/contracts/contracts/tokens/EtherToken.sol b/packages/contracts/contracts/tokens/EtherToken.sol
deleted file mode 100644
index 2eae012fc..000000000
--- a/packages/contracts/contracts/tokens/EtherToken.sol
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-
- Copyright 2017 ZeroEx Intl.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-*/
-
-pragma solidity ^0.4.11;
-
-import "./UnlimitedAllowanceToken.sol";
-import "./../utils/SafeMath.sol";
-
-contract EtherToken is UnlimitedAllowanceToken, SafeMath {
-
- string constant public name = "Ether Token";
- string constant public symbol = "WETH";
- uint8 constant public decimals = 18;
-
- /// @dev Fallback to calling deposit when ether is sent directly to contract.
- function()
- public
- payable
- {
- deposit();
- }
-
- /// @dev Buys tokens with Ether, exchanging them 1:1.
- function deposit()
- public
- payable
- {
- balances[msg.sender] = safeAdd(balances[msg.sender], msg.value);
- totalSupply = safeAdd(totalSupply, msg.value);
- }
-
- /// @dev Sells tokens in exchange for Ether, exchanging them 1:1.
- /// @param amount Number of tokens to sell.
- function withdraw(uint amount)
- public
- {
- balances[msg.sender] = safeSub(balances[msg.sender], amount);
- totalSupply = safeSub(totalSupply, amount);
- require(msg.sender.send(amount));
- }
-}
-
diff --git a/packages/contracts/contracts/tokens/EtherToken_v2.sol b/packages/contracts/contracts/tokens/EtherToken_v2.sol
deleted file mode 100644
index f172c8e35..000000000
--- a/packages/contracts/contracts/tokens/EtherToken_v2.sol
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-
- Copyright 2017 ZeroEx Intl.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-*/
-
-pragma solidity 0.4.18;
-
-import "./UnlimitedAllowanceToken_v2.sol";
-import "./../utils/SafeMath_v2.sol";
-
-contract EtherToken_v2 is UnlimitedAllowanceToken_v2, SafeMath_v2 {
-
- string constant public name = "Ether Token";
- string constant public symbol = "WETH";
- string constant public version = "2.0.0"; // version 1.0.0 deployed on mainnet at 0x2956356cd2a2bf3202f771f50d3d14a367b48070
- uint8 constant public decimals = 18;
-
- /// @dev Fallback to calling deposit when ether is sent directly to contract.
- function()
- public
- payable
- {
- deposit();
- }
-
- /// @dev Buys tokens with Ether, exchanging them 1:1.
- function deposit()
- public
- payable
- {
- balances[msg.sender] = safeAdd(balances[msg.sender], msg.value);
- totalSupply = safeAdd(totalSupply, msg.value);
- Transfer(address(0), msg.sender, msg.value);
- }
-
- /// @dev Sells tokens in exchange for Ether, exchanging them 1:1.
- /// @param _value Number of tokens to sell.
- function withdraw(uint _value)
- public
- {
- balances[msg.sender] = safeSub(balances[msg.sender], _value);
- totalSupply = safeSub(totalSupply, _value);
- require(msg.sender.send(_value));
- Transfer(msg.sender, address(0), _value);
- }
-}
-
diff --git a/packages/contracts/deploy/migrations/migrate.ts b/packages/contracts/deploy/migrations/migrate.ts
index e2c220f68..d21d48a82 100644
--- a/packages/contracts/deploy/migrations/migrate.ts
+++ b/packages/contracts/deploy/migrations/migrate.ts
@@ -19,8 +19,7 @@ export const migrator = {
const tokenTransferProxy = await deployer.deployAndSaveAsync('TokenTransferProxy');
const zrxToken = await deployer.deployAndSaveAsync('ZRXToken');
- const etherToken = await deployer.deployAndSaveAsync('EtherToken');
- const makerEtherToken = await deployer.deployAndSaveAsync('WETH9');
+ const etherToken = await deployer.deployAndSaveAsync('WETH9');
const tokenReg = await deployer.deployAndSaveAsync('TokenRegistry');
const exchangeArgs = [zrxToken.address, tokenTransferProxy.address];
@@ -69,18 +68,6 @@ export const migrator = {
gas: addTokenGasEstimate,
},
);
- await tokenReg.addToken.sendTransactionAsync(
- makerEtherToken.address,
- 'Maker Ether Token',
- 'WETH9',
- 18,
- constants.NULL_BYTES,
- constants.NULL_BYTES,
- {
- from: owner,
- gas: addTokenGasEstimate,
- },
- );
for (const token of tokenInfo) {
const totalSupply = new BigNumber(0);
const args = [
diff --git a/packages/contracts/migrations/2_deploy_independent_contracts.ts b/packages/contracts/migrations/2_deploy_independent_contracts.ts
index 4bf316be6..b465db7db 100644
--- a/packages/contracts/migrations/2_deploy_independent_contracts.ts
+++ b/packages/contracts/migrations/2_deploy_independent_contracts.ts
@@ -4,7 +4,6 @@ const {
MultiSigWalletWithTimeLock,
TokenTransferProxy,
EtherToken,
- EtherTokenV2,
TokenRegistry,
} = new Artifacts(artifacts);
@@ -34,8 +33,6 @@ module.exports = (deployer: any, network: string, accounts: string[]) => {
return deployer.deploy(TokenRegistry);
}).then(() => {
return deployer.deploy(EtherToken);
- }).then(() => {
- return deployer.deploy(EtherTokenV2);
});
} else {
deployer.deploy([
diff --git a/packages/contracts/test/ts/ether_token_v2.ts b/packages/contracts/test/ts/ether_token_v2.ts
deleted file mode 100644
index 480c4035b..000000000
--- a/packages/contracts/test/ts/ether_token_v2.ts
+++ /dev/null
@@ -1,166 +0,0 @@
-import {ZeroEx, ZeroExError} from '0x.js';
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as chai from 'chai';
-import Web3 = require('web3');
-
-import {Artifacts} from '../../util/artifacts';
-import {constants} from '../../util/constants';
-
-import {chaiSetup} from './utils/chai_setup';
-
-const {EtherTokenV2} = new Artifacts(artifacts);
-
-chaiSetup.configure();
-const expect = chai.expect;
-
-// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle
-// with type `any` to a variable of type `Web3`.
-const web3: Web3 = (global as any).web3;
-
-contract('EtherTokenV2', (accounts: string[]) => {
- const account = accounts[0];
- const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
- let zeroEx: ZeroEx;
- let etherTokenAddress: string;
- beforeEach(async () => {
- const etherToken = await EtherTokenV2.new();
- etherTokenAddress = etherToken.address;
- zeroEx = new ZeroEx(web3.currentProvider, {
- gasPrice,
- networkId: constants.TESTRPC_NETWORK_ID,
- });
- });
-
- const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction);
- const getEthBalanceAsync = async (owner: string) => {
- const balanceStr = await promisify<string>(web3.eth.getBalance)(owner);
- const balance = new BigNumber(balanceStr);
- return balance;
- };
-
- describe('deposit', () => {
- it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
- const ethToDeposit = initEthBalance.plus(1);
-
- return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account))
- .to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit);
- });
-
- it('should convert deposited Ether to wrapped Ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(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 getEthBalanceAsync(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));
- });
-
- it('should log 1 event with correct arguments', async () => {
- const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
-
- const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const logs = receipt.logs;
- expect(logs.length).to.equal(1);
-
- const expectedFrom = ZeroEx.NULL_ADDRESS;
- const expectedTo = account;
- const expectedValue = ethToDeposit;
- const logArgs = (logs[0] as any).args;
- expect(logArgs._from).to.equal(expectedFrom);
- expect(logArgs._to).to.equal(expectedTo);
- expect(logArgs._value).to.be.bignumber.equal(expectedValue);
- });
- });
-
- describe('withdraw', () => {
- beforeEach(async () => {
- const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
- await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
- });
-
- it('should throw if caller attempts to withdraw greater than caller balance', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const ethTokensToWithdraw = initEthTokenBalance.plus(1);
-
- return expect(zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account))
- .to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
- });
-
- it('should convert ether tokens to ether with sufficient balance', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const initEthBalance = await getEthBalanceAsync(account);
- const ethTokensToWithdraw = initEthTokenBalance;
- expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
- const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
- gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
- });
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- expect(finalEthBalance).to.be.bignumber
- .equal(initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)));
- expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
- });
-
- it('should log 1 event with correct arguments', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const ethTokensToWithdraw = initEthTokenBalance;
- expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
- const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
- gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
- });
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const logs = receipt.logs;
- expect(logs.length).to.equal(1);
-
- const expectedFrom = account;
- const expectedTo = ZeroEx.NULL_ADDRESS;
- const expectedValue = ethTokensToWithdraw;
- const logArgs = (logs[0] as any).args;
- expect(logArgs._from).to.equal(expectedFrom);
- expect(logArgs._to).to.equal(expectedTo);
- expect(logArgs._value).to.be.bignumber.equal(expectedValue);
- });
- });
-
- describe('fallback', () => {
- it('should convert sent ether to ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
-
- const txHash = await sendTransactionAsync({
- from: account,
- to: etherTokenAddress,
- value: ethToDeposit,
- gasPrice,
- });
-
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(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));
- });
- });
-});
diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts
index 6b05df78c..14acd32a1 100644
--- a/packages/contracts/util/artifacts.ts
+++ b/packages/contracts/util/artifacts.ts
@@ -8,7 +8,6 @@ export class Artifacts {
public DummyToken: any;
public DummyTokenV2: any;
public EtherToken: any;
- public EtherTokenV2: any;
public MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: any;
public MaliciousToken: any;
constructor(artifacts: any) {
@@ -20,8 +19,7 @@ export class Artifacts {
this.ZRXToken = artifacts.require('ZRXToken');
this.DummyToken = artifacts.require('DummyToken');
this.DummyTokenV2 = artifacts.require('DummyToken_v2');
- this.EtherToken = artifacts.require('EtherToken');
- this.EtherTokenV2 = artifacts.require('EtherToken_v2');
+ this.EtherToken = artifacts.require('WETH9');
this.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = artifacts.require(
'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress');
this.MaliciousToken = artifacts.require('MaliciousToken');