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 13 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
17 changes: 11 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MAINNET_RPC=
OPTIMISM_RPC=
BASE_RPC=
TESTNET_RPC=

# Mainnet
MAINNET_PK=
Expand All @@ -27,10 +28,12 @@ OP_BURN_CALLER_PK=
OP_NEW_USDC_OWNER=

# Testnet
SEPOLIA_PK=
L1_FACTORY_SEPOLIA=
L1_ADAPTER_OP_SEPOLIA=
L2_ADAPTER_OP_SEPOLIA=
TESTNET_PK=
L1_FACTORY_TESTNET=
L1_ADAPTER_OP_TESTNET=
L2_ADAPTER_OP_TESTNET=
TESTNET_BRIDGED_USDC_IMPLEMENTATION=


# Op Sepolia
# Migration related variables
Expand All @@ -48,9 +51,11 @@ ETHERSCAN_API_KEY=
# These need to be deployed and set manually, ideally from circle's stablecoin-evm repo

# Mainnets
USDC=
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
USDC_BASE_IMPLEMENTATION=
USDC_OPTIMISM_IMPLEMENTATION=

# Testnets
USDC_BASE_SEPOLIA_IMPLEMENTATION=
USDC_OPTIMISM_SEPOLIA_IMPLEMENTATION=
TESTNET_USDC=
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
USDC_BASE_TESTNET_IMPLEMENTATION=
USDC_OPTIMISM_TESTNET_IMPLEMENTATION=
30 changes: 26 additions & 4 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 @@ -166,10 +166,32 @@ And when you are ready to deploy to mainnet, run:
yarn script:deploy:broadcast
```

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

And when you are ready to deploy to mainnet, run:
```bash
yarn mainnet:deploy: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>"
}
```
Make sure to add it inside the `"libraries"` field of the `"settings"` block where `"compilationTarget"` matches `"src/contracts/L1OpUSDCFactory.sol": "L1OpUSDCFactory"`.

## 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 Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ runs = 1000
mainnet = "${MAINNET_RPC}"
optimism = "${OPTIMISM_RPC}"
base = "${BASE_RPC}"
testnet = "${TESTNET_RPC}"
sepolia = "${SEPOLIA_RPC}"

[etherscan]
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@
"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'",
"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'",
"mainnet:deploy:factory": "dotenv -e .env -- sh -c 'forge script script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol:L1FactoryDeployAndSetup --via-ir -vv --rpc-url $MAINNET_RPC'",
"mainnet:deploy:factory:broadcast": "dotenv -e .env -- sh -c 'forge script script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol:L1FactoryDeployAndSetup --via-ir --broadcast -vv --rpc-url $MAINNET_RPC'",
"mainnet:deploy:protocol": "dotenv -e .env -- sh -c 'forge script script/mainnet/deploy/Deploy.s.sol --slow --via-ir -vv --rpc-url $MAINNET_RPC'",
"mainnet:deploy:protocol:broadcast": "dotenv -e .env -- sh -c 'forge script script/mainnet/deploy/Deploy.s.sol --slow --via-ir --broadcast -vv --rpc-url $MAINNET_RPC'",
"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",
"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",
"test:symb": "halmos",
"test:unit": "forge test --match-contract Unit -vvv",
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit"
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit",
"testnet:deploy:factory": "dotenv -e .env -- sh -c 'forge script script/testnet/deploy/L1FactoryDeployAndSetup.s.sol:L1FactoryDeployAndSetup --slow --via-ir -vv --rpc-url $TESTNET_RPC'",
"testnet:deploy:factory:broadcast": "dotenv -e .env -- sh -c 'forge script script/testnet/deploy/L1FactoryDeployAndSetup.s.sol:L1FactoryDeployAndSetup --via-ir --broadcast -vv --rpc-url ${TESTNET_RPC}'",
"testnet:deploy:protocol": "dotenv -e .env -- sh -c 'forge script script/testnet/deploy/Deploy.s.sol --via-ir -vv --rpc-url $TESTNET_RPC'",
"testnet:deploy:protocol:broadcast": "dotenv -e .env -- sh -c 'forge script script/testnet/deploy/Deploy.s.sol --slow --via-ir --broadcast -vv --rpc-url $TESTNET_RPC'"
},
"lint-staged": {
"*.{js,css,md,ts,sol}": "forge fmt",
Expand All @@ -41,6 +45,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
2 changes: 0 additions & 2 deletions script/mainnet/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ contract Deploy is Script {
address public owner = vm.rememberKey(vm.envUint('MAINNET_PK'));

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

bytes[] memory _usdcInitTxs = new bytes[](3);
string memory _name = string.concat('Bridged USDC', ' ', '(', chainName, ')');

Expand Down
49 changes: 49 additions & 0 deletions script/testnet/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Script} from 'forge-std/Script.sol';
import {console} from 'forge-std/Test.sol';
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 {
uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000;
IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_TESTNET'));
address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('TESTNET_BRIDGED_USDC_IMPLEMENTATION');
address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER_TESTNET');
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
string public chainName = vm.envString('TESTNET_CHAIN_NAME');
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
address public owner = vm.rememberKey(vm.envUint('TESTNET_PK'));

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

// NOTE: We have these hardcoded to default values, if used in product you will need to change them
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
bytes[] memory _usdcInitTxs = new bytes[](3);
string memory _name = string.concat('Bridged USDC', ' ', '(', chainName, ')');
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved

_usdcInitTxs[0] = abi.encodeCall(IUSDC.initializeV2, (_name));
_usdcInitTxs[1] = USDCInitTxs.INITIALIZEV2_1;
_usdcInitTxs[2] = USDCInitTxs.INITIALIZEV2_2;

// Sanity check to ensure the caller of this script changed this value to the proper naming
assert(keccak256(_usdcInitTxs[0]) != keccak256(USDCInitTxs.INITIALIZEV2));

IL1OpUSDCFactory.L2Deployments memory _l2Deployments = IL1OpUSDCFactory.L2Deployments({
l2AdapterOwner: owner,
usdcImplAddr: BRIDGED_USDC_IMPLEMENTATION,
usdcInitTxs: _usdcInitTxs,
minGasLimitDeploy: MIN_GAS_LIMIT_DEPLOY
});

// Deploy the L2 contracts
(address _l1Adapter, address _l2Factory, 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
console.log('L1 Adapter:', _l1Adapter);
console.log('L2 Factory:', _l2Factory);
console.log('L2 Adapter:', _l2Adapter);
}
}
10 changes: 5 additions & 5 deletions script/testnet/deploy/L1FactoryDeployAndSetup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ 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'));
address public deployer = vm.rememberKey(vm.envUint('TESTNET_PK'));
address public usdc = vm.envAddress('TESTNET_USDC');

function run() public {
vm.createSelectFork(vm.rpcUrl(vm.envString('TESTNET_RPC')));
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
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 address on `L1_FACTORY_TESTNET` inside the `.env` file
vm.stopBroadcast();
}
}
3 changes: 2 additions & 1 deletion test/integration/L2OpUSDCBridgeAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ contract Integration_Bridging is IntegrationBase {
vm.prank(address(l2Adapter));
bridgedUSDC.mint(_user, _amount);

uint256 _userBalanceBefore = bridgedUSDC.balanceOf(_user);
0xDiscotech marked this conversation as resolved.
Show resolved Hide resolved
vm.startPrank(_user);
bridgedUSDC.approve(address(l2Adapter), _amount);
l2Adapter.sendMessage(_user, _amount, _MIN_GAS_LIMIT);
vm.stopPrank();

assertEq(bridgedUSDC.balanceOf(_user), 0);
assertEq(bridgedUSDC.balanceOf(_user), _userBalanceBefore - _amount);
assertEq(bridgedUSDC.balanceOf(address(l2Adapter)), 0);

vm.selectFork(mainnet);
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,26 @@ dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

[email protected]:
version "7.4.2"
resolved "https://registry.yarnpkg.com/dotenv-cli/-/dotenv-cli-7.4.2.tgz#c158a818de08e1fbc51d310f628cbace9075b734"
integrity sha512-SbUj8l61zIbzyhIbg0FwPJq6+wjbzdn9oEtozQpZ6kW2ihCcapKVZj49oCT3oPM+mgQm+itgvUQcG5szxVrZTA==
dependencies:
cross-spawn "^7.0.3"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0:
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

"ds-test@github:dapphub/ds-test#e282159":
version "1.0.0"
resolved "https://codeload.github.com/dapphub/ds-test/tar.gz/e282159d5170298eb2455a6c05280ab5a73a4ef0"
Expand Down