From cdcab0de8fe1589383e5a74076b34c06b6782345 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Thu, 7 Nov 2024 00:19:35 +0530 Subject: [PATCH] WIP --- .../src/config/deploy.ts | 51 +++++++++++++++++ .../secret-contracts-scripts/src/index.ts | 56 ++++++------------ .../src/instantiate.ts | 57 +++++++------------ 3 files changed, 89 insertions(+), 75 deletions(-) create mode 100644 packages/secret-contracts-scripts/src/config/deploy.ts diff --git a/packages/secret-contracts-scripts/src/config/deploy.ts b/packages/secret-contracts-scripts/src/config/deploy.ts new file mode 100644 index 0000000..7777121 --- /dev/null +++ b/packages/secret-contracts-scripts/src/config/deploy.ts @@ -0,0 +1,51 @@ +import dotenv from "dotenv"; +dotenv.config(); + +// https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-testnet-pulsar-3-contracts +// https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-mainnet-secret-4-contracts + +const config = { + network: "testnet", + // codeId 1533 + mainnet: { + walletMnemonic: process.env.WALLET_MNEMONIC_MAINNET, + isOptimizedContractWasm: true, + wasmContractPath: "secret_evm_storage.wasm.gz", + // TODO: is it correct that the Gateway public key is the same for both Mainnet and Testnet as shown in the docs here, even though they have a different Gateway address? https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway + gatewayAddress: "secret1qzk574v8lckjmqdg3r3qf3337pk45m7qd8x02a", + gatewayHash: "012dd8efab9526dec294b6898c812ef6f6ad853e32172788f54ef3c305c1ecc5", + gatewayPublicKey: "0x04a0d632acd0d2f5da02fc385ea30a8deab4d5639d1a821a3a552625ad0f1759d0d2e80ca3adb236d90caf1b12e0ddf3a351c5729b5e00505472dca6fed5c31e2a", + nunyaBusinessContractAddress: "", + codeId: "1533", // only know after upload + contractCodeHash: "", // only know after upload + }, + // codeId 3375 + testnet: { + walletMnemonic: process.env.WALLET_MNEMONIC_TESTNET, + isOptimizedContractWasm: true, + wasmContractPath: "secret_evm_storage.wasm.gz", + gatewayAddress: "secret10ex7r7c4y704xyu086lf74ymhrqhypayfk7fkj", + gatewayHash: "ad8ca07ffba1cb26ebf952c29bc4eced8319c171430993e5b5089887f27b3f70", + gatewayPublicKey: "0x046d0aac3ef10e69055e934ca899f508ba516832dc74aa4ed4d741052ed5a568774d99d3bfed641a7935ae73aac8e34938db747c2f0e8b2aa95c25d069a575cc8b", + nunyaBusinessContractAddress: "", + chainId: "pulsar-3", + endpoint: process.env.ENDPOINT_TESTNET, + codeId: "3375", // only know after upload + contractCodeHash: "", // only know after upload + }, + local: { + walletMnemonic: process.env.WALLET_MNEMONIC_LOCAL, + isOptimizedContractWasm: false, + wasmContractPath: "secret_evm_storage.wasm.gz", + gatewayAddress: "", + gatewayHash: "", + gatewayPublicKey: "", + nunyaBusinessContractAddress: "", + chainId: "secretdev-1", + endpoint: process.env.ENDPOINT_LOCAL, + codeId: "0", // only know after upload + contractCodeHash: "", // only know after upload + } +}; + +export default config; diff --git a/packages/secret-contracts-scripts/src/index.ts b/packages/secret-contracts-scripts/src/index.ts index 7b65f6e..0d798f6 100644 --- a/packages/secret-contracts-scripts/src/index.ts +++ b/packages/secret-contracts-scripts/src/index.ts @@ -1,48 +1,31 @@ -import dotenv from "dotenv"; -dotenv.config(); import { BroadcastMode, SecretNetworkClient, Wallet } from "secretjs"; import * as fs from "fs"; import path from 'path'; +import config from './config/deploy'; const walletOptions = { hdAccountIndex: 0, coinType: 529, bech32Prefix: 'secret', } -console.log('process.env.WALLET_MNEMONIC_TESTNET loaded?', process.env.WALLET_MNEMONIC_TESTNET !== "") -// const wallet = new Wallet(process.env.WALLET_MNEMONIC_LOCAL, walletOptions); -const wallet = new Wallet(process.env.WALLET_MNEMONIC_TESTNET, walletOptions); + +const { walletMnemonic, isOptimizedContractWasm, wasmContractPath, gatewayAddress, gatewayHash, gatewayPublicKey, nunyaBusinessContractAddress, chainId, endpoint } = + config.network == "testnet" + ? config.testnet + : config.local; + +if (walletMnemonic == "") { + throw Error("Unable to obtain mnemonic phrase"); +} + +const wallet = new Wallet(walletMnemonic, walletOptions); console.log('wallet address: ', wallet.address); const rootPath = path.resolve(__dirname, '../../../'); // relative to ./dist console.log('rootPath', rootPath) -// const contract_wasm: any = fs.readFileSync(`${rootPath}/packages/secret-contracts/nunya-contract/contract.wasm.gz`); -// // Optimised my-counter-contract -// const contract_wasm: any = fs.readFileSync(`${rootPath}/packages/secret-contracts/my-counter-contract/optimized-wasm/secret_contract_example.wasm.gz`); +// const contract_wasm: any = fs.readFileSync(`${rootPath}/packages/secret-contracts/nunya-contract/${wasmContractPath}`); // Optimised nunya-contract -const contract_wasm: any = fs.readFileSync(`${rootPath}/packages/secret-contracts/nunya-contract/optimized-wasm/secret_evm_storage.wasm.gz`); - -// Secret Testnet -// reference: https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-testnet-pulsar-3-contracts - -// Code ID 3375 -const gatewayAddress = "secret10ex7r7c4y704xyu086lf74ymhrqhypayfk7fkj"; -const gatewayHash = - "ad8ca07ffba1cb26ebf952c29bc4eced8319c171430993e5b5089887f27b3f70"; -const gatewayPublicKey = - "0x046d0aac3ef10e69055e934ca899f508ba516832dc74aa4ed4d741052ed5a568774d99d3bfed641a7935ae73aac8e34938db747c2f0e8b2aa95c25d069a575cc8b"; -const nunyaBusinessContractAddress = ""; - -// Secret Mainnet -// reference: https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-mainnet-secret-4-contracts - -// Code ID 1533 -// const gatewayAddress = "secret1qzk574v8lckjmqdg3r3qf3337pk45m7qd8x02a"; -// const gatewayHash = -// "012dd8efab9526dec294b6898c812ef6f6ad853e32172788f54ef3c305c1ecc5"; -// // TODO: is it correct that the Gateway public key is the same for both Mainnet and Testnet as shown in the docs here, even though they have a different Gateway address? https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway -// const gatewayPublicKey = -// "0x04a0d632acd0d2f5da02fc385ea30a8deab4d5639d1a821a3a552625ad0f1759d0d2e80ca3adb236d90caf1b12e0ddf3a351c5729b5e00505472dca6fed5c31e2a"; +const contract_wasm: any = fs.readFileSync(`${rootPath}/packages/secret-contracts/nunya-contract/${isOptimizedContractWasm ? "optimized-wasm/" : "/"}${wasmContractPath}`); const gatewayPublicKeyBytes = Buffer.from( gatewayPublicKey.substring(2), @@ -51,10 +34,8 @@ const gatewayPublicKeyBytes = Buffer.from( async function main () { const secretjs = new SecretNetworkClient({ - // chainId: "secretdev-1", - // url: process.env.ENDPOINT_LOCAL || "", - chainId: "pulsar-3", - url: process.env.ENDPOINT_TESTNET || "", + chainId: chainId, + url: endpoint || "", wallet: wallet, walletAddress: wallet.address, }); @@ -73,11 +54,6 @@ async function main () { contractCodeHash: String, }; - type CONTRACT_PARAMS = { - contractAddress: String, - contractCodeHash: String, - }; - let upload_contract = async () => { console.log("Starting deployment..."); diff --git a/packages/secret-contracts-scripts/src/instantiate.ts b/packages/secret-contracts-scripts/src/instantiate.ts index 5d1e130..21352c2 100644 --- a/packages/secret-contracts-scripts/src/instantiate.ts +++ b/packages/secret-contracts-scripts/src/instantiate.ts @@ -1,46 +1,30 @@ -import dotenv from "dotenv"; -dotenv.config(); import { BroadcastMode, SecretNetworkClient, Wallet } from "secretjs"; -import * as fs from "fs"; import path from 'path'; +import config from './config/deploy'; const walletOptions = { hdAccountIndex: 0, coinType: 529, bech32Prefix: 'secret', } -console.log('process.env.WALLET_MNEMONIC_TESTNET loaded?', process.env.WALLET_MNEMONIC_TESTNET !== "") -// const wallet = new Wallet(process.env.WALLET_MNEMONIC_LOCAL, walletOptions); -const wallet = new Wallet(process.env.WALLET_MNEMONIC_TESTNET, walletOptions); -console.log('wallet address: ', wallet.address); - -const rootPath = path.resolve(__dirname, '../../../'); // relative to ./dist -console.log('rootPath', rootPath) -let CODE_ID: String = ""; -let CONTRACT_CODE_HASH: String = ""; +const { walletMnemonic, codeId, contractCodeHash, gatewayAddress, gatewayHash, gatewayPublicKey, nunyaBusinessContractAddress, chainId, endpoint } = + config.network == "testnet" + ? config.testnet + : config.local; -// Secret Testnet -// reference: https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-testnet-pulsar-3-contracts +if (walletMnemonic == "") { + throw Error("Unable to obtain mnemonic phrase"); +} -// Code ID 3375 -const gatewayAddress = "secret10ex7r7c4y704xyu086lf74ymhrqhypayfk7fkj"; -const gatewayHash = - "ad8ca07ffba1cb26ebf952c29bc4eced8319c171430993e5b5089887f27b3f70"; -const gatewayPublicKey = - "0x046d0aac3ef10e69055e934ca899f508ba516832dc74aa4ed4d741052ed5a568774d99d3bfed641a7935ae73aac8e34938db747c2f0e8b2aa95c25d069a575cc8b"; -const nunyaBusinessContractAddress = ""; +const wallet = new Wallet(walletMnemonic, walletOptions); +console.log('wallet address: ', wallet.address); -// Secret Mainnet -// reference: https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-mainnet-secret-4-contracts +const rootPath = path.resolve(__dirname, '../../../'); // relative to ./dist +console.log('rootPath', rootPath) -// Code ID 1533 -// const gatewayAddress = "secret1qzk574v8lckjmqdg3r3qf3337pk45m7qd8x02a"; -// const gatewayHash = -// "012dd8efab9526dec294b6898c812ef6f6ad853e32172788f54ef3c305c1ecc5"; -// // TODO: is it correct that the Gateway public key is the same for both Mainnet and Testnet as shown in the docs here, even though they have a different Gateway address? https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway -// const gatewayPublicKey = -// "0x04a0d632acd0d2f5da02fc385ea30a8deab4d5639d1a821a3a552625ad0f1759d0d2e80ca3adb236d90caf1b12e0ddf3a351c5729b5e00505472dca6fed5c31e2a"; +let CODE_ID: String = codeId; +let CONTRACT_CODE_HASH: String = contractCodeHash; const gatewayPublicKeyBytes = Buffer.from( gatewayPublicKey.substring(2), @@ -49,10 +33,8 @@ const gatewayPublicKeyBytes = Buffer.from( async function main () { const secretjs = new SecretNetworkClient({ - // chainId: "secretdev-1", - // url: process.env.ENDPOINT_LOCAL || "", - chainId: "pulsar-3", - url: process.env.ENDPOINT_TESTNET || "", + chainId: chainId, + url: endpoint || "", wallet: wallet, walletAddress: wallet.address, }); @@ -78,6 +60,11 @@ async function main () { codeId: String, contractCodeHash: String, }; + + type CONTRACT_PARAMS = { + contractAddress: String, + contractCodeHash: String, + }; let instantiate_contract = async (params: CODE_PARAMS) => { console.log("Instantiating contract..."); @@ -131,7 +118,7 @@ async function main () { throw Error("Unable to find the contract_address"); } - let contractParams = { + let contractParams: CONTRACT_PARAMS = { contractAddress, contractCodeHash: params.contractCodeHash, };