diff --git a/etc/EXAMPLE.json b/etc/EXAMPLE.json index 088df91..a812d8e 100644 --- a/etc/EXAMPLE.json +++ b/etc/EXAMPLE.json @@ -1,7 +1,8 @@ { "network": { "name": "devnet", - "url": "http://127.0.0.1", + "declareUrl": "http://127.0.0.1", + "deployUrl": "http://127.0.0.1", "accounts": { "deployer": { "address": "", diff --git a/package-lock.json b/package-lock.json index 7e1d342..8a2f469 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "commander": "^11.0.0", - "starknet": "^5.19.5" + "starknet": "5.24.3" } }, "node_modules/@noble/curves": { @@ -59,9 +59,9 @@ } }, "node_modules/commander": { - "version": "11.0.0", - "resolved": "https://registry.npmmirror.com/commander/-/commander-11.0.0.tgz", - "integrity": "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", "engines": { "node": ">=16" } @@ -76,14 +76,14 @@ } }, "node_modules/lossless-json": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-2.0.9.tgz", - "integrity": "sha512-PUfJ5foxULG1x/dXpSckmt0woBDqyq/WFoI885vEqjGwuP41K2EBYh2IT3zYx9dWqcTLIfXiCE5AjhF1jk9Sbg==" + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-2.0.11.tgz", + "integrity": "sha512-BP0vn+NGYvzDielvBZaFain/wgeJ1hTvURCqtKvhr1SCPePdaaTanmmcplrHfEJSJOUql7hk4FHwToNJjWRY3g==" }, "node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -134,9 +134,9 @@ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/whatwg-fetch": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", - "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" + "version": "3.6.19", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.19.tgz", + "integrity": "sha512-d67JP4dHSbm2TrpFj8AbO8DnL1JXL5J9u0Kq2xW6d0TFDbCA3Muhdt8orXC22utleTVj7Prqt82baN6RBvnEgw==" }, "node_modules/whatwg-url": { "version": "5.0.0", diff --git a/package.json b/package.json index 219d186..7208484 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "type": "module", "dependencies": { "commander": "^11.0.0", - "starknet": "^5.24.3" + "starknet": "5.24.3" }, "scripts": { "build": "node scripts/build.js build", diff --git a/scripts/constants.js b/scripts/constants.js index 3aaf448..0e81f4b 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -49,6 +49,15 @@ const NOTICE_PERIOD = "NoticePeriod"; // command const COMMAND_BUILD = "scarb --release build"; +// connetion type +const DECLARE = "declare"; +const DEPLOY = "deploy"; + +export var connectionType = { + DECLARE, + DEPLOY +} + export var UpgradeStatus = { IDLE, NOTICE_PERIOD diff --git a/scripts/deploy_faucet.js b/scripts/deploy_faucet.js index baa4352..8ab3066 100644 --- a/scripts/deploy_faucet.js +++ b/scripts/deploy_faucet.js @@ -1,7 +1,7 @@ import { program } from "commander"; import fs from "fs"; import { connectStarknet, buildFaucetTokenConstructorArgs, getClassHashFromError, getContractClass, getDeployLog } from "./utils.js"; -import { logName, contractPath } from "./constants.js" +import { logName, contractPath, connectionType } from "./constants.js" program .command("deployFaucetToken") @@ -25,7 +25,7 @@ async function deploy_faucet_token(options) { console.log("symbol:", symbol); console.log("decimals:", decimals); - let { provider, deployer, governor, netConfig} = await connectStarknet(); + let { provider, deployer, governor, netConfig} = await connectStarknet(connectionType.DECLARE); // declare faucet token const {sierraContract, casmContract} = getContractClass(contractPath.FAUCET_TOKEN); @@ -38,7 +38,7 @@ async function deploy_faucet_token(options) { classHash = declareResponse.class_hash; console.log('✅ Faucet Token Contract declared with classHash = ', classHash); } catch (error) { - if (!error.message.includes('is already declared.')) { + if (!error.message.includes('StarkFelt(\\')) { throw error; } @@ -50,11 +50,14 @@ async function deploy_faucet_token(options) { console.log('✅ Faucet Token Contract already declared with classHash =', classHash); } } + } else { + console.log('✅ Faucet Token Contract already declared with classHash =', classHash); } deployLog[logName.DEPLOY_LOG_FAUCET_TOKEN_CLASS_HASH] = classHash; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); // deploy faucet token + ({ provider, deployer, governor, netConfig } = await connectStarknet(connectionType.DEPLOY)); const constructorArgs = buildFaucetTokenConstructorArgs(sierraContract.abi, name, symbol, decimals); const deployResponse = await deployer.deployContract({ classHash: classHash, constructorCalldata: constructorArgs }); await provider.waitForTransaction(deployResponse.transaction_hash); diff --git a/scripts/deploy_multicall.js b/scripts/deploy_multicall.js index 7e026a8..ab4ede4 100644 --- a/scripts/deploy_multicall.js +++ b/scripts/deploy_multicall.js @@ -1,6 +1,6 @@ import { program } from "commander"; import fs from "fs"; -import { logName, contractPath } from "./constants.js"; +import { logName, contractPath, connectionType } from "./constants.js"; import { connectStarknet, buildMulticallConstructorArgs, getClassHashFromError, getContractClass, getDeployLog } from "./utils.js"; program @@ -16,20 +16,20 @@ program.parse(); async function deploy_multicall(options) { const { deployLogPath, deployLog } = getDeployLog(logName.DEPLOY_MULTICALL_LOG_PREFIX); - let { provider, deployer, governor, netConfig } = await connectStarknet(); + let { provider, deployer, governor, netConfig } = await connectStarknet(connectionType.DECLARE); // declare multicall contract const {sierraContract, casmContract} = getContractClass(contractPath.MULTICALL); let classHash = deployLog[logName.DEPLOY_LOG_MULTICALL_CLASS_HASH]; - if (!(logName.DEPLOY_LOG_FAUCET_TOKEN_CLASS_HASH in deployLog)) { + if (!(logName.DEPLOY_LOG_MULTICALL_CLASS_HASH in deployLog)) { try { const declareResponse = await deployer.declare({ contract: sierraContract, casm: casmContract }); await provider.waitForTransaction(declareResponse.transaction_hash); classHash = declareResponse.class_hash; console.log('✅ Multicall Contract declared with classHash = ', classHash); } catch (error) { - if (!error.message.includes('is already declared.')) { + if (!error.message.includes('StarkFelt(\\')) { throw error; } @@ -41,22 +41,19 @@ async function deploy_multicall(options) { console.log('✅ Multicall Contract already declared with classHash =', classHash); } } + } else { + console.log('✅ Multicall Contract already declared with classHash =', classHash); } deployLog[logName.DEPLOY_LOG_MULTICALL_CLASS_HASH] = classHash; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); // deploy multicall + ({ provider, deployer, governor, netConfig } = await connectStarknet(connectionType.DEPLOY)); const constructorArgs = buildMulticallConstructorArgs(sierraContract.abi); const deployResponse = await deployer.deployContract({ classHash: classHash, constructorCalldata: constructorArgs }); - let tx = await provider.waitForTransaction(deployResponse.transaction_hash); - while (tx.block_number === undefined) { - await new Promise(resolve => setTimeout(resolve, 60000)); - tx = await provider.waitForTransaction(deployResponse.transaction_hash); - } - console.log('tx block number', tx.block_number); + await provider.waitForTransaction(deployResponse.transaction_hash); console.log('✅ Multicall Contract deployed at =', deployResponse.contract_address); deployLog[logName.DEPLOY_LOG_MULTICALL] = deployResponse.contract_address; deployLog[logName.DEPLOY_LOG_MULTICALL_TX_HASH] = deployResponse.transaction_hash; - deployLog[logName.DEPLOY_LOG_MULTICALL_BLOCK_NUMBER] = tx.block_number; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } \ No newline at end of file diff --git a/scripts/deploy_zklink.js b/scripts/deploy_zklink.js index 5229ead..03cb49a 100644 --- a/scripts/deploy_zklink.js +++ b/scripts/deploy_zklink.js @@ -1,7 +1,7 @@ import { Contract } from "starknet"; import fs from "fs"; import { program } from "commander"; -import { logName, contractPath } from "./constants.js" +import { logName, contractPath, connectionType } from "./constants.js" import { connectStarknet, getDeployLog, buildVerifierConstructorArgs, buildZklinkConstructorArgs, buildGateKeeperConstructorArgs, declare_zklink, getContractClass } from "./utils.js"; @@ -21,7 +21,7 @@ program async function deploy_zklink(options) { const log = getDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); const { deployLogPath, deployLog } = log; - let { provider, deployer, governor, netConfig } = await connectStarknet(); + let { provider, deployer, governor, netConfig } = await connectStarknet(connectionType.DECLARE); // declare contracts const declare_options = { @@ -49,6 +49,8 @@ async function deploy_zklink(options) { deployLog[logName.DEPLOY_LOG_VALIDATOR] = options.validator; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + ({ provider, deployer, governor, netConfig } = await connectStarknet(connectionType.DEPLOY)); + const {sierraContract: gatekeeperContractSierra, casmContract: gatekeeperContractCasm} = getContractClass(contractPath.GATEKEEPER); const {sierraContract: verifierContractSierra, casmContract: verifierContractCasm} = getContractClass(contractPath.VERIFIER); const {sierraContract: zklinkContractSierra, casmContract: zklinkContractCasm} = getContractClass(contractPath.ZKLINK); diff --git a/scripts/interact.js b/scripts/interact.js index a17b008..c0c54af 100644 --- a/scripts/interact.js +++ b/scripts/interact.js @@ -1,7 +1,7 @@ import { program } from "commander"; import fs from "fs"; import { Contract, json } from "starknet"; -import { contractPath, logName } from "./constants.js"; +import { contractPath, logName, connectionType } from "./constants.js"; import { connectStarknet, getDeployLog, getContractClass } from "./utils.js"; program @@ -26,7 +26,7 @@ program program.parse(); async function add_token(options) { - let { provider, deployer, governor, netConfig} = await connectStarknet(); + let { provider, deployer, governor, netConfig} = await connectStarknet(connectionType.DEPLOY); const { deployLogPath, deployLog } = getDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); const zklinkAddress = options.zklink === undefined ? deployLog[logName.DEPLOY_LOG_ZKLINK] : options.zklink; @@ -52,7 +52,7 @@ async function add_token(options) { } async function add_bridge(options) { - let { provider, deployer, governor, netConfig} = await connectStarknet(); + let { provider, deployer, governor, netConfig} = await connectStarknet(connectionType.DEPLOY); const { deployLogPath, deployLog } = getDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); const bridgeAddress = options.bridge; diff --git a/scripts/upgrade_zklink.js b/scripts/upgrade_zklink.js index b3a7d54..9dcf17a 100644 --- a/scripts/upgrade_zklink.js +++ b/scripts/upgrade_zklink.js @@ -1,7 +1,7 @@ import { Contract, json} from "starknet"; import fs from "fs"; import { program } from "commander"; -import { logName, contractPath, UpgradeStatus } from "./constants.js" +import { logName, contractPath, UpgradeStatus, connectionType } from "./constants.js" import { connectStarknet, getDeployLog, declare_zklink, getContractClass } from "./utils.js" program @@ -19,7 +19,7 @@ program.parse(); async function upgrade_zklink(options) { const log = getDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); const { deployLog, deployLogPath } = log; - let { provider, deployer, governor, netConfig} = await connectStarknet(); + let { provider, deployer, governor, netConfig} = await connectStarknet(connectionType.DECLARE); const upgradeVerifier = options.upgradeVerifier; const upgradeZklink = options.upgradeZklink; diff --git a/scripts/utils.js b/scripts/utils.js index 0ad6972..d756917 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,23 +1,31 @@ import fs from "fs"; import { RpcProvider, CallData, Account, json } from "starknet"; import { exec } from "child_process"; -import { logName, contractPath } from "./constants.js"; +import { logName, contractPath, connectionType } from "./constants.js"; -function buildProvider(networkConfig) { - let provider = new RpcProvider({ nodeUrl: networkConfig.url }); - console.log(`✅ Connected to ${networkConfig.name}`); +function buildProvider(networkConfig, type) { + let url = undefined; + if (type === connectionType.DEPLOY) { + url = networkConfig.deployUrl; + console.log('Connecting Starknet for deployment...'); + } else if (type === connectionType.DECLARE) { + url = networkConfig.declareUrl; + console.log('Connecting Starknet for declaration...'); + } + let provider = new RpcProvider({ nodeUrl: url }); + console.log(`✅ Connected to ${url}`); return provider; } -export async function connectStarknet() { +export async function connectStarknet(type) { // read config json file const netName = process.env.NET === undefined ? "EXAMPLE" : process.env.NET; let netConfig = await fs.promises.readFile(`./etc/${netName}.json`, "utf-8"); netConfig = JSON.parse(netConfig); // create provider - const provider = buildProvider(netConfig.network); + const provider = buildProvider(netConfig.network, type); const deployerConfig = netConfig.network.accounts.deployer; const governorConfig = netConfig.network.accounts.governor; @@ -93,7 +101,7 @@ export async function declare_zklink(provider, deployer, log, options) { gatekeeperContractClassHash = gatekeeperDeclareResponse.class_hash; console.log('✅ Gatekeeper Contract declared with classHash = ', gatekeeperContractClassHash); } catch (error) { - if (!error.message.includes('is already declared.')) { + if (!error.message.includes('StarkFelt(\\')) { throw error; } gatekeeperContractClassHash = getClassHashFromError(error); @@ -124,7 +132,7 @@ export async function declare_zklink(provider, deployer, log, options) { verifierContractClassHash = verifierDeclareResponse.class_hash; console.log('✅ Verifier Contract declared with classHash = ', verifierContractClassHash); } catch (error) { - if (!error.message.includes('is already declared.')) { + if (!error.message.includes('StarkFelt(\\')) { throw error; } @@ -154,7 +162,7 @@ export async function declare_zklink(provider, deployer, log, options) { zklinkContractClassHash = zklinkDeclareResponse.class_hash; console.log('✅ Zklink Contract declared with classHash = ', zklinkContractClassHash); } catch (error) { - if (!error.message.includes('is already declared.')) { + if (!error.message.includes('StarkFelt(\\')) { throw error; }