Skip to content

Commit

Permalink
split logic into delegate and delegateFor functions, restored old Go …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
Zodomo committed Dec 18, 2024
1 parent af3a71f commit 1bc71e1
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 43 deletions.
5 changes: 0 additions & 5 deletions cli/cmd/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,7 @@ func newDelegateCmd() *cobra.Command {
return cmd
}

<<<<<<< HEAD
func Delegate(ctx context.Context, cfg DelegateConfig) error {
=======
// Note(zodomo): This still needs to be updated to support non-self delegation.
func delegate(ctx context.Context, cfg delegateConfig) error {
>>>>>>> b893b3e (implemented user stake delegation, cli still only supports validator self-delegation)
delegatorPriv, err := cfg.privateKey()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion contracts/allocs/devnet.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/allocs/staging.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/admin.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/allocpredeploys.go

Large diffs are not rendered by default.

49 changes: 35 additions & 14 deletions contracts/bindings/staking.go

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions contracts/core/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Admin_Test:test_pause_unpause() (gas: 33930691)
Admin_Test:test_pause_unpause_bridge() (gas: 28960444)
Admin_Test:test_pause_unpause_xcall() (gas: 33884665)
Admin_Test:test_pause_unpause_xsubmit() (gas: 33884372)
Admin_Test:test_upgrade() (gas: 37965866)
AllocPredeploys_Test:test_num_allocs() (gas: 1181319043)
AllocPredeploys_Test:test_predeploys() (gas: 1181300853)
AllocPredeploys_Test:test_preinstalls() (gas: 1182017269)
AllocPredeploys_Test:test_proxies() (gas: 1408944070)
Admin_Test:test_pause_unpause() (gas: 34067696)
Admin_Test:test_pause_unpause_bridge() (gas: 29097449)
Admin_Test:test_pause_unpause_xcall() (gas: 34021670)
Admin_Test:test_pause_unpause_xsubmit() (gas: 34021377)
Admin_Test:test_upgrade() (gas: 38102871)
AllocPredeploys_Test:test_num_allocs() (gas: 1181324720)
AllocPredeploys_Test:test_predeploys() (gas: 1181306530)
AllocPredeploys_Test:test_preinstalls() (gas: 1182022946)
AllocPredeploys_Test:test_proxies() (gas: 1408949747)
FeeOracleV1_Test:test_bulkSetFeeParams() (gas: 173154)
FeeOracleV1_Test:test_feeFor() (gas: 122830)
FeeOracleV1_Test:test_setBaseGasLimit() (gas: 32375)
Expand Down Expand Up @@ -149,8 +149,8 @@ Quorum_Test:test_verify_sigsNotSorted_reverts() (gas: 282992)
Quorum_Test:test_verify_succeeds() (gas: 294059)
Slashing_Test:test_stub() (gas: 143)
Slashing_Test:test_unjail() (gas: 54734)
Staking_Test:test_createValidator() (gas: 145464)
Staking_Test:test_delegate() (gas: 99147)
Staking_Test:test_createValidator() (gas: 145288)
Staking_Test:test_delegate() (gas: 98742)
Staking_Test:test_stub() (gas: 143)
Upgrade_Test:test_stub() (gas: 143)
XAppUpgradeable_Test:test_isXCall() (gas: 148924)
Expand Down
9 changes: 7 additions & 2 deletions contracts/core/script/admin/StakingPostUpgradeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ contract StakingPostUpgradeTest is Test {

function _testDelegate() internal {
uint256 deposit = staking.MinDelegation();
vm.deal(validator, deposit);
vm.deal(validator, deposit * 2);

vm.expectEmit();
emit Staking.Delegate(validator, validator, deposit);
vm.prank(validator);
staking.delegate{ value: deposit }(validator);

vm.expectEmit();
emit Staking.Delegate(validator, validator, deposit);
vm.prank(validator);
staking.delegate{ value: deposit }(validator, validator);
staking.delegateFor{ value: deposit }(validator, validator);
}
}
17 changes: 15 additions & 2 deletions contracts/core/src/octane/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,23 @@ contract Staking is OwnableUpgradeable, EIP712Upgradeable {
}

/**
* @notice Increase your validators self delegation.
* @notice Delegate tokens to a validator
* @dev Proxies x/staking.MsgDelegate
* @param validator The address of the validator to delegate to
*/
function delegate(address delegator, address validator) external payable {
function delegate(address validator) external payable {
require(!isAllowlistEnabled || isAllowedValidator[validator], "Staking: not allowed val");
require(msg.value >= MinDelegation, "Staking: insufficient deposit");

emit Delegate(msg.sender, validator, msg.value);
}

/**
* @notice Delegate tokens to a validator for another address
* @param delegator The address of the delegator
* @param validator The address of the validator to delegate to
*/
function delegateFor(address delegator, address validator) external payable {
require(!isAllowlistEnabled || isAllowedValidator[validator], "Staking: not allowed val");
require(msg.value >= MinDelegation, "Staking: insufficient deposit");

Expand Down
6 changes: 3 additions & 3 deletions contracts/core/test/octane/Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ contract Staking_Test is Test {
vm.deal(validator, minDelegation);

vm.expectRevert("Staking: insufficient deposit");
staking.delegate{ value: minDelegation - 1 }(validator, validator);
staking.delegate{ value: minDelegation - 1 }(validator);

// if allowlist enabled, must be in allowlist
vm.prank(owner);
staking.enableAllowlist();

vm.expectRevert("Staking: not allowed val");
vm.prank(validator);
staking.delegate{ value: minDelegation }(validator, validator);
staking.delegate{ value: minDelegation }(validator);

// succeeds
address[] memory validators = new address[](1);
Expand All @@ -135,7 +135,7 @@ contract Staking_Test is Test {
emit Delegate(validator, validator, minDelegation);

vm.prank(validator);
staking.delegate{ value: minDelegation }(validator, validator);
staking.delegate{ value: minDelegation }(validator);
}
}

Expand Down
Loading

0 comments on commit 1bc71e1

Please sign in to comment.