Skip to content

Commit

Permalink
Merge pull request #96 from clober-dex/feat/deploy-zksync
Browse files Browse the repository at this point in the history
Feat/deploy zksync
  • Loading branch information
JhChoy authored Sep 9, 2024
2 parents aee8fdd + 4ea181e commit f1ecec4
Show file tree
Hide file tree
Showing 9 changed files with 8,969 additions and 8,858 deletions.
58 changes: 58 additions & 0 deletions deploy/deploy-mockToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { Wallet } from 'zksync-ethers'
import * as ethers from 'ethers'
import { Deployer } from '@matterlabs/hardhat-zksync-deploy'

// load env file
import dotenv from 'dotenv'
dotenv.config()

// load wallet private key from env file
const PRIVATE_KEY = process.env.DEV_PRIVATE_KEY || ''

if (!PRIVATE_KEY) throw '⛔️ Private key not detected! Add it to the .env file!'

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the Foo contract`)

// Initialize the wallet.
const wallet = new Wallet(PRIVATE_KEY)

// Create deployer object and load the artifact of the contract you want to deploy.
const deployer = new Deployer(hre, wallet)
const artifact = await deployer.loadArtifact('Foo')

// Estimate contract deployment fee
const args: any[] = []
const deploymentFee = await deployer.estimateDeployFee(artifact, args)

// ⚠️ OPTIONAL: You can skip this block if your account already has funds in L2
// const depositHandle = await deployer.zkWallet.deposit({
// to: deployer.zkWallet.address,
// token: utils.ETH_ADDRESS,
// amount: deploymentFee.mul(2),
// });
// // Wait until the deposit is processed on zkSync
// await depositHandle.wait();

// Deploy this contract. The returned object will be of a `Contract` type, similar to ones in `ethers`.
// `greeting` is an argument for contract constructor.
const parsedFee = ethers.formatEther(deploymentFee)
console.log(`The deployment is estimated to cost ${parsedFee} ETH`)

const greeterContract = await deployer.deploy(artifact, args)

//obtain the Constructor Arguments
console.log('constructor args:' + greeterContract.interface.encodeDeploy(args))

// Show the contract info.
const contractAddress = await greeterContract.getAddress()
console.log(`${artifact.contractName} was deployed to ${contractAddress}`)

await hre.run('verify:verify', {
address: contractAddress,
args,
contract: 'src/Foo.sol:Foo',
})
}
68 changes: 68 additions & 0 deletions deploy/deploy-zkSync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Wallet } from 'zksync-ethers'
import * as ethers from 'ethers'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { Deployer } from '@matterlabs/hardhat-zksync-deploy'

// load env file
import dotenv from 'dotenv'
import { getChain } from '@nomicfoundation/hardhat-viem/internal/chains'
import { zkSync, zkSyncSepoliaTestnet } from 'viem/chains'
dotenv.config()

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the BookManager contract`)
const chain = await getChain(hre.network.provider)
if (chain.id !== zkSyncSepoliaTestnet.id && chain.id !== zkSync.id) {
throw new Error('Unsupported chain')
}

// Initialize the wallet.
const accounts = hre.config.networks[chain.id].accounts
if (!Array.isArray(accounts)) throw new Error('Invalid accounts')
const privateKey = accounts[0]
if (!privateKey) throw new Error('Private key not found')
if (typeof privateKey !== 'string') throw new Error('Invalid private key')
const wallet = new Wallet(privateKey)

// Create deployer object and load the artifact of the contract you want to deploy.
const deployer = new Deployer(hre, wallet)
const artifact = await deployer.loadArtifact('BookManager')

// Estimate contract deployment fee
let owner = ''
let treasury = ''
if (chain.id === zkSyncSepoliaTestnet.id) {
owner = deployer.zkWallet.address
treasury = deployer.zkWallet.address
} else if (chain.id === zkSync.id) {
owner = '0xc0f2c32E7FF56318291c6bfA4C998A2F7213D2e0'
treasury = '0xfc5899d93df81ca11583bee03865b7b13ce093a7'
}
const constructorArguments = [
owner,
treasury,
`https://clober.io/api/nft/chains/${chain.id}/orders/`,
`https://clober.io/api/contract/chains/${chain.id}`,
'Clober Orderbook Maker Order',
'CLOB-ORDER',
]
const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments)
const parsedFee = ethers.formatEther(deploymentFee)
console.log(`The deployment is estimated to cost ${parsedFee} ETH`)

const contract = await deployer.deploy(artifact, constructorArguments)

//obtain the Constructor Arguments
console.log('constructor args:' + contract.interface.encodeDeploy(constructorArguments))

// Show the contract info.
const contractAddress = await contract.getAddress()
console.log(`${artifact.contractName} was deployed to ${contractAddress}`)

await hre.run('verify:verify', {
address: contractAddress,
constructorArguments,
contract: 'src/BookManager.sol:BookManager',
})
}
1 change: 1 addition & 0 deletions deployments-zk/300/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x12c
Loading

0 comments on commit f1ecec4

Please sign in to comment.