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

feat: set native token env var #64

Merged
merged 2 commits into from
Jan 25, 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
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) {
Comment on lines +51 to 54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know is not exactly part of this PR but you could do if (process.env.CONTRACTS_L1_NATIVE_ERC20_TOKEN_ADDR) and it should work fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would, but I though that it would be better to declare a shorter variable once, and then use it three times, than calling calling process.env.CONTRACTS_L1_NATIVE_ERC20_TOKEN_ADDR each time.

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
Loading