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

Custom vesting commands #80

Merged
merged 3 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,20 @@ test-unit-coverage-report: ## Generate global code coverage report in HTML
###############################################################################
### Proto ###
###############################################################################
protoVer=v0.8
protoVer=v0.9
protoImageName=osmolabs/osmo-proto-gen:$(protoVer)
containerProtoGen=nolus-proto-gen-$(protoVer)
PROTO_FORMATTER_IMAGE=tendermintdev/docker-build-proto@sha256:aabcfe2fc19c31c0f198d4cd26393f5e5ca9502d7ea3feafbfe972448fee7cae

.PHONY: proto-gen

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi

proto-format:
@echo "Formatting Protobuf files"
docker run --rm -v $(CURDIR):/workspace \
--workdir /workspace $(PROTO_FORMATTER_IMAGE) \
find ./ -name *.proto -exec clang-format -i {} \;
18 changes: 17 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import (
"github.com/Nolus-Protocol/nolus-core/x/tax"
taxmodulekeeper "github.com/Nolus-Protocol/nolus-core/x/tax/keeper"
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
"github.com/Nolus-Protocol/nolus-core/x/vestings"
vestingskeeper "github.com/Nolus-Protocol/nolus-core/x/vestings/keeper"
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -154,7 +157,8 @@ type AppKeepers struct {
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper

TaxKeeper taxmodulekeeper.Keeper
TaxKeeper taxmodulekeeper.Keeper
VestingsKeeper vestingskeeper.Keeper

InterchainTxsKeeper interchaintxskeeper.Keeper
InterchainQueriesKeeper interchainquerieskeeper.Keeper
Expand All @@ -170,6 +174,7 @@ type AppKeepers struct {
TransferModule transferSudo.AppModule
FeeRefunderModule feerefunder.AppModule
TaxModule tax.AppModule
VestingsModule vestings.AppModule
IcaModule ica.AppModule
}

Expand Down Expand Up @@ -441,6 +446,16 @@ func NewAppKeeper(
)
appKeepers.TaxModule = tax.NewAppModule(appCodec, appKeepers.TaxKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper)

appKeepers.VestingsKeeper = *vestingskeeper.NewKeeper(
appCodec,
appKeepers.keys[vestingstypes.StoreKey],
appKeepers.keys[vestingstypes.MemStoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.GetSubspace(vestingstypes.ModuleName),
)
appKeepers.VestingsModule = vestings.NewAppModule(appCodec, appKeepers.VestingsKeeper)

transferIBCModule := transferSudo.NewIBCModule(appKeepers.TransferKeeper)

var icaControllerStack ibcporttypes.IBCModule
Expand Down Expand Up @@ -487,6 +502,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(feetypes.ModuleName)
paramsKeeper.Subspace(interchaintxstypes.ModuleName)
paramsKeeper.Subspace(interchainqueriestypes.ModuleName)
paramsKeeper.Subspace(vestingstypes.ModuleName)

return paramsKeeper
}
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types"
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

"github.com/CosmWasm/wasmd/x/wasm"

Expand All @@ -36,7 +37,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey,
upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey,
taxmoduletypes.StoreKey, icacontrollertypes.StoreKey, capabilitytypes.StoreKey,
taxmoduletypes.StoreKey, vestingstypes.StoreKey, icacontrollertypes.StoreKey, capabilitytypes.StoreKey,
interchainqueriestypes.StoreKey, contractmanagermoduletypes.StoreKey, interchaintxstypes.StoreKey,
wasm.StoreKey, feerefundertypes.StoreKey,
)
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types"
"github.com/Nolus-Protocol/nolus-core/x/tax"
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
"github.com/Nolus-Protocol/nolus-core/x/vestings"
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
Expand Down Expand Up @@ -89,6 +91,7 @@ var maccPerms = map[string][]string{
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasm.ModuleName: {authtypes.Burner},
vestingstypes.ModuleName: nil,
icatypes.ModuleName: nil,
interchainqueriestypes.ModuleName: nil,
feetypes.ModuleName: nil,
Expand All @@ -115,6 +118,7 @@ var ModuleBasics = module.NewBasicManager(
transferSudo.AppModuleBasic{},
vesting.AppModuleBasic{},
wasm.AppModuleBasic{},
vestings.AppModuleBasic{},
tax.AppModuleBasic{},
ica.AppModuleBasic{},
interchaintxs.AppModuleBasic{},
Expand Down Expand Up @@ -156,6 +160,7 @@ func appModules(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
app.AppKeepers.TransferModule,
app.AppKeepers.VestingsModule,
app.AppKeepers.TaxModule,
app.AppKeepers.IcaModule,
app.AppKeepers.InterchainQueriesModule,
Expand Down Expand Up @@ -228,6 +233,7 @@ func orderBeginBlockers() []string {
ibctransfertypes.ModuleName,
crisistypes.ModuleName,
taxmoduletypes.ModuleName,
vestingstypes.ModuleName,
govtypes.ModuleName,
icatypes.ModuleName,
interchaintxstypes.ModuleName,
Expand Down Expand Up @@ -257,6 +263,7 @@ func orderEndBlockers() []string {
banktypes.ModuleName,
distrtypes.ModuleName,
taxmoduletypes.ModuleName,
vestingstypes.ModuleName,
icatypes.ModuleName,
interchaintxstypes.ModuleName,
interchainqueriestypes.ModuleName,
Expand Down Expand Up @@ -287,6 +294,7 @@ func orderInitBlockers() []string {
minttypes.ModuleName,
crisistypes.ModuleName,
taxmoduletypes.ModuleName,
vestingstypes.ModuleName,
ibchost.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand Down
38 changes: 38 additions & 0 deletions doc/adr/20230529-custom-vestings-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Accept fees in NLS only

- Status: accepted
- Deciders: the product owner, the dev team
- Date: 2023-05-29
- Tags: vestings module, vesting accounts, custom vesting start time

Technical Story:
We want to add vesting accounts with a custom start time which is currently not supported in the cosmos-sdk's native vesting module.
There is an ongoing discussion in the cosmos-sdk community about adding this feature/flag to the native vesting module.
https://github.com/cosmos/cosmos-sdk/issues/4287

We decided to implement our own vesting module which will support custom vesting start time.

## Context and Problem Statement

We need to be able to create vesting accounts that have start-time different than the current block time after the chain has started.

There is a command for creating vesting accounts in the cosmos-sdk's native vesting module, but it does not support custom vesting start time.
Instead it always uses the current block time as the vesting start time.

## Decision Drivers

- We need to be able to create vesting accounts with a custom start time after the chain has started

## Decision Outcome

The decision we took is to create a new module that will support adding a vesting account with custom vesting start time.
We've seen that there is a similar module developed for this purpose in stargaze network(alloc module), but it has additional features that we don't need.

### Positive Consequences

- We will be able to create vesting accounts with custom vesting start time after the chain has started


## Potential evolution

If a flag for custom start time is added to the cosmos-sdk's native vesting module, we can deprecate our custom vesting module and use the native one instead.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/CosmWasm/wasmd v0.31.0
github.com/CosmWasm/wasmvm v1.2.3
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-sdk v0.45.15
github.com/cosmos/gogoproto v1.4.6
github.com/cosmos/ibc-go/v4 v4.3.1
Expand Down Expand Up @@ -35,7 +36,6 @@ require (
github.com/DataDog/zstd v1.5.0 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 839ad55704e84abfa130445b8ee3ef9d
commit: f384ef1fd55a41d8b34331f77d2077eb
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 34d970b699f84aa382f3c29773a60836
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 783e4b5374fa488ab068d08af9658438
commit: 5ae7f88519b04fe1965da0f8a375a088
4 changes: 2 additions & 2 deletions proto/nolus/mint/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ option go_package = "github.com/Nolus-Protocol/nolus-core/x/mint/types";
// GenesisState defines the mint module's genesis state.
message GenesisState {
// minter is a space for holding current inflation information.
Minter minter = 1 [(gogoproto.nullable) = false];
Minter minter = 1 [ (gogoproto.nullable) = false ];

// params defines all the paramaters of the module.
Params params = 2 [(gogoproto.nullable) = false];
Params params = 2 [ (gogoproto.nullable) = false ];
}
18 changes: 9 additions & 9 deletions proto/nolus/mint/v1beta1/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ option go_package = "github.com/Nolus-Protocol/nolus-core/x/mint/types";

// Minter represents the minting state.
message Minter {
string norm_time_passed = 2
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
string norm_time_passed = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string total_minted = 3
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
string total_minted = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];

string prev_block_timestamp = 4
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
string prev_block_timestamp = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];

string annual_inflation = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
(gogoproto.nullable) = false
];
}

Expand All @@ -33,8 +33,8 @@ message Params {
// type of coin to mint
string mint_denom = 1;

string max_mintable_nanoseconds = 2
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
string max_mintable_nanoseconds = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}
32 changes: 22 additions & 10 deletions proto/nolus/mint/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ service Query {
option (google.api.http).get = "/nolus/mint/v1beta1/state";
}

// AnnualInflation returns the current minting inflation rate for the next 12 months.
rpc AnnualInflation(QueryAnnualInflationRequest) returns (QueryAnnualInflationResponse) {
// AnnualInflation returns the current minting inflation rate for the next 12
// months.
rpc AnnualInflation(QueryAnnualInflationRequest)
returns (QueryAnnualInflationResponse) {
option (google.api.http).get = "/nolus/mint/v1beta1/annual_inflation";
}
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand All @@ -31,7 +33,7 @@ message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryMintStateRequest is the request type for the Query/State RPC method.
Expand All @@ -40,16 +42,26 @@ message QueryMintStateRequest {}
// QueryMintStateResponse is the response type for the Query/State RPC
// method.
message QueryMintStateResponse {
bytes norm_time_passed = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
bytes total_minted = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint", (gogoproto.nullable) = false];
bytes norm_time_passed = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
bytes total_minted = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}

// QueryAnnualInflationRequest is the request type for the Query/AnnualInflation RPC method.
// QueryAnnualInflationRequest is the request type for the Query/AnnualInflation
// RPC method.
message QueryAnnualInflationRequest {}

// QueryAnnualInflationResponse is the response type for the Query/AnnualInflation RPC
// method.
// QueryAnnualInflationResponse is the response type for the
// Query/AnnualInflation RPC method.
message QueryAnnualInflationResponse {
// inflation is the current minting inflation value.
bytes annual_inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint", (gogoproto.nullable) = false];
bytes annual_inflation = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}
4 changes: 1 addition & 3 deletions proto/tax/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ import "tax/params.proto";
option go_package = "github.com/Nolus-Protocol/nolus-core/x/tax/types";

// GenesisState defines the tax module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
}
message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; }
2 changes: 1 addition & 1 deletion proto/tax/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ 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 ];
}
10 changes: 10 additions & 0 deletions proto/vestings/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package vestings;

import "gogoproto/gogo.proto";
import "vestings/params.proto";

option go_package = "github.com/Nolus-Protocol/nolus-core/x/vestings/types";

// GenesisState defines the vestings module's genesis state.
message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; }
9 changes: 9 additions & 0 deletions proto/vestings/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package vestings;

import "gogoproto/gogo.proto";

option go_package = "github.com/Nolus-Protocol/nolus-core/x/vestings/types";

// Params defines the parameters for the module.
message Params { option (gogoproto.stringer) = false; }
25 changes: 25 additions & 0 deletions proto/vestings/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package vestings;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "vestings/params.proto";

option go_package = "github.com/Nolus-Protocol/nolus-core/x/vestings/types";

// 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 defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/nolus/vestings/params";
}
}
Loading