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

Fix fixAssetsAboveLimits imbalance when feeManager enabled #218

Merged
merged 1 commit into from
Jul 1, 2019
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
8 changes: 7 additions & 1 deletion contracts/upgradeable_contracts/OverdrawManagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pragma solidity 0.4.24;
import "../upgradeability/EternalStorage.sol";
import "../libraries/SafeMath.sol";
import "./OwnedUpgradeability.sol";
import "./RewardableBridge.sol";


contract OverdrawManagement is EternalStorage, OwnedUpgradeability {
contract OverdrawManagement is EternalStorage, RewardableBridge, OwnedUpgradeability {
using SafeMath for uint256;

event UserRequestForSignature(address recipient, uint256 value);
Expand All @@ -18,6 +19,11 @@ contract OverdrawManagement is EternalStorage, OwnedUpgradeability {
require(recipient != address(0) && value > 0);
setOutOfLimitAmount(outOfLimitAmount().sub(value));
if (unlockOnForeign) {
address feeManager = feeManagerContract();
if (feeManager != address(0)) {
uint256 fee = calculateFee(value, false, feeManager, HOME_FEE);
value = value.sub(fee);
}
emit UserRequestForSignature(recipient, value);
}
setFixedAssets(txHash);
Expand Down
34 changes: 34 additions & 0 deletions test/erc_to_erc/home_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,40 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
.should.be.rejectedWith(ERROR_MSG)
await homeBridge.fixAssetsAboveLimits(transactionHash, true, { from: owner }).should.be.fulfilled
})
it('Should emit UserRequestForSignature with value reduced by fee', async () => {
const recipient = accounts[5]
const value = oneEther
const transactionHash = '0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415'

const feeManager = await FeeManagerErcToErcPOSDAO.new()
const fee = 0.001
const feeInWei = ether(fee.toString())
const valueCalc = 1 - fee
const finalValue = ether(valueCalc.toString())
await homeBridge.setFeeManagerContract(feeManager.address, { from: owner }).should.be.fulfilled
await homeBridge.setHomeFee(feeInWei, { from: owner }).should.be.fulfilled

const { logs: affirmationLogs } = await homeBridge.executeAffirmation(recipient, value, transactionHash, {
from: authorities[0]
}).should.be.fulfilled

expectEventInLogs(affirmationLogs, 'AmountLimitExceeded', {
recipient,
value,
transactionHash
})

const outOfLimitAmount = await homeBridge.outOfLimitAmount()
outOfLimitAmount.should.be.bignumber.equal(value)

const { logs } = await homeBridge.fixAssetsAboveLimits(transactionHash, true).should.be.fulfilled

logs.length.should.be.equal(1)
expectEventInLogs(logs, 'UserRequestForSignature', {
recipient,
value: finalValue
})
})
})

describe('#rewardableInitialize', async () => {
Expand Down
64 changes: 64 additions & 0 deletions test/erc_to_native/home_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,70 @@ contract('HomeBridge_ERC20_to_Native', async accounts => {
.should.be.rejectedWith(ERROR_MSG)
await homeBridge.fixAssetsAboveLimits(transactionHash, true, { from: owner }).should.be.fulfilled
})
it('Should emit UserRequestForSignature with value reduced by fee', async () => {
// Initialize
const owner = accounts[9]
const validators = [accounts[1]]
const rewards = [accounts[2]]
const requiredSignatures = 1
const rewardableValidators = await RewardableValidators.new()
const homeBridgeImpl = await HomeBridge.new()
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
await storageProxy.upgradeTo('1', homeBridgeImpl.address).should.be.fulfilled
const homeBridge = await HomeBridge.at(storageProxy.address)
await rewardableValidators.initialize(requiredSignatures, validators, rewards, owner, {
from: owner
}).should.be.fulfilled
await homeBridge.initialize(
rewardableValidators.address,
oneEther,
halfEther,
minPerTx,
gasPrice,
requireBlockConfirmations,
blockRewardContract.address,
foreignDailyLimit,
foreignMaxPerTx,
owner
).should.be.fulfilled
await blockRewardContract.sendTransaction({
from: accounts[2],
value: oneEther
}).should.be.fulfilled

// Given
// 0.1% fee
const fee = 0.001
const feeInWei = ether(fee.toString())
const feeManager = await FeeManagerErcToNative.new()
await homeBridge.setFeeManagerContract(feeManager.address, { from: owner }).should.be.fulfilled
await homeBridge.setHomeFee(feeInWei, { from: owner }).should.be.fulfilled

const recipient = accounts[5]
const value = oneEther
const valueCalc = 1 - fee
const finalValue = ether(valueCalc.toString())
const transactionHash = '0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415'

// When
const { logs: affirmationLogs } = await homeBridge.executeAffirmation(recipient, value, transactionHash, {
from: validators[0]
}).should.be.fulfilled

expectEventInLogs(affirmationLogs, 'AmountLimitExceeded', {
recipient,
value,
transactionHash
})

const { logs } = await homeBridge.fixAssetsAboveLimits(transactionHash, true).should.be.fulfilled

// Then
expectEventInLogs(logs, 'UserRequestForSignature', {
recipient,
value: finalValue
})
})
})

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