From 8976217ae61564ce2c7ca318f0234626c14b58c7 Mon Sep 17 00:00:00 2001 From: 0xtekgrinder <0xtekgrinder@protonmail.com> Date: Tue, 6 Aug 2024 12:15:48 +0200 Subject: [PATCH] feat: upgradeRouter script --- .gitmodules | 3 ++ contracts/BaseRouter.sol | 18 ++++++++++-- lib/forge-std | 2 +- lib/utils | 1 + remappings.txt | 1 + scripts/foundry/UpgradeRouter.s.sol | 45 +++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 4 deletions(-) create mode 160000 lib/utils create mode 100644 scripts/foundry/UpgradeRouter.s.sol diff --git a/.gitmodules b/.gitmodules index 888d42d..74640c6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std +[submodule "lib/utils"] + path = lib/utils + url = https://github.com/AngleProtocol/utils diff --git a/contracts/BaseRouter.sol b/contracts/BaseRouter.sol index b3d468d..2d4fde3 100644 --- a/contracts/BaseRouter.sol +++ b/contracts/BaseRouter.sol @@ -155,7 +155,11 @@ abstract contract BaseRouter is Initializable, IDepositWithReferral { ); /// @notice Deploys the router contract on a chain - function initializeRouter(address _core, address _uniswapRouter, address _oneInch) public initializer { + function initializeRouter( + address _core, + address _uniswapRouter, + address _oneInch + ) public initializer { if (_core == address(0)) revert ZeroAddress(); core = ICoreBorrow(_core); uniswapV3Router = IUniswapV3Router(_uniswapRouter); @@ -409,7 +413,11 @@ abstract contract BaseRouter is Initializable, IDepositWithReferral { /// @param tokenOut Token to sweep /// @param minAmountOut Minimum amount of tokens to recover /// @param to Address to which tokens should be sent - function _sweep(address tokenOut, uint256 minAmountOut, address to) internal virtual { + function _sweep( + address tokenOut, + uint256 minAmountOut, + address to + ) internal virtual { uint256 balanceToken = IERC20(tokenOut).balanceOf(address(this)); _slippageCheck(balanceToken, minAmountOut); if (balanceToken != 0) { @@ -580,7 +588,11 @@ abstract contract BaseRouter is Initializable, IDepositWithReferral { /// @param token Address of the token to change allowance /// @param spender Address to change the allowance of /// @param amount Amount allowed - function _changeAllowance(IERC20 token, address spender, uint256 amount) internal { + function _changeAllowance( + IERC20 token, + address spender, + uint256 amount + ) internal { uint256 currentAllowance = token.allowance(address(this), spender); // In case `currentAllowance < type(uint256).max / 2` and we want to increase it: // Do nothing (to handle tokens that need reapprovals to 0 and save gas) diff --git a/lib/forge-std b/lib/forge-std index 26413f2..1714bee 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 26413f24cbbd4b4fb5c855d542ef9721790c1e7f +Subproject commit 1714bee72e286e73f76e320d110e0eaf5c4e649d diff --git a/lib/utils b/lib/utils new file mode 160000 index 0000000..e64751f --- /dev/null +++ b/lib/utils @@ -0,0 +1 @@ +Subproject commit e64751fc263a2f3a7f52563da3c010a13195cb6b diff --git a/remappings.txt b/remappings.txt index c3b565e..362914c 100644 --- a/remappings.txt +++ b/remappings.txt @@ -4,3 +4,4 @@ @uniswap/=node_modules/@uniswap/ ds-test/=lib/forge-std/lib/ds-test/src/ forge-std/=lib/forge-std/src/ +utils/=lib/utils/ \ No newline at end of file diff --git a/scripts/foundry/UpgradeRouter.s.sol b/scripts/foundry/UpgradeRouter.s.sol new file mode 100644 index 0000000..61de30c --- /dev/null +++ b/scripts/foundry/UpgradeRouter.s.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.17; + +import "forge-std/Script.sol"; +import "utils/src/CommonUtils.sol"; +import { AngleRouterMainnet } from "contracts/implementations/mainnet/AngleRouterMainnet.sol"; +import { AngleRouterArbitrum } from "contracts/implementations/arbitrum/AngleRouterArbitrum.sol"; +import { AngleRouterOptimism } from "contracts/implementations/optimism/AngleRouterOptimism.sol"; +import { AngleRouterAvalanche } from "contracts/implementations/avalanche/AngleRouterAvalanche.sol"; +import { AngleRouterBase } from "contracts/implementations/base/AngleRouterBase.sol"; +import { AngleRouterCelo } from "contracts/implementations/celo/AngleRouterCelo.sol"; +import { AngleRouterGnosis } from "contracts/implementations/gnosis/AngleRouterGnosis.sol"; +import { AngleRouterLinea } from "contracts/implementations/linea/AngleRouterLinea.sol"; +import { AngleRouterPolygon } from "contracts/implementations/polygon/AngleRouterPolygon.sol"; + +contract UpgradeRouterScript is Script, CommonUtils { + +function run() public { + uint256 chainId = vm.envUint("CHAIN_ID"); + + address routerImpl; + if (chainId == CHAIN_ETHEREUM) { + routerImpl = address(new AngleRouterMainnet()); + } else if (chainId == CHAIN_ARBITRUM) { + routerImpl = address(new AngleRouterArbitrum()); + } else if (chainId == CHAIN_OPTIMISM) { + routerImpl = address(new AngleRouterOptimism()); + } else if (chainId == CHAIN_AVALANCHE) { + routerImpl = address(new AngleRouterAvalanche()); + } else if (chainId == CHAIN_BASE) { + routerImpl = address(new AngleRouterBase()); + } else if (chainId == CHAIN_CELO) { + routerImpl = address(new AngleRouterCelo()); + } else if (chainId == CHAIN_GNOSIS) { + routerImpl = address(new AngleRouterGnosis()); + } else if (chainId == CHAIN_LINEA) { + routerImpl = address(new AngleRouterLinea()); + } else if (chainId == CHAIN_POLYGON) { + routerImpl = address(new AngleRouterPolygon()); + } + + console.log("Deployed router implementation at address: %s", routerImpl); +} + +}