Skip to content

Commit 4210968

Browse files
committed
fix
1 parent 2291807 commit 4210968

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

packages/secret-contracts-scripts/src/config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let initialNetworkSettings = {
1818
evm: {
1919
network: "localhost",
2020
localhost: {
21-
chainId: 31337,
21+
chainId: "31337",
2222
endpoint: "http://127.0.0.1:8545/",
2323
// Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
2424
privateKey: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
@@ -28,7 +28,7 @@ let initialNetworkSettings = {
2828
gatewayContractAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", // only know after deploy
2929
},
3030
sepolia: {
31-
chainId: 11155111,
31+
chainId: "11155111",
3232
endpoint: process.env.PROVIDER_RPC_ETHEREUM_SEPOLIA,
3333
privateKey: process.env.DEPLOYER_PRIVATE_KEY,
3434
nunyaBusinessContractAddress: "0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D", // only know after deploy

packages/secret-contracts-scripts/src/evm/setEVMGatewayAddress.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ethers, Contract, Wallet, utils } from "ethers";
55
import gatewayAbi from "../../../hardhat/artifacts/contracts/Gateway.sol/Gateway.json" assert { type: "json" };
66
import nunyaAbi from "../../../hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json" assert { type: "json" };
77
import config from '../config/config.js';
8+
import { loadDeployed } from "../loadDeployed.js";
89

910
let varsEvm;
1011
if (config.networkSettings.evm.network == "sepolia") {
@@ -14,10 +15,22 @@ if (config.networkSettings.evm.network == "sepolia") {
1415
} else {
1516
throw new Error(`Unsupported network.`)
1617
}
17-
const { chainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = varsEvm;
18+
const { endpoint: evmEndpoint, privateKey } = varsEvm;
1819

1920
// Sets the deployed Gateway address storage value for the NunyaBusiness contract
2021
async function setGatewayAddress() {
22+
23+
let deployed = await loadDeployed();
24+
let varsDeployedEvm;
25+
if (deployed.data.evm.network == "sepolia") {
26+
varsDeployedEvm = deployed.data.evm.sepolia;
27+
} else if (deployed.data.evm.network == "localhost") {
28+
varsDeployedEvm = deployed.data.evm.localhost;
29+
} else {
30+
throw new Error(`Unsupported network.`)
31+
}
32+
const { nunyaBusinessContractAddress, gatewayContractAddress } = varsDeployedEvm;
33+
2134
if (nunyaBusinessContractAddress == "") {
2235
console.error("Please deploy Nunya.business contract first");
2336
}
@@ -28,7 +41,7 @@ async function setGatewayAddress() {
2841
}
2942

3043
let provider;
31-
provider = new ethers.providers.JsonRpcProvider(endpoint);
44+
provider = new ethers.providers.JsonRpcProvider(evmEndpoint);
3245
// console.log(provider);
3346
await provider.detectNetwork();
3447
const signer = new Wallet(privateKey, provider);

packages/secret-contracts-scripts/src/functions/evm/requestNunya.ts

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dotenv.config();
55
import { ethers, Wallet } from "ethers";
66
import { NonceManager } from "@ethersproject/experimental";
77
import config from './../../config/config.js';
8+
import { loadDeployed } from "../../loadDeployed.js";
89
import gatewayAbi from "../../../../hardhat/artifacts/contracts/Gateway.sol/Gateway.json" assert { type: "json" };
910
import nunyaAbi from "../../../../hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json" assert { type: "json" };
1011
import { generateKeys } from "../../functions/secretpath/generateKeys.js";
@@ -15,16 +16,6 @@ import { hexlify } from "ethers/lib/utils.js";
1516
import { assert } from "console";
1617
import { RequestParams } from "../../types/index.js";
1718

18-
let varsSecret;
19-
if (config.networkSettings.secret.network == "testnet") {
20-
varsSecret = config.networkSettings.secret.testnet;
21-
} else if (config.networkSettings.secret.network == "localhost") {
22-
varsSecret = config.networkSettings.secret.localhost;
23-
} else {
24-
throw new Error(`Unsupported Secret network.`)
25-
}
26-
const { chainId: secretChainId, secretNunya: { nunyaContractAddress, nunyaContractCodeHash } } = varsSecret;
27-
2819
let varsEvm;
2920
if (config.networkSettings.evm.network == "sepolia") {
3021
varsEvm = config.networkSettings.evm.sepolia;
@@ -33,13 +24,34 @@ if (config.networkSettings.evm.network == "sepolia") {
3324
} else {
3425
throw new Error(`Unsupported network.`)
3526
}
36-
const { chainId: evmChainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = varsEvm;
27+
const { privateKey } = varsEvm;
3728

3829
export const requestNunya = async (params: RequestParams) => {
3930
const { callbackSelectorName, callbackGasLimitAmount, requestFunctionName, requestEthValue, secretContractRequestHandle, secretContractRequestHandleArgs } = params;
4031
const ifaceGateway = new ethers.utils.Interface(gatewayAbi.abi);
4132
const ifaceNunya = new ethers.utils.Interface(nunyaAbi.abi);
4233

34+
let deployed = await loadDeployed();
35+
let varsDeployedEvm;
36+
if (deployed.data.evm.network == "sepolia") {
37+
varsDeployedEvm = deployed.data.evm.sepolia;
38+
} else if (deployed.data.evm.network == "localhost") {
39+
varsDeployedEvm = deployed.data.evm.localhost;
40+
} else {
41+
throw new Error(`Unsupported network.`)
42+
}
43+
const { chainId: evmChainId, endpoint: evmEndpoint, nunyaBusinessContractAddress, gatewayContractAddress } = varsDeployedEvm;
44+
45+
let varsDeployedSecret;
46+
if (deployed.data.secret.network == "testnet") {
47+
varsDeployedSecret = deployed.data.secret.testnet;
48+
} else if (deployed.data.secret.network == "localhost") {
49+
varsDeployedSecret = deployed.data.secret.localhost;
50+
} else {
51+
throw new Error(`Unsupported network.`)
52+
}
53+
const { secretNunya: { nunyaContractCodeHash, nunyaContractAddress } } = varsDeployedSecret;
54+
4355
const routing_contract = nunyaContractAddress;
4456
const routing_code_hash = nunyaContractCodeHash;
4557

@@ -49,7 +61,7 @@ export const requestNunya = async (params: RequestParams) => {
4961
}
5062

5163
let provider;
52-
provider = new ethers.providers.JsonRpcProvider(endpoint);
64+
provider = new ethers.providers.JsonRpcProvider(evmEndpoint);
5365
console.log(provider);
5466
await provider.detectNetwork();
5567
const signer = new Wallet(privateKey, provider);
@@ -93,7 +105,7 @@ export const requestNunya = async (params: RequestParams) => {
93105
// Data are the calldata/parameters that are passed into the contract
94106
const data = JSON.stringify(secretContractRequestHandleArgs);
95107

96-
assert!(evmChainId.toString() == (await provider.getNetwork()).chainId.toString());
108+
assert!(evmChainId == (await provider.getNetwork()).chainId.toString());
97109

98110
// EVM gateway contract address
99111
// const publicClientAddress = await getPublicClientAddress(evmChainId);
@@ -188,31 +200,31 @@ export const requestNunya = async (params: RequestParams) => {
188200
// let amountOfGas;
189201
// let my_gas = 150000;
190202

191-
// if (evmChainId.toString() === "4202") {
203+
// if (evmChainId === "4202") {
192204
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2);
193-
// } else if (evmChainId.toString() === "128123") {
205+
// } else if (evmChainId === "128123") {
194206
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2);
195207
// my_gas = 15000000;
196-
// } else if (evmChainId.toString() === "1287") {
208+
// } else if (evmChainId === "1287") {
197209
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2);
198210
// my_gas = 15000000;
199-
// } else if (evmChainId.toString() === "300") {
211+
// } else if (evmChainId === "300") {
200212
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2);
201213
// my_gas = 15000000;
202-
// } else if (evmChainId.toString() === "5003") {
214+
// } else if (evmChainId === "5003") {
203215
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000000).div(2);
204216
// my_gas = 1500000000;
205-
// } else if (evmChainId.toString() === "80002") {
217+
// } else if (evmChainId === "80002") {
206218
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
207219
// my_gas = 200000;
208-
// } else if (evmChainId.toString() === "1995") {
220+
// } else if (evmChainId === "1995") {
209221
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
210222
// my_gas = 200000;
211-
// } else if (evmChainId.toString() === "713715") {
223+
// } else if (evmChainId === "713715") {
212224
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
213225
// my_gas = 200000;
214226
// } else {
215-
// // Note: Sepolia Ethereum has evmChainId 11155111
227+
// // Note: Sepolia Ethereum has chainId 11155111
216228
// amountOfGas = gasFee.mul(callbackGasLimit).mul(3).div(2);
217229
// }
218230
// // 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) => {
256268
gasPrice: hexlify(my_gas),
257269
nonce: nextNonceNum,
258270
data: functionData, // function to call and args
259-
chainId: evmChainId,
271+
chainId: parseInt(evmChainId),
260272
}
261273

262274
tx = await managedSigner.sendTransaction(txParamsSend);

packages/secret-contracts-scripts/src/uploadAndInstantiateNunya.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@ const walletOptions = {
1717
}
1818

1919
let isLocal: boolean;
20-
if (config.networkSettings.secret.network == "testnet") {
21-
isLocal = false;
22-
} else if (config.networkSettings.secret.network == "localhost") {
23-
isLocal = true;
24-
} else if (config.networkSettings.secret.network == "mainnet") {
25-
throw new Error(`Unsupported Secret network.`)
26-
}
27-
2820
let varsSecret;
2921
if (config.networkSettings.secret.network == "testnet") {
22+
isLocal = false;
3023
varsSecret = config.networkSettings.secret.testnet;
3124
} else if (config.networkSettings.secret.network == "localhost") {
25+
isLocal = true;
3226
varsSecret = config.networkSettings.secret.localhost;
3327
} else {
3428
throw new Error(`Unsupported Secret network.`)

scripts/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ sudo chown -R ethlocal_service /root/nunya/packages/hardhat/node_modules/hardhat
133133
sudo chmod 755 /opt/ethlocal/hardhat
134134
sudo chmod 755 ~/nunya/packages/hardhat/node_modules/.bin/hardhat
135135
sudo chmod 755 ~/nunya/packages/hardhat/node_modules/hardhat/internal/cli/bootstrap.js
136-
ls -al /opt/ethlocal
136+
# ls -al /opt/ethlocal
137137

138138
# Create service file
139139

0 commit comments

Comments
 (0)