diff --git a/packages/contracts/.gitignore b/packages/contracts/.gitignore index a3c19dd..a99b0b4 100644 --- a/packages/contracts/.gitignore +++ b/packages/contracts/.gitignore @@ -10,3 +10,5 @@ docs/ # Dotenv file .env + +deployment.json \ No newline at end of file diff --git a/packages/contracts/foundry.toml b/packages/contracts/foundry.toml index c0287a3..d29ea51 100644 --- a/packages/contracts/foundry.toml +++ b/packages/contracts/foundry.toml @@ -13,6 +13,7 @@ libs = ["lib"] fs_permissions = [ { access='read', path='./configs' }, { access='read', path='./test' }, + { access='write', path='./deployment.json' } ] remappings = [ diff --git a/packages/contracts/index.d.ts b/packages/contracts/index.d.ts new file mode 100644 index 0000000..81e21e3 --- /dev/null +++ b/packages/contracts/index.d.ts @@ -0,0 +1,6 @@ +import { Address } from 'viem' + +export const deployment: { + deployedAddress: Address + ownerAddress: Address +} diff --git a/packages/contracts/index.js b/packages/contracts/index.js new file mode 100644 index 0000000..d81ba41 --- /dev/null +++ b/packages/contracts/index.js @@ -0,0 +1 @@ +export { default as deployment } from './deployment.json' \ No newline at end of file diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 86256e6..a68799b 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -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", @@ -9,5 +10,7 @@ "test": "forge test", "init:env": "cp .env.example .env" }, - "devDependencies": {} + "dependencies": { + "viem": "^2.21.37" + } } \ No newline at end of file diff --git a/packages/contracts/scripts/SuperchainERC20Deployer.s.sol b/packages/contracts/scripts/SuperchainERC20Deployer.s.sol index a9d4ff8..5be97fa 100644 --- a/packages/contracts/scripts/SuperchainERC20Deployer.s.sol +++ b/packages/contracts/scripts/SuperchainERC20Deployer.s.sol @@ -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) { @@ -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"); diff --git a/packages/e2e-test/package.json b/packages/e2e-test/package.json index fec6021..a3e4f7d 100644 --- a/packages/e2e-test/package.json +++ b/packages/e2e-test/package.json @@ -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", diff --git a/packages/e2e-test/src/envVars.ts b/packages/e2e-test/src/envVars.ts index 0f3b8a4..60663ec 100644 --- a/packages/e2e-test/src/envVars.ts +++ b/packages/e2e-test/src/envVars.ts @@ -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), }) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 1f98452..4c5ed55 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -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", @@ -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", diff --git a/packages/frontend/src/envVars.ts b/packages/frontend/src/envVars.ts index 0aac827..b52422a 100644 --- a/packages/frontend/src/envVars.ts +++ b/packages/frontend/src/envVars.ts @@ -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(), }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc771ac..91a6aaf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,7 +27,11 @@ importers: specifier: ^1.1.0 version: 1.1.0 - packages/contracts: {} + packages/contracts: + dependencies: + viem: + specifier: ^2.21.37 + version: 2.21.37(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@5.0.10)(zod@3.23.8) packages/e2e-test: devDependencies: @@ -37,6 +41,9 @@ importers: '@eth-optimism/viem': specifier: ^0.0.11 version: 0.0.11(viem@2.21.37(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@5.0.10)(zod@3.23.8)) + '@superchainerc20-starter/contracts': + specifier: workspace:* + version: link:../contracts abitype: specifier: ^1.0.6 version: 1.0.6(typescript@5.6.2)(zod@3.23.8) @@ -106,6 +113,9 @@ importers: '@radix-ui/react-tooltip': specifier: ^1.1.3 version: 1.1.3(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@superchainerc20-starter/contracts': + specifier: workspace:* + version: link:../contracts '@tanstack/react-query': specifier: ^5.59.16 version: 5.59.16(react@18.3.1)