Skip to content

Commit

Permalink
Add claimTokensFromTokenContract function for HomeMultiAMBErc20ToErc6…
Browse files Browse the repository at this point in the history
…77 contract (#573)
  • Loading branch information
k1rill-fedoseev authored Feb 2, 2021
1 parent a85d9ab commit 8d11272
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ contract HomeMultiAMBErc20ToErc677 is

event NewTokenRegistered(address indexed foreignToken, address indexed homeToken);

/**
* @dev Throws if called by any account other than the owner.
* Overrides modifier from the Ownable contract in order to reduce bytecode size.
*/
modifier onlyOwner() {
_onlyOwner();
/* solcov ignore next */
_;
}

/**
* @dev Internal function for reducing onlyOwner modifier bytecode size overhead.
*/
function _onlyOwner() internal {
require(msg.sender == owner());
}

/**
* @dev Stores the initial parameters of the mediator.
* @param _bridgeContract the address of the AMB bridge contract.
Expand Down Expand Up @@ -320,14 +337,16 @@ contract HomeMultiAMBErc20ToErc677 is
}

/**
* @dev One-time upgrade function for transferring ownership of the STAKE token to the TokenMinter address.
* Should be called together with upgradeToAndCall function
* @dev Withdraws erc20 tokens or native coins from the bridged token contract.
* Only the proxy owner is allowed to call this method.
* @param _bridgedToken address of the bridged token contract.
* @param _token address of the claimed token or address(0) for native coins.
* @param _to address of the tokens/coins receiver.
*/
function transferTokenOwnership() external {
require(msg.sender == address(this));

Ownable(0xb7D311E2Eb55F2f68a9440da38e7989210b9A05e).transferOwnership(
0x1111111111111111111111111111111111111111
);
function claimTokensFromTokenContract(address _bridgedToken, address _token, address _to)
external
onlyIfUpgradeabilityOwner
{
IBurnableMintableERC677Token(_bridgedToken).claimTokens(_token, _to);
}
}
14 changes: 14 additions & 0 deletions test/multi_amb_erc20_to_erc677/home_mediator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ contract('HomeMultiAMBErc20ToErc677', async accounts => {
expect(toBN(await web3.eth.getBalance(contract.address))).to.be.bignumber.equal(ZERO)
expect(toBN(await web3.eth.getBalance(accounts[3]))).to.be.bignumber.equal(balanceBefore.add(oneEther))
})

it('should allow owner to claim tokens from token contract', async () => {
const homeToken = await bridgeToken(token)

await token.mint(user, 1).should.be.fulfilled
await token.transfer(homeToken.address, 1, { from: user }).should.be.fulfilled

await contract.claimTokensFromTokenContract(homeToken.address, token.address, accounts[3], { from: user }).should
.be.rejected
await contract.claimTokensFromTokenContract(homeToken.address, token.address, accounts[3], { from: owner }).should
.be.fulfilled

expect(await token.balanceOf(accounts[3])).to.be.bignumber.equal('1')
})
})

describe('afterInitialization', () => {
Expand Down

0 comments on commit 8d11272

Please sign in to comment.