@@ -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
381382type IBCTransferHooks struct {
0 commit comments