From 6e91bd3b64e9dff6827e148fc69d3d2899b07251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 6 Feb 2025 14:45:40 +0100 Subject: [PATCH] feat: use safeCast. --- .../strategies/BaseCurveAMOStrategy.sol | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/contracts/contracts/strategies/BaseCurveAMOStrategy.sol b/contracts/contracts/strategies/BaseCurveAMOStrategy.sol index 834bd1d18a..150b3d0fa8 100644 --- a/contracts/contracts/strategies/BaseCurveAMOStrategy.sol +++ b/contracts/contracts/strategies/BaseCurveAMOStrategy.sol @@ -6,7 +6,8 @@ pragma solidity ^0.8.0; * @notice AMO strategy for the Curve OETH/WETH pool * @author Origin Protocol Inc */ -import "@openzeppelin/contracts/utils/math/Math.sol"; +import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; +import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { IERC20, InitializableAbstractStrategy } from "../utils/InitializableAbstractStrategy.sol"; import { StableMath } from "../utils/StableMath.sol"; @@ -18,6 +19,7 @@ import { IChildLiquidityGaugeFactory } from "../interfaces/IChildLiquidityGaugeF contract BaseCurveAMOStrategy is InitializableAbstractStrategy { using StableMath for uint256; + using SafeCast for uint256; /** * @dev a threshold under which the contract no longer allows for the protocol to manually rebalance. @@ -91,16 +93,16 @@ contract BaseCurveAMOStrategy is InitializableAbstractStrategy { // Get the asset and OToken balances in the Curve pool uint256[] memory balancesBefore = curvePool.get_balances(); // diff = ETH balance - OETH balance - int256 diffBefore = int256(balancesBefore[ethCoinIndex]) - - int256(balancesBefore[oethCoinIndex]); + int256 diffBefore = balancesBefore[ethCoinIndex].toInt256() - + balancesBefore[oethCoinIndex].toInt256(); _; // Get the asset and OToken balances in the Curve pool uint256[] memory balancesAfter = curvePool.get_balances(); // diff = ETH balance - OETH balance - int256 diffAfter = int256(balancesAfter[ethCoinIndex]) - - int256(balancesAfter[oethCoinIndex]); + int256 diffAfter = balancesAfter[ethCoinIndex].toInt256() - + balancesAfter[oethCoinIndex].toInt256(); if (diffBefore <= 0) { // If the pool was originally imbalanced in favor of OETH, then @@ -191,9 +193,9 @@ contract BaseCurveAMOStrategy is InitializableAbstractStrategy { uint256 oethToAdd = uint256( _max( 0, - int256(balances[ethCoinIndex]) + - int256(_wethAmount) - - int256(balances[oethCoinIndex]) + balances[ethCoinIndex].toInt256() + + _wethAmount.toInt256() - + balances[oethCoinIndex].toInt256() ) ); @@ -592,7 +594,6 @@ contract BaseCurveAMOStrategy is InitializableAbstractStrategy { Approvals ****************************************/ - /** * @notice Sets the maximum slippage allowed for any swap/liquidity operation * @param _maxSlippage Maximum slippage allowed, 1e18 = 100%.