-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support zkSyncEra and zkSyndTestnet chains #1259
Merged
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8834eb0
added zksync packages and hardhat config
KolevDarko 69d037a
deployed erc20feeproxy and eth fee proxy to zkSyncTestnet
KolevDarko e617b4d
added artifacts config for erc and eth proxies on zksync era goerli
KolevDarko b43b865
added zksync networks to types and currency packages
KolevDarko 419bd9c
added accounts to hardhat config for zksync
KolevDarko 80979e9
deployed contracts to zkSync and addresses in config
KolevDarko fc9dbdf
renamed zkSyncEraGoerli to zkSyncEraTestnet and cleanup
KolevDarko c32363e
one more place to rename
KolevDarko cee7716
Merge branch 'master' into feat/support-zksync
KolevDarko c5c8bda
getting rpc directly and removed zksync types
KolevDarko 3ed4097
absolute versions of matterlab packages
KolevDarko ee242bd
renamed zksync symbol to ETH
KolevDarko da521fc
deploy batch contract on zksync testnet
KolevDarko 2a262a3
updated zksync native token names
KolevDarko 6ec7bec
updated README with zkSync info in smart-contracts package
KolevDarko 84eaa48
check if it works without xdai on SF test
KolevDarko cc85517
improved comments
KolevDarko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const chainId = 280; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const chainId = 324; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/smart-contracts/deploy/deploy-zk-batch-contracts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||||
import { erc20FeeProxyArtifact, ethereumFeeProxyArtifact } from '../src/lib'; | ||||||||
import { deployContract } from './utils'; | ||||||||
import * as hre from 'hardhat'; | ||||||||
import { VMChainName } from 'types/dist/currency-types'; | ||||||||
KolevDarko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
// An example of a basic deploy script | ||||||||
// It will deploy a Greeter contract to selected network | ||||||||
// as well as verify it on Block Explorer if possible for the network | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
export default async function () { | ||||||||
const [deployer] = await hre.ethers.getSigners(); | ||||||||
const constructorArguments = [ | ||||||||
erc20FeeProxyArtifact.getAddress(hre.network.name as VMChainName), | ||||||||
ethereumFeeProxyArtifact.getAddress(hre.network.name as VMChainName), | ||||||||
hre.ethers.constants.AddressZero, | ||||||||
hre.ethers.constants.AddressZero, | ||||||||
hre.ethers.constants.AddressZero, | ||||||||
deployer.address, | ||||||||
]; | ||||||||
console.log(`Deploying BatchConversionPayments to zkSync ...`); | ||||||||
await deployContract('BatchConversionPayments', constructorArguments); | ||||||||
} |
14 changes: 14 additions & 0 deletions
14
packages/smart-contracts/deploy/deploy-zk-proxy-contracts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { deployContract } from './utils'; | ||
|
||
// An example of a basic deploy script | ||
KolevDarko marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment |
||
// It will deploy a Greeter contract to selected network | ||
// as well as verify it on Block Explorer if possible for the network | ||
export default async function () { | ||
const deployList: string[] = ['ERC20FeeProxy', 'EthereumFeeProxy']; | ||
|
||
for (let index = 0; index < deployList.length; index++) { | ||
const contractName = deployList[index]; | ||
console.log(`Deploying ${contractName} to zkSync ...`); | ||
await deployContract(contractName, []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import { Provider, Wallet, Contract } from 'zksync-web3'; | ||
import * as hre from 'hardhat'; | ||
import { Deployer } from '@matterlabs/hardhat-zksync-deploy'; | ||
import { formatEther } from 'ethers/lib/utils'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import '@matterlabs/hardhat-zksync-node/dist/type-extensions'; | ||
import '@matterlabs/hardhat-zksync-verify/dist/src/type-extensions'; | ||
KolevDarko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { config } from 'dotenv'; | ||
|
||
config(); | ||
|
||
const accounts = process.env.DEPLOYMENT_PRIVATE_KEY | ||
? [process.env.DEPLOYMENT_PRIVATE_KEY] | ||
: process.env.DEPLOYER_MASTER_KEY | ||
? [process.env.DEPLOYER_MASTER_KEY] | ||
: process.env.ADMIN_PRIVATE_KEY | ||
? [process.env.ADMIN_PRIVATE_KEY] | ||
: undefined; | ||
|
||
const WALLET_PRIVATE_KEY = (accounts || [])[0]; | ||
|
||
export const getProvider = () => { | ||
const rpcUrl = hre.network.config.url; | ||
if (!rpcUrl) | ||
throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; | ||
|
||
// Initialize zkSync Provider | ||
const provider = new Provider(rpcUrl); | ||
KolevDarko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return provider; | ||
}; | ||
|
||
export const getWallet = (privateKey?: string): Wallet => { | ||
if (!privateKey) { | ||
// Get wallet private key from .env file | ||
if (!WALLET_PRIVATE_KEY) throw "⛔️ Wallet private key wasn't found in .env file!"; | ||
} | ||
|
||
const provider = getProvider(); | ||
|
||
// Initialize zkSync Wallet | ||
const wallet = new Wallet(privateKey ?? WALLET_PRIVATE_KEY!, provider); | ||
|
||
return wallet; | ||
}; | ||
|
||
export const verifyEnoughBalance = async (wallet: Wallet, amount: BigNumberish) => { | ||
// Check if the wallet has enough balance | ||
const balance = await wallet.getBalance(); | ||
if (balance.lt(amount)) | ||
throw `⛔️ Wallet balance is too low! Required ${formatEther(amount)} ETH, but current ${ | ||
wallet.address | ||
} balance is ${formatEther(balance)} ETH`; | ||
}; | ||
|
||
/** | ||
* @param {string} data.contract The contract's path and name. E.g., "contracts/Greeter.sol:Greeter" | ||
*/ | ||
export const verifyContract = async (data: { | ||
address: string; | ||
contract: string; | ||
constructorArguments: string | []; | ||
bytecode: string; | ||
}) => { | ||
const verificationRequestId: number = await hre.run('verify:verify', { | ||
...data, | ||
noCompile: true, | ||
}); | ||
return verificationRequestId; | ||
}; | ||
|
||
type DeployContractOptions = { | ||
/** | ||
* If true, the deployment process will not print any logs | ||
*/ | ||
silent?: boolean; | ||
/** | ||
* If true, the contract will not be verified on Block Explorer | ||
*/ | ||
noVerify?: boolean; | ||
/** | ||
* If specified, the contract will be deployed using this wallet | ||
*/ | ||
wallet?: Wallet; | ||
}; | ||
|
||
export const verifyContractByName = async ( | ||
contractArtifactName: string, | ||
contractAddress: string, | ||
) => { | ||
const wallet = getWallet(); | ||
const deployer = new Deployer(hre, wallet); | ||
|
||
const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => { | ||
if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) { | ||
console.error(error.message); | ||
throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; | ||
} else { | ||
throw error; | ||
} | ||
}); | ||
|
||
const fullContractSource = `${artifact.sourceName}:${artifact.contractName}`; | ||
|
||
// Display contract deployment info | ||
console.log(`\n"${artifact.contractName}" was successfully deployed:`); | ||
console.log(` - Contract address: ${contractAddress}`); | ||
console.log(` - Contract source: ${fullContractSource}`); | ||
|
||
console.log(`Requesting contract verification...`); | ||
await verifyContract({ | ||
address: contractAddress, | ||
contract: fullContractSource, | ||
constructorArguments: [], | ||
bytecode: artifact.bytecode, | ||
}); | ||
}; | ||
|
||
export const deployContract = async ( | ||
contractArtifactName: string, | ||
constructorArguments?: any[], | ||
options?: DeployContractOptions, | ||
): Promise<Contract> => { | ||
const log = (message: string) => { | ||
if (!options?.silent) console.log(message); | ||
}; | ||
|
||
log(`\nStarting deployment process of "${contractArtifactName}"...`); | ||
|
||
const wallet = options?.wallet ?? getWallet(); | ||
const deployer = new Deployer(hre, wallet); | ||
|
||
const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => { | ||
if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) { | ||
console.error(error.message); | ||
throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; | ||
} else { | ||
throw error; | ||
} | ||
}); | ||
|
||
// Estimate contract deployment fee | ||
const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []); | ||
log(`Estimated deployment cost: ${formatEther(deploymentFee)} ETH`); | ||
|
||
// Check if the wallet has enough balance | ||
await verifyEnoughBalance(wallet, deploymentFee); | ||
|
||
// Deploy the contract to zkSync | ||
const contract = await deployer.deploy(artifact, constructorArguments); | ||
|
||
const constructorArgs = contract.interface.encodeDeploy(constructorArguments); | ||
const fullContractSource = `${artifact.sourceName}:${artifact.contractName}`; | ||
|
||
// Display contract deployment info | ||
log(`\n"${artifact.contractName}" was successfully deployed:`); | ||
log(` - Contract address: ${contract.address}`); | ||
log(` - Contract source: ${fullContractSource}`); | ||
log(` - Encoded constructor arguments: ${constructorArgs}\n`); | ||
|
||
if (!options?.noVerify && hre.network.config.verifyURL) { | ||
log(`Requesting contract verification...`); | ||
await verifyContract({ | ||
address: contract.address, | ||
contract: fullContractSource, | ||
constructorArguments: constructorArgs, | ||
bytecode: artifact.bytecode, | ||
}); | ||
} | ||
|
||
return contract; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"test/", | ||
"scripts/", | ||
"scripts-create2/", | ||
"deploy/", | ||
"hardhat.config.ts" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we don't keep the usual format (
zk-sync-era-testnet
) ?