Skip to content

Commit

Permalink
Updated flattened files
Browse files Browse the repository at this point in the history
  • Loading branch information
chompomonim committed May 3, 2022
1 parent 0a360b1 commit cfd6ac6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
8 changes: 4 additions & 4 deletions contracts/flattened/ChannelImplementation.sol.flattened
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ interface IERC20 {
// File: contracts/interfaces/IERC20Token.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.4;
pragma solidity 0.8.9;


abstract contract IERC20Token is IERC20 {
Expand All @@ -317,7 +317,7 @@ abstract contract IERC20Token is IERC20 {
// File: contracts/interfaces/IHermesContract.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.6;
pragma solidity 0.8.9;

interface IHermesContract {
enum Status { Active, Paused, Punishment, Closed }
Expand All @@ -331,7 +331,7 @@ interface IHermesContract {
// File: contracts/interfaces/IUniswapV2Router.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.4;
pragma solidity 0.8.9;

interface IUniswapV2Router {
function factory() external pure returns (address);
Expand Down Expand Up @@ -551,7 +551,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);
}
Expand Down
34 changes: 16 additions & 18 deletions contracts/flattened/HermesImplementation.sol.flattened
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ library ECDSA {
// File: contracts/interfaces/IUniswapV2Router.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.4;
pragma solidity 0.8.9;

interface IUniswapV2Router {
function factory() external pure returns (address);
Expand Down Expand Up @@ -406,7 +406,7 @@ interface IERC20 {
// File: contracts/interfaces/IERC20Token.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.4;
pragma solidity 0.8.9;


abstract contract IERC20Token is IERC20 {
Expand Down Expand Up @@ -537,7 +537,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);
}
Expand Down Expand Up @@ -693,11 +693,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 -------------------------------------------
Expand All @@ -723,6 +719,8 @@ contract HermesImplementation is FundsRecovery, Utils {
// Approving all myst for dex, because MYST token's `transferFrom` is cheaper when there is approval of uint(-1)
token.approve(_dexAddress, type(uint256).max);
dex = IUniswapV2Router(_dexAddress);

transferOwnership(_operator);
}

function isInitialized() public view returns (bool) {
Expand Down Expand Up @@ -764,7 +762,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;
Expand Down Expand Up @@ -874,7 +872,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);
}

Expand Down Expand Up @@ -907,7 +905,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);
}
Expand All @@ -926,21 +924,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);
}
Expand Down Expand Up @@ -1026,13 +1022,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();
Expand All @@ -1051,6 +1047,8 @@ contract HermesImplementation is FundsRecovery, Utils {

uint256 _amount = token.balanceOf(address(this)) - punishment.amount;
token.transfer(_beneficiary, _amount);

emit HermesStakeReturned(_beneficiary);
}

/*
Expand Down
12 changes: 6 additions & 6 deletions contracts/flattened/Registry.sol.flattened
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ interface IERC20 {
// File: contracts/interfaces/IERC20Token.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.4;
pragma solidity 0.8.9;


abstract contract IERC20Token is IERC20 {
Expand All @@ -317,7 +317,7 @@ abstract contract IERC20Token is IERC20 {
// File: contracts/interfaces/IHermesContract.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.6;
pragma solidity 0.8.9;

interface IHermesContract {
enum Status { Active, Paused, Punishment, Closed }
Expand Down Expand Up @@ -452,7 +452,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);
}
Expand Down Expand Up @@ -515,7 +515,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;
Expand Down Expand Up @@ -585,7 +585,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);
Expand All @@ -609,7 +609,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);
}
Expand Down

0 comments on commit cfd6ac6

Please sign in to comment.