Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement KRO-based validator system #374

Merged
merged 81 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
bcafeda
feat(contracts): add arctangent library
sm-stack Mar 8, 2024
7bc46e5
feat(contracts): add AssetManager contract
sm-stack Mar 8, 2024
34a2700
feat(contracts): add interface for KGHManager contract
sm-stack Mar 8, 2024
15e0c7f
feat(contracts): add test codes for AssetManager
sm-stack Mar 8, 2024
cef7a30
feat(contracts): add Uint128Math library
sm-stack Mar 11, 2024
a726010
feat(contracts): add balanced weight tree library
seolaoh Mar 11, 2024
1c9e2ad
fix(contracts): check correct minimum timestamp for next output submi…
seolaoh Feb 28, 2024
62c9912
feat(contracts): add `ValidatorManager` contract and refac `AssetMana…
seolaoh Mar 29, 2024
0cb9f85
feat(contracts): handle validator system upgrade in `L2OutputOracle`
seolaoh Mar 18, 2024
208cd2a
feat(chain-ops): apply changes with `AssetManager` and `ValidatorMana…
seolaoh Mar 27, 2024
0108d07
chore(contracts): update bindings and snapshots
seolaoh Mar 29, 2024
c39f2da
feat(contracts): apply PR reviews
seolaoh Apr 18, 2024
a96e0a2
feat(contracts): upgrade validator system in `Colosseum`
seolaoh Apr 17, 2024
dbed8b6
refac(contracts): replace all errors with custom error in `Colosseum`
seolaoh Apr 17, 2024
1a693d3
feat(contracts): send the challenge loser to jail when slashing
seolaoh Apr 18, 2024
0d94687
refac(contracts): move interfaces to separate folder
seolaoh Apr 18, 2024
85f26e8
refac(contracts): add `IAssetManager`
seolaoh Apr 18, 2024
d30a495
test(contracts): modify tests related to slashing
seolaoh Apr 19, 2024
edf7208
test(contracts): add tests for validator system upgrade in `Colosseum`
seolaoh Apr 21, 2024
9d1bfff
chore(contracts): update bindings and snapshots
seolaoh Apr 21, 2024
16802c3
feat(contracts): apply PR reviews
seolaoh Apr 23, 2024
2511cbc
feat(validator): add logics for new validator system
sm-stack Apr 2, 2024
852e5b8
feat(e2e): add action tests for new validator system
sm-stack Apr 2, 2024
0c05940
chore: set required flags for devnet
sm-stack Apr 17, 2024
02d5012
fix(validator): add real-time update logic for terminate index of Val…
sm-stack Apr 21, 2024
333f513
fix(contracts): fix ValidatorPool to check termination by index
sm-stack Apr 22, 2024
95665a2
fix(validator): remove inJail status in the validator client
sm-stack Apr 22, 2024
8169f41
feat(validator): apply PR Reviews
sm-stack Apr 23, 2024
85c9784
feat(validator): add subcommands for the new validator system
sm-stack Apr 17, 2024
845b217
feat(validator): add flags used in subcommands
sm-stack Apr 23, 2024
8a5d782
docs(validator): add README for subcommands
sm-stack Apr 24, 2024
a5a8009
feat(validator): add PR reviews
sm-stack Apr 24, 2024
7142220
fix(validator): fix subcommand related changes
seolaoh May 2, 2024
6bfa308
test(validator): redeploy `ValidatorPool` to test `ValidatorManager`
seolaoh May 3, 2024
c99be8b
refac(validator): reorder functions of l2_validator
seolaoh May 7, 2024
2195eca
test(validator): add challenger actions test for `ValidatorManager`
seolaoh May 7, 2024
3d8e78b
refac(validator): reorder functions of l2_challenger_test
seolaoh May 7, 2024
80817d4
refac(validator): add runtime functions to use in validator actions test
seolaoh May 8, 2024
06bff6d
refac(validator): reorder functions of l2_runtime
seolaoh May 8, 2024
64592da
test(validator): apply PR reviews
seolaoh May 9, 2024
46cc561
Merge branch 'refs/heads/dev' into feat/implement-validator-system-v2
seolaoh May 10, 2024
6ce71fb
feat(validator): modify guardian to handle challenger timeout (#320)
seolaoh May 17, 2024
c6cce6f
feat(contracts): support validator system V2 from genesis (#322)
seolaoh May 21, 2024
7f91022
test(e2e): add tests about validator system V2 (#323)
seolaoh May 27, 2024
9c41722
fix: remove validator from tree when sending to jail (#325)
seolaoh May 29, 2024
9c507ba
fix(contracts): fix some bugs related to `AssetManager` (#327)
seolaoh Jun 5, 2024
1474ae4
fix(validator): change challenger and guardian scan until head L1 (#330)
seolaoh Jun 5, 2024
7359dbe
Merge branch 'refs/heads/dev' into feat/implement-validator-system-v2
seolaoh Jun 7, 2024
38772d2
Merge branch 'refs/heads/dev' into feat/implement-validator-system-v2
seolaoh Jul 3, 2024
14047a3
feat: deploy `GovernanceToken` using normal proxy for devnet
seolaoh Jul 4, 2024
481160e
Merge remote-tracking branch 'origin/dev' into feat/implement-validat…
seolaoh Jul 12, 2024
45760b5
feat(contracts): add withdraw account to validator (#343)
0xHansLee Jul 15, 2024
b9c706a
feat: add delay of commission rate change (#345)
seolaoh Jul 17, 2024
99e6a68
feat(contracts): separate validator kro from delegation pool (#344)
0xHansLee Jul 17, 2024
104b313
feat(contracts): fix interface of `ValidatorManager`, `AssetManager` …
seolaoh Jul 18, 2024
a7529b0
feat(contracts): bond validator KRO (#347)
seolaoh Jul 19, 2024
6e0ec89
feat: implement claimKghReward function (#348)
sm-stack Jul 19, 2024
bf82155
feat: remove KGH share and modify KGH delegation func (#349)
0xHansLee Jul 19, 2024
ceedcb0
feat(contracts): separate jail period (#352)
sm-stack Jul 22, 2024
b5b2ec9
feat(contracts): unbond validator KRO (#351)
seolaoh Jul 22, 2024
627c070
feat(contracts): add transferFrom when increasing reward of vault (#354)
sm-stack Jul 22, 2024
7abe40c
feat(contracts): update validator reward calculation (#355)
sm-stack Jul 22, 2024
8eab79f
feat(contracts): implement 1-step undelegation of KRO (#350)
0xHansLee Jul 22, 2024
e0f36b0
feat(contracts): implement 1-step undelegation for KGH (#353)
0xHansLee Jul 23, 2024
b7dd902
chore: remove 2 step claim of validator reward. (#356)
0xHansLee Jul 23, 2024
f8bbed7
feat(contracts): remove KRO in KGH (#358)
seolaoh Jul 23, 2024
0b00b05
feat(contracts): add withdraw method for validator (#357)
sm-stack Jul 23, 2024
3f0e5ec
test(contracts): setup for `AssetManager` and `ValidatorManager` (#359)
seolaoh Jul 23, 2024
c0c77dd
test(contracts): add `AssetManager` tests (#361)
seolaoh Jul 25, 2024
c77accc
feat: change validator client subcommands (#360)
sm-stack Jul 25, 2024
01f14c6
feat: modify validator client for validator system V2 (#362)
sm-stack Jul 26, 2024
b70a4e3
test(contracts): modify `Colosseum` tests related to V2 (#363)
seolaoh Jul 26, 2024
1c302b5
test: fix validator manager contract tests (#364)
0xHansLee Jul 26, 2024
042efa8
feat(contracts): modify deploy scripts (#365)
seolaoh Jul 30, 2024
5583cf9
test(validator): modify e2e tests related to V2 (#366)
seolaoh Jul 30, 2024
ab37de4
feat(contracts): auto activate validator when deposit (#367)
seolaoh Jul 31, 2024
aca9645
fix(validator): modify validator to be able to turn on without V2 (#368)
seolaoh Aug 1, 2024
f885f5f
fix(validator): disable validator to be turned on without V2 (#369)
seolaoh Aug 2, 2024
96aec79
fix(contracts): avoid overflow error during calculating output reward…
seolaoh Aug 2, 2024
4f5570d
feat(contracts): apply audit results (#373)
seolaoh Aug 22, 2024
75ae796
Merge branch 'refs/heads/dev' into feat/implement-validator-system-v2
seolaoh Aug 23, 2024
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
Prev Previous commit
Next Next commit
feat(contracts): add withdraw method for validator (#357)
* feat: add withdraw method for validator

* feat: apply PR reviews

* feat: review applied

* feat: review applied

* feat: review applied
  • Loading branch information
sm-stack authored Jul 23, 2024
commit 0b00b05b5f2e0fd8abf5b678669e8b401544fdb5
53 changes: 51 additions & 2 deletions packages/contracts/contracts/L1/AssetManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager {
_;
}

/**
* @notice Modifier to check if the caller is the withdraw account of the validator.
*/
modifier onlyWithdrawAccount(address validator) {
if (msg.sender != _vaults[validator].withdrawAccount) revert NotAllowedCaller();
_;
}

/**
* @notice Semantic version.
* @custom:semver 1.0.0
Expand Down Expand Up @@ -190,6 +198,13 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager {
MIN_DELEGATION_PERIOD;
}

/**
* @inheritdoc IAssetManager
*/
function canWithdrawAt(address validator) public view returns (uint128) {
return _vaults[validator].lastDepositedAt + MIN_DELEGATION_PERIOD;
}

/**
* @inheritdoc IAssetManager
*/
Expand Down Expand Up @@ -284,6 +299,24 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager {
emit Deposited(msg.sender, assets);
}

/**
* @inheritdoc IAssetManager
*/
function withdraw(address validator, uint128 assets) external onlyWithdrawAccount(validator) {
if (assets == 0) revert NotAllowedZeroInput();
if (canWithdrawAt(validator) > block.timestamp) {
revert NotElapsedMinDelegationPeriod();
}

_withdraw(validator, assets);

VALIDATOR_MANAGER.updateValidatorTree(validator, true);

ASSET_TOKEN.safeTransfer(_vaults[validator].withdrawAccount, assets);

emit Withdrawn(validator, assets);
}

/**
* @inheritdoc IAssetManager
*/
Expand Down Expand Up @@ -664,18 +697,34 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager {
* @param updateTree Flag to update the validator tree.
*/
function _deposit(address validator, uint128 assets, bool updateTree) internal {
Asset storage asset = _vaults[validator].asset;
Vault storage vault = _vaults[validator];
ASSET_TOKEN.safeTransferFrom(validator, address(this), assets);

unchecked {
asset.validatorKro += assets;
vault.asset.validatorKro += assets;
vault.lastDepositedAt = uint128(block.timestamp);
}

if (updateTree) {
VALIDATOR_MANAGER.updateValidatorTree(validator, false);
}
}

/**
* @notice Internal function to withdraw KRO by the validator.
*
* @param validator Address of the validator.
* @param assets The amount of KRO to withdraw.
*/
function _withdraw(address validator, uint128 assets) internal {
Asset storage asset = _vaults[validator].asset;
if (assets > asset.validatorKro - asset.validatorKroBonded) revert InsufficientAsset();

unchecked {
asset.validatorKro -= assets;
}
}

/**
* @notice Internal function to delegate KRO to the validator.
*
Expand Down
17 changes: 10 additions & 7 deletions packages/contracts/contracts/L1/interfaces/IAssetManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ interface IAssetManager {
*/
function deposit(uint128 assets) external;

/**
* @notice Withdraw KRO. To withdraw KRO, the validator should be initiated and MIN_DELEGATION_PERIOD
* should be passed after the last deposit time. Only withdrawAccount of the validator can call
* this function.
*
* @param validator Address of the validator.
* @param assets The amount of KRO to withdraw.
*/
function withdraw(address validator, uint128 assets) external;

/**
* @notice Delegate KRO to the validator and returns the amount of shares that the vault would
* exchange.
Expand Down Expand Up @@ -427,13 +437,6 @@ interface IAssetManager {
*/
function delegateKghBatch(address validator, uint256[] calldata tokenIds) external;

/**
* @notice Withdraw KRO by the validator.
*
* @param assets The amount of KRO to withdraw.
*/
function withdraw(uint128 assets) external;

/**
* @notice Undelegate the KRO of given assets for the given validator.
*
Expand Down