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

Add system contracts KIP-81, 103, 113, 149 #29

Merged
merged 10 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contracts/KIP/protocol/**/*.sol
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contracts/KIP/protocol/**/*.sol
Binary file added audit/KIP81_certik_20230208.pdf
Binary file not shown.
Binary file added audit/KIP81_theori_20230428.pdf
Binary file not shown.
10 changes: 5 additions & 5 deletions contracts/KIP/mocks/KIP37MintableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract KIP37MintableMock is KIP37Mintable {
function create(
uint256 id,
uint256 initialSupply,
string calldata uri_
string memory uri_
) public override returns (bool) {
return super.create(id, initialSupply, uri_);
}
Expand All @@ -33,16 +33,16 @@ contract KIP37MintableMock is KIP37Mintable {

function mint(
uint256 id,
address[] calldata toList,
uint256[] calldata amounts
address[] memory toList,
uint256[] memory amounts
) public override {
super.mint(id, toList, amounts);
}

function mintBatch(
address to,
uint256[] calldata ids,
uint256[] calldata amounts
uint256[] memory ids,
uint256[] memory amounts
) public override {
super.mintBatch(to, ids, amounts);
}
Expand Down
190 changes: 190 additions & 0 deletions contracts/KIP/protocol/KIP103/ITreasuryRebalance.sol
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;
}
82 changes: 82 additions & 0 deletions contracts/KIP/protocol/KIP103/Ownable.sol
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;
}
}
42 changes: 42 additions & 0 deletions contracts/KIP/protocol/KIP103/SenderTest1.sol
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.");
}
}
29 changes: 29 additions & 0 deletions contracts/KIP/protocol/KIP103/SenderTest2.sol
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.");
}
}
Loading
Loading