Skip to content

Commit 0cf0ec4

Browse files
committed
refactor: replaced Core._setStakeBySystem by ._setStake
Neo NFT checking moved from CoreNeo to VaultNeo
1 parent 9d87373 commit 0cf0ec4

File tree

4 files changed

+10
-76
lines changed

4 files changed

+10
-76
lines changed

contracts/src/arbitration/KlerosCoreXBase.sol

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,13 @@ abstract contract KlerosCoreXBase is IArbitratorV2, Initializable, UUPSProxiable
474474
/// @param _courtID The ID of the court.
475475
/// @param _newStake The new stake amount for the juror in the court.
476476
/// @return success Whether the stake was successfully set or not.
477-
function setStakeBySystem(
477+
function setStakeByController(
478478
address _account,
479479
uint96 _courtID,
480480
uint256 _newStake
481481
) external onlyStakeController returns (bool success) {
482-
return _setStakeBySystem(_account, _courtID, _newStake);
482+
// TODO: use TRY/CATCH ?? then delete _stakingFailed()
483+
return _setStake(_account, _courtID, _newStake, OnError.Return);
483484
}
484485

485486
/// @inheritdoc IArbitratorV2
@@ -1121,47 +1122,6 @@ abstract contract KlerosCoreXBase is IArbitratorV2, Initializable, UUPSProxiable
11211122
return true;
11221123
}
11231124

1124-
/// @dev Internal implementation of setStakeBySystem
1125-
/// @param _account The account to set the stake for.
1126-
/// @param _courtID The ID of the court to set the stake for.
1127-
/// @param _newStake The new stake.
1128-
/// @return success Whether the stake was successfully set or not.
1129-
function _setStakeBySystem(
1130-
address _account,
1131-
uint96 _courtID,
1132-
uint256 _newStake
1133-
) internal virtual returns (bool success) {
1134-
(uint256 pnkDeposit, uint256 pnkWithdrawal, StakingResult stakingResult) = stakeController.setStake(
1135-
_account,
1136-
_courtID,
1137-
_newStake
1138-
);
1139-
OnError onError = OnError.Return;
1140-
if (stakingResult != StakingResult.Successful) {
1141-
_stakingFailed(onError, stakingResult);
1142-
return false;
1143-
}
1144-
if (pnkDeposit > 0) {
1145-
try vault.deposit(_account, pnkDeposit) {
1146-
// Successfully deposited PNK
1147-
} catch {
1148-
// Revert with a specific error or reuse existing one
1149-
_stakingFailed(onError, StakingResult.StakingTransferFailed); // Indicating failure in the deposit part of staking
1150-
return false;
1151-
}
1152-
}
1153-
if (pnkWithdrawal > 0) {
1154-
try vault.withdraw(_account, pnkWithdrawal) {
1155-
// Successfully withdrew PNK via Vault
1156-
} catch {
1157-
// Revert with a specific error or reuse existing one
1158-
_stakingFailed(onError, StakingResult.UnstakingTransferFailed); // Indicating failure in the withdrawal part of unstaking
1159-
return false;
1160-
}
1161-
}
1162-
return true;
1163-
}
1164-
11651125
/// @dev It may revert depending on the _onError parameter.
11661126
function _stakingFailed(OnError _onError, StakingResult _result) internal pure virtual {
11671127
if (_onError == OnError.Return) return;
@@ -1221,6 +1181,7 @@ abstract contract KlerosCoreXBase is IArbitratorV2, Initializable, UUPSProxiable
12211181
error InvalidForkingCourtAsParent();
12221182
error WrongDisputeKitIndex();
12231183
error CannotDisableClassicDK();
1184+
error StakingZeroWhenNoStake();
12241185
error StakingInTooManyCourts();
12251186
error StakingNotPossibleInThisCourt();
12261187
error StakingLessThanCourtMinStake();
@@ -1244,5 +1205,4 @@ abstract contract KlerosCoreXBase is IArbitratorV2, Initializable, UUPSProxiable
12441205
error TransferFailed();
12451206
error WhenNotPausedOnly();
12461207
error WhenPausedOnly();
1247-
error StakingZeroWhenNoStake();
12481208
}

contracts/src/arbitration/KlerosCoreXNeo.sol

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import "./KlerosCoreXBase.sol";
66
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
77

88
/// @title KlerosCoreXNeo
9-
/// @notice KlerosCore implementation with new StakeController architecture for production environments
9+
/// @notice KlerosCore with whitelisted arbitrables
1010
contract KlerosCoreXNeo is KlerosCoreXBase {
11-
/// @notice Version of the implementation contract
1211
string public constant override version = "0.0.1";
1312

1413
// ************************************* //
1514
// * Storage * //
1615
// ************************************* //
1716

1817
mapping(address => bool) public arbitrableWhitelist; // Arbitrable whitelist.
19-
IERC721 public jurorNft; // Eligible jurors NFT.
2018

2119
// ************************************* //
2220
// * Constructor * //
@@ -37,7 +35,6 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
3735
/// @param _timesPerPeriod The timesPerPeriod array for courts
3836
/// @param _sortitionExtraData Extra data for sortition module setup
3937
/// @param _stakeController The stake controller for coordination
40-
/// @param _jurorNft NFT contract to vet the jurors
4138
function initialize(
4239
address _governor,
4340
address _guardian,
@@ -48,8 +45,7 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
4845
uint256[4] memory _timesPerPeriod,
4946
bytes memory _sortitionExtraData,
5047
IStakeController _stakeController,
51-
IVault _vault,
52-
IERC721 _jurorNft
48+
IVault _vault
5349
) external reinitializer(2) {
5450
__KlerosCoreXBase_initialize(
5551
_governor,
@@ -63,7 +59,6 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
6359
_stakeController,
6460
_vault
6561
);
66-
jurorNft = _jurorNft;
6762
}
6863

6964
function initialize5() external reinitializer(5) {
@@ -77,13 +72,7 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
7772
/// @notice Access Control to perform implementation upgrades (UUPS Proxiable)
7873
/// Only the governor can perform upgrades (`onlyByGovernor`)
7974
function _authorizeUpgrade(address) internal view override onlyByGovernor {
80-
// Empty block: access control implemented by `onlyByGovernor` modifier
81-
}
82-
83-
/// @dev Changes the `jurorNft` storage variable.
84-
/// @param _jurorNft The new value for the `jurorNft` storage variable.
85-
function changeJurorNft(IERC721 _jurorNft) external onlyByGovernor {
86-
jurorNft = _jurorNft;
75+
// NOP
8776
}
8877

8978
/// @dev Adds or removes an arbitrable from whitelist.
@@ -93,20 +82,6 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
9382
arbitrableWhitelist[_arbitrable] = _allowed;
9483
}
9584

96-
// ************************************* //
97-
// * State Modifiers * //
98-
// ************************************* //
99-
100-
/// @dev Sets the caller's stake in a court.
101-
/// Note: Staking and unstaking is forbidden during pause.
102-
/// @param _courtID The ID of the court.
103-
/// @param _newStake The new stake.
104-
/// Note that the existing delayed stake will be nullified as non-relevant.
105-
function setStake(uint96 _courtID, uint256 _newStake) external override whenNotPaused {
106-
if (jurorNft.balanceOf(msg.sender) == 0) revert NotEligibleForStaking();
107-
_setStake(msg.sender, _courtID, _newStake, OnError.Revert);
108-
}
109-
11085
// ************************************* //
11186
// * Internal * //
11287
// ************************************* //
@@ -131,7 +106,6 @@ contract KlerosCoreXNeo is KlerosCoreXBase {
131106
// * Errors * //
132107
// ************************************* //
133108

134-
error NotEligibleForStaking();
135109
error StakingMoreThanMaxStakePerJuror();
136110
error StakingMoreThanMaxTotalStaked();
137111
error ArbitrableNotWhitelisted();

contracts/src/arbitration/StakeControllerBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ abstract contract StakeControllerBase is IStakeController, Initializable, UUPSPr
188188
if (delayedStake.account == address(0)) continue;
189189

190190
// Let KlerosCore coordinate stake update and vault deposit/withdrawal.
191-
core.setStakeBySystem(delayedStake.account, delayedStake.courtID, delayedStake.stake);
191+
core.setStakeByController(delayedStake.account, delayedStake.courtID, delayedStake.stake);
192192
delete delayedStakes[i];
193193
}
194194
delayedStakeReadIndex = newDelayedStakeReadIndex;

contracts/src/arbitration/VaultNeo.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract VaultNeo is VaultBase {
103103
function _deposit(address _from, uint256 _amount) internal override {
104104
// Check NFT requirement if set
105105
if (address(depositNft) != address(0) && depositNft.balanceOf(_from) == 0) {
106-
revert DepositNftRequired();
106+
revert NotEligible();
107107
}
108108

109109
// Check per-user deposit limit
@@ -135,7 +135,7 @@ contract VaultNeo is VaultBase {
135135
// * Errors * //
136136
// ************************************* //
137137

138-
error DepositNftRequired();
138+
error NotEligible();
139139
error ExceedsMaxDepositPerUser();
140140
error ExceedsTotalDepositCap();
141141
}

0 commit comments

Comments
 (0)