Skip to content

Commit

Permalink
feat: output contract address
Browse files Browse the repository at this point in the history
  • Loading branch information
jakim929 committed Nov 6, 2024
1 parent c4bffa5 commit f390c2a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ docs/

# Dotenv file
.env

deployment.json
1 change: 1 addition & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ libs = ["lib"]
fs_permissions = [
{ access='read', path='./configs' },
{ access='read', path='./test' },
{ access='write', path='./deployment.json' }
]

remappings = [
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Address } from 'viem'

export const deployment: {
deployedAddress: Address
ownerAddress: Address
}
1 change: 1 addition & 0 deletions packages/contracts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as deployment } from './deployment.json'
5 changes: 4 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@superchainerc20-starter/contracts",
"main": "index.js",
"scripts": {
"deploy:dev": "source .env && wait-port http://:8420/ready && forge script scripts/SuperchainERC20Deployer.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"deploy:token": "source .env && forge script scripts/SuperchainERC20Deployer.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
Expand All @@ -9,5 +10,7 @@
"test": "forge test",
"init:env": "cp .env.example .env"
},
"devDependencies": {}
"dependencies": {
"viem": "^2.21.37"
}
}
27 changes: 22 additions & 5 deletions packages/contracts/scripts/SuperchainERC20Deployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,31 @@ contract SuperchainERC20Deployer is Script {
function run() public {
string[] memory chainsToDeployTo = vm.parseTomlStringArray(deployConfig, ".deploy_config.chains");

address deployedAddress;
address ownerAddr;

for (uint256 i = 0; i < chainsToDeployTo.length; i++) {
string memory chainToDeployTo = chainsToDeployTo[i];

console.log("Deploying to chain: ", chainToDeployTo);

vm.createSelectFork(chainToDeployTo);
deployL2NativeSuperchainERC20();
(address _deployedAddress, address _ownerAddr) = deployL2NativeSuperchainERC20();
deployedAddress = _deployedAddress;
ownerAddr = _ownerAddr;
}

outputDeploymentResult(deployedAddress, ownerAddr);
}

function deployL2NativeSuperchainERC20() public broadcast returns (address addr_) {
address owner = vm.parseTomlAddress(deployConfig, ".token.owner_address");
function deployL2NativeSuperchainERC20() public broadcast returns (address addr_, address ownerAddr_) {
ownerAddr_ = vm.parseTomlAddress(deployConfig, ".token.owner_address");
string memory name = vm.parseTomlString(deployConfig, ".token.name");
string memory symbol = vm.parseTomlString(deployConfig, ".token.symbol");
uint256 decimals = vm.parseTomlUint(deployConfig, ".token.decimals");
require(decimals <= type(uint8).max, "decimals exceeds uint8 range");
bytes memory initCode = abi.encodePacked(
type(L2NativeSuperchainERC20).creationCode, abi.encode(owner, name, symbol, uint8(decimals))
type(L2NativeSuperchainERC20).creationCode, abi.encode(ownerAddr_, name, symbol, uint8(decimals))
);
address preComputedAddress = vm.computeCreate2Address(_implSalt(), keccak256(initCode));
if (preComputedAddress.code.length > 0) {
Expand All @@ -52,11 +59,21 @@ contract SuperchainERC20Deployer is Script {
);
addr_ = preComputedAddress;
} else {
addr_ = address(new L2NativeSuperchainERC20{salt: _implSalt()}(owner, name, symbol, uint8(decimals)));
addr_ = address(new L2NativeSuperchainERC20{salt: _implSalt()}(ownerAddr_, name, symbol, uint8(decimals)));
console.log("Deployed L2NativeSuperchainERC20 at address: ", addr_, "on chain id: ", block.chainid);
}
}

function outputDeploymentResult(address deployedAddress, address ownerAddr) public {
console.log("Outputting deployment result");

string memory obj = "result";
vm.serializeAddress(obj, "deployedAddress", deployedAddress);
string memory jsonOutput = vm.serializeAddress(obj, "ownerAddress", ownerAddr);

vm.writeJson(jsonOutput, "deployment.json");
}

/// @notice The CREATE2 salt to be used when deploying the token.
function _implSalt() internal view returns (bytes32) {
string memory salt = vm.parseTomlString(deployConfig, ".deploy_config.salt");
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devDependencies": {
"@eslint/js": "^9.13.0",
"@eth-optimism/viem": "^0.0.11",
"@superchainerc20-starter/contracts": "workspace:*",
"abitype": "^1.0.6",
"typescript": "~5.6.2",
"typescript-eslint": "^8.10.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-test/src/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { parseEnv, z } from 'znv'
import { Address as ZodAddress } from 'abitype/zod'
import { deployment } from '@superchainerc20-starter/contracts'

export const envVars = parseEnv(import.meta.env, {
VITE_TOKEN_CONTRACT_ADDRESS: ZodAddress.default("0x040fC8E3cb47245BaAE006286e8EC177Ff676C1C"),
VITE_TOKEN_MINTER_ADDRESS: ZodAddress.default("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"),
VITE_TOKEN_CONTRACT_ADDRESS: ZodAddress.default(deployment.deployedAddress),
VITE_TOKEN_MINTER_ADDRESS: ZodAddress.default(deployment.ownerAddress),
})
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint \"**/*.{ts,tsx}\" && pnpm prettier --check \"**/*.{ts,tsx}\"",
"lint:fix": "eslint \"**/*.{ts,tsx}\" --fix --quiet && pnpm prettier \"**/*.{ts,tsx}\" --write --loglevel=warn",
"preview": "vite preview",
Expand All @@ -28,6 +27,7 @@
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.3",
"@superchainerc20-starter/contracts": "workspace:*",
"@tanstack/react-query": "^5.59.16",
"@wagmi/core": "^2.14.1",
"abitype": "^1.0.6",
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/src/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { parseEnv, z } from 'znv'
import { Address as ZodAddress } from 'abitype/zod'
import { deployment } from '@superchainerc20-starter/contracts'

export const envVars = parseEnv(import.meta.env, {
VITE_TOKEN_CONTRACT_ADDRESS: ZodAddress,
VITE_TOKEN_CONTRACT_ADDRESS: ZodAddress.default(deployment.deployedAddress),
VITE_TOKEN_MINTER_ADDRESS: ZodAddress.default(deployment.ownerAddress),
VITE_WALLET_CONNECT_PROJECT_ID: z.string().optional(),
})
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f390c2a

Please sign in to comment.