Skip to content

Commit

Permalink
feat: Puneet/update ratesync (#755)
Browse files Browse the repository at this point in the history
* add transfer channel-id and port to host-chain.

* add transfer channel-id and port to host-chain.

* add CHANGELOG.md

* add validation for channel, port.

* have portID and not port

* have portID and not port

* fix tests

* more tests
  • Loading branch information
puneet2019 authored Feb 1, 2024
1 parent cdae4fa commit c02835a
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 203 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## Unreleased

### Features

- [755](https://github.com/persistenceOne/pstake-native/pull/755) Add channel-id, port to ratesync host-chains and liquidstake instantiate.
- [737](https://github.com/persistenceOne/pstake-native/pull/737) Unhandled errors.
- [736](https://github.com/persistenceOne/pstake-native/pull/736) Check for host denom duplicates.
- [733](https://github.com/persistenceOne/pstake-native/pull/733) Add more validation for host-chain.
Expand Down
17 changes: 12 additions & 5 deletions proto/pstake/ratesync/v1beta1/contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types

// msg blob for instantiate contract.
message InstantiateLiquidStakeRateContract {
string admin = 1[(cosmos_proto.scalar) = "cosmos.AddressString"];
string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string transfer_channel_i_d = 2;
string transfer_port_i_d = 3;
}

// wrapper for liquidstakerate as wasm msg should be marshalled as encodedMsg = { wasmMsg: { wasm MsgDetails } }
message ExecuteLiquidStakeRate{
LiquidStakeRate liquid_stake_rate = 1[(gogoproto.nullable) = false];
// wrapper for liquidstakerate as wasm msg should be marshalled as encodedMsg =
// { wasmMsg: { wasm MsgDetails } }
message ExecuteLiquidStakeRate {
LiquidStakeRate liquid_stake_rate = 1 [ (gogoproto.nullable) = false ];
}

// msg blob for execute contract.
Expand All @@ -23,6 +26,10 @@ message LiquidStakeRate {
string stk_denom = 2;
// cvalue = default_bond_denom_price/stk_denom_price
// cvalue = stk_denom_supply/default_bond_denom_supply
string c_value = 3[(gogoproto.nullable) = false, (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
string c_value = 3 [
(gogoproto.nullable) = false,
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"
];
int64 controller_chain_time = 4;
}
4 changes: 2 additions & 2 deletions proto/pstake/ratesync/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types

// GenesisState defines the ratesync module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated HostChain host_chains = 2 [(gogoproto.nullable) = false];
Params params = 1 [ (gogoproto.nullable) = false ];
repeated HostChain host_chains = 2 [ (gogoproto.nullable) = false ];
}
2 changes: 1 addition & 1 deletion proto/pstake/ratesync/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types
message Params {
option (gogoproto.goproto_stringer) = false;

string admin = 1[(cosmos_proto.scalar) = "cosmos.AddressString"];
string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}
21 changes: 9 additions & 12 deletions proto/pstake/ratesync/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ service Query {
option (google.api.http).get = "/pstake/ratesync/v1beta1/params";
}


// Queries a list of Chain items.
rpc HostChain (QueryGetHostChainRequest) returns (QueryGetHostChainResponse) {
option (google.api.http).get = "/pstake-native/v2/ratesync/host_chain/{i_d}";

rpc HostChain(QueryGetHostChainRequest) returns (QueryGetHostChainResponse) {
option (google.api.http).get =
"/pstake-native/v2/ratesync/host_chain/{i_d}";
}
rpc AllHostChains (QueryAllHostChainsRequest) returns (QueryAllHostChainsResponse) {
rpc AllHostChains(QueryAllHostChainsRequest)
returns (QueryAllHostChainsResponse) {
option (google.api.http).get = "/pstake-native/v2/ratesync/host_chains";

}
}

Expand All @@ -34,22 +33,20 @@ message QueryParamsRequest {}
// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryGetHostChainRequest {
uint64 i_d = 1;
}
message QueryGetHostChainRequest { uint64 i_d = 1; }

message QueryGetHostChainResponse {
HostChain host_chain = 1 [(gogoproto.nullable) = false];
HostChain host_chain = 1 [ (gogoproto.nullable) = false ];
}

message QueryAllHostChainsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllHostChainsResponse {
repeated HostChain host_chains = 1 [(gogoproto.nullable) = false];
repeated HostChain host_chains = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
33 changes: 20 additions & 13 deletions proto/pstake/ratesync/v1beta1/ratesync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ import "amino/amino.proto";
option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types";

// HostChain defines the ratesync module's HostChain state.
message HostChain{
message HostChain {
// unique id
uint64 i_d = 1;
string chain_i_d = 2; //not really required, just easier readability
string chain_i_d = 2; // not really required, just easier readability
string connection_i_d = 3;
pstake.liquidstakeibc.v1beta1.ICAAccount i_c_a_account = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Feature features = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
pstake.liquidstakeibc.v1beta1.ICAAccount i_c_a_account = 4
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
Feature features = 5
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
string transfer_channel_i_d = 6;
string transfer_port_i_d = 7;
}
message Feature{
message Feature {
// triggers on hooks
LiquidStake liquid_stake_i_b_c = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
LiquidStake liquid_stake_i_b_c = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

// triggers on hour epoch
LiquidStake liquid_stake = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
LiquidStake liquid_stake = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

//add more features
// add more features
}

enum InstantiationState{
enum InstantiationState {
// Not Initiated
INSTANTIATION_NOT_INITIATED = 0;
// Initiated
Expand All @@ -40,16 +46,18 @@ enum FeatureType {
LIQUID_STAKE = 1;
}

message LiquidStake{
message LiquidStake {
FeatureType feature_type = 1;

// needs to be uploaded before hand
uint64 code_i_d = 2;
// state of instantiation, do not support gov based instantiation. (need ICA to be at least admin)
// state of instantiation, do not support gov based instantiation. (need ICA
// to be at least admin)
InstantiationState instantiation = 3;
// address of instantiated contract.
string contract_address = 4;
// allow * as default for all denoms in case of lsibc, or default bond denom in case of ls.
// allow * as default for all denoms in case of lsibc, or default bond denom
// in case of ls.
repeated string denoms = 5;

bool enabled = 6;
Expand All @@ -60,4 +68,3 @@ message ICAMemo {
FeatureType feature_type = 1;
uint64 host_chain_i_d = 2;
}

29 changes: 15 additions & 14 deletions proto/pstake/ratesync/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types

// Msg defines the Msg service.
service Msg {
rpc CreateHostChain (MsgCreateHostChain) returns (MsgCreateHostChainResponse);
rpc UpdateHostChain (MsgUpdateHostChain) returns (MsgUpdateHostChainResponse);
rpc DeleteHostChain (MsgDeleteHostChain) returns (MsgDeleteHostChainResponse);
rpc UpdateParams (MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc CreateHostChain(MsgCreateHostChain) returns (MsgCreateHostChainResponse);
rpc UpdateHostChain(MsgUpdateHostChain) returns (MsgUpdateHostChainResponse);
rpc DeleteHostChain(MsgDeleteHostChain) returns (MsgDeleteHostChainResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgCreateHostChain {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "pstake/ratesync/MsgCreateHostChain";

string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"];
HostChain host_chain = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
HostChain host_chain = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message MsgCreateHostChainResponse {
uint64 i_d = 1;
}
message MsgCreateHostChainResponse { uint64 i_d = 1; }

message MsgUpdateHostChain {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "pstake/ratesync/MsgUpdateHostChain";

string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"];
HostChain host_chain = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
HostChain host_chain = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message MsgUpdateHostChainResponse {}
Expand All @@ -45,7 +45,7 @@ message MsgDeleteHostChain {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "pstake/ratesync/MsgDeleteHostChain";

string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"];
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
uint64 i_d = 2;
}

Expand All @@ -55,8 +55,9 @@ message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "pstake/ratesync/MsgUpdateParams";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Params params = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
Params params = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message MsgUpdateParamsResponse {}
19 changes: 10 additions & 9 deletions x/liquidstakeibc/types/params.pb.go

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

2 changes: 2 additions & 0 deletions x/ratesync/keeper/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var ValidHostChainInMsg = func(id uint64) types.HostChain {
Enabled: false,
},
},
TransferChannelID: "channel-0",
TransferPortID: "transfer",
}
}

Expand Down
6 changes: 3 additions & 3 deletions x/ratesync/keeper/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (suite *IntegrationTestSuite) TestOnAcknowledgementPacket() {
hc, _ := k.GetHostChain(ctx, 1)
// case 1, instantiate msg.
{
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID)
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID, hc.TransferChannelID, hc.TransferPortID)
suite.Require().NoError(err)
msgData, err := icatypes.SerializeCosmosTx(suite.app.AppCodec(), []proto.Message{msg})
suite.Require().NoError(err)
Expand Down Expand Up @@ -59,7 +59,7 @@ func (suite *IntegrationTestSuite) TestOnAcknowledgementPacket() {
}
// case 2 instantiate failure
{
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID)
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID, hc.TransferChannelID, hc.TransferPortID)
suite.Require().NoError(err)
msgData, err := icatypes.SerializeCosmosTx(suite.app.AppCodec(), []proto.Message{msg})
suite.Require().NoError(err)
Expand Down Expand Up @@ -142,7 +142,7 @@ func (suite *IntegrationTestSuite) TestOnTimeoutPacket() {
hc, _ := k.GetHostChain(ctx, 1)
// case 1, instantiate msg.
{
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID)
msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID, hc.TransferChannelID, hc.TransferPortID)
suite.Require().NoError(err)
msgData, err := icatypes.SerializeCosmosTx(suite.app.AppCodec(), []proto.Message{msg})
suite.Require().NoError(err)
Expand Down
10 changes: 6 additions & 4 deletions x/ratesync/keeper/ica_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ func GenerateExecuteLiquidStakeRateTxMsg(blockTime int64, feature types.LiquidSt
}

func (k *Keeper) InstantiateLiquidStakeContract(ctx sdk.Context, icaAccount liquidstakeibctypes.ICAAccount,
feature types.LiquidStake, id uint64, connectionID string,
feature types.LiquidStake, id uint64, connectionID, transferChannelID, transferPort string,
) error {
// generate contract msg{msg}
msg, memoBz, err := GenerateInstantiateLiquidStakeContractMsg(icaAccount, feature, id)
msg, memoBz, err := GenerateInstantiateLiquidStakeContractMsg(icaAccount, feature, id, transferChannelID, transferPort)
if err != nil {
return err
}
Expand All @@ -163,10 +163,12 @@ func (k *Keeper) InstantiateLiquidStakeContract(ctx sdk.Context, icaAccount liqu
}

func GenerateInstantiateLiquidStakeContractMsg(icaAccount liquidstakeibctypes.ICAAccount,
feature types.LiquidStake, id uint64,
feature types.LiquidStake, id uint64, transferChannelID, transferPort string,
) (sdk.Msg, []byte, error) {
contractMsg := types.InstantiateLiquidStakeRateContract{
Admin: icaAccount.Address,
Admin: icaAccount.Address,
TransferChannelID: transferChannelID,
TransferPortID: transferPort,
}
contractMsgBz, err := json.Marshal(contractMsg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/ratesync/keeper/ica_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func (suite *IntegrationTestSuite) TestExecuteLiquidStakeRateTx() {
suite.Require().NoError(k.ExecuteLiquidStakeRateTx(ctx, hc.Features.LiquidStakeIBC,
"stk/uatom", "uatom", sdk.OneDec(), hc.ID, suite.ratesyncPathAB.EndpointA.ConnectionID, hc.ICAAccount))
suite.Require().NoError(k.InstantiateLiquidStakeContract(ctx, hc.ICAAccount,
hc.Features.LiquidStake, hc.ID, suite.ratesyncPathAB.EndpointA.ConnectionID))
hc.Features.LiquidStake, hc.ID, suite.ratesyncPathAB.EndpointA.ConnectionID, hc.TransferChannelID, hc.TransferPortID))
}
Loading

0 comments on commit c02835a

Please sign in to comment.