Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove usage of ToDec() #910

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/claim/types/claim_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func (m ClaimRecord) IsMissionCompleted(missionID uint64) bool {

// ClaimableFromMission returns the amount claimable for this claim record from the provided mission completion
func (m ClaimRecord) ClaimableFromMission(mission Mission) sdk.Int {
return mission.Weight.Mul(m.Claimable.ToDec()).TruncateInt()
return mission.Weight.Mul(sdk.NewDecFromInt(m.Claimable)).TruncateInt()
}
2 changes: 1 addition & 1 deletion x/launch/keeper/genesis_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (k Keeper) GetValidatorsAndTotalDelegation(
k.cdc.MustUnmarshal(iterator.Value(), &val)
consPubKey := base64.StdEncoding.EncodeToString(val.ConsPubKey)
validators[consPubKey] = val
totalDelegation = totalDelegation.Add(val.SelfDelegation.Amount.ToDec())
totalDelegation = totalDelegation.Add(sdk.NewDecFromInt(val.SelfDelegation.Amount))
}
return validators, totalDelegation
}
2 changes: 1 addition & 1 deletion x/launch/keeper/genesis_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestKeeper_GetValidatorsAndTotalDelegation(t *testing.T) {
for _, validator := range validators {
consPubKey := base64.StdEncoding.EncodeToString(validator.ConsPubKey)
validatorMap[consPubKey] = validator
totalSelfDelegation = totalSelfDelegation.Add(validator.SelfDelegation.Amount.ToDec())
totalSelfDelegation = totalSelfDelegation.Add(sdk.NewDecFromInt(validator.SelfDelegation.Amount))
}

t.Run("should get a map of genesis validator and the total delegation", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/launch/keeper/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (k Keeper) CheckValidatorSet(
validator.PubKey.Address().String(),
)
}
valSetSelfDelegation = valSetSelfDelegation.Add(launchValidator.SelfDelegation.Amount.ToDec())
valSetSelfDelegation = valSetSelfDelegation.Add(sdk.NewDecFromInt(launchValidator.SelfDelegation.Amount))
}

// check if 2/3 of total self-delegation is reached from the provided validator set
Expand Down
2 changes: 1 addition & 1 deletion x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (k Keeper) AddCollectedFees(ctx sdk.Context, fees sdk.Coins) error {

// GetProportions gets the balance of the `MintedDenom` from minted coins and returns coins according to the `AllocationRatio`.
func (k Keeper) GetProportions(ctx sdk.Context, mintedCoin sdk.Coin, ratio sdk.Dec) sdk.Coin {
return sdk.NewCoin(mintedCoin.Denom, mintedCoin.Amount.ToDec().Mul(ratio).TruncateInt())
return sdk.NewCoin(mintedCoin.Denom, sdk.NewDecFromInt(mintedCoin.Amount).Mul(ratio).TruncateInt())
}

// DistributeMintedCoins implements distribution of minted coins from mint
Expand Down
2 changes: 1 addition & 1 deletion x/participation/keeper/total_allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// GetTotalAllocations returns the number of available allocations based on delegations
func (k Keeper) GetTotalAllocations(ctx sdk.Context, address string) (uint64, error) {
allocationPriceBondedDec := k.AllocationPrice(ctx).Bonded.ToDec()
allocationPriceBondedDec := sdk.NewDecFromInt(k.AllocationPrice(ctx).Bonded)

accAddr, err := sdk.AccAddressFromBech32(address)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/reward_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func CalculateRewards(blockRatio, signatureRatio sdk.Dec, coins sdk.Coins) (sdk.
// calculate rewards
rewards := sdk.NewCoins()
for _, coin := range coins {
amount := blockRatio.Mul(signatureRatio).Mul(coin.Amount.ToDec())
amount := blockRatio.Mul(signatureRatio).Mul(sdk.NewDecFromInt(coin.Amount))
coin.Amount = amount.TruncateInt()
rewards = rewards.Add(coin)
}
Expand Down