Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace explicit module owner address with mediator owner #32

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions contracts/mocks/CompoundInterestERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import "../upgradeable_contracts/modules/interest/CompoundInterestERC20.sol";

contract CompoundInterestERC20Mock is CompoundInterestERC20 {
constructor(
address _omnibridge,
address _owner,
IOwnable _omnibridge,
uint256 _minCompPaid,
address _compReceiver
) CompoundInterestERC20(_omnibridge, _owner, _minCompPaid, _compReceiver) {}
) CompoundInterestERC20(_omnibridge, _minCompPaid, _compReceiver) {}

function comptroller() public pure override returns (IComptroller) {
return IComptroller(0x85e855b22F01BdD33eE194490c7eB16b7EdaC019);
Expand Down
30 changes: 0 additions & 30 deletions contracts/upgradeable_contracts/modules/MediatorOwnableModule.sol

This file was deleted.

44 changes: 44 additions & 0 deletions contracts/upgradeable_contracts/modules/OmnibridgeModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity 0.7.5;

import "@openzeppelin/contracts/utils/Address.sol";
import "../../interfaces/IOwnable.sol";

/**
* @title OmnibridgeModule
* @dev Common functionality for Omnibridge extension non-upgradeable module.
*/
abstract contract OmnibridgeModule is IOwnable {
IOwnable public mediator;

/**
* @dev Initializes this contract.
* @param _mediator address of the Omnibridge mediator contract that is allowed to perform additional actions on the particular module.
*/
constructor(IOwnable _mediator) {
mediator = _mediator;
}

/**
* @dev Throws if sender is not the owner of this contract.
*/
modifier onlyOwner {
require(msg.sender == owner());
_;
}

/**
* @dev Throws if sender is not the mediator.
*/
modifier onlyMediator {
require(msg.sender == address(mediator));
_;
}

/**
* Tells the contract owner address that is allowed to change configuration of this module.
* @return address of the owner account.
*/
function owner() public view override returns (address) {
return mediator.owner();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
pragma solidity 0.7.5;

import "./TokenProxy.sol";
import "../OwnableModule.sol";
import "../OmnibridgeModule.sol";

/**
* @title TokenFactory
* @dev Factory contract for deployment of new TokenProxy contracts.
*/
contract TokenFactory is OwnableModule {
contract TokenFactory is OmnibridgeModule {
address public tokenImage;

/**
* @dev Initializes this contract
* @param _owner of this factory contract.
* @param _mediator address of the mediator contract used together with this token factory.
* @param _tokenImage address of the token image contract that should be used for creation of new tokens.
*/
constructor(address _owner, address _tokenImage) OwnableModule(_owner) {
constructor(IOwnable _mediator, address _tokenImage) OmnibridgeModule(_mediator) {
tokenImage = _tokenImage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pragma solidity 0.7.5;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "../MediatorOwnableModule.sol";
import "../OmnibridgeModule.sol";

/**
* @title OmnibridgeFeeManager
* @dev Implements the logic to distribute fees from the Omnibridge mediator contract operations.
* The fees are distributed in the form of ERC20/ERC677 tokens to the list of reward addresses.
*/
contract OmnibridgeFeeManager is MediatorOwnableModule {
contract OmnibridgeFeeManager is OmnibridgeModule {
using SafeMath for uint256;
using SafeERC20 for IERC20;

Expand All @@ -31,17 +31,15 @@ contract OmnibridgeFeeManager is MediatorOwnableModule {
/**
* @dev Stores the initial parameters of the fee manager.
* @param _mediator address of the mediator contract used together with this fee manager.
* @param _owner address of the contract owner.
* @param _rewardAddresses list of unique initial reward addresses, between whom fees will be distributed
* @param _fees array with initial fees for both bridge directions.
* [ 0 = homeToForeignFee, 1 = foreignToHomeFee ]
*/
constructor(
address _mediator,
address _owner,
IOwnable _mediator,
address[] memory _rewardAddresses,
uint256[2] memory _fees
) MediatorOwnableModule(_mediator, _owner) {
) OmnibridgeModule(_mediator) {
require(_rewardAddresses.length <= MAX_REWARD_ACCOUNTS);
_setFee(HOME_TO_FOREIGN_FEE, address(0), _fees[0]);
_setFee(FOREIGN_TO_HOME_FEE, address(0), _fees[1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma solidity 0.7.5;

import "../OwnableModule.sol";
import "../OmnibridgeModule.sol";

/**
* @title MultiTokenForwardingRulesManager
* @dev Multi token mediator functionality for managing destination AMB lanes permissions.
*/
contract MultiTokenForwardingRulesManager is OwnableModule {
contract MultiTokenForwardingRulesManager is OmnibridgeModule {
address internal constant ANY_ADDRESS = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;

// Forwarding rules mapping
Expand All @@ -15,7 +15,7 @@ contract MultiTokenForwardingRulesManager is OwnableModule {

event ForwardingRuleUpdated(address token, address sender, address receiver, int256 lane);

constructor(address _owner) OwnableModule(_owner) {}
constructor(IOwnable _mediator) OmnibridgeModule(_mediator) {}

/**
* @dev Tells the destination lane for a particular bridge operation by checking several wildcard forwarding rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../../BasicOmnibridge.sol";
* @title SelectorTokenGasLimitManager
* @dev Multi token mediator functionality for managing request gas limits.
*/
contract SelectorTokenGasLimitManager is OwnableModule {
contract SelectorTokenGasLimitManager is OmnibridgeModule {
IAMB public immutable bridge;

uint256 internal defaultGasLimit;
Expand All @@ -17,9 +17,9 @@ contract SelectorTokenGasLimitManager is OwnableModule {

constructor(
IAMB _bridge,
address _owner,
IOwnable _mediator,
uint256 _gasLimit
) OwnableModule(_owner) {
) OmnibridgeModule(_mediator) {
require(_gasLimit <= _bridge.maxGasPerTx());
bridge = _bridge;
defaultGasLimit = _gasLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import "../../../interfaces/IComptroller.sol";
import "../../../interfaces/IOwnable.sol";
import "../../../interfaces/IInterestReceiver.sol";
import "../../../interfaces/IInterestImplementation.sol";
import "../MediatorOwnableModule.sol";
import "../OmnibridgeModule.sol";

/**
* @title CompoundInterestERC20
* @dev This contract contains token-specific logic for investing ERC20 tokens into Compound protocol.
*/
contract CompoundInterestERC20 is IInterestImplementation, MediatorOwnableModule {
contract CompoundInterestERC20 is IInterestImplementation, OmnibridgeModule {
using SafeMath for uint256;

event PaidInterest(address indexed token, address to, uint256 value);
Expand All @@ -33,11 +33,10 @@ contract CompoundInterestERC20 is IInterestImplementation, MediatorOwnableModule
address public compReceiver;

constructor(
address _omnibridge,
address _owner,
IOwnable _omnibridge,
uint256 _minCompPaid,
address _compReceiver
) MediatorOwnableModule(_omnibridge, _owner) {
) OmnibridgeModule(_omnibridge) {
minCompPaid = _minCompPaid;
compReceiver = _compReceiver;
}
Expand Down Expand Up @@ -121,7 +120,7 @@ contract CompoundInterestERC20 is IInterestImplementation, MediatorOwnableModule
uint256 invested = params.investedAmount;
uint256 redeemed = _safeWithdraw(_token, _amount > invested ? invested : _amount);
params.investedAmount = redeemed > invested ? 0 : invested - redeemed;
IERC20(_token).transfer(mediator, redeemed);
IERC20(_token).transfer(address(mediator), redeemed);
}

/**
Expand Down Expand Up @@ -188,9 +187,9 @@ contract CompoundInterestERC20 is IInterestImplementation, MediatorOwnableModule
// try to redeem all cTokens
if (cToken.redeem(cTokenBalance) != SUCCESS) {
// transfer cTokens as-is, if redeem has failed
cToken.transfer(mediator, cTokenBalance);
cToken.transfer(address(mediator), cTokenBalance);
}
IERC20(_token).transfer(mediator, IERC20(_token).balanceOf(address(this)));
IERC20(_token).transfer(address(mediator), IERC20(_token).balanceOf(address(this)));

delete params.cToken;
delete params.dust;
Expand Down
14 changes: 5 additions & 9 deletions deploy/src/omnibridge/foreign.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const { web3Foreign, deploymentAddress } = require('../web3')
const { deployContract, upgradeProxy } = require('../deploymentUtils')
const { EternalStorageProxy, ForeignOmnibridge, PermittableToken, TokenFactory } = require('../loadContracts')
const {
FOREIGN_TOKEN_FACTORY,
FOREIGN_ERC677_TOKEN_IMAGE,
FOREIGN_BRIDGE_OWNER,
FOREIGN_TOKEN_NAME_SUFFIX,
} = require('../loadEnv')
const { FOREIGN_TOKEN_FACTORY, FOREIGN_ERC677_TOKEN_IMAGE, FOREIGN_TOKEN_NAME_SUFFIX } = require('../loadEnv')

async function deployForeign() {
let nonce = await web3Foreign.eth.getTransactionCount(deploymentAddress)
Expand All @@ -16,7 +11,8 @@ async function deployForeign() {
network: 'foreign',
nonce: nonce++,
})
console.log('[Foreign] Bridge Mediator Storage: ', foreignBridgeStorage.options.address)
const storageAddress = foreignBridgeStorage.options.address
console.log('[Foreign] Bridge Mediator Storage: ', storageAddress)

let tokenFactory = FOREIGN_TOKEN_FACTORY
if (!tokenFactory) {
Expand All @@ -34,7 +30,7 @@ async function deployForeign() {
console.log('\n[Foreign] Using existing ERC677 token image: ', foreignTokenImage)
}
console.log('\n[Foreign] Deploying new token factory')
const factory = await deployContract(TokenFactory, [FOREIGN_BRIDGE_OWNER, foreignTokenImage], {
const factory = await deployContract(TokenFactory, [storageAddress, foreignTokenImage], {
network: 'foreign',
nonce: nonce++,
})
Expand Down Expand Up @@ -63,7 +59,7 @@ async function deployForeign() {

console.log('\nForeign part of OMNIBRIDGE has been deployed\n')
return {
foreignBridgeMediator: { address: foreignBridgeStorage.options.address },
foreignBridgeMediator: { address: storageAddress },
tokenFactory: { address: tokenFactory },
}
}
Expand Down
18 changes: 9 additions & 9 deletions deploy/src/omnibridge/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
HOME_ERC677_TOKEN_IMAGE,
HOME_TOKEN_FACTORY,
HOME_FORWARDING_RULES_MANAGER,
HOME_BRIDGE_OWNER,
HOME_REWARDABLE,
HOME_TRANSACTIONS_FEE,
FOREIGN_TRANSACTIONS_FEE,
Expand Down Expand Up @@ -33,7 +32,8 @@ async function deployHome() {
const homeBridgeStorage = await deployContract(EternalStorageProxy, [], {
nonce: nonce++,
})
console.log('[Home] Bridge Mediator Storage: ', homeBridgeStorage.options.address)
const storageAddress = homeBridgeStorage.options.address
console.log('[Home] Bridge Mediator Storage: ', storageAddress)

let tokenFactory = HOME_TOKEN_FACTORY
if (!tokenFactory) {
Expand All @@ -50,7 +50,7 @@ async function deployHome() {
console.log('\n[Home] Using existing ERC677 token image: ', homeTokenImage)
}
console.log('\n[Home] Deploying new token factory')
const factory = await deployContract(TokenFactory, [HOME_BRIDGE_OWNER, homeTokenImage], {
const factory = await deployContract(TokenFactory, [storageAddress, homeTokenImage], {
nonce: nonce++,
})
tokenFactory = factory.options.address
Expand All @@ -71,7 +71,7 @@ async function deployHome() {
`)
const manager = await deployContract(
OmnibridgeFeeManager,
[homeBridgeStorage.options.address, HOME_BRIDGE_OWNER, rewardList, [homeFeeInWei, foreignFeeInWei]],
[storageAddress, rewardList, [homeFeeInWei, foreignFeeInWei]],
{ nonce: nonce++ }
)
feeManager = manager.options.address
Expand All @@ -81,9 +81,9 @@ async function deployHome() {
let forwardingRulesManager = HOME_FORWARDING_RULES_MANAGER === false ? ZERO_ADDRESS : HOME_FORWARDING_RULES_MANAGER
if (forwardingRulesManager === '') {
console.log(`\n[Home] Deploying Forwarding Rules Manager contract with the following parameters:
OWNER: ${HOME_BRIDGE_OWNER}
MEDIATOR: ${storageAddress}
`)
const manager = await deployContract(MultiTokenForwardingRulesManager, [HOME_BRIDGE_OWNER], { nonce: nonce++ })
const manager = await deployContract(MultiTokenForwardingRulesManager, [storageAddress], { nonce: nonce++ })
forwardingRulesManager = manager.options.address
console.log('\n[Home] New Forwarding Rules Manager has been deployed: ', forwardingRulesManager)
} else {
Expand All @@ -92,11 +92,11 @@ async function deployHome() {

console.log(`\n[Home] Deploying gas limit manager contract with the following parameters:
HOME_AMB_BRIDGE: ${HOME_AMB_BRIDGE}
OWNER: ${HOME_BRIDGE_OWNER}
MEDIATOR: ${storageAddress}
`)
const gasLimitManager = await deployContract(
SelectorTokenGasLimitManager,
[HOME_AMB_BRIDGE, HOME_BRIDGE_OWNER, HOME_MEDIATOR_REQUEST_GAS_LIMIT],
[HOME_AMB_BRIDGE, storageAddress, HOME_MEDIATOR_REQUEST_GAS_LIMIT],
{ nonce: nonce++ }
)
console.log('\n[Home] New Gas Limit Manager has been deployed: ', gasLimitManager.options.address)
Expand All @@ -120,7 +120,7 @@ async function deployHome() {

console.log('\nHome part of OMNIBRIDGE has been deployed\n')
return {
homeBridgeMediator: { address: homeBridgeStorage.options.address },
homeBridgeMediator: { address: storageAddress },
tokenFactory: { address: tokenFactory },
feeManager: { address: feeManager },
gasLimitManager: { address: gasLimitManager.options.address },
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function deployWETHRouter(web3, options, bridge, WETH, owner) {
}

async function deployInterestImpl(web3, mediator, owner, cToken, options) {
const args = [toAddress(mediator), owner, '1', owner]
const args = [toAddress(mediator), '1', owner]
const contract = await deploy(web3, options, InterestImpl.abi, InterestImpl.bytecode, args)
await contract.methods.enableInterestToken(toAddress(cToken), toWei('1'), owner, toWei('1')).send({ from: owner })
console.log(`Deployed Interest implementation contract ${contract.options.address}`)
Expand Down
Loading