Skip to content

Commit

Permalink
refactor: replace sdk.int with sdkmath.int
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Apr 25, 2024
1 parent e80ba58 commit b701c7c
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@

# ignore visual studio code dev container config
.devcontainer

# ignore build dir
build
4 changes: 3 additions & 1 deletion app/upgrades/v3/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package v3

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

"github.com/sge-network/sge/app/upgrades"
)

Expand All @@ -11,7 +13,7 @@ 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)
// DefaultExpeditedThreshold is the default voting threshold percentage required for expedited proposals.
Expand Down
10 changes: 5 additions & 5 deletions x/bet/keeper/settle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Status: types.Bet_STATUS_SETTLED,
Expand All @@ -73,7 +73,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -92,7 +92,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -111,7 +111,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -131,7 +131,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,

Expand Down
5 changes: 2 additions & 3 deletions x/bet/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"gopkg.in/yaml.v2"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

Expand Down Expand Up @@ -134,11 +133,11 @@ func validateConstraints(i interface{}) error {
return fmt.Errorf("%s: %T", ErrTextInvalidParamType, i)
}

if v.MinAmount.LTE(sdk.OneInt()) {
if v.MinAmount.LTE(sdkmath.OneInt()) {
return fmt.Errorf("minimum bet amount must be more than one: %d", v.MinAmount.Int64())
}

if v.Fee.LT(sdk.ZeroInt()) {
if v.Fee.LT(sdkmath.ZeroInt()) {
return fmt.Errorf("minimum bet fee must be positive: %d", v.Fee.Int64())
}

Expand Down
2 changes: 1 addition & 1 deletion x/house/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k Keeper) Deposit(ctx sdk.Context, creator, depositor string,
marketUID string, amount sdkmath.Int,
) (participationIndex uint64, feeAmount sdkmath.Int, err error) {
// Create the deposit object
deposit := types.NewDeposit(creator, depositor, marketUID, amount, sdk.ZeroInt(), 0)
deposit := types.NewDeposit(creator, depositor, marketUID, amount, sdkmath.ZeroInt(), 0)

feeAmount = deposit.CalcHouseParticipationFeeAmount(k.GetHouseParticipationFee(ctx))

Expand Down
2 changes: 1 addition & 1 deletion x/house/types/deposit_authorizaton.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a DepositAuthorization) ValidateBasic() error {
if a.SpendLimit.IsNil() {
return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be nil")
}
if a.SpendLimit.LTE(sdk.ZeroInt()) {
if a.SpendLimit.LTE(sdkmath.ZeroInt()) {
return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be less than or equal to zero")
}
if a.SpendLimit.LT(minDepositGrant) {
Expand Down
5 changes: 2 additions & 3 deletions x/house/types/message_deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"

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

"github.com/sge-network/sge/testutil/sample"
Expand Down Expand Up @@ -49,7 +48,7 @@ func TestMsgDepositValidateBasic(t *testing.T) {
msg: types.MsgDeposit{
Creator: sample.AccAddress(),
MarketUID: uuid.NewString(),
Amount: sdk.ZeroInt(),
Amount: sdkmath.ZeroInt(),
Ticket: "Ticket",
},
err: sdkerrtypes.ErrInvalidRequest,
Expand All @@ -76,7 +75,7 @@ func TestNewDeposit(t *testing.T) {
Amount: sdkmath.NewInt(100),
ParticipationIndex: 0,
WithdrawalCount: 0,
TotalWithdrawalAmount: sdk.ZeroInt(),
TotalWithdrawalAmount: sdkmath.ZeroInt(),
}
res := types.NewDeposit(
expected.Creator,
Expand Down
2 changes: 1 addition & 1 deletion x/house/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func validateMinimumDeposit(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.LTE(sdk.OneInt()) {
if v.LTE(sdkmath.OneInt()) {
return fmt.Errorf("minimum deposit must be positive and more than one: %d", v)
}

Expand Down
2 changes: 1 addition & 1 deletion x/house/types/withdraw_authorizaton.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a WithdrawAuthorization) ValidateBasic() error {
if a.WithdrawLimit.IsNil() {
return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be nil")
}
if a.WithdrawLimit.LTE(sdk.ZeroInt()) {
if a.WithdrawLimit.LTE(sdkmath.ZeroInt()) {
return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be less than or equal to zero")
}
if a.WithdrawLimit.GT(maxWithdrawGrant) {
Expand Down
3 changes: 1 addition & 2 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

Expand Down Expand Up @@ -57,7 +56,7 @@ func TestRandomizedGenState(t *testing.T) {
require.Equal(
t,
"0.000000000000000000",
mintGenesis.Minter.NextPhaseProvisions(sdk.OneInt(), types.DefaultExcludeAmount, types.NonePhase()).
mintGenesis.Minter.NextPhaseProvisions(sdkmath.OneInt(), types.DefaultExcludeAmount, types.NonePhase()).
String(),
)
require.Equal(t, "0.229787234042553191", params.GetPhaseAtStep(1).Inflation.String())
Expand Down
2 changes: 1 addition & 1 deletion x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func validateExcludeAmount(i interface{}) error {
return fmt.Errorf(ErrTextInvalidParamType, i)
}

if v.LT(sdk.ZeroInt()) {
if v.LT(sdkmath.ZeroInt()) {
return fmt.Errorf(ErrTextExcludeAmountMustBePositive, v)
}

Expand Down
6 changes: 3 additions & 3 deletions x/orderbook/keeper/bet_wager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (k Keeper) fulfillBetByParticipationQueue(

// the decimal amount that is being lost in the bet amount calculation from payout profit
truncatedBetAmount := sdk.NewDec(0)
requeThreshold := sdk.NewIntFromUint64(k.GetRequeueThreshold(ctx))
requeThreshold := sdkmath.NewIntFromUint64(k.GetRequeueThreshold(ctx))
// continue until updatedFulfillmentQueue gets empty
for fInfo.hasUnfulfilledQueueItem() {
var err error
Expand Down Expand Up @@ -464,7 +464,7 @@ func (fInfo *fulfillmentInfo) checkFullfillmentForOtherOdds(requeThreshold sdkma

// availableLiquidity is the available amount of tokens to be used from the participation exposure
fInfo.secondaryProcessItem.setAvailableLiquidity(betOdd.MaxLossMultiplier)
if fInfo.secondaryProcessItem.isLiquidityLessThanThreshold(requeThreshold, sdk.ZeroInt()) {
if fInfo.secondaryProcessItem.isLiquidityLessThanThreshold(requeThreshold, sdkmath.ZeroInt()) {
fInfo.inProcessItem.setFulfilledSecondary(&fInfo.secondaryProcessItem)
eUpdate = append(eUpdate, fInfo.secondaryProcessItem.participationExposure)
}
Expand Down Expand Up @@ -513,7 +513,7 @@ func (fItem *fulfillmentItem) isLiquidityLessThanThreshold(threshold, adjAmount
}

func (fItem *fulfillmentItem) noLiquidityAvailable() bool {
return fItem.availableLiquidity.LTE(sdk.ZeroInt())
return fItem.availableLiquidity.LTE(sdkmath.ZeroInt())
}

func (fItem *fulfillmentItem) setFulfilled() {
Expand Down
2 changes: 1 addition & 1 deletion x/orderbook/keeper/bet_wager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (ts *testBetSuite) bulkDepositPlaceBetsAndTest() {
OddsUID: ts.market.Odds[1].UID,
OddsValue: "4.415",
Amount: betAmount,
Fee: sdk.ZeroInt(),
Fee: sdkmath.ZeroInt(),
Status: bettypes.Bet_STATUS_PENDING,
Creator: bettorAddr.String(),
CreatedAt: cast.ToInt64(ts.ctx.BlockTime().Unix()),
Expand Down
5 changes: 3 additions & 2 deletions x/orderbook/keeper/exposure_odds.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

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

"github.com/sge-network/sge/x/orderbook/types"
Expand Down Expand Up @@ -92,8 +93,8 @@ func (k Keeper) initParticipationExposures(
pe := types.NewParticipationExposure(
orderBookUID,
boe.OddsUID,
sdk.ZeroInt(),
sdk.ZeroInt(),
sdkmath.ZeroInt(),
sdkmath.ZeroInt(),
participationIndex,
1,
false,
Expand Down
2 changes: 1 addition & 1 deletion x/orderbook/keeper/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (k Keeper) InitiateOrderBookParticipation(
index, book.UID, addr.String(),
book.OddsCount, // all odds need to be filled in the next steps
liquidity, feeAmount, liquidity, // int the start, liquidity and current round liquidity are the same
sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdkmath.Int{}, "", sdk.ZeroInt(),
sdkmath.ZeroInt(), sdkmath.ZeroInt(), sdkmath.ZeroInt(), sdkmath.Int{}, "", sdkmath.ZeroInt(),
)

// fund order book liquidity pool from participant's account.
Expand Down
4 changes: 2 additions & 2 deletions x/orderbook/keeper/participation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) {
{
desc: "no participation",
depositorAddr: simapp.TestParamUsers["user1"].Address,
depositAmount: sdk.ZeroInt(),
depositAmount: sdkmath.ZeroInt(),
withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL,
err: types.ErrOrderBookParticipationNotFound,
},
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) {
marketUID,
participationIndex,
tc.withdrawMode,
sdk.ZeroInt(),
sdkmath.ZeroInt(),
tc.depositAmount,
)

Expand Down
5 changes: 2 additions & 3 deletions x/orderbook/types/exposure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
yaml "gopkg.in/yaml.v2"

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

// NewOrderBookOddsExposure creates a new book odds exposure object
Expand Down Expand Up @@ -55,8 +54,8 @@ func (pe ParticipationExposure) NextRound() ParticipationExposure {
return NewParticipationExposure(
pe.OrderBookUID,
pe.OddsUID,
sdk.ZeroInt(),
sdk.ZeroInt(),
sdkmath.ZeroInt(),
sdkmath.ZeroInt(),
pe.ParticipationIndex,
pe.Round+1,
false,
Expand Down
20 changes: 10 additions & 10 deletions x/orderbook/types/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func (p *OrderBookParticipation) ValidateWithdraw(

// maxWithdrawalAmount returns the max withdrawal amount of a participation.
func (p *OrderBookParticipation) maxWithdrawalAmount() sdkmath.Int {
if p.CurrentRoundMaxLoss.LT(sdk.ZeroInt()) {
if p.CurrentRoundMaxLoss.LT(sdkmath.ZeroInt()) {
return p.CurrentRoundLiquidity
}
return p.CurrentRoundLiquidity.Sub(p.CurrentRoundMaxLoss)
}

// IsLiquidityInCurrentRound determines if the participation has liquidity in current round.
func (p *OrderBookParticipation) IsLiquidityInCurrentRound() bool {
return p.CurrentRoundLiquidity.GT(sdk.ZeroInt())
return p.CurrentRoundLiquidity.GT(sdkmath.ZeroInt())
}

// WithdrawableAmount returns the withdrawal amount according to the withdrawal mode and max withdrawable amount.
Expand All @@ -100,7 +100,7 @@ func (p *OrderBookParticipation) WithdrawableAmount(
var withdrawalAmt sdkmath.Int
switch mode {
case housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL:
if maxTransferableAmount.LTE(sdk.ZeroInt()) {
if maxTransferableAmount.LTE(sdkmath.ZeroInt()) {
return sdkmath.Int{}, sdkerrors.Wrapf(
ErrMaxWithdrawableAmountIsZero,
"%d, %d",
Expand Down Expand Up @@ -135,25 +135,25 @@ func (p *OrderBookParticipation) SetLiquidityAfterWithdrawal(withdrawalAmt sdkma
// NotParticipatedInBetFulfillment determines if the participation has
// participated in the bet fulfillment.
func (p *OrderBookParticipation) NotParticipatedInBetFulfillment() bool {
return p.TotalBetAmount.Equal(sdk.ZeroInt())
return p.TotalBetAmount.Equal(sdkmath.ZeroInt())
}

// IsEligibleForNextRound determines if the participation has enough
// liquidity to be used in the next round or not
func (p *OrderBookParticipation) IsEligibleForNextRound() bool {
return p.CurrentRoundLiquidity.GT(sdk.ZeroInt())
return p.CurrentRoundLiquidity.GT(sdkmath.ZeroInt())
}

// IsEligibleForNextRound determines if the participation has enough
// liquidity to be used in the next round or not
func (p *OrderBookParticipation) IsEligibleForNextRoundPreLiquidityReduction() bool {
maxLoss := sdk.MaxInt(sdk.ZeroInt(), p.CurrentRoundMaxLoss)
return p.CurrentRoundLiquidity.Sub(maxLoss).GT(sdk.ZeroInt())
maxLoss := sdk.MaxInt(sdkmath.ZeroInt(), p.CurrentRoundMaxLoss)
return p.CurrentRoundLiquidity.Sub(maxLoss).GT(sdkmath.ZeroInt())
}

// TrimCurrentRoundLiquidity subtracts the max loss from the current round liquidity.
func (p *OrderBookParticipation) TrimCurrentRoundLiquidity() {
maxLoss := sdk.MaxInt(sdk.ZeroInt(), p.CurrentRoundMaxLoss)
maxLoss := sdk.MaxInt(sdkmath.ZeroInt(), p.CurrentRoundMaxLoss)
p.CurrentRoundLiquidity = p.CurrentRoundLiquidity.Sub(maxLoss)
}

Expand All @@ -163,8 +163,8 @@ func (p *OrderBookParticipation) ResetForNextRound(notFilledExposures uint64) {
// prepare participation for the next round
p.ExposuresNotFilled = notFilledExposures
p.MaxLoss = p.MaxLoss.Add(p.CurrentRoundMaxLoss)
p.CurrentRoundTotalBetAmount = sdk.ZeroInt()
p.CurrentRoundMaxLoss = sdk.ZeroInt()
p.CurrentRoundTotalBetAmount = sdkmath.ZeroInt()
p.CurrentRoundMaxLoss = sdkmath.ZeroInt()
}

// SetCurrentRound sets the current round total bet amount and max loss.
Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createNCampaign(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Camp
items[i].RewardAmountType = types.RewardAmountType_REWARD_AMOUNT_TYPE_FIXED
items[i].IsActive = true
items[i].Meta = "campaign " + items[i].UID
items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Withdrawn: sdk.ZeroInt(), Total: sdkmath.NewInt(100)}
items[i].Pool = types.Pool{Spent: sdkmath.ZeroInt(), Withdrawn: sdkmath.ZeroInt(), Total: sdkmath.NewInt(100)}

keeper.SetCampaign(ctx, items[i])
}
Expand Down
5 changes: 3 additions & 2 deletions x/reward/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
sdkerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cast"

Expand All @@ -12,7 +13,7 @@ import (
// DistributeRewards distributes the rewards according to the input distribution list.
func (k Keeper) DistributeRewards(ctx sdk.Context, receiver types.Receiver) (uint64, error) {
unlockTS := uint64(0)
if receiver.RewardAmount.SubaccountAmount.GT(sdk.ZeroInt()) {
if receiver.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt()) {
moduleAccAddr := types.RewardPoolFunder{}.GetModuleAcc()
unlockTS = cast.ToUint64(ctx.BlockTime().Unix()) + receiver.RewardAmount.UnlockPeriod
if _, err := k.subaccountKeeper.TopUp(ctx, k.accountKeeper.GetModuleAddress(moduleAccAddr).String(), receiver.MainAccountAddr,
Expand All @@ -25,7 +26,7 @@ func (k Keeper) DistributeRewards(ctx sdk.Context, receiver types.Receiver) (uin
return unlockTS, sdkerrors.Wrapf(types.ErrSubaccountRewardTopUp, "subaccount address %s, %s", receiver.SubaccountAddr, err)
}
}
if receiver.RewardAmount.MainAccountAmount.GT(sdk.ZeroInt()) {
if receiver.RewardAmount.MainAccountAmount.GT(sdkmath.ZeroInt()) {
if err := k.modFunder.Refund(
types.RewardPoolFunder{}, ctx,
sdk.MustAccAddressFromBech32(receiver.MainAccountAddr),
Expand Down
Loading

0 comments on commit b701c7c

Please sign in to comment.