Skip to content

Commit

Permalink
Adding new traderoute types and keepers (#980)
Browse files Browse the repository at this point in the history
Co-authored-by: sampocs <sam@stridelabs.co>
Co-authored-by: sampocs <sam.pochyly@gmail.com>
  • Loading branch information
3 people authored Nov 20, 2023
1 parent 6476e39 commit 44c3f65
Show file tree
Hide file tree
Showing 38 changed files with 7,871 additions and 3,909 deletions.
69 changes: 69 additions & 0 deletions proto/osmosis/gamm/v1beta1/osmosis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
syntax = "proto3";
package osmosis.gamm.v1beta1;

import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";

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

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

string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
repeated SwapAmountInRoute routes = 2 [ (gogoproto.nullable) = false ];
cosmos.base.v1beta1.Coin token_in = 3 [
(gogoproto.moretags) = "yaml:\"token_in\"",
(gogoproto.nullable) = false
];
string token_out_min_amount = 4 [

(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.moretags) = "yaml:\"token_out_min_amount\"",
(gogoproto.nullable) = false
];
}

message MsgSwapExactAmountInResponse {
string token_out_amount = 1 [

(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.moretags) = "yaml:\"token_out_amount\"",
(gogoproto.nullable) = false
];
}

message SwapAmountInRoute {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
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\"" ];
}
17 changes: 0 additions & 17 deletions proto/stride/stakeibc/callbacks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,3 @@ message DelegatorSharesQueryCallback {
(gogoproto.nullable) = false
];
}

message WithdrawalRewardBalanceQueryCallback {
string reward_denom_on_host_zone = 1;
string host_zone_id = 2;
}

message TradeRewardBalanceQueryCallback {
string reward_denom_on_trade_zone = 1;
string host_zone_id = 2;
string trade_zone_id = 3;
}

message TradeConvertedBalanceQueryCallback {
string converted_denom_on_trade_zone = 1;
string host_zone_id = 2;
string trade_zone_id = 3;
}
2 changes: 1 addition & 1 deletion proto/stride/stakeibc/host_zone.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message HostZone {
string redemption_ica_address = 25
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string reward_trade_ica_address = 32
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string total_delegations = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
Expand Down
10 changes: 9 additions & 1 deletion proto/stride/stakeibc/ica_account.proto
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ enum ICAAccountType {
FEE = 1;
WITHDRAWAL = 2;
REDEMPTION = 3;
TRADE = 6;
UNWIND = 6;
TRADE = 7;
}

message ICAAccount {
string chain_id = 1;
ICAAccountType type = 2;
string connection_id = 3;
string address = 4;
}
2 changes: 0 additions & 2 deletions proto/stride/stakeibc/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ syntax = "proto3";
package stride.stakeibc;

import "gogoproto/gogo.proto";
import "stride/stakeibc/trade_route.proto";

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

Expand All @@ -27,7 +26,6 @@ message Params {
uint64 default_max_redemption_rate_threshold = 15;
uint64 ibc_transfer_timeout_nanos = 16;
uint64 validator_slash_query_threshold = 19;
TradeRoutes trade_routes = 20;

reserved 8, 17, 18;
}
74 changes: 43 additions & 31 deletions proto/stride/stakeibc/trade_route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,53 @@ syntax = "proto3";
package stride.stakeibc;

import "gogoproto/gogo.proto";
import "stride/stakeibc/ica_account.proto";

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

// TradeRoutes defines all info needed for token transfers and trade operations
message TradeRoutes {
repeated TransferRoute transfer_routes = 1 [ (gogoproto.nullable) = false ];
repeated TradePool trade_pools = 3 [ (gogoproto.nullable) = false ];
// Represents a single directional hop from one ICA to another ICA
// transfer_channel is between the first chain and second
// No need for the transfer port because that is a fixed variable
message TradeHop {
string transfer_channel_id = 1;
ICAAccount from_account = 2 [ (gogoproto.nullable) = false ];
ICAAccount to_account = 3 [ (gogoproto.nullable) = false ];
}

// TransferRoute has the connection info needed to do either a direct or two-hop unwinding ibc transfer
// For direct routes:
// middle_denom, middle_chain_id, finish_transfer_port/channel, and passthrough_ica_address should be empty
// For unwinding routes,
// the middle denom ought to be the host denom for the middle chain
// if the middle chain has the newest pfm installed, the passthrough_ica_address can be "pfm"
// if the middle chain has pfm installed but is older, a legal address will be needed on the middle chain
// if the middle chain doesn't have pfm installed at all, two separate ibc transfers will be needed
message TransferRoute {
string start_denom = 1;
string middle_denom = 2;
string finish_denom = 3;
string start_chain_id = 4;
string middle_chain_id = 5;
string finish_chain_id = 6;
string start_transfer_port = 7;
string start_transfer_channel = 8;
string finish_transfer_port = 9;
string finish_transfer_channel = 10;
string passthrough_ica_address = 11;
}
// TradeRoute represents a round trip including info on transfer and how to do
// the swap. It makes the assumption that the reward token is always foreign to
// the host so therefore the first two hops are to unwind the ibc denom enroute
// to the trade chain and the last hop is the return so funds start/end in the
// withdrawl ICA on hostZone
message TradeRoute {
// ibc denom for the reward on the host zone
string reward_denom_on_host_zone = 1;
// should be the native denom for the reward chain
string reward_denom_on_reward_zone = 2;
// ibc denom of the reward on the trade chain, input to the swap
string reward_denom_on_trade_zone = 3;
// ibc of the host denom on the trade chain, output from the swap
string target_denom_on_trade_zone = 4;
// should be the same as the native host denom on the host chain
string target_denom_on_host_zone = 5;

TradeHop host_to_reward_hop = 6 [ (gogoproto.nullable) = false ];
TradeHop reward_to_trade_hop = 7 [ (gogoproto.nullable) = false ];
TradeHop trade_to_host_hop = 8 [ (gogoproto.nullable) = false ];

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

// Spot price is a decimal ratio of the input to output denom as a string
string spot_price = 10;

// TradePool defines which pool on the tradeZone to use when making a swap
message TradePool {
string host_chain_id = 1;
string input_denom = 2;
string output_denom = 3;
uint64 pool_id = 4;
// min and max set boundaries of reward denom on trade chain we will swap
string min_swap_amount = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string max_swap_amount = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
64 changes: 64 additions & 0 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ service Msg {
rpc UpdateValidatorSharesExchRate(MsgUpdateValidatorSharesExchRate)
returns (MsgUpdateValidatorSharesExchRateResponse);
rpc ClearBalance(MsgClearBalance) returns (MsgClearBalanceResponse);
rpc CreateTradeRoute(MsgCreateTradeRoute)
returns (MsgCreateTradeRouteResponse);
rpc DeleteTradeRoute(MsgDeleteTradeRoute)
returns (MsgDeleteTradeRouteResponse);
rpc UpdateTradeRoute(MsgUpdateTradeRoute)
returns (MsgUpdateTradeRouteResponse);
}

message MsgLiquidStake {
Expand Down Expand Up @@ -151,3 +157,61 @@ message MsgUpdateValidatorSharesExchRate {
string valoper = 3;
}
message MsgUpdateValidatorSharesExchRateResponse {}

message MsgCreateTradeRoute {
string creator = 1;
string host_chain_id = 2;
string host_connection_id = 3;
string host_ica_address = 4;
string reward_chain_id = 5;
string reward_connection_id = 6;
string reward_ica_address = 7;
string trade_chain_id = 8;
string trade_connection_id = 9;
string trade_ica_address = 10;
string host_reward_transfer_channel_id = 11;
string reward_trade_transfer_channel_id = 12;
string trade_host_transfer_channel_id = 13;
string reward_denom_on_host = 14;
string reward_denom_on_reward = 15;
string reward_denom_on_trade = 16;
string target_denom_on_trade = 17;
string target_denom_on_host = 18;
uint64 pool_id = 19;
string min_swap_amount = 20 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string max_swap_amount = 21 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
message MsgCreateTradeRouteResponse {}

message MsgDeleteTradeRoute {
string creator = 1;
string host_denom = 2;
string reward_denom = 3;
}
message MsgDeleteTradeRouteResponse {}

message MsgUpdateTradeRoute {
string creator = 1;
string host_denom = 2;
string reward_denom = 3;
uint64 pool_id = 4;
string min_swap_amount = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string max_swap_amount = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
message MsgUpdateTradeRouteResponse {}
1 change: 1 addition & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cd proto
generate_protos "./stride"
generate_protos "./cosmos"
generate_protos "./cosmwasm"
generate_protos "./osmosis"

cd ..

Expand Down
3 changes: 3 additions & 0 deletions x/stakeibc/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdRestoreInterchainAccount())
cmd.AddCommand(CmdUpdateValidatorSharesExchRate())
cmd.AddCommand(CmdClearBalance())
cmd.AddCommand(CmdCreateTradeRoute())
cmd.AddCommand(CmdDeleteTradeRoute())
cmd.AddCommand(CmdUpdateTradeRoute())

return cmd
}
Loading

0 comments on commit 44c3f65

Please sign in to comment.