Incorrect slippage protection on deposits
The slippage on deposits is enforced by the `minMarketTokenAmt` parameter. But in the calculation of `minMarketTokenAmt`, the slippage is factored on the user's deposit value and not the leveraged amount which is actually being deposited to GMX.\\n```\\n  function deposit(\\n    GMXTypes.Store storage self,\\n    GMXTypes.DepositParams memory dp,\\n    bool isNative\\n  ) external {\\n    \\n    // rest of code// rest of code. more code \\n\\n    if (dp.token == address(self.lpToken)) {\\n      // If LP token deposited\\n      _dc.depositValue = self.gmxOracle.getLpTokenValue(\\n        address(self.lpToken),\\n        address(self.tokenA),\\n        address(self.tokenA),\\n        address(self.tokenB),\\n        false,\\n        false\\n      )\\n      * dp.amt\\n      / SAFE_MULTIPLIER;\\n    } else {\\n      // If tokenA or tokenB deposited\\n      _dc.depositValue = GMXReader.convertToUsdValue(\\n        self,\\n        address(dp.token),\\n        dp.amt\\n      );\\n    }\\n    \\n     // rest of code// rest of code. more code\\n\\n    _alp.tokenAAmt = self.tokenA.balanceOf(address(this));\\n    _alp.tokenBAmt = self.tokenB.balanceOf(address(this));\\n    _alp.minMarketTokenAmt = GMXManager.calcMinMarketSlippageAmt(\\n      self,\\n      _dc.depositValue,\\n      dp.slippage\\n    );\\n    _alp.executionFee = dp.executionFee;\\n\\n\\n    _dc.depositKey = GMXManager.addLiquidity(\\n      self,\\n      _alp\\n    );\\n```\\n\\nhttps://github.com/Cyfrin/2023-10-SteadeFi/blob/0f909e2f0917cb9ad02986f631d622376510abec/contracts/strategy/gmx/GMXDeposit.sol#L54-L146\\nBut vaults with leverage greater than 1 will be adding more than `_dc.depositValue` worth of liquidity in which case the calculated `minMarketTokenAmt` will result in a much higher slippage.\\nExample Scenario\\nThe vault is a 3x leveraged vault\\nUser deposits 1 usd worth tokenA and sets slippage to 1%.\\nThe `minMarketTokenAmt` calculated is worth 0.99 usd\\nThe actual deposit added is worth 3 usd due to leverage\\nThe deposit receives 2.90 worth of LP token which is more than 1% slippage
Use the actual deposit value instead of the user's initial deposit value when calculating the `minMarketTokenAmt`\\n```\\ndiff // Remove the line below\\n// Remove the line below\\ngit a/contracts/strategy/gmx/GMXDeposit.sol b/contracts/strategy/gmx/GMXDeposit.sol\\nindex 1b28c3b..aeba68b 100644\\n// Remove the line below\\n// Remove the line below\\n// Remove the line below\\n a/contracts/strategy/gmx/GMXDeposit.sol\\n// Add the line below\\n// Add the line below\\n// Add the line below\\n b/contracts/strategy/gmx/GMXDeposit.sol\\n@@ // Remove the line below\\n135,7 // Add the line below\\n135,15 @@ library GMXDeposit {\\n     _alp.tokenBAmt = self.tokenB.balanceOf(address(this));\\n     _alp.minMarketTokenAmt = GMXManager.calcMinMarketSlippageAmt(\\n       self,\\n// Remove the line below\\n      _dc.depositValue,\\n// Add the line below\\n      GMXReader.convertToUsdValue(\\n// Add the line below\\n        self,\\n// Add the line below\\n        address(self.tokenA),\\n// Add the line below\\n        _alp.tokenAAmt\\n// Add the line below\\n      ) // Add the line below\\n GMXReader.convertToUsdValue(\\n// Add the line below\\n        self,\\n// Add the line below\\n        address(self.tokenB),\\n// Add the line below\\n        _alp.tokenBAmt\\n// Add the line below\\n      ),\\n       dp.slippage\\n     );\\n     _alp.executionFee = dp.executionFee;\\n```\\n
Depositors can loose value
```\\n  function deposit(\\n    GMXTypes.Store storage self,\\n    GMXTypes.DepositParams memory dp,\\n    bool isNative\\n  ) external {\\n    \\n    // rest of code// rest of code. more code \\n\\n    if (dp.token == address(self.lpToken)) {\\n      // If LP token deposited\\n      _dc.depositValue = self.gmxOracle.getLpTokenValue(\\n        address(self.lpToken),\\n        address(self.tokenA),\\n        address(self.tokenA),\\n        address(self.tokenB),\\n        false,\\n        false\\n      )\\n      * dp.amt\\n      / SAFE_MULTIPLIER;\\n    } else {\\n      // If tokenA or tokenB deposited\\n      _dc.depositValue = GMXReader.convertToUsdValue(\\n        self,\\n        address(dp.token),\\n        dp.amt\\n      );\\n    }\\n    \\n     // rest of code// rest of code. more code\\n\\n    _alp.tokenAAmt = self.tokenA.balanceOf(address(this));\\n    _alp.tokenBAmt = self.tokenB.balanceOf(address(this));\\n    _alp.minMarketTokenAmt = GMXManager.calcMinMarketSlippageAmt(\\n      self,\\n      _dc.depositValue,\\n      dp.slippage\\n    );\\n    _alp.executionFee = dp.executionFee;\\n\\n\\n    _dc.depositKey = GMXManager.addLiquidity(\\n      self,\\n      _alp\\n    );\\n```\\n