From 99208e6dcc120dfb678d6acf0d61e38007a5986e Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 20 Aug 2024 17:19:27 +0300 Subject: [PATCH] Pass chainId --- src/gnosis-safe.ts | 15 +++++++++------ src/submitters/auto-submitter.ts | 4 ++-- src/submitters/safe-submitter.ts | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gnosis-safe.ts b/src/gnosis-safe.ts index a25a73a..bf8b41f 100644 --- a/src/gnosis-safe.ts +++ b/src/gnosis-safe.ts @@ -105,9 +105,7 @@ const getSafeTransactionUrl = (chainId: bigint) => { ` at network with chainId = ${chainId}`); }; -const getSafeService = async () => { - const - {chainId} = await ethers.provider.getNetwork(); +const getSafeService = (chainId: bigint) => { const safeService = new SafeApiKit({ chainId, "txServiceUrl": getSafeTransactionUrl(chainId) @@ -117,10 +115,11 @@ const getSafeService = async () => { const estimateSafeTransaction = async ( safeAddress: string, + chainId: bigint, safeTransactionData: SafeTransactionDataPartial | MetaTransactionData[] ) => { console.log("Estimate gas"); - const safeService = await getSafeService(); + const safeService = getSafeService(chainId); const gasEstimations = await Promise. all((safeTransactionData as MetaTransactionData[]). map((transaction) => safeService.estimateSafeTransaction( @@ -141,13 +140,14 @@ const estimateSafeTransaction = async ( const proposeTransaction = async ( safeAddress: string, + chainId: bigint, safeTransaction: SafeTransaction ) => { const [safeOwner] = await ethers.getSigners(); const safeSdk = await Safe.init({provider: network.provider, safeAddress}); const safeTxHash = await safeSdk.getTransactionHash(safeTransaction); const senderSignature = await safeSdk.signHash(safeTxHash); - const safeService = await getSafeService(); + const safeService = getSafeService(chainId); await safeService.proposeTransaction({ safeAddress, "safeTransactionData": safeTransaction.data, @@ -161,10 +161,11 @@ const proposeTransaction = async ( export const createMultiSendTransaction = async ( safeAddress: string, + chainId: bigint, transactions: Transaction[] ) => { const safeTransactionData = getSafeTransactionData(transactions); - const safeService = await getSafeService(); + const safeService = getSafeService(chainId); const nonce = await safeService.getNextNonce(safeAddress); console.log( "Will send tx to Gnosis with nonce", @@ -194,11 +195,13 @@ export const createMultiSendTransaction = async ( await estimateSafeTransaction( safeAddress, + chainId, safeTransactionData ); await proposeTransaction( safeAddress, + chainId, safeTransaction ); }; diff --git a/src/submitters/auto-submitter.ts b/src/submitters/auto-submitter.ts index ca123f8..5427599 100644 --- a/src/submitters/auto-submitter.ts +++ b/src/submitters/auto-submitter.ts @@ -54,12 +54,12 @@ export class AutoSubmitter extends Submitter { } private static async getSubmitterForContractOwner (owner: string) { + const mainnetChainId = AutoSubmitter.getMainnetChainId(); if (ethers.getAddress(owner) === ethers.getAddress(MARIONETTE_ADDRESS)) { console.log("Marionette owner is detected"); const imaInstance = await AutoSubmitter.getImaInstance(); - const mainnetChainId = AutoSubmitter.getMainnetChainId(); const safeAddress = AutoSubmitter.getSafeAddress(); const schainHash = AutoSubmitter.getSchainHash(); @@ -101,7 +101,7 @@ export class AutoSubmitter extends Submitter { // Assuming owner is a Gnosis Safe console.log("Using Gnosis Safe"); - return new SafeSubmitter(owner); + return new SafeSubmitter(owner, mainnetChainId); } private static async getImaInstance () { diff --git a/src/submitters/safe-submitter.ts b/src/submitters/safe-submitter.ts index 29467a4..c8aea16 100644 --- a/src/submitters/safe-submitter.ts +++ b/src/submitters/safe-submitter.ts @@ -21,6 +21,7 @@ export class SafeSubmitter extends Submitter { } await createMultiSendTransaction( this.safeAddress, + this.chainId, transactions ); }