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

min_swap_amount also gates reward token transfers #991

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions proto/stride/stakeibc/trade_route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ message TradeRoute {
string spot_price = 10;

// min and max set boundaries of reward denom on trade chain we will swap
// min also decides when reward token transfers are worth it (transfer fees)
string min_swap_amount = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
Expand Down
14 changes: 11 additions & 3 deletions x/stakeibc/keeper/reward_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

errorsmod "cosmossdk.io/errors"
math "cosmossdk.io/math"
ethan-stride marked this conversation as resolved.
Show resolved Hide resolved
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -41,7 +42,14 @@ import (
// This will be two hops to unwind the ibc denom through the rewardZone using pfm in the transfer memo if possible
//
// msgs with packet forwarding memos can unwind through the reward zone and chain two transfer hops without callbacks
func (k Keeper) TransferRewardTokensHostToTrade(ctx sdk.Context, amount sdk.Int, route types.TradeRoute) error {
func (k Keeper) TransferRewardTokensHostToTrade(ctx sdk.Context, amount math.Int, route types.TradeRoute) error {
// If the min swap amount was not set it would be ZeroInt, if positive we need to compare to the amount given
// then if the min swap amount is greater than the current amount, do nothing this epoch to avoid small transfers
// Particularly important for the PFM hop if the reward chain has frictional transfer fees (like noble chain)
if route.MinSwapAmount.IsPositive() && route.MinSwapAmount.GT(amount) {
return nil
}

// Timeout for ica tx and the transfer msgs is at end of epoch
strideEpochTracker, found := k.GetEpochTracker(ctx, epochstypes.STRIDE_EPOCH)
if !found {
Expand Down Expand Up @@ -90,7 +98,7 @@ func (k Keeper) TransferRewardTokensHostToTrade(ctx sdk.Context, amount sdk.Int,
}

// ICA tx to kick off transfering the converted tokens back from tradeZone to the hostZone withdrawal ICA
func (k Keeper) TransferConvertedTokensTradeToHost(ctx sdk.Context, amount sdk.Int, route types.TradeRoute) error {
func (k Keeper) TransferConvertedTokensTradeToHost(ctx sdk.Context, amount math.Int, route types.TradeRoute) error {
// Timeout for ica tx and the transfer msgs is at end of epoch
strideEpochTracker, found := k.GetEpochTracker(ctx, epochstypes.STRIDE_EPOCH)
if !found {
Expand Down Expand Up @@ -133,7 +141,7 @@ func (k Keeper) TransferConvertedTokensTradeToHost(ctx sdk.Context, amount sdk.I
// Trade reward tokens in the Trade ICA for the target output token type using ICA remote tx on trade zone
// The amount represents the total amount of the reward token in the trade ICA found by the calling ICQ
// Depending on min and max swap amounts set in the route, it is possible not the full amount given will swap
func (k Keeper) TradeRewardTokens(ctx sdk.Context, amount sdk.Int, route types.TradeRoute) error {
func (k Keeper) TradeRewardTokens(ctx sdk.Context, amount math.Int, route types.TradeRoute) error {
// If the min swap amount was not set it would be ZeroInt, if positive we need to compare to the amount given
// then if the min swap amount is greater than the current amount, do nothing this epoch to avoid small swaps
if route.MinSwapAmount.IsPositive() && route.MinSwapAmount.GT(amount) {
Expand Down
1 change: 1 addition & 0 deletions x/stakeibc/types/trade_route.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.