From 88b2d9f8dcc4f33d1b472ad70d48a708352ee59f Mon Sep 17 00:00:00 2001 From: Ewan Sheldon Date: Fri, 3 Jan 2025 15:23:17 +0100 Subject: [PATCH] minimum out should be 99% of usd value of collateral, to give some buffer for swap fee --- contracts/SmartVaultV4.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/SmartVaultV4.sol b/contracts/SmartVaultV4.sol index e83e911..2f27cf3 100644 --- a/contracts/SmartVaultV4.sol +++ b/contracts/SmartVaultV4.sol @@ -324,10 +324,10 @@ contract SmartVaultV4 is ISmartVault, IRedeemable { recipient: address(this), deadline: block.timestamp, amountIn: _amountIn, - // minimum USD value of collateral out from swap amountOutMinimum: calculator.tokenToUSD( ITokenManager(ISmartVaultManager(manager).tokenManager()).getTokenIfExists(_collateralToken), _amountIn - ) + ) * 99 / 100 // 99% of usd value of collateral – usds should be bought at around .98-.99 on average, + // but this gives some buffer for lower liquidity / higher fee pools }) ); IERC20(_collateralToken).forceApprove(_swapRouterAddress, 0); @@ -366,7 +366,7 @@ contract SmartVaultV4 is ISmartVault, IRedeemable { _collateralToken = ISmartVaultManager(manager).weth(); IWETH(_collateralToken).deposit{value: address(this).balance}(); } - uint256 _redeemed = swapCollateral(_swapRouterAddress, _quoterAddress, _collateralToken, _swapPath, _USDsTargetAmount); + _redeemed = swapCollateral(_swapRouterAddress, _quoterAddress, _collateralToken, _swapPath, _USDsTargetAmount); minted -= _redeemed; USDs.burn(address(this), _redeemed); if (_hypervisor != address(0) && _withdrawn > 0) {