-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create:account, create:backup scripts
- Loading branch information
1 parent
3b965d4
commit 2c348a3
Showing
5 changed files
with
170 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const generateBackupAbiWithArgs = ({name, unlockAt, beneficiaries}) => ({ | ||
abi: [ | ||
{ | ||
name: "updateBackup", | ||
type: "function", | ||
stateMutability: "nonpayable", | ||
inputs: [ | ||
{ internalType: 'string', name: 'name', type: 'string' }, | ||
{ internalType: 'uint48', name: 'unlockAt', type: 'uint48' }, | ||
{ | ||
internalType: 'struct Wingman.Beneficiary[]', | ||
name: 'beneficiaries', | ||
type: 'tuple[]', | ||
components: [ | ||
{ internalType: 'address', name: 'account', type: 'address' }, | ||
{ internalType: 'uint8', name: 'percentage', type: 'uint8' }, | ||
{ internalType: 'uint256', name: 'amount', type: 'uint256' } | ||
] | ||
} | ||
], | ||
outputs: [] | ||
} | ||
], | ||
functionName: "updateBackup", | ||
args: [name, unlockAt, beneficiaries] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {parseAccount, sendUserOperation} from "permissionless"; | ||
import {generateBackupAbiWithArgs} from "./backup-abi"; | ||
import {createSmartWallet} from "./create-smart-account"; | ||
|
||
async function updateBackup({ | ||
smartClient, | ||
accountAddress, | ||
moduleAddress, | ||
name, | ||
unlockAt, | ||
beneficiaries, | ||
bundlerClient | ||
}) { | ||
const account = parseAccount(accountAddress); | ||
|
||
const updateBackupCallData = account.encodeFunctionData( | ||
generateBackupAbiWithArgs({name, unlockAt, beneficiaries}) | ||
); | ||
|
||
const opHash = await smartClient.sendUserOperation({ | ||
sender: account.address, | ||
updateBackupCallData, | ||
to: moduleAddress | ||
}); | ||
|
||
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: opHash }); | ||
return receipt; | ||
} | ||
|
||
async function main({ | ||
name, | ||
unlockAt, | ||
beneficiaries | ||
}) { | ||
const { | ||
smartAccountClient, | ||
safeAccount, | ||
pimlicoBundlerClient | ||
} = createSmartWallet({ | ||
privateKey: "<PK>", | ||
bundlerUrl: "<bundler url>", | ||
}); | ||
|
||
await updateBackup({ | ||
smartClient: smartAccountClient, | ||
accountAddress: safeAccount.address, | ||
moduleAddress: "0xab614e4a5398bb2a2a0bf73f9c913ec7ff47d81f", | ||
name, | ||
unlockAt, | ||
beneficiaries, | ||
bundlerClient: pimlicoBundlerClient | ||
}); | ||
|
||
console.log("Backup updated successfully!"); | ||
} | ||
|
||
main({ | ||
name: "name", | ||
unlockAt: 1231231233, | ||
beneficiaries: [ | ||
{ | ||
account: "0xAddress1", | ||
percentage: 50, | ||
amount: BigInt(1000) | ||
}, | ||
{ | ||
account: "0xAddress2", | ||
percentage: 50, | ||
amount: BigInt(1000) | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
ENTRYPOINT_ADDRESS_V07, | ||
createSmartAccountClient, | ||
} from "permissionless"; | ||
import { signerToSafeSmartAccount } from "permissionless/accounts"; | ||
import { createPimlicoBundlerClient } from "permissionless/clients/pimlico"; | ||
import { createPublicClient, http } from "viem"; | ||
import { sepolia } from "viem/chains"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { erc7579Actions } from "permissionless/actions/erc7579.js"; | ||
import { pimlicoPaymasterActions } from "permissionless/actions/pimlico"; | ||
|
||
|
||
export async function createSmartWallet({privateKey, bundlerUrl}) { | ||
const signer = privateKeyToAccount(privateKey); | ||
|
||
|
||
const publicClient = createPublicClient({ | ||
transport: http("https://rpc.ankr.com/eth_sepolia"), | ||
}) | ||
|
||
const pimlicoBundlerClient = createPimlicoBundlerClient({ | ||
transport: http(bundlerUrl), | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
}).extend(pimlicoPaymasterActions(ENTRYPOINT_ADDRESS_V07)); | ||
|
||
const safeAccount = await signerToSafeSmartAccount(publicClient, { | ||
signer, | ||
safeVersion: "1.4.1", | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
safe4337ModuleAddress: "0x3Fdb5BC686e861480ef99A6E3FaAe03c0b9F32e2", | ||
erc7579LaunchpadAddress: "0xEBe001b3D534B9B6E2500FB78E67a1A137f561CE", | ||
}) | ||
|
||
const smartAccountClient = createSmartAccountClient({ | ||
account: safeAccount, | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
chain: sepolia, | ||
bundlerTransport: http(bundlerUrl), | ||
middleware: { | ||
gasPrice: async () => { | ||
return (await pimlicoBundlerClient.getUserOperationGasPrice()).fast | ||
}, | ||
sponsorUserOperation: pimlicoBundlerClient.sponsorUserOperation | ||
}, | ||
}).extend(erc7579Actions({ entryPoint: ENTRYPOINT_ADDRESS_V07 })) | ||
|
||
return { smartAccountClient, safeAccount, pimlicoBundlerClient, publicClient } | ||
} | ||
|
||
createSmartWallet({ | ||
privateKey: "0x30320097c1d7009d6d970376c792fe157a5e989f057b8908345043393a56a8a5", | ||
bundlerUrl: "https://api.pimlico.io/v2/sepolia/rpc?apikey=04287e53-84d2-413b-bbc6-450629d7e999", | ||
}) |