From d28e18e9433c9d2cc8aa5c47e571c0efc8b0a05f Mon Sep 17 00:00:00 2001 From: j75689 Date: Mon, 15 Jan 2024 10:44:24 +0800 Subject: [PATCH 1/2] fix: do not charge relayerFee for auto cross undelegate after SecondSunsetFork --- x/stake/keeper/delegation.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index b4c1c66f2..8b2dbda0b 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -879,8 +879,14 @@ func (k Keeper) crossDistributeUndelegated(ctx sdk.Context, delAddr sdk.AccAddre if relayFee.Tokens.AmountOf(denom) >= amount { return sdk.Events{}, ErrNotEnoughRelayerFeeForCrossPkg } + bscRelayFee := bsc.ConvertBCAmountToBSCAmount(relayFee.Tokens.AmountOf(denom)) - bscTransferAmount := new(big.Int).Sub(bsc.ConvertBCAmountToBSCAmount(amount), bscRelayFee) + var bscTransferAmount *big.Int + if sdk.IsUpgrade(sdk.SecondSunsetFork) && k.IsAutoUnDelegate(ctx, delAddr, valAddr) { + bscTransferAmount = bsc.ConvertBCAmountToBSCAmount(amount) + } else { + bscTransferAmount = new(big.Int).Sub(bsc.ConvertBCAmountToBSCAmount(amount), bscRelayFee) + } delBscAddrAcc := types.GetStakeCAoB(delAddr.Bytes(), types.DelegateCAoBSalt) delBscAddr := hex.EncodeToString(delBscAddrAcc.Bytes()) From ba07eb06feec642fd964b14382baf9323959ea4a Mon Sep 17 00:00:00 2001 From: j75689 Date: Mon, 15 Jan 2024 11:07:11 +0800 Subject: [PATCH 2/2] fix: FeeCalculator --- x/stake/keeper/delegation.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index 8b2dbda0b..96bd91863 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -871,7 +871,13 @@ func (k Keeper) ValidateUnbondAmount( func (k Keeper) crossDistributeUndelegated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Events, sdk.Error) { denom := k.BondDenom(ctx) amount := k.BankKeeper.GetCoins(ctx, delAddr).AmountOf(denom) - relayFeeCalc := fees.GetCalculator(types.CrossDistributeUndelegatedRelayFee) + + var relayFeeCalc fees.FeeCalculator + if sdk.IsUpgrade(sdk.SecondSunsetFork) && k.IsAutoUnDelegate(ctx, delAddr, valAddr) { + relayFeeCalc = fees.FreeFeeCalculator() + } else { + relayFeeCalc = fees.GetCalculator(types.CrossDistributeUndelegatedRelayFee) + } if relayFeeCalc == nil { return sdk.Events{}, ErrNoFeeCalculator } @@ -881,12 +887,7 @@ func (k Keeper) crossDistributeUndelegated(ctx sdk.Context, delAddr sdk.AccAddre } bscRelayFee := bsc.ConvertBCAmountToBSCAmount(relayFee.Tokens.AmountOf(denom)) - var bscTransferAmount *big.Int - if sdk.IsUpgrade(sdk.SecondSunsetFork) && k.IsAutoUnDelegate(ctx, delAddr, valAddr) { - bscTransferAmount = bsc.ConvertBCAmountToBSCAmount(amount) - } else { - bscTransferAmount = new(big.Int).Sub(bsc.ConvertBCAmountToBSCAmount(amount), bscRelayFee) - } + bscTransferAmount := new(big.Int).Sub(bsc.ConvertBCAmountToBSCAmount(amount), bscRelayFee) delBscAddrAcc := types.GetStakeCAoB(delAddr.Bytes(), types.DelegateCAoBSalt) delBscAddr := hex.EncodeToString(delBscAddrAcc.Bytes())