Skip to content

Commit

Permalink
feat: set native token env var (#64)
Browse files Browse the repository at this point in the history
* set native token env

* rmv try-catch
  • Loading branch information
juan518munoz authored Jan 25, 2024
1 parent 2691733 commit 2212e89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function waitForServer() {
*/
export async function loadTestEnvironment(): Promise<TestEnvironment> {
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) {
Expand Down
9 changes: 9 additions & 0 deletions infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 12 additions & 4 deletions infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`
);
});
}
}

Expand Down

0 comments on commit 2212e89

Please sign in to comment.