Skip to content

Commit

Permalink
fix: metamask works
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Oct 30, 2023
1 parent e69ad01 commit 19484c5
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions examples/account-abstraction/safe/src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'rea
import AccountAbstraction from '@safe-global/account-abstraction-kit-poc';
import { Web3AuthModalPack } from '@safe-global/auth-kit';

import Safe, { EthersAdapter } from '@safe-global/protocol-kit';
import { GelatoRelayPack } from '@safe-global/relay-kit';
import { MetaTransactionData, MetaTransactionOptions } from '@safe-global/safe-core-sdk-types';
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types';
import { useQuery } from '@tanstack/react-query';

const goerliChain: Chain = {
Expand Down Expand Up @@ -196,7 +197,7 @@ const AccountAbstractionProvider = ({ children }: { children: JSX.Element }) =>
const getSafeAddress = async () => {
if (web3Provider) {
const signer = web3Provider.getSigner();
const relayPack = new GelatoRelayPack();
const relayPack = new GelatoRelayPack('_H2parOk7AeLqmhXkgRhPjVOUUYz31FNFGJA7CwNEzE_');
const safeAccountAbstraction = new AccountAbstraction(signer);

await safeAccountAbstraction.init({ relayPack });
Expand Down Expand Up @@ -232,20 +233,44 @@ const AccountAbstractionProvider = ({ children }: { children: JSX.Element }) =>
setIsRelayerLoading(true);

const signer = web3Provider.getSigner();
const relayPack = new GelatoRelayPack();
const safeAccountAbstraction = new AccountAbstraction(signer);
// const safeAccountAbstraction = new AccountAbstraction(signer);

await safeAccountAbstraction.init({ relayPack });
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: signer
});

const dumpSafeTransafer: MetaTransactionData[] = [transaction];
const safeSDK = await Safe.create({
ethAdapter,
safeAddress: safeSelected
});

const options: MetaTransactionOptions = {
isSponsored: false,
gasLimit: '600000', // in this alfa version we need to manually set the gas limit
gasToken: ethers.constants.AddressZero // native token
};
const relayPack = new GelatoRelayPack('_H2parOk7AeLqmhXkgRhPjVOUUYz31FNFGJA7CwNEzE_');

// const signedSafeTransaction = await safeSDK.signTransaction(safeTransaction);

// await safeAccountAbstraction.init({ relayPack });

const transactions: MetaTransactionData[] = [transaction];

// const options: MetaTransactionOptions = {
// isSponsored: false,
// gasLimit: '600000', // in this alfa version we need to manually set the gas limit
// gasToken: ethers.constants.AddressZero // native token
// };

const safeTransaction = await relayPack.createRelayedTransaction({
safe: safeSDK,
transactions
});

const signedSafeTransaction = await safeSDK.signTransaction(safeTransaction);

const response = await relayPack.executeRelayTransaction(signedSafeTransaction, safeSDK);

console.log(`Relay Transaction Task ID: https://relay.gelato.digital/tasks/status/${response.taskId}`);

const gelatoTaskId = await safeAccountAbstraction.relayTransaction(dumpSafeTransafer, options);
// const gelatoTaskId = await safeAccountAbstraction.relayTransaction(dumpSafeTransafer, options);

setIsRelayerLoading(false);
setGelatoTaskId(gelatoTaskId);
Expand Down

0 comments on commit 19484c5

Please sign in to comment.