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

Add fee manager mode interface #150

Merged
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
2 changes: 2 additions & 0 deletions contracts/upgradeable_contracts/BaseFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ contract BaseFeeManager is EternalStorage {
distributeFeeProportionally(_fee, REWARD_FOR_TRANSFERRING_FROM_HOME);
}

function getFeeManagerMode() public pure returns(bytes4);

function random(uint256 _count) public view returns(uint256) {
return uint256(blockhash(block.number.sub(1))) % _count;
}
Expand Down
14 changes: 14 additions & 0 deletions contracts/upgradeable_contracts/RewardableBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ contract RewardableBridge is Ownable {
return fee;
}

function getFeeManagerMode() public view returns(bytes4) {
bytes4 mode;
bytes memory callData = abi.encodeWithSignature("getFeeManagerMode()");
address feeManager = feeManagerContract();
assembly {
let result := callcode(gas, feeManager, 0x0, add(callData, 0x20), mload(callData), 0, 4)
mode := mload(0)

switch result
case 0 { revert(0, 0) }
}
return mode;
}

function feeManagerContract() public view returns(address) {
return addressStorage[keccak256(abi.encodePacked("feeManagerContract"))];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import "../Sacrifice.sol";

contract FeeManagerErcToNative is BaseFeeManager {

function getFeeManagerMode() public pure returns(bytes4) {
return bytes4(keccak256(abi.encodePacked("manages-both-directions")));
}

function blockRewardContract() internal view returns(IBlockReward) {
return IBlockReward(addressStorage[keccak256(abi.encodePacked("blockRewardContract"))]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import "../Sacrifice.sol";

contract FeeManagerNativeToErc is BaseFeeManager {

function getFeeManagerMode() public pure returns(bytes4) {
return bytes4(keccak256(abi.encodePacked("manages-one-direction")));
}

function erc677token() public view returns(IBurnableMintableERC677Token) {
return IBurnableMintableERC677Token(addressStorage[keccak256(abi.encodePacked("erc677token"))]);
}
Expand Down
12 changes: 12 additions & 0 deletions test/erc_to_native/home_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,18 @@ contract('HomeBridge_ERC20_to_Native', async (accounts) => {
const bridgeFee = await homeBridge.getFee()
bridgeFee.should.be.bignumber.equal(fee)
})
it('should be able to get fee manager mode', async () => {
// Given
const feeManager = await FeeManagerErcToNative.new()
const bothDirectionsModeHash = '0xd7de965f'

// When
await homeBridge.setFeeManagerContract(feeManager.address, { from: owner }).should.be.fulfilled

// Then
const feeManagerMode = await homeBridge.getFeeManagerMode()
feeManagerMode.should.be.equals(bothDirectionsModeHash)
})
})
describe('#feeManager_ExecuteAffirmation', async () => {
it('should distribute fee to validator', async () => {
Expand Down
13 changes: 13 additions & 0 deletions test/native_to_erc/foreign_bridge_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,19 @@ contract('ForeignBridge', async (accounts) => {
const bridgeFee = await foreignBridge.getFee()
bridgeFee.should.be.bignumber.equal(newFee)
})

it('should be able to get fee manager mode', async () => {
// Given
const feeManager = await FeeManagerNativeToErc.new()
const oneDirectionsModeHash = '0xf2aed8f7'

// When
await foreignBridge.rewardableInitialize(rewardableValidators.address, token.address, oneEther, halfEther, minPerTx, gasPrice, requireBlockConfirmations, homeDailyLimit, homeMaxPerTx, owner, feeManager.address, fee).should.be.fulfilled;

// Then
const feeManagerMode = await foreignBridge.getFeeManagerMode()
feeManagerMode.should.be.equals(oneDirectionsModeHash)
})
})

describe('#RewardableBridge_executeSignatures', async () => {
Expand Down
12 changes: 12 additions & 0 deletions test/native_to_erc/home_bridge_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,18 @@ contract('HomeBridge', async (accounts) => {
const bridgeFee = await homeBridge.getFee()
bridgeFee.should.be.bignumber.equal(newFee)
})
it('should be able to get fee manager mode', async () => {
// Given
const feeManager = await FeeManagerNativeToErc.new()
const oneDirectionsModeHash = '0xf2aed8f7'

// When
await homeBridge.rewardableInitialize(rewardableValidators.address, oneEther, halfEther, minPerTx, gasPrice, requireBlockConfirmations, foreignDailyLimit, foreignMaxPerTx, owner, feeManager.address, fee).should.be.fulfilled;

// Then
const feeManagerMode = await homeBridge.getFeeManagerMode()
feeManagerMode.should.be.equals(oneDirectionsModeHash)
})
})

describe('#feeManager_ExecuteAffirmation', async () => {
Expand Down