Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit f54fb80

Browse files
authored
Merge pull request #29 from klaytn/protocol
Add system contracts KIP-81, 103, 113, 149
2 parents 9eea853 + 646e726 commit f54fb80

33 files changed

+4326
-9
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
contracts/KIP/protocol/**/*.sol

.solhintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
contracts/KIP/protocol/**/*.sol

audit/KIP81_certik_20230208.pdf

3.31 MB
Binary file not shown.

audit/KIP81_theori_20230428.pdf

1.29 MB
Binary file not shown.

contracts/KIP/mocks/KIP37MintableMock.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract KIP37MintableMock is KIP37Mintable {
1818
function create(
1919
uint256 id,
2020
uint256 initialSupply,
21-
string calldata uri_
21+
string memory uri_
2222
) public override returns (bool) {
2323
return super.create(id, initialSupply, uri_);
2424
}
@@ -33,16 +33,16 @@ contract KIP37MintableMock is KIP37Mintable {
3333

3434
function mint(
3535
uint256 id,
36-
address[] calldata toList,
37-
uint256[] calldata amounts
36+
address[] memory toList,
37+
uint256[] memory amounts
3838
) public override {
3939
super.mint(id, toList, amounts);
4040
}
4141

4242
function mintBatch(
4343
address to,
44-
uint256[] calldata ids,
45-
uint256[] calldata amounts
44+
uint256[] memory ids,
45+
uint256[] memory amounts
4646
) public override {
4747
super.mintBatch(to, ids, amounts);
4848
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* @dev External interface of TreasuryRebalance
7+
*/
8+
interface ITreasuryRebalance {
9+
/**
10+
* @dev Emitted when the contract is deployed
11+
* `rebalanceBlockNumber` is the target block number of the execution the rebalance in Core
12+
* `deployedBlockNumber` is the current block number when its deployed
13+
*/
14+
event ContractDeployed(
15+
Status status,
16+
uint256 rebalanceBlockNumber,
17+
uint256 deployedBlockNumber
18+
);
19+
20+
/**
21+
* @dev Emitted when a Retired is registered
22+
*/
23+
event RetiredRegistered(address retired);
24+
25+
/**
26+
* @dev Emitted when a Retired is removed
27+
*/
28+
event RetiredRemoved(address retired);
29+
30+
/**
31+
* @dev Emitted when a Newbie is registered
32+
*/
33+
event NewbieRegistered(address newbie, uint256 fundAllocation);
34+
35+
/**
36+
* @dev Emitted when a Newbie is removed
37+
*/
38+
event NewbieRemoved(address newbie);
39+
40+
/**
41+
* @dev Emitted when a admin approves the retired address.
42+
*/
43+
event Approved(address retired, address approver, uint256 approversCount);
44+
45+
/**
46+
* @dev Emitted when the contract status changes
47+
*/
48+
event StatusChanged(Status status);
49+
50+
/**
51+
* @dev Emitted when the contract is finalized
52+
* memo - is the result of the treasury fund rebalancing
53+
*/
54+
event Finalized(string memo, Status status);
55+
56+
// Status of the contract
57+
enum Status {
58+
Initialized,
59+
Registered,
60+
Approved,
61+
Finalized
62+
}
63+
64+
/**
65+
* Retired struct to store retired address and their approver addresses
66+
*/
67+
struct Retired {
68+
address retired;
69+
address[] approvers;
70+
}
71+
72+
/**
73+
* Newbie struct to newbie receiver address and their fund allocation
74+
*/
75+
struct Newbie {
76+
address newbie;
77+
uint256 amount;
78+
}
79+
80+
// State variables
81+
function status() external view returns (Status); // current status of the contract
82+
83+
function rebalanceBlockNumber() external view returns (uint256); // the target block number of the execution of rebalancing
84+
85+
function memo() external view returns (string memory); // result of the treasury fund rebalance
86+
87+
/**
88+
* @dev to get retired details by retiredAddress
89+
*/
90+
function getRetired(
91+
address retiredAddress
92+
) external view returns (address, address[] memory);
93+
94+
/**
95+
* @dev to get newbie details by newbieAddress
96+
*/
97+
function getNewbie(
98+
address newbieAddress
99+
) external view returns (address, uint256);
100+
101+
/**
102+
* @dev returns the sum of retirees balances
103+
*/
104+
function sumOfRetiredBalance()
105+
external
106+
view
107+
returns (uint256 retireesBalance);
108+
109+
/**
110+
* @dev returns the sum of newbie funds
111+
*/
112+
function getTreasuryAmount() external view returns (uint256 treasuryAmount);
113+
114+
/**
115+
* @dev returns the length of retirees list
116+
*/
117+
function getRetiredCount() external view returns (uint256);
118+
119+
/**
120+
* @dev returns the length of newbies list
121+
*/
122+
function getNewbieCount() external view returns (uint256);
123+
124+
/**
125+
* @dev verify all retirees are approved by admin
126+
*/
127+
function checkRetiredsApproved() external view;
128+
129+
// State changing functions
130+
/**
131+
* @dev registers retired details
132+
* Can only be called by the current owner at Initialized state
133+
*/
134+
function registerRetired(address retiredAddress) external;
135+
136+
/**
137+
* @dev remove the retired details from the array
138+
* Can only be called by the current owner at Initialized state
139+
*/
140+
function removeRetired(address retiredAddress) external;
141+
142+
/**
143+
* @dev registers newbie address and its fund distribution
144+
* Can only be called by the current owner at Initialized state
145+
*/
146+
function registerNewbie(address newbieAddress, uint256 amount) external;
147+
148+
/**
149+
* @dev remove the newbie details from the array
150+
* Can only be called by the current owner at Initialized state
151+
*/
152+
function removeNewbie(address newbieAddress) external;
153+
154+
/**
155+
* @dev approves a retiredAddress,the address can be a EOA or a contract address.
156+
* - If the retiredAddress is a EOA, the caller should be the EOA address
157+
* - If the retiredAddress is a Contract, the caller should be one of the contract `admin`
158+
*/
159+
function approve(address retiredAddress) external;
160+
161+
/**
162+
* @dev sets the status to Registered,
163+
* After this stage, registrations will be restricted.
164+
* Can only be called by the current owner at Initialized state
165+
*/
166+
function finalizeRegistration() external;
167+
168+
/**
169+
* @dev sets the status to Approved,
170+
* Can only be called by the current owner at Registered state
171+
*/
172+
function finalizeApproval() external;
173+
174+
/**
175+
* @dev sets the status of the contract to Finalize. Once finalized the storage data
176+
* of the contract cannot be modified
177+
* Can only be called by the current owner at Approved state after the execution of rebalance in the core
178+
* - memo format: { "retirees": [ { "retired": "0xaddr", "balance": 0xamount },
179+
* { "retired": "0xaddr", "balance": 0xamount }, ... ],
180+
* "newbies": [ { "newbie": "0xaddr", "fundAllocated": 0xamount },
181+
* { "newbie": "0xaddr", "fundAllocated": 0xamount }, ... ],
182+
* "burnt": 0xamount, "success": true/false }
183+
*/
184+
function finalizeContract(string memory memo) external;
185+
186+
/**
187+
* @dev resets all storage values to empty objects except targetBlockNumber
188+
*/
189+
function reset() external;
190+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity ^0.8.0;
3+
4+
/**
5+
* @dev Contract module which provides a basic access control mechanism, where
6+
* there is an account (an owner) that can be granted exclusive access to
7+
* specific functions.
8+
*
9+
* This module is used through inheritance. It will make available the modifier
10+
* `onlyOwner`, which can be aplied to your functions to restrict their use to
11+
* the owner.
12+
*/
13+
contract Ownable {
14+
address private _owner;
15+
16+
event OwnershipTransferred(
17+
address indexed previousOwner,
18+
address indexed newOwner
19+
);
20+
21+
/**
22+
* @dev Initializes the contract setting the deployer as the initial owner.
23+
*/
24+
constructor() {
25+
_owner = msg.sender;
26+
emit OwnershipTransferred(address(0), _owner);
27+
}
28+
29+
/**
30+
* @dev Returns the address of the current owner.
31+
*/
32+
function owner() public view returns (address) {
33+
return _owner;
34+
}
35+
36+
/**
37+
* @dev Throws if called by any account other than the owner.
38+
*/
39+
modifier onlyOwner() {
40+
require(isOwner(), "Ownable: caller is not the owner");
41+
_;
42+
}
43+
44+
/**
45+
* @dev Returns true if the caller is the current owner.
46+
*/
47+
function isOwner() public view returns (bool) {
48+
return msg.sender == _owner;
49+
}
50+
51+
/**
52+
* @dev Leaves the contract without owner. It will not be possible to call
53+
* `onlyOwner` functions anymore. Can only be called by the current owner.
54+
*
55+
* > Note: Renouncing ownership will leave the contract without an owner,
56+
* thereby removing any functionality that is only available to the owner.
57+
*/
58+
function renounceOwnership() public onlyOwner {
59+
emit OwnershipTransferred(_owner, address(0));
60+
_owner = address(0);
61+
}
62+
63+
/**
64+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
65+
* Can only be called by the current owner.
66+
*/
67+
function transferOwnership(address newOwner) public onlyOwner {
68+
_transferOwnership(newOwner);
69+
}
70+
71+
/**
72+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
73+
*/
74+
function _transferOwnership(address newOwner) internal {
75+
require(
76+
newOwner != address(0),
77+
"Ownable: new owner is the zero address"
78+
);
79+
emit OwnershipTransferred(_owner, newOwner);
80+
_owner = newOwner;
81+
}
82+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* Test contract to represent KGF contract implementing getState()
7+
*/
8+
contract SenderTest1 {
9+
address[] _adminList;
10+
uint256 public minReq = 1;
11+
12+
constructor() {
13+
_adminList.push(msg.sender);
14+
}
15+
16+
/*
17+
* Getter functions
18+
*/
19+
function getState() external view returns (address[] memory, uint256) {
20+
return (_adminList, minReq);
21+
}
22+
23+
function emptyAdminList() public {
24+
_adminList.pop();
25+
}
26+
27+
function changeMinReq(uint256 req) public {
28+
minReq = req;
29+
}
30+
31+
function addAdmin(address admin) public {
32+
_adminList.push(admin);
33+
}
34+
35+
/*
36+
* Deposit function
37+
*/
38+
/// @dev Fallback function that allows to deposit KLAY
39+
fallback() external payable {
40+
require(msg.value > 0, "Invalid value.");
41+
}
42+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* Test contract to represent KIR contract implementing getState()
7+
*/
8+
contract SenderTest2 {
9+
address[] _adminList;
10+
11+
constructor() {
12+
_adminList.push(msg.sender);
13+
}
14+
15+
/*
16+
* Getter functions
17+
*/
18+
function getState() external view returns (address[] memory, uint256) {
19+
return (_adminList, 1);
20+
}
21+
22+
/*
23+
* Deposit function
24+
*/
25+
/// @dev Fallback function that allows to deposit KLAY
26+
fallback() external payable {
27+
require(msg.value > 0, "Invalid value.");
28+
}
29+
}

0 commit comments

Comments
 (0)