Skip to content

Commit

Permalink
Merge pull request #162 from vzotova/unification
Browse files Browse the repository at this point in the history
`authorizationParameters` and Solidity -> 0.8.22
  • Loading branch information
KPrasch authored Oct 30, 2023
2 parents 5a9eb65 + 60c9609 commit bed94af
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 126 deletions.
12 changes: 6 additions & 6 deletions ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ plugins:
dependencies:
- name: openzeppelin
github: OpenZeppelin/openzeppelin-contracts
version: 4.9.1
version: 5.0.0
config_override:
solidity:
version: 0.8.20
version: 0.8.22
evm_version: paris
- name: openzeppelin-upgradeable
github: OpenZeppelin/openzeppelin-contracts-upgradeable
version: 4.9.1
version: 5.0.0
- name: fx-portal
github: 0xPolygon/fx-portal
version: 1.0.5
Expand All @@ -25,11 +25,11 @@ dependencies:
version: 1.2.1

solidity:
version: 0.8.20
version: 0.8.22
evm_version: paris
import_remapping:
- "@openzeppelin/contracts=openzeppelin/v4.9.1"
- "@openzeppelin-upgradeable/contracts=openzeppelin-upgradeable/v4.9.1"
- "@openzeppelin/contracts=openzeppelin/v5.0.0"
- "@openzeppelin-upgradeable/contracts=openzeppelin-upgradeable/v5.0.0"
- "@fx-portal/contracts=fx-portal/v1.0.5"
- "@threshold/contracts=threshold/v1.2.1"

Expand Down
40 changes: 36 additions & 4 deletions contracts/contracts/TACoApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import "@threshold/contracts/staking/IApplication.sol";
import "@threshold/contracts/staking/IStaking.sol";
Expand Down Expand Up @@ -148,7 +147,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
uint64 endCommitment;
}

uint256 public constant REWARD_PER_TOKEN_MULTIPLIER = 10 ** 4;
uint256 public constant REWARD_PER_TOKEN_MULTIPLIER = 10 ** 3;
uint256 internal constant FLOATING_POINT_DIVISOR = REWARD_PER_TOKEN_MULTIPLIER * 10 ** 18;

uint96 public immutable minimumAuthorization;
Expand Down Expand Up @@ -264,15 +263,15 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
* @notice Initialize function for using with OpenZeppelin proxy
*/
function initialize() external initializer {
__Ownable_init();
__Ownable_init(msg.sender);
}

/**
* @notice Set contract for multi-chain interactions
*/
function setChildApplication(ITACoRootToChild _childApplication) external onlyOwner {
require(address(childApplication) == address(0), "Child application is already set");
require(Address.isContract(address(_childApplication)), "Child app must be contract");
require(address(_childApplication).code.length > 0, "Child app must be contract");
childApplication = _childApplication;
}

Expand All @@ -287,6 +286,39 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
adjudicator = _adjudicator;
}

/// @notice Returns authorization-related parameters of the application.
/// @dev The minimum authorization is also returned by `minimumAuthorization()`
/// function, as a requirement of `IApplication` interface.
/// @return _minimumAuthorization The minimum authorization amount required
/// so that operator can participate in the application.
/// @return authorizationDecreaseDelay Delay in seconds that needs to pass
/// between the time authorization decrease is requested and the
/// time that request gets approved. Protects against free-riders
/// earning rewards and not being active in the network.
/// @return authorizationDecreaseChangePeriod Authorization decrease change
/// period in seconds. It is the time, before authorization decrease
/// delay end, during which the pending authorization decrease
/// request can be overwritten.
/// If set to 0, pending authorization decrease request can not be
/// overwritten until the entire `authorizationDecreaseDelay` ends.
/// If set to value equal `authorizationDecreaseDelay`, request can
/// always be overwritten.
function authorizationParameters()
external
view
returns (
uint96 _minimumAuthorization,
uint64 authorizationDecreaseDelay,
uint64 authorizationDecreaseChangePeriod
)
{
return (
minimumAuthorization,
uint64(deauthorizationDuration),
uint64(deauthorizationDuration)
);
}

//------------------------Reward------------------------------

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/contracts/TestnetThresholdStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contract TestnetThresholdStaking is Ownable {

mapping(address => StakingProviderInfo) public stakingProviderInfo;

constructor() Ownable(msg.sender) {}

function setApplication(IApplication _application) external onlyOwner {
application = _application;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControlDefaultAdminRules.sol";
import "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./FlatRateFeeModel.sol";
Expand Down
4 changes: 3 additions & 1 deletion contracts/contracts/coordination/GlobalAllowList.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControlDefaultAdminRules.sol";
import "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./IEncryptionAuthorizer.sol";
import "./Coordinator.sol";

contract GlobalAllowList is AccessControlDefaultAdminRules, IEncryptionAuthorizer {
using MessageHashUtils for bytes32;
using ECDSA for bytes32;

Coordinator public coordinator;
Expand Down
16 changes: 7 additions & 9 deletions contracts/contracts/proxy/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.0;


import "./Upgradeable.sol";
import "@openzeppelin/contracts/utils/Address.sol";


/**
Expand All @@ -21,7 +20,6 @@ interface ERCProxy {
* Client should use ABI of real contract and address of this contract
*/
contract Dispatcher is Upgradeable, ERCProxy {
using Address for address;

event Upgraded(address indexed from, address indexed to, address owner);
event RolledBack(address indexed from, address indexed to, address owner);
Expand All @@ -40,7 +38,7 @@ contract Dispatcher is Upgradeable, ERCProxy {
* @param _target Target contract address
*/
constructor(address _target) upgrading {
require(_target.isContract());
require(_target.code.length > 0);
// Checks that target contract inherits Dispatcher state
verifyState(_target);
// `verifyState` must work with its contract
Expand Down Expand Up @@ -71,12 +69,12 @@ contract Dispatcher is Upgradeable, ERCProxy {
* @param _target New target contract address
*/
function upgrade(address _target) public onlyOwner upgrading {
require(_target.isContract());
require(_target.code.length > 0);
// Checks that target contract has "correct" (as much as possible) state layout
verifyState(_target);
//`verifyState` must work with its contract
verifyUpgradeableState(_target, _target);
if (target.isContract()) {
if (target.code.length > 0) {
verifyUpgradeableState(target, _target);
}
previousTarget = target;
Expand All @@ -90,12 +88,12 @@ contract Dispatcher is Upgradeable, ERCProxy {
* @dev Test storage carefully before upgrade again after rollback
*/
function rollback() public onlyOwner upgrading {
require(previousTarget.isContract());
require(previousTarget.code.length > 0);
emit RolledBack(target, previousTarget, msg.sender);
// should be always true because layout previousTarget -> target was already checked
// but `verifyState` is not 100% accurate so check again
verifyState(previousTarget);
if (target.isContract()) {
if (target.code.length > 0) {
verifyUpgradeableState(previousTarget, target);
}
target = previousTarget;
Expand Down Expand Up @@ -136,7 +134,7 @@ contract Dispatcher is Upgradeable, ERCProxy {
* @dev Receive function sends empty request to the target contract
*/
receive() external payable {
assert(target.isContract());
assert(target.code.length > 0);
// execute receive function from target contract using storage of the dispatcher
(bool callSuccess,) = target.delegatecall("");
if (!callSuccess) {
Expand All @@ -148,7 +146,7 @@ contract Dispatcher is Upgradeable, ERCProxy {
* @dev Fallback function sends all requests to the target contract
*/
fallback() external payable {
assert(target.isContract());
assert(target.code.length > 0);
// execute requested function from target contract using storage of the dispatcher
(bool callSuccess,) = target.delegatecall(msg.data);
if (callSuccess) {
Expand Down
2 changes: 2 additions & 0 deletions contracts/contracts/proxy/Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ abstract contract Upgradeable is Ownable {
uint8 constant UPGRADE_FALSE = 1;
uint8 constant UPGRADE_TRUE = 2;

constructor() Ownable(msg.sender) {}

/**
* @dev Checks that function executed while upgrading
* Recommended to add to `verifyState` and `finishUpgrade` methods
Expand Down
6 changes: 4 additions & 2 deletions contracts/contracts/testnet/LynxSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "../TACoApplication.sol";
contract MockPolygonRoot is Ownable, ITACoChildToRoot, ITACoRootToChild {
ITACoChildToRoot public rootApplication;

constructor(ITACoChildToRoot _rootApplication) {
constructor(ITACoChildToRoot _rootApplication) Ownable(msg.sender) {
require(
address(_rootApplication) != address(0),
"Address for root application must be specified"
Expand All @@ -44,6 +44,8 @@ contract MockPolygonRoot is Ownable, ITACoChildToRoot, ITACoRootToChild {
contract MockPolygonChild is Ownable, ITACoChildToRoot, ITACoRootToChild {
ITACoRootToChild public childApplication;

constructor() Ownable(msg.sender) {}

function setChildApplication(ITACoRootToChild _childApplication) external onlyOwner {
childApplication = _childApplication;
}
Expand All @@ -70,7 +72,7 @@ contract LynxTACoChildApplication is TACoChildApplication, Ownable {
constructor(
ITACoChildToRoot _rootApplication,
uint96 _minimumAuthorization
) TACoChildApplication(_rootApplication, _minimumAuthorization) {}
) TACoChildApplication(_rootApplication, _minimumAuthorization) Ownable(msg.sender) {}

function setCoordinator(address _coordinator) external onlyOwner {
require(_coordinator != address(0), "Coordinator must be specified");
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/testnet/TapirSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract TapirTACoChildApplication is TACoChildApplication, Ownable {
constructor(
ITACoChildToRoot _rootApplication,
uint96 _minimumAuthorization
) TACoChildApplication(_rootApplication, _minimumAuthorization) {}
) TACoChildApplication(_rootApplication, _minimumAuthorization) Ownable(msg.sender) {}

function setCoordinator(address _coordinator) external onlyOwner {
require(_coordinator != address(0), "Coordinator must be specified");
Expand Down
6 changes: 3 additions & 3 deletions contracts/matic/SubscriptionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ contract SubscriptionManager is Initializable, AccessControlUpgradeable {

function initialize(uint256 _feeRate) public initializer {
_setFeeRate(_feeRate);
_setupRole(SET_RATE_ROLE, msg.sender);
_setupRole(WITHDRAW_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(SET_RATE_ROLE, msg.sender);
_grantRole(WITHDRAW_ROLE, msg.sender);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function getPolicyCost(
Expand Down
2 changes: 1 addition & 1 deletion contracts/xchain/PolygonChild.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
contract PolygonChild is FxBaseChildTunnel, Ownable {
address public childApplication;

constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {}
constructor(address _fxChild) FxBaseChildTunnel(_fxChild) Ownable(msg.sender) {}

function _processMessageFromRoot(
uint256 /* stateId */,
Expand Down
2 changes: 1 addition & 1 deletion deployment/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
BYTES_PREFIX = "bytes"
DEPLOYER_INDICATOR = "deployer"
PROXY_NAME = "TransparentUpgradeableProxy"
OZ_DEPENDENCY = project.dependencies["openzeppelin"]["4.9.1"]
OZ_DEPENDENCY = project.dependencies["openzeppelin"]["5.0.0"]

#
# Domains
Expand Down
3 changes: 1 addition & 2 deletions deployment/constructor_params/lynx/child.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ artifacts:

contracts:
- MockPolygonChild
- ProxyAdmin
- LynxTACoChildApplication:
_rootApplication: $MockPolygonChild
_minimumAuthorization: 40000000000000000000000
- TransparentUpgradeableProxy:
_logic: $LynxTACoChildApplication
admin_: $ProxyAdmin
initialOwner: $deployer
_data: $bytes:0x
- LynxRitualToken:
_totalSupplyOfTokens: 10000000000000000000000000
Expand Down
5 changes: 2 additions & 3 deletions deployment/constructor_params/lynx/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ deployment:

artifacts:
dir: ./deployment/artifacts/
filename: lynx.json
filename: test.json

contracts:
- LynxStakingToken:
_totalSupplyOfTokens: 10000000000000000000000000
- TestnetThresholdStaking
- ProxyAdmin
- TACoApplication:
_token: $LynxStakingToken
_tStaking: $TestnetThresholdStaking
Expand All @@ -21,7 +20,7 @@ contracts:
_commitmentDurationOptions: [15724800, 31449600]
- TransparentUpgradeableProxy:
_logic: $TACoApplication
admin_: $ProxyAdmin
initialOwner: $deployer
_data: $bytes:0x
- MockPolygonRoot:
_rootApplication: $TransparentUpgradeableProxy:TACoApplication
3 changes: 1 addition & 2 deletions deployment/constructor_params/tapir/child.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ artifacts:

contracts:
- MockPolygonChild
- ProxyAdmin
- TapirTACoChildApplication:
_rootApplication: $MockPolygonChild
_minimumAuthorization: 40000000000000000000000
- TransparentUpgradeableProxy:
_logic: $TapirTACoChildApplication
admin_: $ProxyAdmin
initialOwner: $deployer
_data: $bytes:0x
- TapirRitualToken:
_totalSupplyOfTokens: 10000000000000000000000000
Expand Down
3 changes: 1 addition & 2 deletions deployment/constructor_params/tapir/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ contracts:
- TapirStakingToken:
_totalSupplyOfTokens: 10000000000000000000000000
- TestnetThresholdStaking
- ProxyAdmin
- TACoApplication:
_token: $TapirStakingToken
_tStaking: $TestnetThresholdStaking
Expand All @@ -21,7 +20,7 @@ contracts:
_commitmentDurationOptions: [15724800, 31449600]
- TransparentUpgradeableProxy:
_logic: $TACoApplication
admin_: $ProxyAdmin
initialOwner: $deployer
_data: $bytes:0x
- MockPolygonRoot:
_rootApplication: $TransparentUpgradeableProxy:TACoApplication
14 changes: 2 additions & 12 deletions scripts/lynx/deploy_child.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/python3

from ape import project

from deployment.constants import (
CONSTRUCTOR_PARAMS_DIR,
OZ_DEPENDENCY,
)
from deployment.constants import CONSTRUCTOR_PARAMS_DIR, OZ_DEPENDENCY
from deployment.params import Deployer

VERIFY = False
Expand All @@ -26,15 +22,10 @@ def main():
eth-ape 0.6.20
"""

deployer = Deployer.from_yaml(
filepath=CONSTRUCTOR_PARAMS_FILEPATH,
verify=VERIFY
)
deployer = Deployer.from_yaml(filepath=CONSTRUCTOR_PARAMS_FILEPATH, verify=VERIFY)

mock_polygon_child = deployer.deploy(project.MockPolygonChild)

proxy_admin = deployer.deploy(OZ_DEPENDENCY.ProxyAdmin)

taco_implementation = deployer.deploy(project.LynxTACoChildApplication)

proxy = deployer.deploy(OZ_DEPENDENCY.TransparentUpgradeableProxy)
Expand All @@ -52,7 +43,6 @@ def main():

deployments = [
mock_polygon_child,
proxy_admin,
taco_implementation, # implementation (contract name is different than proxy contract)
taco_child_application, # proxy
ritual_token,
Expand Down
Loading

0 comments on commit bed94af

Please sign in to comment.