Skip to content

Commit

Permalink
refactor: replace sdk.Dec with sdkmath.LegacyDec
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Feb 5, 2024
1 parent c659e33 commit 2588ecf
Show file tree
Hide file tree
Showing 58 changed files with 464 additions and 468 deletions.
6 changes: 4 additions & 2 deletions app/prefix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package app

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

"github.com/sge-network/sge/app/keepers"
"github.com/sge-network/sge/app/params"
)
Expand All @@ -26,11 +28,11 @@ func SetConfig() {
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)

err := sdk.RegisterDenom(params.HumanCoinUnit, sdk.OneDec())
err := sdk.RegisterDenom(params.HumanCoinUnit, sdkmath.LegacyOneDec())
if err != nil {
panic(err)
}
err = sdk.RegisterDenom(params.BaseCoinUnit, sdk.NewDecWithPrec(1, params.SGEExponent))
err = sdk.RegisterDenom(params.BaseCoinUnit, sdkmath.LegacyNewDecWithPrec(1, params.SGEExponent))
if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v1/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand All @@ -13,7 +14,7 @@ import (
func setCommissionRate(stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context) {
// the minimal commission rate of 5% (0.05)
// (default is needed to be set because of SDK store migrations that set the param)
stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2)
stakingtypes.DefaultMinCommissionRate = sdkmath.LegacyNewDecWithPrec(5, 2)

stakingKeeper.IterateValidators(ctx, func(index int64, val stakingtypes.ValidatorI) (stop bool) {
if val.GetCommission().LT(stakingtypes.DefaultMinCommissionRate) {
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func CreateUpgradeHandler(
var minDeposit sdkmath.Int
housePS.Get(ctx, []byte("MinDeposit"), &minDeposit)

var houseParticipationFee sdk.Dec
var houseParticipationFee sdkmath.LegacyDec
housePS.Get(ctx, []byte("HouseParticipationFee"), &houseParticipationFee)

p := housetypes.NewParams(
Expand Down
8 changes: 4 additions & 4 deletions app/upgrades/v3/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmath "cosmossdk.io/math"
"github.com/sge-network/sge/app/upgrades"
)

Expand All @@ -11,11 +11,11 @@ const UpgradeName = "v1.2.0"
// Expedite governance params
var (
// DefaultMinExpeditedDepositTokens is the default minimum deposit required for expedited proposals.
DefaultMinExpeditedDepositTokens = sdk.NewInt(50000000000)
DefaultMinExpeditedDepositTokens = sdkmath.NewInt(50000000000)
// DefaultExpeditedQuorum is the default quorum percentage required for expedited proposals.
DefaultExpeditedQuorum = sdk.NewDecWithPrec(750, 3)
DefaultExpeditedQuorum = sdkmath.LegacyNewDecWithPrec(750, 3)
// DefaultExpeditedThreshold is the default voting threshold percentage required for expedited proposals.
DefaultExpeditedThreshold = sdk.NewDecWithPrec(750, 3)
DefaultExpeditedThreshold = sdkmath.LegacyNewDecWithPrec(750, 3)
)

var Upgrade = upgrades.Upgrade{
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v8

import (
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -108,7 +109,7 @@ func CreateUpgradeHandler(

// update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler
govParams := k.GovKeeper.GetParams(ctx)
govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String()
govParams.MinInitialDepositRatio = sdkmath.LegacyNewDec(20).Quo(sdkmath.LegacyNewDec(100)).String()
if err := k.GovKeeper.SetParams(ctx, govParams); err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions docs/specs/Mint/04_Begin_Block.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (m Minter) CurrentPhase(params Params, currentBlock int64) (Phase, int) {
return params.GetPhaseAtStep(1), 1
}

cumulativeBlock := sdk.NewDec(0)
cumulativeBlock := sdkmath.LegacyNewDec(0)
var currentStep int
var found bool

Expand All @@ -26,7 +26,7 @@ func (m Minter) CurrentPhase(params Params, currentBlock int64) (Phase, int) {

// if the current block is less than or equal to cummulative blocks
// this means that we are in the i+1 step which is set in above line
if sdk.NewDec(currentBlock).LTE(cumulativeBlock) {
if sdkmath.LegacyNewDec(currentBlock).LTE(cumulativeBlock) {
found = true
// it is the current phase
// so there is no need for furthur phase blocks check
Expand Down Expand Up @@ -77,7 +77,7 @@ Since the SGE-Network chain is predominantly reliant on phases for its inflation
```go
// NextPhaseProvisions returns the phase provisions based on current total
// supply and inflation rate.
func (m Minter) NextPhaseProvisions(totalSupply sdkmath.Int, excludeAmount sdkmath.Int, phase Phase) sdk.Dec {
func (m Minter) NextPhaseProvisions(totalSupply sdkmath.Int, excludeAmount sdkmath.Int, phase Phase) sdkmath.LegacyDec {
// calculate annual provisions as normal
annualProvisions := m.Inflation.MulInt(totalSupply.Sub(excludeAmount))

Expand All @@ -99,7 +99,7 @@ Calculate the provisions generated for each block based on current phase provisi
```go
// BlockProvisions returns the provisions for a block based on the phase
// provisions rate.
func (m Minter) BlockProvisions(params Params, phaseStep int) (sdk.Coin, sdk.Dec) {
func (m Minter) BlockProvisions(params Params, phaseStep int) (sdk.Coin, sdkmath.LegacyDec) {

// get total blocks in this phase
blocksPerPhase := params.getPhaseBlocks(phaseStep).TruncateDec()
Expand Down
12 changes: 6 additions & 6 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: e7dd2c968d9a403b8f1a01a8d8c8a581
digest: shake256:e766fba8cb060d67357cc715f5c39ca32661b069f829a016962e2b6879f3cebcaecb23c9ac9f7846e04e10a0a6163298713078bc9ef0cf3400885a0acf5ba3bc
commit: fb7629d893cb44a799c16916d09ccc0b
digest: shake256:7cbbcdd4f4b2ca91e7b161ef0c58b794d37d105b87b1aab0a73b539508b1f39b3ff8b94148dd75eeaebbdb049730a6a3606d8879f84e65f08559bd9aa4d512c8
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 5e5b9fdd01804356895f8f79a6f1ddc1
digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
- remote: buf.build
owner: googleapis
repository: googleapis
commit: a86849a25cc04f4dbe9b15ddddfbc488
digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943
commit: e874a0be2bf140a5a4c7d4122c635823
digest: shake256:4fe3036b4d706f6ee2b13c730bd04777f021dfd02ed27e6e40480acfe664a7548238312ee0727fd77648a38d227e296d43f4a38a34cdd46068156211016d9657
- remote: buf.build
owner: protocolbuffers
repository: wellknowntypes
Expand Down
2 changes: 1 addition & 1 deletion proto/sgenetwork/sge/bet/bet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ message Bet {

// max_loss_multiplier is the multiplier coefficient of max loss.
string max_loss_multiplier = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

Expand Down
4 changes: 2 additions & 2 deletions proto/sgenetwork/sge/bet/bet_odds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message BetOdds {
(gogoproto.customname) = "MaxLossMultiplier",
(gogoproto.jsontag) = "max_loss_multiplier",
json_name = "max_loss_multiplier",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
Expand All @@ -49,7 +49,7 @@ message BetOddsCompact {
(gogoproto.customname) = "MaxLossMultiplier",
(gogoproto.jsontag) = "max_loss_multiplier",
json_name = "max_loss_multiplier",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
2 changes: 1 addition & 1 deletion proto/sgenetwork/sge/house/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message Params {
// house_participation_fee is the % of the deposit to be paid for a house
// participation by the depositor.
string house_participation_fee = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

Expand Down
6 changes: 3 additions & 3 deletions proto/sgenetwork/sge/mint/minter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import "gogoproto/gogo.proto";
message Minter {
// inflation is the current annual inflation rate.
string inflation = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// phase_step is the index of phases slice + 1.
int32 phase_step = 2;
// phase_provisions is the current phase expected provisions.
string phase_provisions = 3 [
(gogoproto.moretags) = "yaml:\"phase_provisions\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// truncated_tokens holds current truncated tokens because of Dec to Int
// conversion in the minting.
string truncated_tokens = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
4 changes: 2 additions & 2 deletions proto/sgenetwork/sge/mint/phase.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ message Phase {
// inflation is the current phase inflation rate.
string inflation = 1 [
(gogoproto.moretags) = "yaml:\"inflation\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// year_coefficient is the proportion of a complete year.
string year_coefficient = 2 [
(gogoproto.moretags) = "yaml:\"year_coefficient\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
4 changes: 2 additions & 2 deletions proto/sgenetwork/sge/mint/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ message QueryInflationRequest {}
message QueryInflationResponse {
// inflation is the current minting inflation value.
bytes inflation = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
Expand All @@ -84,7 +84,7 @@ message QueryPhaseProvisionsRequest {}
message QueryPhaseProvisionsResponse {
// phase_provisions is the current minting phase provisions value.
bytes phase_provisions = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
Expand Down
6 changes: 4 additions & 2 deletions proto/sgenetwork/sge/orderbook/participation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ message OrderBookParticipation {
// is_settled represents if the participation is settled or not.
bool is_settled = 14 [ (gogoproto.moretags) = "yaml:\"is_settled\"" ];

// returned_amount is the total returned amount to the user's account including reimbursed fees.
// returned_amount is the total returned amount to the user's account
// including reimbursed fees.
string returned_amount = 15 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"returned_amount\""
];

// reimbursed_fee is the fee reimbursed because of reasons such as market calcellation.
// reimbursed_fee is the fee reimbursed because of reasons such as market
// calcellation.
string reimbursed_fee = 16 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
Expand Down
22 changes: 11 additions & 11 deletions testutil/simapp/simapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,25 @@ func stakingDefaultTestGenesis(
ConsensusPubkey: pk0,
Status: stakingtypes.Bonded,
Tokens: valPower1,
DelegatorShares: sdk.NewDecFromInt(valPower1),
DelegatorShares: sdkmath.LegacyNewDecFromInt(valPower1),
Description: stakingtypes.NewDescription("hoop", "", "", "", ""),
Commission: stakingtypes.NewCommission(
sdk.NewDecWithPrec(5, 1),
sdk.NewDecWithPrec(5, 1),
sdk.NewDec(0),
sdkmath.LegacyNewDecWithPrec(5, 1),
sdkmath.LegacyNewDecWithPrec(5, 1),
sdkmath.LegacyNewDec(0),
),
}
bondedVal2 := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(addr2).String(),
ConsensusPubkey: pk1,
Status: stakingtypes.Bonded,
Tokens: valPower2,
DelegatorShares: sdk.NewDecFromInt(valPower2),
DelegatorShares: sdkmath.LegacyNewDecFromInt(valPower2),
Description: stakingtypes.NewDescription("bloop", "", "", "", ""),
Commission: stakingtypes.NewCommission(
sdk.NewDecWithPrec(5, 1),
sdk.NewDecWithPrec(5, 1),
sdk.NewDec(0),
sdkmath.LegacyNewDecWithPrec(5, 1),
sdkmath.LegacyNewDecWithPrec(5, 1),
sdkmath.LegacyNewDec(0),
),
}

Expand Down Expand Up @@ -379,9 +379,9 @@ func NewStakingHelper(t *testing.T, ctx sdk.Context, k stakingKeeper.Keeper) *st

func validatorDefaultCommission() stakingtypes.CommissionRates {
return stakingtypes.NewCommissionRates(
sdk.MustNewDecFromStr("0.1"),
sdk.MustNewDecFromStr("0.2"),
sdk.MustNewDecFromStr("0.01"),
sdkmath.LegacyMustNewDecFromStr("0.1"),
sdkmath.LegacyMustNewDecFromStr("0.2"),
sdkmath.LegacyMustNewDecFromStr("0.01"),
)
}

Expand Down
3 changes: 1 addition & 2 deletions x/bet/client/cli/query_bet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/google/uuid"
"github.com/spf13/cast"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -66,7 +65,7 @@ func networkWithBetObjects(t *testing.T, n int) (*network.Network, []types.Bet)
OddsValue: "10",
Amount: sdkmath.NewInt(10),
Fee: sdkmath.NewInt(1),
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
MaxLossMultiplier: sdkmath.LegacyMustNewDecFromStr("0.1"),
}
nullify.Fill(&bet)

Expand Down
2 changes: 1 addition & 1 deletion x/bet/keeper/bet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func createNBet(
items[i].Amount = sdkmath.NewInt(10)
items[i].Fee = sdkmath.NewInt(1)
items[i].MarketUID = testMarketUID
items[i].MaxLossMultiplier = sdk.NewDec(10)
items[i].MaxLossMultiplier = sdkmath.LegacyNewDec(10)

id := uint64(i + 1)
keeper.SetBet(ctx, items[i], id)
Expand Down
8 changes: 4 additions & 4 deletions x/bet/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ var (
UID: testOddsUID1,
MarketUID: testMarketUID,
Value: "4.20",
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
MaxLossMultiplier: sdkmath.LegacyMustNewDecFromStr("0.1"),
}
testBetOdds = &[]types.BetOdds{
{
UID: testOddsUID1,
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
MaxLossMultiplier: sdkmath.LegacyMustNewDecFromStr("0.1"),
},
{
UID: testOddsUID2,
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
MaxLossMultiplier: sdkmath.LegacyMustNewDecFromStr("0.1"),
},
{
UID: testOddsUID3,
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
MaxLossMultiplier: sdkmath.LegacyMustNewDecFromStr("0.1"),
},
}
testCreator string
Expand Down
Loading

0 comments on commit 2588ecf

Please sign in to comment.