Skip to content

Commit

Permalink
staketia migration (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Jun 13, 2024
1 parent 74c51cb commit 99d773f
Show file tree
Hide file tree
Showing 43 changed files with 5,087 additions and 3,121 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ func NewStrideApp(
app.BankKeeper,
app.ICAOracleKeeper,
app.RatelimitKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
app.TransferKeeper,
)
stakeTiaModule := staketia.NewAppModule(appCodec, app.StaketiaKeeper)
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *AppTestHelper) Setup() {
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
}
s.TestAccs = CreateRandomAccounts(3)
s.TestAccs = CreateRandomAccounts(4)
s.IbcEnabled = false
s.IcaAddresses = make(map[string]string)

Expand Down
2 changes: 2 additions & 0 deletions proto/stride/stakeibc/host_zone.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ message HostZone {
// The max number of messages that can be sent in a delegation
// or undelegation ICA tx
uint64 max_messages_per_ica_tx = 36;
// Indicates whether redemptions are allowed through this module
bool redemptions_enabled = 37;
// An optional fee rebate
// If there is no rebate for the host zone, this will be nil
CommunityPoolRebate community_pool_rebate = 34;
Expand Down
41 changes: 3 additions & 38 deletions proto/stride/staketia/staketia.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,45 +35,8 @@ message HostZone {
string safe_address_on_stride = 11
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Previous redemption rate
string last_redemption_rate = 12 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Current redemption rate
string redemption_rate = 13 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Min outer redemption rate - adjusted by governance
string min_redemption_rate = 14 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Max outer redemption rate - adjusted by governance
string max_redemption_rate = 15 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Min inner redemption rate - adjusted by controller
string min_inner_redemption_rate = 16 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Max inner redemption rate - adjusted by controller
string max_inner_redemption_rate = 17 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Total delegated balance on the host zone delegation account
string delegated_balance = 18 [
string remaining_delegated_balance = 18 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
Expand All @@ -82,6 +45,8 @@ message HostZone {
uint64 unbonding_period_seconds = 19;
// Indicates whether the host zone has been halted
bool halted = 20;

reserved 13;
}

// Status fields for a delegation record
Expand Down
7 changes: 7 additions & 0 deletions proto/stride/staketia/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ service Msg {
returns (MsgSetOperatorAddressResponse);
}

// Deprecated: Liquid stakes should be handled in stakeibc
// LiquidStake
message MsgLiquidStake {
option (cosmos.msg.v1.signer) = "staker";
option (amino.name) = "staketia/MsgLiquidStake";
option deprecated = true;

string staker = 1;
string native_amount = 2 [
Expand All @@ -87,6 +89,8 @@ message MsgLiquidStake {
];
}
message MsgLiquidStakeResponse {
option deprecated = true;

cosmos.base.v1beta1.Coin st_token = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
Expand All @@ -103,6 +107,9 @@ message MsgRedeemStake {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// The receiver field is a celestia address
// It is only used in the case where the redemption spills over to stakeibc
string receiver = 3;
}
message MsgRedeemStakeResponse {
cosmos.base.v1beta1.Coin native_token = 1 [
Expand Down
13 changes: 7 additions & 6 deletions x/autopilot/keeper/redeem_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func (s *KeeperTestSuite) SetupAutopilotRedeemStake(featureEnabled bool, redeemA

// store the host zone
s.App.StakeibcKeeper.SetHostZone(s.Ctx, stakeibctypes.HostZone{
ChainId: HostChainId,
Bech32Prefix: HostBechPrefix, // required to validate claim receiver
HostDenom: HostDenom,
RedemptionRate: sdk.NewDec(1), // used to determine native token amount
DepositAddress: depositAddress.String(),
TotalDelegations: redeemAmount, // there must be enough stake to cover the redemption
ChainId: HostChainId,
Bech32Prefix: HostBechPrefix, // required to validate claim receiver
HostDenom: HostDenom,
RedemptionRate: sdk.NewDec(1), // used to determine native token amount
DepositAddress: depositAddress.String(),
TotalDelegations: redeemAmount, // there must be enough stake to cover the redemption
RedemptionsEnabled: true,
})

// fund the user with sttokens so they can redeem
Expand Down
1 change: 1 addition & 0 deletions x/stakeibc/keeper/community_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func (s *KeeperTestSuite) SetupRedeemCommunityPoolTokens() RedeemCommunityPoolTo
DepositAddress: depositAddress.String(),
TotalDelegations: initialStTokens, // at least as much as we are trying to redeem
RedemptionRate: sdk.OneDec(),
RedemptionsEnabled: true,
}
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone)

Expand Down
13 changes: 13 additions & 0 deletions x/stakeibc/keeper/host_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,16 @@ func (k Keeper) GetTargetValAmtsForHostZone(ctx sdk.Context, hostZone types.Host

return targetUnbondingsByValidator, nil
}

// Enables redemptions by setting the parameter on the host zone to true
// This is used during the staketia/stakedym migrations
func (k Keeper) EnableRedemptions(ctx sdk.Context, chainId string) error {
hostZone, found := k.GetHostZone(ctx, chainId)
if !found {
return types.ErrHostZoneNotFound.Wrapf(chainId)
}

hostZone.RedemptionsEnabled = true
k.SetHostZone(ctx, hostZone)
return nil
}
13 changes: 13 additions & 0 deletions x/stakeibc/keeper/host_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,16 @@ func (s *KeeperTestSuite) TestGetTargetValAmtsForHostZone() {
_, err = s.App.StakeibcKeeper.GetTargetValAmtsForHostZone(s.Ctx, types.HostZone{}, sdkmath.NewInt(1))
s.Require().ErrorContains(err, "No non-zero validators found for host zone")
}

func (s *KeeperTestSuite) TestEnableRedemptions() {
s.App.StakeibcKeeper.SetHostZone(s.Ctx, types.HostZone{
ChainId: HostChainId,
RedemptionsEnabled: false,
})

err := s.App.StakeibcKeeper.EnableRedemptions(s.Ctx, HostChainId)
s.Require().NoError(err)

hostZone := s.MustGetHostZone(HostChainId)
s.Require().True(hostZone.RedemptionsEnabled, "redemptions should have been enabled")
}
Loading

0 comments on commit 99d773f

Please sign in to comment.