Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit a2cb8fb

Browse files
authored
reverts ibc from delegation account to puneet/handle-deposits-to-delegation-acc account, removes delegation acc from c_value. (#386)
1 parent 0e6face commit a2cb8fb

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

x/lscosmos/keeper/c_value.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ func (k Keeper) GetDepositAccountAmount(ctx sdk.Context) sdk.Int {
2121
).Amount
2222
}
2323

24-
// GetDelegationAccountAmount returns the delegation account amount of the IBC denom
25-
func (k Keeper) GetDelegationAccountAmount(ctx sdk.Context) sdk.Int {
26-
return k.bankKeeper.GetBalance(
27-
ctx,
28-
authtypes.NewModuleAddress(types.DelegationModuleAccount),
29-
k.GetIBCDenom(ctx),
30-
).Amount
31-
}
32-
3324
// GetIBCTransferTransientAmount returns the IBC transfer transient amount of the IBC denom
3425
func (k Keeper) GetIBCTransferTransientAmount(ctx sdk.Context) sdk.Int {
3526
transferAmount := k.GetIBCTransientStore(ctx).IBCTransfer
@@ -70,7 +61,6 @@ func (k Keeper) GetHostDelegationAccountAmount(ctx sdk.Context) sdk.Int {
7061
// function is called. Returns 1 if stakedAmount or mintedAmount is zero.
7162
func (k Keeper) GetCValue(ctx sdk.Context) sdk.Dec {
7263
stakedAmount := k.GetDepositAccountAmount(ctx).
73-
Add(k.GetDelegationAccountAmount(ctx)).
7464
Add(k.GetIBCTransferTransientAmount(ctx)).
7565
Add(k.GetDelegationTransientAmount(ctx)).
7666
Add(k.GetStakedAmount(ctx)).

x/lscosmos/keeper/c_value_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (suite *IntegrationTestSuite) TestCValue() {
8989
)
9090
suite.NoError(err)
9191

92+
// Delegation module account should not be counted in c_value.
9293
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx,
9394
types.ModuleName,
9495
types.DelegationModuleAccount,
@@ -97,15 +98,15 @@ func (suite *IntegrationTestSuite) TestCValue() {
9798
suite.NoError(err)
9899

99100
cValue = lscosmosKeeper.GetCValue(ctx)
100-
suite.Equal(sdk.NewDecWithPrec(979431929480901077, 18), cValue)
101+
suite.Equal(sdk.NewDecWithPrec(989119683481701286, 18), cValue)
101102

102103
cValue = lscosmosKeeper.GetCValue(ctx)
103104
tokenValue, residue = lscosmosKeeper.ConvertStkToToken(ctx, sdk.NewDecCoin(lscosmosKeeper.GetHostChainParams(ctx).MintDenom, sdk.NewInt(1000000)), cValue)
104-
suite.True(sdk.NewInt64Coin(lscosmosKeeper.GetIBCDenom(ctx), 1021000).IsEqual(tokenValue))
105+
suite.True(sdk.NewInt64Coin(lscosmosKeeper.GetIBCDenom(ctx), 1011000).IsEqual(tokenValue))
105106
suite.True(sdk.NewDecCoinFromDec(lscosmosKeeper.GetIBCDenom(ctx), sdk.ZeroDec()).IsEqual(residue))
106107

107108
cValue = lscosmosKeeper.GetCValue(ctx)
108109
stkValue, residue = lscosmosKeeper.ConvertTokenToStk(ctx, sdk.NewDecCoin(lscosmosKeeper.GetIBCDenom(ctx), sdk.NewInt(1000000)), cValue)
109-
suite.True(sdk.NewInt64Coin(lscosmosKeeper.GetHostChainParams(ctx).MintDenom, 979431).IsEqual(stkValue))
110-
suite.True(sdk.NewDecCoinFromDec(lscosmosKeeper.GetHostChainParams(ctx).MintDenom, sdk.NewDecWithPrec(929480901077000000, 18)).IsEqual(residue))
110+
suite.True(sdk.NewInt64Coin(lscosmosKeeper.GetHostChainParams(ctx).MintDenom, 989119).IsEqual(stkValue))
111+
suite.True(sdk.NewDecCoinFromDec(lscosmosKeeper.GetHostChainParams(ctx).MintDenom, sdk.NewDecWithPrec(683481701286000000, 18)).IsEqual(residue))
111112
}

x/lscosmos/keeper/hooks.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (k Keeper) DelegationEpochWorkFlow(ctx sdk.Context, hostChainParams lscosmo
124124
}
125125
allDelegationBalances := k.bankKeeper.GetAllBalances(ctx, authtypes.NewModuleAddress(lscosmostypes.DelegationModuleAccount))
126126
delegationBalance := sdk.NewCoin(ibcDenom, allDelegationBalances.AmountOf(ibcDenom))
127-
if delegationBalance.IsPositive() {
127+
if delegationBalance.IsPositive() && depositBalance.IsPositive() && delegationBalance.IsGTE(depositBalance) {
128128
delegationState := k.GetDelegationState(ctx)
129129
_, clientState, err := k.channelKeeper.GetChannelClientState(ctx, hostChainParams.TransferPort, hostChainParams.TransferChannel)
130130
if err != nil {
@@ -134,7 +134,7 @@ func (k Keeper) DelegationEpochWorkFlow(ctx sdk.Context, hostChainParams lscosmo
134134
timeoutHeight := clienttypes.NewHeight(clientState.GetLatestHeight().GetRevisionNumber(), clientState.GetLatestHeight().GetRevisionHeight()+lscosmostypes.IBCTimeoutHeightIncrement)
135135

136136
msg := ibctransfertypes.NewMsgTransfer(hostChainParams.TransferPort, hostChainParams.TransferChannel,
137-
delegationBalance, authtypes.NewModuleAddress(lscosmostypes.DelegationModuleAccount).String(),
137+
depositBalance, authtypes.NewModuleAddress(lscosmostypes.DelegationModuleAccount).String(),
138138
delegationState.HostChainDelegationAddress, timeoutHeight, 0)
139139

140140
handler := k.msgRouter.Handler(msg)
@@ -144,14 +144,14 @@ func (k Keeper) DelegationEpochWorkFlow(ctx sdk.Context, hostChainParams lscosmo
144144
k.Logger(ctx).Error(fmt.Sprintf("could not send transfer msg via MsgServiceRouter, error: %s", err))
145145
return err
146146
}
147-
k.AddIBCTransferToTransientStore(ctx, delegationBalance)
147+
k.AddIBCTransferToTransientStore(ctx, depositBalance)
148148

149149
ctx.EventManager().EmitEvents(res.GetEvents())
150150
}
151151
// move extra tokens to pstake address - anyone can send tokens to delegation address.
152152
// deposit address is deny-listed address - can only accept tokens via transactions, so should not have any extra tokens
153153
// should be transferred to pstake address.
154-
remainingDelegationBalance := allDelegationBalances.Sub(sdk.NewCoins(delegationBalance))
154+
remainingDelegationBalance := k.bankKeeper.GetAllBalances(ctx, authtypes.NewModuleAddress(lscosmostypes.DelegationModuleAccount))
155155

156156
if remainingDelegationBalance.IsAllPositive() {
157157
feeAddr, err := sdk.AccAddressFromBech32(hostChainParams.PstakeParams.PstakeFeeAddress)
@@ -375,7 +375,8 @@ func (k Keeper) OnTimeoutIBCTransferPacket(ctx sdk.Context, packet channeltypes.
375375
}
376376
ibcDenom := ibctransfertypes.ParseDenomTrace(data.GetDenom())
377377
k.RemoveIBCTransferFromTransientStore(ctx, sdk.NewCoin(ibcDenom.IBCDenom(), amount))
378-
return nil
378+
//move tokens to deposit account
379+
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, lscosmostypes.DelegationModuleAccount, lscosmostypes.DepositModuleAccount, sdk.NewCoins(sdk.NewCoin(ibcDenom.IBCDenom(), amount)))
379380
}
380381

381382
type IBCTransferHooks struct {

0 commit comments

Comments
 (0)