@latticexyz/paymaster 2.2.15-entrykit-510cc59769bcf83670255be3102d702c4b673225 → 2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/transports/quarryPassIssuer.ts","../src/debug.ts","../src/claimGasPass.ts","../src/getAllowance.ts","../src/paymaster.ts","../src/getPaymasterAddress.ts","../src/hasPassIssuer.ts","../src/transports/methods/estimateUserOperationGas.ts","../src/transports/gasEstimator.ts","../src/transports/userOpExecutor.ts","../src/transports/methods/sendUserOperation.ts"],"sourcesContent":["import { Address, EIP1193RequestFn, Hex, Transport, http } from \"viem\";\n\nexport type QuarryPassIssuerRpcSchema = [\n {\n Method: \"quarry_issuePass\";\n Parameters: [passId: Hex, receiver: Address];\n ReturnType: { message: string };\n },\n {\n Method: \"quarry_claimAllowance\";\n Parameters: [passId: Hex, receiver: Address];\n ReturnType: { message: string };\n },\n];\n\nexport function quarryPassIssuer(): Transport<\"http\", {}, EIP1193RequestFn<QuarryPassIssuerRpcSchema>> {\n return ({ chain }) => {\n if (!chain) throw new Error(\"No chain provided to issuer transport.\");\n\n const url = \"quarryPassIssuer\" in chain.rpcUrls ? chain.rpcUrls.quarryPassIssuer.http[0] : undefined;\n // TODO: add fallback for anvil to do what quarryPassIssuer does internally\n if (!url) throw new Error(`No \\`quarryPassIssuer\\` RPC URL found for chain ${chain.id}.`);\n\n return http(url)({ chain, retryCount: 0 });\n };\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:paymaster\");\n","import { Address, Chain } from \"viem\";\nimport { quarryPassIssuer } from \"./transports/quarryPassIssuer\";\nimport { debug } from \"./debug\";\n\nexport async function claimGasPass({ chain, userAddress }: { chain: Chain; userAddress: Address }) {\n const transport = quarryPassIssuer()({ chain });\n\n // TODO: handle case where you already have a pass?\n debug(\"Issuing gas pass to\", userAddress);\n await transport.request({\n method: \"quarry_issuePass\",\n params: [\"0x01\", userAddress],\n });\n\n debug(\"Claiming gas allowance for\", userAddress);\n await transport.request({\n method: \"quarry_claimAllowance\",\n params: [\"0x01\", userAddress],\n });\n}\n","import { Address, Client, numberToHex } from \"viem\";\nimport { paymasterTables } from \"./paymaster\";\nimport { getRecord, getStaticDataLocation } from \"@latticexyz/store/internal\";\nimport { getKeyTuple } from \"@latticexyz/protocol-parser/internal\";\nimport { setStorageAt } from \"viem/actions\";\n\nexport type GetAllowanceParams = {\n client: Client;\n paymasterAddress: Address;\n userAddress: Address;\n};\n\nexport async function getAllowance({ client, paymasterAddress, userAddress }: GetAllowanceParams) {\n const record = await getRecord(client, {\n address: paymasterAddress,\n table: paymasterTables.Allowance,\n key: { user: userAddress },\n blockTag: \"pending\",\n });\n return record.allowance;\n}\n\nexport function getAllowanceSlot({ userAddress }: { userAddress: Address }) {\n return getStaticDataLocation(\n paymasterTables.Allowance.tableId,\n getKeyTuple(paymasterTables.Allowance, { user: userAddress }),\n );\n}\n\n// TODO: move this into some sort of store util to `setField`\nexport async function setAllowanceSlot({\n client,\n paymasterAddress,\n userAddress,\n allowance,\n}: GetAllowanceParams & { allowance: bigint }) {\n const slot = getStaticDataLocation(\n paymasterTables.Allowance.tableId,\n getKeyTuple(paymasterTables.Allowance, { user: userAddress }),\n );\n\n await setStorageAt(\n client.extend(() => ({ mode: \"anvil\" })),\n {\n address: paymasterAddress,\n index: slot,\n value: numberToHex(allowance, { size: 32 }),\n },\n );\n}\n","import { defineStore } from \"@latticexyz/store\";\nimport { parseAbi } from \"viem\";\n\n// TODO: move the whole paymaster in here so we can just re-export ABI + MUD config\n\nexport const paymasterAbi = parseAbi([\n \"error SpenderSystem_AlreadyRegistered(address spender, address user)\",\n \"error SpenderSystem_HasOwnBalance(address spender)\",\n \"function registerSpender(address spender)\",\n]);\n\nexport const paymasterConfig = defineStore({\n namespaces: {\n root: {\n namespace: \"\",\n tables: {\n Allowance: {\n schema: {\n user: \"address\",\n allowance: \"uint256\",\n },\n key: [\"user\"],\n },\n Grantor: {\n schema: {\n grantor: \"address\",\n allowance: \"uint256\",\n },\n key: [\"grantor\"],\n },\n PassHolder: {\n schema: {\n user: \"address\",\n passId: \"bytes32\",\n lastRenewed: \"uint256\",\n lastClaimed: \"uint256\",\n },\n key: [\"user\", \"passId\"],\n },\n PassConfig: {\n schema: {\n passId: \"bytes32\",\n claimAmount: \"uint256\",\n claimInterval: \"uint256\",\n validityPeriod: \"uint256\",\n grantor: \"address\",\n },\n key: [\"passId\"],\n },\n Spender: {\n schema: {\n spender: \"address\",\n user: \"address\",\n },\n key: [\"spender\"],\n },\n SystemConfig: {\n schema: {\n entryPoint: \"address\",\n },\n key: [],\n },\n },\n },\n },\n});\n\nexport const paymasterTables = paymasterConfig.namespaces.root.tables;\n","import { Chain, getChainContractAddress } from \"viem\";\n\nexport function getPaymasterAddress(chain: Chain) {\n return getChainContractAddress({ chain, contract: \"quarryPaymaster\" });\n}\n","import { Chain, ChainContract } from \"viem\";\n\nexport function hasPassIssuer(chain: Chain) {\n const paymasterContract = chain?.contracts?.quarryPaymaster as ChainContract | undefined;\n const paymasterAddress = paymasterContract?.address;\n\n const passIssuerUrl = \"quarryPassIssuer\" in chain.rpcUrls ? chain.rpcUrls.quarryPassIssuer.http[0] : undefined;\n\n return paymasterAddress != null && passIssuerUrl;\n}\n","import { BundlerRpcSchema } from \"viem\";\nimport { formatUserOperationRequest } from \"viem/account-abstraction\";\nimport { getRpcMethod } from \"../common\";\n\n// TODO: revisit after demo (don't hardcode gas)\n\ntype rpcMethod = getRpcMethod<BundlerRpcSchema, \"eth_estimateUserOperationGas\">;\n\nexport async function estimateUserOperationGas(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _params: rpcMethod[\"Parameters\"],\n): Promise<rpcMethod[\"ReturnType\"]> {\n return formatUserOperationRequest({\n callGasLimit: 20_000_000n,\n preVerificationGas: 200_000n,\n verificationGasLimit: 2_000_000n,\n paymasterVerificationGasLimit: 200_000n,\n paymasterPostOpGasLimit: 200_000n,\n });\n}\n","import { BundlerRpcSchema, Transport } from \"viem\";\nimport { estimateUserOperationGas } from \"./methods/estimateUserOperationGas\";\nimport { TransportRequestFn, getRpcSchema } from \"./common\";\n\n// TODO: move to common package?\n\nexport function gasEstimator<const transport extends Transport>(getTransport: transport): transport {\n return ((opts) => {\n const { request: originalRequest, ...rest } = getTransport(opts);\n\n const request: TransportRequestFn<getRpcSchema<BundlerRpcSchema, \"eth_estimateUserOperationGas\">> = async (\n { method, params },\n options,\n ) => {\n if (method === \"eth_estimateUserOperationGas\") {\n return estimateUserOperationGas(params);\n }\n return originalRequest({ method, params }, options);\n };\n\n return { request, ...rest };\n }) as transport;\n}\n","import {\n Account,\n BundlerRpcSchema,\n Chain,\n Client,\n EIP1193RequestFn,\n Hash,\n RpcUserOperationReceipt,\n Transport,\n createTransport,\n numberToHex,\n} from \"viem\";\nimport { entryPoint07Address } from \"viem/account-abstraction\";\nimport { TransportRequestFn } from \"./common\";\nimport { estimateUserOperationGas } from \"./methods/estimateUserOperationGas\";\nimport { sendUserOperation } from \"./methods/sendUserOperation\";\n\n// TODO: move to common package?\n\nexport function userOpExecutor({ executor }: { executor: Client<Transport, Chain, Account> }): Transport {\n return () => {\n const receipts = new Map<Hash, RpcUserOperationReceipt<\"0.7\">>();\n\n // @ts-expect-error TODO\n const request: TransportRequestFn<BundlerRpcSchema> = async ({ method, params }) => {\n // TODO: move chain/ID into args and executors as accounts instead of clients?\n if (method === \"eth_chainId\") {\n return numberToHex(executor.chain.id);\n }\n\n if (method === \"eth_supportedEntryPoints\") {\n return [entryPoint07Address];\n }\n\n if (method === \"eth_sendUserOperation\") {\n const [rpcUserOp, entrypoint] = params;\n if (entrypoint === entryPoint07Address) {\n const result = await sendUserOperation({ executor, rpcUserOp });\n receipts.set(result.userOpHash, result as RpcUserOperationReceipt<\"0.7\">);\n return result.userOpHash;\n }\n }\n\n if (method === \"eth_getUserOperationReceipt\") {\n const [hash] = params;\n return receipts.get(hash) ?? null;\n }\n\n if (method === \"eth_estimateUserOperationGas\") {\n return await estimateUserOperationGas(params);\n }\n\n throw new Error(\"Not implemented\");\n };\n\n return createTransport({\n key: \"userOpExecutor\",\n type: \"userOpExecutor\",\n name: \"User Operation Executor Transport\",\n request: request as EIP1193RequestFn,\n });\n };\n}\n","import {\n Client,\n Transport,\n Chain,\n Account,\n RpcUserOperation,\n RpcUserOperationReceipt,\n parseEther,\n parseEventLogs,\n} from \"viem\";\nimport {\n formatUserOperation,\n toPackedUserOperation,\n getUserOperationHash,\n entryPoint07Address,\n entryPoint07Abi,\n} from \"viem/account-abstraction\";\nimport { setBalance, waitForTransactionReceipt, writeContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\n\n// TODO: move to common package?\n\n// TODO: move this into a generic to support other versions?\nconst entryPointVersion = \"0.7\";\ntype entryPointVersion = typeof entryPointVersion;\n\nexport async function sendUserOperation({\n executor,\n rpcUserOp,\n}: {\n executor: Client<Transport, Chain, Account>;\n rpcUserOp: RpcUserOperation<entryPointVersion>;\n}): Promise<\n Pick<RpcUserOperationReceipt<entryPointVersion>, \"success\" | \"userOpHash\"> & {\n receipt: Pick<RpcUserOperationReceipt<entryPointVersion>[\"receipt\"], \"transactionHash\">;\n }\n> {\n if (executor.chain.id === 31337) {\n await setBalance(\n executor.extend(() => ({ mode: \"anvil\" })),\n {\n address: executor.account.address,\n value: parseEther(\"100\"),\n },\n );\n }\n\n const userOp = formatUserOperation(rpcUserOp);\n const packedUserOp = toPackedUserOperation(userOp);\n\n const userOpHash = getUserOperationHash({\n userOperation: userOp,\n chainId: executor.chain.id,\n entryPointVersion: \"0.7\",\n entryPointAddress: entryPoint07Address,\n });\n\n const transactionHash = await getAction(\n executor,\n writeContract,\n \"writeContract\",\n )({\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n functionName: \"handleOps\",\n args: [[packedUserOp], executor.account.address],\n chain: executor.chain,\n account: executor.account,\n });\n\n const receipt = await getAction(\n executor,\n waitForTransactionReceipt,\n \"waitForTransactionReceipt\",\n )({ hash: transactionHash });\n\n // TODO: replace with `getUserOperationReceipt`?\n const parsedLogs = parseEventLogs({\n logs: receipt.logs,\n abi: entryPoint07Abi,\n eventName: \"UserOperationEvent\" as const,\n });\n\n return {\n success: parsedLogs[0]!.args.success,\n userOpHash,\n receipt,\n };\n}\n"],"mappings":"AAAA,OAAoD,QAAAA,MAAY,OAezD,SAASC,GAAuF,CACrG,MAAO,CAAC,CAAE,MAAAC,CAAM,IAAM,CACpB,GAAI,CAACA,EAAO,MAAM,IAAI,MAAM,wCAAwC,EAEpE,IAAMC,EAAM,qBAAsBD,EAAM,QAAUA,EAAM,QAAQ,iBAAiB,KAAK,CAAC,EAAI,OAE3F,GAAI,CAACC,EAAK,MAAM,IAAI,MAAM,mDAAmDD,EAAM,KAAK,EAExF,OAAOF,EAAKG,CAAG,EAAE,CAAE,MAAAD,EAAO,WAAY,CAAE,CAAC,CAC3C,CACF,CCzBA,OAAOE,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,eAAe,ECEhD,eAAsBE,EAAa,CAAE,MAAAC,EAAO,YAAAC,CAAY,EAA2C,CACjG,IAAMC,EAAYC,EAAiB,EAAE,CAAE,MAAAH,CAAM,CAAC,EAG9CI,EAAM,sBAAuBH,CAAW,EACxC,MAAMC,EAAU,QAAQ,CACtB,OAAQ,mBACR,OAAQ,CAAC,OAAQD,CAAW,CAC9B,CAAC,EAEDG,EAAM,6BAA8BH,CAAW,EAC/C,MAAMC,EAAU,QAAQ,CACtB,OAAQ,wBACR,OAAQ,CAAC,OAAQD,CAAW,CAC9B,CAAC,CACH,CCnBA,OAA0B,eAAAI,MAAmB,OCA7C,OAAS,eAAAC,MAAmB,oBAC5B,OAAS,YAAAC,MAAgB,OAIlB,IAAMC,EAAeD,EAAS,CACnC,uEACA,qDACA,2CACF,CAAC,EAEYE,EAAkBH,EAAY,CACzC,WAAY,CACV,KAAM,CACJ,UAAW,GACX,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AAU,CAAC,EAC9D,OAAAN,EAAS,IAAIQ,EAAO,WAAYA,CAAwC,EACjEA,EAAO,YAIlB,GAAIN,IAAW,8BAA+B,CAC5C,GAAM,CAACQ,CAAI,EAAIP,EACf,OAAOH,EAAS,IAAIU,CAAI,GAAK,KAG/B,GAAIR,IAAW,+BACb,OAAO,MAAMS,EAAyBR,CAAM,EAG9C,MAAM,IAAI,MAAM,iBAAiB,CACnC,CAOA,CAAC,CACH,CACF","names":["http","quarryPassIssuer","chain","url","createDebug","debug","claimGasPass","chain","userAddress","transport","quarryPassIssuer","debug","numberToHex","defineStore","parseAbi","paymasterAbi","paymasterConfig","paymasterTables","getRecord","getStaticDataLocation","getKeyTuple","setStorageAt","getAllowance","client","paymasterAddress","userAddress","paymasterTables","getAllowanceSlot","setAllowanceSlot","allowance","slot","numberToHex","getChainContractAddress","getPaymasterAddress","chain","hasPassIssuer","chain","paymasterAddress","passIssuerUrl","formatUserOperationRequest","estimateUserOperationGas","_params","gasEstimator","getTransport","opts","originalRequest","rest","method","params","options","estimateUserOperationGas","createTransport","numberToHex","entryPoint07Address","parseEther","parseEventLogs","formatUserOperation","toPackedUserOperation","getUserOperationHash","entryPoint07Address","entryPoint07Abi","setBalance","waitForTransactionReceipt","writeContract","getAction","sendUserOperation","executor","rpcUserOp","setBalance","parseEther","userOp","formatUserOperation","packedUserOp","toPackedUserOperation","userOpHash","getUserOperationHash","entryPoint07Address","transactionHash","getAction","writeContract","entryPoint07Abi","receipt","waitForTransactionReceipt","parseEventLogs","userOpExecutor","executor","receipts","createTransport","method","params","numberToHex","entryPoint07Address","rpcUserOp","entrypoint","result","sendUserOperation","hash","estimateUserOperationGas"]}