Skip to content

Commit

Permalink
replace all deprecated types
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 committed May 17, 2024
1 parent 5e7be72 commit 3e02c52
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 45 deletions.
3 changes: 2 additions & 1 deletion custom/auth/ante/expected_keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
Expand All @@ -10,7 +11,7 @@ import (
type TreasuryKeeper interface {
RecordEpochTaxProceeds(ctx sdk.Context, delta sdk.Coins)
GetTaxRate(ctx sdk.Context) (taxRate sdk.Dec)
GetTaxCap(ctx sdk.Context, denom string) (taxCap sdk.Int)
GetTaxCap(ctx sdk.Context, denom string) (taxCap math.Int)
GetBurnSplitRate(ctx sdk.Context) sdk.Dec
HasBurnTaxExemptionAddress(ctx sdk.Context, addresses ...string) bool
HasBurnTaxExemptionContract(ctx sdk.Context, address string) bool
Expand Down
11 changes: 6 additions & 5 deletions custom/auth/client/utils/feeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"context"

"cosmossdk.io/math"
"github.com/spf13/pflag"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -13,7 +14,7 @@ import (

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

wasmexported "github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
marketexported "github.com/classic-terra/core/v3/x/market/exported"
treasuryexported "github.com/classic-terra/core/v3/x/treasury/exported"
)
Expand Down Expand Up @@ -143,23 +144,23 @@ func FilterMsgAndComputeTax(clientCtx client.Context, msgs ...sdk.Msg) (taxes sd

taxes = taxes.Add(tax...)

case *wasmexported.MsgInstantiateContract:
case *wasmtypes.MsgInstantiateContract:
tax, err := computeTax(clientCtx, taxRate, msg.Funds)
if err != nil {
return nil, err
}

taxes = taxes.Add(tax...)

case *wasmexported.MsgInstantiateContract2:
case *wasmtypes.MsgInstantiateContract2:
tax, err := computeTax(clientCtx, taxRate, msg.Funds)
if err != nil {
return nil, err
}

taxes = taxes.Add(tax...)

case *wasmexported.MsgExecuteContract:
case *wasmtypes.MsgExecuteContract:
tax, err := computeTax(clientCtx, taxRate, msg.Funds)
if err != nil {
return nil, err
Expand Down Expand Up @@ -208,7 +209,7 @@ func queryTaxRate(clientCtx client.Context) (sdk.Dec, error) {
return res.TaxRate, err
}

func queryTaxCap(clientCtx client.Context, denom string) (sdk.Int, error) {
func queryTaxCap(clientCtx client.Context, denom string) (math.Int, error) {
queryClient := treasuryexported.NewQueryClient(clientCtx)

res, err := queryClient.TaxCap(context.Background(), &treasuryexported.QueryTaxCapRequest{Denom: denom})
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

"cosmossdk.io/math"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -97,7 +98,7 @@ func (n *NodeConfig) QuerySpecificBalance(addr, denom string) (sdk.Coin, error)
return sdk.Coin{}, nil
}

func (n *NodeConfig) QuerySupplyOf(denom string) (sdk.Int, error) {
func (n *NodeConfig) QuerySupplyOf(denom string) (math.Int, error) {
path := fmt.Sprintf("cosmos/bank/v1beta1/supply/%s", denom)
bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)
Expand Down
3 changes: 2 additions & 1 deletion x/oracle/keeper/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"cosmossdk.io/math"
simparams "cosmossdk.io/simapp/params"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -240,7 +241,7 @@ func CreateTestInput(t *testing.T) TestInput {
}

// NewTestMsgCreateValidator test msg creator
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator {
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt math.Int) *stakingtypes.MsgCreateValidator {
commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
msg, _ := stakingtypes.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(core.MicroLunaDenom, amt),
Expand Down
3 changes: 2 additions & 1 deletion x/oracle/tally.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oracle

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/classic-terra/core/v3/x/oracle/keeper"
Expand Down Expand Up @@ -37,7 +38,7 @@ func Tally(pb types.ExchangeRateBallot, rewardBand sdk.Dec, validatorClaimMap ma
}

// ballot for the asset is passing the threshold amount of voting power
func ballotIsPassing(ballot types.ExchangeRateBallot, thresholdVotes sdk.Int) (sdk.Int, bool) {
func ballotIsPassing(ballot types.ExchangeRateBallot, thresholdVotes math.Int) (math.Int, bool) {
ballotPower := sdk.NewInt(ballot.Power())
return ballotPower, !ballotPower.IsZero() && ballotPower.GTE(thresholdVotes)
}
Expand Down
7 changes: 4 additions & 3 deletions x/oracle/types/expected_keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -10,13 +11,13 @@ import (
// StakingKeeper is expected keeper for staking module
type StakingKeeper interface {
Validator(ctx sdk.Context, address sdk.ValAddress) stakingtypes.ValidatorI // get validator by operator address; nil when validator not found
TotalBondedTokens(sdk.Context) sdk.Int // total bonded tokens within the validator set
TotalBondedTokens(sdk.Context) math.Int // total bonded tokens within the validator set
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) sdk.Int
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) math.Int
Jail(sdk.Context, sdk.ConsAddress) // jail a validator
ValidatorsPowerStoreIterator(ctx sdk.Context) sdk.Iterator // an iterator for the current validator power store
MaxValidators(sdk.Context) uint32 // MaxValidators returns the maximum amount of bonded validators
PowerReduction(ctx sdk.Context) (res sdk.Int)
PowerReduction(ctx sdk.Context) (res math.Int)
}

// DistributionKeeper is expected keeper for distribution module
Expand Down
37 changes: 22 additions & 15 deletions x/oracle/types/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"time"

sdkmath "cosmossdk.io/math"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -69,11 +70,11 @@ func (sk DummyStakingKeeper) Validator(_ sdk.Context, address sdk.ValAddress) st
return nil
}

func (DummyStakingKeeper) TotalBondedTokens(sdk.Context) sdk.Int {
func (DummyStakingKeeper) TotalBondedTokens(sdk.Context) sdkmath.Int {
return sdk.ZeroInt()
}

func (DummyStakingKeeper) Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) sdk.Int {
func (DummyStakingKeeper) Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) sdkmath.Int {
return sdk.ZeroInt()
}

Expand All @@ -94,7 +95,7 @@ func (DummyStakingKeeper) MaxValidators(sdk.Context) uint32 {
}

// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power
func (DummyStakingKeeper) PowerReduction(sdk.Context) (res sdk.Int) {
func (DummyStakingKeeper) PowerReduction(sdk.Context) (res sdkmath.Int) {
res = sdk.DefaultPowerReduction
return
}
Expand All @@ -118,23 +119,29 @@ func (MockValidator) TmConsPublicKey() (tmprotocrypto.PublicKey, error) {
return tmprotocrypto.PublicKey{}, nil
}
func (MockValidator) GetConsAddr() (sdk.ConsAddress, error) { return nil, nil }
func (v MockValidator) GetTokens() sdk.Int {
func (v MockValidator) GetTokens() sdkmath.Int {
return sdk.TokensFromConsensusPower(v.power, sdk.DefaultPowerReduction)
}

func (v MockValidator) GetBondedTokens() sdk.Int {
func (v MockValidator) GetBondedTokens() sdkmath.Int {
return sdk.TokensFromConsensusPower(v.power, sdk.DefaultPowerReduction)
}
func (v MockValidator) GetConsensusPower(_ sdk.Int) int64 { return v.power }
func (v *MockValidator) SetConsensusPower(power int64) { v.power = power }
func (v MockValidator) GetCommission() sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) GetMinSelfDelegation() sdk.Int { return sdk.OneInt() }
func (v MockValidator) GetDelegatorShares() sdk.Dec { return sdk.NewDec(v.power) }
func (v MockValidator) TokensFromShares(sdk.Dec) sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) TokensFromSharesTruncated(sdk.Dec) sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) TokensFromSharesRoundUp(sdk.Dec) sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) SharesFromTokens(_ sdk.Int) (sdk.Dec, error) { return sdk.ZeroDec(), nil }
func (v MockValidator) SharesFromTokensTruncated(_ sdk.Int) (sdk.Dec, error) {
func (v MockValidator) GetConsensusPower(_ sdkmath.Int) int64 { return v.power }
func (v *MockValidator) SetConsensusPower(power int64) { v.power = power }
func (v MockValidator) GetCommission() sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) GetMinSelfDelegation() sdkmath.Int { return sdk.OneInt() }
func (v MockValidator) GetDelegatorShares() sdk.Dec { return sdk.NewDec(v.power) }
func (v MockValidator) TokensFromShares(sdk.Dec) sdk.Dec { return sdk.ZeroDec() }
func (v MockValidator) TokensFromSharesTruncated(sdk.Dec) sdk.Dec {
return sdk.ZeroDec()
}

Check failure on line 137 in x/oracle/types/test_utils.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
func (v MockValidator) TokensFromSharesRoundUp(sdk.Dec) sdk.Dec {
return sdk.ZeroDec()
}

Check failure on line 140 in x/oracle/types/test_utils.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
func (v MockValidator) SharesFromTokens(_ sdkmath.Int) (sdk.Dec, error) {
return sdk.ZeroDec(), nil
}

Check failure on line 143 in x/oracle/types/test_utils.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
func (v MockValidator) SharesFromTokensTruncated(_ sdkmath.Int) (sdk.Dec, error) {
return sdk.ZeroDec(), nil
}

Expand Down
3 changes: 2 additions & 1 deletion x/treasury/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package treasury
import (
"fmt"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

core "github.com/classic-terra/core/v3/types"
Expand Down Expand Up @@ -62,7 +63,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisSt
epochInitialIssuance := keeper.GetEpochInitialIssuance(ctx)

var taxCaps []types.TaxCap
keeper.IterateTaxCap(ctx, func(denom string, taxCap sdk.Int) bool {
keeper.IterateTaxCap(ctx, func(denom string, taxCap math.Int) bool {
taxCaps = append(taxCaps, types.TaxCap{
Denom: denom,
TaxCap: taxCap,
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/keeper/indicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"testing"

"cosmossdk.io/math"
core "github.com/classic-terra/core/v3/types"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -125,7 +126,7 @@ func TestLoadIndicatorByEpoch(t *testing.T) {
input.TreasuryKeeper.SetSR(input.Ctx, int64(epoch), SR)
}

TSLArr := []sdk.Int{
TSLArr := []math.Int{
sdk.NewInt(1000000),
sdk.NewInt(2000000),
sdk.NewInt(3000000),
Expand Down
17 changes: 9 additions & 8 deletions x/treasury/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"fmt"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -118,21 +119,21 @@ func (k Keeper) GetRewardWeight(ctx sdk.Context) sdk.Dec {
}

// SetRewardWeight sets the reward weight
func (k Keeper) SetRewardWeight(ctx sdk.Context, rewardWeight sdk.Dec) {
func (k Keeper) SetRewardWeight(ctx sdk.Context, rewardWeight math.LegacyDec) {
store := ctx.KVStore(k.storeKey)
b := k.cdc.MustMarshal(&sdk.DecProto{Dec: rewardWeight})
store.Set(types.RewardWeightKey, b)
}

// SetTaxCap sets the tax cap denominated in integer units of the reference {denom}
func (k Keeper) SetTaxCap(ctx sdk.Context, denom string, cap sdk.Int) {
func (k Keeper) SetTaxCap(ctx sdk.Context, denom string, cap math.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: cap})
store.Set(types.GetTaxCapKey(denom), bz)
}

// GetTaxCap gets the tax cap denominated in integer units of the reference {denom}
func (k Keeper) GetTaxCap(ctx sdk.Context, denom string) sdk.Int {
func (k Keeper) GetTaxCap(ctx sdk.Context, denom string) math.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.GetTaxCapKey(denom))
if bz == nil {
Expand All @@ -146,7 +147,7 @@ func (k Keeper) GetTaxCap(ctx sdk.Context, denom string) sdk.Int {
}

// IterateTaxCap iterates all tax cap
func (k Keeper) IterateTaxCap(ctx sdk.Context, handler func(denom string, taxCap sdk.Int) (stop bool)) {
func (k Keeper) IterateTaxCap(ctx sdk.Context, handler func(denom string, taxCap math.Int) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iter := sdk.KVStorePrefixIterator(store, types.TaxCapKey)

Expand Down Expand Up @@ -234,7 +235,7 @@ func (k Keeper) GetEpochInitialIssuance(ctx sdk.Context) sdk.Coins {
}

// PeekEpochSeigniorage returns epoch seigniorage
func (k Keeper) PeekEpochSeigniorage(ctx sdk.Context) sdk.Int {
func (k Keeper) PeekEpochSeigniorage(ctx sdk.Context) math.Int {
epochIssuance := k.bankKeeper.GetSupply(ctx, core.MicroLunaDenom).Amount
preEpochIssuance := k.GetEpochInitialIssuance(ctx).AmountOf(core.MicroLunaDenom)
epochSeigniorage := preEpochIssuance.Sub(epochIssuance)
Expand Down Expand Up @@ -315,13 +316,13 @@ func (k Keeper) ClearSRs(ctx sdk.Context) {
}

// GetTSL returns the total staked luna for the epoch
func (k Keeper) GetTSL(ctx sdk.Context, epoch int64) sdk.Int {
func (k Keeper) GetTSL(ctx sdk.Context, epoch int64) math.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.GetTSLKey(epoch))

ip := sdk.IntProto{}
if bz == nil {
ip.Int = sdk.ZeroInt()
ip.Int = math.ZeroInt()
} else {
k.cdc.MustUnmarshal(bz, &ip)
}
Expand All @@ -330,7 +331,7 @@ func (k Keeper) GetTSL(ctx sdk.Context, epoch int64) sdk.Int {
}

// SetTSL stores the total staked luna for the epoch
func (k Keeper) SetTSL(ctx sdk.Context, epoch int64, tsl sdk.Int) {
func (k Keeper) SetTSL(ctx sdk.Context, epoch int64, tsl math.Int) {
store := ctx.KVStore(k.storeKey)

bz := k.cdc.MustMarshal(&sdk.IntProto{Int: tsl})
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/rand"
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"

"github.com/cometbft/cometbft/crypto/secp256k1"
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestIterateTaxCap(t *testing.T) {
input.TreasuryKeeper.SetTaxCap(input.Ctx, core.MicroUSDDenom, usdCap)
input.TreasuryKeeper.SetTaxCap(input.Ctx, core.MicroKRWDenom, krwCap)

input.TreasuryKeeper.IterateTaxCap(input.Ctx, func(denom string, taxCap sdk.Int) bool {
input.TreasuryKeeper.IterateTaxCap(input.Ctx, func(denom string, taxCap math.Int) bool {
switch denom {
case core.MicroCNYDenom:
require.Equal(t, cnyCap, taxCap)
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
Expand Down Expand Up @@ -59,7 +60,7 @@ func (q querier) TaxCaps(c context.Context, _ *types.QueryTaxCapsRequest) (*type
ctx := sdk.UnwrapSDKContext(c)

var taxCaps []types.QueryTaxCapsResponseItem
q.IterateTaxCap(ctx, func(denom string, taxCap sdk.Int) bool {
q.IterateTaxCap(ctx, func(denom string, taxCap sdkmath.Int) bool {
taxCaps = append(taxCaps, types.QueryTaxCapsResponseItem{
Denom: denom,
TaxCap: taxCap,
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/keeper/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"cosmossdk.io/math"
simparams "cosmossdk.io/simapp/params"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -323,7 +324,7 @@ func CreateTestInput(t *testing.T) TestInput {
}

// NewTestMsgCreateValidator test msg creator
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator {
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt math.Int) *stakingtypes.MsgCreateValidator {
commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
msg, _ := stakingtypes.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(core.MicroLunaDenom, amt),
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/types/exptected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -30,7 +31,7 @@ type MarketKeeper interface {

// StakingKeeper expected keeper for staking module
type StakingKeeper interface {
TotalBondedTokens(sdk.Context) sdk.Int // total bonded tokens within the validator set
TotalBondedTokens(sdk.Context) math.Int // total bonded tokens within the validator set
}

// DistributionKeeper expected keeper for distribution module
Expand Down
Loading

0 comments on commit 3e02c52

Please sign in to comment.