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

removed trade route dead code #1189

Merged
merged 14 commits into from
May 14, 2024
11 changes: 11 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
v20 "github.com/Stride-Labs/stride/v22/app/upgrades/v20"
v21 "github.com/Stride-Labs/stride/v22/app/upgrades/v21"
v22 "github.com/Stride-Labs/stride/v22/app/upgrades/v22"
v23 "github.com/Stride-Labs/stride/v22/app/upgrades/v23"
v3 "github.com/Stride-Labs/stride/v22/app/upgrades/v3"
v4 "github.com/Stride-Labs/stride/v22/app/upgrades/v4"
v5 "github.com/Stride-Labs/stride/v22/app/upgrades/v5"
Expand Down Expand Up @@ -296,6 +297,16 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
),
)

// v23 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v23.UpgradeName,
v23.CreateUpgradeHandler(
app.mm,
app.configurator,
app.StakeibcKeeper,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand Down
39 changes: 39 additions & 0 deletions app/upgrades/v23/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v23

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

stakeibckeeper "github.com/Stride-Labs/stride/v22/x/stakeibc/keeper"
)

var (
UpgradeName = "v23"
)

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

ctx.Logger().Info("Migrating trade routes...")
MigrateTradeRoutes(ctx, stakeibcKeeper)

ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}

// Migration to deprecate the trade config
// The min transfer amount can be set from the min swap amount
func MigrateTradeRoutes(ctx sdk.Context, k stakeibckeeper.Keeper) {
for _, tradeRoute := range k.GetAllTradeRoutes(ctx) {
tradeRoute.MinTransferAmount = tradeRoute.TradeConfig.MinSwapAmount
k.SetTradeRoute(ctx, tradeRoute)
}
}
48 changes: 48 additions & 0 deletions app/upgrades/v23/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v23_test

import (
"testing"

"github.com/stretchr/testify/suite"

sdkmath "cosmossdk.io/math"

"github.com/Stride-Labs/stride/v22/app/apptesting"
stakeibctypes "github.com/Stride-Labs/stride/v22/x/stakeibc/types"
)

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() {
dummyUpgradeHeight := int64(5)
minTransferAmount := sdkmath.NewInt(100)

// Create a trade route with the deprecated trade config
tradeRoutes := stakeibctypes.TradeRoute{
HostDenomOnHostZone: "host-denom",
RewardDenomOnRewardZone: "reward-denom",

TradeConfig: stakeibctypes.TradeConfig{

Check failure on line 35 in app/upgrades/v23/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: stakeibctypes.TradeConfig is deprecated: Do not use. (staticcheck)
MinSwapAmount: minTransferAmount,
},
}
s.App.StakeibcKeeper.SetTradeRoute(s.Ctx, tradeRoutes)

// Run the upgrade
s.ConfirmUpgradeSucceededs("v23", dummyUpgradeHeight)

// Confirm trade route was migrated
for _, tradeRoute := range s.App.StakeibcKeeper.GetAllTradeRoutes(s.Ctx) {
s.Require().Equal(tradeRoute.MinTransferAmount, minTransferAmount)
}
}
18 changes: 17 additions & 1 deletion proto/stride/stakeibc/trade_route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import "cosmos_proto/cosmos.proto";

option go_package = "github.com/Stride-Labs/stride/v22/x/stakeibc/types";

// Deprecated, this configuration is no longer needed since swaps
// are executed off-chain via authz
//
// Stores pool information needed to execute the swap along a trade route
message TradeConfig {
option deprecated = true;

// Currently Osmosis is the only trade chain so this is an osmosis pool id
uint64 pool_id = 1;

Expand Down Expand Up @@ -84,7 +89,18 @@ message TradeRoute {
// zone, back to the host zone. This is the channel ID on the trade zone side
string trade_to_host_channel_id = 11;

// Minimum amount of reward token that must be accumulated before
// the tokens are transferred to the trade ICA
string min_transfer_amount = 13 [
ethan-stride marked this conversation as resolved.
Show resolved Hide resolved
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// Deprecated, the trades are now executed off-chain via authz
// so the trade configuration is no longer needed
//
// specifies the configuration needed to execute the swap
// such as pool_id, slippage, min trade amount, etc.
TradeConfig trade_config = 12 [ (gogoproto.nullable) = false ];
TradeConfig trade_config = 12
[ deprecated = true, (gogoproto.nullable) = false ];
}
40 changes: 36 additions & 4 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -245,27 +245,42 @@ message MsgCreateTradeRoute {
// the host zone's native denom (e.g. dydx on dYdX)
string host_denom_on_host = 12;

// Deprecated, the trades are now executed off-chain via authz
//
// The osmosis pool ID
uint64 pool_id = 13;
uint64 pool_id = 13 [ deprecated = true ];

// Deprecated, the trades are now executed off-chain via authz
//
// Threshold defining the percentage of tokens that could be lost in the trade
// This captures both the loss from slippage and from a stale price on stride
// "0.05" means the output from the trade can be no less than a 5% deviation
// from the current value
string max_allowed_swap_loss_rate = 14;
string max_allowed_swap_loss_rate = 14 [ deprecated = true ];

// Deprecated, the trades are now executed off-chain via authz
//
// minimum amount of reward tokens to initate a swap
// if not provided, defaults to 0
string min_swap_amount = 15 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// Deprecated, the trades are now executed off-chain via authz
//
// maximum amount of reward tokens in a single swap
// if not provided, defaults to 10e24
string max_swap_amount = 16 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// Minimum amount of reward token that must be accumulated before
// the tokens are transferred to the trade ICA
string min_transfer_amount = 17 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
message MsgCreateTradeRouteResponse {}

Expand Down Expand Up @@ -299,24 +314,41 @@ message MsgUpdateTradeRoute {
// The host zone's denom in it's native form (e.g. dydx)
string host_denom = 3;

// Deprecated, the trades are now executed off-chain via authz
//
// The osmosis pool ID
uint64 pool_id = 4;
uint64 pool_id = 4 [ deprecated = true ];

// Deprecated, the trades are now executed off-chain via authz
//
// Threshold defining the percentage of tokens that could be lost in the trade
// This captures both the loss from slippage and from a stale price on stride
// "0.05" means the output from the trade can be no less than a 5% deviation
// from the current value
string max_allowed_swap_loss_rate = 5;
string max_allowed_swap_loss_rate = 5 [ deprecated = true ];

// Deprecated, the trades are now executed off-chain via authz
//
// minimum amount of reward tokens to initate a swap
// if not provided, defaults to 0
string min_swap_amount = 6 [
deprecated = true,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// Deprecated, the trades are now executed off-chain via authz
//
// maximum amount of reward tokens in a single swap
// if not provided, defaults to 10e24
string max_swap_amount = 7 [
deprecated = true,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// Minimum amount of reward token that must be accumulated before
// the tokens are transferred to the trade ICA
string min_transfer_amount = 17 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
Expand Down
6 changes: 1 addition & 5 deletions x/stakeibc/keeper/icqcallbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const (
ICQCallbackID_Calibrate = "calibrate"
ICQCallbackID_CommunityPoolIcaBalance = "communitypoolicabalance"
ICQCallbackID_WithdrawalRewardBalance = "withdrawalrewardbalance"
ICQCallbackID_TradeRewardBalance = "traderewardbalance"
ICQCallbackID_TradeConvertedBalance = "tradeconvertedbalance"
ICQCallbackID_PoolPrice = "poolprice"
)

// ICQCallbacks wrapper struct for stakeibc keeper
Expand Down Expand Up @@ -56,7 +54,5 @@ func (c ICQCallbacks) RegisterICQCallbacks() icqtypes.QueryCallbacks {
AddICQCallback(ICQCallbackID_Calibrate, ICQCallback(CalibrateDelegationCallback)).
AddICQCallback(ICQCallbackID_CommunityPoolIcaBalance, ICQCallback(CommunityPoolIcaBalanceCallback)).
AddICQCallback(ICQCallbackID_WithdrawalRewardBalance, ICQCallback(WithdrawalRewardBalanceCallback)).
AddICQCallback(ICQCallbackID_TradeRewardBalance, ICQCallback(TradeRewardBalanceCallback)).
AddICQCallback(ICQCallbackID_TradeConvertedBalance, ICQCallback(TradeConvertedBalanceCallback)).
AddICQCallback(ICQCallbackID_PoolPrice, ICQCallback(PoolPriceCallback))
AddICQCallback(ICQCallbackID_TradeConvertedBalance, ICQCallback(TradeConvertedBalanceCallback))
}
97 changes: 0 additions & 97 deletions x/stakeibc/keeper/icqcallbacks_pool_price.go

This file was deleted.

Loading
Loading