Skip to content

Commit

Permalink
Merge 0bc5874 into a362a74
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov committed May 6, 2020
2 parents a362a74 + 0bc5874 commit 648e326
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
@@ -1,9 +1,15 @@
node_modules
deploy/node_modules
.git
.gitignore
.dockerignore
deploy/.env
deploy/*.config
docker-compose.yml
Dockerfile
*.log
flats
contracts.sublime-project
contracts.sublime-workspace
upgrade/.env*
!upgrade/.env.example
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,7 @@ flats
.idea
coverage
*.sublime-*
.0x-artifacts
.0x-artifacts
upgrade/.env*
deploy/.env
deploy/*.config
18 changes: 17 additions & 1 deletion Dockerfile
Expand Up @@ -18,9 +18,25 @@ COPY ./upgrade/package.json ./upgrade/
COPY ./upgrade/package-lock.json ./upgrade/
RUN cd ./upgrade; npm install; cd ..

COPY . .
COPY ./scripts ./scripts

COPY truffle-config.js truffle-config.js
COPY ./contracts ./contracts
RUN npm run compile

COPY flatten.sh flatten.sh
RUN bash flatten.sh

COPY .eslintignore .eslintignore
COPY .eslintrc .eslintrc
COPY .prettierrc .prettierrc

COPY ./upgrade ./upgrade
COPY deploy.sh deploy.sh
COPY ./deploy ./deploy
COPY .solhint.json .solhint.json
COPY codechecks.yml codechecks.yml
COPY ./test ./test

ENV PATH="/contracts/:${PATH}"
ENV NOFLAT=true
Expand Up @@ -45,7 +45,8 @@ contract HomeStakeTokenFeeManager is BlockRewardBridge, Ownable {
}

/**
* @dev Sets the fee percentage amount for the mediator operations. Only the owner can call this method.
* @dev Sets the fee percentage amount for the mediator operations.
* Only the owner can call this method.
* @param _fee the fee percentage
*/
function setFee(uint256 _fee) external onlyOwner {
Expand All @@ -61,4 +62,25 @@ contract HomeStakeTokenFeeManager is BlockRewardBridge, Ownable {
uintStorage[FEE] = _fee;
emit FeeUpdated(_fee);
}

/**
* @dev Returns the state of the fee manager configuration: whether
* it is ready to collect and distribute fee or not.
*/
function isFeeCollectingActivated() public view returns (bool) {
return ((address(_blockRewardContract()) != address(0)) && (getFee() > 0));
}

/**
* @dev Distributes fee as per the logic of the fee manager.
* In this particular case, the amount of fee is passed the block
* reward contract which will mint new tokens and distribute them
* among the stakers.
* @param _fee amount of tokens to be distributed
*/
function _distributeFee(uint256 _fee) internal {
if (address(_blockRewardContract()) != address(0)) {
_blockRewardContract().addBridgeTokenRewardReceivers(_fee);
}
}
}
Expand Up @@ -2,7 +2,6 @@ pragma solidity 0.4.24;

import "../../interfaces/IMintHandler.sol";
import "./BasicStakeTokenMediator.sol";
import "../BlockRewardBridge.sol";
import "./HomeStakeTokenFeeManager.sol";
import "../../interfaces/IBurnableMintableERC677Token.sol";

Expand Down Expand Up @@ -141,17 +140,16 @@ contract HomeStakeTokenMediator is BasicStakeTokenMediator, HomeStakeTokenFeeMan
// burn all incoming tokens
IBurnableMintableERC677Token(_token).burn(_value);

if (address(_blockRewardContract()) == address(0)) {
// in case if block reward contract is not configured, the fee is not collected
passMessage(_from, chooseReceiver(_from, _data), _value);
} else {
// when block reward contract is defined, the calculated fee is subtracted from the original value
if (isFeeCollectingActivated()) {
uint256 fee = calculateFee(_value);
// the calculated fee is subtracted from the original value
passMessage(_from, chooseReceiver(_from, _data), _value.sub(fee));
if (fee > 0) {
// the fee itself is distributed later in the block reward contract
_blockRewardContract().addBridgeTokenRewardReceivers(fee);
// the fee manager will take care about fee distribution
_distributeFee(fee);
}
} else {
passMessage(_from, chooseReceiver(_from, _data), _value);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/stake_token_mediators/home_mediator.test.js
Expand Up @@ -198,6 +198,31 @@ contract('HomeStakeTokenMediator', async accounts => {
})
})

describe('isFeeCollectingActivated', async () => {
it('should return false when no block reward and no fee', async () => {
expect(await homeMediator.isFeeCollectingActivated()).to.be.equal(false)
})

it('should return false when block reward is configured but no fee', async () => {
await homeMediator.setBlockRewardContract(blockReward.address)

expect(await homeMediator.isFeeCollectingActivated()).to.be.equal(false)
})

it('should return false when no block reward but fee is set', async () => {
await homeMediator.setFee(ether('0.05'), { from: owner }).should.be.fulfilled

expect(await homeMediator.isFeeCollectingActivated()).to.be.equal(false)
})

it('should return true when both block reward and fee are configured', async () => {
await homeMediator.setFee(ether('0.05'), { from: owner }).should.be.fulfilled
await homeMediator.setBlockRewardContract(blockReward.address)

expect(await homeMediator.isFeeCollectingActivated()).to.be.equal(true)
})
})

describe('calculateFee', async () => {
it('should calculate fee for given value', async () => {
expect(await homeMediator.calculateFee(ether('0'))).to.be.bignumber.equal(ZERO)
Expand Down

0 comments on commit 648e326

Please sign in to comment.