Skip to content

Commit

Permalink
Hide erc677token method for amb-erc-to-native and amb-native-to-erc
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Jun 26, 2020
1 parent a45e63e commit 65c0a17
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
4 changes: 2 additions & 2 deletions contracts/upgradeable_contracts/BaseERC677Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "./ERC677Storage.sol";
import "../libraries/Bytes.sol";

contract BaseERC677Bridge is BasicTokenBridge, ERC677Receiver, ERC677Storage {
function erc677token() public view returns (ERC677) {
function _erc677token() internal view returns (ERC677) {
return ERC677(addressStorage[ERC677_TOKEN]);
}

Expand All @@ -18,7 +18,7 @@ contract BaseERC677Bridge is BasicTokenBridge, ERC677Receiver, ERC677Storage {
}

function onTokenTransfer(address _from, uint256 _value, bytes _data) external returns (bool) {
ERC677 token = erc677token();
ERC677 token = _erc677token();
require(msg.sender == address(token));
require(withinLimit(_value));
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_value));
Expand Down
4 changes: 4 additions & 0 deletions contracts/upgradeable_contracts/ERC677Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import "./BaseERC677Bridge.sol";
import "./OtherSideBridgeStorage.sol";

contract ERC677Bridge is BaseERC677Bridge, OtherSideBridgeStorage {
function erc677token() public view returns (ERC677) {
return _erc677token();
}

function bridgeSpecificActionsOnTokenTransfer(
ERC677, /*_token*/
address _from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
return isInitialized();
}

/**
* @dev Public getter for token contract.
* Internal _erc677token() is hidden from the end users, in order to not confuse them with the supported token standard.
* @return address of the used token contract
*/
function erc20token() external view returns (ERC677) {
return _erc677token();
}

/**
* @dev It will initiate the bridge operation that will lock the amount of tokens transferred and mint the native tokens on
* the other network. The user should first call Approve method of the ERC677 token.
Expand Down Expand Up @@ -81,7 +90,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
* otherwise it will be empty.
*/
function onTokenTransfer(address _from, uint256 _value, bytes _data) external returns (bool) {
ERC677 token = erc677token();
ERC677 token = _erc677token();
require(msg.sender == address(token));
if (!lock()) {
require(withinLimit(_value));
Expand All @@ -98,7 +107,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
* @param _to address that will receive the locked tokens on this contract.
*/
function claimTokens(address _token, address _to) public onlyIfUpgradeabilityOwner validAddress(_to) {
require(_token != address(erc677token()));
require(_token != address(_erc677token()));
claimValues(_token, _to);
}

Expand All @@ -116,7 +125,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
* @param _receiver the address that will receive the tokens on the other network
*/
function fixMediatorBalance(address _receiver) public onlyIfUpgradeabilityOwner {
uint256 balance = erc677token().balanceOf(address(this));
uint256 balance = _erc677token().balanceOf(address(this));
require(balance > mediatorBalance());
uint256 diff = balance.sub(mediatorBalance());
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(diff));
Expand All @@ -134,7 +143,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
bytes32 _messageId = messageId();

_setMediatorBalance(mediatorBalance().sub(valueToTransfer));
erc677token().transfer(_receiver, valueToTransfer);
_erc677token().transfer(_receiver, valueToTransfer);
emit TokensBridged(_receiver, valueToTransfer, _messageId);
}

Expand All @@ -145,7 +154,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
*/
function executeActionOnFixedTokens(address _receiver, uint256 _value) internal {
_setMediatorBalance(mediatorBalance().sub(_value));
erc677token().transfer(_receiver, _value);
_erc677token().transfer(_receiver, _value);
}

/**
Expand Down Expand Up @@ -179,7 +188,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
// When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract
// which will call passMessage.
require(!lock());
ERC677 token = erc677token();
ERC677 token = _erc677token();
address to = address(this);
require(withinLimit(_value));
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ contract BasicAMBErc677ToErc677 is
return isInitialized();
}

/**
* @dev Public getter for token contract.
* @return address of the used token contract
*/
function erc677token() public view returns (ERC677) {
return _erc677token();
}

function bridgeContractOnOtherSide() internal view returns (address) {
return mediatorContractOnOtherSide();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
return isInitialized();
}

/**
* @dev Public getter for token contract.
* Internal _erc677token() is hidden from the end users, in order to not confuse them with the supported token standard.
* @return address of the used token contract
*/
function erc20token() external view returns (ERC677) {
return _erc677token();
}

/**
* @dev Mint the amount of tokens that were bridged from the other network.
* If configured, it calculates, subtract and distribute the fees among the reward accounts.
Expand All @@ -71,7 +80,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
}
}

IBurnableMintableERC677Token(erc677token()).mint(_receiver, valueToMint);
IBurnableMintableERC677Token(_erc677token()).mint(_receiver, valueToMint);
emit TokensBridged(_receiver, valueToMint, _messageId);
}

Expand All @@ -81,7 +90,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
* @param _value amount of tokens to be received
*/
function executeActionOnFixedTokens(address _receiver, uint256 _value) internal {
IBurnableMintableERC677Token(erc677token()).mint(_receiver, _value);
IBurnableMintableERC677Token(_erc677token()).mint(_receiver, _value);
}

/**
Expand Down Expand Up @@ -109,7 +118,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
// When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract
// which will call passMessage.
require(!lock());
ERC677 token = erc677token();
ERC677 token = _erc677token();
address to = address(this);
require(withinLimit(_value));
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_value));
Expand Down Expand Up @@ -140,7 +149,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
* otherwise it will be empty.
*/
function onTokenTransfer(address _from, uint256 _value, bytes _data) external bridgeMessageAllowed returns (bool) {
ERC677 token = erc677token();
ERC677 token = _erc677token();
require(msg.sender == address(token));
if (!lock()) {
require(withinLimit(_value));
Expand Down Expand Up @@ -171,7 +180,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
* @param _fee amount of tokens to be minted.
*/
function onFeeDistribution(address _feeManager, uint256 _fee) internal {
IBurnableMintableERC677Token(erc677token()).mint(_feeManager, _fee);
IBurnableMintableERC677Token(_erc677token()).mint(_feeManager, _fee);
}

/**
Expand All @@ -180,7 +189,7 @@ contract ForeignAMBNativeToErc20 is BasicAMBNativeToErc20, ReentrancyGuard, Base
* @param _to address that will receive the locked tokens on this contract.
*/
function claimTokensFromErc677(address _token, address _to) external onlyIfUpgradeabilityOwner {
IBurnableMintableERC677Token(erc677token()).claimTokens(_token, _to);
IBurnableMintableERC677Token(_erc677token()).claimTokens(_token, _to);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/amb_erc20_to_native/foreign_mediator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract('ForeignAMBErc20ToNative', async accounts => {
expect(await contract.requestGasLimit()).to.be.bignumber.equal(ZERO)
expect(await contract.decimalShift()).to.be.bignumber.equal(ZERO)
expect(await contract.owner()).to.be.equal(ZERO_ADDRESS)
expect(await contract.erc677token()).to.be.equal(ZERO_ADDRESS)
expect(await contract.erc20token()).to.be.equal(ZERO_ADDRESS)

// When
// not valid bridge address
Expand Down Expand Up @@ -177,7 +177,7 @@ contract('ForeignAMBErc20ToNative', async accounts => {
expect(await contract.requestGasLimit()).to.be.bignumber.equal(maxGasPerTx)
expect(await contract.decimalShift()).to.be.bignumber.equal(ZERO)
expect(await contract.owner()).to.be.equal(owner)
expect(await contract.erc677token()).to.be.equal(token.address)
expect(await contract.erc20token()).to.be.equal(token.address)

expectEventInLogs(logs, 'ExecutionDailyLimitChanged', { newLimit: executionDailyLimit })
expectEventInLogs(logs, 'DailyLimitChanged', { newLimit: dailyLimit })
Expand Down
4 changes: 2 additions & 2 deletions test/amb_native_to_erc20/foreign_mediator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ contract('ForeignAMBNativeToErc20', async accounts => {
expect(await contract.requestGasLimit()).to.be.bignumber.equal(ZERO)
expect(await contract.decimalShift()).to.be.bignumber.equal(ZERO)
expect(await contract.owner()).to.be.equal(ZERO_ADDRESS)
expect(await contract.erc677token()).to.be.equal(ZERO_ADDRESS)
expect(await contract.erc20token()).to.be.equal(ZERO_ADDRESS)
expect(await contract.feeManagerContract()).to.be.equal(ZERO_ADDRESS)

// When
Expand Down Expand Up @@ -237,7 +237,7 @@ contract('ForeignAMBNativeToErc20', async accounts => {
expect(await contract.requestGasLimit()).to.be.bignumber.equal(maxGasPerTx)
expect(await contract.decimalShift()).to.be.bignumber.equal(ZERO)
expect(await contract.owner()).to.be.equal(owner)
expect(await contract.erc677token()).to.be.equal(token.address)
expect(await contract.erc20token()).to.be.equal(token.address)
expect(await contract.feeManagerContract()).to.be.equal(feeManager.address)

expectEventInLogs(logs, 'ExecutionDailyLimitChanged', { newLimit: executionDailyLimit })
Expand Down

0 comments on commit 65c0a17

Please sign in to comment.