Skip to content

Commit

Permalink
WIP - Add depleyment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcorbalan committed May 3, 2024
1 parent b81010a commit e5f4262
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"


export DEPLOYER_PK="your deployer private key"
export SEPOLIA_RPC_URL="some sepolia RPC URL"
export ETHERSCAN_API_KEY="your etherscan api key"

export XERC20_FACTORY="0x89c1ffFc94Fd0FAb9F98bC58cCA884B5dF1dA437"
export XERC20_NAME="XERC20 TEST"
export XERC20_SYMBOL="XERC20 TEST"

export L1_GATEWAY_OWNER="L1 gateway owner address"
export L1_ARBITRUM_ROUTER="0xcE18836b233C83325Cc8848CA4487e94C6288264"
export L1_ARBITRUM_INBOX="0xaAe29B0366299461418F5324a79Afc425BE5ae21"
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
mainnet = "https://eth.llamarpc.com"
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${API_KEY_ALCHEMY}"
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
"dependencies": {
"@arbitrum/token-bridge-contracts": "github:OffchainLabs/token-bridge-contracts",
"@openzeppelin/contracts": "^4.9.6",
"solmate": "github:transmissions11/solmate",
"xerc20": "github:defi-wonderland/xERC20"
},
"devDependencies": {
"dotenv": "^16.4.5",
"dotenv-run-script": "^0.4.1",
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
"prettier": "^3.0.0",
"solhint": "^3.6.2"
Expand All @@ -26,6 +29,12 @@
"prettier:write": "prettier --write \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"",
"test": "forge test",
"test:coverage": "forge coverage",
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage"
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage",
"factory:sepolia": "forge script script/XERC20/XERC20Factory.s.sol:XERC20FactoryDeploy --rpc-url $SEPOLIA_RPC_URL --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -vvvv",
"deploy:factory:sepolia": "dotenv-run-script factory:sepolia",
"token:sepolia": "forge script script/XERC20/XERC20.s.sol:XERC20Deploy --rpc-url $SEPOLIA_RPC_URL --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -vvvv",
"deploy:token:sepolia": "dotenv-run-script token:sepolia",
"gateway:sepolia": "forge script script/L1Gateway.s.sol:L1GatewayDeploy --rpc-url $SEPOLIA_RPC_URL --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -vvvv",
"deploy:gateway:sepolia": "dotenv-run-script gateway:sepolia"
}
}
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
forge-std/=node_modules/forge-std/src/
xerc20/=node_modules/xerc20/solidity/
solmate/=node_modules/solmate/src/
isolmate/=node_modules/solmate/src/
12 changes: 0 additions & 12 deletions script/Deploy.s.sol

This file was deleted.

53 changes: 53 additions & 0 deletions script/L1Gateway.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { Script } from "forge-std/Script.sol";
import { L1XERC20Gateway } from "src/L1XERC20Gateway.sol";
import {CREATE3} from 'solmate/utils/CREATE3.sol';

/// @title Factory for deploying contracts to deterministic addresses via CREATE3
/// @author zefram.eth
/// @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has
/// its own namespace for deployed addresses.
interface ICREATE3Factory {
/// @notice Deploys a contract using CREATE3
/// @dev The provided salt is hashed together with msg.sender to generate the final salt
/// @param salt The deployer-specific salt for determining the deployed contract's address
/// @param creationCode The creation code of the contract to deploy
/// @return deployed The address of the deployed contract
function deploy(bytes32 salt, bytes memory creationCode)
external
payable
returns (address deployed);

/// @notice Predicts the address of a deployed contract
/// @dev The provided salt is hashed together with the deployer address to generate the final salt
/// @param deployer The deployer account that will call deploy()
/// @param salt The deployer-specific salt for determining the deployed contract's address
/// @return deployed The address of the contract that will be deployed
function getDeployed(address deployer, bytes32 salt)
external
view
returns (address deployed);
}

contract L1GatewayDeploy is Script {
string public constant SALT = 'XERC20Gateway-v0.2';
function run() public {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PK");
address owner = vm.envAddress("L1_GATEWAY_OWNER");
address router = vm.envAddress("L1_ARBITRUM_ROUTER");
address inbox = vm.envAddress("L1_ARBITRUM_INBOX");

vm.startBroadcast(deployerPrivateKey);

bytes32 _salt = keccak256(abi.encodePacked(SALT, msg.sender));

bytes memory _creation = type(L1XERC20Gateway).creationCode;
bytes memory _bytecode = abi.encodePacked(_creation, abi.encode(owner, router, inbox));

ICREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1).deploy(_salt, _bytecode);

vm.stopBroadcast();
}
}
24 changes: 24 additions & 0 deletions script/XERC20/XERC20.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { Script } from "forge-std/Script.sol";
import { XERC20Factory } from "xerc20/contracts/XERC20Factory.sol";

contract XERC20Deploy is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PK");

address factoryAdrress = vm.envAddress("XERC20_FACTORY");
string memory name = vm.envString("XERC20_NAME");
string memory symbol = vm.envString("XERC20_SYMBOL");

uint256[] memory limits = vm.envOr("XERC20_BURN_MINT_LIMITS", ',', new uint256[](0));
address[] memory bridges = vm.envOr("XERC20_BRIDGES", ',', new address[](0));

vm.startBroadcast(deployerPrivateKey);

XERC20Factory(factoryAdrress).deployXERC20(name, symbol, limits, limits, bridges);

vm.stopBroadcast();
}
}
21 changes: 21 additions & 0 deletions script/XERC20/XERC20Factory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { Script } from "forge-std/Script.sol";
import { XERC20Factory } from "xerc20/contracts/XERC20Factory.sol";

contract XERC20FactoryDeploy is Script {
string public constant SALT = 'xERC20-v1.5';

function run() public {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PK");

vm.startBroadcast(deployerPrivateKey);

bytes32 _salt = keccak256(abi.encodePacked(SALT, msg.sender));

new XERC20Factory{salt: _salt}();

vm.stopBroadcast();
}
}

0 comments on commit e5f4262

Please sign in to comment.