Skip to content

Commit

Permalink
resolve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
duonghb53 committed Nov 29, 2024
1 parent 71143d8 commit d26e250
Show file tree
Hide file tree
Showing 44 changed files with 518 additions and 532 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ import (
v8_1 "github.com/classic-terra/core/v3/app/upgrades/v8_1"
v8_2 "github.com/classic-terra/core/v3/app/upgrades/v8_2"
v8_3 "github.com/classic-terra/core/v3/app/upgrades/v8_3"
v8_4 "github.com/classic-terra/core/v3/app/upgrades/v8_4"

// v9 had been used by tax2gas and has to be skipped
v10 "github.com/classic-terra/core/v3/app/upgrades/v10"
v10_1 "github.com/classic-terra/core/v3/app/upgrades/v10_1"

customante "github.com/classic-terra/core/v3/custom/auth/ante"
custompost "github.com/classic-terra/core/v3/custom/auth/post"
Expand Down Expand Up @@ -95,7 +95,7 @@ var (
v8_1.Upgrade,
v8_2.Upgrade,
v8_3.Upgrade,
v8_4.Upgrade,
v10_1.Upgrade,
v10.Upgrade,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//nolint:revive
package v8_4
package v10_1

import (
"github.com/classic-terra/core/v3/app/upgrades"
)

const UpgradeName = "v8_4"
const UpgradeName = "v10_1"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV84UpgradeHandler,
CreateUpgradeHandler: CreateV101UpgradeHandler,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//nolint:revive
package v8_4
package v10_1

import (
"github.com/classic-terra/core/v3/app/keepers"
Expand All @@ -9,7 +9,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateV84UpgradeHandler(
func CreateV101UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
Expand Down
4 changes: 2 additions & 2 deletions cmd/terrad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path/filepath"
"time"

govv2lunc1 "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
govv2custom "github.com/classic-terra/core/v3/custom/gov/types/v2custom"
tmconfig "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
Expand Down Expand Up @@ -309,7 +309,7 @@ func initGenFiles(
appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState)

// set gov in the genesis state
var govGenState govv2lunc1.GenesisState
var govGenState govv2custom.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)
votingPeriod := time.Minute * 3
govGenState.Params.VotingPeriod = &votingPeriod
Expand Down
6 changes: 3 additions & 3 deletions custom/auth/ante/min_initial_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper custom
}
// set offset price change 3%
offsetPrice := sdk.NewDecWithPrec(97, 2)
minLuncAmount, err := govKeeper.GetMinimumDepositBaseUusd(ctx)
minUlunaAmount, err := govKeeper.GetMinimumDepositBaseUstc(ctx)
minInitialDepositRatio := treasuryKeeper.GetMinInitialDepositRatio(ctx)
if err == nil && minLuncAmount.GT(sdk.ZeroInt()) {
requiredDeposit := sdk.NewDecFromInt(minLuncAmount).Mul(minInitialDepositRatio).Mul(offsetPrice).TruncateInt()
if err == nil && minUlunaAmount.GT(sdk.ZeroInt()) {
requiredDeposit := sdk.NewDecFromInt(minUlunaAmount).Mul(minInitialDepositRatio).Mul(offsetPrice).TruncateInt()
requiredDepositCoins := sdk.NewCoins(sdk.NewCoin(core.MicroLunaDenom, requiredDeposit))
if initialDepositCoins.IsAllLT(requiredDepositCoins) {
return fmt.Errorf("not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
Expand Down
20 changes: 10 additions & 10 deletions custom/auth/ante/min_initial_deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/classic-terra/core/v3/custom/auth/ante"
govv2lunc1 "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
govv2custom "github.com/classic-terra/core/v3/custom/gov/types/v2custom"
core "github.com/classic-terra/core/v3/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand All @@ -25,13 +25,13 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioDefault() {
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2custom.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())
price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUstc(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUstc %s", price.String())

// set initial deposit ratio to 0.0
ratio := sdk.ZeroDec()
Expand Down Expand Up @@ -85,13 +85,13 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioWithSufficientDeposit() {
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2custom.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())
price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUstc(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUstc %s", price.String())

// set initial deposit ratio to 0.2
ratio := sdk.NewDecWithPrec(2, 1)
Expand Down Expand Up @@ -151,13 +151,13 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioWithInsufficientDeposit()
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2custom.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())
price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUstc(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUstc %s", price.String())

// set initial deposit ratio to 0.2
ratio := sdk.NewDecWithPrec(2, 1)
Expand Down
2 changes: 1 addition & 1 deletion custom/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/x/distribution/types"

govtypes "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
govtypes "github.com/classic-terra/core/v3/custom/gov/types/v2custom"
)

// RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types
Expand Down
18 changes: 9 additions & 9 deletions custom/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ module uses the `MsgServiceRouter` to check that these messages are correctly co
and have a respective path to execute on but do not perform a full validity check.
### Deposit

To prevent spam, proposals must be submitted with a deposit in the coins defined by the equation `luncMinDepositAmountBasedOnUusd` = `MinUusdDeposit` / real-time price of LUNC at the time of proposal submission.
To prevent spam, proposals must be submitted with a deposit in the coins defined by the equation `luncMinDepositAmountBasedOnUstc` = `MinUusdDeposit` / real-time price of LUNC at the time of proposal submission.
```keeper reference
github.com/classic-terra/core/v3/custom/gov/keeper/proposal.go#L136-L149
```
The value of `luncMinDepositAmountBasedOnUusd` will be stored in KVStores, using a key defined as `UUSDMinKeyPrefix|proposalID`, where the proposal ID is appended to the prefix, represented as a single byte.
The value of `luncMinDepositAmountBasedOnUstc` will be stored in KVStores, using a key defined as `USTCMinKeyPrefix|proposalID`, where the proposal ID is appended to the prefix, represented as a single byte.
```types reference
github.com/classic-terra/core/v3/custom/gov/types/keys.go#L20-L22
```

When a proposal is submitted, it has to be accompanied with a deposit that must be
strictly positive, but can be inferior to `luncMinDepositAmountBasedOnUusd`. The submitter doesn't need
strictly positive, but can be inferior to `luncMinDepositAmountBasedOnUstc`. The submitter doesn't need
to pay for the entire deposit on their own. The newly created proposal is stored in
an *inactive proposal queue* and stays there until its deposit passes the `luncMinDepositAmountBasedOnUusd`.
an *inactive proposal queue* and stays there until its deposit passes the `luncMinDepositAmountBasedOnUstc`.
Other token holders can increase the proposal's deposit by sending a `Deposit`
transaction. If a proposal doesn't pass the `luncMinDepositAmountBasedOnUusd` before the deposit end time
transaction. If a proposal doesn't pass the `luncMinDepositAmountBasedOnUstc` before the deposit end time
(the time when deposits are no longer accepted), the proposal will be destroyed: the
proposal will be removed from state and the deposit will be burned (see x/gov `EndBlocker`).
When a proposal deposit passes the `luncMinDepositAmountBasedOnUusd` threshold (even during the proposal
When a proposal deposit passes the `luncMinDepositAmountBasedOnUstc` threshold (even during the proposal
submission) before the deposit end time, the proposal will be moved into the
*active proposal queue* and the voting period will begin.

Expand All @@ -73,7 +73,7 @@ according to the final tally of the proposal:

#### Voting period

Once a proposal reaches `luncMinDepositAmountBasedOnUusd`, it immediately enters `Voting period`. We
Once a proposal reaches `luncMinDepositAmountBasedOnUstc`, it immediately enters `Voting period`. We
define `Voting period` as the interval between the moment the vote opens and
the moment the vote closes. `Voting period` should always be shorter than
`Unbonding period` to prevent double voting. The initial value of
Expand All @@ -94,7 +94,7 @@ We will use one KVStore `Governance` to store five mappings:
x/gov params.
* A mapping from `VotingPeriodProposalKeyPrefix|proposalID` to a single byte. This allows
us to know if a proposal is in the voting period or not with very low gas cost.
* A mapping from `UUSDMinKeyPrefix|proposalID` to a single byte. This allows us to determine the minimum amount of LUNC that a specific proposal must deposit to pass the deposit phase.
* A mapping from `USTCMinKeyPrefix|proposalID` to a single byte. This allows us to determine the minimum amount of LUNC that a specific proposal must deposit to pass the deposit phase.

For pseudocode purposes, here are the two function we will use to read or write in stores:

Expand Down Expand Up @@ -128,7 +128,7 @@ A user can query and interact with the `gov` module using the CLI.
We have added two new commands

##### MinimalDeposit
The `MinimalDeposit` command enables users to query the minimum LUNC deposit required for a specific proposal, calculated based on the UUSD value.
The `MinimalDeposit` command enables users to query the minimum LUNC deposit required for a specific proposal, calculated based on the USTC value.


```bash
Expand Down
12 changes: 6 additions & 6 deletions custom/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

v2lunc1types "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
v2customtypes "github.com/classic-terra/core/v3/custom/gov/types/v2custom"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -65,7 +65,7 @@ $ %s query gov min-deposit 1
if err != nil {
return err
}
queryClient := v2lunc1types.NewQueryClient(clientCtx)
queryClient := v2customtypes.NewQueryClient(clientCtx)

// validate that the proposal id is a uint
proposalID, err := strconv.ParseUint(args[0], 10, 64)
Expand All @@ -74,9 +74,9 @@ $ %s query gov min-deposit 1
}

// Query the proposal
res, err := queryClient.ProposalMinimalLUNCByUusd(
res, err := queryClient.ProposalMinimalLUNCByUstc(
cmd.Context(),
&v2lunc1types.QueryProposalRequest{ProposalId: proposalID},
&v2customtypes.QueryProposalRequest{ProposalId: proposalID},
)
if err != nil {
return err
Expand All @@ -102,11 +102,11 @@ func GetCmdQueryCustomParams() *cobra.Command {
if err != nil {
return err
}
queryClient := v2lunc1types.NewQueryClient(clientCtx)
queryClient := v2customtypes.NewQueryClient(clientCtx)
// Query the proposal
res, err := queryClient.Params(
cmd.Context(),
&v2lunc1types.QueryParamsRequest{},
&v2customtypes.QueryParamsRequest{},
)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions custom/gov/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

v2lunc1cli "github.com/classic-terra/core/v3/custom/gov/client/cli"
v2customcli "github.com/classic-terra/core/v3/custom/gov/client/cli"
)

func (s *CLITestSuite) TestGetCmdQueryMinimalDeposit() {
Expand Down Expand Up @@ -33,7 +33,7 @@ func (s *CLITestSuite) TestGetCmdQueryMinimalDeposit() {
tc := tc

s.Run(tc.name, func() {
cmd := v2lunc1cli.GetCmdQueryMinimalDeposit()
cmd := v2customcli.GetCmdQueryMinimalDeposit()
cmd.SetArgs(tc.args)
s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput))
})
Expand Down
8 changes: 4 additions & 4 deletions custom/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

"github.com/classic-terra/core/v3/custom/gov/keeper"
"github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
"github.com/classic-terra/core/v3/custom/gov/types/v2custom"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v2lunc1.GenesisState) {
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v2custom.GenesisState) {
k.SetProposalID(ctx, data.StartingProposalId)
k.SetParams(ctx, *data.Params)

Expand Down Expand Up @@ -55,7 +55,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
}

// ExportGenesis - output genesis parameters
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v2lunc1.GenesisState {
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v2custom.GenesisState {
startingProposalID, _ := k.GetProposalID(ctx)
proposals := k.GetProposals(ctx)
params := k.GetParams(ctx)
Expand All @@ -70,7 +70,7 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v2lunc1.GenesisState {
proposalsVotes = append(proposalsVotes, votes...)
}

return &v2lunc1.GenesisState{
return &v2custom.GenesisState{
StartingProposalId: startingProposalID,
Deposits: proposalsDeposits,
Votes: proposalsVotes,
Expand Down
4 changes: 2 additions & 2 deletions custom/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd

// HandleCheckLimitDeposit
minDeposit := keeper.GetParams(ctx).MinDeposit
requiredAmount := keeper.GetDepositLimitBaseUusd(ctx, proposalID)
requiredAmount := keeper.GetDepositLimitBaseUstc(ctx, proposalID)
if requiredAmount.IsZero() {
requiredAmount = minDeposit[0].Amount
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func (keeper Keeper) validateInitialDeposit(ctx sdk.Context, initialDeposit sdk.
if minInitialDepositRatio.IsZero() {
return nil
}
totalLuncDeposit, err := keeper.GetMinimumDepositBaseUusd(ctx)
totalLuncDeposit, err := keeper.GetMinimumDepositBaseUstc(ctx)
luncCoin := sdk.NewCoin(params.MinDeposit[0].Denom, totalLuncDeposit)
minDepositCoins := params.MinDeposit
minDepositCoins[0] = luncCoin
Expand Down
Loading

0 comments on commit d26e250

Please sign in to comment.