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

phase 2: auto-trade reward token revenue via routes in params #955

Merged
merged 34 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6476e39
phase 2: auto-trade reward token revenue via routes in params
ethan-stride Oct 16, 2023
44c3f65
Adding new traderoute types and keepers (#980)
ethan-stride Nov 20, 2023
126fac2
Merge branch 'main' into autoswap-revenue-tokens
sampocs Nov 21, 2023
f0f74a6
phase 2 - trade route query (#988)
sampocs Nov 27, 2023
6ce4a61
phase 2 nit comments (#986)
sampocs Nov 27, 2023
2dee6d7
phase 2 - implement create trade route (#989)
sampocs Nov 27, 2023
18733e3
phase 2 - price ICQ to Osmosis twap store (#987)
sampocs Nov 28, 2023
d4f4fa6
min_swap_amount also gates reward token transfers (#991)
ethan-stride Nov 28, 2023
b32af28
phase 2 - misc proto renaming (#992)
sampocs Nov 28, 2023
3e0917a
phase 2 - added trade config (#995)
sampocs Nov 29, 2023
ba177b9
phase 2 - set ICA addresses in callback (#994)
sampocs Nov 29, 2023
bf9655c
phase 2 - integration tests (#997)
sampocs Nov 29, 2023
a28fb9d
reward converter - fixed pfm bug (#998)
sampocs Nov 30, 2023
74cd8a2
reward converter - remove cache context wrapper and add trade route c…
sampocs Nov 30, 2023
3abaee6
reward converter - generalized scripts for integration test host zone…
sampocs Nov 30, 2023
74c2d15
reward converter - validate basic unit tests (#1002)
sampocs Dec 4, 2023
4fac08f
reward converter - OnChanOpenAck unit tests (#1004)
sampocs Dec 4, 2023
fe21ad3
reward collector - ICA message unit tests (#1005)
sampocs Dec 4, 2023
919be7d
fixed issue with merge
sampocs Dec 4, 2023
5c9250e
reward converter - added ICA address validation (#1008)
sampocs Dec 6, 2023
981bfa3
reward converter - add trade route ID to portId (#1011)
sampocs Dec 7, 2023
4d98b92
reward converter - fix timeouts (#1019)
sampocs Dec 7, 2023
913b4d7
fixed merge errors
sampocs Dec 7, 2023
6704631
reward converter - Create/Update/Delete TradeRoute unit tests (#1015)
sampocs Dec 8, 2023
9fabe9b
reward converter - pool price query unit test (#1016)
sampocs Dec 8, 2023
5cd9b9f
reward converter - unit tests on query submissions and icqcallbacks (…
sampocs Dec 8, 2023
407a510
Merge branch 'main' into autoswap-revenue-tokens
sampocs Dec 8, 2023
01eb42a
nit changes after final skim
sampocs Dec 8, 2023
40a181a
Merge branch 'autoswap-revenue-tokens' of github.com:Stride-Labs/stri…
sampocs Dec 8, 2023
1e4d060
fixed merge conflict
sampocs Dec 8, 2023
c4298c8
added guardclause to prevent transfer if pool price not set
sampocs Dec 8, 2023
7ea1544
reward converter - restore trade route ICA (#1023)
sampocs Dec 9, 2023
c75e093
nit change to create_logs
sampocs Dec 9, 2023
57c0ea1
made IG tests dynamic
sampocs Dec 9, 2023
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ 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: 2,967 additions & 0 deletions go.sum

Large diffs are not rendered by default.

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/v16/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\"" ];
}
9 changes: 9 additions & 0 deletions proto/stride/stakeibc/ica_account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ enum ICAAccountType {
REDEMPTION = 3;
COMMUNITY_POOL_DEPOSIT = 4;
COMMUNITY_POOL_RETURN = 5;
UNWIND = 6;
TRADE = 7;
}

message ICAAccount {
string chain_id = 1;
ICAAccountType type = 2;
string connection_id = 3;
string address = 4;
}
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: 20
// next id: 21
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;
}
}
54 changes: 54 additions & 0 deletions proto/stride/stakeibc/trade_route.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";
package stride.stakeibc;

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

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

// 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 ];
}

// 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;

// 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
];
}
67 changes: 66 additions & 1 deletion proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ service Msg {
rpc UpdateInnerRedemptionRateBounds(MsgUpdateInnerRedemptionRateBounds)
returns (MsgUpdateInnerRedemptionRateBoundsResponse);
rpc ResumeHostZone(MsgResumeHostZone) returns (MsgResumeHostZoneResponse);
rpc CreateTradeRoute(MsgCreateTradeRoute)
returns (MsgCreateTradeRouteResponse);
rpc DeleteTradeRoute(MsgDeleteTradeRoute)
returns (MsgDeleteTradeRouteResponse);
rpc UpdateTradeRoute(MsgUpdateTradeRoute)
returns (MsgUpdateTradeRouteResponse);
}

message MsgUpdateInnerRedemptionRateBounds {
Expand Down Expand Up @@ -180,6 +186,7 @@ message MsgUpdateValidatorSharesExchRate {
string valoper = 3;
}
message MsgUpdateValidatorSharesExchRateResponse {}

message MsgUndelegateHost {
string creator = 1;
string amount = 2 [
Expand All @@ -200,4 +207,62 @@ message MsgResumeHostZone {
string creator = 1;
string chain_id = 2;
}
message MsgResumeHostZoneResponse {}
message MsgResumeHostZoneResponse {}

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 @@ -40,6 +40,9 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdUndelegateHost())
cmd.AddCommand(CmdUpdateInnerRedemptionRateBounds())
cmd.AddCommand(CmdResumeHostZone())
cmd.AddCommand(CmdCreateTradeRoute())
cmd.AddCommand(CmdDeleteTradeRoute())
cmd.AddCommand(CmdUpdateTradeRoute())

return cmd
}
Loading