Skip to content

Commit

Permalink
feat: liquidstake module (#684)
Browse files Browse the repository at this point in the history
* feat: stkxprt impl

* fix: codec

* chore: re-gen

* feat: lsm-lp integration; some refactorings

* fix: un-bump wasmd version

* chore: fix proto files, update proto-builder to 0.14.0 and make proto-format.
  • Loading branch information
Max Kupriianov authored Dec 11, 2023
1 parent 4ecf59e commit d82b71b
Show file tree
Hide file tree
Showing 43 changed files with 8,954 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ test-docker-push: test-docker
### Protobuf ###
###############################################################################

protoVer=0.13.5
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
github.com/CosmWasm/wasmd v0.40.2
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.9.1
github.com/cosmos/cosmos-proto v1.0.0-beta.2
Expand All @@ -25,6 +26,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand All @@ -41,6 +43,7 @@ require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/CosmWasm/wasmvm v1.2.4 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -69,6 +72,7 @@ require (
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
Expand Down Expand Up @@ -125,6 +129,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
Expand Down Expand Up @@ -166,7 +171,6 @@ require (
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
Expand All @@ -182,6 +186,7 @@ replace (

// use persistence's forks with LSM implemented
replace (
github.com/CosmWasm/wasmd => github.com/persistenceOne/wasmd v0.40.2-lsm3
github.com/cosmos/cosmos-sdk => github.com/persistenceOne/cosmos-sdk v0.47.3-lsm4
github.com/cosmos/ibc-go/v7 => github.com/persistenceOne/ibc-go/v7 v7.2.0-lsm3
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/wasmvm v1.2.4 h1:6OfeZuEcEH/9iqwrg2pkeVtDCkMoj9U6PpKtcrCyVrQ=
github.com/CosmWasm/wasmvm v1.2.4/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down Expand Up @@ -455,6 +457,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
Expand Down Expand Up @@ -1009,6 +1013,8 @@ github.com/persistenceOne/ibc-go/v7 v7.2.0-lsm3 h1:U4NsRXpg9VHCFVyrk1JfG+sIA3frt
github.com/persistenceOne/ibc-go/v7 v7.2.0-lsm3/go.mod h1:PDvFOPEd8Fz25qBmhX7KXSPX4COyGnytKweRdEP1yfA=
github.com/persistenceOne/persistence-sdk/v2 v2.1.1 h1:fo8Og2QkjsqqhH/wiEiOSB99M2Jr0kLqirU2xhJRZfQ=
github.com/persistenceOne/persistence-sdk/v2 v2.1.1/go.mod h1:6ufKMowypJB865CT5Gm6Gs42YCtSkX7k3ZqKzx63y+8=
github.com/persistenceOne/wasmd v0.40.2-lsm3 h1:JdUu2TNEA+rJVYX7gt7EP/WUUA78f67joBOWtWAEShg=
github.com/persistenceOne/wasmd v0.40.2-lsm3/go.mod h1:xF6v70lqO7+Ys2wsfAHybuQXQI7IOqGf2LCq/XK8Fk8=
github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
Expand Down
20 changes: 20 additions & 0 deletions proto/pstake/liquidstake/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package pstake.liquidstake.v1beta1;

import "gogoproto/gogo.proto";
import "pstake/liquidstake/v1beta1/liquidstake.proto";

option go_package = "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types";
option (gogoproto.equal_all) = true;

// GenesisState defines the liquidstake module's genesis state.
message GenesisState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// params defines all the parameters for the liquidstake module
Params params = 1 [ (gogoproto.nullable) = false ];

repeated LiquidValidator liquid_validators = 2
[ (gogoproto.nullable) = false ];
}
191 changes: 191 additions & 0 deletions proto/pstake/liquidstake/v1beta1/liquidstake.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
syntax = "proto3";

package pstake.liquidstake.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types";

// Params defines the set of params for the liquidstake module.
message Params {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

// LiquidBondDenom specifies the denomination of the token receiving after
// liquid stake, The value is calculated through NetAmount.
string liquid_bond_denom = 1;

// WhitelistedValidators specifies the validators elected to become Active
// Liquid Validators.
repeated WhitelistedValidator whitelisted_validators = 2
[ (gogoproto.nullable) = false ];

// UnstakeFeeRate specifies the fee rate when liquid unstake is requested,
// unbonded by subtracting it from unbondingAmount
string unstake_fee_rate = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// LsmDisabled allows to block any msgs that convert staked tokens into
// stkXPRT through LSM.
bool lsm_disabled = 4;

// MinLiquidStakingAmount specifies the minimum number of coins to be staked
// to the active liquid validators on liquid staking to minimize decimal loss
// and consider gas efficiency.
string min_liquid_stake_amount = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// cw_locked_pool_address defines the bech32-encoded address of
// a CW smart-contract representing a time locked LP (e.g. Superfluid LP).
string cw_locked_pool_address = 6
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

// ValidatorStatus enumerates the status of a liquid validator.
enum ValidatorStatus {
option (gogoproto.goproto_enum_prefix) = false;

// VALIDATOR_STATUS_UNSPECIFIED defines the unspecified invalid status.
VALIDATOR_STATUS_UNSPECIFIED = 0
[ (gogoproto.enumvalue_customname) = "ValidatorStatusUnspecified" ];
// VALIDATOR_STATUS_ACTIVE defines the active, valid status
VALIDATOR_STATUS_ACTIVE = 1
[ (gogoproto.enumvalue_customname) = "ValidatorStatusActive" ];
// VALIDATOR_STATUS_INACTIVE defines the inactive, invalid status
VALIDATOR_STATUS_INACTIVE = 2
[ (gogoproto.enumvalue_customname) = "ValidatorStatusInactive" ];
}

// WhitelistedValidator consists of the validator operator address and the
// target weight, which is a value for calculating the real weight to be derived
// according to the active status. In the case of inactive, it is calculated as
// zero.
message WhitelistedValidator {
option (gogoproto.goproto_getters) = false;

// validator_address defines the bech32-encoded address that whitelisted
// validator
string validator_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
;

// target_weight specifies the target weight for liquid staking, unstaking
// amount, which is a value for calculating the real weight to be derived
// according to the active status
string target_weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// LiquidValidator defines a Validator that can be the target of LiquidStaking
// and LiquidUnstaking, Active, Weight, etc. fields are derived as functions to
// deal with by maintaining consistency with the state of the staking module.
message LiquidValidator {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// operator_address defines the address of the validator's operator; bech
// encoded in JSON.
string operator_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

// LiquidValidatorState is type LiquidValidator with state added to return to
// query results.
message LiquidValidatorState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// operator_address defines the address of the validator's operator; bech
// encoded in JSON.
string operator_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// weight specifies the weight for liquid staking, unstaking amount
string weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// status is the liquid validator status
ValidatorStatus status = 3;

// del_shares define the delegation shares of the validator
string del_shares = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// liquid_tokens define the token amount worth of delegation shares of the
// validator (slashing applied amount)
string liquid_tokens = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// NetAmountState is type for net amount raw data and mint rate, This is a value
// that depends on the several module state every time, so it is used only for
// calculation and query and is not stored in kv.
message NetAmountState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = true;

// mint_rate is stkXPRTTotalSupply / NetAmount
string mint_rate = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// btoken_total_supply returns the total supply of stk/uxprt (stkXPRT denom)
string stkxprt_total_supply = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// net_amount is proxy account's native token balance + total liquid tokens +
// total remaining rewards + total unbonding balance
string net_amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// total_del_shares define the delegation shares of all liquid validators
string total_del_shares = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// total_liquid_tokens define the token amount worth of delegation shares of
// all liquid validator (slashing applied amount)
string total_liquid_tokens = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// total_remaining_rewards define the sum of remaining rewards of proxy
// account by all liquid validators
string total_remaining_rewards = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// total_unbonding_balance define the unbonding balance of proxy account by
// all liquid validator (slashing applied amount)
string total_unbonding_balance = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// proxy_acc_balance define the balance of proxy account for the native token
string proxy_acc_balance = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
55 changes: 55 additions & 0 deletions proto/pstake/liquidstake/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
syntax = "proto3";
package pstake.liquidstake.v1beta1;

import "google/api/annotations.proto";
import "pstake/liquidstake/v1beta1/liquidstake.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types";

// Query defines the gRPC query service for the liquidstake module.
service Query {
// Params returns parameters of the liquidstake module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pstake/liquidstake/v1beta1/params";
}

// LiquidValidators returns liquid validators with states of the liquidstake
// module.
rpc LiquidValidators(QueryLiquidValidatorsRequest)
returns (QueryLiquidValidatorsResponse) {
option (google.api.http).get = "/pstake/liquidstake/v1beta1/validators";
}

// States returns states of the liquidstake module.
rpc States(QueryStatesRequest) returns (QueryStatesResponse) {
option (google.api.http).get = "/pstake/liquidstake/v1beta1/states";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryLiquidValidatorsRequest is the request type for the
// Query/LiquidValidators RPC method.
message QueryLiquidValidatorsRequest {}

// QueryLiquidValidatorsResponse is the response type for the
// Query/LiquidValidators RPC method.
message QueryLiquidValidatorsResponse {
repeated LiquidValidatorState liquid_validators = 1
[ (gogoproto.nullable) = false ];
}

// QueryStatesRequest is the request type for the Query/States RPC method.
message QueryStatesRequest {}

// QueryStatesResponse is the response type for the Query/States RPC method.
message QueryStatesResponse {
NetAmountState net_amount_state = 1 [ (gogoproto.nullable) = false ];
}
Loading

0 comments on commit d82b71b

Please sign in to comment.