Skip to content

Commit

Permalink
Fix build to deploy, install Wingman Module WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Stadnyk committed Jul 13, 2024
1 parent 57d713a commit 1c49c30
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 56 deletions.
12 changes: 8 additions & 4 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -35,7 +39,7 @@ export default function Home() {
assets and support your loved ones if things don't go as planned.
</p>

{ !!connectedTo ? (
{ !connectedTo ? (
<ConnectSafeButton />
) : null }

Expand All @@ -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
</Button>
Expand Down
1 change: 0 additions & 1 deletion frontend/hooks/useSmartAccountClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion frontend/services/consts.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
67 changes: 19 additions & 48 deletions frontend/services/installModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"target": "es2020",
"lib": ["esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand Down

0 comments on commit 1c49c30

Please sign in to comment.