Skip to content

Commit

Permalink
Router upgrade (#25)
Browse files Browse the repository at this point in the history
* checking the routing contracts

* feat: deploy new router implementations

* fix: linea router

* fix: lint
  • Loading branch information
sogipec authored Aug 5, 2024
1 parent 46a3b57 commit 60c1c95
Show file tree
Hide file tree
Showing 43 changed files with 7,962 additions and 494 deletions.
62 changes: 0 additions & 62 deletions contracts/BaseAngleRouterSidechain.sol

This file was deleted.

35 changes: 13 additions & 22 deletions contracts/BaseRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import "@openzeppelin/contracts/interfaces/IERC4626.sol";
import "./interfaces/external/uniswap/IUniswapRouter.sol";
import "./interfaces/external/IWETH9.sol";
import "./interfaces/ICoreBorrow.sol";
import "./interfaces/IDepositWithReferral.sol";
import "./interfaces/ILiquidityGauge.sol";
import "./interfaces/ISwapper.sol";
import "./interfaces/IVaultManager.sol";
Expand Down Expand Up @@ -72,7 +73,9 @@ enum ActionType {
prepareRedeemSavingsRate,
// Deprecated
claimRedeemSavingsRate,
// Deprecated
swapIn,
// Deprecated
swapOut,
claimWeeklyInterest,
// Deprecated
Expand Down Expand Up @@ -117,7 +120,7 @@ struct PermitVaultManagerType {
/// @author Angle Core Team
/// @notice Base contract that Angle router contracts on different chains should override
/// @dev Router contracts are designed to facilitate the composition of actions on the different modules of the protocol
abstract contract BaseRouter is Initializable {
abstract contract BaseRouter is Initializable, IDepositWithReferral {
using SafeERC20 for IERC20;

// ================================= REFERENCES ================================
Expand Down Expand Up @@ -152,11 +155,7 @@ abstract contract BaseRouter is Initializable {
);

/// @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 @@ -293,16 +292,16 @@ abstract contract BaseRouter is Initializable {
/// @notice Wrapper built on top of the base `_deposit4626Referral` function to add a proxy enabling to track
/// addresses depositing from a certain referring address into an ERC4626 contract
function deposit4626Referral(
IERC20 token,
IERC4626 savings,
address token,
address savings,
uint256 amount,
address to,
uint256 minSharesOut,
address referrer
) external {
token.safeTransferFrom(msg.sender, address(this), amount);
_changeAllowance(token, address(savings), type(uint256).max);
_deposit4626Referral(savings, amount, to, minSharesOut, referrer);
) external returns (uint256 sharesOut) {
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
_changeAllowance(IERC20(token), savings, type(uint256).max);
sharesOut = _deposit4626Referral(IERC4626(savings), amount, to, minSharesOut, referrer);
}

/// @notice Wrapper built on top of the base `mixer` function to grant approval to a `VaultManager` contract before performing
Expand Down Expand Up @@ -407,11 +406,7 @@ abstract contract BaseRouter is Initializable {
/// @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 @@ -582,11 +577,7 @@ abstract contract BaseRouter is Initializable {
/// @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
4 changes: 2 additions & 2 deletions contracts/implementations/arbitrum/AngleRouterArbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterArbitrum
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Arbitrum
contract AngleRouterArbitrum is BaseAngleRouterSidechain {
contract AngleRouterArbitrum is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);
Expand Down
4 changes: 2 additions & 2 deletions contracts/implementations/avalanche/AngleRouterAvalanche.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterAvalanche
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Avalanche
contract AngleRouterAvalanche is BaseAngleRouterSidechain {
contract AngleRouterAvalanche is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7);
Expand Down
4 changes: 2 additions & 2 deletions contracts/implementations/base/AngleRouterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterBase
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Base
contract AngleRouterBase is BaseAngleRouterSidechain {
contract AngleRouterBase is BaseRouter {
/// @inheritdoc BaseRouter
/// @dev There is no wCELO contract on CELO
function _getNativeWrapper() internal pure override returns (IWETH9) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/implementations/celo/AngleRouterCelo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterCelo
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Celo
contract AngleRouterCelo is BaseAngleRouterSidechain {
contract AngleRouterCelo is BaseRouter {
/// @inheritdoc BaseRouter
/// @dev There is no wCELO contract on CELO
function _getNativeWrapper() internal pure override returns (IWETH9) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/implementations/gnosis/AngleRouterGnosis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterGnosis
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Gnosis
contract AngleRouterGnosis is BaseAngleRouterSidechain {
contract AngleRouterGnosis is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d);
Expand Down
15 changes: 15 additions & 0 deletions contracts/implementations/linea/AngleRouterLinea.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.17;

import "../../BaseRouter.sol";

/// @title AngleRouterLinea
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Linea
contract AngleRouterLinea is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f);
}
}
4 changes: 2 additions & 2 deletions contracts/implementations/optimism/AngleRouterOptimism.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterOptimism
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Optimism
contract AngleRouterOptimism is BaseAngleRouterSidechain {
contract AngleRouterOptimism is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0x4200000000000000000000000000000000000006);
Expand Down
4 changes: 2 additions & 2 deletions contracts/implementations/polygon/AngleRouterPolygon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity ^0.8.17;

import "../../BaseAngleRouterSidechain.sol";
import "../../BaseRouter.sol";

/// @title AngleRouterPolygon
/// @author Angle Core Team
/// @notice Router contract built specifially for Angle use cases on Polygon
contract AngleRouterPolygon is BaseAngleRouterSidechain {
contract AngleRouterPolygon is BaseRouter {
/// @inheritdoc BaseRouter
function _getNativeWrapper() internal pure override returns (IWETH9) {
return IWETH9(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);
Expand Down
25 changes: 25 additions & 0 deletions contracts/interfaces/IDepositWithReferral.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IDepositWithReferral
/// @author Angle Core Team
/// @notice Interface for Angle routing contract to notably deposit into ERC4626 with a referral address
interface IDepositWithReferral {
/// @notice Deposits `amount` of `token` into an ERC4626 `savings` contract (with `token` as an asset)
/// @param minSharesOut Minimum amount of shares of the ERC4626 the deposit should return. If less is
/// obtained, the function reverts
/// @param referrer Address which referred `msg.sender` to deposit into `savings`. Any address can be entered
/// and the referrer address has no storage implication, it just changes the event emitted by this contract
/// when a deposit takes place
/// @dev This function is a wrapper on top of the base `deposit` function of ERC4626 with the ability to
/// specify a referring address (`referrer`) as well as a slippage parameter (`minSharesOut`)
function deposit4626Referral(
address token,
address savings,
uint256 amount,
address to,
uint256 minSharesOut,
address referrer
) external returns (uint256 sharesOut);
}
4 changes: 2 additions & 2 deletions contracts/mock/MockRouterSidechain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../interfaces/external/IWETH9.sol";

import "../BaseAngleRouterSidechain.sol";
import "../BaseRouter.sol";

/// @title MockRouterSidechain
/// @author Angle Core Team
/// @notice Mock contract but built for tests as if to be deployed on Ethereum
contract MockRouterSidechain is BaseAngleRouterSidechain {
contract MockRouterSidechain is BaseRouter {
IWETH9 public constant WETH = IWETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

function _wrapNative() internal pure override returns (uint256) {
Expand Down
4 changes: 4 additions & 0 deletions deploy/networks/linea.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"oneInchRouter": "0x0000000000000000000000000000000000000000",
"uniswapV3Router": "0x0000000000000000000000000000000000000000"
}
17 changes: 10 additions & 7 deletions deploy/routerSidechain.ts → deploy/routerDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,38 @@ const func: DeployFunction = async ({ ethers, deployments, network }) => {
let chainName: string;

if (!network.live) {
chainId = ChainId.BASE;
chainName = 'Base';
chainId = ChainId.LINEA;
chainName = 'Linea';
} else {
chainId = ChainId.BASE;
chainId = ChainId.LINEA;
chainName = network.name.charAt(0).toUpperCase() + network.name.substring(1);
}

const contractName = `AngleRouter${chainName}`;

console.log('Now deploying the implementation');
await deploy(`${contractName}V2_1_Implementation`, {
/*
await deploy(`${contractName}V3_0_Implementation`, {
contract: contractName,
from: deployer.address,
log: !argv.ci,
});
*/

const routerImplementation = (await ethers.getContract(`${contractName}V2_1_Implementation`)).address;
const routerImplementation = (await ethers.getContract(`${contractName}V3_0_Implementation`)).address;
console.log(`Successfully deployed the implementation for the router at ${routerImplementation}`);

const proxyAdmin = registry(chainId)?.ProxyAdminGuardian;
const coreBorrow = registry(chainId)?.CoreBorrow;
// const coreBorrow = "0x4b1E2c2762667331Bc91648052F646d1b0d35984";
console.log(proxyAdmin, coreBorrow);
console.log('Now deploying the proxy contract');
const dataRouter = new ethers.Contract(
routerImplementation,
AngleRouterPolygon__factory.createInterface(),
).interface.encodeFunctionData('initializeRouter', [coreBorrow, json.uniswapV3Router, json.oneInchRouter]);

await deploy(`${contractName}V2`, {
await deploy(`${contractName}V3`, {
contract: 'TransparentUpgradeableProxy',
from: deployer.address,
args: [routerImplementation, proxyAdmin, dataRouter],
Expand All @@ -58,5 +61,5 @@ const func: DeployFunction = async ({ ethers, deployments, network }) => {
console.log('Success');
};

func.tags = ['routerSidechain'];
func.tags = ['router'];
export default func;
26 changes: 0 additions & 26 deletions deploy/routerMainnet.ts

This file was deleted.

Loading

0 comments on commit 60c1c95

Please sign in to comment.