Skip to content

Commit

Permalink
1. use ZeroInt and LegacyZeroDec to replace NewInt(0) and `Lega…
Browse files Browse the repository at this point in the history
…cyNewDec(0)`

2. refine the command format and description of voting power snapshot
  • Loading branch information
TimmyExogenous committed Nov 10, 2024
1 parent f6def84 commit f6bf40d
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 146 deletions.
4 changes: 2 additions & 2 deletions app/ante/cosmos/min_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
err := suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
true,
Expand Down Expand Up @@ -96,7 +96,7 @@ func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
err := suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
false,
Expand Down
2 changes: 1 addition & 1 deletion app/ante/evm/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *AnteTestSuite) TestEthMinGasPriceDecorator() {
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn",
Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}},
}
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
false,
Expand Down
2 changes: 1 addition & 1 deletion precompiles/assets/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (p Precompile) RegisterToken(

stakingAsset := &assetstypes.StakingAssetInfo{
AssetBasicInfo: asset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
}

if err := p.assetsKeeper.RegisterNewTokenAndSetTokenFeeder(ctx, &oInfo); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avs/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func (suite *AVSManagerPrecompileSuite) TestRunRegTaskInfo() {
suite.Ctx,
&assetstypes.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down
10 changes: 5 additions & 5 deletions precompiles/avs/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOptedInOperatorAccAddrs() {

func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
method := s.precompile.Methods[avsManagerPrecompile.MethodGetAVSUSDValue]
expectedUSDvalue := sdkmath.LegacyNewDec(0)
expectedUSDvalue := sdkmath.LegacyZeroDec()

setUp := func() {
suite.prepare()
Expand All @@ -163,7 +163,7 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
suite.Ctx,
&assetstype.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down Expand Up @@ -233,7 +233,7 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {

func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
method := s.precompile.Methods[avsManagerPrecompile.MethodGetOperatorOptedUSDValue]
expectedUSDvalue := sdkmath.LegacyNewDec(0)
expectedUSDvalue := sdkmath.LegacyZeroDec()

setUp := func() {
suite.prepare()
Expand All @@ -251,7 +251,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
suite.Ctx,
&assetstype.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down Expand Up @@ -509,7 +509,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetTaskInfo() {
TaskResponsePeriod: 10,
StartingEpoch: 5,
TaskStatisticalPeriod: 60,
TaskTotalPower: sdk.Dec(sdkmath.NewInt(0)),
TaskTotalPower: sdk.Dec(sdkmath.ZeroInt()),
}
err := suite.App.AVSManagerKeeper.SetTaskInfo(suite.Ctx, info)
suite.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions precompiles/avs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func (suite *AVSManagerPrecompileSuite) TestOptOut() {
OptedInHeight: uint64(optInHeight),
OptedOutHeight: uint64(suite.Ctx.BlockHeight()),
},
AVSTotalShare: sdkmath.LegacyNewDec(0),
AVSOperatorShare: sdkmath.LegacyNewDec(0),
AVSTotalShare: sdkmath.LegacyZeroDec(),
AVSOperatorShare: sdkmath.LegacyZeroDec(),
AssetState: nil,
OperatorShare: sdkmath.LegacyDec{},
StakerShare: sdkmath.LegacyDec{},
Expand Down
7 changes: 5 additions & 2 deletions proto/exocore/operator/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ message OperatorVotingPower {
];
}

// VotingPowerSnapshot is used to record the historical voting power for AVSs
// VotingPowerSnapshot records historical voting power for AVSs at specific epochs
// or after slashing events.These snapshots are created at the end of each epoch and
// when slashing occurs, enabling historical queries of operator voting power at
// specific points in time.
message VotingPowerSnapshot {
// total_voting_power is the total voting power of specified AVS
string total_voting_power = 1
Expand All @@ -78,7 +81,7 @@ message VotingPowerSnapshot {
// for the specified AVS
repeated OperatorVotingPower operator_voting_powers = 2;
// last_changed_height is used to indicate the height of most recent change when
// the voting_power_set is nil, which can help to fall back to the correct epoch height.
// the operator_voting_powers is nil, which can help to fall back to the correct epoch height.
int64 last_changed_height = 3;
// epoch_identifier record the epoch info
string epoch_identifier = 4;
Expand Down
2 changes: 1 addition & 1 deletion types/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func SafeInt64(value uint64) (int64, error) {
// SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits
func SafeNewIntFromBigInt(i *big.Int) (sdkmath.Int, error) {
if !IsValidInt256(i) {
return sdkmath.NewInt(0), fmt.Errorf("big int out of bound: %s", i)
return sdkmath.ZeroInt(), fmt.Errorf("big int out of bound: %s", i)
}
return sdkmath.NewIntFromBigInt(i), nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k *Keeper) GetAVSSlashContract(ctx sdk.Context, avsAddr string) (string, e
func (k *Keeper) GetAVSMinimumSelfDelegation(ctx sdk.Context, avsAddr string) (sdkmath.LegacyDec, error) {
avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
if err != nil {
return sdkmath.LegacyNewDec(0), errorsmod.Wrap(err, fmt.Sprintf("GetAVSMinimumSelfDelegation: key is %s", avsAddr))
return sdkmath.LegacyZeroDec(), errorsmod.Wrap(err, fmt.Sprintf("GetAVSMinimumSelfDelegation: key is %s", avsAddr))
}
// #nosec G115
return sdkmath.LegacyNewDec(int64(avsInfo.Info.MinSelfDelegation)), nil
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/impl_epoch_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (wrapper EpochsHooksWrapper) AfterEpochEnd(
var taskAddr string
var avsAddr string
var operatorPowers []*types.OperatorActivePowerInfo
operatorPowerTotal := sdkmath.LegacyNewDec(0)
operatorPowerTotal := sdkmath.LegacyZeroDec()
for _, res := range value {
// Find signed operators
if res.BlsSignature != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/submit_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (suite *AVSTestSuite) prepareTaskInfo() {
StartingEpoch: uint64(epoch.CurrentEpoch + 1),
ActualThreshold: 0,
OptInOperators: operatorList,
TaskTotalPower: sdk.Dec(sdkmath.NewInt(0)),
TaskTotalPower: sdk.Dec(sdkmath.ZeroInt()),
}
err = suite.App.AVSManagerKeeper.SetTaskInfo(suite.Ctx, info)
suite.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (suite *AVSTestSuite) TestTaskInfo() {
TaskResponsePeriod: 10000,
TaskChallengePeriod: 5000,
ThresholdPercentage: 60,
TaskTotalPower: sdk.Dec(sdkmath.NewInt(0)),
TaskTotalPower: sdk.Dec(sdkmath.ZeroInt()),
}
err := suite.App.AVSManagerKeeper.SetTaskInfo(suite.Ctx, info)
suite.NoError(err)
Expand Down
68 changes: 34 additions & 34 deletions x/delegation/keeper/delegation_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,23 @@ func (suite *DelegationTestSuite) TestDelegateTo() {
suite.Equal(types.StakerAssetInfo{
TotalDepositAmount: suite.depositAmount,
WithdrawableAmount: suite.depositAmount.Sub(delegationParams.OpAmount),
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
}, *restakerState)

operatorState, err := suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, opAccAddr, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: delegationParams.OpAmount,
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
TotalShare: sdkmath.LegacyNewDecFromBigInt(delegationParams.OpAmount.BigInt()),
OperatorShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err := suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, opAccAddr.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
UndelegatableShare: sdkmath.LegacyNewDecFromBigInt(delegationParams.OpAmount.BigInt()),
WaitUndelegationAmount: sdkmath.NewInt(0),
WaitUndelegationAmount: sdkmath.ZeroInt(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err := suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
Expand Down Expand Up @@ -163,22 +163,22 @@ func (suite *DelegationTestSuite) TestDelegateTo() {
suite.Equal(types.StakerAssetInfo{
TotalDepositAmount: balance.Amount.Add(delegationParams.OpAmount),
WithdrawableAmount: balance.Amount,
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
}, *restakerState)
operatorState, err = suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, opAccAddr, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: delegationParams.OpAmount,
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
TotalShare: sdkmath.LegacyNewDecFromBigInt(delegationParams.OpAmount.BigInt()),
OperatorShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err = suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, opAccAddr.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
UndelegatableShare: sdkmath.LegacyNewDecFromBigInt(delegationParams.OpAmount.BigInt()),
WaitUndelegationAmount: sdkmath.NewInt(0),
WaitUndelegationAmount: sdkmath.ZeroInt(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err = suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
Expand Down Expand Up @@ -208,22 +208,22 @@ func (suite *DelegationTestSuite) TestUndelegateFrom() {
operatorState, err := suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, delegationEvent.OperatorAddress, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: sdkmath.NewInt(0),
TotalAmount: sdkmath.ZeroInt(),
PendingUndelegationAmount: delegationEvent.OpAmount,
TotalShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyNewDec(0),
TotalShare: sdkmath.LegacyZeroDec(),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err := suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, delegationEvent.OperatorAddress.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
WaitUndelegationAmount: delegationEvent.OpAmount,
UndelegatableShare: sdkmath.LegacyNewDec(0),
UndelegatableShare: sdkmath.LegacyZeroDec(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err := suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
suite.NoError(err)
suite.Equal(sdkmath.NewInt(0), totalDelegationAmount)
suite.Equal(sdkmath.ZeroInt(), totalDelegationAmount)

records, err := suite.App.DelegationKeeper.GetStakerUndelegationRecords(suite.Ctx, stakerID, assetID)
suite.NoError(err)
Expand Down Expand Up @@ -267,22 +267,22 @@ func (suite *DelegationTestSuite) TestUndelegateFrom() {
operatorState, err = suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, delegationEvent.OperatorAddress, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: sdkmath.NewInt(0),
TotalAmount: sdkmath.ZeroInt(),
PendingUndelegationAmount: delegationEvent.OpAmount,
TotalShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyNewDec(0),
TotalShare: sdkmath.LegacyZeroDec(),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err = suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, delegationEvent.OperatorAddress.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
WaitUndelegationAmount: delegationEvent.OpAmount,
UndelegatableShare: sdkmath.LegacyNewDec(0),
UndelegatableShare: sdkmath.LegacyZeroDec(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err = suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
suite.NoError(err)
suite.Equal(sdkmath.NewInt(0), totalDelegationAmount)
suite.Equal(sdkmath.ZeroInt(), totalDelegationAmount)

records, err = suite.App.DelegationKeeper.GetStakerUndelegationRecords(suite.Ctx, stakerID, assetID)
suite.NoError(err)
Expand Down Expand Up @@ -351,28 +351,28 @@ func (suite *DelegationTestSuite) TestCompleteUndelegation() {
suite.Equal(types.StakerAssetInfo{
TotalDepositAmount: suite.depositAmount,
WithdrawableAmount: suite.depositAmount,
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
}, *restakerState)

operatorState, err := suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, delegationEvent.OperatorAddress, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.NewInt(0),
TotalShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyNewDec(0),
TotalAmount: sdkmath.ZeroInt(),
PendingUndelegationAmount: sdkmath.ZeroInt(),
TotalShare: sdkmath.LegacyZeroDec(),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err := suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, delegationEvent.OperatorAddress.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
UndelegatableShare: sdkmath.LegacyNewDec(0),
WaitUndelegationAmount: sdkmath.NewInt(0),
UndelegatableShare: sdkmath.LegacyZeroDec(),
WaitUndelegationAmount: sdkmath.ZeroInt(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err := suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
suite.NoError(err)
suite.Equal(sdkmath.NewInt(0), totalDelegationAmount)
suite.Equal(sdkmath.ZeroInt(), totalDelegationAmount)

records, err := suite.App.DelegationKeeper.GetStakerUndelegationRecords(suite.Ctx, stakerID, assetID)
suite.NoError(err)
Expand Down Expand Up @@ -419,28 +419,28 @@ func (suite *DelegationTestSuite) TestCompleteUndelegation() {
suite.Equal(types.StakerAssetInfo{
TotalDepositAmount: balance.Amount,
WithdrawableAmount: balance.Amount,
PendingUndelegationAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.ZeroInt(),
}, *restakerState)

operatorState, err = suite.App.AssetsKeeper.GetOperatorSpecifiedAssetInfo(suite.Ctx, delegationEvent.OperatorAddress, assetID)
suite.NoError(err)
suite.Equal(types.OperatorAssetInfo{
TotalAmount: sdkmath.NewInt(0),
PendingUndelegationAmount: sdkmath.NewInt(0),
TotalShare: sdkmath.LegacyNewDec(0),
OperatorShare: sdkmath.LegacyNewDec(0),
TotalAmount: sdkmath.ZeroInt(),
PendingUndelegationAmount: sdkmath.ZeroInt(),
TotalShare: sdkmath.LegacyZeroDec(),
OperatorShare: sdkmath.LegacyZeroDec(),
}, *operatorState)

specifiedDelegationAmount, err = suite.App.DelegationKeeper.GetSingleDelegationInfo(suite.Ctx, stakerID, assetID, delegationEvent.OperatorAddress.String())
suite.NoError(err)
suite.Equal(delegationtype.DelegationAmounts{
UndelegatableShare: sdkmath.LegacyNewDec(0),
WaitUndelegationAmount: sdkmath.NewInt(0),
UndelegatableShare: sdkmath.LegacyZeroDec(),
WaitUndelegationAmount: sdkmath.ZeroInt(),
}, *specifiedDelegationAmount)

totalDelegationAmount, err = suite.App.DelegationKeeper.TotalDelegatedAmountForStakerAsset(suite.Ctx, stakerID, assetID)
suite.NoError(err)
suite.Equal(sdkmath.NewInt(0), totalDelegationAmount)
suite.Equal(sdkmath.ZeroInt(), totalDelegationAmount)

records, err = suite.App.DelegationKeeper.GetStakerUndelegationRecords(suite.Ctx, stakerID, assetID)
suite.NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions x/delegation/keeper/delegation_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k Keeper) IterateDelegationsForStaker(ctx sdk.Context, stakerID string, op
// TotalDelegatedAmountForStakerAsset query the total delegation amount of the specified staker and asset.
// It needs to be calculated from the share and amount of the asset pool.
func (k Keeper) TotalDelegatedAmountForStakerAsset(ctx sdk.Context, stakerID string, assetID string) (amount sdkmath.Int, err error) {
amount = sdkmath.NewInt(0)
amount = sdkmath.ZeroInt()
opFunc := func(keys *delegationtype.SingleDelegationInfoReq, amounts *delegationtype.DelegationAmounts) (bool, error) {
if amounts.UndelegatableShare.IsZero() {
return false, nil
Expand Down Expand Up @@ -143,8 +143,8 @@ func (k Keeper) UpdateDelegationState(ctx sdk.Context, stakerID, assetID, opAddr
}
singleStateKey := assetstype.GetJoinedStoreKey(stakerID, assetID, opAddr)
delegationState := delegationtype.DelegationAmounts{
WaitUndelegationAmount: sdkmath.NewInt(0),
UndelegatableShare: sdkmath.LegacyNewDec(0),
WaitUndelegationAmount: sdkmath.ZeroInt(),
UndelegatableShare: sdkmath.LegacyZeroDec(),
}

value := store.Get(singleStateKey)
Expand Down Expand Up @@ -305,7 +305,7 @@ func (k *Keeper) SetStakerShareToZero(ctx sdk.Context, operator, assetID string,
if value != nil {
delegationState := delegationtype.DelegationAmounts{}
k.cdc.MustUnmarshal(value, &delegationState)
delegationState.UndelegatableShare = sdkmath.LegacyNewDec(0)
delegationState.UndelegatableShare = sdkmath.LegacyZeroDec()
bz := k.cdc.MustMarshal(&delegationState)
store.Set(singleStateKey, bz)
}
Expand Down
6 changes: 3 additions & 3 deletions x/delegation/keeper/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
// caused by the bankers rounding.
func TokensFromShares(stakerShare, totalShare sdkmath.LegacyDec, totalAmount sdkmath.Int) (sdkmath.Int, error) {
if stakerShare.GT(totalShare) {
return sdkmath.NewInt(0), errorsmod.Wrapf(delegationtypes.ErrInsufficientShares, "the stakerShare is:%v the totalShare is:%v", stakerShare, totalShare)
return sdkmath.ZeroInt(), errorsmod.Wrapf(delegationtypes.ErrInsufficientShares, "the stakerShare is:%v the totalShare is:%v", stakerShare, totalShare)
}
if totalShare.IsZero() {
if totalAmount.IsZero() {
// this can happen if everyone exits.
return sdkmath.NewInt(0), nil
return sdkmath.ZeroInt(), nil
}
return sdkmath.NewInt(0), delegationtypes.ErrDivisorIsZero
return sdkmath.ZeroInt(), delegationtypes.ErrDivisorIsZero
}
return (stakerShare.MulInt(totalAmount)).Quo(totalShare).TruncateInt(), nil
}
Expand Down
Loading

0 comments on commit f6bf40d

Please sign in to comment.