Skip to content

Commit

Permalink
feat: upgradeRouter script
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Aug 6, 2024
1 parent a393ec2 commit 8976217
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions contracts/BaseRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 64 files
+1 −0 .gitattributes
+128 −0 .github/workflows/ci.yml
+31 −0 .github/workflows/sync.yml
+0 −27 .github/workflows/tests.yml
+1 −1 .gitignore
+0 −3 .gitmodules
+1 −1 LICENSE-APACHE
+1 −1 LICENSE-MIT
+9 −5 README.md
+19 −0 foundry.toml
+0 −1 lib/ds-test
+16 −0 package.json
+635 −0 scripts/vm.py
+35 −0 src/Base.sol
+24 −41 src/Script.sol
+669 −0 src/StdAssertions.sol
+259 −0 src/StdChains.sol
+817 −0 src/StdCheats.sol
+15 −0 src/StdError.sol
+122 −0 src/StdInvariant.sol
+122 −61 src/StdJson.sol
+43 −0 src/StdMath.sol
+473 −0 src/StdStorage.sol
+333 −0 src/StdStyle.sol
+179 −0 src/StdToml.sol
+226 −0 src/StdUtils.sol
+29 −1,134 src/Test.sol
+1,865 −218 src/Vm.sol
+401 −382 src/console.sol
+1 −1,535 src/console2.sol
+105 −0 src/interfaces/IERC1155.sol
+12 −0 src/interfaces/IERC165.sol
+43 −0 src/interfaces/IERC20.sol
+190 −0 src/interfaces/IERC4626.sol
+164 −0 src/interfaces/IERC721.sol
+73 −0 src/interfaces/IMulticall3.sol
+234 −0 src/mocks/MockERC20.sol
+231 −0 src/mocks/MockERC721.sol
+13,937 −0 src/safeconsole.sol
+0 −20 src/test/Script.t.sol
+0 −602 src/test/StdAssertions.t.sol
+0 −282 src/test/StdCheats.t.sol
+0 −200 src/test/StdMath.t.sol
+0 −321 src/test/StdStorage.t.sol
+145 −0 test/StdAssertions.t.sol
+226 −0 test/StdChains.t.sol
+618 −0 test/StdCheats.t.sol
+14 −18 test/StdError.t.sol
+49 −0 test/StdJson.t.sol
+212 −0 test/StdMath.t.sol
+471 −0 test/StdStorage.t.sol
+110 −0 test/StdStyle.t.sol
+49 −0 test/StdToml.t.sol
+342 −0 test/StdUtils.t.sol
+15 −0 test/Vm.t.sol
+10 −0 test/compilation/CompilationScript.sol
+10 −0 test/compilation/CompilationScriptBase.sol
+10 −0 test/compilation/CompilationTest.sol
+10 −0 test/compilation/CompilationTestBase.sol
+0 −0 test/fixtures/broadcast.log.json
+8 −0 test/fixtures/test.json
+6 −0 test/fixtures/test.toml
+441 −0 test/mocks/MockERC20.t.sol
+721 −0 test/mocks/MockERC721.t.sol
1 change: 1 addition & 0 deletions lib/utils
Submodule utils added at e64751
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
45 changes: 45 additions & 0 deletions scripts/foundry/UpgradeRouter.s.sol
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 8976217

Please sign in to comment.