From 4bcb89e8330f25e7824512098b27369898cd452f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Mon, 30 Sep 2024 17:27:24 +0700 Subject: [PATCH 1/5] add gov for MsgActiveCollateral module vaults --- script/proposal-1.json | 13 +++ script/vaults-gov-test.sh | 137 +++++++++++++++++++++++++++++ x/vaults/keeper/keeper.go | 2 +- x/vaults/keeper/msg_server.go | 4 + x/vaults/module/proposal_handle.go | 23 +++++ x/vaults/types/codec.go | 8 +- x/vaults/types/errors.go | 3 +- x/vaults/types/keys.go | 5 +- x/vaults/types/msgs.go | 45 ++++++++++ 9 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 script/proposal-1.json create mode 100755 script/vaults-gov-test.sh create mode 100644 x/vaults/module/proposal_handle.go diff --git a/script/proposal-1.json b/script/proposal-1.json new file mode 100644 index 00000000..7f7fc6ee --- /dev/null +++ b/script/proposal-1.json @@ -0,0 +1,13 @@ +{ + "messages": [{ + "@type": "/reserve.vaults.MsgActiveCollateral", + "denom": "atom", + "authority":"onomy10d07y265gmmuvt4z0w9aw880jnsr700jqr8n8k", + "min_collateral_ratio": "0.5", + "liquidation_ratio":"0.5", + "max_debt":"10000" + }], + "deposit": "100000000stake", + "title": "My proposal", + "summary": "A short summary of my proposal" + } \ No newline at end of file diff --git a/script/vaults-gov-test.sh b/script/vaults-gov-test.sh new file mode 100755 index 00000000..3231dc8c --- /dev/null +++ b/script/vaults-gov-test.sh @@ -0,0 +1,137 @@ +#!/bin/bash +set -xeu + +# always returns true so set -e doesn't exit if it is not running. +killall reserved || true +rm -rf $HOME/.reserved/ + +mkdir $HOME/.reserved +mkdir $HOME/.reserved/validator1 +mkdir $HOME/.reserved/validator2 +mkdir $HOME/.reserved/validator3 + +# init all three validators +reserved init --chain-id=testing-1 validator1 --home=$HOME/.reserved/validator1 +reserved init --chain-id=testing-1 validator2 --home=$HOME/.reserved/validator2 +reserved init --chain-id=testing-1 validator3 --home=$HOME/.reserved/validator3 + +# create keys for all three validators +mnemonic1="top toddler wrist parade hobby supply odor ginger resource copy square tell vanish pride volcano effort planet style transfer pipe wise bus tuition luxury" +mnemonic2="panther giant oyster hand song region chunk coil laundry glance ball denial void ramp palm fiscal pizza soccer before upset diet valid story cement" +mnemonic3="gap track crop knee galaxy square case resemble subway math moon mom casino trade finish exotic author comic gap margin elegant claw fire business" + +echo $mnemonic1| reserved keys add validator1 --recover --keyring-backend=test --home=$HOME/.reserved/validator1 +echo $mnemonic2| reserved keys add validator2 --recover --keyring-backend=test --home=$HOME/.reserved/validator2 +echo $mnemonic3| reserved keys add validator3 --recover --keyring-backend=test --home=$HOME/.reserved/validator3 + +# create validator node with tokens to transfer to the three other nodes +reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1 +reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1 +reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1 +reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2 +reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2 +reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2 +reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3 +reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3 +reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3 +reserved genesis gentx validator1 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator1 --chain-id=testing-1 +reserved genesis gentx validator2 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator2 --chain-id=testing-1 +reserved genesis gentx validator3 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator3 --chain-id=testing-1 + +# cp validator2/config/gentx/*.json $HOME/.reserved/validator1/config/gentx/ +# cp validator3/config/gentx/*.json $HOME/.reserved/validator1/config/gentx/ +reserved genesis collect-gentxs --home=$HOME/.reserved/validator1 + +# change app.toml values +VALIDATOR1_APP_TOML=$HOME/.reserved/validator1/config/app.toml +VALIDATOR2_APP_TOML=$HOME/.reserved/validator2/config/app.toml +VALIDATOR3_APP_TOML=$HOME/.reserved/validator3/config/app.toml + +# validator1 +sed -i -E 's|0.0.0.0:9090|0.0.0.0:9050|g' $VALIDATOR1_APP_TOML +sed -i -E 's|127.0.0.1:9090|127.0.0.1:9050|g' $VALIDATOR1_APP_TOML +sed -i -E 's|minimum-gas-prices = ""|minimum-gas-prices = "0.0001stake"|g' $VALIDATOR1_APP_TOML + +# validator2 +sed -i -E 's|tcp://0.0.0.0:1317|tcp://0.0.0.0:1316|g' $VALIDATOR2_APP_TOML +sed -i -E 's|0.0.0.0:9090|0.0.0.0:9088|g' $VALIDATOR2_APP_TOML +sed -i -E 's|0.0.0.0:9091|0.0.0.0:9089|g' $VALIDATOR2_APP_TOML +sed -i -E 's|minimum-gas-prices = ""|minimum-gas-prices = "0.0001stake"|g' $VALIDATOR2_APP_TOML + +# validator3 +sed -i -E 's|tcp://0.0.0.0:1317|tcp://0.0.0.0:1315|g' $VALIDATOR3_APP_TOML +sed -i -E 's|0.0.0.0:9090|0.0.0.0:9086|g' $VALIDATOR3_APP_TOML +sed -i -E 's|0.0.0.0:9091|0.0.0.0:9087|g' $VALIDATOR3_APP_TOML +sed -i -E 's|minimum-gas-prices = ""|minimum-gas-prices = "0.0001stake"|g' $VALIDATOR3_APP_TOML + +# change config.toml values +VALIDATOR1_CONFIG=$HOME/.reserved/validator1/config/config.toml +VALIDATOR2_CONFIG=$HOME/.reserved/validator2/config/config.toml +VALIDATOR3_CONFIG=$HOME/.reserved/validator3/config/config.toml + + +# validator1 +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR1_CONFIG + + +# validator2 +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26655|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26654|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' $VALIDATOR2_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26630"|g' $VALIDATOR2_CONFIG + +# validator3 +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26652|g' $VALIDATOR3_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26651|g' $VALIDATOR3_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR3_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR3_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR3_CONFIG +sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26620"|g' $VALIDATOR3_CONFIG + +# copy, update validator1 genesis file to validator2-3 +update_test_genesis () { + cat $HOME/.reserved/validator1/config/genesis.json | jq "$1" > tmp.json && mv tmp.json $HOME/.reserved/validator1/config/genesis.json +} + +update_test_genesis '.app_state["gov"]["params"]["voting_period"] = "15s"' +update_test_genesis '.app_state["gov"]["params"]["expedited_voting_period"] = "10s"' + +cp $HOME/.reserved/validator1/config/genesis.json $HOME/.reserved/validator2/config/genesis.json +cp $HOME/.reserved/validator1/config/genesis.json $HOME/.reserved/validator3/config/genesis.json + +# copy tendermint node id of validator1 to persistent peers of validator2-3 +node1=$(reserved tendermint show-node-id --home=$HOME/.reserved/validator1) +node2=$(reserved tendermint show-node-id --home=$HOME/.reserved/validator2) +node3=$(reserved tendermint show-node-id --home=$HOME/.reserved/validator3) +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.reserved/validator1/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.reserved/validator2/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.reserved/validator3/config/config.toml + + +# # start all three validators +screen -S onomy1 -t onomy1 -d -m reserved start --home=$HOME/.reserved/validator1 +screen -S onomy2 -t onomy2 -d -m reserved start --home=$HOME/.reserved/validator2 +screen -S onomy3 -t onomy3 -d -m reserved start --home=$HOME/.reserved/validator3 + +# submit proposal add usdt +sleep 7 +reserved q gov proposals +# reserved tx gov submit-legacy-proposal active-collateral "title" "description" "atom" "10" "0.1" "10000" 10000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator1 --from validator1 -y --chain-id testing-1 --fees 20stake + +reserved tx gov submit-proposal ./script/proposal-1.json --home=$HOME/.reserved/validator1 --from validator1 --keyring-backend test --fees 20stake --chain-id testing-1 -y + +# # vote +sleep 7 +reserved tx gov vote 1 yes --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake +reserved tx gov vote 1 yes --from validator2 --keyring-backend test --home ~/.reserved/validator2 --chain-id testing-1 -y --fees 20stake +reserved tx gov vote 1 yes --from validator3 --keyring-backend test --home ~/.reserved/validator3 --chain-id testing-1 -y --fees 20stake + +# wait voting_perio=15s +echo "========sleep==========" +sleep 15 +reserved q gov proposals + +killall reserved || true \ No newline at end of file diff --git a/x/vaults/keeper/keeper.go b/x/vaults/keeper/keeper.go index a83e0891..d3b508f6 100644 --- a/x/vaults/keeper/keeper.go +++ b/x/vaults/keeper/keeper.go @@ -7,8 +7,8 @@ import ( "cosmossdk.io/collections" storetypes "cosmossdk.io/core/store" "cosmossdk.io/math" - "github.com/onomyprotocol/reserve/x/vaults/types" oraclekeeper "github.com/onomyprotocol/reserve/x/oracle/keeper" + "github.com/onomyprotocol/reserve/x/vaults/types" "github.com/cosmos/cosmos-sdk/codec" ) diff --git a/x/vaults/keeper/msg_server.go b/x/vaults/keeper/msg_server.go index 1ac6203f..1b0a5f2d 100644 --- a/x/vaults/keeper/msg_server.go +++ b/x/vaults/keeper/msg_server.go @@ -34,6 +34,10 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam } func (k msgServer) ActiveCollateral(ctx context.Context, msg *types.MsgActiveCollateral) (*types.MsgActiveCollateralResponse, error) { + if k.authority != msg.Authority { + return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority) + } + err := k.ActiveCollateralAsset(ctx, msg.Denom, msg.MinCollateralRatio, msg.LiquidationRatio, msg.MaxDebt) if err != nil { return nil, err diff --git a/x/vaults/module/proposal_handle.go b/x/vaults/module/proposal_handle.go new file mode 100644 index 00000000..cbf82049 --- /dev/null +++ b/x/vaults/module/proposal_handle.go @@ -0,0 +1,23 @@ +package vaults + +import ( + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + "github.com/onomyprotocol/reserve/x/vaults/keeper" + "github.com/onomyprotocol/reserve/x/vaults/types" +) + +func NewVaultsProposalHandler(k *keeper.Keeper) govtypes.Handler { + return func(ctx sdk.Context, content govtypes.Content) error { + switch c := content.(type) { + case *types.MsgActiveCollateral: + return k.ActiveCollateralAsset(ctx, c.Denom, c.MinCollateralRatio, c.LiquidationRatio, c.MaxDebt) + default: + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) + } + } +} diff --git a/x/vaults/types/codec.go b/x/vaults/types/codec.go index 85e226fb..9e11c73f 100644 --- a/x/vaults/types/codec.go +++ b/x/vaults/types/codec.go @@ -4,7 +4,7 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - // this line is used by starport scaffolding # 1 + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -20,4 +20,10 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgRepay{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) + + registry.RegisterImplementations( + (*govtypes.Content)(nil), + &MsgActiveCollateral{}, + ) + } diff --git a/x/vaults/types/errors.go b/x/vaults/types/errors.go index ebf7cc05..b41135bd 100644 --- a/x/vaults/types/errors.go +++ b/x/vaults/types/errors.go @@ -8,5 +8,6 @@ import ( // x/vaults module sentinel errors var ( - ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidActiveCollateralProposal = sdkerrors.Register(ModuleName, 2, "invalid active collateral proposal") ) diff --git a/x/vaults/types/keys.go b/x/vaults/types/keys.go index 6b0a95c4..d1a4b04c 100644 --- a/x/vaults/types/keys.go +++ b/x/vaults/types/keys.go @@ -3,12 +3,13 @@ package types import "cosmossdk.io/collections" const ( - ModuleName = "vaults" + ModuleName = "vaults" // StoreKey is the string store representation StoreKey = ModuleName - + ReserveModuleName = "reserve" + RouterKey = ModuleName ) var ( diff --git a/x/vaults/types/msgs.go b/x/vaults/types/msgs.go index 4f58f10a..3466c5e6 100644 --- a/x/vaults/types/msgs.go +++ b/x/vaults/types/msgs.go @@ -1,6 +1,51 @@ package types +import ( + sdkerrors "cosmossdk.io/errors" + "cosmossdk.io/math" +) + var ( Query_serviceDesc = _Query_serviceDesc Msg_serviceDesc = _Msg_serviceDesc ) + +const ( + ProposalTypeActiveCollateral string = "MsgActiveCollateral" +) + +func (m *MsgActiveCollateral) GetDescription() string { + return " " +} + +func (m *MsgActiveCollateral) GetTitle() string { + return " " +} + +func (m *MsgActiveCollateral) ProposalRoute() string { + return RouterKey +} + +func (m *MsgActiveCollateral) ProposalType() string { + return ProposalTypeActiveCollateral +} + +func (a *MsgActiveCollateral) ValidateBasic() error { + if a.Denom == "" { + return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "empty denom") + } + + if a.MinCollateralRatio.LT(math.LegacyZeroDec()) { + return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "less than zero") + } + + if a.LiquidationRatio.LT(math.LegacyZeroDec()) { + return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "less than zero") + } + + if a.MaxDebt.LT(math.ZeroInt()) { + return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "less than zero") + } + + return nil +} From ffcfe5c9a8b8c21b1143c0380da35762f3faaee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Mon, 30 Sep 2024 17:31:40 +0700 Subject: [PATCH 2/5] updates --- x/vaults/module/module.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/vaults/module/module.go b/x/vaults/module/module.go index 3bf005d0..817ec7c1 100644 --- a/x/vaults/module/module.go +++ b/x/vaults/module/module.go @@ -17,7 +17,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - // govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" abci "github.com/cometbft/cometbft/abci/types" @@ -28,10 +28,10 @@ import ( "cosmossdk.io/core/appmodule" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/onomyprotocol/reserve/x/vaults/keeper" + modulev1 "github.com/onomyprotocol/reserve/api/reserve/vaults/module" oraclekeeper "github.com/onomyprotocol/reserve/x/oracle/keeper" + "github.com/onomyprotocol/reserve/x/vaults/keeper" "github.com/onomyprotocol/reserve/x/vaults/types" - modulev1 "github.com/onomyprotocol/reserve/api/reserve/vaults/module" ) const consensusVersion uint64 = 1 @@ -175,9 +175,9 @@ type ModuleInputs struct { type ModuleOutputs struct { depinject.Out - PsmKeeper keeper.Keeper - Module appmodule.AppModule - // GovHandler govv1beta1.HandlerRoute + PsmKeeper keeper.Keeper + Module appmodule.AppModule + GovHandler govv1beta1.HandlerRoute } func ProvideModule(in ModuleInputs) ModuleOutputs { @@ -203,7 +203,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.BankKeeper, ) - // govHandler := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewStablecoinProposalHandler(&k)} + govHandler := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewVaultsProposalHandler(k)} - return ModuleOutputs{PsmKeeper: *k, Module: m} //GovHandler: govHandler} + return ModuleOutputs{PsmKeeper: *k, Module: m, GovHandler: govHandler} } From eeb0b708cec51f45461718ea4b0275d7629338d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Tue, 1 Oct 2024 11:10:06 +0700 Subject: [PATCH 3/5] use proto type proposal --- proto/reserve/vaults/proposal.proto | 21 ++ x/vaults/module/proposal_handle.go | 4 +- x/vaults/types/codec.go | 8 +- x/vaults/types/msgs.go | 15 +- x/vaults/types/proposal.pb.go | 410 ++++++++++++++++++++++++++++ 5 files changed, 448 insertions(+), 10 deletions(-) create mode 100644 proto/reserve/vaults/proposal.proto create mode 100644 x/vaults/types/proposal.pb.go diff --git a/proto/reserve/vaults/proposal.proto b/proto/reserve/vaults/proposal.proto new file mode 100644 index 00000000..9d8c8812 --- /dev/null +++ b/proto/reserve/vaults/proposal.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package reserve.vaults; + +import "gogoproto/gogo.proto"; +import "reserve/vaults/tx.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; + + +option go_package = "github.com/onomyprotocol/reserve/x/vaults/types"; + + +message ActiveCollateralProposal { + option (gogoproto.goproto_getters) = false; + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + option (amino.name) = "reserve/ActiveCollateralProposal"; + + string title = 1; + string description = 2; + MsgActiveCollateral active_collateral = 3 [(gogoproto.nullable) = false]; +} diff --git a/x/vaults/module/proposal_handle.go b/x/vaults/module/proposal_handle.go index cbf82049..2b6a1d56 100644 --- a/x/vaults/module/proposal_handle.go +++ b/x/vaults/module/proposal_handle.go @@ -14,8 +14,8 @@ import ( func NewVaultsProposalHandler(k *keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { - case *types.MsgActiveCollateral: - return k.ActiveCollateralAsset(ctx, c.Denom, c.MinCollateralRatio, c.LiquidationRatio, c.MaxDebt) + case *types.ActiveCollateralProposal: + return k.ActiveCollateralAsset(ctx, c.ActiveCollateral.Denom, c.ActiveCollateral.MinCollateralRatio, c.ActiveCollateral.LiquidationRatio, c.ActiveCollateral.MaxDebt) default: return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) } diff --git a/x/vaults/types/codec.go b/x/vaults/types/codec.go index 9e11c73f..31adfa84 100644 --- a/x/vaults/types/codec.go +++ b/x/vaults/types/codec.go @@ -1,12 +1,18 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) +// RegisterLegacyAminoCodec registers all necessary param module types with a given LegacyAmino codec. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&ActiveCollateralProposal{}, "reserve/ActiveCollateralProposal", nil) +} + func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 @@ -23,7 +29,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations( (*govtypes.Content)(nil), - &MsgActiveCollateral{}, + &ActiveCollateralProposal{}, ) } diff --git a/x/vaults/types/msgs.go b/x/vaults/types/msgs.go index 3466c5e6..6214e675 100644 --- a/x/vaults/types/msgs.go +++ b/x/vaults/types/msgs.go @@ -11,26 +11,27 @@ var ( ) const ( - ProposalTypeActiveCollateral string = "MsgActiveCollateral" + ProposalTypeActiveCollateralProposal string = "ActiveCollateralProposal" ) -func (m *MsgActiveCollateral) GetDescription() string { +func (m *ActiveCollateralProposal) GetDescription() string { return " " } -func (m *MsgActiveCollateral) GetTitle() string { +func (m *ActiveCollateralProposal) GetTitle() string { return " " } -func (m *MsgActiveCollateral) ProposalRoute() string { +func (m *ActiveCollateralProposal) ProposalRoute() string { return RouterKey } -func (m *MsgActiveCollateral) ProposalType() string { - return ProposalTypeActiveCollateral +func (m *ActiveCollateralProposal) ProposalType() string { + return ProposalTypeActiveCollateralProposal } -func (a *MsgActiveCollateral) ValidateBasic() error { +func (m *ActiveCollateralProposal) ValidateBasic() error { + a := m.ActiveCollateral if a.Denom == "" { return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "empty denom") } diff --git a/x/vaults/types/proposal.pb.go b/x/vaults/types/proposal.pb.go new file mode 100644 index 00000000..e69ec93d --- /dev/null +++ b/x/vaults/types/proposal.pb.go @@ -0,0 +1,410 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: reserve/vaults/proposal.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ActiveCollateralProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + ActiveCollateral MsgActiveCollateral `protobuf:"bytes,3,opt,name=active_collateral,json=activeCollateral,proto3" json:"active_collateral"` +} + +func (m *ActiveCollateralProposal) Reset() { *m = ActiveCollateralProposal{} } +func (m *ActiveCollateralProposal) String() string { return proto.CompactTextString(m) } +func (*ActiveCollateralProposal) ProtoMessage() {} +func (*ActiveCollateralProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_784ca0e6565c75e5, []int{0} +} +func (m *ActiveCollateralProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ActiveCollateralProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ActiveCollateralProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ActiveCollateralProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_ActiveCollateralProposal.Merge(m, src) +} +func (m *ActiveCollateralProposal) XXX_Size() int { + return m.Size() +} +func (m *ActiveCollateralProposal) XXX_DiscardUnknown() { + xxx_messageInfo_ActiveCollateralProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_ActiveCollateralProposal proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ActiveCollateralProposal)(nil), "reserve.vaults.ActiveCollateralProposal") +} + +func init() { proto.RegisterFile("reserve/vaults/proposal.proto", fileDescriptor_784ca0e6565c75e5) } + +var fileDescriptor_784ca0e6565c75e5 = []byte{ + // 318 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x4a, 0x2d, 0x4e, + 0x2d, 0x2a, 0x4b, 0xd5, 0x2f, 0x4b, 0x2c, 0xcd, 0x29, 0x29, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc8, + 0x2f, 0x4e, 0xcc, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0x4a, 0xeb, 0x41, 0xa4, + 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0x95, 0x94, 0x38, 0x9a, + 0x21, 0x25, 0x15, 0x50, 0x09, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x15, 0x92, + 0x4c, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, 0x87, 0x18, 0x02, 0xe1, 0x40, 0xa4, 0x94, 0x3e, 0x33, + 0x72, 0x49, 0x38, 0x26, 0x97, 0x64, 0x96, 0xa5, 0x3a, 0xe7, 0xe7, 0xe4, 0x24, 0x96, 0xa4, 0x16, + 0x25, 0xe6, 0x04, 0x40, 0xdd, 0x23, 0x24, 0xc2, 0xc5, 0x5a, 0x92, 0x59, 0x92, 0x93, 0x2a, 0xc1, + 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0xe1, 0x08, 0x29, 0x70, 0x71, 0xa7, 0xa4, 0x16, 0x27, 0x17, + 0x65, 0x16, 0x94, 0x64, 0xe6, 0xe7, 0x49, 0x30, 0x81, 0xe5, 0x90, 0x85, 0x84, 0xc2, 0xb8, 0x04, + 0x13, 0xc1, 0x66, 0xc6, 0x27, 0xc3, 0x0d, 0x95, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd6, + 0x43, 0xf5, 0x9d, 0x9e, 0x6f, 0x71, 0x3a, 0xba, 0xfd, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, + 0x09, 0x24, 0xa2, 0x89, 0x5b, 0xb9, 0x77, 0x2c, 0x90, 0x67, 0x38, 0xb5, 0x45, 0x57, 0x0a, 0xea, + 0x85, 0xf4, 0xfc, 0x32, 0xbd, 0x32, 0xc3, 0xa4, 0xd4, 0x92, 0x44, 0x43, 0x3d, 0xe7, 0xfc, 0xbc, + 0x92, 0xd4, 0xbc, 0x92, 0xae, 0xe7, 0x1b, 0xb4, 0x14, 0x60, 0x41, 0x83, 0xcb, 0x63, 0x4e, 0x9e, + 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, + 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, + 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9f, 0x97, 0x9f, 0x5b, 0x09, 0x0e, 0xa6, 0xe4, 0xfc, + 0x1c, 0x7d, 0x98, 0xa1, 0x15, 0xf0, 0x10, 0xaf, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x2b, 0x30, + 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x54, 0xfa, 0x07, 0x31, 0xd5, 0x01, 0x00, 0x00, +} + +func (m *ActiveCollateralProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ActiveCollateralProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ActiveCollateralProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ActiveCollateral.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { + offset -= sovProposal(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ActiveCollateralProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = m.ActiveCollateral.Size() + n += 1 + l + sovProposal(uint64(l)) + return n +} + +func sovProposal(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozProposal(x uint64) (n int) { + return sovProposal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ActiveCollateralProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ActiveCollateralProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ActiveCollateralProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ActiveCollateral", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ActiveCollateral.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipProposal(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProposal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProposal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProposal + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthProposal + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupProposal + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthProposal + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthProposal = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowProposal = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupProposal = fmt.Errorf("proto: unexpected end of group") +) From ef6455d4fd0428d52c74b5cc4d2aa57564ce24fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Fri, 4 Oct 2024 12:10:41 +0700 Subject: [PATCH 4/5] add gov updates Collateral --- proto/reserve/vaults/proposal.proto | 10 ++ x/vaults/module/proposal_handle.go | 2 + x/vaults/types/codec.go | 2 + x/vaults/types/errors.go | 5 +- x/vaults/types/msgs.go | 40 ++++- x/vaults/types/proposal.pb.go | 270 +++++++++++++++++++++++++++- 6 files changed, 319 insertions(+), 10 deletions(-) diff --git a/proto/reserve/vaults/proposal.proto b/proto/reserve/vaults/proposal.proto index 9d8c8812..b1d0289d 100644 --- a/proto/reserve/vaults/proposal.proto +++ b/proto/reserve/vaults/proposal.proto @@ -19,3 +19,13 @@ message ActiveCollateralProposal { string description = 2; MsgActiveCollateral active_collateral = 3 [(gogoproto.nullable) = false]; } + +message UpdatesCollateralProposal { + option (gogoproto.goproto_getters) = false; + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + option (amino.name) = "reserve/UpdatesCollateralProposal"; + + string title = 1; + string description = 2; + MsgUpdatesCollateral updates_collateral = 3 [(gogoproto.nullable) = false]; +} diff --git a/x/vaults/module/proposal_handle.go b/x/vaults/module/proposal_handle.go index 2b6a1d56..b5cf877b 100644 --- a/x/vaults/module/proposal_handle.go +++ b/x/vaults/module/proposal_handle.go @@ -16,6 +16,8 @@ func NewVaultsProposalHandler(k *keeper.Keeper) govtypes.Handler { switch c := content.(type) { case *types.ActiveCollateralProposal: return k.ActiveCollateralAsset(ctx, c.ActiveCollateral.Denom, c.ActiveCollateral.MinCollateralRatio, c.ActiveCollateral.LiquidationRatio, c.ActiveCollateral.MaxDebt) + case *types.UpdatesCollateralProposal: + return k.UpdatesCollateralAsset(ctx, c.UpdatesCollateral.Denom, c.UpdatesCollateral.MinCollateralRatio, c.UpdatesCollateral.LiquidationRatio, c.UpdatesCollateral.MaxDebt) default: return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) } diff --git a/x/vaults/types/codec.go b/x/vaults/types/codec.go index 8416a390..b4e7a346 100644 --- a/x/vaults/types/codec.go +++ b/x/vaults/types/codec.go @@ -11,6 +11,7 @@ import ( // RegisterLegacyAminoCodec registers all necessary param module types with a given LegacyAmino codec. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&ActiveCollateralProposal{}, "reserve/ActiveCollateralProposal", nil) + cdc.RegisterConcrete(&UpdatesCollateralProposal{}, "reserve/UpdatesCollateralProposal", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -31,6 +32,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations( (*govtypes.Content)(nil), &ActiveCollateralProposal{}, + &UpdatesCollateralProposal{}, ) } diff --git a/x/vaults/types/errors.go b/x/vaults/types/errors.go index b41135bd..046d86b2 100644 --- a/x/vaults/types/errors.go +++ b/x/vaults/types/errors.go @@ -8,6 +8,7 @@ import ( // x/vaults module sentinel errors var ( - ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") - ErrInvalidActiveCollateralProposal = sdkerrors.Register(ModuleName, 2, "invalid active collateral proposal") + ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidActiveCollateralProposal = sdkerrors.Register(ModuleName, 2, "invalid active collateral proposal") + ErrInvalidUpdatesCollateralProposal = sdkerrors.Register(ModuleName, 3, "invalid updates collateral proposal") ) diff --git a/x/vaults/types/msgs.go b/x/vaults/types/msgs.go index a577129f..1c8d2453 100644 --- a/x/vaults/types/msgs.go +++ b/x/vaults/types/msgs.go @@ -7,7 +7,8 @@ import ( ) const ( - ProposalTypeActiveCollateralProposal string = "ActiveCollateralProposal" + ProposalTypeActiveCollateralProposal string = "ActiveCollateralProposal" + ProposalTypeUpdatesCollateralProposal string = "UpdatesCollateralProposal" ) var ( @@ -98,3 +99,40 @@ func (m *ActiveCollateralProposal) ValidateBasic() error { return nil } + +func (m *UpdatesCollateralProposal) GetDescription() string { + return " " +} + +func (m *UpdatesCollateralProposal) GetTitle() string { + return " " +} + +func (m *UpdatesCollateralProposal) ProposalRoute() string { + return RouterKey +} + +func (m *UpdatesCollateralProposal) ProposalType() string { + return ProposalTypeActiveCollateralProposal +} + +func (m *UpdatesCollateralProposal) ValidateBasic() error { + a := m.UpdatesCollateral + if a.Denom == "" { + return sdkerrors.Wrap(ErrInvalidUpdatesCollateralProposal, "empty denom") + } + + if a.MinCollateralRatio.LT(math.LegacyZeroDec()) { + return sdkerrors.Wrap(ErrInvalidUpdatesCollateralProposal, "less than zero") + } + + if a.LiquidationRatio.LT(math.LegacyZeroDec()) { + return sdkerrors.Wrap(ErrInvalidUpdatesCollateralProposal, "less than zero") + } + + if a.MaxDebt.LT(math.ZeroInt()) { + return sdkerrors.Wrap(ErrInvalidUpdatesCollateralProposal, "less than zero") + } + + return nil +} diff --git a/x/vaults/types/proposal.pb.go b/x/vaults/types/proposal.pb.go index e69ec93d..723b7060 100644 --- a/x/vaults/types/proposal.pb.go +++ b/x/vaults/types/proposal.pb.go @@ -64,14 +64,54 @@ func (m *ActiveCollateralProposal) XXX_DiscardUnknown() { var xxx_messageInfo_ActiveCollateralProposal proto.InternalMessageInfo +type UpdatesCollateralProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + UpdatesCollateral MsgUpdatesCollateral `protobuf:"bytes,3,opt,name=updates_collateral,json=updatesCollateral,proto3" json:"updates_collateral"` +} + +func (m *UpdatesCollateralProposal) Reset() { *m = UpdatesCollateralProposal{} } +func (m *UpdatesCollateralProposal) String() string { return proto.CompactTextString(m) } +func (*UpdatesCollateralProposal) ProtoMessage() {} +func (*UpdatesCollateralProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_784ca0e6565c75e5, []int{1} +} +func (m *UpdatesCollateralProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UpdatesCollateralProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UpdatesCollateralProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UpdatesCollateralProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdatesCollateralProposal.Merge(m, src) +} +func (m *UpdatesCollateralProposal) XXX_Size() int { + return m.Size() +} +func (m *UpdatesCollateralProposal) XXX_DiscardUnknown() { + xxx_messageInfo_UpdatesCollateralProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdatesCollateralProposal proto.InternalMessageInfo + func init() { proto.RegisterType((*ActiveCollateralProposal)(nil), "reserve.vaults.ActiveCollateralProposal") + proto.RegisterType((*UpdatesCollateralProposal)(nil), "reserve.vaults.UpdatesCollateralProposal") } func init() { proto.RegisterFile("reserve/vaults/proposal.proto", fileDescriptor_784ca0e6565c75e5) } var fileDescriptor_784ca0e6565c75e5 = []byte{ - // 318 bytes of a gzipped FileDescriptorProto + // 364 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x4a, 0x2d, 0x4e, 0x2d, 0x2a, 0x4b, 0xd5, 0x2f, 0x4b, 0x2c, 0xcd, 0x29, 0x29, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc8, 0x2f, 0x4e, 0xcc, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0x4a, 0xeb, 0x41, 0xa4, @@ -86,12 +126,15 @@ var fileDescriptor_784ca0e6565c75e5 = []byte{ 0x43, 0xf5, 0x9d, 0x9e, 0x6f, 0x71, 0x3a, 0xba, 0xfd, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x09, 0x24, 0xa2, 0x89, 0x5b, 0xb9, 0x77, 0x2c, 0x90, 0x67, 0x38, 0xb5, 0x45, 0x57, 0x0a, 0xea, 0x85, 0xf4, 0xfc, 0x32, 0xbd, 0x32, 0xc3, 0xa4, 0xd4, 0x92, 0x44, 0x43, 0x3d, 0xe7, 0xfc, 0xbc, - 0x92, 0xd4, 0xbc, 0x92, 0xae, 0xe7, 0x1b, 0xb4, 0x14, 0x60, 0x41, 0x83, 0xcb, 0x63, 0x4e, 0x9e, - 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, - 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, - 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9f, 0x97, 0x9f, 0x5b, 0x09, 0x0e, 0xa6, 0xe4, 0xfc, - 0x1c, 0x7d, 0x98, 0xa1, 0x15, 0xf0, 0x10, 0xaf, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x2b, 0x30, - 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x54, 0xfa, 0x07, 0x31, 0xd5, 0x01, 0x00, 0x00, + 0x92, 0xd4, 0xbc, 0x92, 0xae, 0xe7, 0x1b, 0xb4, 0x14, 0x60, 0x41, 0x83, 0xcb, 0x63, 0x4a, 0x3f, + 0x18, 0xb9, 0x24, 0x43, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0x8b, 0xa9, 0xe8, 0xed, 0x48, 0x2e, 0xa1, + 0x52, 0x88, 0xa1, 0x98, 0xfe, 0x56, 0xc1, 0xe2, 0x6f, 0x0c, 0x17, 0x40, 0x3d, 0x2e, 0x58, 0x8a, + 0x2e, 0x61, 0xe5, 0x41, 0x9c, 0xcf, 0x15, 0x61, 0x3e, 0xc7, 0xe9, 0x39, 0x27, 0xcf, 0x13, 0x8f, + 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, + 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xd2, 0x4f, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, + 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0xcf, 0xcb, 0xcf, 0xad, 0x04, 0xa7, 0x90, 0xe4, 0xfc, 0x1c, 0x7d, + 0x98, 0xa9, 0x15, 0xf0, 0xc4, 0x56, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x56, 0x60, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0x62, 0xbd, 0x9e, 0x9d, 0xd0, 0x02, 0x00, 0x00, } func (m *ActiveCollateralProposal) Marshal() (dAtA []byte, err error) { @@ -141,6 +184,53 @@ func (m *ActiveCollateralProposal) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *UpdatesCollateralProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UpdatesCollateralProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UpdatesCollateralProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.UpdatesCollateral.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { offset -= sovProposal(v) base := offset @@ -171,6 +261,25 @@ func (m *ActiveCollateralProposal) Size() (n int) { return n } +func (m *UpdatesCollateralProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = m.UpdatesCollateral.Size() + n += 1 + l + sovProposal(uint64(l)) + return n +} + func sovProposal(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -324,6 +433,153 @@ func (m *ActiveCollateralProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *UpdatesCollateralProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UpdatesCollateralProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UpdatesCollateralProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatesCollateral", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.UpdatesCollateral.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipProposal(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From eaaceaccf5adab5b86f5b8a0d267f1c78e05bf15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Fri, 4 Oct 2024 12:18:07 +0700 Subject: [PATCH 5/5] add AddNewSymbolToBandOracleRequest --- x/oracle/keeper/keeper.go | 6 ++++++ x/vaults/keeper/keeper.go | 5 +++++ x/vaults/keeper/mock/oracle_keeper.go | 4 ++++ x/vaults/types/expected_keepers.go | 1 + 4 files changed, 16 insertions(+) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index d49be157..d12398f5 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -135,6 +135,12 @@ func (k *Keeper) ScopedKeeper() exported.ScopedKeeper { return k.scopedKeeper } +// need to delete when merging with oracle func (k *Keeper) GetPrice(ctx context.Context, denom string) math.LegacyDec { return math.LegacyZeroDec() } + +// need to delete when merging with oracle +func (k *Keeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error { + return nil +} diff --git a/x/vaults/keeper/keeper.go b/x/vaults/keeper/keeper.go index 667eb86c..69b95961 100644 --- a/x/vaults/keeper/keeper.go +++ b/x/vaults/keeper/keeper.go @@ -89,6 +89,11 @@ func (k *Keeper) ActiveCollateralAsset( }, MintAvailable: maxDebt, } + err := k.OracleKeeper.AddNewSymbolToBandOracleRequest(ctx, denom, 1) + if err != nil { + return err + } + return k.VaultsManager.Set(ctx, denom, vm) } diff --git a/x/vaults/keeper/mock/oracle_keeper.go b/x/vaults/keeper/mock/oracle_keeper.go index b2996120..41ec7b65 100644 --- a/x/vaults/keeper/mock/oracle_keeper.go +++ b/x/vaults/keeper/mock/oracle_keeper.go @@ -23,3 +23,7 @@ func (s *MockOracleKeeper) GetPrice(ctx context.Context, denom string) math.Lega func (s *MockOracleKeeper) SetPrice(denom string, price math.LegacyDec) { s.prices[denom] = price } + +func (s *MockOracleKeeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error { + return nil +} diff --git a/x/vaults/types/expected_keepers.go b/x/vaults/types/expected_keepers.go index 8cb6e047..d319bb9f 100644 --- a/x/vaults/types/expected_keepers.go +++ b/x/vaults/types/expected_keepers.go @@ -30,4 +30,5 @@ type BankKeeper interface { type OracleKeeper interface { GetPrice(ctx context.Context, denom string) math.LegacyDec + AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error }