forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from klaytn/protocol
Add system contracts KIP-81, 103, 113, 149
- Loading branch information
Showing
33 changed files
with
4,326 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
contracts/KIP/protocol/**/*.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
contracts/KIP/protocol/**/*.sol |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev External interface of TreasuryRebalance | ||
*/ | ||
interface ITreasuryRebalance { | ||
/** | ||
* @dev Emitted when the contract is deployed | ||
* `rebalanceBlockNumber` is the target block number of the execution the rebalance in Core | ||
* `deployedBlockNumber` is the current block number when its deployed | ||
*/ | ||
event ContractDeployed( | ||
Status status, | ||
uint256 rebalanceBlockNumber, | ||
uint256 deployedBlockNumber | ||
); | ||
|
||
/** | ||
* @dev Emitted when a Retired is registered | ||
*/ | ||
event RetiredRegistered(address retired); | ||
|
||
/** | ||
* @dev Emitted when a Retired is removed | ||
*/ | ||
event RetiredRemoved(address retired); | ||
|
||
/** | ||
* @dev Emitted when a Newbie is registered | ||
*/ | ||
event NewbieRegistered(address newbie, uint256 fundAllocation); | ||
|
||
/** | ||
* @dev Emitted when a Newbie is removed | ||
*/ | ||
event NewbieRemoved(address newbie); | ||
|
||
/** | ||
* @dev Emitted when a admin approves the retired address. | ||
*/ | ||
event Approved(address retired, address approver, uint256 approversCount); | ||
|
||
/** | ||
* @dev Emitted when the contract status changes | ||
*/ | ||
event StatusChanged(Status status); | ||
|
||
/** | ||
* @dev Emitted when the contract is finalized | ||
* memo - is the result of the treasury fund rebalancing | ||
*/ | ||
event Finalized(string memo, Status status); | ||
|
||
// Status of the contract | ||
enum Status { | ||
Initialized, | ||
Registered, | ||
Approved, | ||
Finalized | ||
} | ||
|
||
/** | ||
* Retired struct to store retired address and their approver addresses | ||
*/ | ||
struct Retired { | ||
address retired; | ||
address[] approvers; | ||
} | ||
|
||
/** | ||
* Newbie struct to newbie receiver address and their fund allocation | ||
*/ | ||
struct Newbie { | ||
address newbie; | ||
uint256 amount; | ||
} | ||
|
||
// State variables | ||
function status() external view returns (Status); // current status of the contract | ||
|
||
function rebalanceBlockNumber() external view returns (uint256); // the target block number of the execution of rebalancing | ||
|
||
function memo() external view returns (string memory); // result of the treasury fund rebalance | ||
|
||
/** | ||
* @dev to get retired details by retiredAddress | ||
*/ | ||
function getRetired( | ||
address retiredAddress | ||
) external view returns (address, address[] memory); | ||
|
||
/** | ||
* @dev to get newbie details by newbieAddress | ||
*/ | ||
function getNewbie( | ||
address newbieAddress | ||
) external view returns (address, uint256); | ||
|
||
/** | ||
* @dev returns the sum of retirees balances | ||
*/ | ||
function sumOfRetiredBalance() | ||
external | ||
view | ||
returns (uint256 retireesBalance); | ||
|
||
/** | ||
* @dev returns the sum of newbie funds | ||
*/ | ||
function getTreasuryAmount() external view returns (uint256 treasuryAmount); | ||
|
||
/** | ||
* @dev returns the length of retirees list | ||
*/ | ||
function getRetiredCount() external view returns (uint256); | ||
|
||
/** | ||
* @dev returns the length of newbies list | ||
*/ | ||
function getNewbieCount() external view returns (uint256); | ||
|
||
/** | ||
* @dev verify all retirees are approved by admin | ||
*/ | ||
function checkRetiredsApproved() external view; | ||
|
||
// State changing functions | ||
/** | ||
* @dev registers retired details | ||
* Can only be called by the current owner at Initialized state | ||
*/ | ||
function registerRetired(address retiredAddress) external; | ||
|
||
/** | ||
* @dev remove the retired details from the array | ||
* Can only be called by the current owner at Initialized state | ||
*/ | ||
function removeRetired(address retiredAddress) external; | ||
|
||
/** | ||
* @dev registers newbie address and its fund distribution | ||
* Can only be called by the current owner at Initialized state | ||
*/ | ||
function registerNewbie(address newbieAddress, uint256 amount) external; | ||
|
||
/** | ||
* @dev remove the newbie details from the array | ||
* Can only be called by the current owner at Initialized state | ||
*/ | ||
function removeNewbie(address newbieAddress) external; | ||
|
||
/** | ||
* @dev approves a retiredAddress,the address can be a EOA or a contract address. | ||
* - If the retiredAddress is a EOA, the caller should be the EOA address | ||
* - If the retiredAddress is a Contract, the caller should be one of the contract `admin` | ||
*/ | ||
function approve(address retiredAddress) external; | ||
|
||
/** | ||
* @dev sets the status to Registered, | ||
* After this stage, registrations will be restricted. | ||
* Can only be called by the current owner at Initialized state | ||
*/ | ||
function finalizeRegistration() external; | ||
|
||
/** | ||
* @dev sets the status to Approved, | ||
* Can only be called by the current owner at Registered state | ||
*/ | ||
function finalizeApproval() external; | ||
|
||
/** | ||
* @dev sets the status of the contract to Finalize. Once finalized the storage data | ||
* of the contract cannot be modified | ||
* Can only be called by the current owner at Approved state after the execution of rebalance in the core | ||
* - memo format: { "retirees": [ { "retired": "0xaddr", "balance": 0xamount }, | ||
* { "retired": "0xaddr", "balance": 0xamount }, ... ], | ||
* "newbies": [ { "newbie": "0xaddr", "fundAllocated": 0xamount }, | ||
* { "newbie": "0xaddr", "fundAllocated": 0xamount }, ... ], | ||
* "burnt": 0xamount, "success": true/false } | ||
*/ | ||
function finalizeContract(string memory memo) external; | ||
|
||
/** | ||
* @dev resets all storage values to empty objects except targetBlockNumber | ||
*/ | ||
function reset() external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev Contract module which provides a basic access control mechanism, where | ||
* there is an account (an owner) that can be granted exclusive access to | ||
* specific functions. | ||
* | ||
* This module is used through inheritance. It will make available the modifier | ||
* `onlyOwner`, which can be aplied to your functions to restrict their use to | ||
* the owner. | ||
*/ | ||
contract Ownable { | ||
address private _owner; | ||
|
||
event OwnershipTransferred( | ||
address indexed previousOwner, | ||
address indexed newOwner | ||
); | ||
|
||
/** | ||
* @dev Initializes the contract setting the deployer as the initial owner. | ||
*/ | ||
constructor() { | ||
_owner = msg.sender; | ||
emit OwnershipTransferred(address(0), _owner); | ||
} | ||
|
||
/** | ||
* @dev Returns the address of the current owner. | ||
*/ | ||
function owner() public view returns (address) { | ||
return _owner; | ||
} | ||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(isOwner(), "Ownable: caller is not the owner"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Returns true if the caller is the current owner. | ||
*/ | ||
function isOwner() public view returns (bool) { | ||
return msg.sender == _owner; | ||
} | ||
|
||
/** | ||
* @dev Leaves the contract without owner. It will not be possible to call | ||
* `onlyOwner` functions anymore. Can only be called by the current owner. | ||
* | ||
* > Note: Renouncing ownership will leave the contract without an owner, | ||
* thereby removing any functionality that is only available to the owner. | ||
*/ | ||
function renounceOwnership() public onlyOwner { | ||
emit OwnershipTransferred(_owner, address(0)); | ||
_owner = address(0); | ||
} | ||
|
||
/** | ||
* @dev Transfers ownership of the contract to a new account (`newOwner`). | ||
* Can only be called by the current owner. | ||
*/ | ||
function transferOwnership(address newOwner) public onlyOwner { | ||
_transferOwnership(newOwner); | ||
} | ||
|
||
/** | ||
* @dev Transfers ownership of the contract to a new account (`newOwner`). | ||
*/ | ||
function _transferOwnership(address newOwner) internal { | ||
require( | ||
newOwner != address(0), | ||
"Ownable: new owner is the zero address" | ||
); | ||
emit OwnershipTransferred(_owner, newOwner); | ||
_owner = newOwner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* Test contract to represent KGF contract implementing getState() | ||
*/ | ||
contract SenderTest1 { | ||
address[] _adminList; | ||
uint256 public minReq = 1; | ||
|
||
constructor() { | ||
_adminList.push(msg.sender); | ||
} | ||
|
||
/* | ||
* Getter functions | ||
*/ | ||
function getState() external view returns (address[] memory, uint256) { | ||
return (_adminList, minReq); | ||
} | ||
|
||
function emptyAdminList() public { | ||
_adminList.pop(); | ||
} | ||
|
||
function changeMinReq(uint256 req) public { | ||
minReq = req; | ||
} | ||
|
||
function addAdmin(address admin) public { | ||
_adminList.push(admin); | ||
} | ||
|
||
/* | ||
* Deposit function | ||
*/ | ||
/// @dev Fallback function that allows to deposit KLAY | ||
fallback() external payable { | ||
require(msg.value > 0, "Invalid value."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* Test contract to represent KIR contract implementing getState() | ||
*/ | ||
contract SenderTest2 { | ||
address[] _adminList; | ||
|
||
constructor() { | ||
_adminList.push(msg.sender); | ||
} | ||
|
||
/* | ||
* Getter functions | ||
*/ | ||
function getState() external view returns (address[] memory, uint256) { | ||
return (_adminList, 1); | ||
} | ||
|
||
/* | ||
* Deposit function | ||
*/ | ||
/// @dev Fallback function that allows to deposit KLAY | ||
fallback() external payable { | ||
require(msg.value > 0, "Invalid value."); | ||
} | ||
} |
Oops, something went wrong.