/
OPBridgedERC20.js
95 lines (82 loc) · 2.6 KB
/
OPBridgedERC20.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Deploy a bridged ERC20 UDT token contract on Optimism networks
*
* Please edit the chain ids constant below to use
*/
const { getNetwork, getEvent } = require('@unlock-protocol/hardhat-helpers')
const { getProvider } = require('../../helpers/multisig')
const { ethers } = require('hardhat')
const fs = require('fs-extra')
// base factory address from https://docs.base.org/base-contracts/
const OptimismMintableERC20Factory = {
base: '0xf23d369d7471bD9f6487E198723eEa023389f1d4',
optimism: '0x4200000000000000000000000000000000000012',
baseSepolia: '0x4200000000000000000000000000000000000012',
}
// OP factory address
// const OP_OptimismMintableERC20Factory =
// edit default values
const L1_CHAIN_ID = 11155111 // default to (Sepolia 11155111)
const l2_CHAIN_ID = 84532 // default to (Base Sepolia 84532)
async function main({
tokenSymbol = 'UDT',
tokenName = 'UnlockDiscountToken',
factoryAddress = OptimismMintableERC20Factory.baseSepolia, // bridged erc20 factory address
l1ChainId = L1_CHAIN_ID,
l2ChainId = l2_CHAIN_ID,
} = {}) {
const { DEPLOYER_PRIVATE_KEY } = process.env
const {
name: l1Name,
unlockDaoToken: { address: l1TokenAddress },
} = await getNetwork(l1ChainId)
if (!l1TokenAddress) {
throw new Error(`Missing UDT on L1 ${l1Name}`)
}
// get l2 network info
const l2 = await getNetwork(l2ChainId)
console.log(
`Deploying bridged token from L1 (${l1Name}) ${l1TokenAddress} to L2 ${l2.name} (${l2.id})...
- token: ${l1TokenAddress} `
)
// Create the RPC providers and wallets
const { provider: l2Provider } = await getProvider(l2ChainId)
const l2Wallet = new ethers.Wallet(DEPLOYER_PRIVATE_KEY, l2Provider)
// read ABI from node_modules
const { abi: factoryAbi } = JSON.parse(
fs
.readFileSync(
'../node_modules/@eth-optimism/contracts-bedrock/deployments/mainnet/OptimismMintableERC20Factory.json'
)
.toString()
.replace(/\n/g, '')
)
// get factory contract instance
const factory = await ethers.getContractAt(
factoryAbi,
factoryAddress,
l2Wallet
)
// create bridged token
const tx = await factory.createOptimismMintableERC20(
l1TokenAddress,
tokenName,
tokenSymbol
)
// fetch info from tx
const receipt = await tx.wait()
const {
args: { localToken },
hash,
} = await getEvent(receipt, 'OptimismMintableERC20Created')
console.log(`Bridged token deployed at: ${localToken} (${hash})`)
}
// execute as standalone
if (require.main === module) {
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
}