From 2212e8917e39a96a71bd1385a772a95062164af1 Mon Sep 17 00:00:00 2001 From: juan518munoz <62400508+juan518munoz@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:00:48 -0300 Subject: [PATCH] feat: set native token env var (#64) * set native token env * rmv try-catch --- core/tests/ts-integration/src/env.ts | 2 +- infrastructure/zk/src/hyperchain_wizard.ts | 9 +++++++++ infrastructure/zk/src/run/run.ts | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/tests/ts-integration/src/env.ts b/core/tests/ts-integration/src/env.ts index 68209ada4297..8857f40d4bb7 100644 --- a/core/tests/ts-integration/src/env.ts +++ b/core/tests/ts-integration/src/env.ts @@ -48,7 +48,7 @@ export async function waitForServer() { */ export async function loadTestEnvironment(): Promise { const network = process.env.CHAIN_ETH_NETWORK || 'localhost'; - const nativeErc20Testing = process.env.NATIVE_ERC20_ADDRESS ? true : false; // if set, we assume user wants to test native erc20 tokens + const nativeErc20Testing = process.env.CONTRACTS_L1_NATIVE_ERC20_TOKEN_ADDR ? true : false; // if set, we assume user wants to test native erc20 tokens let mainWalletPK; if (nativeErc20Testing) { diff --git a/infrastructure/zk/src/hyperchain_wizard.ts b/infrastructure/zk/src/hyperchain_wizard.ts index 9d140aa33e86..7e5baab6ca46 100644 --- a/infrastructure/zk/src/hyperchain_wizard.ts +++ b/infrastructure/zk/src/hyperchain_wizard.ts @@ -630,6 +630,15 @@ export function getTokens(network: string): L1Token[] { } } +export function getNativeToken(): L1Token { + const configPath = `${process.env.ZKSYNC_HOME}/etc/tokens/native_erc20.json`; + return JSON.parse( + fs.readFileSync(configPath, { + encoding: 'utf-8' + }) + ); +} + async function selectHyperchainConfiguration() { const envs = env.getAvailableEnvsFromFiles(); diff --git a/infrastructure/zk/src/run/run.ts b/infrastructure/zk/src/run/run.ts index 5db31fb281b7..b3c714fa3a22 100644 --- a/infrastructure/zk/src/run/run.ts +++ b/infrastructure/zk/src/run/run.ts @@ -4,7 +4,7 @@ import { Wallet } from 'ethers'; import fs from 'fs'; import * as path from 'path'; import * as dataRestore from './data-restore'; -import { getTokens } from '../hyperchain_wizard'; +import { getNativeToken, getTokens } from '../hyperchain_wizard'; import * as env from '../env'; import { IERC20Factory } from 'zksync-web3/build/typechain'; import { Provider } from 'zksync-web3'; @@ -50,9 +50,17 @@ export async function deployERC20( env.modify('CONTRACTS_L1_WETH_TOKEN_ADDR', `CONTRACTS_L1_WETH_TOKEN_ADDR=${WETH.address}`); } else if (command == 'new') { let destinationFile = 'native_erc20'; - await utils.spawn( - `yarn --silent --cwd contracts/ethereum deploy-erc20 add --token-name ${name} --symbol ${symbol} --decimals ${decimals} > ./etc/tokens/${destinationFile}.json` - ); + await utils + .spawn( + `yarn --silent --cwd contracts/ethereum deploy-erc20 add --token-name ${name} --symbol ${symbol} --decimals ${decimals} > ./etc/tokens/${destinationFile}.json` + ) + .then(() => { + const NATIVE_ERC20 = getNativeToken(); + env.modify( + 'CONTRACTS_L1_NATIVE_ERC20_TOKEN_ADDR', + `CONTRACTS_L1_NATIVE_ERC20_TOKEN_ADDR=${NATIVE_ERC20.address}` + ); + }); } }