From 1c49c30e0d7fced7695f35848080dcbca20873ff Mon Sep 17 00:00:00 2001 From: Igor Stadnyk Date: Sat, 13 Jul 2024 20:52:46 +0200 Subject: [PATCH] Fix build to deploy, install Wingman Module WIP --- frontend/app/page.tsx | 12 +++-- frontend/hooks/useSmartAccountClient.js | 1 - frontend/services/consts.js | 1 - frontend/services/installModule.js | 67 +++++++------------------ frontend/tsconfig.json | 4 +- 5 files changed, 29 insertions(+), 56 deletions(-) diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 74b9979..1c3291b 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -9,17 +9,21 @@ import ConnectSafeButton from '@/components/ConnectSafeButton'; import useUniversalAccountInfo from "@/hooks/useUniversalAccountInfo"; import useSmartAccountClient from "@/hooks/useSmartAccountClient"; import {Button} from "@nextui-org/button"; +import {installWingmanModule} from "@/services/installModule.js"; export default function Home() { const { connectedTo } = useUniversalAccountInfo(); const { isModuleSupported, - isWingmanDeployed + isWingmanDeployed, + smartAccountClient } = useSmartAccountClient(); async function handleModuleDeploy() { - + if (!smartAccountClient) return; + console.log(installWingmanModule) + installWingmanModule(smartAccountClient).then(() => console.log('Module installed')); } return ( @@ -35,7 +39,7 @@ export default function Home() { assets and support your loved ones if things don't go as planned.

- { !!connectedTo ? ( + { !connectedTo ? ( ) : null } @@ -53,7 +57,7 @@ export default function Home() { className="font-semibold" color="primary" size="lg" - // onClick={() => open({ view: 'Connect' })} + onClick={handleModuleDeploy} > Deploy Wingman module to your wallet diff --git a/frontend/hooks/useSmartAccountClient.js b/frontend/hooks/useSmartAccountClient.js index 9952f4c..167abed 100644 --- a/frontend/hooks/useSmartAccountClient.js +++ b/frontend/hooks/useSmartAccountClient.js @@ -7,7 +7,6 @@ import {prepareSafeAccount, prepareSmartAccountClient} from "@/services/prepareS import {isWingmanModuleInitialized} from "@/services/installModule"; import {walletClientToSmartAccountSigner} from "permissionless"; - export default function useSmartAccountClient() { const [client, setClient] = useState({ smartAccountClient: null, diff --git a/frontend/services/consts.js b/frontend/services/consts.js index dbc7bc8..c2763d5 100644 --- a/frontend/services/consts.js +++ b/frontend/services/consts.js @@ -1,7 +1,6 @@ 'use client' import {createPublicClient, http} from "viem"; -import {checkEnvVar} from "./utils"; // export const pimlicoApiKey = checkEnvVar("NEXT_PUBLIC_PIMLICO_API_KEY"); // export const wingmanModuleAddress = checkEnvVar("NEXT_PUBLIC_WINGMAN_MODULE_ADDRESS"); diff --git a/frontend/services/installModule.js b/frontend/services/installModule.js index 0f017d8..a0a90ff 100644 --- a/frontend/services/installModule.js +++ b/frontend/services/installModule.js @@ -6,7 +6,7 @@ import { import { createPimlicoBundlerClient, } from "permissionless/clients/pimlico"; -import {encodePacked, http} from "viem"; +import {http} from "viem"; import {pimlicoPaymasterActions} from "permissionless/actions/pimlico"; import abi from "./module.abi.json"; @@ -27,69 +27,40 @@ export function isWingmanModuleInitialized(smartAccountAddress) { }) } -async function installModule({smartClient, beneficiaryAddress, timeout, moduleType, hook, bundlerClient, moduleAddress, publicClient}) { +export async function installWingmanModule(smartAccountClient) { const module = { module: wingmanModuleAddress, - initData: encodePacked(['address', 'uint48'], [beneficiaryAddress, timeout]), + initData: '0x', deInitData: '0x', additionalContext: '0x', type: 'executor', - hook, + hook: '0x', } - const opHash = await smartClient.installModule({ + const opHash = await smartAccountClient.installModule({ type: module.type, address: module.module, context: module.initData, }); - const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: opHash }) - console.log('receipt', receipt) -} - -const timeout = 123123123; - -async function installModule({smartClient, beneficiaryAddress, timeout, moduleType, hook, account, bundlerClient, moduleAddress, publicClient}) { - const module = { - module: moduleAddress, - initData: '0x', - deInitData: '0x', - additionalContext: '0x', - type: 'executor', - hook, - } - - const ownableExecutorModule = "0xbDa1dE70eAE1A18BbfdCaE95B42b5Ff6d3352492" - - const moduleData = encodePacked(["address"], ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"]) + const receipt = await pimlicoBundlerClient.waitForUserOperationReceipt({hash: opHash}) - const userOpHash = await smartAccountClient.installModule({ - type: "executor", - address: ownableExecutorModule, - context: "0x", - }) - - const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: userOpHash }) + console.log(receipt); + return receipt } -const { smartAccountClient, safeAccount, pimlicoBundlerClient, publicClient } = await createSmartWallet({ - privateKey: "0xba52725ea00c53ea649d0479eede2a3caf3c2cfdb0f90010db6d83b64c94ebfe", - bundlerUrl: "https://api.pimlico.io/v2/sepolia/rpc?apikey=5499b16e-f9de-427c-8cd1-76417e0a7d22" -}) - - +// installModule({ +// smartClient: smartAccountClient, +// beneficiaryAddress: beneficiary.address, +// timeout, +// moduleType: "executor", +// hook: '0x', +// account: safeAccount, +// bundlerClient: pimlicoBundlerClient, +// moduleAddress: "0xbDa1dE70eAE1A18BbfdCaE95B42b5Ff6d3352492", +// publicClient +// }); -installModule({ - smartClient: smartAccountClient, - beneficiaryAddress: beneficiary.address, - timeout, - moduleType: "executor", - hook: '0x', - account: safeAccount, - bundlerClient: pimlicoBundlerClient, - moduleAddress: "0xbDa1dE70eAE1A18BbfdCaE95B42b5Ff6d3352492", - publicClient -}); // // installModule({ // smartClient: smartAccountClient, diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index e06a445..547fb12 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], + "target": "es2020", + "lib": ["esnext"], "allowJs": true, "skipLibCheck": true, "strict": true,