-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
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,59 @@ | ||
import { ethers } from "hardhat" | ||
import * as fs from "fs" | ||
import * as path from "path" | ||
import ecPem from "ec-pem" | ||
|
||
import { P256AccountFactory } from "../../typechain" | ||
import { EntryPoint } from "@account-abstraction/contracts" | ||
import { Client, Presets } from "userop" | ||
import { P256Account } from "../userop/p256-account" | ||
import { P2565Signer } from "../userop/p256-signature" | ||
|
||
// TODO need create account first | ||
async function main() { | ||
const rpc = "https://babel-api.testnet.iotex.io" | ||
const bundlerRpc = "https://bundler.testnet.w3bstream.com" | ||
const accountFactory = (await ethers.getContract("P256AccountFactory")) as P256AccountFactory | ||
const accountTpl = await ethers.getContractFactory("P256Account") | ||
const entryPoint = (await ethers.getContract("EntryPoint")) as EntryPoint | ||
const client = await Client.init(rpc, { | ||
entryPoint: entryPoint.address, | ||
overrideBundlerRpc: bundlerRpc, | ||
}) | ||
|
||
const keyContent = fs.readFileSync(path.join(__dirname, "key.pem")) | ||
const keyPair = ecPem.loadPrivateKey(keyContent) | ||
const signer = new P2565Signer(keyPair) | ||
|
||
const accountBuilder = await P256Account.init(signer, rpc, { | ||
overrideBundlerRpc: bundlerRpc, | ||
factory: accountFactory.address, | ||
entryPoint: entryPoint.address, | ||
salt: 0, | ||
paymasterMiddleware: Presets.Middleware.verifyingPaymaster( | ||
// paymaster rpc | ||
`https://paymaster.testnet.w3bstream.com/rpc/${process.env.API_KEY}`, | ||
"" | ||
), | ||
}) | ||
const account = accountBuilder.getSender() | ||
|
||
const callData = accountTpl.interface.encodeFunctionData("execute", [ | ||
account, | ||
0, | ||
accountTpl.interface.encodeFunctionData("stopRecovery", []), | ||
]) | ||
accountBuilder.setCallData(callData) | ||
|
||
const response = await client.sendUserOperation(accountBuilder) | ||
console.log(`Stop recovery account ${account} ophash: ${response.userOpHash}`) | ||
const userOperationEvent = await response.wait() | ||
console.log(`Stop recovery account ${account} txhash: ${userOperationEvent?.transactionHash}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
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