@@ -5,6 +5,7 @@ dotenv.config();
55import { ethers , Wallet } from "ethers" ;
66import { NonceManager } from "@ethersproject/experimental" ;
77import config from './../../config/config.js' ;
8+ import { loadDeployed } from "../../loadDeployed.js" ;
89import gatewayAbi from "../../../../hardhat/artifacts/contracts/Gateway.sol/Gateway.json" assert { type : "json" } ;
910import nunyaAbi from "../../../../hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json" assert { type : "json" } ;
1011import { generateKeys } from "../../functions/secretpath/generateKeys.js" ;
@@ -15,16 +16,6 @@ import { hexlify } from "ethers/lib/utils.js";
1516import { assert } from "console" ;
1617import { 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-
2819let varsEvm ;
2920if ( 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
3829export 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 ) ;
0 commit comments