diff --git a/cadence/contracts/connectors/SwapConnectors.cdc b/cadence/contracts/connectors/SwapConnectors.cdc index 21d9986..2fd651c 100644 --- a/cadence/contracts/connectors/SwapConnectors.cdc +++ b/cadence/contracts/connectors/SwapConnectors.cdc @@ -505,7 +505,7 @@ access(all) contract SwapConnectors { /// @return a Vault of type `outVault` containing the swapped currency. /// access(self) - fun _swap(quote: {DeFiActions.Quote}?, from: @{FungibleToken.Vault}, reverse: Bool): @{FungibleToken.Vault} { + fun _swap(quote _: {DeFiActions.Quote}?, from: @{FungibleToken.Vault}, reverse: Bool): @{FungibleToken.Vault} { let range = reverse ? InclusiveRange(self.swappers.length - 1, 0, step: -1) : InclusiveRange(0, self.swappers.length - 1) diff --git a/cadence/contracts/connectors/evm/ERC4626SwapConnectors.cdc b/cadence/contracts/connectors/evm/ERC4626SwapConnectors.cdc index 73a032a..df85bbd 100644 --- a/cadence/contracts/connectors/evm/ERC4626SwapConnectors.cdc +++ b/cadence/contracts/connectors/evm/ERC4626SwapConnectors.cdc @@ -289,7 +289,7 @@ access(all) contract ERC4626SwapConnectors { /// /// @return A vault containing the original input tokens (not supported - always panics) /// - access(all) fun swapBack(quote: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} { + access(all) fun swapBack(quote _: {DeFiActions.Quote}?, residual _1: @{FungibleToken.Vault}): @{FungibleToken.Vault} { panic("ERC4626SwapConnectors.Swapper.swapBack() is not supported - ERC4626 Vaults do not support synchronous withdrawals") } /// Returns a ComponentInfo struct containing information about this component and a list of ComponentInfo for diff --git a/cadence/contracts/connectors/evm/UniswapV2SwapConnectors.cdc b/cadence/contracts/connectors/evm/UniswapV2SwapConnectors.cdc index a82d585..d847737 100644 --- a/cadence/contracts/connectors/evm/UniswapV2SwapConnectors.cdc +++ b/cadence/contracts/connectors/evm/UniswapV2SwapConnectors.cdc @@ -201,7 +201,7 @@ access(all) contract UniswapV2SwapConnectors { /// access(self) fun swapExactTokensForTokens( exactVaultIn: @{FungibleToken.Vault}, - amountOutMin: UFix64, + amountOutMin _: UFix64, reverse: Bool ): @{FungibleToken.Vault} { let id = self.uniqueID?.id?.toString() ?? "UNASSIGNED" diff --git a/cadence/contracts/connectors/increment-fi/IncrementFiPoolLiquidityConnectors.cdc b/cadence/contracts/connectors/increment-fi/IncrementFiPoolLiquidityConnectors.cdc index eca677d..2a62dfe 100644 --- a/cadence/contracts/connectors/increment-fi/IncrementFiPoolLiquidityConnectors.cdc +++ b/cadence/contracts/connectors/increment-fi/IncrementFiPoolLiquidityConnectors.cdc @@ -245,7 +245,7 @@ access(all) contract IncrementFiPoolLiquidityConnectors { let pairPublicRef = self.getPairPublicRef() let token0Key = SwapConfig.SliceTokenTypeIdentifierFromVaultType(vaultTypeIdentifier: self.token0Type.identifier) - let token1Key = SwapConfig.SliceTokenTypeIdentifierFromVaultType(vaultTypeIdentifier: self.token1Type.identifier) + if (!reverse) { // Calculate how much to zap from token0 to token1 let zappedAmount = self.calculateZappedAmount(forProvided: forProvided, pairPublicRef: pairPublicRef) @@ -309,7 +309,7 @@ access(all) contract IncrementFiPoolLiquidityConnectors { } /// Converts inToken to LP token - access(all) fun swap(quote: {DeFiActions.Quote}?, inVault: @{FungibleToken.Vault}): @{FungibleToken.Vault} { + access(all) fun swap(quote _: {DeFiActions.Quote}?, inVault: @{FungibleToken.Vault}): @{FungibleToken.Vault} { let pairPublicRef = self.getPairPublicRef() let zappedAmount = self.calculateZappedAmount(forProvided: inVault.balance, pairPublicRef: pairPublicRef) @@ -328,7 +328,7 @@ access(all) contract IncrementFiPoolLiquidityConnectors { } /// Converts back LP token to inToken - access(all) fun swapBack(quote: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} { + access(all) fun swapBack(quote _: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} { let pairPublicRef = self.getPairPublicRef() // Remove liquidity @@ -437,7 +437,7 @@ access(all) contract IncrementFiPoolLiquidityConnectors { let reserveAft1 = token1Reserve - amountOut let ratioUser = (forProvided - midAmount) / amountOut let ratioPool = reserveAft0 / reserveAft1 - var ratioBias = 0.0 + if (ratioUser >= ratioPool) { if (ratioUser - ratioPool) <= SwapConfig.ufix64NonZeroMin { break @@ -629,7 +629,7 @@ access(all) contract IncrementFiPoolLiquidityConnectors { // Returns the maximum amount of LP tokens that can be minted // It's bound by the reserves of token1 that can be swapped to token0 access(self) fun getMaxLpMintAmount( - pairPublicRef: &{SwapInterfaces.PairPublic}, + pairPublicRef _: &{SwapInterfaces.PairPublic}, ): UFix64 { let quote = self.quoteOut(forProvided: UFix64.max, reverse: false) return quote.outAmount diff --git a/cadence/contracts/connectors/increment-fi/IncrementFiStakingConnectors.cdc b/cadence/contracts/connectors/increment-fi/IncrementFiStakingConnectors.cdc index b12eb1c..09f185d 100644 --- a/cadence/contracts/connectors/increment-fi/IncrementFiStakingConnectors.cdc +++ b/cadence/contracts/connectors/increment-fi/IncrementFiStakingConnectors.cdc @@ -231,10 +231,11 @@ access(all) contract IncrementFiStakingConnectors { return 0.0 // no capacity if the staking pool is not available } - /// Withdraws rewards from the staking pool up to the specified maximum amount - /// Overflow rewards are sent to the appropriate overflow sinks if provided + /// Withdraws rewards from the staking pool up to the specified maximum amount. + /// Panics if the claimed rewards exceed maxAmount, as the staking pool does not support partial claims. + /// Callers must ensure maxAmount >= minimumAvailable() to avoid a panic. /// - /// @param maxAmount: The maximum amount of rewards to claim + /// @param maxAmount: The maximum amount of rewards to claim. The full reward balance is claimed and must not exceed this value. /// @return a Vault containing the claimed rewards /// access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} { @@ -245,10 +246,6 @@ access(all) contract IncrementFiStakingConnectors { if let pool = IncrementFiStakingConnectors.borrowPool(pid: self.pid) { if let userCertificate = self.userCertificate.borrow() { - let withdrawAmount = maxAmount < minimumAvailable - ? maxAmount - : minimumAvailable - let rewards <- pool.claimRewards(userCertificate: userCertificate) let targetSliceType = SwapConfig.SliceTokenTypeIdentifierFromVaultType(vaultTypeIdentifier: self.vaultType.identifier) @@ -265,6 +262,10 @@ access(all) contract IncrementFiStakingConnectors { ) let reward <- rewards.remove(key: rewards.keys[0])! destroy rewards + assert( + reward.balance <= maxAmount, + message: "Claimed reward balance \(reward.balance) exceeds maxAmount \(maxAmount). The staking pool does not support partial claims — callers must ensure maxAmount >= minimumAvailable()." + ) return <- reward } } diff --git a/cadence/contracts/connectors/increment-fi/IncrementFiSwapConnectors.cdc b/cadence/contracts/connectors/increment-fi/IncrementFiSwapConnectors.cdc index 02558f7..a2f2d92 100644 --- a/cadence/contracts/connectors/increment-fi/IncrementFiSwapConnectors.cdc +++ b/cadence/contracts/connectors/increment-fi/IncrementFiSwapConnectors.cdc @@ -111,7 +111,7 @@ access(all) contract IncrementFiSwapConnectors { /// Performs a swap taking a Vault of type inVault, outputting a resulting outVault. Implementations may choose /// to swap along a pre-set path or an optimal path of a set of paths or even set of contained Swappers adapted /// to use multiple Flow swap protocols. - access(all) fun swap(quote: {DeFiActions.Quote}?, inVault: @{FungibleToken.Vault}): @{FungibleToken.Vault} { + access(all) fun swap(quote _: {DeFiActions.Quote}?, inVault: @{FungibleToken.Vault}): @{FungibleToken.Vault} { let amountOut = self.quoteOut(forProvided: inVault.balance, reverse: false).outAmount return <- SwapRouter.swapExactTokensForTokens( exactVaultIn: <-inVault, @@ -123,7 +123,7 @@ access(all) contract IncrementFiSwapConnectors { /// Performs a swap taking a Vault of type outVault, outputting a resulting inVault. Implementations may choose /// to swap along a pre-set path or an optimal path of a set of paths or even set of contained Swappers adapted /// to use multiple Flow swap protocols. - access(all) fun swapBack(quote: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} { + access(all) fun swapBack(quote _: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} { let amountOut = self.quoteOut(forProvided: residual.balance, reverse: true).outAmount return <- SwapRouter.swapExactTokensForTokens( exactVaultIn: <-residual,