Skip to content

Commit

Permalink
Feat/script migration (#2)
Browse files Browse the repository at this point in the history
* feat: deployAgTokenSideChain script

* feat: DeployChain script

* feat: deployTokenSideChain script

* feat: remove BasicScript

* chore: update fs_permissions in foundry.toml

* refactor: rename angleImpl to agTokenImpl

* feat: deploy proxy with create2

* feat: rename to new A naming

* chore: add optimizer in ci profile

* feat: hardcode symbol for ANGLE

* feat: check expectedAddress before create2

* refactor: rename script to deploy angle on sidechain

* feat: in case of a mock coreborrow, initialize contracts

* chore: update utils dependency

* feat: immutable proxy first to deployer hen real implementation

* feat: env vvariable for governor / guardian

* feat: remove guardian proxyAdmin from DeployCHain script

* feat: store addresses in a json

* feat: LayerZeroBridgeTokenERC20

* feat: remove mock governor when using scripts as mock

* feat: treasury write to addresses json

* feat: add back require to check preocmputed address

* feat: vanity now loads everything from multiple files

* feat: create2 deploy for veANGLE

* fix: vanity address script returns salt

* feat: expected address is env or chain to contract on mainnet

* chore: remove via_ir in foundry.toml

* chore: update forge-std to add envExists

* feat: ir-minmum in coverage

* chore: remappings for slither

* chore: add back foundry compile before

* chore: ignore script and test for slither

* chore: specify version for slither in ci

* chore: remove wrong src

* chore: tmate

* chore: try to run slither manually

* chore: set sarif file

* chore: debug ci

* chore: use new version of slither ci

* feat: scripts works even if addresses.json doesn't exists

* chore: update utils dependency

* fix: compile DeployAgTokenSideChain

* chore: manual ci for slither

* chore: try to set output to a constant

* chore: try to rename sarif file

* chore: add an && in stead of | in ci

* chore: try to redirect output to stdout

* chore: results.sarif file

* chore: upgrade utils dependency

* feat: change governor optional

* feat: governor and guardian inside addresses.json

* chore: loads slither errors

* chore: update utils dependency

* feat: update vanity of EURA

* feat: new salt for EUR

* chore: update foundry.toml to add base and linea etherscan api keys

* feat: expected addresses for EURA and ANGLE

* chore: remove base from etherscan keys

* feat: mantle

* feat: update name of AngleSideChain to ANGLE

* feat: setuseCustomAdapterParams

* feat: useCustomAdapaters good interface

* feat: all steps to deploy a new chain

* feat: transfer ownership of ProxyAdmin

* feat: add governor when deploying a new chain

* feat: remove useless line

* feat: finalize is optional

* feat: deploy savings

* fix: savings now compile

* feat: change address for savings to arbitrum

* fix: correct epxectedAddress

* fix: write savings address in json

* feat: deduce stableType from STABLE_NAME

* feat: add blast config

* fix: forwardUtils

* fix: deployChain works without sdk

* feat: governor and guardian addresses
  • Loading branch information
0xtekgrinder authored Jun 24, 2024
1 parent c136910 commit 2484a65
Show file tree
Hide file tree
Showing 27 changed files with 727 additions and 60 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,20 @@ jobs:
version: nightly

- name: Compile foundry
run: forge clean && forge build --build-info --force
run: forge clean && forge build --build-info --force --skip "*/test/**" "*/scripts/**"

- name: "Install Slither"
run: "python3 -m pip install slither-analyzer"

- name: "Run Slither analysis"
uses: "crytic/[email protected]"
id: "slither"
with:
ignore-compile: true
fail-on: "none"
sarif: "results.sarif"
id: slither
run:
slither . --ignore-compile --sarif results.sarif --fail-none

- name: "Upload SARIF file to GitHub code scanning"
uses: "github/codeql-action/upload-sarif@v2"
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
sarif_file: results.sarif

- name: "Add Slither summary"
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "lib/LayerZero"]
path = lib/LayerZero
url = https://github.com/LayerZero-Labs/LayerZero
[submodule "lib/angle-transmuter"]
path = lib/angle-transmuter
url = https://github.com/AngleProtocol/angle-transmuter
150 changes: 150 additions & 0 deletions contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.12;

import "./utils/OFTCore.sol";
import "../../interfaces/IAgTokenSideChainMultiBridge.sol";
import "oz-upgradeable/security/PausableUpgradeable.sol";
import "oz-upgradeable/token/ERC20/ERC20Upgradeable.sol";

/// @title LayerZeroBridgeTokenERC20
/// @author Angle Core Team, forked from https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/token/oft/OFT.sol

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130

Check warning on line 11 in contracts/agToken/layerZero/LayerZeroBridgeTokenERC20.sol

View workflow job for this annotation

GitHub Actions / lint

Line length must be no more than 120 but current length is 130
/// @notice Contract to be deployed on a L2/sidechain for bridging a token (ANGLE for instance) using
/// a bridge intermediate token and LayerZero
contract LayerZeroBridgeTokenERC20 is OFTCore, ERC20Upgradeable, PausableUpgradeable {
/// @notice Address of the bridgeable token
IAgTokenSideChainMultiBridge public canonicalToken;

// =================================== ERRORS ==================================

error InvalidAllowance();

// ================================ CONSTRUCTOR ================================

/// @notice Initializes the contract
/// @param _name Name of the token corresponding to this contract
/// @param _symbol Symbol of the token corresponding to this contract
/// @param _lzEndpoint Layer zero endpoint to pass messages
/// @param _coreBorrow Address of the `CoreBorrow` contract used for access control
/// @param _canonicalToken Address of the bridgeable token
function initialize(
string memory _name,
string memory _symbol,
address _lzEndpoint,
address _coreBorrow,
address _canonicalToken
) external initializer {
if (_canonicalToken == address(0)) revert ZeroAddress();
__ERC20_init_unchained(_name, _symbol);
__LzAppUpgradeable_init(_lzEndpoint, _coreBorrow);

canonicalToken = IAgTokenSideChainMultiBridge(_canonicalToken);
_approve(address(this), _canonicalToken, type(uint256).max);
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}

// ===================== EXTERNAL PERMISSIONLESS FUNCTIONS =====================

/// @inheritdoc OFTCore
function sendWithPermit(
uint16 _dstChainId,
bytes memory _toAddress,
uint256 _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes memory _adapterParams,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public payable override {
canonicalToken.permit(msg.sender, address(this), _amount, deadline, v, r, s);
send(_dstChainId, _toAddress, _amount, _refundAddress, _zroPaymentAddress, _adapterParams);
}

/// @inheritdoc OFTCore
function withdraw(uint256 amount, address recipient) external override returns (uint256 amountMinted) {
// Does not check allowances as transfers from `msg.sender`
_transfer(msg.sender, address(this), amount);
amountMinted = canonicalToken.swapIn(address(this), amount, recipient);
uint256 leftover = balanceOf(address(this));
if (leftover > 0) {
_transfer(address(this), msg.sender, leftover);
}
}

// ============================= INTERNAL FUNCTIONS ============================

/// @inheritdoc OFTCore
function _debitFrom(
uint16,
bytes memory,
uint256 _amount
) internal override whenNotPaused returns (uint256 amountSwapped) {
// No need to use safeTransferFrom as we know this implementation reverts on failure
canonicalToken.transferFrom(msg.sender, address(this), _amount);

// Swap canonical for this bridge token. There may be some fees
amountSwapped = canonicalToken.swapOut(address(this), _amount, address(this));
_burn(address(this), amountSwapped);
}

/// @inheritdoc OFTCore
function _debitCreditFrom(uint16, bytes memory, uint256 _amount) internal override whenNotPaused returns (uint256) {
_burn(msg.sender, _amount);
return _amount;
}

/// @inheritdoc OFTCore
function _creditTo(
uint16,
address _toAddress,
uint256 _amount
) internal override whenNotPaused returns (uint256 amountMinted) {
_mint(address(this), _amount);
amountMinted = canonicalToken.swapIn(address(this), _amount, _toAddress);
uint256 leftover = balanceOf(address(this));
if (leftover > 0) {
_transfer(address(this), _toAddress, leftover);
}
}

// =============================== VIEW FUNCTIONS ==============================

/// @inheritdoc ERC165Upgradeable
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IOFT).interfaceId ||
interfaceId == type(IERC20).interfaceId ||
super.supportsInterface(interfaceId);
}

// ============================ GOVERNANCE FUNCTIONS ===========================

/// @notice Mints the intermediate contract to the `canonicalToken`
/// @dev Used to increase the bridging capacity
function mint(uint256 amount) external onlyGovernorOrGuardian {
_mint(address(canonicalToken), amount);
}

/// @notice Burns the intermediate contract from the `canonicalToken`
/// @dev Used to decrease the bridging capacity
function burn(uint256 amount) external onlyGovernorOrGuardian {
_burn(address(canonicalToken), amount);
}

/// @notice Increases allowance of the `canonicalToken`
function setupAllowance() public onlyGovernorOrGuardian {
_approve(address(this), address(canonicalToken), type(uint256).max);
}

/// @notice Pauses bridging through the contract
/// @param pause Future pause status
function pauseSendTokens(bool pause) external onlyGovernorOrGuardian {
pause ? _pause() : _unpause();
}

uint256[49] private __gap;
}
12 changes: 12 additions & 0 deletions contracts/interfaces/ICoreBorrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ interface ICoreBorrow {
/// @dev Governance should make sure when adding a governor to also give this governor the guardian
/// role by calling the `addGovernor` function
function isGovernorOrGuardian(address admin) external view returns (bool);

/// @notice Adds a governor in the protocol
/// @param governor Address to grant the role to
/// @dev It is necessary to call this function to grant a governor role to make sure
/// all governors also have the guardian role
function addGovernor(address governor) external;

/// @notice Revokes a governor from the protocol
/// @param governor Address to remove the role to
/// @dev It is necessary to call this function to remove a governor role to make sure
/// the address also loses its guardian role
function removeGovernor(address governor) external;
}
8 changes: 8 additions & 0 deletions contracts/mock/MockCoreBorrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ contract MockCoreBorrow is ICoreBorrow {
function setFlashLoanModule(ITreasury _treasury, address _flashLoanModule) external {
_treasury.setFlashLoanModule(_flashLoanModule);
}

function addGovernor(address governor) external override {
governors[governor] = true;
}

function removeGovernor(address governor) external override {
governors[governor] = false;
}
}
14 changes: 10 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ optimizer = true
optimizer_runs = 1000
solc_version = "0.8.22"
ffi = true
fs_permissions = [{ access = "read-write", path = "./scripts"}]

[fuzz]
runs = 10000
Expand All @@ -32,6 +33,10 @@ celo = "${ETH_NODE_URI_CELO}"
polygonzkevm = "${ETH_NODE_URI_POLYGONZKEVM}"
bsc = "${ETH_NODE_URI_BSC}"
base = "${ETH_NODE_URI_BASE}"
linea = "${ETH_NODE_URI_LINEA}"
mantle = "${ETH_NODE_URI_MANTLE}"
mode = "${ETH_NODE_URI_MODE}"
blast = "${ETH_NODE_URI_BLAST}"

[etherscan]
arbitrum = { key = "${ARBITRUM_ETHERSCAN_API_KEY}" }
Expand All @@ -44,12 +49,13 @@ celo = { key = "${CELO_ETHERSCAN_API_KEY}", url = "https://api.celoscan.io/api"
base = { key = "${BASE_ETHERSCAN_API_KEY}", url = "https://api.basescan.org/api" }
polygonzkevm = { key = "${POLYGONZKEVM_ETHERSCAN_API_KEY}", url = "https://api-zkevm.polygonscan.com/api" }
bsc = { key = "${BSC_ETHERSCAN_API_KEY}"}
linea = { key = "${LINEA_ETHERSCAN_API_KEY}"}
blast = { key = "${BLAST_ETHERSCAN_API_KEY}", url = "https://api.blastscan.io/api" }

[profile.dev]
optimizer = true
via_ir = false
src = "test"
gas_reports = ["*"]
via_ir=true

[profile.dev.fuzz]
runs = 2000
Expand All @@ -60,9 +66,9 @@ depth = 1
fail_on_revert = false

[profile.ci]
src = "test"
via_ir = false
optimizer = true
gas_reports = ["*"]
via_ir=true

[profile.ci.fuzz]
runs = 100
Expand Down
1 change: 1 addition & 0 deletions lib/angle-transmuter
Submodule angle-transmuter added at d592dd
2 changes: 1 addition & 1 deletion lib/utils
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"ci:coverage": "forge coverage --report lcov && yarn lcov:clean",
"coverage": "FOUNDRY_PROFILE=dev forge coverage --report lcov && yarn lcov:clean && yarn lcov:generate-html",
"ci:coverage": "forge coverage --report lcov --ir-minimum && yarn lcov:clean",
"coverage": "FOUNDRY_PROFILE=dev forge coverage --report lcov --ir-minimum && yarn lcov:clean && yarn lcov:generate-html",
"compile": "forge build",
"compile:dev": "FOUNDRY_PROFILE=dev forge build",
"deploy": "forge script --skip test --broadcast --verify --slow -vvvv --rpc-url",
Expand Down
4 changes: 3 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ chainlink/=lib/chainlink/contracts/
utils/=lib/utils/
contracts/=contracts/
chainlink/=lib/chainlink/contracts/
layer-zero/=lib/LayerZero/contracts/
layer-zero/=lib/LayerZero/contracts/
transmuter/=lib/angle-transmuter/contracts/
test/=test/
24 changes: 0 additions & 24 deletions scripts/BasicScript.s.sol

This file was deleted.

Loading

0 comments on commit 2484a65

Please sign in to comment.