diff --git a/contracts/FundsRecovery.sol b/contracts/FundsRecovery.sol index db803a9..9a74546 100644 --- a/contracts/FundsRecovery.sol +++ b/contracts/FundsRecovery.sol @@ -30,7 +30,7 @@ contract FundsRecovery is Ownable, ReentrancyGuard { /** * Possibility to recover funds in case they were sent to this address before smart contract deployment */ - function claimEthers() public nonReentrant { + function claimNativeCoin() public nonReentrant { require(fundsDestination != address(0)); fundsDestination.transfer(address(this).balance); } diff --git a/contracts/HermesImplementation.sol b/contracts/HermesImplementation.sol index 1cffa9b..c955310 100644 --- a/contracts/HermesImplementation.sol +++ b/contracts/HermesImplementation.sol @@ -110,11 +110,7 @@ contract HermesImplementation is FundsRecovery, Utils { event HermesStakeIncreased(uint256 newStake); event HermesPunishmentActivated(uint256 activationBlockTime); event HermesPunishmentDeactivated(); - - modifier onlyOperator() { - require(msg.sender == operator, "Hermes: only hermes operator can call this function"); - _; - } + event HermesStakeReturned(address beneficiary); /* ------------------------------------------- SETUP ------------------------------------------- @@ -183,7 +179,7 @@ contract HermesImplementation is FundsRecovery, Utils { Channel storage _channel = channels[_channelId]; require(_channel.settled > 0 || _channel.stake >= minStake || _ignoreStake, "Hermes: not enough stake"); - // If there are not enought funds to rebalance we have to enable punishment mode. + // If there are not enough funds to rebalance we have to enable punishment mode. uint256 _availableBalance = availableBalance(); if (_availableBalance < _channel.stake) { status = Status.Punishment; @@ -293,7 +289,7 @@ contract HermesImplementation is FundsRecovery, Utils { // Anyone can increase channel's capacity by staking more into hermes function increaseStake(bytes32 _channelId, uint256 _amount) public { - require(getStatus() != Status.Closed, "hermes should be not closed"); + require(getStatus() != Status.Closed, "Hermes: should be not closed"); _increaseStake(_channelId, _amount, false); } @@ -326,7 +322,7 @@ contract HermesImplementation is FundsRecovery, Utils { _channel.stake = _newStakeAmount; totalStake = totalStake - _amount; - // Pay transacor fee then withdraw the rest + // Pay transactor fee then withdraw the rest if (_transactorFee > 0) { token.transfer(msg.sender, _transactorFee); } @@ -345,21 +341,19 @@ contract HermesImplementation is FundsRecovery, Utils { function resolveEmergency() public { require(getStatus() == Status.Punishment, "Hermes: should be in punishment status"); - // 0.04% of total channels amount per time unit - uint256 _punishmentPerUnit = round(totalStake * PUNISHMENT_PERCENT, 100) / 100; - // No punishment during first time unit uint256 _unit = getUnitTime(); uint256 _timePassed = block.timestamp - punishment.activationBlockTime; uint256 _punishmentUnits = round(_timePassed, _unit) / _unit - 1; - uint256 _punishmentAmount = _punishmentUnits * _punishmentPerUnit; + // Using 0.04% of total channels amount per time unit + uint256 _punishmentAmount = _punishmentUnits * round(totalStake * PUNISHMENT_PERCENT, 100) / 100; punishment.amount = punishment.amount + _punishmentAmount; // XXX alternativelly we could send tokens into BlackHole (0x0000000...) uint256 _shouldHave = minimalExpectedBalance() + maxStake; // hermes should have funds for at least one maxStake settlement uint256 _currentBalance = token.balanceOf(address(this)); - // If there are not enough available funds, they have to be topuped from msg.sender. + // If there are not enough available funds, they have to be topupped from msg.sender. if (_currentBalance < _shouldHave) { token.transferFrom(msg.sender, address(this), _shouldHave - _currentBalance); } @@ -445,13 +439,13 @@ contract HermesImplementation is FundsRecovery, Utils { return _status != Status.Punishment && _status != Status.Closed; } - function pauseChannelOpening() public onlyOperator { + function pauseChannelOpening() public onlyOwner { require(getStatus() == Status.Active, "Hermes: have to be in active state"); status = Status.Paused; emit ChannelOpeningPaused(); } - function activateChannelOpening() public onlyOperator { + function activateChannelOpening() public onlyOwner { require(getStatus() == Status.Paused, "Hermes: have to be in paused state"); status = Status.Active; emit ChannelOpeningActivated(); @@ -470,6 +464,8 @@ contract HermesImplementation is FundsRecovery, Utils { uint256 _amount = token.balanceOf(address(this)) - punishment.amount; token.transfer(_beneficiary, _amount); + + emit HermesStakeReturned(_beneficiary); } /* diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol index 57465ba..021f238 100644 --- a/contracts/Migrations.sol +++ b/contracts/Migrations.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0; +pragma solidity 0.8.9; contract Migrations { address public owner; diff --git a/contracts/Registry.sol b/contracts/Registry.sol index 8b981ef..b39c421 100644 --- a/contracts/Registry.sol +++ b/contracts/Registry.sol @@ -17,7 +17,7 @@ contract Registry is FundsRecovery, Utils { uint256 public lastNonce; address payable public dex; // Any uniswap v2 compatible DEX router address uint256 public minimalHermesStake; - Registry public parentRegistry; // If there is parent registry, we will check for + Registry public parentRegistry; // Contract could have parent registry if Registry SC was already upgraded struct Implementation { address channelImplAddress; @@ -87,7 +87,7 @@ contract Registry is FundsRecovery, Utils { // Tokens amount to get from channel to cover tx fee and provider's stake uint256 _totalFee = _stakeAmount + _transactorFee; - require(_totalFee <= token.balanceOf(getChannelAddress(_identity, _hermesId)), "Registry: not enought funds in channel to cover fees"); + require(_totalFee <= token.balanceOf(getChannelAddress(_identity, _hermesId)), "Registry: not enough funds in channel to cover fees"); // Open consumer channel _openChannel(_identity, _hermesId, _beneficiary, _totalFee); @@ -111,7 +111,7 @@ contract Registry is FundsRecovery, Utils { address _identity = keccak256(abi.encodePacked(getChainID(), address(this), _hermesId, _transactorFee)).recover(_signature); require(_identity != address(0), "Registry: wrong channel openinig signature"); - require(_transactorFee <= token.balanceOf(getChannelAddress(_identity, _hermesId)), "Registry: not enought funds in channel to cover fees"); + require(_transactorFee <= token.balanceOf(getChannelAddress(_identity, _hermesId)), "Registry: not enough funds in channel to cover fees"); _openChannel(_identity, _hermesId, address(0), _transactorFee); } diff --git a/contracts/interfaces/IERC20Token.sol b/contracts/interfaces/IERC20Token.sol index 29ea799..046106e 100644 --- a/contracts/interfaces/IERC20Token.sol +++ b/contracts/interfaces/IERC20Token.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.8.4; +pragma solidity 0.8.9; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/interfaces/IHermesContract.sol b/contracts/interfaces/IHermesContract.sol index 01662d6..3bef1d6 100644 --- a/contracts/interfaces/IHermesContract.sol +++ b/contracts/interfaces/IHermesContract.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.6; +pragma solidity 0.8.9; interface IHermesContract { enum Status { Active, Paused, Punishment, Closed } diff --git a/contracts/interfaces/IUniswapV2Router.sol b/contracts/interfaces/IUniswapV2Router.sol index 295eb68..531e012 100644 --- a/contracts/interfaces/IUniswapV2Router.sol +++ b/contracts/interfaces/IUniswapV2Router.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.8.4; +pragma solidity 0.8.9; interface IUniswapV2Router { function factory() external pure returns (address); diff --git a/contracts/interfaces/IUpgradeAgent.sol b/contracts/interfaces/IUpgradeAgent.sol index ca773be..636d5ee 100644 --- a/contracts/interfaces/IUpgradeAgent.sol +++ b/contracts/interfaces/IUpgradeAgent.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.8.4; +pragma solidity 0.8.9; /** * Upgrade agent interface inspired by Lunyr. diff --git a/test/fundsRecovery.js b/test/fundsRecovery.js index 141dd62..450009a 100644 --- a/test/fundsRecovery.js +++ b/test/fundsRecovery.js @@ -54,7 +54,7 @@ contract('General tests for funds recovery', ([txMaker, owner, fundsDestination, it('anyone should successfully claim ethers', async () => { const initialBalance = await web3.eth.getBalance(fundsDestination) - await contract.claimEthers().should.be.fulfilled + await contract.claimNativeCoin().should.be.fulfilled const expectedBalance = Number(initialBalance) + topupAmount expect(await web3.eth.getBalance(fundsDestination)).to.be.equal(expectedBalance.toString()) @@ -112,7 +112,7 @@ contract('Registry funds recovery', ([_, txMaker, identity, account, fundsDestin it('should recover ethers sent to registry before its deployment', async () => { const initialBalance = new BN(await web3.eth.getBalance(fundsDestination)) const amount = new BN(topupAmount.toString()) - await registry.claimEthers().should.be.fulfilled + await registry.claimNativeCoin().should.be.fulfilled const expectedBalance = initialBalance.add(amount) expect(await web3.eth.getBalance(fundsDestination)).to.be.equal(expectedBalance.toString()) }) @@ -161,7 +161,7 @@ contract('Channel implementation funds recovery', ([_, txMaker, identity, identi it('should recover ethers sent to identity implementation before its deployment', async () => { const initialBalance = new BN(await web3.eth.getBalance(fundsDestination)) const amount = new BN(topupAmount.toString()) - await channelImplementation.claimEthers().should.be.fulfilled + await channelImplementation.claimNativeCoin().should.be.fulfilled const expectedBalance = initialBalance.add(amount) expect(await web3.eth.getBalance(fundsDestination)).to.be.equal(expectedBalance.toString()) @@ -214,7 +214,7 @@ contract('Hermes funds recovery', ([_, txMaker, account, fundsDestination, ...ot const initialBalance = new BN(await web3.eth.getBalance(fundsDestination)) topupAmount = new BN(topupAmount.toString()) - await hermesImplementation.claimEthers().should.be.fulfilled + await hermesImplementation.claimNativeCoin().should.be.fulfilled const expectedBalance = topupAmount.add(new BN(initialBalance)) expect(await web3.eth.getBalance(fundsDestination)).to.be.equal(expectedBalance.toString()) diff --git a/test/fundsRecoveryByCheque.js b/test/fundsRecoveryByCheque.js index 356ae4b..df53099 100644 --- a/test/fundsRecoveryByCheque.js +++ b/test/fundsRecoveryByCheque.js @@ -80,7 +80,7 @@ contract('Full path (in channel using cheque) test for funds recovery', ([txMake it('should fail recovering funds when destination is not set', async () => { channel = await ChannelImplementation.at(expectedAddress) - await channel.claimEthers().should.be.rejected + await channel.claimNativeCoin().should.be.rejected expect(await channel.getFundsDestination()).to.be.equal(ZeroAddress) }) @@ -107,7 +107,7 @@ contract('Full path (in channel using cheque) test for funds recovery', ([txMake it('should recover ethers', async () => { const initialBalance = await web3.eth.getBalance(fundsDestination) - await channel.claimEthers({ from: otherAccounts[1] }).should.be.fulfilled + await channel.claimNativeCoin({ from: otherAccounts[1] }).should.be.fulfilled const expectedBalance = Number(initialBalance) + topupAmount expect(await web3.eth.getBalance(fundsDestination)).to.be.equal(expectedBalance.toString()) diff --git a/test/hermesPayAndSettle.js b/test/hermesPayAndSettle.js index 34f0972..bde7934 100644 --- a/test/hermesPayAndSettle.js +++ b/test/hermesPayAndSettle.js @@ -53,7 +53,7 @@ contract('Pay and settle', ([txMaker, operatorAddress, ...otherAccounts]) => { // Topup some tokens into txMaker address so it could register hermes await topUpTokens(token, txMaker, OneToken) - await token.approve(registry.address, OneToken.add(OneToken)) // approve enought so it would enought for any case + await token.approve(registry.address, OneToken.add(OneToken)) // approve enough so it would enough for any case }) it("should register and initialize hermes", async () => { diff --git a/test/hermesStakeAndPunishment.js b/test/hermesStakeAndPunishment.js index ab2220e..0a20ccc 100644 --- a/test/hermesStakeAndPunishment.js +++ b/test/hermesStakeAndPunishment.js @@ -44,10 +44,10 @@ contract('Hermes stake and punishment management', ([txMaker, operatorAddress, . // Topup some tokens into txMaker address so it could register hermes await topUpTokens(token, txMaker, OneToken) - await token.approve(registry.address, OneToken) // approve a lot so it would enought for any case + await token.approve(registry.address, OneToken) // approve a lot so it would enough for any case }) - it('should reject hermes registration if he do not pay enought stake', async () => { + it('should reject hermes registration if he do not pay enough stake', async () => { const stateAmount = stake - 1 await registry.registerHermes(hermesOperator.address, stateAmount, Zero, 25, OneToken, hermesURL).should.be.rejected }) @@ -172,7 +172,7 @@ contract('Hermes stake and punishment management', ([txMaker, operatorAddress, . const channelId = generateChannelId(provider.address, hermes.address) const initialChannelStake = (await hermes.channels(channelId)).stake - // txMaker should have enought tokens + // txMaker should have enough tokens await topUpTokens(token, txMaker, amountToStake) await token.approve(hermes.address, amountToStake) @@ -221,7 +221,7 @@ contract('Hermes stake and punishment management', ([txMaker, operatorAddress, . expect(hermesStatus.toNumber()).to.be.equal(0) expect(await hermes.isHermesActive()).to.be.true - // Because emergency was resolved fast enought, punishment amount should be not increased + // Because emergency was resolved fast enough, punishment amount should be not increased const punishmentAmount = (await hermes.punishment()).amount punishmentAmount.should.be.bignumber.equal(initialPunishmentAmount) }) @@ -242,7 +242,7 @@ contract('Hermes stake and punishment management', ([txMaker, operatorAddress, . let signature = signIdentityRegistration(registry.address, hermes.address, channelStake, Zero, beneficiaries[1], newProvider) await registry.registerIdentity(hermes.address, channelStake, Zero, beneficiaries[1], signature) - // Ensure that hermes has enought funds + // Ensure that hermes has enough funds await topUpTokens(token, hermes.address, OneToken) // Should be able to settle promise diff --git a/test/registry.js b/test/registry.js index 40104b5..1a9f701 100644 --- a/test/registry.js +++ b/test/registry.js @@ -66,7 +66,7 @@ contract('Deterministic registry', ([txMaker, ...otherAccounts]) => { }) it('should have hermes implementation deployed into deterministic address', async () => { - const expectedAddress = '0x98FC2aDD4692Dad03AD73AF4544da99db3033858' + const expectedAddress = '0xB6D6838664c7DB04Fe33F0E2EeD950Ac17a3dcbD' expect(await registry.getHermesImplementation()).to.be.equal(expectedAddress) }) })