|
| 1 | +import { |
| 2 | + deepHexlify, |
| 3 | + resolveProperties, |
| 4 | + type UserOperationRequest_v7, |
| 5 | +} from "@aa-sdk/core"; |
| 6 | +import { concat, encodeAbiParameters, keccak256, pad, toHex } from "viem"; |
| 7 | +import { accounts, entrypoint080 } from "../constants"; |
| 8 | +import { toPaymaster } from "./base"; |
| 9 | +import type { Paymaster } from "./types"; |
| 10 | +import { VerifyingPaymaster070Abi } from "./VerifyingPaymaster070"; |
| 11 | + |
| 12 | +export const paymaster080: Paymaster = toPaymaster({ |
| 13 | + entryPointVersion: "0.8.0", |
| 14 | + entryPointAddress: entrypoint080, |
| 15 | + abi: VerifyingPaymaster070Abi, |
| 16 | + dummyData: concat([ |
| 17 | + "0xffffffffffffffffffffffff", |
| 18 | + "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c", |
| 19 | + ]), |
| 20 | + getPaymasterStubData(self) { |
| 21 | + const { address, dummyData } = self.getPaymasterDetails(); |
| 22 | + |
| 23 | + return { paymaster: address, paymasterData: dummyData }; |
| 24 | + }, |
| 25 | + async getPaymasterData(self, uo_, client) { |
| 26 | + const { address } = self.getPaymasterDetails(); |
| 27 | + const uo = deepHexlify( |
| 28 | + // @ts-ignore |
| 29 | + await resolveProperties(uo_), |
| 30 | + ) as UserOperationRequest_v7; |
| 31 | + |
| 32 | + const validUntil = 0n; |
| 33 | + const validFrom = 0n; |
| 34 | + const expiryPacked = |
| 35 | + (validUntil << BigInt(160)) | (validFrom << BigInt(160 + 48)); |
| 36 | + |
| 37 | + const encoding = keccak256( |
| 38 | + encodeAbiParameters( |
| 39 | + [ |
| 40 | + { type: "address" }, |
| 41 | + { type: "uint256" }, |
| 42 | + { type: "bytes32" }, |
| 43 | + { type: "bytes32" }, |
| 44 | + { type: "bytes32" }, |
| 45 | + { type: "uint256" }, |
| 46 | + { type: "bytes32" }, |
| 47 | + { type: "bytes32" }, |
| 48 | + { type: "address" }, |
| 49 | + { type: "uint" }, |
| 50 | + { type: "uint256" }, |
| 51 | + ], |
| 52 | + [ |
| 53 | + uo.sender, |
| 54 | + BigInt(uo.nonce), |
| 55 | + keccak256(uo.factory ? concat([uo.factory, uo.factoryData!]) : "0x"), |
| 56 | + keccak256(uo.callData), |
| 57 | + concat([ |
| 58 | + pad(uo.verificationGasLimit, { dir: "left", size: 16 }), |
| 59 | + pad(uo.callGasLimit, { dir: "left", size: 16 }), |
| 60 | + ]), |
| 61 | + BigInt(uo.preVerificationGas), |
| 62 | + concat([ |
| 63 | + pad(uo.maxPriorityFeePerGas, { dir: "left", size: 16 }), |
| 64 | + pad(uo.maxFeePerGas, { dir: "left", size: 16 }), |
| 65 | + ]), |
| 66 | + concat([ |
| 67 | + pad(uo.paymasterVerificationGasLimit ?? "0x0", { |
| 68 | + dir: "left", |
| 69 | + size: 16, |
| 70 | + }), |
| 71 | + pad(uo.paymasterPostOpGasLimit ?? "0x0", { dir: "left", size: 16 }), |
| 72 | + ]), |
| 73 | + entrypoint080, |
| 74 | + BigInt(client.chain!.id), |
| 75 | + expiryPacked, |
| 76 | + ], |
| 77 | + ), |
| 78 | + ); |
| 79 | + |
| 80 | + const signature = await accounts.paymasterOwner.signMessage({ |
| 81 | + message: { raw: encoding }, |
| 82 | + }); |
| 83 | + |
| 84 | + const paymasterData = concat([ |
| 85 | + toHex(validFrom, { size: 6 }), |
| 86 | + toHex(validUntil, { size: 6 }), |
| 87 | + signature, |
| 88 | + ]); |
| 89 | + |
| 90 | + return { paymaster: address, paymasterData }; |
| 91 | + }, |
| 92 | +}); |
0 commit comments