-
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.
Delete example, add installing module scripts
- Loading branch information
1 parent
277e451
commit 19c45ff
Showing
7 changed files
with
144 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const abi = [ | ||
{ | ||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }], | ||
name: 'config', | ||
outputs: [ | ||
{ internalType: 'uint48', name: 'lastAccess', type: 'uint48' }, | ||
{ internalType: 'uint48', name: 'timeout', type: 'uint48' }, | ||
{ internalType: 'address', name: 'nominee', type: 'address' }, | ||
], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: 'address', name: 'smartAccount', type: 'address' }, | ||
], | ||
name: 'isInitialized', | ||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
] |
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 |
---|---|---|
@@ -1,51 +0,0 @@ | ||
import {generatePrivateKey, privateKeyToAccount} from "viem/accounts"; | ||
import {pimlicoBundlerClient, publicClient, safeAccount, smartAccountClient} from "./smart-account.js"; | ||
import {abi} from "./abi.js"; | ||
import {encodePacked} from "viem"; | ||
|
||
const privateKey = generatePrivateKey() | ||
|
||
const beneficiary = privateKeyToAccount(privateKey); | ||
const timeout = 100; //in seconds | ||
|
||
async function installModule({smartClient, beneficiaryAddress, timeout, moduleType, hook, account, bundlerClient, moduleAddress, publicClient}) { | ||
const isInitialized = (await publicClient.readContract({ | ||
address: moduleAddress, | ||
abi, | ||
functionName: 'isInitialized', | ||
args: [account.address], | ||
})) | ||
|
||
const module = { | ||
module: moduleAddress, | ||
initData: isInitialized | ||
? '0x' | ||
: encodePacked(['address', 'uint48'], [beneficiaryAddress, timeout]), | ||
deInitData: '0x', | ||
additionalContext: '0x', | ||
type: moduleType, | ||
hook, | ||
} | ||
|
||
|
||
const opHash = await smartClient.installModule({ | ||
type: module.type, | ||
address: module.module, | ||
context: module.initData, | ||
}); | ||
|
||
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: opHash }) | ||
console.log('receipt', receipt) | ||
} | ||
|
||
installModule({ | ||
smartClient: smartAccountClient, | ||
beneficiaryAddress: beneficiary.address, | ||
timeout, | ||
moduleType: "validator", | ||
hook: '0x', | ||
account: safeAccount, | ||
bundlerClient: pimlicoBundlerClient, | ||
moduleAddress: "0xab614e4a5398bb2a2a0bf73f9c913ec7ff47d81f", //deadmanswitch module address | ||
publicClient | ||
}) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +0,0 @@ | ||
{ | ||
"name": "permissionless_test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"run": "bun run index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"permissionless": "^0.1.39", | ||
"viem": "^2.17.3" | ||
} | ||
} | ||
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,22 @@ | ||
export const abi = [ | ||
{ | ||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }], | ||
name: 'config', | ||
outputs: [ | ||
{ internalType: 'uint48', name: 'lastAccess', type: 'uint48' }, | ||
{ internalType: 'uint48', name: 'timeout', type: 'uint48' }, | ||
{ internalType: 'address', name: 'nominee', type: 'address' }, | ||
], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: 'address', name: 'smartAccount', type: 'address' }, | ||
], | ||
name: 'isInitialized', | ||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
] |
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,98 @@ | ||
import { | ||
ENTRYPOINT_ADDRESS_V07, | ||
createSmartAccountClient, | ||
} from "permissionless"; | ||
import { signerToSafeSmartAccount } from "permissionless/accounts"; | ||
import { | ||
createPimlicoBundlerClient, | ||
} from "permissionless/clients/pimlico"; | ||
import { createPublicClient, http, encodePacked } from "viem"; | ||
import { sepolia } from "viem/chains"; | ||
import {generatePrivateKey, privateKeyToAccount} from "viem/accounts"; | ||
import {erc7579Actions} from "permissionless/actions/erc7579.js"; | ||
import {pimlicoPaymasterActions} from "permissionless/actions/pimlico"; | ||
import {abi} from "./abi"; | ||
|
||
const apiKey = "" | ||
|
||
const privateKey = generatePrivateKey() | ||
|
||
export const bundlerUrl = `https://api.pimlico.io/v2/sepolia/rpc?apikey=${apiKey}` | ||
|
||
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 })) | ||
|
||
const beneficiary = privateKeyToAccount(privateKey); | ||
const timeout = 100; //in seconds | ||
|
||
async function installModule({smartClient, beneficiaryAddress, timeout, moduleType, hook, account, bundlerClient, moduleAddress, publicClient}) { | ||
const isInitialized = (await publicClient.readContract({ | ||
address: moduleAddress, | ||
abi, | ||
functionName: 'isInitialized', | ||
args: [account.address], | ||
})) | ||
|
||
const module = { | ||
module: moduleAddress, | ||
initData: isInitialized | ||
? '0x' | ||
: encodePacked(['address', 'uint48'], [beneficiaryAddress, timeout]), | ||
deInitData: '0x', | ||
additionalContext: '0x', | ||
type: moduleType, | ||
hook, | ||
} | ||
|
||
|
||
const opHash = await smartClient.installModule({ | ||
type: module.type, | ||
address: module.module, | ||
context: module.initData, | ||
}); | ||
|
||
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: opHash }) | ||
} | ||
|
||
installModule({ | ||
smartClient: smartAccountClient, | ||
beneficiaryAddress: beneficiary.address, | ||
timeout, | ||
moduleType: "validator", | ||
hook: '0x', | ||
account: safeAccount, | ||
bundlerClient: pimlicoBundlerClient, | ||
moduleAddress: "0x6A53E204b8A21dfD64516ff27484e6113640CB96", | ||
publicClient | ||
}) |