Skip to content

Commit

Permalink
phase 2 nit comments (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Nov 27, 2023
1 parent f0f74a6 commit 6ce4a61
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 3,547 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/osmosis-labs/osmosis v1.0.4 // indirect
github.com/oxyno-zeta/gomock-extra-matcher v1.1.0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/zerolog v1.29.1 // indirect
golang.org/x/sync v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
Expand Down
2,967 changes: 0 additions & 2,967 deletions go.sum

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions proto/osmosis/gamm/v1beta1/osmosis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "cosmos/base/v1beta1/coin.proto";

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

// ===================== MsgSwapExactAmountIn
message MsgSwapExactAmountIn {
option (amino.name) = "osmosis/gamm/swap-exact-amount-in";

Expand Down Expand Up @@ -39,31 +38,3 @@ message SwapAmountInRoute {
string token_out_denom = 2
[ (gogoproto.moretags) = "yaml:\"token_out_denom\"" ];
}

// This is the query and response type on gamm/v1beta1, there is also a similar
// type on gamm/v2 This version is deprecated, the intended one is in
// x/poolmanager which is the newer rpc route The most up to date is an rpc
// route named SpotPriceV2 on poolmanager/v2 In poolmanager/v1beta1 and
// poolmanager/v2 all fields are the same as defined here... But the messages
// are called SpotPriceRequest/Response without Query in front

// QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice
// query.
message QuerySpotPriceRequest {
option deprecated = true;
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string base_asset_denom = 2
[ (gogoproto.moretags) = "yaml:\"base_asset_denom\"" ];
string quote_asset_denom = 3
[ (gogoproto.moretags) = "yaml:\"quote_asset_denom\"" ];
reserved 4;
reserved "withSwapFee";
}

// QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice
// query.
message QuerySpotPriceResponse {
option deprecated = true;
// String of the Dec. Ex) 10.203uatom
string spot_price = 1 [ (gogoproto.moretags) = "yaml:\"spot_price\"" ];
}
4 changes: 2 additions & 2 deletions proto/stride/stakeibc/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "gogoproto/gogo.proto";
option go_package = "github.com/Stride-Labs/stride/v16/x/stakeibc/types";

// Params defines the parameters for the module.
// next id: 21
// next id: 20
message Params {
option (gogoproto.goproto_stringer) = false;

Expand All @@ -28,4 +28,4 @@ message Params {
uint64 validator_slash_query_threshold = 19;

reserved 8, 17, 18;
}
}
39 changes: 18 additions & 21 deletions x/stakeibc/keeper/icqcallbacks_pool_spot_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/gogoproto/proto"

"github.com/Stride-Labs/stride/v16/utils"
icqtypes "github.com/Stride-Labs/stride/v16/x/interchainquery/types"
"github.com/Stride-Labs/stride/v16/x/stakeibc/types"
)

// TradeRewardBalanceCallback is a callback handler for TradeRewardBalance queries.
Expand All @@ -20,29 +16,30 @@ func PoolSpotPriceCallback(k Keeper, ctx sdk.Context, args []byte, query icqtype
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(query.ChainId, ICQCallbackID_PoolSpotPrice,
"Starting pool spot price callback, QueryId: %vs, QueryType: %s, Connection: %s", query.Id, query.QueryType, query.ConnectionId))

chainId := query.ChainId // should be the tradeZoneId, used in logging
// chainId := query.ChainId // should be the tradeZoneId, used in logging

// TODO: [DYDX] Fix in separate PR
// Unmarshal the query response args, should be a SpotPriceResponse type
var reponse types.QuerySpotPriceResponse
err := reponse.Unmarshal(args)
if err != nil {
return errorsmod.Wrap(err, "unable to unmarshal the query response")
}
// var reponse types.QuerySpotPriceResponse
// err := reponse.Unmarshal(args)
// if err != nil {
// return errorsmod.Wrap(err, "unable to unmarshal the query response")
// }

// response.SpotPrice should be a string representation of the denom ratios in pool like "10.203"

// Unmarshal the callback data containing the tradeRoute we are on
var tradeRoute types.TradeRoute
if err := proto.Unmarshal(query.CallbackData, &tradeRoute); err != nil {
return errorsmod.Wrapf(err, "unable to unmarshal trade reward balance callback data")
}
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_PoolSpotPrice,
"Query response - spot price ratio of %s to %s is %s",
tradeRoute.RewardDenomOnTradeZone, tradeRoute.TargetDenomOnTradeZone, reponse.SpotPrice))

// Update the spot price stored on the trade route data in the keeper
tradeRoute.SpotPrice = reponse.SpotPrice
k.SetTradeRoute(ctx, tradeRoute)
// var tradeRoute types.TradeRoute
// if err := proto.Unmarshal(query.CallbackData, &tradeRoute); err != nil {
// return errorsmod.Wrapf(err, "unable to unmarshal trade reward balance callback data")
// }
// k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_PoolSpotPrice,
// "Query response - spot price ratio of %s to %s is %s",
// tradeRoute.RewardDenomOnTradeZone, tradeRoute.TargetDenomOnTradeZone, reponse.SpotPrice))

// // Update the spot price stored on the trade route data in the keeper
// tradeRoute.SpotPrice = reponse.SpotPrice
// k.SetTradeRoute(ctx, tradeRoute)

return nil
}
11 changes: 9 additions & 2 deletions x/stakeibc/keeper/icqcallbacks_trade_converted_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ func TradeConvertedBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query
}

// Using ICA commands on the trade address, transfer the found converted tokens from the trade zone to the host zone
k.TransferConvertedTokensTradeToHost(ctx, tradeConvertedBalanceAmount, tradeRoute)
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalRewardBalance,
err = utils.ApplyFuncIfNoError(ctx, func(c sdk.Context) error {
return k.TransferConvertedTokensTradeToHost(ctx, tradeConvertedBalanceAmount, tradeRoute)
})
if err != nil {
k.Logger(ctx).Error(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_TradeConvertedBalance,
"Initiating transfer of converted tokens to back to host zone failed: %s", err.Error()))
}

k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_TradeConvertedBalance,
"Sending discovered converted tokens %v %s from tradeZone back to hostZone",
tradeConvertedBalanceAmount, tradeRoute.TargetDenomOnTradeZone))

Expand Down
13 changes: 10 additions & 3 deletions x/stakeibc/keeper/icqcallbacks_trade_reward_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
//
// Note: for now, to get proofs in your ICQs, you need to query the entire store on the host zone! e.g. "store/bank/key"
func TradeRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icqtypes.Query) error {
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(query.ChainId, ICQCallbackID_WithdrawalRewardBalance,
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(query.ChainId, ICQCallbackID_TradeRewardBalance,
"Starting withdrawal reward balance callback, QueryId: %vs, QueryType: %s, Connection: %s", query.Id, query.QueryType, query.ConnectionId))

chainId := query.ChainId // should be the tradeZoneId, used in logging
Expand All @@ -34,7 +34,7 @@ func TradeRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query ic
// Confirm the balance is greater than zero, or else exit without further action for now
if tradeRewardBalanceAmount.LTE(sdkmath.ZeroInt()) {
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_TradeRewardBalance,
"Not enough balance of reward tokens yet found in trade ICA! balance: %+v", tradeRewardBalanceAmount))
"Not enough reward tokens found in trade ICA, balance: %+v", tradeRewardBalanceAmount))
return nil
}

Expand All @@ -47,7 +47,14 @@ func TradeRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query ic
"Query response - Withdrawal Reward Balance: %v %s", tradeRewardBalanceAmount, tradeRoute.RewardDenomOnTradeZone))

// Trade all found reward tokens in the trade ICA to the output denom of their trade pool
k.TradeRewardTokens(ctx, tradeRewardBalanceAmount, tradeRoute)
err = utils.ApplyFuncIfNoError(ctx, func(c sdk.Context) error {
return k.TradeRewardTokens(ctx, tradeRewardBalanceAmount, tradeRoute)
})
if err != nil {
k.Logger(ctx).Error(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_TradeRewardBalance,
"Submitting ICA to swapping reward tokens failed: %s", err.Error()))
}

k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_TradeRewardBalance,
"Swapping discovered reward tokens %v %s for %s",
tradeRewardBalanceAmount, tradeRoute.RewardDenomOnTradeZone, tradeRoute.TargetDenomOnTradeZone))
Expand Down
11 changes: 9 additions & 2 deletions x/stakeibc/keeper/icqcallbacks_withdrawal_reward_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WithdrawalRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, que

// Confirm the balance is greater than zero, or else exit early without further action
if withdrawalRewardBalanceAmount.LTE(sdkmath.ZeroInt()) {
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalBalance,
k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalRewardBalance,
"Not enough reward tokens yet found in withdrawalICA, balance: %v", withdrawalRewardBalanceAmount))
return nil
}
Expand All @@ -47,7 +47,14 @@ func WithdrawalRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, que
"Query response - Withdrawal Reward Balance: %v %s", withdrawalRewardBalanceAmount, tradeRoute.RewardDenomOnHostZone))

// Using ICA commands on the withdrawal address, transfer the found reward tokens from the host zone to the trade zone
k.TransferRewardTokensHostToTrade(ctx, withdrawalRewardBalanceAmount, tradeRoute)
err = utils.ApplyFuncIfNoError(ctx, func(c sdk.Context) error {
return k.TransferRewardTokensHostToTrade(ctx, withdrawalRewardBalanceAmount, tradeRoute)
})
if err != nil {
k.Logger(ctx).Error(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalRewardBalance,
"Initiating transfer of reward tokens to trade ICA failed: %s", err.Error()))
}

k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalRewardBalance,
"Sending discovered reward tokens %v %s from hostZone to tradeZone",
withdrawalRewardBalanceAmount, tradeRoute.RewardDenomOnHostZone))
Expand Down
Loading

0 comments on commit 6ce4a61

Please sign in to comment.