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

fix(staking): fix redelegate #257

Merged
merged 1 commit into from
Oct 20, 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
4 changes: 2 additions & 2 deletions contracts/src/interfaces/IIPTokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ interface IIPTokenStaking {
bytes calldata validatorUncmpDstPubkey,
uint256 delegationId,
uint256 amount
) external payable;
) external;

/// @notice Entry point for redelegating the stake to another validator on behalf of the delegator.
/// @dev For non flexible staking, your staking period will continue as is.
Expand All @@ -284,7 +284,7 @@ interface IIPTokenStaking {
bytes calldata validatorUncmpDstPubkey,
uint256 delegationId,
uint256 amount
) external payable;
) external;

/// @notice Entry point for unstaking the previously staked token.
/// @dev Unstake (withdrawal) will trigger native minting, so token in this contract is considered as burned.
Expand Down
6 changes: 2 additions & 4 deletions contracts/src/protocol/IPTokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
uint256 amount
)
external
payable
verifyUncmpPubkeyWithExpectedAddress(delegatorUncmpPubkey, msg.sender)
verifyUncmpPubkey(validatorUncmpSrcPubkey)
verifyUncmpPubkey(validatorUncmpDstPubkey)
Expand All @@ -441,7 +440,6 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
uint256 amount
)
external
payable
verifyUncmpPubkey(delegatorUncmpPubkey)
verifyUncmpPubkey(validatorUncmpSrcPubkey)
verifyUncmpPubkey(validatorUncmpDstPubkey)
Expand All @@ -460,7 +458,7 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
keccak256(validatorUncmpSrcPubkey) != keccak256(validatorUncmpDstPubkey),
"IPTokenStaking: Redelegating to same validator"
);
(uint256 stakeAmount, ) = roundedStakeAmount(msg.value);
(uint256 stakeAmount, ) = roundedStakeAmount(amount);
require(stakeAmount >= minStakeAmount, "IPTokenStaking: Stake amount under min");
require(delegationId <= _delegationIdCounter, "IPTokenStaking: Invalid delegation id");

Expand All @@ -470,7 +468,7 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
validatorUncmpDstPubkey,
delegationId,
msg.sender,
amount
stakeAmount
);
}

Expand Down
30 changes: 15 additions & 15 deletions contracts/test/stake/IPTokenStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ contract IPTokenStakingTest is Test {
);
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
Expand All @@ -390,7 +390,7 @@ contract IPTokenStakingTest is Test {
vm.deal(address(0x4545), stakeAmount);
vm.prank(address(0x4545));
vm.expectRevert("PubKeyVerifier: Invalid pubkey derived address");
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
Expand All @@ -402,7 +402,7 @@ contract IPTokenStakingTest is Test {
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectRevert("IPTokenStaking: Redelegating to same validator");
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpSrcPubkey,
Expand All @@ -413,7 +413,7 @@ contract IPTokenStakingTest is Test {
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectRevert("PubKeyVerifier: Invalid pubkey length");
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
validatorUncmpDstPubkey,
Expand All @@ -424,7 +424,7 @@ contract IPTokenStakingTest is Test {
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectRevert("PubKeyVerifier: Invalid pubkey length");
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
Expand All @@ -435,19 +435,19 @@ contract IPTokenStakingTest is Test {
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectRevert("IPTokenStaking: Stake amount under min");
ipTokenStaking.redelegate{ value: stakeAmount - 1 }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
delegationId,
stakeAmount + 100
stakeAmount - 1
);

// Revert if delegationId is invalid
delegationId++;
vm.prank(delegatorAddr);
vm.expectRevert("IPTokenStaking: Invalid delegation id");
ipTokenStaking.redelegate{ value: stakeAmount }(
ipTokenStaking.redelegate(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
Expand Down Expand Up @@ -483,7 +483,7 @@ contract IPTokenStakingTest is Test {
);
vm.deal(operator, stakeAmount);
vm.prank(operator);
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
Expand All @@ -495,7 +495,7 @@ contract IPTokenStakingTest is Test {
vm.deal(operator, stakeAmount);
vm.prank(operator);
vm.expectRevert("IPTokenStaking: Redelegating to same validator");
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpSrcPubkey,
Expand All @@ -506,7 +506,7 @@ contract IPTokenStakingTest is Test {
vm.deal(operator, stakeAmount);
vm.prank(operator);
vm.expectRevert("PubKeyVerifier: Invalid pubkey length");
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
validatorUncmpDstPubkey,
Expand All @@ -517,7 +517,7 @@ contract IPTokenStakingTest is Test {
vm.deal(operator, stakeAmount);
vm.prank(operator);
vm.expectRevert("PubKeyVerifier: Invalid pubkey length");
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
Expand All @@ -528,19 +528,19 @@ contract IPTokenStakingTest is Test {
vm.deal(operator, stakeAmount);
vm.prank(operator);
vm.expectRevert("IPTokenStaking: Stake amount under min");
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount - 1 }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
delegationId,
stakeAmount + 100
stakeAmount - 1
);

// Revert if delegationId is invalid
delegationId++;
vm.prank(operator);
vm.expectRevert("IPTokenStaking: Invalid delegation id");
ipTokenStaking.redelegateOnBehalf{ value: stakeAmount }(
ipTokenStaking.redelegateOnBehalf(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
validatorUncmpDstPubkey,
Expand Down
Loading