From 4210968360487b7c885afbdd0f08328adc91349e Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Mon, 30 Dec 2024 19:05:00 +1100 Subject: [PATCH] fix --- .../src/config/config.ts | 4 +- .../src/evm/setEVMGatewayAddress.ts | 17 +++++- .../src/functions/evm/requestNunya.ts | 58 +++++++++++-------- .../src/uploadAndInstantiateNunya.ts | 10 +--- scripts/run.sh | 2 +- 5 files changed, 55 insertions(+), 36 deletions(-) diff --git a/packages/secret-contracts-scripts/src/config/config.ts b/packages/secret-contracts-scripts/src/config/config.ts index 8bcd68b..4116c11 100644 --- a/packages/secret-contracts-scripts/src/config/config.ts +++ b/packages/secret-contracts-scripts/src/config/config.ts @@ -18,7 +18,7 @@ let initialNetworkSettings = { evm: { network: "localhost", localhost: { - chainId: 31337, + chainId: "31337", endpoint: "http://127.0.0.1:8545/", // Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH) privateKey: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", @@ -28,7 +28,7 @@ let initialNetworkSettings = { gatewayContractAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", // only know after deploy }, sepolia: { - chainId: 11155111, + chainId: "11155111", endpoint: process.env.PROVIDER_RPC_ETHEREUM_SEPOLIA, privateKey: process.env.DEPLOYER_PRIVATE_KEY, nunyaBusinessContractAddress: "0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D", // only know after deploy diff --git a/packages/secret-contracts-scripts/src/evm/setEVMGatewayAddress.ts b/packages/secret-contracts-scripts/src/evm/setEVMGatewayAddress.ts index e3e1b24..c1bd9b5 100644 --- a/packages/secret-contracts-scripts/src/evm/setEVMGatewayAddress.ts +++ b/packages/secret-contracts-scripts/src/evm/setEVMGatewayAddress.ts @@ -5,6 +5,7 @@ import { ethers, Contract, Wallet, utils } from "ethers"; import gatewayAbi from "../../../hardhat/artifacts/contracts/Gateway.sol/Gateway.json" assert { type: "json" }; import nunyaAbi from "../../../hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json" assert { type: "json" }; import config from '../config/config.js'; +import { loadDeployed } from "../loadDeployed.js"; let varsEvm; if (config.networkSettings.evm.network == "sepolia") { @@ -14,10 +15,22 @@ if (config.networkSettings.evm.network == "sepolia") { } else { throw new Error(`Unsupported network.`) } -const { chainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = varsEvm; +const { endpoint: evmEndpoint, privateKey } = varsEvm; // Sets the deployed Gateway address storage value for the NunyaBusiness contract async function setGatewayAddress() { + + let deployed = await loadDeployed(); + let varsDeployedEvm; + if (deployed.data.evm.network == "sepolia") { + varsDeployedEvm = deployed.data.evm.sepolia; + } else if (deployed.data.evm.network == "localhost") { + varsDeployedEvm = deployed.data.evm.localhost; + } else { + throw new Error(`Unsupported network.`) + } + const { nunyaBusinessContractAddress, gatewayContractAddress } = varsDeployedEvm; + if (nunyaBusinessContractAddress == "") { console.error("Please deploy Nunya.business contract first"); } @@ -28,7 +41,7 @@ async function setGatewayAddress() { } let provider; - provider = new ethers.providers.JsonRpcProvider(endpoint); + provider = new ethers.providers.JsonRpcProvider(evmEndpoint); // console.log(provider); await provider.detectNetwork(); const signer = new Wallet(privateKey, provider); diff --git a/packages/secret-contracts-scripts/src/functions/evm/requestNunya.ts b/packages/secret-contracts-scripts/src/functions/evm/requestNunya.ts index f503ad2..708bd02 100644 --- a/packages/secret-contracts-scripts/src/functions/evm/requestNunya.ts +++ b/packages/secret-contracts-scripts/src/functions/evm/requestNunya.ts @@ -5,6 +5,7 @@ dotenv.config(); import { ethers, Wallet } from "ethers"; import { NonceManager } from "@ethersproject/experimental"; import config from './../../config/config.js'; +import { loadDeployed } from "../../loadDeployed.js"; import gatewayAbi from "../../../../hardhat/artifacts/contracts/Gateway.sol/Gateway.json" assert { type: "json" }; import nunyaAbi from "../../../../hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json" assert { type: "json" }; import { generateKeys } from "../../functions/secretpath/generateKeys.js"; @@ -15,16 +16,6 @@ import { hexlify } from "ethers/lib/utils.js"; import { assert } from "console"; import { RequestParams } from "../../types/index.js"; -let varsSecret; -if (config.networkSettings.secret.network == "testnet") { - varsSecret = config.networkSettings.secret.testnet; -} else if (config.networkSettings.secret.network == "localhost") { - varsSecret = config.networkSettings.secret.localhost; -} else { - throw new Error(`Unsupported Secret network.`) -} -const { chainId: secretChainId, secretNunya: { nunyaContractAddress, nunyaContractCodeHash } } = varsSecret; - let varsEvm; if (config.networkSettings.evm.network == "sepolia") { varsEvm = config.networkSettings.evm.sepolia; @@ -33,13 +24,34 @@ if (config.networkSettings.evm.network == "sepolia") { } else { throw new Error(`Unsupported network.`) } -const { chainId: evmChainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = varsEvm; +const { privateKey } = varsEvm; export const requestNunya = async (params: RequestParams) => { const { callbackSelectorName, callbackGasLimitAmount, requestFunctionName, requestEthValue, secretContractRequestHandle, secretContractRequestHandleArgs } = params; const ifaceGateway = new ethers.utils.Interface(gatewayAbi.abi); const ifaceNunya = new ethers.utils.Interface(nunyaAbi.abi); + let deployed = await loadDeployed(); + let varsDeployedEvm; + if (deployed.data.evm.network == "sepolia") { + varsDeployedEvm = deployed.data.evm.sepolia; + } else if (deployed.data.evm.network == "localhost") { + varsDeployedEvm = deployed.data.evm.localhost; + } else { + throw new Error(`Unsupported network.`) + } + const { chainId: evmChainId, endpoint: evmEndpoint, nunyaBusinessContractAddress, gatewayContractAddress } = varsDeployedEvm; + + let varsDeployedSecret; + if (deployed.data.secret.network == "testnet") { + varsDeployedSecret = deployed.data.secret.testnet; + } else if (deployed.data.secret.network == "localhost") { + varsDeployedSecret = deployed.data.secret.localhost; + } else { + throw new Error(`Unsupported network.`) + } + const { secretNunya: { nunyaContractCodeHash, nunyaContractAddress } } = varsDeployedSecret; + const routing_contract = nunyaContractAddress; const routing_code_hash = nunyaContractCodeHash; @@ -49,7 +61,7 @@ export const requestNunya = async (params: RequestParams) => { } let provider; - provider = new ethers.providers.JsonRpcProvider(endpoint); + provider = new ethers.providers.JsonRpcProvider(evmEndpoint); console.log(provider); await provider.detectNetwork(); const signer = new Wallet(privateKey, provider); @@ -93,7 +105,7 @@ export const requestNunya = async (params: RequestParams) => { // Data are the calldata/parameters that are passed into the contract const data = JSON.stringify(secretContractRequestHandleArgs); - assert!(evmChainId.toString() == (await provider.getNetwork()).chainId.toString()); + assert!(evmChainId == (await provider.getNetwork()).chainId.toString()); // EVM gateway contract address // const publicClientAddress = await getPublicClientAddress(evmChainId); @@ -188,31 +200,31 @@ export const requestNunya = async (params: RequestParams) => { // let amountOfGas; // let my_gas = 150000; - // if (evmChainId.toString() === "4202") { + // if (evmChainId === "4202") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2); - // } else if (evmChainId.toString() === "128123") { + // } else if (evmChainId === "128123") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2); // my_gas = 15000000; - // } else if (evmChainId.toString() === "1287") { + // } else if (evmChainId === "1287") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2); // my_gas = 15000000; - // } else if (evmChainId.toString() === "300") { + // } else if (evmChainId === "300") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2); // my_gas = 15000000; - // } else if (evmChainId.toString() === "5003") { + // } else if (evmChainId === "5003") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(1000000).div(2); // my_gas = 1500000000; - // } else if (evmChainId.toString() === "80002") { + // } else if (evmChainId === "80002") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2); // my_gas = 200000; - // } else if (evmChainId.toString() === "1995") { + // } else if (evmChainId === "1995") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2); // my_gas = 200000; - // } else if (evmChainId.toString() === "713715") { + // } else if (evmChainId === "713715") { // amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2); // my_gas = 200000; // } else { - // // Note: Sepolia Ethereum has evmChainId 11155111 + // // Note: Sepolia Ethereum has chainId 11155111 // amountOfGas = gasFee.mul(callbackGasLimit).mul(3).div(2); // } // // Note: Only if get error `replacement fee too low` then just increase gasPrice by 10% @@ -256,7 +268,7 @@ export const requestNunya = async (params: RequestParams) => { gasPrice: hexlify(my_gas), nonce: nextNonceNum, data: functionData, // function to call and args - chainId: evmChainId, + chainId: parseInt(evmChainId), } tx = await managedSigner.sendTransaction(txParamsSend); diff --git a/packages/secret-contracts-scripts/src/uploadAndInstantiateNunya.ts b/packages/secret-contracts-scripts/src/uploadAndInstantiateNunya.ts index 40c9d80..e156c59 100644 --- a/packages/secret-contracts-scripts/src/uploadAndInstantiateNunya.ts +++ b/packages/secret-contracts-scripts/src/uploadAndInstantiateNunya.ts @@ -17,18 +17,12 @@ const walletOptions = { } let isLocal: boolean; -if (config.networkSettings.secret.network == "testnet") { - isLocal = false; -} else if (config.networkSettings.secret.network == "localhost") { - isLocal = true; -} else if (config.networkSettings.secret.network == "mainnet") { - throw new Error(`Unsupported Secret network.`) -} - let varsSecret; if (config.networkSettings.secret.network == "testnet") { + isLocal = false; varsSecret = config.networkSettings.secret.testnet; } else if (config.networkSettings.secret.network == "localhost") { + isLocal = true; varsSecret = config.networkSettings.secret.localhost; } else { throw new Error(`Unsupported Secret network.`) diff --git a/scripts/run.sh b/scripts/run.sh index 70e869a..bf4d72a 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -133,7 +133,7 @@ sudo chown -R ethlocal_service /root/nunya/packages/hardhat/node_modules/hardhat sudo chmod 755 /opt/ethlocal/hardhat sudo chmod 755 ~/nunya/packages/hardhat/node_modules/.bin/hardhat sudo chmod 755 ~/nunya/packages/hardhat/node_modules/hardhat/internal/cli/bootstrap.js -ls -al /opt/ethlocal +# ls -al /opt/ethlocal # Create service file