Skip to content

Commit

Permalink
Rewrite gen-token-add-contract in ts
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Dec 30, 2020
1 parent 176362d commit 9bf564e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 88 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"core/bin/key_generator",
"core/bin/server",
"core/bin/prover",
"core/bin/gen_token_add_contract",
"core/bin/parse_pub_data",

# Server micro-services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.5.0;
contract TokenDeployInit {
function getTokens() internal pure returns (address[] memory) {
address[] memory tokens = new address[]({{ token_len }});
{{~ #each tokens }}
{{#each tokens}}
tokens[{{@index}}] = {{ this.address }};
{{~ /each }}
{{/each}}
return tokens;
}
}
4 changes: 3 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"ethers": "^5.0.19",
"ethjs": "^0.4.0",
"fs": "^0.0.1-security",
"handlebars": "^4.7.6",
"mocha": "^8.2.0",
"openzeppelin-solidity": "^2.3.0",
"path": "^0.12.7",
Expand All @@ -36,6 +37,7 @@
"deploy-erc20": "ts-node scripts/deploy-erc20.ts",
"deploy-testkit": "ts-node scripts/deploy-testkit.ts",
"publish-sources": "ts-node scripts/publish.ts",
"deploy-testnet-erc20": "ts-node scripts/deploy-testnet-token.ts"
"deploy-testnet-erc20": "ts-node scripts/deploy-testnet-token.ts",
"gen-token-add-contract": "ts-node scripts/gen-token-add-contract.ts"
}
}
24 changes: 24 additions & 0 deletions contracts/scripts/gen-token-add-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as fs from 'fs';
import * as path from 'path';
import * as Handlebars from 'handlebars';

const network = process.env.ETH_NETWORK as string;
const ZKSYNC_HOME = process.env.ZKSYNC_HOME as string;
if (!network) {
throw new Error('ETH_NETWORK is not set');
}
if (!ZKSYNC_HOME) {
throw new Error('ZKSYNC_HOME is not set');
}

const pathToTokenList = path.join(ZKSYNC_HOME, `etc/tokens/${network}.json`);
const tokenList = JSON.parse(fs.readFileSync(pathToTokenList, { encoding: 'utf-8' }));
const pathToExample = path.join(ZKSYNC_HOME, `contracts/contract-templates/TokenInitTemplate.template`);
const template = Handlebars.compile(fs.readFileSync(pathToExample, { encoding: 'utf-8' }));
const templateParams = {
token_len: tokenList.length,
tokens: tokenList
};
const contract = template(templateParams);
const outputPath = path.join(ZKSYNC_HOME, `contracts/contracts/TokenInit.sol`);
fs.writeFileSync(outputPath, contract, { encoding: 'utf-8' });
19 changes: 0 additions & 19 deletions core/bin/gen_token_add_contract/Cargo.toml

This file was deleted.

52 changes: 0 additions & 52 deletions core/bin/gen_token_add_contract/src/main.rs

This file was deleted.

2 changes: 0 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ This section provides an overview on folders / sub-projects that exist in this r
- `/prover`: zkSync prover application.
- `/data_restore`: Utility to restore a state of the zkSync network from a smart contract.
- `/key_generator`: Utility to generate verification keys for network.
- `/gen_token_add_contract`: Utility to generate `TokenDeployInit` smart contract, required for initial network
launch.
- `/parse_pub_data`: Utility to parse zkSync operation pubdata.
- `/zksync_core`: zkSync server Core microservice.
- `/zksync_api`: zkSync server API microservice.
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function prepareVerify() {
export async function build() {
await utils.confirmAction();
prepareVerify();
await utils.spawn('cargo run --release --bin gen_token_add_contract');
await utils.spawn('yarn contracts gen-token-add-contract');
await utils.spawn('yarn contracts build');
}

Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6933,6 +6933,18 @@ handle-thing@^2.0.0:
resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg==

handlebars@^4.7.6:
version "4.7.6"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e"
integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==
dependencies:
minimist "^1.2.5"
neo-async "^2.6.0"
source-map "^0.6.1"
wordwrap "^1.0.0"
optionalDependencies:
uglify-js "^3.1.4"

har-schema@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
Expand Down Expand Up @@ -12636,6 +12648,11 @@ [email protected]:
commander "~2.19.0"
source-map "~0.6.1"

uglify-js@^3.1.4:
version "3.12.3"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.3.tgz#bb26c4abe0e68c55e9776bca9bed99a4df73facf"
integrity sha512-feZzR+kIcSVuLi3s/0x0b2Tx4Iokwqt+8PJM7yRHKuldg4MLdam4TCFeICv+lgDtuYiCtdmrtIP+uN9LWvDasw==

ultron@~1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c"
Expand Down Expand Up @@ -13541,6 +13558,11 @@ word-wrap@~1.2.3:
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==

wordwrap@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=

worker-farm@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.7.0.tgz#26a94c5391bbca926152002f69b84a4bf772e5a8"
Expand Down Expand Up @@ -13811,7 +13833,7 @@ zksync-crypto@^0.4.2:
integrity sha512-PQw0e7t80uP7c5LHonEh4dS4wGpK2TC4uYR/16jcDCaCS2wY/exF37hAOeQiskb0hnU2C6/jqtvBMbsMTzVh7Q==

"zksync@link:sdk/zksync.js":
version "0.8.3"
version "0.8.4"
dependencies:
axios "^0.21.0"
websocket "^1.0.30"
Expand Down

0 comments on commit 9bf564e

Please sign in to comment.