@@ -231,24 +231,21 @@ access(all) contract IncrementFiStakingConnectors {
231231 return 0.0 // no capacity if the staking pool is not available
232232 }
233233
234- /// Withdraws rewards from the staking pool up to the specified maximum amount
235- /// Overflow rewards are sent to the appropriate overflow sinks if provided
234+ /// Withdraws rewards from the staking pool up to the specified maximum amount.
235+ /// Panics if the claimed rewards exceed maxAmount, as the staking pool does not support partial claims.
236+ /// Callers must ensure maxAmount >= minimumAvailable() to avoid a panic.
236237 ///
237- /// @param maxAmount: The maximum amount of rewards to claim. Currently ignored and the entire reward vault is claimed.
238+ /// @param maxAmount: The maximum amount of rewards to claim. The full reward balance is claimed and must not exceed this value .
238239 /// @return a Vault containing the claimed rewards
239240 ///
240- access (FungibleToken.Withdraw ) fun withdrawAvailable (maxAmount _ : UFix64 ): @{FungibleToken .Vault } {
241+ access (FungibleToken.Withdraw ) fun withdrawAvailable (maxAmount : UFix64 ): @{FungibleToken .Vault } {
241242 let minimumAvailable = self .minimumAvailable ()
242243 if minimumAvailable == 0.0 {
243244 return <- DeFiActionsUtils .getEmptyVault (self .getSourceType ())
244245 }
245246
246247 if let pool = IncrementFiStakingConnectors .borrowPool (pid : self .pid ) {
247248 if let userCertificate = self .userCertificate .borrow () {
248- // let withdrawAmount = maxAmount < minimumAvailable
249- // ? maxAmount
250- // : minimumAvailable
251-
252249 let rewards <- pool .claimRewards (userCertificate : userCertificate )
253250 let targetSliceType = SwapConfig .SliceTokenTypeIdentifierFromVaultType (vaultTypeIdentifier : self .vaultType .identifier )
254251
@@ -265,6 +262,10 @@ access(all) contract IncrementFiStakingConnectors {
265262 )
266263 let reward <- rewards .remove (key : rewards .keys [0 ])!
267264 destroy rewards
265+ assert (
266+ reward .balance < = maxAmount ,
267+ message : " Claimed reward balance \( reward .balance ) exceeds maxAmount \( maxAmount ) . The staking pool does not support partial claims — callers must ensure maxAmount >= minimumAvailable()."
268+ )
268269 return <- reward
269270 }
270271 }
0 commit comments