Skip to content

Commit

Permalink
Change inheritance in token contract
Browse files Browse the repository at this point in the history
  • Loading branch information
varasev committed May 4, 2020
1 parent 988b69b commit 34bf411
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 119 deletions.
12 changes: 6 additions & 6 deletions contracts/ERC677BridgeToken.sol
@@ -1,24 +1,24 @@
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import "openzeppelin-solidity/contracts/AddressUtils.sol";
import "./interfaces/IBurnableMintableERC677Token.sol";
import "./upgradeable_contracts/Claimable.sol";
import "./PermittableToken.sol";

/**
* @title ERC677BridgeToken
* @dev The basic implementation of a bridgeable ERC677-compatible token
*/
contract ERC677BridgeToken is PermittableToken, Claimable {
contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, BurnableToken, MintableToken, Claimable {
bytes4 internal constant ON_TOKEN_TRANSFER = 0xa4c0ed36; // onTokenTransfer(address,uint256,bytes)

address internal bridgeContractAddr;

event ContractFallbackCallFailed(address from, address to, uint256 value);

constructor(string _name, string _symbol, uint8 _decimals, uint256 _chainId)
public
PermittableToken(_name, _symbol, _decimals, _chainId)
{
constructor(string _name, string _symbol, uint8 _decimals) public DetailedERC20(_name, _symbol, _decimals) {
// solhint-disable-previous-line no-empty-blocks
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/ERC677MultiBridgeToken.sol
@@ -1,12 +1,12 @@
pragma solidity 0.4.24;

import "./ERC677BridgeToken.sol";
import "./PermittableToken.sol";

/**
* @title ERC677MultiBridgeToken
* @dev This contract extends ERC677BridgeToken to support several bridge simulteniously
*/
contract ERC677MultiBridgeToken is ERC677BridgeToken {
contract ERC677MultiBridgeToken is PermittableToken {
address public constant F_ADDR = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;
uint256 internal constant MAX_BRIDGES = 50;
mapping(address => address) public bridgePointers;
Expand All @@ -17,7 +17,7 @@ contract ERC677MultiBridgeToken is ERC677BridgeToken {

constructor(string _name, string _symbol, uint8 _decimals, uint256 _chainId)
public
ERC677BridgeToken(_name, _symbol, _decimals, _chainId)
PermittableToken(_name, _symbol, _decimals, _chainId)
{
bridgePointers[F_ADDR] = F_ADDR; // empty bridge contracts list
}
Expand Down
10 changes: 4 additions & 6 deletions contracts/PermittableToken.sol
@@ -1,11 +1,8 @@
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import "./interfaces/IBurnableMintableERC677Token.sol";
import "./ERC677BridgeToken.sol";

contract PermittableToken is IBurnableMintableERC677Token, DetailedERC20, BurnableToken, MintableToken {
contract PermittableToken is ERC677BridgeToken {
string public constant version = "1";

// EIP712 niceties
Expand All @@ -18,7 +15,7 @@ contract PermittableToken is IBurnableMintableERC677Token, DetailedERC20, Burnab

constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _chainId)
public
DetailedERC20(_name, _symbol, _decimals)
ERC677BridgeToken(_name, _symbol, _decimals)
{
require(_chainId != 0);
DOMAIN_SEPARATOR = keccak256(
Expand Down Expand Up @@ -66,6 +63,7 @@ contract PermittableToken is IBurnableMintableERC677Token, DetailedERC20, Burnab
// the function works just like `transfer()`
}

callAfterTransfer(_sender, _recipient, _amount);
return true;
}

Expand Down
10 changes: 7 additions & 3 deletions deploy/src/amb_erc677_to_erc677/home.js
Expand Up @@ -62,11 +62,15 @@ async function deployHome() {

console.log('\n[Home] deploying Bridgeable token')
const erc677Contract = DEPLOY_REWARDABLE_TOKEN ? ERC677BridgeTokenRewardable : ERC677BridgeToken
const chainId = await web3Home.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
let args = [BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS]
if (DEPLOY_REWARDABLE_TOKEN) {
const chainId = await web3Home.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
args.push(chainId)
}
const erc677token = await deployContract(
erc677Contract,
[BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS, chainId],
args,
{ from: DEPLOYMENT_ACCOUNT_ADDRESS, network: 'home', nonce }
)
nonce++
Expand Down
16 changes: 9 additions & 7 deletions deploy/src/erc_to_erc/home.js
Expand Up @@ -229,15 +229,17 @@ async function deployHome() {
nonce++

console.log('\n[Home] deploying Bridgeable token')
const erc677Contract =
(isRewardableBridge && BLOCK_REWARD_ADDRESS !== ZERO_ADDRESS) || DEPLOY_REWARDABLE_TOKEN
? ERC677BridgeTokenRewardable
: ERC677BridgeToken
const chainId = await web3Home.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
const rewardable = (isRewardableBridge && BLOCK_REWARD_ADDRESS !== ZERO_ADDRESS) || DEPLOY_REWARDABLE_TOKEN
const erc677Contract = rewardable ? ERC677BridgeTokenRewardable : ERC677BridgeToken
let args = [BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS]
if (rewardable) {
const chainId = await web3Home.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
args.push(chainId)
}
const erc677token = await deployContract(
erc677Contract,
[BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS, chainId],
args,
{ from: DEPLOYMENT_ACCOUNT_ADDRESS, network: 'home', nonce }
)
nonce++
Expand Down
10 changes: 7 additions & 3 deletions deploy/src/native_to_erc/foreign.js
Expand Up @@ -170,11 +170,15 @@ async function deployForeign(homeBridgeAddress) {
console.log('========================================\n')

console.log('\n[Foreign] deploying bridgeable token')
const chainId = await web3Foreign.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
let args = [BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS]
if (DEPLOY_REWARDABLE_TOKEN) {
const chainId = await web3Foreign.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
args.push(chainId)
}
const erc677bridgeToken = await deployContract(
DEPLOY_REWARDABLE_TOKEN ? ERC677BridgeTokenRewardable : ERC677BridgeToken,
[BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS, chainId],
args,
{ from: DEPLOYMENT_ACCOUNT_ADDRESS, network: 'foreign', nonce }
)
nonce++
Expand Down
4 changes: 1 addition & 3 deletions deploy/src/utils/deployERC20Token.js
Expand Up @@ -20,12 +20,10 @@ const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVAT

async function deployToken() {
let foreignNonce = await web3Foreign.eth.getTransactionCount(DEPLOYMENT_ACCOUNT_ADDRESS)
const chainId = await web3Foreign.eth.net.getId()
assert.strictEqual(chainId > 0, true, 'Invalid chain ID')
console.log('\n[Foreign] deploying ERC20 token')
const erc677token = await deployContract(
ERC677BridgeToken,
[BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS, chainId],
[BRIDGEABLE_TOKEN_NAME, BRIDGEABLE_TOKEN_SYMBOL, BRIDGEABLE_TOKEN_DECIMALS],
{ from: DEPLOYMENT_ACCOUNT_ADDRESS, network: 'foreign', nonce: foreignNonce }
)
foreignNonce++
Expand Down
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions test/amb_erc677_to_erc677/AMBErc677ToErc677Behavior.test.js
Expand Up @@ -31,7 +31,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
})
it('should initialize', async function() {
const contract = this.bridge
Expand Down Expand Up @@ -258,7 +258,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

contract = this.bridge

Expand Down Expand Up @@ -340,7 +340,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

contract = this.proxyContract

Expand Down Expand Up @@ -692,7 +692,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
})
it('should prevent emitting the event twice when ERC677 used by relayTokens and ERC677 is owned by token manager', async function() {
// Given
const erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
const erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled
await erc677Token.setBridgeContract(contract.address, { from: owner }).should.be.fulfilled
await erc677Token.transferOwnership(contract.address, { from: owner }).should.be.fulfilled
Expand Down Expand Up @@ -727,7 +727,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
})
it('should prevent emitting the event twice when ERC677 used by relayTokens and ERC677 is not owned by token manager', async function() {
// Given
const erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
const erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled

contract = this.bridge
Expand Down Expand Up @@ -766,7 +766,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

contract = this.proxyContract

Expand Down Expand Up @@ -875,7 +875,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled

contract = this.bridge
Expand Down Expand Up @@ -999,7 +999,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
bridgeContract = await AMBMock.new()
await bridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await otherSideMediatorContract.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled

contract = this.bridge
Expand Down Expand Up @@ -1089,7 +1089,7 @@ function shouldBehaveLikeBasicAMBErc677ToErc677(otherSideMediatorContract, accou
owner
).should.be.fulfilled

const tokenSecond = await ERC677BridgeToken.new('Test Token', 'TST', 18, 100)
const tokenSecond = await ERC677BridgeToken.new('Test Token', 'TST', 18)

await tokenSecond.mint(accounts[0], halfEther).should.be.fulfilled
expect(await tokenSecond.balanceOf(accounts[0])).to.be.bignumber.equal(halfEther)
Expand Down
6 changes: 3 additions & 3 deletions test/amb_erc677_to_erc677/foreign_bridge.test.js
Expand Up @@ -47,7 +47,7 @@ contract('ForeignAMBErc677ToErc677', async accounts => {
ambBridgeContract = await ForeignAMB.new()
await ambBridgeContract.initialize(validatorContract.address, maxGasPerTx, '1', '1', owner)
mediatorContract = await HomeAMBErc677ToErc677.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled

foreignBridge = await ForeignAMBErc677ToErc677.new()
Expand Down Expand Up @@ -121,7 +121,7 @@ contract('ForeignAMBErc677ToErc677', async accounts => {
ambBridgeContract = await AMBMock.new()
await ambBridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await HomeAMBErc677ToErc677.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

foreignBridge = await ForeignAMBErc677ToErc677.new()
await foreignBridge.initialize(
Expand Down Expand Up @@ -187,7 +187,7 @@ contract('ForeignAMBErc677ToErc677', async accounts => {
it('should transfer locked tokens on message from amb with decimal shift of two', async () => {
// Given
const decimalShiftTwo = 2
erc677Token = await ERC677BridgeToken.new('test', 'TST', 16, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 16)

foreignBridge = await ForeignAMBErc677ToErc677.new()
await foreignBridge.initialize(
Expand Down
6 changes: 3 additions & 3 deletions test/amb_erc677_to_erc677/home_bridge.test.js
Expand Up @@ -47,7 +47,7 @@ contract('HomeAMBErc677ToErc677', async accounts => {
ambBridgeContract = await HomeAMB.new()
await ambBridgeContract.initialize(validatorContract.address, maxGasPerTx, '1', '1', owner)
mediatorContract = await ForeignAMBErc677ToErc677.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled

homeBridge = await HomeAMBErc677ToErc677.new()
Expand Down Expand Up @@ -127,7 +127,7 @@ contract('HomeAMBErc677ToErc677', async accounts => {
ambBridgeContract = await AMBMock.new()
await ambBridgeContract.setMaxGasPerTx(maxGasPerTx)
mediatorContract = await ForeignAMBErc677ToErc677.new()
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

homeBridge = await HomeAMBErc677ToErc677.new()
await homeBridge.initialize(
Expand Down Expand Up @@ -193,7 +193,7 @@ contract('HomeAMBErc677ToErc677', async accounts => {
it('should mint tokens on message from amb with decimal shift of two', async () => {
// Given
const decimalShiftTwo = 2
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18, 100)
erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)

homeBridge = await HomeAMBErc677ToErc677.new()
await homeBridge.initialize(
Expand Down

0 comments on commit 34bf411

Please sign in to comment.