Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:kaiachain/kaia into update-cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-TinnNguyen committed Jun 20, 2024
2 parents c2035d1 + 08e0f43 commit 5d5a37b
Show file tree
Hide file tree
Showing 13 changed files with 766 additions and 732 deletions.
23 changes: 10 additions & 13 deletions contracts/contracts/system_contracts/consensus/CnV3/CnStakingV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
publicDelegation = address(IPublicDelegationFactory(_pdFactory).deployPublicDelegation(_decodedPDArgs));
rewardAddress = publicDelegation;

emit SetPublicDelegation(_msgSender(), publicDelegation, rewardAddress);
emit SetPublicDelegation(msg.sender, publicDelegation, rewardAddress);
}

/// @dev Agree on the initial lockup conditions.
/// Emits a ReviewInitialConditions event.
/// Emits a CompleteReviewInitialConditions.
function reviewInitialConditions() external override beforeInit onlyRole(ADMIN_ROLE) {
address _caller = _msgSender();
address _caller = msg.sender;
require(lockupConditions.reviewedAdmin[_caller] == false, "Msg.sender already reviewed.");
lockupConditions.reviewedAdmin[_caller] = true;
unchecked {
Expand Down Expand Up @@ -228,7 +228,7 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
_grantStakingRoles();

isInitialized = true;
emit DepositLockupStakingAndInit(_msgSender(), msg.value);
emit DepositLockupStakingAndInit(msg.sender, msg.value);
}

/// @dev Grants staking related roles to the appropriate addresses.
Expand Down Expand Up @@ -356,7 +356,7 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
///
/// Emits a Redelegate event.
function redelegate(address _user, address _targetCnV3, uint256 _value) external override afterInit notNull(_user) {
require(isRedelegationEnabled && _msgSender() == publicDelegation, "Redelegation disabled.");
require(isRedelegationEnabled && msg.sender == publicDelegation, "Redelegation disabled.");
require(_targetCnV3 != address(this), "Target can't be self.");
require(_targetCnV3._validCnStaking(3), "Invalid CnStakingV3.");
require(_value > 0 && unstaking + _value <= staking, "Invalid value.");
Expand Down Expand Up @@ -387,7 +387,7 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
// Early exit if the Redelegation disabled.
// Note that isRedelegationEnabled can be true only if the public delegation is enabled.
require(isRedelegationEnabled, "Redelegation disabled.");
require(_msgSender()._validCnStaking(3), "Invalid CnStakingV3.");
require(msg.sender._validCnStaking(3), "Invalid CnStakingV3.");

lastRedelegation[_user] = block.timestamp;

Expand All @@ -404,7 +404,7 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
_publicDelegation.stakeFor{value: msg.value}(_user);
require(expected == address(this).balance, "Invalid stakeFor.");

emit HandleRedelegation(_user, _msgSender(), address(this), msg.value);
emit HandleRedelegation(_user, msg.sender, address(this), msg.value);
}

/// @dev Withdraw a part of delegated stakes.
Expand Down Expand Up @@ -506,7 +506,7 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl
}

_refreshStake();
emit DelegateKaia(_msgSender(), msg.value);
emit DelegateKaia(msg.sender, msg.value);
}

/// @dev Validate initial conditions
Expand Down Expand Up @@ -534,20 +534,17 @@ contract CnStakingV3 is ICnStakingV3, CnStakingV3Storage, AccessControlEnumerabl

/// @dev Refresh the balance of this contract recorded in StakingTracker
function _refreshStake() private {
(bool success, ) = address(stakingTracker).call(
abi.encodeWithSignature("refreshStake(address)", address(this))
);
require(success, "StakingTracker call failed.");
IStakingTracker(stakingTracker).refreshStake(address(this));
}

/// @dev Check if the caller can accept the reward address
function _canAcceptRewardAddress() private view returns (bool) {
if (_msgSender() == pendingRewardAddress) {
if (msg.sender == pendingRewardAddress) {
return true;
}
(address[] memory abookAdminList, ) = IAddressBook(ADDRESS_BOOK_ADDRESS).getState();
for (uint256 i = 0; i < abookAdminList.length; i++) {
if (_msgSender() == abookAdminList[i]) {
if (msg.sender == abookAdminList[i]) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage
bytes32 _secondArg,
bytes32 _thirdArg
) public override notConfirmedRequest(_id) onlyRole(ADMIN_ROLE) {
require(!_hasConfirmed(_id, _msgSender()), "Msg.sender already confirmed.");
require(!_hasConfirmed(_id, msg.sender), "Msg.sender already confirmed.");
Request storage _req = _requestMap[_id];
require(
_req.functionId == _functionId &&
Expand All @@ -391,8 +391,8 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage
"Function id and arguments do not match."
);

_req.confirmers.add(_msgSender());
emit ConfirmRequest(_id, _msgSender(), _functionId, _firstArg, _secondArg, _thirdArg, _req.confirmers.values());
_req.confirmers.add(msg.sender);
emit ConfirmRequest(_id, msg.sender, _functionId, _firstArg, _secondArg, _thirdArg, _req.confirmers.values());

if (_req.confirmers.length() >= requirement) {
_executeRequest(_id);
Expand All @@ -418,7 +418,7 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage
bytes32 _secondArg,
bytes32 _thirdArg
) external override notConfirmedRequest(_id) onlyRole(ADMIN_ROLE) {
require(_hasConfirmed(_id, _msgSender()), "Msg.sender has not confirmed.");
require(_hasConfirmed(_id, msg.sender), "Msg.sender has not confirmed.");
Request storage _req = _requestMap[_id];
require(
_req.functionId == _functionId &&
Expand All @@ -428,14 +428,14 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage
"Function id and arguments do not match."
);

if (_req.requestProposer == _msgSender()) {
if (_req.requestProposer == msg.sender) {
_req.state = RequestState.Canceled;
emit CancelRequest(_id, _msgSender(), _req.functionId, _req.firstArg, _req.secondArg, _req.thirdArg);
emit CancelRequest(_id, msg.sender, _req.functionId, _req.firstArg, _req.secondArg, _req.thirdArg);
} else {
_req.confirmers.remove(_msgSender());
_req.confirmers.remove(msg.sender);
emit RevokeConfirmation(
_id,
_msgSender(),
msg.sender,
_req.functionId,
_req.firstArg,
_req.secondArg,
Expand Down Expand Up @@ -464,10 +464,10 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage
req.firstArg = _firstArg;
req.secondArg = _secondArg;
req.thirdArg = _thirdArg;
req.requestProposer = _msgSender();
req.requestProposer = msg.sender;
req.state = RequestState.NotConfirmed;

emit SubmitRequest(id, _msgSender(), _functionId, _firstArg, _secondArg, _thirdArg);
emit SubmitRequest(id, msg.sender, _functionId, _firstArg, _secondArg, _thirdArg);
return id;
}

Expand Down Expand Up @@ -499,10 +499,10 @@ contract CnStakingV3MultiSig is ICnStakingV3MultiSig, CnStakingV3MultiSigStorage

if (ok) {
req.state = RequestState.Executed;
emit ExecuteRequestSuccess(_id, _msgSender(), funcId, a1, a2, a3);
emit ExecuteRequestSuccess(_id, msg.sender, funcId, a1, a2, a3);
} else {
req.state = RequestState.ExecutionFailed;
emit ExecuteRequestFailure(_id, _msgSender(), funcId, a1, a2, a3);
emit ExecuteRequestFailure(_id, msg.sender, funcId, a1, a2, a3);
}
}

Expand Down
1,356 changes: 678 additions & 678 deletions contracts/contracts/system_contracts/consensus/Kip163.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,
/// @dev Stake KAIA to CnStakingV3.
/// Emits a Staked event.
function stake() external payable override {
_sweepAndStake(_msgSender(), msg.value);
_sweepAndStake(msg.sender, msg.value);
}

/// @dev Stake KAIA to CnStakingV3 for a specific address.
Expand All @@ -131,7 +131,7 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,

/// @dev Fallback function to receive KAIA.
receive() external payable override {
_sweepAndStake(_msgSender(), msg.value);
_sweepAndStake(msg.sender, msg.value);
}

/* ========== REDELEGATE FUNCTIONS ========== */
Expand All @@ -154,7 +154,7 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,
_sweepAndStake(address(0), 0);

uint256 _shares = previewWithdraw(_assets);
_burn(_msgSender(), _shares);
_burn(msg.sender, _shares);

_redelegate(_targetCnV3, _assets);
}
Expand All @@ -177,7 +177,7 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,
_sweepAndStake(address(0), 0);

uint256 _assets = previewRedeem(_shares);
_burn(_msgSender(), _shares);
_burn(msg.sender, _shares);

_redelegate(_targetCnV3, _assets);
}
Expand All @@ -201,10 +201,10 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,

uint256 _shares = previewWithdraw(_assets);

_burn(_msgSender(), _shares);
_requestWithdrawal(_msgSender(), _recipient, _assets);
_burn(msg.sender, _shares);
_requestWithdrawal(msg.sender, _recipient, _assets);

emit Redeemed(_msgSender(), _recipient, _assets, _shares);
emit Redeemed(msg.sender, _recipient, _assets, _shares);
}

/// @dev Request withdrawal of staked KAIA by shares.
Expand All @@ -224,10 +224,10 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,

uint256 _assets = previewRedeem(_shares);

_burn(_msgSender(), _shares);
_requestWithdrawal(_msgSender(), _recipient, _assets);
_burn(msg.sender, _shares);
_requestWithdrawal(msg.sender, _recipient, _assets);

emit Redeemed(_msgSender(), _recipient, _assets, _shares);
emit Redeemed(msg.sender, _recipient, _assets, _shares);
}

/* ========== CANCEL/CLAIM WITHDRAWAL FUNCTIONS ========== */
Expand Down Expand Up @@ -319,9 +319,9 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,
function _redelegate(address _targetCnV3, uint256 _assets) private {
require(_assets > 0, "Redelegate amount is too low.");

baseCnStakingV3.redelegate(_msgSender(), _targetCnV3, _assets);
baseCnStakingV3.redelegate(msg.sender, _targetCnV3, _assets);

emit Redelegated(_msgSender(), _targetCnV3, _assets);
emit Redelegated(msg.sender, _targetCnV3, _assets);
}

/// @dev Send the approved staking withdrawal.
Expand All @@ -337,21 +337,21 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,

/// @dev Cancel the approved staking withdrawal.
function _cancelApprovedStakingWithdrawal(uint256 _id) private {
require(requestIdToOwner[_id] == _msgSender(), "Not the owner of the request.");
require(requestIdToOwner[_id] == msg.sender, "Not the owner of the request.");

// Revive the shares
(, uint256 _assets, , ) = _withdrawalRequest(_id);
uint256 _shares = previewDeposit(_assets);
_mint(_msgSender(), _shares);
_mint(msg.sender, _shares);

baseCnStakingV3.cancelApprovedStakingWithdrawal(_id);

emit RequestCancelWithdrawal(_msgSender(), _id);
emit RequestCancelWithdrawal(msg.sender, _id);
}

/// @dev Claim the approved staking withdrawal.
function _claim(uint256 _id) private {
require(requestIdToOwner[_id] == _msgSender(), "Not the owner of the request.");
require(requestIdToOwner[_id] == msg.sender, "Not the owner of the request.");

baseCnStakingV3.withdrawApprovedStaking(_id);

Expand All @@ -361,11 +361,11 @@ contract PublicDelegation is IPublicDelegation, PublicDelegationStorage, ERC20,
// Since the `_totalAsset()` was already increased by _asset, it needs to be subtracted.
if (_state == ICnStakingV3.WithdrawalStakingState.Canceled) {
uint256 _shares = _convertToShares(_asset, totalSupply(), _totalAssets() - _asset);
_mint(_msgSender(), _shares);
_mint(msg.sender, _shares);
return;
}

emit Claimed(_msgSender(), _id);
emit Claimed(msg.sender, _id);
}

/// @dev Send the commission to the commission address.
Expand Down
16 changes: 11 additions & 5 deletions contracts/contracts/system_contracts/kaiabridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ contract KAIABridge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeabl
/// @param initOperator operator address
/// @param initGuardian guardian address
/// @param initJudge Judge contract address
function initialize(address initOperator, address initGuardian, address initJudge, uint256 newMaxTryTransfer) public initializer {
function initialize(address initOperator, address initGuardian, address initJudge, uint256 newMaxTryTransfer)
public
initializer
notNull(initOperator)
notNull(initGuardian)
notNull(initJudge)
{
require(IERC165(initOperator).supportsInterface(type(IOperator).interfaceId), "KAIA::Bridger: Operator contract address does not implement IOperator");
__ReentrancyGuard_init();
bridgeServiceStarted = block.timestamp;
Expand Down Expand Up @@ -292,19 +298,19 @@ contract KAIABridge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeabl
}

/// @dev See {IBridge-changeOperator}
function changeOperator(address newOperator) public override onlyGuardian {
function changeOperator(address newOperator) public override onlyGuardian notNull(newOperator) {
emit ChangeOperator(operator, newOperator);
operator = newOperator;
}

/// @dev See {IBridge-changeGuardian}
function changeGuardian(address newGuardian) public override onlyGuardian {
function changeGuardian(address newGuardian) public override onlyGuardian notNull(newGuardian) {
emit ChangeGuardian(guardian, newGuardian);
guardian = newGuardian;
}

/// @dev See {IBridge-changeJudge}
function changeJudge(address newJudge) public override onlyGuardian {
function changeJudge(address newJudge) public override onlyGuardian notNull(newJudge) {
emit ChangeJudge(judge, newJudge);
judge = newJudge;
}
Expand Down Expand Up @@ -465,7 +471,7 @@ contract KAIABridge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeabl
emit KAIACharged(msg.sender, msg.value);
}

function burnBridgeBalance() public override onlyGuardian inPause {
function burnBridgeBalance() public override onlyGuardian inPause nonReentrant {
require(block.timestamp > bridgeServicePeriod, "KAIA::Bridge: Service period is not expired yet");
uint256 bridgeBalance = address(this).balance;
(bool sent, ) = BURN_TARGET.call{value: bridgeBalance}("");
Expand Down
4 changes: 3 additions & 1 deletion contracts/contracts/system_contracts/kaiabridge/Guardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract Guardian is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable,
onlyGuardian
guardianExists(guardian)
{
require(guardians.length > 1, "KAIA::Guardian: Guardian size must be greater than one to remove a guardian");
isGuardian[guardian] = false;
for (uint256 i=0; i<guardians.length - 1; i++)
if (guardians[i] == guardian) {
Expand All @@ -94,6 +95,7 @@ contract Guardian is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable,
onlyGuardian
guardianExists(guardian)
guardianDoesNotExist(newGuardian)
notNull(newGuardian)
{
for (uint256 i=0; i<guardians.length; i++) {
if (guardians[i] == guardian) {
Expand Down Expand Up @@ -210,7 +212,7 @@ contract Guardian is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable,
emit Submission(txID);

if (uniqUserTxIndex != 0) {
require(userIdx2TxID[uniqUserTxIndex] == 0, "KAIA::Operator: Submission to txID exists");
require(userIdx2TxID[uniqUserTxIndex] == 0, "KAIA::Guardian: Submission to txID exists");
userIdx2TxID[uniqUserTxIndex] = txID;
}
return txID;
Expand Down
5 changes: 5 additions & 0 deletions contracts/contracts/system_contracts/kaiabridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ abstract contract IBridge {
}

//////////////////// Modifier ////////////////////
modifier notNull(address addr) {
require(addr != address(0), "KAIA::Guardian: A zero address is not allowed");
_;
}

modifier onlyOperator {
require(operator == msg.sender, "KAIA::Bridge: Not an operator");
_;
Expand Down
4 changes: 3 additions & 1 deletion contracts/contracts/system_contracts/kaiabridge/Judge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ contract Judge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable, IE
onlyGuardian
judgeExists(judge)
judgeDoesNotExist(newJudge)
notNull(newJudge)
{
for (uint256 i=0; i<judges.length; i++) {
if (judges[i] == judge) {
Expand All @@ -116,6 +117,7 @@ contract Judge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable, IE
public
override
onlyGuardian
notNull(newGuardian)
{
emit ChangeGuardian(guardian, newGuardian);
guardian = newGuardian;
Expand Down Expand Up @@ -224,7 +226,7 @@ contract Judge is Initializable, ReentrancyGuardUpgradeable, UUPSUpgradeable, IE
emit Submission(txID);

if (uniqUserTxIndex != 0) {
require(userIdx2TxID[uniqUserTxIndex] == 0, "KAIA::Operator: Submission to txID exists");
require(userIdx2TxID[uniqUserTxIndex] == 0, "KAIA::Judge: Submission to txID exists");
userIdx2TxID[uniqUserTxIndex] = txID;
}
return txID;
Expand Down
Loading

0 comments on commit 5d5a37b

Please sign in to comment.