Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deployment scripts #184

Merged
merged 27 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
afb29b2
chore: add testnet deployments and update settings (#170)
0xDiscotech Sep 17, 2024
ef22e57
fix: dependabots alerts (#181)
0xDiscotech Sep 23, 2024
b61cfb5
refactor: update package json deployment scripts
0xDiscotech Oct 3, 2024
6206a97
chore: add scripts to readme
0xDiscotech Oct 3, 2024
a759aac
chore: update env values
0xDiscotech Oct 4, 2024
270ffed
fix: integration test assertion
0xDiscotech Oct 4, 2024
725a534
chore: add new testnet deployment addresses
0xDiscotech Oct 4, 2024
b9f851e
fix: update yarn lock
0xDiscotech Oct 4, 2024
a21706d
chore: let usdc mainnet hardcoded on l1 factory deploy
0xDiscotech Oct 4, 2024
582f4a1
Merge branch 'dev' into fix/deployment-scripts
0xDiscotech Oct 4, 2024
db5147d
chore: remove rpc command on mainnet factory deployment script
0xDiscotech Oct 4, 2024
3a64629
chore: add verification tip on readme
0xDiscotech Oct 7, 2024
f7f51ba
fix: typo
0xDiscotech Oct 7, 2024
785b999
fix: comments
0xDiscotech Oct 7, 2024
628a1e2
fix: feedback
0xDiscotech Oct 8, 2024
5580a21
chore: enhance tips for verifying section
0xDiscotech Oct 8, 2024
fa3bbd2
feat: checkpoint
0xDiscotech Oct 8, 2024
8edf3b4
refactor: simplify scripts
hexshire Oct 8, 2024
106ec1d
chore: add forge clean before script
hexshire Oct 8, 2024
8b9316e
chore: add init to husky script
0xDiscotech Oct 8, 2024
4a8f57e
fix: husky pre commit
0xDiscotech Oct 8, 2024
2fdbcee
chore: remove unused envs on env testnet example
0xDiscotech Oct 8, 2024
5107057
chore: enhance comments
0xDiscotech Oct 8, 2024
5f9730a
fix: migration script
0xDiscotech Oct 9, 2024
f065b72
chore: update ci
0xDiscotech Oct 9, 2024
923d478
fix: typo
0xDiscotech Oct 9, 2024
db7714d
chore: polish package json
0xDiscotech Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 14 additions & 47 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,56 +1,23 @@
MAINNET_RPC=
OPTIMISM_RPC=
BASE_RPC=
# Commons
PRIVATE_KEY=
ETHEREUM_RPC=
ETHERSCAN_API_KEY=

# Mainnet
MAINNET_PK=
L1_FACTORY_MAINNET=
L1_ADAPTER_OP=
L2_ADAPTER_OP=
# Required to run DeployL1Factory script
USDC_ETHEREUM_PROXY=

# Custom Chain
# Required to run DeployProtocol script
L1_FACTORY=
BRIDGED_USDC_IMPLEMENTATION=
L1_MESSENGER=
CHAIN_NAME=

# Required to run MigrateToNative
L1_ADAPTER_OWNER_PK=
L1_ADAPTER=
ROLE_CALLER=
BURN_CALLER=


# Optimism
# Migration related variables
OP_USDC_ADMIN=
OP_ROLE_CALLER=
OP_ROLE_CALLER_PK=
OP_BURN_CALLER=
OP_BURN_CALLER_PK=
OP_NEW_USDC_OWNER=

# Testnet
SEPOLIA_PK=
L1_FACTORY_SEPOLIA=
L1_ADAPTER_OP_SEPOLIA=
L2_ADAPTER_OP_SEPOLIA=

# Op Sepolia
# Migration related variables
OP_SEPOLIA_USDC_ADMIN=
OP_SEPOLIA_ROLE_CALLER=
OP_SEPOLIA_ROLE_CALLER_PK=
SEPOLIA_OP_BURN_CALLER=
SEPOLIA_OP_BURN_CALLER_PK=
OP_SEPOLIA_NEW_USDC_OWNER=

# Etherscan
ETHERSCAN_API_KEY=

# USDC Implementation addresses
# These need to be deployed and set manually, ideally from circle's stablecoin-evm repo

# Mainnets
USDC_BASE_IMPLEMENTATION=
USDC_OPTIMISM_IMPLEMENTATION=

# Testnets
USDC_BASE_SEPOLIA_IMPLEMENTATION=
USDC_OPTIMISM_SEPOLIA_IMPLEMENTATION=
# Required to run Integration Tests
OPTIMISM_RPC=
BASE_RPC=
19 changes: 19 additions & 0 deletions .env.testnet.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Commons
PRIVATE_KEY=
ETHEREUM_RPC=
ETHERSCAN_API_KEY=

# Required to run DeployL1Factory script
USDC_ETHEREUM_PROXY=

# Required to run DeployProtocol script
L1_FACTORY=
BRIDGED_USDC_IMPLEMENTATION=
L1_MESSENGER=
CHAIN_NAME=

# Required to run MigrateToNative
L1_ADAPTER_OWNER_PK=
L1_ADAPTER=
ROLE_CALLER=
BURN_CALLER=
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ concurrency:
cancel-in-progress: true

env:
MAINNET_RPC: ${{ secrets.MAINNET_RPC }}
ETHEREUM_RPC: ${{ secrets.ETHEREUM_RPC }}
OPTIMISM_RPC: ${{ secrets.OPTIMISM_RPC }}
BASE_RPC: ${{ secrets.BASE_RPC }}
SEPOLIA_RPC: ${{ secrets.SEPOLIA_RPC }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ out-via-ir

# Config files
.env
.env.testnet

# Avoid ignoring gitkeep
!/**/.gitkeep
Expand Down
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Chain operators can use the Bridged USDC Standard for the OP Stack to get bridge
## Contracts
> :exclamation: `L1OpUSDCFactory.sol` has been deployed to the following addresses:
- Mainnet: `0x7dB8637A5fd20BbDab1176BdF49C943A96F2E9c6`
- Sepolia: `0x3c66c9b865c7c43330606D8CfAf86480c92f9f40`
- Sepolia: `0x82c6c4940cE0066B9F8b500aBF8535810524890c`

> :exclamation: `L1OpUSDCBridgeAdapter.sol` has been deployed to the following addresses:
- Sepolia: `0xE9E655E8420E8191a7b747a43f9752a4F93913d2`
- Sepolia: `0x0429b5441c85EF7932B694f1998B778D89375b12`

> :exclamation: `L2OpUSDCBridgeAdapter.sol` has been deployed to the following addresses:
- Optimism Sepolia: `0xa2865E6f7a981914732466ab44a4a53d5FfEFE80`
- Optimism Sepolia: `0xCe7bb486F2b17735a2ee7566Fe03cA77b1a1aa9d`

> :exclamation: `Bridged USDC` contract has been deployed to the following addresses:
- Optimism Sepolia: `0x13C8BBfee9aaD48393fcfF409Fac17e1E108B744`
- Optimism Sepolia: `0x7a30534619d60e4A610833F985bdF7892fD9bcD5`

_`L1OpUSDCFactory.sol`_ - Factory contract to deploy and setup the `L1OpUSDCBridgeAdapter` contract on L1. Precalculates the addresses of the L2 deployments and triggers their deployment, by sending a transaction to L2.

Expand Down Expand Up @@ -124,21 +124,21 @@ yarn coverage

> :exclamation: `BRIDGED_USDC_IMPLEMENTATION` needs to be deployed ahead of time onto the target L2 chain.

In order to deploy the opUSDC procotol for your OP Stack chain, you will need to fill out these variables in the `.env` file:
In order to deploy the opUSDC protocol for your OP Stack chain, you will need to fill out these variables in the `.env` file:

```python
# The factory contract address on L1
L1_FACTORY_MAINNET=0x7dB8637A5fd20BbDab1176BdF49C943A96F2E9c6
L1_FACTORY=0x7dB8637A5fd20BbDab1176BdF49C943A96F2E9c6
# The bridged USDC implementation address on L2
BRIDGED_USDC_IMPLEMENTATION=
# The address of your CrossDomainMessenger on L1
L1_MESSENGER=
# The name of your chain
CHAIN_NAME=
# The private key that will sign the transactions on L1
MAINNET_PK=
PRIVATE_KEY=
# Ethereum RPC URL
MAINNET_RPC=
ETHEREUM_RPC=
```

After all these variables are set, navigate to the `script/mainnet/Deploy.s.sol` file and edit the following lines with your desired configuration, we add a sanity check that will revert if you forget to change this value:
Expand Down Expand Up @@ -166,10 +166,31 @@ And when you are ready to deploy to mainnet, run:
yarn script:deploy:broadcast
```

In addittion, the L1OpUSDCFactory deployment command is:
```bash
yarn deploy:mainnet:factory
```

And when you are ready to deploy to mainnet, run:
```bash
yarn deploy:mainnet:factory:broadcast
```

Alternatively, you can run the deployment scripts over your desired testent by replacing mainnet with testnet in the commands above.
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved

### Tips For Verifying

- Remember to set the EVM version to `paris` when verifying the contracts.
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
- Remember to add the `--via-ir` version if you compiled the contracts with the optimized flag and you're verifying them through the CLI.
- If you are verifying manually through a block explorer UI, you can choose a single Soldiity file option and use `forge flatten <contract_name> > <flattened_contract_name>` to get the flattened contract and avoid having to upload multiple Solidity files.
- If you're facing issues with the `L1OpUSDCFactory` verification, you can resolve them by adding the `CrossChainDeployments` library address to the `L1OpUSDCFactory.json` file as shown below:

```json
"libraries": {
"src/libraries/CrossChainDeployments.sol": {
"CrossChainDeployments":"<CROSS_CHAIN_DEPLOYMENTS_ADDRESS>"
}
```

## Migrating to Native USDC
> ⚠️ Migrating to native USDC is a manual process that requires communication with Circle, this section assumes both parties are ready to migrate to native USDC. Please review [Circle’s documentation](https://www.circle.com/blog/bridged-usdc-standard) to learn about the process around Circle obtaining ownership of the Bridged USDC Standard token contract.
Expand All @@ -179,7 +200,7 @@ In order to migrate to native USDC, you will need to fill out these variables in
# The address of the L1 opUSDC bridge adapter
L1_ADAPTER=
# The private key of the transaction signer, should be the owner of the L1 Adapter
MAINNET_OWNER_PK=
L1_ADAPTER_OWNER_PK=
# The address of the role caller, should be provided by circle
ROLE_CALLER=
# The address of the burn caller, should be provided by circle
Expand Down
4 changes: 1 addition & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ src = 'src/interfaces/'
runs = 1000

[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
mainnet = "${ETHEREUM_RPC}"
optimism = "${OPTIMISM_RPC}"
base = "${BASE_RPC}"
sepolia = "${SEPOLIA_RPC}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", chain = "mainnet" }
sepolia = { key = "${ETHERSCAN_API_KEY}", chain = "sepolia" }
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
{
"name": "op-usdc",
"version": "1.0.0",
"description": "opUSDC, a USDC bridge for any op-chain's canonical bridge",
"description": "opUSDC, a USDC bridge for any OP Stack chain's canonical bridge",
"license": "MIT",
"author": "Wonderland",
"scripts": {
"build": "forge build",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"coverage": "forge coverage --match-contract Unit",
"deploy:mainnet": "bash -c 'source .env && forge script Deploy --broadcast --chain mainnet --private-key $MAINNET_DEPLOYER_PK'",
"deploy:sepolia": "bash -c 'source .env && forge script Deploy --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK'",
"deploy:mainnet:factory": "forge clean && dotenv -e .env -- sh -c 'forge script script/DeployL1Factory.s.sol:DeployL1Factory --via-ir -vv --rpc-url $ETHEREUM_RPC'",
"deploy:mainnet:factory:broadcast": "forge clean && dotenv -e .env -- sh -c 'forge script script/DeployL1Factory.s.sol:DeployL1Factory --via-ir --broadcast -vv --rpc-url $ETHEREUM_RPC'",
"deploy:mainnet:protocol": "forge clean && dotenv -e .env -- sh -c 'forge script script/DeployProtocol.s.sol:DeployProtocol --via-ir -vv --rpc-url $ETHEREUM_RPC'",
"deploy:mainnet:protocol:broadcast": "forge clean && dotenv -e .env -- sh -c 'forge script script/DeployProtocol.s.sol:DeployProtocol --slow --via-ir --broadcast -vv --rpc-url $ETHEREUM_RPC'",
"deploy:testnet:factory": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/DeployL1Factory.s.sol:DeployL1Factory --via-ir -vv --rpc-url $ETHEREUM_RPC'",
"deploy:testnet:factory:broadcast": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/DeployL1Factory.s.sol:DeployL1Factory --via-ir --broadcast -vv --rpc-url $ETHEREUM_RPC'",
"deploy:testnet:protocol": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/DeployProtocol.s.sol:DeployProtocol --via-ir -vv --rpc-url $ETHEREUM_RPC'",
"deploy:testnet:protocol:broadcast": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/DeployProtocol.s.sol:DeployProtocol --slow --via-ir --broadcast -vv --rpc-url $ETHEREUM_RPC'",
"lint:check": "yarn lint:sol-tests && yarn lint:sol-logic && forge fmt --check",
"lint:fix": "sort-package-json && forge fmt && yarn lint:sol-tests --fix && yarn lint:sol-logic --fix",
"lint:natspec": "npx @defi-wonderland/natspec-smells --config natspec-smells.config.js",
"lint:sol-logic": "solhint -c .solhint.json 'src/**/*.sol' 'script/**/*.sol'",
"lint:sol-tests": "solhint -c .solhint.tests.json 'test/**/*.sol'",
"prepare": "husky install",
"script:deploy": "forge script script/mainnet/deploy/Deploy.s.sol --slow --via-ir",
"script:deploy:broadcast": "forge script script/mainnet/deploy/Deploy.s.sol --broadcast --verify --slow --via-ir",
"script:migrate": "forge script script/mainnet/migration/MigrateToNative.s.sol --slow --via-ir",
"script:migrate:broadcast": "forge script script/mainnet/migration/MigrateToNative.s.sol --broadcast --verify --slow --via-ir",
"migrate:mainnet": "forge clean && dotenv -e .env -- sh -c 'forge script script/MigrateToNative.s.sol --via-ir --rpc-url $ETHEREUM_RPC'",
"migrate:mainnet:broadcast": "forge clean && dotenv -e .env -- sh -c 'forge script script/MigrateToNative.s.sol --broadcast --via-ir --rpc-url $ETHEREUM_RPC'",
"migrate:testnet": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/MigrateToNative.s.sol --via-ir --rpc-url $ETHEREUM_RPC'",
"migrate:testnet:broadcast": "forge clean && dotenv -e .env.testnet -- sh -c 'forge script script/MigrateToNative.s.sol --broadcast --via-ir --rpc-url $ETHEREUM_RPC'",
"prepare": "husky init",
"test": "forge test -vvv",
"test:fuzz": "echidna test/invariants/fuzz/OpUSDC.t.sol --config test/invariants/fuzz/OpUsdc.yaml --contract FuzzOpUsdc",
"test:integration": "forge test --match-contract Integration -vvv",
Expand All @@ -41,6 +47,7 @@
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"@defi-wonderland/natspec-smells": "1.0.3",
"dotenv-cli": "7.4.2",
"ds-test": "github:dapphub/ds-test#e282159",
"forge-std": "github:foundry-rs/forge-std#1.8.2",
"halmos-cheatcodes": "github:a16z/halmos-cheatcodes#c0d8655",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import {Script} from 'forge-std/Script.sol';
import {console} from 'forge-std/Test.sol';
import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol';

contract L1FactoryDeployAndSetup is Script {
address public constant USDC = 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238;
address public deployer = vm.rememberKey(vm.envUint('SEPOLIA_PK'));
contract DeployL1Factory is Script {
address public deployer = vm.rememberKey(vm.envUint('PRIVATE_KEY'));
address public usdc = vm.envAddress('USDC_ETHEREUM_PROXY');

function run() public {
vm.startBroadcast(deployer);

console.log('Deploying L1OpUSDCFactory ...');
IL1OpUSDCFactory _l1Factory = new L1OpUSDCFactory(USDC);
IL1OpUSDCFactory _l1Factory = new L1OpUSDCFactory(usdc);
console.log('L1OpUSDCFactory deployed at:', address(_l1Factory));
/// NOTE: Hardcode the address on `L1_FACTORY_SEPOLIA` inside the `.env` file
/// NOTE: Hardcode the newly deployed `_l1Factory` address on `L1_FACTORY` inside the `.env` or `.env.testnet` file
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol';
import {IUSDC} from 'interfaces/external/IUSDC.sol';
import {USDCInitTxs} from 'src/contracts/utils/USDCInitTxs.sol';

contract Deploy is Script {
contract DeployProtocol is Script {
uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000;
IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_MAINNET'));
IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY'));
address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('BRIDGED_USDC_IMPLEMENTATION');
address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER');
string public chainName = vm.envString('CHAIN_NAME');
address public owner = vm.rememberKey(vm.envUint('MAINNET_PK'));
address public owner = vm.rememberKey(vm.envUint('PRIVATE_KEY'));

function run() public {
vm.createSelectFork(vm.rpcUrl(vm.envString('MAINNET_RPC')));
vm.startBroadcast(owner);

// NOTE: We have these hardcoded to default values, if used in product you will need to change them

// NOTE: We have these hardcoded to default values, if used in production you will need to change them
bytes[] memory _usdcInitTxs = new bytes[](3);
string memory _name = string.concat('Bridged USDC', ' ', '(', chainName, ')');

Expand All @@ -39,13 +37,13 @@ contract Deploy is Script {
});

// Deploy the L2 contracts
(address _l1Adapter, address _l2Factory, address _l2Adapter) =
(address _l1Adapter, address _l2Deploy, address _l2Adapter) =
L1_FACTORY.deploy(L1_MESSENGER, owner, chainName, _l2Deployments);
vm.stopBroadcast();

/// NOTE: Hardcode the `L1_ADAPTER_BASE` and `L2_ADAPTER_BASE` addresses inside the `.env` file
/// NOTE: Hardcode the newly deployed `_l1Adapter` address on `L1_ADAPTER` inside the `.env` or `env.example` file
console.log('L1 Adapter:', _l1Adapter);
console.log('L2 Factory:', _l2Factory);
console.log('L2 Deploy:', _l2Deploy);
console.log('L2 Adapter:', _l2Adapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ contract MigrateToNative is Script {
uint32 public constant MIN_GAS_LIMIT_SET_BURN_AMOUNT_L2 = 100_000;
IL1OpUSDCBridgeAdapter public immutable L1_ADAPTER = IL1OpUSDCBridgeAdapter(vm.envAddress('L1_ADAPTER'));

address public owner = vm.rememberKey(vm.envUint('MAINNET_OWNER_PK'));
address public owner = vm.rememberKey(vm.envUint('L1_ADAPTER_OWNER_PK'));
address public roleCaller = vm.envAddress('ROLE_CALLER');
address public burnCaller = vm.envAddress('BURN_CALLER');

function run() public {
vm.createSelectFork(vm.rpcUrl(vm.envString('MAINNET_RPC')));
vm.startBroadcast(owner);
L1_ADAPTER.migrateToNative(roleCaller, burnCaller, MIN_GAS_LIMIT_RECEIVE_L2, MIN_GAS_LIMIT_SET_BURN_AMOUNT_L2);
vm.stopBroadcast();
Expand Down
41 changes: 0 additions & 41 deletions script/mainnet/deploy/DeployBase.s.sol

This file was deleted.

Loading