Skip to content

Commit

Permalink
Merge pull request #287 from skalenetwork/chain-id
Browse files Browse the repository at this point in the history
Pass chainId
  • Loading branch information
DimaStebaev authored Aug 20, 2024
2 parents 04583dc + 99208e6 commit a25071e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/gnosis-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -194,11 +195,13 @@ export const createMultiSendTransaction = async (

await estimateSafeTransaction(
safeAddress,
chainId,
safeTransactionData
);

await proposeTransaction(
safeAddress,
chainId,
safeTransaction
);
};
4 changes: 2 additions & 2 deletions src/submitters/auto-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions src/submitters/safe-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class SafeSubmitter extends Submitter {
}
await createMultiSendTransaction(
this.safeAddress,
this.chainId,
transactions
);
}
Expand Down

0 comments on commit a25071e

Please sign in to comment.