Skip to content
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

[SC-1343] Update zkSync verification to use an Etherscan-like explorer #167

Merged
merged 8 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions docs/js/hardhat-setup/classes/Networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#### Defined in

[hardhat-setup/networks.ts:75](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L75)
[hardhat-setup/networks.ts:75](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L75)

## Properties

Expand All @@ -38,7 +38,7 @@

#### Defined in

[hardhat-setup/networks.ts:73](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L73)
[hardhat-setup/networks.ts:73](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L73)

***

Expand All @@ -48,13 +48,13 @@

#### Defined in

[hardhat-setup/networks.ts:72](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L72)
[hardhat-setup/networks.ts:72](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L72)

## Methods

### register()

> **register**(`name`, `chainId`, `rpc`?, `privateKey`?, `etherscanNetworkName`?, `etherscanKey`?, `hardfork`?): `void`
> **register**(`name`, `chainId`, `rpc`?, `privateKey`?, `etherscanNetworkName`?, `etherscanKey`?, `hardfork`?, `l1Network`?): `void`

#### Parameters

Expand All @@ -72,13 +72,15 @@

• **hardfork?**: `string` = `'shanghai'`

• **l1Network?**: `string`

#### Returns

`void`

#### Defined in

[hardhat-setup/networks.ts:99](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L99)
[hardhat-setup/networks.ts:99](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L99)

***

Expand All @@ -100,7 +102,7 @@

#### Defined in

[hardhat-setup/networks.ts:142](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L142)
[hardhat-setup/networks.ts:124](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L124)

***

Expand Down Expand Up @@ -132,34 +134,4 @@

#### Defined in

[hardhat-setup/networks.ts:116](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L116)

***

### registerZksync()

> **registerZksync**(`name`, `chainId`, `rpc`?, `ethNetwork`?, `privateKey`?, `verifyURL`?, `hardfork`?): `void`

#### Parameters

• **name**: `string`

• **chainId**: `number`

• **rpc?**: `string`

• **ethNetwork?**: `string`

• **privateKey?**: `string`

• **verifyURL?**: `string`

• **hardfork?**: `string` = `'paris'`

#### Returns

`void`

#### Defined in

[hardhat-setup/networks.ts:123](https://github.com/1inch/solidity-utils/blob/f9426ba6dab1eac9ac07fe3976b8d1cb2d2e5ba1/hardhat-setup/networks.ts#L123)
[hardhat-setup/networks.ts:117](https://github.com/1inch/solidity-utils/blob/1f96397aedbb993a6d3faaeed4b2f77929d81ef0/hardhat-setup/networks.ts#L117)
15 changes: 2 additions & 13 deletions hardhat-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ This class is your go-to assistant for setting up various blockchain networks fo

3. **`registerCustom(...)`**: Allows registering custom networks with custom parameters for Etherscan contract verifications.

4. **`registerZksync(...)`**: A specialized method for registering zkSync networks with additional parameters which specified for zksync network.

5. **`registerAll()`**: Registers multiple standard networks using environment variables for configuration.

## Predefined environment variable names and their format
Expand Down Expand Up @@ -62,24 +60,15 @@ This class is your go-to assistant for setting up various blockchain networks fo
- `PRIVATE_KEY=f040ec294d83b8abf0803b713ebdac7e6ef8c104bd644a45d32114e7a210ce74`
- `MAINNET_PRIVATE_KEY=f040ec294d83b8abf0803b713ebdac7e6ef8c104bd644a45d32114e7a210ce74`

4. **`etherscan key`**
3. **`etherscan key`**

`<NETWORK_NAME>_ETHERSCAN_KEY` - The Etherscan's key to verify contracts for the specific network with `<NETWORK_NAME>`.

Format:
- Just a string with Etherscan API KEY
- Example: `MAINNET_ETHERSCAN_KEY=UFAPYWUQYZMR1NTER4G0BKB52WIOE6LKD9`

4. **`verify url in zksync`**

`<NETWORK_NAME>_VERIFY_URL` - The veridy url to verify contracts for the specific network with `<NETWORK_NAME>`.

Format:
- Just a link to verification service
- Example: `ZKSYNC_VERIFY_URL=https://zksync2-mainnet-explorer.zksync.io/contract_verification`
- Default value (**only for mainnet**): `https://zksync2-mainnet-explorer.zksync.io/contract_verification`

5. **`eth network in zksync`**
4. **`eth network in zksync`**

`ZKSYNC_LOCAL_ETH_NETWORK` - rpc or name of ethNetwork for local zksync node.

Expand Down
38 changes: 11 additions & 27 deletions hardhat-setup/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dotenv from 'dotenv';
import { ChainConfig } from '@nomicfoundation/hardhat-verify/src/types';
import { HardhatNetworkAccountsUserConfig, Network, NetworkUserConfig, NetworksUserConfig } from 'hardhat/types';
import { HardhatNetworkAccountsUserConfig, Network, NetworksUserConfig } from 'hardhat/types';

/**
* @category Hardhat-Setup
Expand Down Expand Up @@ -96,7 +96,7 @@ export class Networks {
}
}

register(name: string, chainId: number, rpc?: string, privateKey?: string, etherscanNetworkName?: string, etherscanKey?: string, hardfork: string = 'shanghai') {
register(name: string, chainId: number, rpc?: string, privateKey?: string, etherscanNetworkName?: string, etherscanKey?: string, hardfork: string = 'shanghai', l1Network?: string) {
if (rpc && privateKey && etherscanNetworkName && etherscanKey) {
const { url, authKeyHttpHeader } = parseRpcEnv(rpc);
this.networks[name] = {
Expand All @@ -105,6 +105,7 @@ export class Networks {
chainId,
accounts: [privateKey],
hardfork,
...(l1Network && { ethNetwork: l1Network, zksync: true }),
};
this.etherscan.apiKey[etherscanNetworkName] = etherscanKey;
console.log(`Network '${name}' registered`);
Expand All @@ -120,27 +121,9 @@ export class Networks {
}
}

registerZksync(name: string, chainId: number, rpc?: string, ethNetwork?: string, privateKey?: string, verifyURL?: string, hardfork: string = 'paris') {
if (privateKey && rpc && ethNetwork) {
const { url, authKeyHttpHeader } = parseRpcEnv(rpc);
this.networks[name] = {
url,
httpHeaders: authKeyHttpHeader ? { 'auth-key': authKeyHttpHeader } : undefined,
zksync: true,
chainId,
accounts: [privateKey],
hardfork,
verifyURL,
ethNetwork,
} as NetworkUserConfig;
console.log(`Network '${name}' registered`);
} else {
console.log(`Network '${name}' not registered`);
}
}

registerAll(): { networks: NetworksUserConfig, etherscan: Etherscan } {
const privateKey = process.env.PRIVATE_KEY;
/* eslint-disable max-len */
this.register('mainnet', 1, process.env.MAINNET_RPC_URL, process.env.MAINNET_PRIVATE_KEY || privateKey, 'mainnet', process.env.MAINNET_ETHERSCAN_KEY);
this.register('bsc', 56, process.env.BSC_RPC_URL, process.env.BSC_PRIVATE_KEY || privateKey, 'bsc', process.env.BSC_ETHERSCAN_KEY);
this.register('sepolia', 11155111, process.env.SEPOLIA_RPC_URL, process.env.SEPOLIA_PRIVATE_KEY || privateKey, 'sepolia', process.env.SEPOLIA_ETHERSCAN_KEY);
Expand All @@ -152,13 +135,14 @@ export class Networks {
this.register('fantom', 250, process.env.FANTOM_RPC_URL, process.env.FANTOM_PRIVATE_KEY || privateKey, 'opera', process.env.FANTOM_ETHERSCAN_KEY, 'paris');
this.register('aurora', 1313161554, process.env.AURORA_RPC_URL, process.env.AURORA_PRIVATE_KEY || privateKey, 'aurora', process.env.AURORA_ETHERSCAN_KEY);
this.register('base', 8453, process.env.BASE_RPC_URL, process.env.BASE_PRIVATE_KEY || privateKey, 'base', process.env.BASE_ETHERSCAN_KEY);
this.registerCustom('klaytn', 8217, process.env.KLAYTN_RPC_URL, process.env.KLAYTN_PRIVATE_KEY || privateKey, process.env.KLAYTN_ETHERSCAN_KEY, 'https://scope.klaytn.com/', 'https://scope.klaytn.com/'); // eslint-disable-line max-len
this.registerCustom('linea', 59144, process.env.LINEA_RPC_URL, process.env.LINEA_PRIVATE_KEY || privateKey, process.env.LINEA_ETHERSCAN_KEY, 'https://api.lineascan.build/api', 'https://lineascan.build/', 'london'); // eslint-disable-line max-len
this.registerZksync('zksync', 324, process.env.ZKSYNC_RPC_URL, 'mainnet', process.env.ZKSYNC_PRIVATE_KEY || privateKey, process.env.ZKSYNC_VERIFY_URL);
this.registerCustom('klaytn', 8217, process.env.KLAYTN_RPC_URL, process.env.KLAYTN_PRIVATE_KEY || privateKey, process.env.KLAYTN_ETHERSCAN_KEY, 'https://scope.klaytn.com/', 'https://scope.klaytn.com/');
this.registerCustom('linea', 59144, process.env.LINEA_RPC_URL, process.env.LINEA_PRIVATE_KEY || privateKey, process.env.LINEA_ETHERSCAN_KEY, 'https://api.lineascan.build/api', 'https://lineascan.build/', 'london');
this.register('zksync', 324, process.env.ZKSYNC_RPC_URL, process.env.ZKSYNC_PRIVATE_KEY || privateKey, 'zksyncmainnet', process.env.ZKSYNC_ETHERSCAN_KEY, 'paris', 'mainnet');
this.register('zksyncTest', 300, process.env.ZKSYNC_TEST_RPC_URL, process.env.ZKSYNC_TEST_PRIVATE_KEY || privateKey, 'zksyncsepolia', process.env.ZKSYNC_TEST_ETHERSCAN_KEY, 'paris', 'sepolia');
// For 'zksyncFork' network you should use zksync fork node: https://github.com/matter-labs/era-test-node
this.registerZksync('zksyncFork', 260, process.env.ZKSYNC_FORK_RPC_URL, 'mainnet', process.env.ZKSYNC_FORK_PRIVATE_KEY || privateKey);
this.registerZksync('zksyncLocal', 270, process.env.ZKSYNC_LOCAL_RPC_URL, process.env.ZKSYNC_LOCAL_ETH_NETWORK, process.env.ZKSYNC_PRIVATE_KEY || privateKey);
this.registerZksync('zksyncTest', 300, process.env.ZKSYNC_TEST_RPC_URL, 'sepolia', process.env.ZKSYNC_TEST_PRIVATE_KEY || privateKey, process.env.ZKSYNC_TEST_VERIFY_URL);
this.register('zksyncFork', 260, process.env.ZKSYNC_FORK_RPC_URL, process.env.ZKSYNC_FORK_PRIVATE_KEY || privateKey, 'zksyncfork', 'none', 'paris', process.env.ZKSYNC_LOCAL_ETH_NETWORK || 'mainnet');
this.register('zksyncLocal', 270, process.env.ZKSYNC_LOCAL_RPC_URL, process.env.ZKSYNC_PRIVATE_KEY || privateKey, 'zksynclocal', 'none', 'paris', process.env.ZKSYNC_LOCAL_ETH_NETWORK);
/* eslint-enable max-len */
return { networks: this.networks, etherscan: this.etherscan };
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "6.2.3",
"version": "6.3.0",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
Expand Down
Loading