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

v25 - stTIA Migration #1271

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
10a1abd
Batched delegations (#1201)
sampocs Jun 13, 2024
74c51cb
batched undelegations (#1195)
sampocs Jun 13, 2024
99d773f
staketia migration (#1212)
sampocs Jun 13, 2024
a5b31a6
fixed unit tests
sampocs Jun 13, 2024
1582770
V23 upgrade handler (batching and stTIA) (#1219)
sampocs Jun 13, 2024
95f12fd
added TODO
sampocs Jun 14, 2024
cd8d976
[AUDIT FIX] - short circuit callback on completed records
sampocs Jun 14, 2024
def6f4a
[AUDIT FIX] - decrement remaining delegated balance in redeem stake
sampocs Jun 20, 2024
f1fe92c
[AUDIT FIX] - set min/max inner redemption rate after migration
sampocs Jun 20, 2024
df38a31
[AUDIT FIX] - updated total delegations in confirm delegation
sampocs Jun 20, 2024
c3ffbf6
Merge branch 'main' into v23
sampocs Jun 20, 2024
25ed61b
[AUDIT FIX] migrate halted field, remove prepare delegation, clarifyi…
sampocs Jun 29, 2024
66041f3
[AUDIT FIX] decrement total delegations in adjust delegated balance
sampocs Jul 9, 2024
82a007b
[AUDIT FIX] enable stakeibc redemptions with if exact remaining amoun…
sampocs Jul 9, 2024
7e4a9a9
[AUDIT FIX] set delegation/undelegationTxsInProgress in migration
sampocs Jul 10, 2024
07d8a83
reset delegation txs in progress to 0 in restore-ica
sampocs Jul 18, 2024
639777d
addressed riley and vishal pr comments
sampocs Jul 26, 2024
38555eb
updated package from v22 -> v23
sampocs Jul 26, 2024
81f7cc9
generated protos
sampocs Jul 26, 2024
68deb54
moved upgrade to v24
sampocs Jul 26, 2024
8fdf6c6
removed trade route migration from v24 upgrade
sampocs Jul 26, 2024
d35a8e8
Merge branch 'main' into v23
sampocs Jul 26, 2024
72b9b41
fixed unit tests
sampocs Jul 26, 2024
13288dd
copied over the redemption rate update functions into staketia migration
sampocs Jul 26, 2024
ec24683
fixed build errors and updated RR functions
sampocs Jul 26, 2024
046f992
added invariant from RR change
sampocs Jul 26, 2024
5c79959
removed debug logs
sampocs Jul 26, 2024
07f1411
fixed unit test
sampocs Jul 26, 2024
c9b390d
nit
sampocs Jul 26, 2024
059843d
moved up RR invariant check and removed balance check
sampocs Aug 6, 2024
a57552d
nit, used GetActiveHostZone and moved epoch tracker
sampocs Aug 6, 2024
f5574b1
fixed unit tests
sampocs Aug 6, 2024
19e3617
nit: fixed comment typo in icacallbacks_undelegate.go
sampocs Aug 7, 2024
b58fea0
Merge branch 'main' into v23
assafmo Aug 8, 2024
afa4bfb
Merge branch 'main' into v23
sampocs Aug 16, 2024
40c03e7
Merge branch 'main' into v25
sampocs Aug 27, 2024
4b0ade8
bumped version to v24
sampocs Sep 5, 2024
e9031c3
Merge branch 'main' into v25
sampocs Sep 5, 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
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ func NewStrideApp(
app.BankKeeper,
app.ICAOracleKeeper,
app.RatelimitKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
app.TransferKeeper,
)
stakeTiaModule := staketia.NewAppModule(appCodec, app.StaketiaKeeper)
Expand Down
14 changes: 14 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
v22 "github.com/Stride-Labs/stride/v24/app/upgrades/v22"
v23 "github.com/Stride-Labs/stride/v24/app/upgrades/v23"
v24 "github.com/Stride-Labs/stride/v24/app/upgrades/v24"
v25 "github.com/Stride-Labs/stride/v24/app/upgrades/v25"
v3 "github.com/Stride-Labs/stride/v24/app/upgrades/v3"
v4 "github.com/Stride-Labs/stride/v24/app/upgrades/v4"
v5 "github.com/Stride-Labs/stride/v24/app/upgrades/v5"
Expand Down Expand Up @@ -324,6 +325,19 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
),
)

// v25 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v25.UpgradeName,
v25.CreateUpgradeHandler(
app.mm,
app.configurator,
app.BankKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
app.StaketiaKeeper,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
OsmosisRedemptionRateBuffer = sdk.MustNewDecFromStr("0.02")
)

// CreateUpgradeHandler creates an SDK upgrade handler for v23
// CreateUpgradeHandler creates an SDK upgrade handler for v24
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down
37 changes: 37 additions & 0 deletions app/upgrades/v25/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v25

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

recordskeeper "github.com/Stride-Labs/stride/v24/x/records/keeper"
stakeibckeeper "github.com/Stride-Labs/stride/v24/x/stakeibc/keeper"
staketiakeeper "github.com/Stride-Labs/stride/v24/x/staketia/keeper"
)

const UpgradeName = "v25"

// CreateUpgradeHandler creates an SDK upgrade handler for v25
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bankKeeper bankkeeper.Keeper,
recordsKeeper recordskeeper.Keeper,
stakeibcKeeper stakeibckeeper.Keeper,
staketiaKeeper staketiakeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v25...")

// Migrate staketia to stakeibc
if err := staketiakeeper.InitiateMigration(ctx, staketiaKeeper, bankKeeper, recordsKeeper, stakeibcKeeper); err != nil {
return vm, errorsmod.Wrapf(err, "unable to migrate staketia to stakeibc")
}

ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}
25 changes: 25 additions & 0 deletions app/upgrades/v25/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v25_test

import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v24/app/apptesting"
)

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) TestUpgrade() {

}
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
8 changes: 4 additions & 4 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ update_version ./scripts/protocgen.sh

echo ">>> Committing changes..."

git add .
git commit -m "updated package from $OLD_VERSION -> $NEW_VERSION"
# git add .
# git commit -m "updated package from $OLD_VERSION -> $NEW_VERSION"

# Re-generate protos
echo ">>> Rebuilding protos..."

make proto-all

git add .
git commit -m 'generated protos'
# git add .
# git commit -m 'generated protos'

echo "Done"
49 changes: 4 additions & 45 deletions x/staketia/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(
CmdLiquidStake(),
CmdRedeemStake(),
CmdConfirmDelegation(),
CmdConfirmUndelegation(),
Expand All @@ -52,52 +51,10 @@ func GetTxCmd() *cobra.Command {
return cmd
}

// User transaction to liquid stake native tokens into stTokens
func CmdLiquidStake() *cobra.Command {
cmd := &cobra.Command{
Use: "liquid-stake [amount]",
Short: "Liquid stakes native tokens and receives stTokens",
Long: strings.TrimSpace(
fmt.Sprintf(`Liquid stakes native tokens and receives stTokens

Example:
$ %[1]s tx %[2]s liquid-stake 10000
`, version.AppName, types.ModuleName),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
amount, ok := sdkmath.NewIntFromString(args[0])
if !ok {
return errors.New("unable to parse amount")
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgLiquidStake(
clientCtx.GetFromAddress().String(),
amount,
)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// User transaction to redeem stake stTokens into native tokens
func CmdRedeemStake() *cobra.Command {
cmd := &cobra.Command{
Use: "redeem-stake [amount]",
Use: "redeem-stake [amount] [reciever]",
Short: "Redeems stTokens tokens for native tokens",
Long: strings.TrimSpace(
fmt.Sprintf(`Redeems stTokens tokens for native tokens.
Expand All @@ -107,12 +64,13 @@ Example:
$ %[1]s tx %[2]s redeem-stake 10000
`, version.AppName, types.ModuleName),
),
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
amount, ok := sdkmath.NewIntFromString(args[0])
if !ok {
return errors.New("unable to parse amount")
}
receiver := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -122,6 +80,7 @@ Example:
msg := types.NewMsgRedeemStake(
clientCtx.GetFromAddress().String(),
amount,
receiver,
)

if err := msg.ValidateBasic(); err != nil {
Expand Down
11 changes: 1 addition & 10 deletions x/staketia/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,4 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k Keeper) BeginBlocker(ctx sdk.Context) {
// Check invariants

// Check redemption rate is within safety bounds
if err := k.CheckRedemptionRateExceedsBounds(ctx); err != nil {
k.Logger(ctx).Error(err.Error())
// If not, halt the zone
k.HaltZone(ctx)
}
}
func (k Keeper) BeginBlocker(ctx sdk.Context) {}
Loading
Loading