Skip to content

Commit

Permalink
feat(tokenfactory): execute msgs for CreateDenom, ChangeAdmin, Update…
Browse files Browse the repository at this point in the history
…ModuleParams (#1607)

* (proto): add some txs and events for token factory

* #wip msg handlers impl

* fix grpc query test

* test(tokenfactory): validate basic and msg server tests

* test(tokenfactory): update module params

* fix(tokenfactory): changelog, linter, put blank CLi commands instead of
panic

* test(tokenfactory): add case for if the denom is not registered in ChangeAdmin

* token factory CLI tests and queries with tests

* test(tokenfactory/types): more coverage

* combo squashed commit: Resolves strange proto break error

test(tokenfactory): more CLI test coverage

feat(perp): Add user discounts (#1594)

* add discounts

* impl genesis

* fix test

* make test more robust

* galaxy brain int encoding fix

* test and optimise

* lint

* CHANGELOG.md

* do merge

* clarify fee variable names in applyDiscountAndRebate func

* refactor dnr_test.go as per PR review

* add genesis tests

---------

Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: godismercilex <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>

feat(perp): Add user discounts (#1594)

* add discounts

* impl genesis

* fix test

* make test more robust

* galaxy brain int encoding fix

* test and optimise

* lint

* CHANGELOG.md

* do merge

* clarify fee variable names in applyDiscountAndRebate func

* refactor dnr_test.go as per PR review

* add genesis tests

---------

Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: godismercilex <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>

* ci(proto-lint): should refer to the PR, not just the last commit

* ci(proto-lint): supply with github token in buf setup b/c rate limits

---------

Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: godismercilex <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Matthias <[email protected]>
  • Loading branch information
5 people authored Oct 3, 2023
1 parent c7ae585 commit e054b45
Show file tree
Hide file tree
Showing 30 changed files with 4,486 additions and 107 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#1596](https://github.com/NibiruChain/nibiru/pull/1596) - epic(tokenfactory):
State transitions, collections, genesis import and export, and app wiring
* [#1607](https://github.com/NibiruChain/nibiru/pull/1607) - Token factory
transaction messages for CreateDenom, ChangeAdmin, and UpdateModuleParams

### State Machine Breaking

Expand Down
16 changes: 16 additions & 0 deletions proto/nibiru/tokenfactory/v1/event.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package nibiru.tokenfactory.v1;

option go_package = "github.com/NibiruChain/nibiru/x/tokenfactory/types";

message EventCreateDenom {
string denom = 1;
string creator = 2;
}

message EventChangeAdmin {
string denom = 1;
string old_admin = 3;
string new_admin = 2;
}
32 changes: 31 additions & 1 deletion proto/nibiru/tokenfactory/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package nibiru.tokenfactory.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "nibiru/tokenfactory/v1/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/tokenfactory/types";
Expand All @@ -15,6 +16,16 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/nibiru/tokenfactory/v1/params";
}

// Denoms retrieves all registered denoms for a given creator
rpc Denoms(QueryDenomsRequest) returns (QueryDenomsResponse) {
option (google.api.http).get = "/nibiru/tokenfactory/v1/denoms/{creator}";
}

// DenomInfo retrieves the denom metadata and admin info
rpc DenomInfo(QueryDenomInfoRequest) returns (QueryDenomInfoResponse) {
option (google.api.http).get = "/nibiru/tokenfactory/v1/denom-info/{denom}";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand All @@ -23,5 +34,24 @@ message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// Module parameters stored in state
ModuleParams params = 1 [ (gogoproto.nullable) = false ];
nibiru.tokenfactory.v1.ModuleParams params = 1
[ (gogoproto.nullable) = false ];
}

// QueryDenomsRequest: gRPC query for all denoms registered for a creator
message QueryDenomsRequest { string creator = 1; }

// QueryDenomsResponse: All registered denoms for a creator
message QueryDenomsResponse { repeated string denoms = 1; }

// QueryDenomInfoRequest: gRPC query for the denom admin and x/bank metadata
message QueryDenomInfoRequest { string denom = 1; }

// QueryDenomInfoResponse: All registered denoms for a creator
message QueryDenomInfoResponse {
// Admin of the token factory denom
string admin = 1;
// Metadata: Official x/bank metadata for the denom. All token factory denoms
// are standard, native assets.
cosmos.bank.v1beta1.Metadata metadata = 2 [ (gogoproto.nullable) = false ];
}
65 changes: 64 additions & 1 deletion proto/nibiru/tokenfactory/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,70 @@ syntax = "proto3";

package nibiru.tokenfactory.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "nibiru/tokenfactory/v1/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/tokenfactory/types";

// Msg defines the gRPC Msg service for transactions.
service Msg {}
service Msg {
// CreateDenom: registers a token factory denom.
rpc CreateDenom(MsgCreateDenom) returns (MsgCreateDenomResponse);
rpc ChangeAdmin(MsgChangeAdmin) returns (MsgChangeAdminResponse);
// UpdateModuleParams: A governance operation for updating the x/tokenfactory
// module parameters.
rpc UpdateModuleParams(MsgUpdateModuleParams)
returns (MsgUpdateModuleParamsResponse);
// TODO MsgMint
// TODO MsgBurn
// TODO MsgSetDenomMetadata
// TODO MsgForceTransfer
}

// MsgCreateDenom: sdk.Msg that registers an a token factory denom.
// A denom has the form "tf/[creatorAddr]/[subdenom]".
// - Denoms become unique x/bank tokens, so the creator-subdenom pair that
// defines a denom cannot be reused.
// - The resulting denom's admin is originally set to be the creator, but the
// admin can be changed later.
message MsgCreateDenom {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
// subdenom can be up to 44 "alphanumeric" characters long.
string subdenom = 2 [ (gogoproto.moretags) = "yaml:\"subdenom\"" ];
}

// MsgCreateDenomResponse is the return value of MsgCreateDenom
message MsgCreateDenomResponse {
// NewTokenDenom: identifier for the newly created token factory denom.
string new_token_denom = 1
[ (gogoproto.moretags) = "yaml:\"new_token_denom\"" ];
}

// MsgChangeAdmin is the sdk.Msg type for allowing an admin account to change
// admin of a denom to a new account
message MsgChangeAdmin {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
string denom = 2 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
string new_admin = 3 [ (gogoproto.moretags) = "yaml:\"new_admin\"" ];
}

// MsgChangeAdminResponse is the gRPC response for the MsgChangeAdmin TxMsg.
message MsgChangeAdminResponse {}

// MsgUpdateModuleParams: sdk.Msg for updating the x/tokenfactory module params
message MsgUpdateModuleParams {
option (cosmos.msg.v1.signer) = "authority";

// Authority: Address of the governance module account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

nibiru.tokenfactory.v1.ModuleParams params = 2
[ (gogoproto.nullable) = false ];
}

// MsgUpdateModuleParamsResponse is the gRPC response for the
// MsgUpdateModuleParams TxMsg.
message MsgUpdateModuleParamsResponse {}
17 changes: 16 additions & 1 deletion x/common/testutil/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,23 @@ func WithQueryEncodingType(e EncodingType) ExecQueryOption {
}
}

func (chain Network) ExecQuery(
cmd *cobra.Command,
args []string,
result codec.ProtoMarshaler,
opts ...ExecQueryOption,
) error {
return ExecQuery(chain.Validators[0].ClientCtx, cmd, args, result, opts...)
}

// ExecQuery executes a CLI query onto the provided Network.
func ExecQuery(clientCtx client.Context, cmd *cobra.Command, args []string, result codec.ProtoMarshaler, opts ...ExecQueryOption) error {
func ExecQuery(
clientCtx client.Context,
cmd *cobra.Command,
args []string,
result codec.ProtoMarshaler,
opts ...ExecQueryOption,
) error {
var options queryOptions
for _, o := range opts {
o(&options)
Expand Down
7 changes: 7 additions & 0 deletions x/common/testutil/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

// AccAddress returns a sample address (sdk.AccAddress) created using secp256k1.
Expand Down Expand Up @@ -77,3 +80,7 @@ func RandLetters(n int) string {
}
return string(b)
}

func GovModuleAddr() sdk.AccAddress {
return authtypes.NewModuleAddress(govtypes.ModuleName)
}
18 changes: 9 additions & 9 deletions x/devgas/v1/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func NewTxCmd() *cobra.Command {
}

txCmd.AddCommand(
NewRegisterFeeShare(),
NewCancelFeeShare(),
NewUpdateFeeShare(),
CmdRegisterFeeShare(),
CmdCancelFeeShare(),
CmdUpdateFeeShare(),
)
return txCmd
}

// NewRegisterFeeShare returns a CLI command handler for registering a
// CmdRegisterFeeShare returns a CLI command handler for registering a
// contract for fee distribution
func NewRegisterFeeShare() *cobra.Command {
func CmdRegisterFeeShare() *cobra.Command {
cmd := &cobra.Command{
Use: "register [contract_bech32] [withdraw_bech32]",
Short: "Register a contract for fee distribution. Only the contract admin can register a contract.",
Expand Down Expand Up @@ -69,9 +69,9 @@ func NewRegisterFeeShare() *cobra.Command {
return cmd
}

// NewCancelFeeShare returns a CLI command handler for canceling a
// CmdCancelFeeShare returns a CLI command handler for canceling a
// contract for fee distribution
func NewCancelFeeShare() *cobra.Command {
func CmdCancelFeeShare() *cobra.Command {
cmd := &cobra.Command{
Use: "cancel [contract_bech32]",
Short: "Cancel a contract from feeshare distribution",
Expand Down Expand Up @@ -104,9 +104,9 @@ func NewCancelFeeShare() *cobra.Command {
return cmd
}

// NewUpdateFeeShare returns a CLI command handler for updating the withdraw
// CmdUpdateFeeShare returns a CLI command handler for updating the withdraw
// address of a contract for fee distribution
func NewUpdateFeeShare() *cobra.Command {
func CmdUpdateFeeShare() *cobra.Command {
cmd := &cobra.Command{
Use: "update [contract_bech32] [new_withdraw_bech32]",
Short: "Update withdrawer address for a contract registered for feeshare distribution.",
Expand Down
7 changes: 4 additions & 3 deletions x/sudo/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (m MsgEditSudoers) ValidateBasic() error {
return nil
}

// GetSigners implements the sdk.Msg interface.
func (m MsgEditSudoers) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
Expand All @@ -43,13 +44,13 @@ func (m MsgEditSudoers) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

// Route Implements Msg.
// Route implements the sdk.Msg interface.
func (msg MsgEditSudoers) Route() string { return ModuleName }

// Type Implements Msg.
// Type implements the sdk.Msg interface.
func (msg MsgEditSudoers) Type() string { return "edit_sudoers" }

// GetSignBytes Implements Msg.
// GetSignBytes implements the sdk.Msg interface.
func (m MsgEditSudoers) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
Expand Down
Loading

0 comments on commit e054b45

Please sign in to comment.