@pepu-chain/sdk 0.2.0 → 0.2.2
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.
- package/README.md +26 -2
- package/dist/aa/kernel.cjs +11 -9
- package/dist/aa/kernel.guard.js +15 -0
- package/dist/aa/kernel.js +5 -4
- package/dist/aa/react-direct.cjs +14 -12
- package/dist/aa/react-direct.cjs.map +1 -1
- package/dist/aa/react-direct.guard.js +15 -0
- package/dist/aa/react-direct.js +7 -6
- package/dist/aa/react-direct.js.map +1 -1
- package/dist/aa/react.cjs +7 -5
- package/dist/aa/react.cjs.map +1 -1
- package/dist/aa/react.d.cts +1 -1
- package/dist/aa/react.d.ts +1 -1
- package/dist/aa/react.guard.js +15 -0
- package/dist/aa/react.js +4 -3
- package/dist/aa/react.js.map +1 -1
- package/dist/aa.cjs +19 -18
- package/dist/aa.d.cts +1 -1
- package/dist/aa.d.ts +1 -1
- package/dist/aa.js +6 -5
- package/dist/chunk-4GEC7GUU.cjs +283 -0
- package/dist/chunk-4GEC7GUU.cjs.map +1 -0
- package/dist/{chunk-PHM3ZORG.cjs → chunk-4L4CHIXE.cjs} +9 -9
- package/dist/{chunk-PHM3ZORG.cjs.map → chunk-4L4CHIXE.cjs.map} +1 -1
- package/dist/{chunk-A5LP2UCS.cjs → chunk-65Y5UCQ7.cjs} +2 -276
- package/dist/chunk-65Y5UCQ7.cjs.map +1 -0
- package/dist/{chunk-MBA4CLA5.js → chunk-7PVR7QSE.js} +3 -3
- package/dist/{chunk-MBA4CLA5.js.map → chunk-7PVR7QSE.js.map} +1 -1
- package/dist/{chunk-7MNJF2OB.cjs → chunk-DNWWZWUW.cjs} +4 -4
- package/dist/{chunk-7MNJF2OB.cjs.map → chunk-DNWWZWUW.cjs.map} +1 -1
- package/dist/{chunk-D52PADVY.js → chunk-GFKIM7HT.js} +25 -2
- package/dist/chunk-GFKIM7HT.js.map +1 -0
- package/dist/{chunk-IY3ALPUJ.js → chunk-GIZNH65Q.js} +5 -273
- package/dist/chunk-GIZNH65Q.js.map +1 -0
- package/dist/{chunk-WANILJZQ.cjs → chunk-HTCX46RJ.cjs} +25 -2
- package/dist/chunk-HTCX46RJ.cjs.map +1 -0
- package/dist/{chunk-TIEAZYHF.cjs → chunk-K7JSQPZO.cjs} +8 -2
- package/dist/chunk-K7JSQPZO.cjs.map +1 -0
- package/dist/{chunk-FCXSP2YF.js → chunk-KJYNF5KH.js} +8 -3
- package/dist/chunk-KJYNF5KH.js.map +1 -0
- package/dist/{chunk-KVG3AYYR.js → chunk-NHPWXIA2.js} +4 -4
- package/dist/{chunk-KVG3AYYR.js.map → chunk-NHPWXIA2.js.map} +1 -1
- package/dist/{chunk-ZB6SVBK4.js → chunk-QIDMFFAQ.js} +4 -4
- package/dist/{chunk-ZB6SVBK4.js.map → chunk-QIDMFFAQ.js.map} +1 -1
- package/dist/{chunk-IB2FSPMJ.js → chunk-QZKUPCUD.js} +3 -3
- package/dist/{chunk-IB2FSPMJ.js.map → chunk-QZKUPCUD.js.map} +1 -1
- package/dist/{chunk-ET3P6TX6.cjs → chunk-RCMKPJZO.cjs} +4 -4
- package/dist/{chunk-ET3P6TX6.cjs.map → chunk-RCMKPJZO.cjs.map} +1 -1
- package/dist/chunk-RSPAN44L.js +276 -0
- package/dist/chunk-RSPAN44L.js.map +1 -0
- package/dist/{chunk-NVOPDXTA.cjs → chunk-UQH4ZAXD.cjs} +10 -10
- package/dist/{chunk-NVOPDXTA.cjs.map → chunk-UQH4ZAXD.cjs.map} +1 -1
- package/dist/{chunk-SLW7FRTL.cjs → chunk-VYMAZVIK.cjs} +52 -22
- package/dist/chunk-VYMAZVIK.cjs.map +1 -0
- package/dist/{chunk-KIIFL4VM.js → chunk-XR5ONV2Y.js} +42 -12
- package/dist/chunk-XR5ONV2Y.js.map +1 -0
- package/dist/combo/react.cjs +62 -13
- package/dist/combo/react.cjs.map +1 -1
- package/dist/combo/react.d.cts +14 -2
- package/dist/combo/react.d.ts +14 -2
- package/dist/combo/react.guard.js +15 -0
- package/dist/combo/react.js +58 -11
- package/dist/combo/react.js.map +1 -1
- package/dist/combo.cjs +45 -29
- package/dist/combo.cjs.map +1 -1
- package/dist/combo.d.cts +11 -0
- package/dist/combo.d.ts +11 -0
- package/dist/combo.guard.js +15 -0
- package/dist/combo.js +33 -18
- package/dist/combo.js.map +1 -1
- package/dist/index.cjs +28 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/paymaster.cjs +39 -38
- package/dist/paymaster.cjs.map +1 -1
- package/dist/paymaster.js +4 -3
- package/dist/paymaster.js.map +1 -1
- package/dist/privy/react.cjs +1 -0
- package/dist/privy/react.guard.js +15 -0
- package/dist/privy/server.cjs +1 -0
- package/dist/privy/server.guard.js +15 -0
- package/dist/privy/wagmi.guard.js +15 -0
- package/dist/react.cjs +6 -4
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.guard.js +15 -0
- package/dist/react.js +4 -3
- package/dist/react.js.map +1 -1
- package/dist/session/kernel.cjs +19 -17
- package/dist/session/kernel.guard.js +15 -0
- package/dist/session/kernel.js +6 -5
- package/dist/session/react.cjs +1 -0
- package/dist/session/react.guard.js +15 -0
- package/dist/session/server.cjs +1 -0
- package/dist/session/server.guard.js +15 -0
- package/dist/{status-DwkkOrGQ.d.ts → status-Dx9zAFo9.d.ts} +42 -10
- package/dist/{status-CmOsyPmO.d.cts → status-wgTM26V7.d.cts} +42 -10
- package/package.json +38 -2
- package/dist/chunk-A5LP2UCS.cjs.map +0 -1
- package/dist/chunk-D52PADVY.js.map +0 -1
- package/dist/chunk-FCXSP2YF.js.map +0 -1
- package/dist/chunk-IY3ALPUJ.js.map +0 -1
- package/dist/chunk-KIIFL4VM.js.map +0 -1
- package/dist/chunk-SLW7FRTL.cjs.map +0 -1
- package/dist/chunk-TIEAZYHF.cjs.map +0 -1
- package/dist/chunk-WANILJZQ.cjs.map +0 -1
package/dist/paymaster.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/paymaster/onchain.ts"],"names":["isAddress","PepuConfigError","getAddress","getContract","pepuMainnet","PepuPaymasterError","keccak256","stringToBytes","isHex","pepuSponsoredPaymasterV2Abi","encodeFunctionData"],"mappings":";;;;;;;;;AA2BA,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,oBAAA,GAAuB,EAAA;AAkCtB,SAAS,0BAA0B,QAAA,EAA6B;AACrE,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,IAAI,CAACA,cAAA,CAAU,QAAA,EAAU,EAAE,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAG;AAC3C,MAAA,MAAM,IAAIC,iCAAA,CAAgB,oBAAA,EAAsB,4DAA4D,CAAA;AAAA,IAC9G;AACA,IAAA,OAAOC,gBAAW,QAAQ,CAAA;AAAA,EAC5B;AACA,EAAA,MAAM,KAAA,GAAQC,6BAAA,CAAYC,6BAAA,CAAY,EAAA,EAAI,aAAa,CAAA;AACvD,EAAA,IAAI,KAAA,EAAO,MAAA,KAAW,UAAA,EAAY,OAAO,KAAA,CAAM,OAAA;AAC/C,EAAA,MAAM,IAAIH,iCAAA;AAAA,IACR,oBAAA;AAAA,IACA;AAAA,GACF;AACF;AAWO,SAAS,iBAAiB,KAAA,EAAoB;AACnD,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,WAAW,CAAA,IAAK,KAAA,CAAM,SAAS,GAAA,EAAK;AACzE,IAAA,MAAM,IAAII,oCAAA,CAAmB,kBAAA,EAAoB,6DAA6D,CAAA;AAAA,EAChH;AACA,EAAA,OAAOC,cAAA,CAAUC,kBAAA,CAAc,KAAK,CAAC,C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paymaster.cjs","sourcesContent":["import { encodeFunctionData, getAddress, isAddress, isHex, keccak256, stringToBytes } from \"viem\";\nimport type { Account, Address, Chain, Hash, Hex, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getContract } from \"../contracts.js\";\nimport { PepuConfigError, PepuPaymasterError } from \"../errors.js\";\nimport { pepuSponsoredPaymasterV2Abi } from \"./abi.js\";\n\n/**\n * v2 (tiered, deposit-only) paymaster on-chain helpers.\n *\n * Facts these helpers encode (services/paymaster/SPONSORSHIP-SPEC.md):\n * - `projectId = keccak256(bytes(appId))`, case-sensitive.\n * - Deposits are one-way. Nobody can withdraw, owner or not. Anyone can `depositFor` any project.\n * - `claimProject` sets ONLY the owner. Nothing is sponsorable until the owner calls `setTargets`,\n * `setDailyLimit` and `setSenderDailyLimit` (see {@link configureProject}). A project with no per-wallet\n * limit (`setSenderDailyLimit`) is rejected on-chain.\n * - The first claim of a project that ALREADY HOLDS deposited funds is pending for the admin change delay (>= 48h):\n * finish it with {@link encodeExecuteReclaim}. An empty project is claimed immediately.\n * - A re-claim of an owned project is timelocked (>= 48h) and the owner can cancel it once per new owner.\n * - Ownership transfer is two-step (propose, then accept).\n *\n * The contract address comes from the registry (`paymasterV2`, the deployed canary: internally reviewed 3x,\n * external audit pending). Every helper takes an explicit `paymaster` address and throws CONFIG_MISSING_ENV when there is none.\n * No transaction is ever sent without the caller's wallet client.\n */\n\nconst U112_MAX = (1n << 112n) - 1n;\nconst U128_MAX = (1n << 128n) - 1n;\nconst MAX_TARGETS_PER_CALL = 50;\n\n/** A transaction a wallet (or smart account batch) can send. */\nexport interface PaymasterCall {\n to: Address;\n data: Hex;\n value: bigint;\n /** Solidity signature, for logs and UIs. */\n function: string;\n}\n\n/** The EIP-712 `ProjectClaim` attestation returned by `POST /v2/projects/verify`. */\nexport interface ProjectClaimAttestation {\n appId: string;\n newOwner: Address;\n nonce: string | bigint;\n deadline: string | bigint;\n signature: Hex;\n}\n\nexport interface PaymasterAddressOption {\n /** v2 paymaster address. Defaults to the registry's `paymasterV2` entry once it is deployed. */\n paymaster?: Address | undefined;\n}\n\n/**\n * Resolve the v2 paymaster address: explicit option first, then the registry. Throws\n * `CONFIG_MISSING_ENV` (never guesses an address) when neither is available.\n *\n * @example\n * ```ts\n * const paymaster = resolvePaymasterV2Address(\"0x1111111111111111111111111111111111111111\");\n * ```\n */\nexport function resolvePaymasterV2Address(explicit?: Address): Address {\n if (explicit !== undefined) {\n if (!isAddress(explicit, { strict: false })) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The v2 paymaster address passed in is not a valid address.\");\n }\n return getAddress(explicit);\n }\n const entry = getContract(pepuMainnet.id, \"paymasterV2\");\n if (entry?.status === \"deployed\") return entry.address;\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"No v2 paymaster address is configured: the registry's paymasterV2 entry is not deployed. Pass the deployed address explicitly as `paymaster` (GET /v2/contract on the policy service returns it). Never guess one.\",\n );\n}\n\n/**\n * `projectId = keccak256(bytes(appId))`. The app id is used exactly as given, so it is case-sensitive:\n * Privy app ids are lower-case cuids, and a different case is a different project.\n *\n * @example\n * ```ts\n * const projectId = computeProjectId(\"clx0example0app0id\");\n * ```\n */\nexport function computeProjectId(appId: string): Hex {\n if (typeof appId !== \"string\" || appId.length === 0 || appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"appId must be a non-empty string of at most 128 characters.\");\n }\n return keccak256(stringToBytes(appId));\n}\n\n/** Plan name for {@link computeProjectId}. */\nexport const getProjectId = computeProjectId;\n\nfunction assertProjectId(projectId: Hex): Hex {\n if (!isHex(projectId, { strict: true }) || projectId.length !== 66) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"projectId must be a 0x-prefixed 32-byte hex string.\");\n }\n return projectId;\n}\n\nfunction amount(label: string, v: bigint, max: bigint): bigint {\n if (typeof v !== \"bigint\" || v <= 0n || v > max) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `${label} must be a bigint greater than 0 and within range.`);\n }\n return v;\n}\n\nfunction call(to: Address, data: Hex, fn: string, value = 0n): PaymasterCall {\n return { to, data, value, function: fn };\n}\n\n/** State of a project, read from the paymaster contract. */\nexport interface ProjectState {\n projectId: Hex;\n paymaster: Address;\n /** `null` when unclaimed. */\n owner: Address | null;\n claimed: boolean;\n paused: boolean;\n /** Deposited, unspent wei. Deposit-only: this can only be spent as gas, never withdrawn. */\n balance: bigint;\n dailyLimit: bigint;\n senderDailyLimit: bigint;\n /** Spent in the current UTC day (0 when the stored day is stale). */\n spentToday: bigint;\n /** Day index (unix seconds / 86400) the stored `spentToday` belongs to. */\n spentDay: number;\n /** True when claimed and both limits are set. Targets are checked via `targetsAllowed`. */\n limitsConfigured: boolean;\n /**\n * Pending timelocked claim, or `null`: a re-claim of an owned project, or (when `claimed` is false) the first\n * claim of a project that already holds funds. Finish it with {@link encodeExecuteReclaim} after `executableAt`.\n */\n pendingReclaim: { newOwner: Address; executableAt: number; signer: Address } | null;\n /** Address proposed in a two-step ownership transfer, or `null`. */\n pendingOwner: Address | null;\n /** Present when `checkTargets` was passed: allowed flag per address (checksummed keys). */\n targetsAllowed?: Record<Address, boolean>;\n}\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nexport interface ReadProjectOptions extends PaymasterAddressOption {\n /** Also check these destinations against the on-chain allowlist (one `isTargetAllowed` read each). */\n checkTargets?: readonly Address[];\n /** Clock override for the day rollover (tests). Milliseconds. */\n now?: () => number;\n}\n\n/**\n * Read a project's on-chain state: owner, pause flag, balance, limits, pending re-claim and pending owner.\n *\n * @example\n * ```ts\n * const p = await readProject(publicClient, computeProjectId(appId), { paymaster });\n * if (!p.claimed) console.log(\"claim it first\");\n * ```\n */\nexport async function readProject(\n client: Pick<PublicClient, \"readContract\">,\n projectId: Hex,\n options: ReadProjectOptions = {},\n): Promise<ProjectState> {\n const paymaster = resolvePaymasterV2Address(options.paymaster);\n const id = assertProjectId(projectId);\n const abi = pepuSponsoredPaymasterV2Abi;\n const [project, reclaim, pendingOwner] = await Promise.all([\n client.readContract({ address: paymaster, abi, functionName: \"getProject\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingReclaim\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingProjectOwner\", args: [id] }),\n ]);\n const [owner, paused, senderDailyLimit, balance, dailyLimit, spentToday, spentDay] = project;\n const [reclaimOwner, executableAt, reclaimSigner] = reclaim;\n const claimed = owner !== ZERO;\n const today = Math.floor((options.now ?? Date.now)() / 1000 / 86_400);\n\n let targetsAllowed: Record<Address, boolean> | undefined;\n if (options.checkTargets && options.checkTargets.length > 0) {\n const entries = await Promise.all(\n options.checkTargets.map(async (t) => {\n const allowed = await client.readContract({\n address: paymaster,\n abi,\n functionName: \"isTargetAllowed\",\n args: [id, t],\n });\n return [getAddress(t), allowed] as const;\n }),\n );\n targetsAllowed = Object.fromEntries(entries) as Record<Address, boolean>;\n }\n\n return {\n projectId: id,\n paymaster,\n owner: claimed ? getAddress(owner) : null,\n claimed,\n paused,\n balance,\n dailyLimit,\n senderDailyLimit,\n spentToday: spentDay === today ? spentToday : 0n,\n spentDay,\n limitsConfigured: claimed && dailyLimit > 0n && senderDailyLimit > 0n,\n pendingReclaim:\n reclaimOwner !== ZERO ? { newOwner: getAddress(reclaimOwner), executableAt, signer: getAddress(reclaimSigner) } : null,\n pendingOwner: pendingOwner !== ZERO ? getAddress(pendingOwner) : null,\n ...(targetsAllowed ? { targetsAllowed } : {}),\n };\n}\n\n/**\n * Encode `depositFor(projectId)` with native PEPU as `value`. ONE-WAY: nothing can ever withdraw the deposit,\n * and the id is `keccak256` of a case-sensitive app id, so a typo deposits into a project nobody can claim.\n * Prefer {@link depositFor}, which checks the project is claimed first.\n *\n * @example\n * ```ts\n * const tx = encodeDeposit(computeProjectId(appId), 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeDeposit(projectId: Hex, amountWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"depositFor\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"depositFor(bytes32)\", amount(\"amountWei\", amountWei, U128_MAX));\n}\n\nfunction claimArgs(a: ProjectClaimAttestation) {\n if (!a.appId || a.appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.appId must be 1 to 128 characters.\");\n }\n if (!isAddress(a.newOwner, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.newOwner is not a valid address.\");\n }\n if (!isHex(a.signature)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.signature must be 0x-prefixed hex.\");\n }\n return {\n appId: a.appId,\n newOwner: getAddress(a.newOwner),\n nonce: BigInt(a.nonce),\n deadline: BigInt(a.deadline),\n signature: a.signature,\n };\n}\n\n/**\n * Encode `claimProject(Claim)`. The attestation fixes the owner; anyone may submit the transaction. The claim\n * sets ONLY the owner: follow with {@link configureProject}'s three calls, because nothing is sponsorable\n * until `setTargets`, `setDailyLimit` and `setSenderDailyLimit` have run. If the project already holds deposited\n * funds the claim is PENDING for the on-chain admin change delay (>= 48h): the contract owner or manager can cancel\n * it, and anyone finishes it with {@link encodeExecuteReclaim}.\n *\n * @example\n * ```ts\n * const tx = encodeClaimProject(attestation, { paymaster });\n * await walletClient.sendTransaction({ to: tx.to, data: tx.data });\n * ```\n */\nexport function encodeClaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"claimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"claimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Encode `reclaimProject(Claim)`: a timelocked (>= 48h) re-claim of an already-owned project. The current owner\n * can cancel it ({@link encodeCancelReclaim}); anyone can finish it after the delay ({@link encodeExecuteReclaim}).\n *\n * @example\n * ```ts\n * const tx = encodeReclaimProject(attestation, { paymaster });\n * ```\n */\nexport function encodeReclaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"reclaimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"reclaimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Pick `claimProject` or `reclaimProject` from a `/v2/projects/verify` result (its `action` field) and encode it.\n *\n * @example\n * ```ts\n * const tx = encodeClaimFromVerification(verified, { paymaster });\n * ```\n */\nexport function encodeClaimFromVerification(\n verified: { action: \"claimProject\" | \"reclaimProject\"; attestation: ProjectClaimAttestation },\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n return verified.action === \"reclaimProject\"\n ? encodeReclaimProject(verified.attestation, options)\n : encodeClaimProject(verified.attestation, options);\n}\n\n/**\n * Encode `executeReclaim(projectId)`: completes a pending claim or re-claim once its delay has passed (and before it\n * expires, 30 days later).\n *\n * @example\n * ```ts\n * const tx = encodeExecuteReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeExecuteReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"executeReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"executeReclaim(bytes32)\");\n}\n\n/**\n * Encode `cancelReclaim(projectId)`: the current owner cancels a pending re-claim, ONCE per new owner (a second\n * attested re-claim by the same new owner cannot be cancelled). For a pending FIRST claim of an unowned project the\n * contract owner or manager cancels instead.\n *\n * @example\n * ```ts\n * const tx = encodeCancelReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeCancelReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"cancelReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"cancelReclaim(bytes32)\");\n}\n\n/**\n * Encode `setTargets(projectId, targets, allowed)`: add or remove destination contracts the project sponsors\n * (at most 50 per call). Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetTargets(projectId, [counter], true, { paymaster });\n * ```\n */\nexport function encodeSetTargets(\n projectId: Hex,\n targets: readonly Address[],\n allowed: boolean,\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (targets.length === 0 || targets.length > MAX_TARGETS_PER_CALL) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `targets must contain 1 to ${MAX_TARGETS_PER_CALL} addresses per call.`);\n }\n for (const t of targets) {\n if (!isAddress(t, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"targets contains an invalid address.\");\n }\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setTargets\",\n args: [assertProjectId(projectId), targets.map((t) => getAddress(t)), allowed],\n });\n return call(to, data, \"setTargets(bytes32,address[],bool)\");\n}\n\n/**\n * Encode `setDailyLimit(projectId, limitWei)`: the project's total daily gas budget. Owner only. Must be above\n * zero; a contract-side zero limit means nothing can be spent, and tightening is instant.\n *\n * @example\n * ```ts\n * const tx = encodeSetDailyLimit(projectId, 5n * 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeSetDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setSenderDailyLimit(projectId, limitWei)`: the per-wallet daily gas limit. Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetSenderDailyLimit(projectId, 10n ** 17n, { paymaster });\n * ```\n */\nexport function encodeSetSenderDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setSenderDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setSenderDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setPaused(projectId, paused)`. Pausing takes effect immediately; it is the project's emergency stop.\n *\n * @example\n * ```ts\n * const stop = encodeSetPaused(projectId, true, { paymaster });\n * ```\n */\nexport function encodeSetPaused(projectId: Hex, paused: boolean, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setPaused\",\n args: [assertProjectId(projectId), paused],\n });\n return call(to, data, \"setPaused(bytes32,bool)\");\n}\n\n/**\n * Encode `proposeProjectOwner(projectId, newOwner)`: step one of the two-step ownership transfer. The new\n * owner must then call {@link encodeAcceptProjectOwnership}.\n *\n * @example\n * ```ts\n * const tx = encodeProposeProjectOwner(projectId, newOwner, { paymaster });\n * ```\n */\nexport function encodeProposeProjectOwner(projectId: Hex, newOwner: Address, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (!isAddress(newOwner, { strict: false }) || newOwner === ZERO) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"newOwner must be a non-zero valid address.\");\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"proposeProjectOwner\",\n args: [assertProjectId(projectId), getAddress(newOwner)],\n });\n return call(to, data, \"proposeProjectOwner(bytes32,address)\");\n}\n\n/**\n * Encode `acceptProjectOwnership(projectId)`: step two of the ownership transfer, sent by the proposed owner.\n *\n * @example\n * ```ts\n * const tx = encodeAcceptProjectOwnership(projectId, { paymaster });\n * ```\n */\nexport function encodeAcceptProjectOwnership(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"acceptProjectOwnership\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"acceptProjectOwnership(bytes32)\");\n}\n\nexport interface ConfigureProjectParams extends PaymasterAddressOption {\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n /** Destination contracts to sponsor (the on-chain allowlist). 1 to 50. */\n targets: readonly Address[];\n /** Total daily budget, wei. */\n dailyLimitWei: bigint;\n /** Per-wallet daily budget, wei. */\n senderDailyLimitWei: bigint;\n}\n\n/**\n * The three post-claim configuration calls, in order: `setTargets(allowed = true)`, `setDailyLimit`,\n * `setSenderDailyLimit`. A project spends nothing until all three have run. All three are owner-only calls to\n * the same contract, so a smart account or batched wallet can send them in one transaction; an EOA sends them\n * one after another with {@link sendPaymasterCalls}.\n *\n * @example\n * ```ts\n * const { calls } = configureProject({\n * appId, paymaster,\n * targets: [counter],\n * dailyLimitWei: 5n * 10n ** 18n,\n * senderDailyLimitWei: 10n ** 17n,\n * });\n * await smartAccountClient.sendUserOperation({ calls: calls.map(({ to, data, value }) => ({ to, data, value })) });\n * ```\n */\nexport function configureProject(params: ConfigureProjectParams): { projectId: Hex; calls: PaymasterCall[] } {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"configureProject needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const o = { paymaster: params.paymaster };\n return {\n projectId,\n calls: [\n encodeSetTargets(projectId, params.targets, true, o),\n encodeSetDailyLimit(projectId, params.dailyLimitWei, o),\n encodeSetSenderDailyLimit(projectId, params.senderDailyLimitWei, o),\n ],\n };\n}\n\ntype SendingWallet = Pick<WalletClient, \"sendTransaction\"> & { account?: Account | undefined; chain?: Chain | undefined };\n\n/**\n * Send prepared calls one after another from a wallet client, returning the hashes. When `publicClient` is\n * given it waits for each receipt first (so a later call is not sent after an earlier one failed). The\n * transaction `value` is exactly the call's value; nothing else is added.\n *\n * @example\n * ```ts\n * const hashes = await sendPaymasterCalls(walletClient, calls, { publicClient });\n * ```\n */\nexport async function sendPaymasterCalls(\n walletClient: SendingWallet,\n calls: readonly PaymasterCall[],\n options: { publicClient?: Pick<PublicClient, \"waitForTransactionReceipt\"> } = {},\n): Promise<Hash[]> {\n const account = walletClient.account;\n if (!account) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The wallet client has no account; create it with an account.\");\n }\n const chain = walletClient.chain ?? pepuMainnet;\n const hashes: Hash[] = [];\n for (const c of calls) {\n const hash = await walletClient.sendTransaction({ account, chain, to: c.to, data: c.data, value: c.value });\n hashes.push(hash);\n if (options.publicClient) {\n const receipt = await options.publicClient.waitForTransactionReceipt({ hash });\n if (receipt.status !== \"success\") {\n throw new PepuPaymasterError(\"TX_REVERTED\", `Paymaster call ${c.function} reverted (transaction ${hash}).`, {\n details: { hash, function: c.function },\n });\n }\n }\n }\n return hashes;\n}\n\nexport interface DepositForParams extends PaymasterAddressOption {\n walletClient: SendingWallet;\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n amountWei: bigint;\n /**\n * Default true: read the project first and refuse when it has no owner, which catches a mistyped (case-sensitive)\n * app id before funds go to a project nobody controls. Needs `publicClient`. Pass false to fund a project its\n * owner has not claimed yet (deposits are credited and become spendable after the claim and configuration).\n */\n requireClaimed?: boolean;\n publicClient?: Pick<PublicClient, \"readContract\">;\n}\n\n/**\n * Deposit native PEPU into a project with the caller's wallet. ONE-WAY: nobody can withdraw it afterwards, and\n * anyone may deposit into any project. By default it first confirms the project is claimed.\n *\n * @example\n * ```ts\n * const hash = await depositFor({ walletClient, publicClient, appId, amountWei: 10n ** 18n, paymaster });\n * ```\n */\nexport async function depositFor(params: DepositForParams): Promise<Hash> {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"depositFor needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const tx = encodeDeposit(projectId, params.amountWei, { paymaster: params.paymaster });\n if (params.requireClaimed ?? true) {\n if (!params.publicClient) {\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"depositFor checks the project is claimed by default and needs a publicClient. Pass publicClient, or requireClaimed: false to fund an unclaimed project.\",\n );\n }\n const state = await readProject(params.publicClient, projectId, { paymaster: params.paymaster });\n if (!state.claimed) {\n throw new PepuPaymasterError(\n \"PAYMASTER_PROJECT_NOT_CLAIMED\",\n \"Refusing to deposit: the project is not claimed. Check the app id spelling (it is case-sensitive), or pass requireClaimed: false. Deposits cannot be withdrawn.\",\n { details: { projectId } },\n );\n }\n }\n const [hash] = await sendPaymasterCalls(params.walletClient, [tx]);\n return hash as Hash;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/paymaster/onchain.ts"],"names":["isAddress","PepuConfigError","getAddress","getContract","pepuMainnet","PepuPaymasterError","keccak256","stringToBytes","isHex","pepuSponsoredPaymasterV2Abi","encodeFunctionData"],"mappings":";;;;;;;;;;AA2BA,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,oBAAA,GAAuB,EAAA;AAkCtB,SAAS,0BAA0B,QAAA,EAA6B;AACrE,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,IA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,GAAK,cAAc,SAAA,EAAW,MAAA,CAAO,WAAW,EAAE,SAAA,EAAW,MAAA,CAAO,SAAA,EAAW,CAAA;AACrF,EAAA,IAAI,MAAA,CAAO,kBAAkB,IAAA,EAAM;AACjC,IAAA,IAAI,CAAC,OAAO,YAAA,EAAc;AACxB,MAAA,MAAM,IAAIJ,iCAAA;AAAA,QACR,oBAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AACA,IAAA,MAAM,KAAA,GAAQ,MAAM,WAAA,CAAY,MAAA,CAAO,YAAA,EAAc,WAAW,EAAE,SAAA,EAAW,MAAA,CAAO,SAAA,EAAW,CAAA;AAC/F,IAAA,IAAI,CAAC,MAAM,OAAA,EAAS;AAClB,MAAA,MAAM,IAAII,oCAAA;AAAA,QACR,+BAAA;AAAA,QACA,iKAAA;AAAA,QACA,EAAE,OAAA,EAAS,EAAE,SAAA,EAAU;AAAE,OAC3B;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,CAAC,IAAI,CAAA,GAAI,MAAM,mBAAmB,MAAA,CAAO,YAAA,EAAc,CAAC,EAAE,CAAC,CAAA;AACjE,EAAA,OAAO,IAAA;AACT","file":"paymaster.cjs","sourcesContent":["import { encodeFunctionData, getAddress, isAddress, isHex, keccak256, stringToBytes } from \"viem\";\nimport type { Account, Address, Chain, Hash, Hex, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getContract } from \"../contracts.js\";\nimport { PepuConfigError, PepuPaymasterError } from \"../errors.js\";\nimport { pepuSponsoredPaymasterV2Abi } from \"./abi.js\";\n\n/**\n * v2 (tiered, deposit-only) paymaster on-chain helpers.\n *\n * Facts these helpers encode (services/paymaster/SPONSORSHIP-SPEC.md):\n * - `projectId = keccak256(bytes(appId))`, case-sensitive.\n * - Deposits are one-way. Nobody can withdraw, owner or not. Anyone can `depositFor` any project.\n * - `claimProject` sets ONLY the owner. Nothing is sponsorable until the owner calls `setTargets`,\n * `setDailyLimit` and `setSenderDailyLimit` (see {@link configureProject}). A project with no per-wallet\n * limit (`setSenderDailyLimit`) is rejected on-chain.\n * - The first claim of a project that ALREADY HOLDS deposited funds is pending for the admin change delay (>= 48h):\n * finish it with {@link encodeExecuteReclaim}. An empty project is claimed immediately.\n * - A re-claim of an owned project is timelocked (>= 48h) and the owner can cancel it once per new owner.\n * - Ownership transfer is two-step (propose, then accept).\n *\n * The contract address comes from the registry (`paymasterV2`, the deployed canary: internally reviewed 3x,\n * external audit pending). Every helper takes an explicit `paymaster` address and throws CONFIG_MISSING_ENV when there is none.\n * No transaction is ever sent without the caller's wallet client.\n */\n\nconst U112_MAX = (1n << 112n) - 1n;\nconst U128_MAX = (1n << 128n) - 1n;\nconst MAX_TARGETS_PER_CALL = 50;\n\n/** A transaction a wallet (or smart account batch) can send. */\nexport interface PaymasterCall {\n to: Address;\n data: Hex;\n value: bigint;\n /** Solidity signature, for logs and UIs. */\n function: string;\n}\n\n/** The EIP-712 `ProjectClaim` attestation returned by `POST /v2/projects/verify`. */\nexport interface ProjectClaimAttestation {\n appId: string;\n newOwner: Address;\n nonce: string | bigint;\n deadline: string | bigint;\n signature: Hex;\n}\n\nexport interface PaymasterAddressOption {\n /** v2 paymaster address. Defaults to the registry's `paymasterV2` entry once it is deployed. */\n paymaster?: Address | undefined;\n}\n\n/**\n * Resolve the v2 paymaster address: explicit option first, then the registry. Throws\n * `CONFIG_MISSING_ENV` (never guesses an address) when neither is available.\n *\n * @example\n * ```ts\n * const paymaster = resolvePaymasterV2Address(\"0x1111111111111111111111111111111111111111\");\n * ```\n */\nexport function resolvePaymasterV2Address(explicit?: Address): Address {\n if (explicit !== undefined) {\n if (!isAddress(explicit, { strict: false })) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The v2 paymaster address passed in is not a valid address.\");\n }\n return getAddress(explicit);\n }\n const entry = getContract(pepuMainnet.id, \"paymasterV2\");\n if (entry?.status === \"deployed\") return entry.address;\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"No v2 paymaster address is configured: the registry's paymasterV2 entry is not deployed. Pass the deployed address explicitly as `paymaster` (GET /v2/contract on the policy service returns it). Never guess one.\",\n );\n}\n\n/**\n * `projectId = keccak256(bytes(appId))`. The app id is used exactly as given, so it is case-sensitive:\n * Privy app ids are lower-case cuids, and a different case is a different project.\n *\n * @example\n * ```ts\n * const projectId = computeProjectId(\"clx0example0app0id\");\n * ```\n */\nexport function computeProjectId(appId: string): Hex {\n if (typeof appId !== \"string\" || appId.length === 0 || appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"appId must be a non-empty string of at most 128 characters.\");\n }\n return keccak256(stringToBytes(appId));\n}\n\n/** Plan name for {@link computeProjectId}. */\nexport const getProjectId = computeProjectId;\n\nfunction assertProjectId(projectId: Hex): Hex {\n if (!isHex(projectId, { strict: true }) || projectId.length !== 66) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"projectId must be a 0x-prefixed 32-byte hex string.\");\n }\n return projectId;\n}\n\nfunction amount(label: string, v: bigint, max: bigint): bigint {\n if (typeof v !== \"bigint\" || v <= 0n || v > max) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `${label} must be a bigint greater than 0 and within range.`);\n }\n return v;\n}\n\nfunction call(to: Address, data: Hex, fn: string, value = 0n): PaymasterCall {\n return { to, data, value, function: fn };\n}\n\n/** State of a project, read from the paymaster contract. */\nexport interface ProjectState {\n projectId: Hex;\n paymaster: Address;\n /** `null` when unclaimed. */\n owner: Address | null;\n claimed: boolean;\n paused: boolean;\n /** Deposited, unspent wei. Deposit-only: this can only be spent as gas, never withdrawn. */\n balance: bigint;\n dailyLimit: bigint;\n senderDailyLimit: bigint;\n /** Spent in the current UTC day (0 when the stored day is stale). */\n spentToday: bigint;\n /** Day index (unix seconds / 86400) the stored `spentToday` belongs to. */\n spentDay: number;\n /** True when claimed and both limits are set. Targets are checked via `targetsAllowed`. */\n limitsConfigured: boolean;\n /**\n * Pending timelocked claim, or `null`: a re-claim of an owned project, or (when `claimed` is false) the first\n * claim of a project that already holds funds. Finish it with {@link encodeExecuteReclaim} after `executableAt`.\n */\n pendingReclaim: { newOwner: Address; executableAt: number; signer: Address } | null;\n /** Address proposed in a two-step ownership transfer, or `null`. */\n pendingOwner: Address | null;\n /** Present when `checkTargets` was passed: allowed flag per address (checksummed keys). */\n targetsAllowed?: Record<Address, boolean>;\n}\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nexport interface ReadProjectOptions extends PaymasterAddressOption {\n /** Also check these destinations against the on-chain allowlist (one `isTargetAllowed` read each). */\n checkTargets?: readonly Address[];\n /** Clock override for the day rollover (tests). Milliseconds. */\n now?: () => number;\n}\n\n/**\n * Read a project's on-chain state: owner, pause flag, balance, limits, pending re-claim and pending owner.\n *\n * @example\n * ```ts\n * const p = await readProject(publicClient, computeProjectId(appId), { paymaster });\n * if (!p.claimed) console.log(\"claim it first\");\n * ```\n */\nexport async function readProject(\n client: Pick<PublicClient, \"readContract\">,\n projectId: Hex,\n options: ReadProjectOptions = {},\n): Promise<ProjectState> {\n const paymaster = resolvePaymasterV2Address(options.paymaster);\n const id = assertProjectId(projectId);\n const abi = pepuSponsoredPaymasterV2Abi;\n const [project, reclaim, pendingOwner] = await Promise.all([\n client.readContract({ address: paymaster, abi, functionName: \"getProject\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingReclaim\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingProjectOwner\", args: [id] }),\n ]);\n const [owner, paused, senderDailyLimit, balance, dailyLimit, spentToday, spentDay] = project;\n const [reclaimOwner, executableAt, reclaimSigner] = reclaim;\n const claimed = owner !== ZERO;\n const today = Math.floor((options.now ?? Date.now)() / 1000 / 86_400);\n\n let targetsAllowed: Record<Address, boolean> | undefined;\n if (options.checkTargets && options.checkTargets.length > 0) {\n const entries = await Promise.all(\n options.checkTargets.map(async (t) => {\n const allowed = await client.readContract({\n address: paymaster,\n abi,\n functionName: \"isTargetAllowed\",\n args: [id, t],\n });\n return [getAddress(t), allowed] as const;\n }),\n );\n targetsAllowed = Object.fromEntries(entries) as Record<Address, boolean>;\n }\n\n return {\n projectId: id,\n paymaster,\n owner: claimed ? getAddress(owner) : null,\n claimed,\n paused,\n balance,\n dailyLimit,\n senderDailyLimit,\n spentToday: spentDay === today ? spentToday : 0n,\n spentDay,\n limitsConfigured: claimed && dailyLimit > 0n && senderDailyLimit > 0n,\n pendingReclaim:\n reclaimOwner !== ZERO ? { newOwner: getAddress(reclaimOwner), executableAt, signer: getAddress(reclaimSigner) } : null,\n pendingOwner: pendingOwner !== ZERO ? getAddress(pendingOwner) : null,\n ...(targetsAllowed ? { targetsAllowed } : {}),\n };\n}\n\n/**\n * Encode `depositFor(projectId)` with native PEPU as `value`. ONE-WAY: nothing can ever withdraw the deposit,\n * and the id is `keccak256` of a case-sensitive app id, so a typo deposits into a project nobody can claim.\n * Prefer {@link depositFor}, which checks the project is claimed first.\n *\n * @example\n * ```ts\n * const tx = encodeDeposit(computeProjectId(appId), 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeDeposit(projectId: Hex, amountWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"depositFor\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"depositFor(bytes32)\", amount(\"amountWei\", amountWei, U128_MAX));\n}\n\nfunction claimArgs(a: ProjectClaimAttestation) {\n if (!a.appId || a.appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.appId must be 1 to 128 characters.\");\n }\n if (!isAddress(a.newOwner, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.newOwner is not a valid address.\");\n }\n if (!isHex(a.signature)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.signature must be 0x-prefixed hex.\");\n }\n return {\n appId: a.appId,\n newOwner: getAddress(a.newOwner),\n nonce: BigInt(a.nonce),\n deadline: BigInt(a.deadline),\n signature: a.signature,\n };\n}\n\n/**\n * Encode `claimProject(Claim)`. The attestation fixes the owner; anyone may submit the transaction. The claim\n * sets ONLY the owner: follow with {@link configureProject}'s three calls, because nothing is sponsorable\n * until `setTargets`, `setDailyLimit` and `setSenderDailyLimit` have run. If the project already holds deposited\n * funds the claim is PENDING for the on-chain admin change delay (>= 48h): the contract owner or manager can cancel\n * it, and anyone finishes it with {@link encodeExecuteReclaim}.\n *\n * @example\n * ```ts\n * const tx = encodeClaimProject(attestation, { paymaster });\n * await walletClient.sendTransaction({ to: tx.to, data: tx.data });\n * ```\n */\nexport function encodeClaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"claimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"claimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Encode `reclaimProject(Claim)`: a timelocked (>= 48h) re-claim of an already-owned project. The current owner\n * can cancel it ({@link encodeCancelReclaim}); anyone can finish it after the delay ({@link encodeExecuteReclaim}).\n *\n * @example\n * ```ts\n * const tx = encodeReclaimProject(attestation, { paymaster });\n * ```\n */\nexport function encodeReclaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"reclaimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"reclaimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Pick `claimProject` or `reclaimProject` from a `/v2/projects/verify` result (its `action` field) and encode it.\n *\n * @example\n * ```ts\n * const tx = encodeClaimFromVerification(verified, { paymaster });\n * ```\n */\nexport function encodeClaimFromVerification(\n verified: { action: \"claimProject\" | \"reclaimProject\"; attestation: ProjectClaimAttestation },\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n return verified.action === \"reclaimProject\"\n ? encodeReclaimProject(verified.attestation, options)\n : encodeClaimProject(verified.attestation, options);\n}\n\n/**\n * Encode `executeReclaim(projectId)`: completes a pending claim or re-claim once its delay has passed (and before it\n * expires, 30 days later).\n *\n * @example\n * ```ts\n * const tx = encodeExecuteReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeExecuteReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"executeReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"executeReclaim(bytes32)\");\n}\n\n/**\n * Encode `cancelReclaim(projectId)`: the current owner cancels a pending re-claim, ONCE per new owner (a second\n * attested re-claim by the same new owner cannot be cancelled). For a pending FIRST claim of an unowned project the\n * contract owner or manager cancels instead.\n *\n * @example\n * ```ts\n * const tx = encodeCancelReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeCancelReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"cancelReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"cancelReclaim(bytes32)\");\n}\n\n/**\n * Encode `setTargets(projectId, targets, allowed)`: add or remove destination contracts the project sponsors\n * (at most 50 per call). Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetTargets(projectId, [counter], true, { paymaster });\n * ```\n */\nexport function encodeSetTargets(\n projectId: Hex,\n targets: readonly Address[],\n allowed: boolean,\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (targets.length === 0 || targets.length > MAX_TARGETS_PER_CALL) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `targets must contain 1 to ${MAX_TARGETS_PER_CALL} addresses per call.`);\n }\n for (const t of targets) {\n if (!isAddress(t, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"targets contains an invalid address.\");\n }\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setTargets\",\n args: [assertProjectId(projectId), targets.map((t) => getAddress(t)), allowed],\n });\n return call(to, data, \"setTargets(bytes32,address[],bool)\");\n}\n\n/**\n * Encode `setDailyLimit(projectId, limitWei)`: the project's total daily gas budget. Owner only. Must be above\n * zero; a contract-side zero limit means nothing can be spent, and tightening is instant.\n *\n * @example\n * ```ts\n * const tx = encodeSetDailyLimit(projectId, 5n * 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeSetDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setSenderDailyLimit(projectId, limitWei)`: the per-wallet daily gas limit. Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetSenderDailyLimit(projectId, 10n ** 17n, { paymaster });\n * ```\n */\nexport function encodeSetSenderDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setSenderDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setSenderDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setPaused(projectId, paused)`. Pausing takes effect immediately; it is the project's emergency stop.\n *\n * @example\n * ```ts\n * const stop = encodeSetPaused(projectId, true, { paymaster });\n * ```\n */\nexport function encodeSetPaused(projectId: Hex, paused: boolean, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setPaused\",\n args: [assertProjectId(projectId), paused],\n });\n return call(to, data, \"setPaused(bytes32,bool)\");\n}\n\n/**\n * Encode `proposeProjectOwner(projectId, newOwner)`: step one of the two-step ownership transfer. The new\n * owner must then call {@link encodeAcceptProjectOwnership}.\n *\n * @example\n * ```ts\n * const tx = encodeProposeProjectOwner(projectId, newOwner, { paymaster });\n * ```\n */\nexport function encodeProposeProjectOwner(projectId: Hex, newOwner: Address, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (!isAddress(newOwner, { strict: false }) || newOwner === ZERO) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"newOwner must be a non-zero valid address.\");\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"proposeProjectOwner\",\n args: [assertProjectId(projectId), getAddress(newOwner)],\n });\n return call(to, data, \"proposeProjectOwner(bytes32,address)\");\n}\n\n/**\n * Encode `acceptProjectOwnership(projectId)`: step two of the ownership transfer, sent by the proposed owner.\n *\n * @example\n * ```ts\n * const tx = encodeAcceptProjectOwnership(projectId, { paymaster });\n * ```\n */\nexport function encodeAcceptProjectOwnership(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"acceptProjectOwnership\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"acceptProjectOwnership(bytes32)\");\n}\n\nexport interface ConfigureProjectParams extends PaymasterAddressOption {\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n /** Destination contracts to sponsor (the on-chain allowlist). 1 to 50. */\n targets: readonly Address[];\n /** Total daily budget, wei. */\n dailyLimitWei: bigint;\n /** Per-wallet daily budget, wei. */\n senderDailyLimitWei: bigint;\n}\n\n/**\n * The three post-claim configuration calls, in order: `setTargets(allowed = true)`, `setDailyLimit`,\n * `setSenderDailyLimit`. A project spends nothing until all three have run. All three are owner-only calls to\n * the same contract, so a smart account or batched wallet can send them in one transaction; an EOA sends them\n * one after another with {@link sendPaymasterCalls}.\n *\n * @example\n * ```ts\n * const { calls } = configureProject({\n * appId, paymaster,\n * targets: [counter],\n * dailyLimitWei: 5n * 10n ** 18n,\n * senderDailyLimitWei: 10n ** 17n,\n * });\n * await smartAccountClient.sendUserOperation({ calls: calls.map(({ to, data, value }) => ({ to, data, value })) });\n * ```\n */\nexport function configureProject(params: ConfigureProjectParams): { projectId: Hex; calls: PaymasterCall[] } {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"configureProject needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const o = { paymaster: params.paymaster };\n return {\n projectId,\n calls: [\n encodeSetTargets(projectId, params.targets, true, o),\n encodeSetDailyLimit(projectId, params.dailyLimitWei, o),\n encodeSetSenderDailyLimit(projectId, params.senderDailyLimitWei, o),\n ],\n };\n}\n\ntype SendingWallet = Pick<WalletClient, \"sendTransaction\"> & { account?: Account | undefined; chain?: Chain | undefined };\n\n/**\n * Send prepared calls one after another from a wallet client, returning the hashes. When `publicClient` is\n * given it waits for each receipt first (so a later call is not sent after an earlier one failed). The\n * transaction `value` is exactly the call's value; nothing else is added.\n *\n * @example\n * ```ts\n * const hashes = await sendPaymasterCalls(walletClient, calls, { publicClient });\n * ```\n */\nexport async function sendPaymasterCalls(\n walletClient: SendingWallet,\n calls: readonly PaymasterCall[],\n options: { publicClient?: Pick<PublicClient, \"waitForTransactionReceipt\"> } = {},\n): Promise<Hash[]> {\n const account = walletClient.account;\n if (!account) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The wallet client has no account; create it with an account.\");\n }\n const chain = walletClient.chain ?? pepuMainnet;\n const hashes: Hash[] = [];\n for (const c of calls) {\n const hash = await walletClient.sendTransaction({ account, chain, to: c.to, data: c.data, value: c.value });\n hashes.push(hash);\n if (options.publicClient) {\n const receipt = await options.publicClient.waitForTransactionReceipt({ hash });\n if (receipt.status !== \"success\") {\n throw new PepuPaymasterError(\"TX_REVERTED\", `Paymaster call ${c.function} reverted (transaction ${hash}).`, {\n details: { hash, function: c.function },\n });\n }\n }\n }\n return hashes;\n}\n\nexport interface DepositForParams extends PaymasterAddressOption {\n walletClient: SendingWallet;\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n amountWei: bigint;\n /**\n * Default true: read the project first and refuse when it has no owner, which catches a mistyped (case-sensitive)\n * app id before funds go to a project nobody controls. Needs `publicClient`. Pass false to fund a project its\n * owner has not claimed yet (deposits are credited and become spendable after the claim and configuration).\n */\n requireClaimed?: boolean;\n publicClient?: Pick<PublicClient, \"readContract\">;\n}\n\n/**\n * Deposit native PEPU into a project with the caller's wallet. ONE-WAY: nobody can withdraw it afterwards, and\n * anyone may deposit into any project. By default it first confirms the project is claimed.\n *\n * @example\n * ```ts\n * const hash = await depositFor({ walletClient, publicClient, appId, amountWei: 10n ** 18n, paymaster });\n * ```\n */\nexport async function depositFor(params: DepositForParams): Promise<Hash> {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"depositFor needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const tx = encodeDeposit(projectId, params.amountWei, { paymaster: params.paymaster });\n if (params.requireClaimed ?? true) {\n if (!params.publicClient) {\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"depositFor checks the project is claimed by default and needs a publicClient. Pass publicClient, or requireClaimed: false to fund an unclaimed project.\",\n );\n }\n const state = await readProject(params.publicClient, projectId, { paymaster: params.paymaster });\n if (!state.claimed) {\n throw new PepuPaymasterError(\n \"PAYMASTER_PROJECT_NOT_CLAIMED\",\n \"Refusing to deposit: the project is not claimed. Check the app id spelling (it is case-sensitive), or pass requireClaimed: false. Deposits cannot be withdrawn.\",\n { details: { projectId } },\n );\n }\n }\n const [hash] = await sendPaymasterCalls(params.walletClient, [tx]);\n return hash as Hash;\n}\n"]}
|
package/dist/paymaster.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
export { assertApproved, buildErc7677Url, createPaymasterApi, credentialKind, hostedErc7677Url, serializeAttestation } from './chunk-RSPAN44L.js';
|
|
2
|
+
import { getContract } from './chunk-KJYNF5KH.js';
|
|
3
|
+
import { pepuSponsoredPaymasterV2Abi } from './chunk-GIZNH65Q.js';
|
|
4
|
+
export { PAYMASTER_DENIAL_REASONS, PAYMASTER_REASON_CODES, decodePaymasterRevert, mapPaymasterReason, paymasterReasonToError, pepuSponsoredPaymasterV2Abi } from './chunk-GIZNH65Q.js';
|
|
4
5
|
import './chunk-XC4IBCI2.js';
|
|
5
6
|
import { pepuMainnet } from './chunk-VTQIHMF3.js';
|
|
6
7
|
import { PepuConfigError, PepuPaymasterError } from './chunk-6DSZ4Z2N.js';
|
package/dist/paymaster.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/paymaster/onchain.ts"],"names":[],"mappings":";;;;;;;;AA2BA,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,oBAAA,GAAuB,EAAA;AAkCtB,SAAS,0BAA0B,QAAA,EAA6B;AACrE,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,IAAI,CAAC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,CAAA;AACrF,EAAA,IAAI,MAAA,CAAO,kBAAkB,IAAA,EAAM;AACjC,IAAA,IAAI,CAAC,OAAO,YAAA,EAAc;AACxB,MAAA,MAAM,IAAI,eAAA;AAAA,QACR,oBAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AACA,IAAA,MAAM,KAAA,GAAQ,MAAM,WAAA,CAAY,MAAA,CAAO,YAAA,EAAc,WAAW,EAAE,SAAA,EAAW,MAAA,CAAO,SAAA,EAAW,CAAA;AAC/F,IAAA,IAAI,CAAC,MAAM,OAAA,EAAS;AAClB,MAAA,MAAM,IAAI,kBAAA;AAAA,QACR,+BAAA;AAAA,QACA,iKAAA;AAAA,QACA,EAAE,OAAA,EAAS,EAAE,SAAA,EAAU;AAAE,OAC3B;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,CAAC,IAAI,CAAA,GAAI,MAAM,mBAAmB,MAAA,CAAO,YAAA,EAAc,CAAC,EAAE,CAAC,CAAA;AACjE,EAAA,OAAO,IAAA;AACT","file":"paymaster.js","sourcesContent":["import { encodeFunctionData, getAddress, isAddress, isHex, keccak256, stringToBytes } from \"viem\";\nimport type { Account, Address, Chain, Hash, Hex, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getContract } from \"../contracts.js\";\nimport { PepuConfigError, PepuPaymasterError } from \"../errors.js\";\nimport { pepuSponsoredPaymasterV2Abi } from \"./abi.js\";\n\n/**\n * v2 (tiered, deposit-only) paymaster on-chain helpers.\n *\n * Facts these helpers encode (services/paymaster/SPONSORSHIP-SPEC.md):\n * - `projectId = keccak256(bytes(appId))`, case-sensitive.\n * - Deposits are one-way. Nobody can withdraw, owner or not. Anyone can `depositFor` any project.\n * - `claimProject` sets ONLY the owner. Nothing is sponsorable until the owner calls `setTargets`,\n * `setDailyLimit` and `setSenderDailyLimit` (see {@link configureProject}). A project with no per-wallet\n * limit (`setSenderDailyLimit`) is rejected on-chain.\n * - The first claim of a project that ALREADY HOLDS deposited funds is pending for the admin change delay (>= 48h):\n * finish it with {@link encodeExecuteReclaim}. An empty project is claimed immediately.\n * - A re-claim of an owned project is timelocked (>= 48h) and the owner can cancel it once per new owner.\n * - Ownership transfer is two-step (propose, then accept).\n *\n * The contract address comes from the registry (`paymasterV2`, the deployed canary: internally reviewed 3x,\n * external audit pending). Every helper takes an explicit `paymaster` address and throws CONFIG_MISSING_ENV when there is none.\n * No transaction is ever sent without the caller's wallet client.\n */\n\nconst U112_MAX = (1n << 112n) - 1n;\nconst U128_MAX = (1n << 128n) - 1n;\nconst MAX_TARGETS_PER_CALL = 50;\n\n/** A transaction a wallet (or smart account batch) can send. */\nexport interface PaymasterCall {\n to: Address;\n data: Hex;\n value: bigint;\n /** Solidity signature, for logs and UIs. */\n function: string;\n}\n\n/** The EIP-712 `ProjectClaim` attestation returned by `POST /v2/projects/verify`. */\nexport interface ProjectClaimAttestation {\n appId: string;\n newOwner: Address;\n nonce: string | bigint;\n deadline: string | bigint;\n signature: Hex;\n}\n\nexport interface PaymasterAddressOption {\n /** v2 paymaster address. Defaults to the registry's `paymasterV2` entry once it is deployed. */\n paymaster?: Address | undefined;\n}\n\n/**\n * Resolve the v2 paymaster address: explicit option first, then the registry. Throws\n * `CONFIG_MISSING_ENV` (never guesses an address) when neither is available.\n *\n * @example\n * ```ts\n * const paymaster = resolvePaymasterV2Address(\"0x1111111111111111111111111111111111111111\");\n * ```\n */\nexport function resolvePaymasterV2Address(explicit?: Address): Address {\n if (explicit !== undefined) {\n if (!isAddress(explicit, { strict: false })) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The v2 paymaster address passed in is not a valid address.\");\n }\n return getAddress(explicit);\n }\n const entry = getContract(pepuMainnet.id, \"paymasterV2\");\n if (entry?.status === \"deployed\") return entry.address;\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"No v2 paymaster address is configured: the registry's paymasterV2 entry is not deployed. Pass the deployed address explicitly as `paymaster` (GET /v2/contract on the policy service returns it). Never guess one.\",\n );\n}\n\n/**\n * `projectId = keccak256(bytes(appId))`. The app id is used exactly as given, so it is case-sensitive:\n * Privy app ids are lower-case cuids, and a different case is a different project.\n *\n * @example\n * ```ts\n * const projectId = computeProjectId(\"clx0example0app0id\");\n * ```\n */\nexport function computeProjectId(appId: string): Hex {\n if (typeof appId !== \"string\" || appId.length === 0 || appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"appId must be a non-empty string of at most 128 characters.\");\n }\n return keccak256(stringToBytes(appId));\n}\n\n/** Plan name for {@link computeProjectId}. */\nexport const getProjectId = computeProjectId;\n\nfunction assertProjectId(projectId: Hex): Hex {\n if (!isHex(projectId, { strict: true }) || projectId.length !== 66) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"projectId must be a 0x-prefixed 32-byte hex string.\");\n }\n return projectId;\n}\n\nfunction amount(label: string, v: bigint, max: bigint): bigint {\n if (typeof v !== \"bigint\" || v <= 0n || v > max) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `${label} must be a bigint greater than 0 and within range.`);\n }\n return v;\n}\n\nfunction call(to: Address, data: Hex, fn: string, value = 0n): PaymasterCall {\n return { to, data, value, function: fn };\n}\n\n/** State of a project, read from the paymaster contract. */\nexport interface ProjectState {\n projectId: Hex;\n paymaster: Address;\n /** `null` when unclaimed. */\n owner: Address | null;\n claimed: boolean;\n paused: boolean;\n /** Deposited, unspent wei. Deposit-only: this can only be spent as gas, never withdrawn. */\n balance: bigint;\n dailyLimit: bigint;\n senderDailyLimit: bigint;\n /** Spent in the current UTC day (0 when the stored day is stale). */\n spentToday: bigint;\n /** Day index (unix seconds / 86400) the stored `spentToday` belongs to. */\n spentDay: number;\n /** True when claimed and both limits are set. Targets are checked via `targetsAllowed`. */\n limitsConfigured: boolean;\n /**\n * Pending timelocked claim, or `null`: a re-claim of an owned project, or (when `claimed` is false) the first\n * claim of a project that already holds funds. Finish it with {@link encodeExecuteReclaim} after `executableAt`.\n */\n pendingReclaim: { newOwner: Address; executableAt: number; signer: Address } | null;\n /** Address proposed in a two-step ownership transfer, or `null`. */\n pendingOwner: Address | null;\n /** Present when `checkTargets` was passed: allowed flag per address (checksummed keys). */\n targetsAllowed?: Record<Address, boolean>;\n}\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nexport interface ReadProjectOptions extends PaymasterAddressOption {\n /** Also check these destinations against the on-chain allowlist (one `isTargetAllowed` read each). */\n checkTargets?: readonly Address[];\n /** Clock override for the day rollover (tests). Milliseconds. */\n now?: () => number;\n}\n\n/**\n * Read a project's on-chain state: owner, pause flag, balance, limits, pending re-claim and pending owner.\n *\n * @example\n * ```ts\n * const p = await readProject(publicClient, computeProjectId(appId), { paymaster });\n * if (!p.claimed) console.log(\"claim it first\");\n * ```\n */\nexport async function readProject(\n client: Pick<PublicClient, \"readContract\">,\n projectId: Hex,\n options: ReadProjectOptions = {},\n): Promise<ProjectState> {\n const paymaster = resolvePaymasterV2Address(options.paymaster);\n const id = assertProjectId(projectId);\n const abi = pepuSponsoredPaymasterV2Abi;\n const [project, reclaim, pendingOwner] = await Promise.all([\n client.readContract({ address: paymaster, abi, functionName: \"getProject\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingReclaim\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingProjectOwner\", args: [id] }),\n ]);\n const [owner, paused, senderDailyLimit, balance, dailyLimit, spentToday, spentDay] = project;\n const [reclaimOwner, executableAt, reclaimSigner] = reclaim;\n const claimed = owner !== ZERO;\n const today = Math.floor((options.now ?? Date.now)() / 1000 / 86_400);\n\n let targetsAllowed: Record<Address, boolean> | undefined;\n if (options.checkTargets && options.checkTargets.length > 0) {\n const entries = await Promise.all(\n options.checkTargets.map(async (t) => {\n const allowed = await client.readContract({\n address: paymaster,\n abi,\n functionName: \"isTargetAllowed\",\n args: [id, t],\n });\n return [getAddress(t), allowed] as const;\n }),\n );\n targetsAllowed = Object.fromEntries(entries) as Record<Address, boolean>;\n }\n\n return {\n projectId: id,\n paymaster,\n owner: claimed ? getAddress(owner) : null,\n claimed,\n paused,\n balance,\n dailyLimit,\n senderDailyLimit,\n spentToday: spentDay === today ? spentToday : 0n,\n spentDay,\n limitsConfigured: claimed && dailyLimit > 0n && senderDailyLimit > 0n,\n pendingReclaim:\n reclaimOwner !== ZERO ? { newOwner: getAddress(reclaimOwner), executableAt, signer: getAddress(reclaimSigner) } : null,\n pendingOwner: pendingOwner !== ZERO ? getAddress(pendingOwner) : null,\n ...(targetsAllowed ? { targetsAllowed } : {}),\n };\n}\n\n/**\n * Encode `depositFor(projectId)` with native PEPU as `value`. ONE-WAY: nothing can ever withdraw the deposit,\n * and the id is `keccak256` of a case-sensitive app id, so a typo deposits into a project nobody can claim.\n * Prefer {@link depositFor}, which checks the project is claimed first.\n *\n * @example\n * ```ts\n * const tx = encodeDeposit(computeProjectId(appId), 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeDeposit(projectId: Hex, amountWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"depositFor\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"depositFor(bytes32)\", amount(\"amountWei\", amountWei, U128_MAX));\n}\n\nfunction claimArgs(a: ProjectClaimAttestation) {\n if (!a.appId || a.appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.appId must be 1 to 128 characters.\");\n }\n if (!isAddress(a.newOwner, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.newOwner is not a valid address.\");\n }\n if (!isHex(a.signature)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.signature must be 0x-prefixed hex.\");\n }\n return {\n appId: a.appId,\n newOwner: getAddress(a.newOwner),\n nonce: BigInt(a.nonce),\n deadline: BigInt(a.deadline),\n signature: a.signature,\n };\n}\n\n/**\n * Encode `claimProject(Claim)`. The attestation fixes the owner; anyone may submit the transaction. The claim\n * sets ONLY the owner: follow with {@link configureProject}'s three calls, because nothing is sponsorable\n * until `setTargets`, `setDailyLimit` and `setSenderDailyLimit` have run. If the project already holds deposited\n * funds the claim is PENDING for the on-chain admin change delay (>= 48h): the contract owner or manager can cancel\n * it, and anyone finishes it with {@link encodeExecuteReclaim}.\n *\n * @example\n * ```ts\n * const tx = encodeClaimProject(attestation, { paymaster });\n * await walletClient.sendTransaction({ to: tx.to, data: tx.data });\n * ```\n */\nexport function encodeClaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"claimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"claimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Encode `reclaimProject(Claim)`: a timelocked (>= 48h) re-claim of an already-owned project. The current owner\n * can cancel it ({@link encodeCancelReclaim}); anyone can finish it after the delay ({@link encodeExecuteReclaim}).\n *\n * @example\n * ```ts\n * const tx = encodeReclaimProject(attestation, { paymaster });\n * ```\n */\nexport function encodeReclaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"reclaimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"reclaimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Pick `claimProject` or `reclaimProject` from a `/v2/projects/verify` result (its `action` field) and encode it.\n *\n * @example\n * ```ts\n * const tx = encodeClaimFromVerification(verified, { paymaster });\n * ```\n */\nexport function encodeClaimFromVerification(\n verified: { action: \"claimProject\" | \"reclaimProject\"; attestation: ProjectClaimAttestation },\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n return verified.action === \"reclaimProject\"\n ? encodeReclaimProject(verified.attestation, options)\n : encodeClaimProject(verified.attestation, options);\n}\n\n/**\n * Encode `executeReclaim(projectId)`: completes a pending claim or re-claim once its delay has passed (and before it\n * expires, 30 days later).\n *\n * @example\n * ```ts\n * const tx = encodeExecuteReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeExecuteReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"executeReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"executeReclaim(bytes32)\");\n}\n\n/**\n * Encode `cancelReclaim(projectId)`: the current owner cancels a pending re-claim, ONCE per new owner (a second\n * attested re-claim by the same new owner cannot be cancelled). For a pending FIRST claim of an unowned project the\n * contract owner or manager cancels instead.\n *\n * @example\n * ```ts\n * const tx = encodeCancelReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeCancelReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"cancelReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"cancelReclaim(bytes32)\");\n}\n\n/**\n * Encode `setTargets(projectId, targets, allowed)`: add or remove destination contracts the project sponsors\n * (at most 50 per call). Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetTargets(projectId, [counter], true, { paymaster });\n * ```\n */\nexport function encodeSetTargets(\n projectId: Hex,\n targets: readonly Address[],\n allowed: boolean,\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (targets.length === 0 || targets.length > MAX_TARGETS_PER_CALL) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `targets must contain 1 to ${MAX_TARGETS_PER_CALL} addresses per call.`);\n }\n for (const t of targets) {\n if (!isAddress(t, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"targets contains an invalid address.\");\n }\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setTargets\",\n args: [assertProjectId(projectId), targets.map((t) => getAddress(t)), allowed],\n });\n return call(to, data, \"setTargets(bytes32,address[],bool)\");\n}\n\n/**\n * Encode `setDailyLimit(projectId, limitWei)`: the project's total daily gas budget. Owner only. Must be above\n * zero; a contract-side zero limit means nothing can be spent, and tightening is instant.\n *\n * @example\n * ```ts\n * const tx = encodeSetDailyLimit(projectId, 5n * 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeSetDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setSenderDailyLimit(projectId, limitWei)`: the per-wallet daily gas limit. Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetSenderDailyLimit(projectId, 10n ** 17n, { paymaster });\n * ```\n */\nexport function encodeSetSenderDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setSenderDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setSenderDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setPaused(projectId, paused)`. Pausing takes effect immediately; it is the project's emergency stop.\n *\n * @example\n * ```ts\n * const stop = encodeSetPaused(projectId, true, { paymaster });\n * ```\n */\nexport function encodeSetPaused(projectId: Hex, paused: boolean, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setPaused\",\n args: [assertProjectId(projectId), paused],\n });\n return call(to, data, \"setPaused(bytes32,bool)\");\n}\n\n/**\n * Encode `proposeProjectOwner(projectId, newOwner)`: step one of the two-step ownership transfer. The new\n * owner must then call {@link encodeAcceptProjectOwnership}.\n *\n * @example\n * ```ts\n * const tx = encodeProposeProjectOwner(projectId, newOwner, { paymaster });\n * ```\n */\nexport function encodeProposeProjectOwner(projectId: Hex, newOwner: Address, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (!isAddress(newOwner, { strict: false }) || newOwner === ZERO) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"newOwner must be a non-zero valid address.\");\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"proposeProjectOwner\",\n args: [assertProjectId(projectId), getAddress(newOwner)],\n });\n return call(to, data, \"proposeProjectOwner(bytes32,address)\");\n}\n\n/**\n * Encode `acceptProjectOwnership(projectId)`: step two of the ownership transfer, sent by the proposed owner.\n *\n * @example\n * ```ts\n * const tx = encodeAcceptProjectOwnership(projectId, { paymaster });\n * ```\n */\nexport function encodeAcceptProjectOwnership(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"acceptProjectOwnership\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"acceptProjectOwnership(bytes32)\");\n}\n\nexport interface ConfigureProjectParams extends PaymasterAddressOption {\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n /** Destination contracts to sponsor (the on-chain allowlist). 1 to 50. */\n targets: readonly Address[];\n /** Total daily budget, wei. */\n dailyLimitWei: bigint;\n /** Per-wallet daily budget, wei. */\n senderDailyLimitWei: bigint;\n}\n\n/**\n * The three post-claim configuration calls, in order: `setTargets(allowed = true)`, `setDailyLimit`,\n * `setSenderDailyLimit`. A project spends nothing until all three have run. All three are owner-only calls to\n * the same contract, so a smart account or batched wallet can send them in one transaction; an EOA sends them\n * one after another with {@link sendPaymasterCalls}.\n *\n * @example\n * ```ts\n * const { calls } = configureProject({\n * appId, paymaster,\n * targets: [counter],\n * dailyLimitWei: 5n * 10n ** 18n,\n * senderDailyLimitWei: 10n ** 17n,\n * });\n * await smartAccountClient.sendUserOperation({ calls: calls.map(({ to, data, value }) => ({ to, data, value })) });\n * ```\n */\nexport function configureProject(params: ConfigureProjectParams): { projectId: Hex; calls: PaymasterCall[] } {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"configureProject needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const o = { paymaster: params.paymaster };\n return {\n projectId,\n calls: [\n encodeSetTargets(projectId, params.targets, true, o),\n encodeSetDailyLimit(projectId, params.dailyLimitWei, o),\n encodeSetSenderDailyLimit(projectId, params.senderDailyLimitWei, o),\n ],\n };\n}\n\ntype SendingWallet = Pick<WalletClient, \"sendTransaction\"> & { account?: Account | undefined; chain?: Chain | undefined };\n\n/**\n * Send prepared calls one after another from a wallet client, returning the hashes. When `publicClient` is\n * given it waits for each receipt first (so a later call is not sent after an earlier one failed). The\n * transaction `value` is exactly the call's value; nothing else is added.\n *\n * @example\n * ```ts\n * const hashes = await sendPaymasterCalls(walletClient, calls, { publicClient });\n * ```\n */\nexport async function sendPaymasterCalls(\n walletClient: SendingWallet,\n calls: readonly PaymasterCall[],\n options: { publicClient?: Pick<PublicClient, \"waitForTransactionReceipt\"> } = {},\n): Promise<Hash[]> {\n const account = walletClient.account;\n if (!account) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The wallet client has no account; create it with an account.\");\n }\n const chain = walletClient.chain ?? pepuMainnet;\n const hashes: Hash[] = [];\n for (const c of calls) {\n const hash = await walletClient.sendTransaction({ account, chain, to: c.to, data: c.data, value: c.value });\n hashes.push(hash);\n if (options.publicClient) {\n const receipt = await options.publicClient.waitForTransactionReceipt({ hash });\n if (receipt.status !== \"success\") {\n throw new PepuPaymasterError(\"TX_REVERTED\", `Paymaster call ${c.function} reverted (transaction ${hash}).`, {\n details: { hash, function: c.function },\n });\n }\n }\n }\n return hashes;\n}\n\nexport interface DepositForParams extends PaymasterAddressOption {\n walletClient: SendingWallet;\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n amountWei: bigint;\n /**\n * Default true: read the project first and refuse when it has no owner, which catches a mistyped (case-sensitive)\n * app id before funds go to a project nobody controls. Needs `publicClient`. Pass false to fund a project its\n * owner has not claimed yet (deposits are credited and become spendable after the claim and configuration).\n */\n requireClaimed?: boolean;\n publicClient?: Pick<PublicClient, \"readContract\">;\n}\n\n/**\n * Deposit native PEPU into a project with the caller's wallet. ONE-WAY: nobody can withdraw it afterwards, and\n * anyone may deposit into any project. By default it first confirms the project is claimed.\n *\n * @example\n * ```ts\n * const hash = await depositFor({ walletClient, publicClient, appId, amountWei: 10n ** 18n, paymaster });\n * ```\n */\nexport async function depositFor(params: DepositForParams): Promise<Hash> {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"depositFor needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const tx = encodeDeposit(projectId, params.amountWei, { paymaster: params.paymaster });\n if (params.requireClaimed ?? true) {\n if (!params.publicClient) {\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"depositFor checks the project is claimed by default and needs a publicClient. Pass publicClient, or requireClaimed: false to fund an unclaimed project.\",\n );\n }\n const state = await readProject(params.publicClient, projectId, { paymaster: params.paymaster });\n if (!state.claimed) {\n throw new PepuPaymasterError(\n \"PAYMASTER_PROJECT_NOT_CLAIMED\",\n \"Refusing to deposit: the project is not claimed. Check the app id spelling (it is case-sensitive), or pass requireClaimed: false. Deposits cannot be withdrawn.\",\n { details: { projectId } },\n );\n }\n }\n const [hash] = await sendPaymasterCalls(params.walletClient, [tx]);\n return hash as Hash;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/paymaster/onchain.ts"],"names":[],"mappings":";;;;;;;;;AA2BA,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,QAAA,GAAA,CAAY,MAAM,IAAA,IAAQ,EAAA;AAChC,IAAM,oBAAA,GAAuB,EAAA;AAkCtB,SAAS,0BAA0B,QAAA,EAA6B;AACrE,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,IAAI,CAAC,SAAA,CAAU,QAAA,EAAU,EAAE,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAG;AAC3C,MAAA,MAAM,IAAI,eAAA,CAAgB,oBAAA,EAAsB,4DAA4D,CAAA;AAAA,IAC9G;AACA,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AACA,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,WAAA,CAAY,EAAA,EAAI,aAAa,CAAA;AACvD,EAAA,IAAI,KAAA,EAAO,MAAA,KAAW,UAAA,EAAY,OAAO,KAAA,CAAM,OAAA;AAC/C,EAAA,MAAM,IAAI,eAAA;AAAA,IACR,oBAAA;AAAA,IACA;AAAA,GACF;AACF;AAWO,SAAS,iBAAiB,KAAA,EAAoB;AACnD,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,WAAW,CAAA,IAAK,KAAA,CAAM,SAAS,GAAA,EAAK;AACzE,IAAA,MAAM,IAAI,kBAAA,CAAmB,kBAAA,EAAoB,6DAA6D,CAAA;AAAA,EAChH;AACA,EAAA,OAAO,SAAA,CAAU,aAAA,CAAc,KAAK,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Bytes } from \"viem\";\nimport type { Account, Address, Chain, Hash, Hex, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getContract } from \"../contracts.js\";\nimport { PepuConfigError, PepuPaymasterError } from \"../errors.js\";\nimport { pepuSponsoredPaymasterV2Abi } from \"./abi.js\";\n\n/**\n * v2 (tiered, deposit-only) paymaster on-chain helpers.\n *\n * Facts these helpers encode (services/paymaster/SPONSORSHIP-SPEC.md):\n * - `projectId = keccak256(bytes(appId))`, case-sensitive.\n * - Deposits are one-way. Nobody can withdraw, owner or not. Anyone can `depositFor` any project.\n * - `claimProject` sets ONLY the owner. Nothing is sponsorable until the owner calls `setTargets`,\n * `setDailyLimit` and `setSenderDailyLimit` (see {@link configureProject}). A project with no per-wallet\n * limit (`setSenderDailyLimit`) is rejected on-chain.\n * - The first claim of a project that ALREADY HOLDS deposited funds is pending for the admin change delay (>= 48h):\n * finish it with {@link encodeExecuteReclaim}. An empty project is claimed immediately.\n * - A re-claim of an owned project is timelocked (>= 48h) and the owner can cancel it once per new owner.\n * - Ownership transfer is two-step (propose, then accept).\n *\n * The contract address comes from the registry (`paymasterV2`, the deployed canary: internally reviewed 3x,\n * external audit pending). Every helper takes an explicit `paymaster` address and throws CONFIG_MISSING_ENV when there is none.\n * No transaction is ever sent without the caller's wallet client.\n */\n\nconst U112_MAX = (1n << 112n) - 1n;\nconst U128_MAX = (1n << 128n) - 1n;\nconst MAX_TARGETS_PER_CALL = 50;\n\n/** A transaction a wallet (or smart account batch) can send. */\nexport interface PaymasterCall {\n to: Address;\n data: Hex;\n value: bigint;\n /** Solidity signature, for logs and UIs. */\n function: string;\n}\n\n/** The EIP-712 `ProjectClaim` attestation returned by `POST /v2/projects/verify`. */\nexport interface ProjectClaimAttestation {\n appId: string;\n newOwner: Address;\n nonce: string | bigint;\n deadline: string | bigint;\n signature: Hex;\n}\n\nexport interface PaymasterAddressOption {\n /** v2 paymaster address. Defaults to the registry's `paymasterV2` entry once it is deployed. */\n paymaster?: Address | undefined;\n}\n\n/**\n * Resolve the v2 paymaster address: explicit option first, then the registry. Throws\n * `CONFIG_MISSING_ENV` (never guesses an address) when neither is available.\n *\n * @example\n * ```ts\n * const paymaster = resolvePaymasterV2Address(\"0x1111111111111111111111111111111111111111\");\n * ```\n */\nexport function resolvePaymasterV2Address(explicit?: Address): Address {\n if (explicit !== undefined) {\n if (!isAddress(explicit, { strict: false })) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The v2 paymaster address passed in is not a valid address.\");\n }\n return getAddress(explicit);\n }\n const entry = getContract(pepuMainnet.id, \"paymasterV2\");\n if (entry?.status === \"deployed\") return entry.address;\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"No v2 paymaster address is configured: the registry's paymasterV2 entry is not deployed. Pass the deployed address explicitly as `paymaster` (GET /v2/contract on the policy service returns it). Never guess one.\",\n );\n}\n\n/**\n * `projectId = keccak256(bytes(appId))`. The app id is used exactly as given, so it is case-sensitive:\n * Privy app ids are lower-case cuids, and a different case is a different project.\n *\n * @example\n * ```ts\n * const projectId = computeProjectId(\"clx0example0app0id\");\n * ```\n */\nexport function computeProjectId(appId: string): Hex {\n if (typeof appId !== \"string\" || appId.length === 0 || appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"appId must be a non-empty string of at most 128 characters.\");\n }\n return keccak256(stringToBytes(appId));\n}\n\n/** Plan name for {@link computeProjectId}. */\nexport const getProjectId = computeProjectId;\n\nfunction assertProjectId(projectId: Hex): Hex {\n if (!isHex(projectId, { strict: true }) || projectId.length !== 66) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"projectId must be a 0x-prefixed 32-byte hex string.\");\n }\n return projectId;\n}\n\nfunction amount(label: string, v: bigint, max: bigint): bigint {\n if (typeof v !== \"bigint\" || v <= 0n || v > max) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `${label} must be a bigint greater than 0 and within range.`);\n }\n return v;\n}\n\nfunction call(to: Address, data: Hex, fn: string, value = 0n): PaymasterCall {\n return { to, data, value, function: fn };\n}\n\n/** State of a project, read from the paymaster contract. */\nexport interface ProjectState {\n projectId: Hex;\n paymaster: Address;\n /** `null` when unclaimed. */\n owner: Address | null;\n claimed: boolean;\n paused: boolean;\n /** Deposited, unspent wei. Deposit-only: this can only be spent as gas, never withdrawn. */\n balance: bigint;\n dailyLimit: bigint;\n senderDailyLimit: bigint;\n /** Spent in the current UTC day (0 when the stored day is stale). */\n spentToday: bigint;\n /** Day index (unix seconds / 86400) the stored `spentToday` belongs to. */\n spentDay: number;\n /** True when claimed and both limits are set. Targets are checked via `targetsAllowed`. */\n limitsConfigured: boolean;\n /**\n * Pending timelocked claim, or `null`: a re-claim of an owned project, or (when `claimed` is false) the first\n * claim of a project that already holds funds. Finish it with {@link encodeExecuteReclaim} after `executableAt`.\n */\n pendingReclaim: { newOwner: Address; executableAt: number; signer: Address } | null;\n /** Address proposed in a two-step ownership transfer, or `null`. */\n pendingOwner: Address | null;\n /** Present when `checkTargets` was passed: allowed flag per address (checksummed keys). */\n targetsAllowed?: Record<Address, boolean>;\n}\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nexport interface ReadProjectOptions extends PaymasterAddressOption {\n /** Also check these destinations against the on-chain allowlist (one `isTargetAllowed` read each). */\n checkTargets?: readonly Address[];\n /** Clock override for the day rollover (tests). Milliseconds. */\n now?: () => number;\n}\n\n/**\n * Read a project's on-chain state: owner, pause flag, balance, limits, pending re-claim and pending owner.\n *\n * @example\n * ```ts\n * const p = await readProject(publicClient, computeProjectId(appId), { paymaster });\n * if (!p.claimed) console.log(\"claim it first\");\n * ```\n */\nexport async function readProject(\n client: Pick<PublicClient, \"readContract\">,\n projectId: Hex,\n options: ReadProjectOptions = {},\n): Promise<ProjectState> {\n const paymaster = resolvePaymasterV2Address(options.paymaster);\n const id = assertProjectId(projectId);\n const abi = pepuSponsoredPaymasterV2Abi;\n const [project, reclaim, pendingOwner] = await Promise.all([\n client.readContract({ address: paymaster, abi, functionName: \"getProject\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingReclaim\", args: [id] }),\n client.readContract({ address: paymaster, abi, functionName: \"pendingProjectOwner\", args: [id] }),\n ]);\n const [owner, paused, senderDailyLimit, balance, dailyLimit, spentToday, spentDay] = project;\n const [reclaimOwner, executableAt, reclaimSigner] = reclaim;\n const claimed = owner !== ZERO;\n const today = Math.floor((options.now ?? Date.now)() / 1000 / 86_400);\n\n let targetsAllowed: Record<Address, boolean> | undefined;\n if (options.checkTargets && options.checkTargets.length > 0) {\n const entries = await Promise.all(\n options.checkTargets.map(async (t) => {\n const allowed = await client.readContract({\n address: paymaster,\n abi,\n functionName: \"isTargetAllowed\",\n args: [id, t],\n });\n return [getAddress(t), allowed] as const;\n }),\n );\n targetsAllowed = Object.fromEntries(entries) as Record<Address, boolean>;\n }\n\n return {\n projectId: id,\n paymaster,\n owner: claimed ? getAddress(owner) : null,\n claimed,\n paused,\n balance,\n dailyLimit,\n senderDailyLimit,\n spentToday: spentDay === today ? spentToday : 0n,\n spentDay,\n limitsConfigured: claimed && dailyLimit > 0n && senderDailyLimit > 0n,\n pendingReclaim:\n reclaimOwner !== ZERO ? { newOwner: getAddress(reclaimOwner), executableAt, signer: getAddress(reclaimSigner) } : null,\n pendingOwner: pendingOwner !== ZERO ? getAddress(pendingOwner) : null,\n ...(targetsAllowed ? { targetsAllowed } : {}),\n };\n}\n\n/**\n * Encode `depositFor(projectId)` with native PEPU as `value`. ONE-WAY: nothing can ever withdraw the deposit,\n * and the id is `keccak256` of a case-sensitive app id, so a typo deposits into a project nobody can claim.\n * Prefer {@link depositFor}, which checks the project is claimed first.\n *\n * @example\n * ```ts\n * const tx = encodeDeposit(computeProjectId(appId), 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeDeposit(projectId: Hex, amountWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"depositFor\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"depositFor(bytes32)\", amount(\"amountWei\", amountWei, U128_MAX));\n}\n\nfunction claimArgs(a: ProjectClaimAttestation) {\n if (!a.appId || a.appId.length > 128) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.appId must be 1 to 128 characters.\");\n }\n if (!isAddress(a.newOwner, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.newOwner is not a valid address.\");\n }\n if (!isHex(a.signature)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"attestation.signature must be 0x-prefixed hex.\");\n }\n return {\n appId: a.appId,\n newOwner: getAddress(a.newOwner),\n nonce: BigInt(a.nonce),\n deadline: BigInt(a.deadline),\n signature: a.signature,\n };\n}\n\n/**\n * Encode `claimProject(Claim)`. The attestation fixes the owner; anyone may submit the transaction. The claim\n * sets ONLY the owner: follow with {@link configureProject}'s three calls, because nothing is sponsorable\n * until `setTargets`, `setDailyLimit` and `setSenderDailyLimit` have run. If the project already holds deposited\n * funds the claim is PENDING for the on-chain admin change delay (>= 48h): the contract owner or manager can cancel\n * it, and anyone finishes it with {@link encodeExecuteReclaim}.\n *\n * @example\n * ```ts\n * const tx = encodeClaimProject(attestation, { paymaster });\n * await walletClient.sendTransaction({ to: tx.to, data: tx.data });\n * ```\n */\nexport function encodeClaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"claimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"claimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Encode `reclaimProject(Claim)`: a timelocked (>= 48h) re-claim of an already-owned project. The current owner\n * can cancel it ({@link encodeCancelReclaim}); anyone can finish it after the delay ({@link encodeExecuteReclaim}).\n *\n * @example\n * ```ts\n * const tx = encodeReclaimProject(attestation, { paymaster });\n * ```\n */\nexport function encodeReclaimProject(attestation: ProjectClaimAttestation, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"reclaimProject\",\n args: [claimArgs(attestation)],\n });\n return call(to, data, \"reclaimProject((string,address,uint256,uint256,bytes))\");\n}\n\n/**\n * Pick `claimProject` or `reclaimProject` from a `/v2/projects/verify` result (its `action` field) and encode it.\n *\n * @example\n * ```ts\n * const tx = encodeClaimFromVerification(verified, { paymaster });\n * ```\n */\nexport function encodeClaimFromVerification(\n verified: { action: \"claimProject\" | \"reclaimProject\"; attestation: ProjectClaimAttestation },\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n return verified.action === \"reclaimProject\"\n ? encodeReclaimProject(verified.attestation, options)\n : encodeClaimProject(verified.attestation, options);\n}\n\n/**\n * Encode `executeReclaim(projectId)`: completes a pending claim or re-claim once its delay has passed (and before it\n * expires, 30 days later).\n *\n * @example\n * ```ts\n * const tx = encodeExecuteReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeExecuteReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"executeReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"executeReclaim(bytes32)\");\n}\n\n/**\n * Encode `cancelReclaim(projectId)`: the current owner cancels a pending re-claim, ONCE per new owner (a second\n * attested re-claim by the same new owner cannot be cancelled). For a pending FIRST claim of an unowned project the\n * contract owner or manager cancels instead.\n *\n * @example\n * ```ts\n * const tx = encodeCancelReclaim(projectId, { paymaster });\n * ```\n */\nexport function encodeCancelReclaim(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"cancelReclaim\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"cancelReclaim(bytes32)\");\n}\n\n/**\n * Encode `setTargets(projectId, targets, allowed)`: add or remove destination contracts the project sponsors\n * (at most 50 per call). Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetTargets(projectId, [counter], true, { paymaster });\n * ```\n */\nexport function encodeSetTargets(\n projectId: Hex,\n targets: readonly Address[],\n allowed: boolean,\n options: PaymasterAddressOption = {},\n): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (targets.length === 0 || targets.length > MAX_TARGETS_PER_CALL) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", `targets must contain 1 to ${MAX_TARGETS_PER_CALL} addresses per call.`);\n }\n for (const t of targets) {\n if (!isAddress(t, { strict: false })) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"targets contains an invalid address.\");\n }\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setTargets\",\n args: [assertProjectId(projectId), targets.map((t) => getAddress(t)), allowed],\n });\n return call(to, data, \"setTargets(bytes32,address[],bool)\");\n}\n\n/**\n * Encode `setDailyLimit(projectId, limitWei)`: the project's total daily gas budget. Owner only. Must be above\n * zero; a contract-side zero limit means nothing can be spent, and tightening is instant.\n *\n * @example\n * ```ts\n * const tx = encodeSetDailyLimit(projectId, 5n * 10n ** 18n, { paymaster });\n * ```\n */\nexport function encodeSetDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setSenderDailyLimit(projectId, limitWei)`: the per-wallet daily gas limit. Owner only.\n *\n * @example\n * ```ts\n * const tx = encodeSetSenderDailyLimit(projectId, 10n ** 17n, { paymaster });\n * ```\n */\nexport function encodeSetSenderDailyLimit(projectId: Hex, limitWei: bigint, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setSenderDailyLimit\",\n args: [assertProjectId(projectId), amount(\"limitWei\", limitWei, U112_MAX)],\n });\n return call(to, data, \"setSenderDailyLimit(bytes32,uint112)\");\n}\n\n/**\n * Encode `setPaused(projectId, paused)`. Pausing takes effect immediately; it is the project's emergency stop.\n *\n * @example\n * ```ts\n * const stop = encodeSetPaused(projectId, true, { paymaster });\n * ```\n */\nexport function encodeSetPaused(projectId: Hex, paused: boolean, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"setPaused\",\n args: [assertProjectId(projectId), paused],\n });\n return call(to, data, \"setPaused(bytes32,bool)\");\n}\n\n/**\n * Encode `proposeProjectOwner(projectId, newOwner)`: step one of the two-step ownership transfer. The new\n * owner must then call {@link encodeAcceptProjectOwnership}.\n *\n * @example\n * ```ts\n * const tx = encodeProposeProjectOwner(projectId, newOwner, { paymaster });\n * ```\n */\nexport function encodeProposeProjectOwner(projectId: Hex, newOwner: Address, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n if (!isAddress(newOwner, { strict: false }) || newOwner === ZERO) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"newOwner must be a non-zero valid address.\");\n }\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"proposeProjectOwner\",\n args: [assertProjectId(projectId), getAddress(newOwner)],\n });\n return call(to, data, \"proposeProjectOwner(bytes32,address)\");\n}\n\n/**\n * Encode `acceptProjectOwnership(projectId)`: step two of the ownership transfer, sent by the proposed owner.\n *\n * @example\n * ```ts\n * const tx = encodeAcceptProjectOwnership(projectId, { paymaster });\n * ```\n */\nexport function encodeAcceptProjectOwnership(projectId: Hex, options: PaymasterAddressOption = {}): PaymasterCall {\n const to = resolvePaymasterV2Address(options.paymaster);\n const data = encodeFunctionData({\n abi: pepuSponsoredPaymasterV2Abi,\n functionName: \"acceptProjectOwnership\",\n args: [assertProjectId(projectId)],\n });\n return call(to, data, \"acceptProjectOwnership(bytes32)\");\n}\n\nexport interface ConfigureProjectParams extends PaymasterAddressOption {\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n /** Destination contracts to sponsor (the on-chain allowlist). 1 to 50. */\n targets: readonly Address[];\n /** Total daily budget, wei. */\n dailyLimitWei: bigint;\n /** Per-wallet daily budget, wei. */\n senderDailyLimitWei: bigint;\n}\n\n/**\n * The three post-claim configuration calls, in order: `setTargets(allowed = true)`, `setDailyLimit`,\n * `setSenderDailyLimit`. A project spends nothing until all three have run. All three are owner-only calls to\n * the same contract, so a smart account or batched wallet can send them in one transaction; an EOA sends them\n * one after another with {@link sendPaymasterCalls}.\n *\n * @example\n * ```ts\n * const { calls } = configureProject({\n * appId, paymaster,\n * targets: [counter],\n * dailyLimitWei: 5n * 10n ** 18n,\n * senderDailyLimitWei: 10n ** 17n,\n * });\n * await smartAccountClient.sendUserOperation({ calls: calls.map(({ to, data, value }) => ({ to, data, value })) });\n * ```\n */\nexport function configureProject(params: ConfigureProjectParams): { projectId: Hex; calls: PaymasterCall[] } {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"configureProject needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const o = { paymaster: params.paymaster };\n return {\n projectId,\n calls: [\n encodeSetTargets(projectId, params.targets, true, o),\n encodeSetDailyLimit(projectId, params.dailyLimitWei, o),\n encodeSetSenderDailyLimit(projectId, params.senderDailyLimitWei, o),\n ],\n };\n}\n\ntype SendingWallet = Pick<WalletClient, \"sendTransaction\"> & { account?: Account | undefined; chain?: Chain | undefined };\n\n/**\n * Send prepared calls one after another from a wallet client, returning the hashes. When `publicClient` is\n * given it waits for each receipt first (so a later call is not sent after an earlier one failed). The\n * transaction `value` is exactly the call's value; nothing else is added.\n *\n * @example\n * ```ts\n * const hashes = await sendPaymasterCalls(walletClient, calls, { publicClient });\n * ```\n */\nexport async function sendPaymasterCalls(\n walletClient: SendingWallet,\n calls: readonly PaymasterCall[],\n options: { publicClient?: Pick<PublicClient, \"waitForTransactionReceipt\"> } = {},\n): Promise<Hash[]> {\n const account = walletClient.account;\n if (!account) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", \"The wallet client has no account; create it with an account.\");\n }\n const chain = walletClient.chain ?? pepuMainnet;\n const hashes: Hash[] = [];\n for (const c of calls) {\n const hash = await walletClient.sendTransaction({ account, chain, to: c.to, data: c.data, value: c.value });\n hashes.push(hash);\n if (options.publicClient) {\n const receipt = await options.publicClient.waitForTransactionReceipt({ hash });\n if (receipt.status !== \"success\") {\n throw new PepuPaymasterError(\"TX_REVERTED\", `Paymaster call ${c.function} reverted (transaction ${hash}).`, {\n details: { hash, function: c.function },\n });\n }\n }\n }\n return hashes;\n}\n\nexport interface DepositForParams extends PaymasterAddressOption {\n walletClient: SendingWallet;\n /** Give `appId` or `projectId`. */\n appId?: string;\n projectId?: Hex;\n amountWei: bigint;\n /**\n * Default true: read the project first and refuse when it has no owner, which catches a mistyped (case-sensitive)\n * app id before funds go to a project nobody controls. Needs `publicClient`. Pass false to fund a project its\n * owner has not claimed yet (deposits are credited and become spendable after the claim and configuration).\n */\n requireClaimed?: boolean;\n publicClient?: Pick<PublicClient, \"readContract\">;\n}\n\n/**\n * Deposit native PEPU into a project with the caller's wallet. ONE-WAY: nobody can withdraw it afterwards, and\n * anyone may deposit into any project. By default it first confirms the project is claimed.\n *\n * @example\n * ```ts\n * const hash = await depositFor({ walletClient, publicClient, appId, amountWei: 10n ** 18n, paymaster });\n * ```\n */\nexport async function depositFor(params: DepositForParams): Promise<Hash> {\n if ((params.appId === undefined) === (params.projectId === undefined)) {\n throw new PepuPaymasterError(\"PAYMASTER_DENIED\", \"depositFor needs exactly one of appId or projectId.\");\n }\n const projectId = params.projectId !== undefined ? assertProjectId(params.projectId) : computeProjectId(params.appId as string);\n const tx = encodeDeposit(projectId, params.amountWei, { paymaster: params.paymaster });\n if (params.requireClaimed ?? true) {\n if (!params.publicClient) {\n throw new PepuConfigError(\n \"CONFIG_MISSING_ENV\",\n \"depositFor checks the project is claimed by default and needs a publicClient. Pass publicClient, or requireClaimed: false to fund an unclaimed project.\",\n );\n }\n const state = await readProject(params.publicClient, projectId, { paymaster: params.paymaster });\n if (!state.claimed) {\n throw new PepuPaymasterError(\n \"PAYMASTER_PROJECT_NOT_CLAIMED\",\n \"Refusing to deposit: the project is not claimed. Check the app id spelling (it is case-sensitive), or pass requireClaimed: false. Deposits cannot be withdrawn.\",\n { details: { projectId } },\n );\n }\n }\n const [hash] = await sendPaymasterCalls(params.walletClient, [tx]);\n return hash as Hash;\n}\n"]}
|
package/dist/privy/react.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/* @pepu-chain/peer-guard */(function(){var p=["react","@privy-io/react-auth"];for(var i=0;i<p.length;i++){try{require.resolve(p[i])}catch(e){if(e&&e.code==="MODULE_NOT_FOUND"){var m="@pepu-chain/sdk/privy/react needs peer packages that are not installed: react @privy-io/react-auth. Install with: npm i react @privy-io/react-auth (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
2
3
|
|
|
3
4
|
var chunkDH6BFNVJ_cjs = require('../chunk-DH6BFNVJ.cjs');
|
|
4
5
|
require('../chunk-NE3QKDOB.cjs');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by scripts/guard-peers.mjs. Used only under the "node" export condition.
|
|
2
|
+
const peers = ["react","@privy-io/react-auth"];
|
|
3
|
+
for (const peer of peers) {
|
|
4
|
+
try {
|
|
5
|
+
import.meta.resolve?.(peer);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e && e.code === "ERR_MODULE_NOT_FOUND") {
|
|
8
|
+
const err = new Error("@pepu-chain/sdk/privy/react needs peer packages that are not installed: react @privy-io/react-auth. Install with: npm i react @privy-io/react-auth (or let create-pepu-app scaffold everything).");
|
|
9
|
+
err.code = "PEPU_MISSING_PEER";
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const mod = await import("./react.js");
|
|
15
|
+
export const { PepuPrivyProvider, WalletGate, composeProviders, requestEnsureWallet, shouldPinEmbeddedWallet, useEmbeddedWallet, useEnsureWallet, usePepuAuthFetch, usePinEmbeddedWallet } = mod;
|
package/dist/privy/server.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/* @pepu-chain/peer-guard */(function(){var p=["@privy-io/node"];for(var i=0;i<p.length;i++){try{require.resolve(p[i])}catch(e){if(e&&e.code==="MODULE_NOT_FOUND"){var m="@pepu-chain/sdk/privy/server needs a peer package that is not installed: @privy-io/node. Install with: npm i @privy-io/node (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
2
3
|
|
|
3
4
|
var chunk45KSZH26_cjs = require('../chunk-45KSZH26.cjs');
|
|
4
5
|
require('../chunk-SVWRRALU.cjs');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by scripts/guard-peers.mjs. Used only under the "node" export condition.
|
|
2
|
+
const peers = ["@privy-io/node"];
|
|
3
|
+
for (const peer of peers) {
|
|
4
|
+
try {
|
|
5
|
+
import.meta.resolve?.(peer);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e && e.code === "ERR_MODULE_NOT_FOUND") {
|
|
8
|
+
const err = new Error("@pepu-chain/sdk/privy/server needs a peer package that is not installed: @privy-io/node. Install with: npm i @privy-io/node (or let create-pepu-app scaffold everything).");
|
|
9
|
+
err.code = "PEPU_MISSING_PEER";
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const mod = await import("./server.js");
|
|
15
|
+
export const { createEnsureWalletRoute, createPrivyServer, findDelegatedEthereumWallet, findEmbeddedEthereumWallet, privyEnvVar, readPrivyServerEnv, requireUser, verifyRequestUser } = mod;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by scripts/guard-peers.mjs. Used only under the "node" export condition.
|
|
2
|
+
const peers = ["react","@privy-io/react-auth","@privy-io/wagmi","wagmi","@tanstack/react-query"];
|
|
3
|
+
for (const peer of peers) {
|
|
4
|
+
try {
|
|
5
|
+
import.meta.resolve?.(peer);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e && e.code === "ERR_MODULE_NOT_FOUND") {
|
|
8
|
+
const err = new Error("@pepu-chain/sdk/privy/wagmi needs peer packages that are not installed: react @privy-io/react-auth @privy-io/wagmi wagmi @tanstack/react-query. Install with: npm i react @privy-io/react-auth @privy-io/wagmi wagmi @tanstack/react-query (or let create-pepu-app scaffold everything).");
|
|
9
|
+
err.code = "PEPU_MISSING_PEER";
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const mod = await import("./wagmi.js");
|
|
15
|
+
export const { EMBEDDED_WALLET_IS_ACTIVE_BY_DEFAULT, PepuPrivyWagmiProvider, pepuWagmiConfig, useActiveWalletPin } = mod;
|
package/dist/react.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/* @pepu-chain/peer-guard */(function(){var p=["react"];for(var i=0;i<p.length;i++){try{require.resolve(p[i])}catch(e){if(e&&e.code==="MODULE_NOT_FOUND"){var m="@pepu-chain/sdk/react needs a peer package that is not installed: react. Install with: npm i react (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
2
3
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
4
|
+
var chunkVYMAZVIK_cjs = require('./chunk-VYMAZVIK.cjs');
|
|
5
|
+
require('./chunk-HTCX46RJ.cjs');
|
|
6
|
+
require('./chunk-K7JSQPZO.cjs');
|
|
7
|
+
require('./chunk-65Y5UCQ7.cjs');
|
|
6
8
|
require('./chunk-VF3D6KLQ.cjs');
|
|
7
9
|
var chunkDPCZJLB3_cjs = require('./chunk-DPCZJLB3.cjs');
|
|
8
10
|
require('./chunk-YQL7NISX.cjs');
|
|
@@ -60,7 +62,7 @@ function usePepuChain(chainId) {
|
|
|
60
62
|
function useSponsorshipStatus(options) {
|
|
61
63
|
const bundlerUrl = options?.bundlerUrl;
|
|
62
64
|
return react.useMemo(
|
|
63
|
-
() =>
|
|
65
|
+
() => chunkVYMAZVIK_cjs.getSponsorshipStatus(bundlerUrl === void 0 ? void 0 : { bundlerUrl }),
|
|
64
66
|
[bundlerUrl]
|
|
65
67
|
);
|
|
66
68
|
}
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/usePepuBalance.ts","../src/react/usePepuChain.ts","../src/react/useSponsorshipStatus.ts"],"names":["useState","useCallback","erc20Abi","useEffect","useMemo","pepuChains","getSponsorshipStatus"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/react/usePepuBalance.ts","../src/react/usePepuChain.ts","../src/react/useSponsorshipStatus.ts"],"names":["useState","useCallback","erc20Abi","useEffect","useMemo","pepuChains","getSponsorshipStatus"],"mappings":";;;;;;;;;;;;AAoCO,SAAS,cAAA,CACd,QACA,OAAA,EACsB;AACtB,EAAA,MAAM,EAAE,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A;AAAA,IACF;AACA,IAAA,MAAM,EAAA,GAAK,YAAY,MAAM;AAC3B,MAAA,KAAK,YAAA,EAAa;AAAA,IACpB,GAAG,eAAe,CAAA;AAClB,IAAA,OAAO,MAAM,cAAc,EAAE,CAAA;AAAA,EAC/B,CAAA,EAAG,CAAC,YAAA,EAAc,eAAe,CAAC,CAAA;AAElC,EAAA,MAAM,OAAA,GAAUF,kBAAY,MAAM;AAChC,IAAA,KAAK,YAAA,EAAa;AAAA,EACpB,CAAA,EAAG,CAAC,YAAY,CAAC,CAAA;AAEjB,EAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ;AAC3C;ACnEO,SAAS,aAAa,OAAA,EAAiD;AAC5E,EAAA,OAAOG,cAAQ,MAAM;AACnB,IAAA,MAAM,QAAQC,4BAAA,CAAW,IAAA,CAAK,CAAC,SAAA,KAAc,SAAA,CAAU,OAAO,OAAO,CAAA;AACrE,IAAA,OAAO,EAAE,KAAA,EAAO,WAAA,EAAa,KAAA,KAAU,MAAA,EAAU;AAAA,EACnD,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AACd;ACNO,SAAS,qBACd,OAAA,EACmB;AACnB,EAAA,MAAM,aAAa,OAAA,EAAS,UAAA;AAC5B,EAAA,OAAOD,aAAAA;AAAA,IACL,MAAME,sCAAA,CAAqB,UAAA,KAAe,SAAY,MAAA,GAAY,EAAE,YAAY,CAAA;AAAA,IAChF,CAAC,UAAU;AAAA,GACb;AACF","file":"react.cjs","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { erc20Abi } from \"viem\";\nimport type { Address, PublicClient, Transport } from \"viem\";\n\nimport type { PepuChain } from \"../chains.js\";\n\n/** Options for {@link usePepuBalance}. */\nexport interface UsePepuBalanceOptions {\n /** Address to read a balance for. The hook holds `data` at `undefined` while this is `undefined`. */\n readonly address: Address | undefined;\n /** ERC-20 token address to read `balanceOf` for. Omit for the native PEPU balance (`client.getBalance`). */\n readonly token?: Address;\n /** Re-fetch on an interval, in milliseconds. Omit (or `0`) to fetch once. */\n readonly pollingInterval?: number;\n}\n\n/** Result of {@link usePepuBalance}. */\nexport interface UsePepuBalanceResult {\n /** The balance in the smallest unit (wei for native PEPU, the token's own base unit for an ERC-20), or `undefined` before the first successful fetch. */\n readonly data: bigint | undefined;\n readonly isLoading: boolean;\n readonly error: Error | undefined;\n /** Re-run the fetch immediately, outside the polling interval. */\n readonly refetch: () => void;\n}\n\n/**\n * Read (and optionally poll) an address's native PEPU balance, or an\n * ERC-20 token balance on a PEPU chain, given a viem `PublicClient`.\n *\n * Deliberately takes the client as a parameter rather than reaching for one\n * itself (e.g. via a context provider this package would have to define\n * and ship) — this keeps the hook usable with whatever client the host app\n * already has (its own `getPublicClient` call, wagmi's `usePublicClient()`,\n * etc.) instead of introducing a second, competing way to obtain one.\n */\nexport function usePepuBalance(\n client: PublicClient<Transport, PepuChain>,\n options: UsePepuBalanceOptions,\n): UsePepuBalanceResult {\n const { address, token, pollingInterval } = options;\n const [data, setData] = useState<bigint | undefined>(undefined);\n const [error, setError] = useState<Error | undefined>(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n const fetchBalance = useCallback(async () => {\n if (!address) {\n setData(undefined);\n setError(undefined);\n return;\n }\n setIsLoading(true);\n try {\n const balance = token\n ? await client.readContract({\n address: token,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [address],\n })\n : await client.getBalance({ address });\n setData(balance);\n setError(undefined);\n } catch (caught) {\n setError(caught instanceof Error ? caught : new Error(String(caught)));\n } finally {\n setIsLoading(false);\n }\n }, [client, address, token]);\n\n useEffect(() => {\n void fetchBalance();\n if (!pollingInterval) {\n return;\n }\n const id = setInterval(() => {\n void fetchBalance();\n }, pollingInterval);\n return () => clearInterval(id);\n }, [fetchBalance, pollingInterval]);\n\n const refetch = useCallback(() => {\n void fetchBalance();\n }, [fetchBalance]);\n\n return { data, isLoading, error, refetch };\n}\n","import { useMemo } from \"react\";\n\nimport { pepuChains } from \"../chains.js\";\nimport type { PepuChain } from \"../chains.js\";\n\n/** Result of {@link usePepuChain}. */\nexport interface UsePepuChainResult {\n /** The matching {@link PepuChain}, or `undefined` if `chainId` isn't one of PEPU's. */\n readonly chain: PepuChain | undefined;\n /** `true` iff `chainId` is one of PEPU's chain ids. Equivalent to `chain !== undefined`. */\n readonly isPepuChain: boolean;\n}\n\n/**\n * Resolve a raw chain id (e.g. from wagmi's `useChainId()`, or an injected\n * wallet's `eth_chainId`) to its {@link PepuChain} definition, if it's one\n * of PEPU's. Pure lookup over {@link pepuChains} — makes no network call\n * and holds no state beyond memoizing the result.\n */\nexport function usePepuChain(chainId: number | undefined): UsePepuChainResult {\n return useMemo(() => {\n const chain = pepuChains.find((candidate) => candidate.id === chainId);\n return { chain, isPepuChain: chain !== undefined };\n }, [chainId]);\n}\n","import { useMemo } from \"react\";\n\nimport { getSponsorshipStatus } from \"../aa/status.js\";\nimport type { GetSponsorshipStatusOptions, SponsorshipStatus } from \"../aa/status.js\";\n\n/**\n * React wrapper around {@link getSponsorshipStatus} — reports whether PEPU\n * gas sponsorship is available. **Deprecated: always reports unavailable.**\n * The hosted bundler and paymaster service are live and sponsorship is proven\n * on mainnet, but the ERC-7677 URL embeds a project token, so availability can\n * only be answered by a live probe. Use `usePepuSponsorship()` from\n * `@pepu-chain/sdk/aa/react` (it wraps `checkSponsorship`) instead. This hook\n * stays so 0.1 callers keep compiling.\n */\n/**\n * @deprecated Always reports unavailable. Use `usePepuSponsorship()` from\n * `@pepu-chain/sdk/aa/react` (live probe). Kept for 0.1 callers.\n */\nexport function useSponsorshipStatus(\n options?: GetSponsorshipStatusOptions,\n): SponsorshipStatus {\n const bundlerUrl = options?.bundlerUrl;\n return useMemo(\n () => getSponsorshipStatus(bundlerUrl === undefined ? undefined : { bundlerUrl }),\n [bundlerUrl],\n );\n}\n"]}
|
package/dist/react.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, PublicClient, Transport } from 'viem';
|
|
2
2
|
import { P as PepuChain } from './chains-DK13zGIp.cjs';
|
|
3
|
-
import { G as GetSponsorshipStatusOptions, c as SponsorshipStatus } from './status-
|
|
3
|
+
import { G as GetSponsorshipStatusOptions, c as SponsorshipStatus } from './status-wgTM26V7.cjs';
|
|
4
4
|
import './errors-CgX1vNj7.cjs';
|
|
5
5
|
|
|
6
6
|
/** Options for {@link usePepuBalance}. */
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, PublicClient, Transport } from 'viem';
|
|
2
2
|
import { P as PepuChain } from './chains-DK13zGIp.js';
|
|
3
|
-
import { G as GetSponsorshipStatusOptions, c as SponsorshipStatus } from './status-
|
|
3
|
+
import { G as GetSponsorshipStatusOptions, c as SponsorshipStatus } from './status-Dx9zAFo9.js';
|
|
4
4
|
import './errors-CgX1vNj7.js';
|
|
5
5
|
|
|
6
6
|
/** Options for {@link usePepuBalance}. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by scripts/guard-peers.mjs. Used only under the "node" export condition.
|
|
2
|
+
const peers = ["react"];
|
|
3
|
+
for (const peer of peers) {
|
|
4
|
+
try {
|
|
5
|
+
import.meta.resolve?.(peer);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e && e.code === "ERR_MODULE_NOT_FOUND") {
|
|
8
|
+
const err = new Error("@pepu-chain/sdk/react needs a peer package that is not installed: react. Install with: npm i react (or let create-pepu-app scaffold everything).");
|
|
9
|
+
err.code = "PEPU_MISSING_PEER";
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const mod = await import("./react.js");
|
|
15
|
+
export const { usePepuBalance, usePepuChain, useSponsorshipStatus } = mod;
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getSponsorshipStatus } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { getSponsorshipStatus } from './chunk-XR5ONV2Y.js';
|
|
2
|
+
import './chunk-GFKIM7HT.js';
|
|
3
|
+
import './chunk-KJYNF5KH.js';
|
|
4
|
+
import './chunk-GIZNH65Q.js';
|
|
4
5
|
import './chunk-XC4IBCI2.js';
|
|
5
6
|
import { pepuChains } from './chunk-VTQIHMF3.js';
|
|
6
7
|
import './chunk-6DSZ4Z2N.js';
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/usePepuBalance.ts","../src/react/usePepuChain.ts","../src/react/useSponsorshipStatus.ts"],"names":["useMemo"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/react/usePepuBalance.ts","../src/react/usePepuChain.ts","../src/react/useSponsorshipStatus.ts"],"names":["useMemo"],"mappings":";;;;;;;;;;AAoCO,SAAS,cAAA,CACd,QACA,OAAA,EACsB;AACtB,EAAA,MAAM,EAAE,OAAA,EAAS,KAAA,EAAO,eAAA,EAAgB,GAAI,OAAA;AAC5C,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,SAA6B,MAAS,CAAA;AAC9D,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA4B,MAAS,CAAA;AAC/D,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AAEhD,EAAA,MAAM,YAAA,GAAe,YAAY,YAAY;AAC3C,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,OAAA,CAAQ,MAAS,CAAA;AACjB,MAAA,QAAA,CAAS,MAAS,CAAA;AAClB,MAAA;AAAA,IACF;AACA,IAAA,YAAA,CAAa,IAAI,CAAA;AACjB,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,KAAA,GACZ,MAAM,MAAA,CAAO,YAAA,CAAa;AAAA,QACxB,OAAA,EAAS,KAAA;AAAA,QACT,GAAA,EAAK,QAAA;AAAA,QACL,YA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;AAAA,EACnD,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AACd;ACNO,SAAS,qBACd,OAAA,EACmB;AACnB,EAAA,MAAM,aAAa,OAAA,EAAS,UAAA;AAC5B,EAAA,OAAOA,OAAAA;AAAA,IACL,MAAM,oBAAA,CAAqB,UAAA,KAAe,SAAY,MAAA,GAAY,EAAE,YAAY,CAAA;AAAA,IAChF,CAAC,UAAU;AAAA,GACb;AACF","file":"react.js","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { erc20Abi } from \"viem\";\nimport type { Address, PublicClient, Transport } from \"viem\";\n\nimport type { PepuChain } from \"../chains.js\";\n\n/** Options for {@link usePepuBalance}. */\nexport interface UsePepuBalanceOptions {\n /** Address to read a balance for. The hook holds `data` at `undefined` while this is `undefined`. */\n readonly address: Address | undefined;\n /** ERC-20 token address to read `balanceOf` for. Omit for the native PEPU balance (`client.getBalance`). */\n readonly token?: Address;\n /** Re-fetch on an interval, in milliseconds. Omit (or `0`) to fetch once. */\n readonly pollingInterval?: number;\n}\n\n/** Result of {@link usePepuBalance}. */\nexport interface UsePepuBalanceResult {\n /** The balance in the smallest unit (wei for native PEPU, the token's own base unit for an ERC-20), or `undefined` before the first successful fetch. */\n readonly data: bigint | undefined;\n readonly isLoading: boolean;\n readonly error: Error | undefined;\n /** Re-run the fetch immediately, outside the polling interval. */\n readonly refetch: () => void;\n}\n\n/**\n * Read (and optionally poll) an address's native PEPU balance, or an\n * ERC-20 token balance on a PEPU chain, given a viem `PublicClient`.\n *\n * Deliberately takes the client as a parameter rather than reaching for one\n * itself (e.g. via a context provider this package would have to define\n * and ship) — this keeps the hook usable with whatever client the host app\n * already has (its own `getPublicClient` call, wagmi's `usePublicClient()`,\n * etc.) instead of introducing a second, competing way to obtain one.\n */\nexport function usePepuBalance(\n client: PublicClient<Transport, PepuChain>,\n options: UsePepuBalanceOptions,\n): UsePepuBalanceResult {\n const { address, token, pollingInterval } = options;\n const [data, setData] = useState<bigint | undefined>(undefined);\n const [error, setError] = useState<Error | undefined>(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n const fetchBalance = useCallback(async () => {\n if (!address) {\n setData(undefined);\n setError(undefined);\n return;\n }\n setIsLoading(true);\n try {\n const balance = token\n ? await client.readContract({\n address: token,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [address],\n })\n : await client.getBalance({ address });\n setData(balance);\n setError(undefined);\n } catch (caught) {\n setError(caught instanceof Error ? caught : new Error(String(caught)));\n } finally {\n setIsLoading(false);\n }\n }, [client, address, token]);\n\n useEffect(() => {\n void fetchBalance();\n if (!pollingInterval) {\n return;\n }\n const id = setInterval(() => {\n void fetchBalance();\n }, pollingInterval);\n return () => clearInterval(id);\n }, [fetchBalance, pollingInterval]);\n\n const refetch = useCallback(() => {\n void fetchBalance();\n }, [fetchBalance]);\n\n return { data, isLoading, error, refetch };\n}\n","import { useMemo } from \"react\";\n\nimport { pepuChains } from \"../chains.js\";\nimport type { PepuChain } from \"../chains.js\";\n\n/** Result of {@link usePepuChain}. */\nexport interface UsePepuChainResult {\n /** The matching {@link PepuChain}, or `undefined` if `chainId` isn't one of PEPU's. */\n readonly chain: PepuChain | undefined;\n /** `true` iff `chainId` is one of PEPU's chain ids. Equivalent to `chain !== undefined`. */\n readonly isPepuChain: boolean;\n}\n\n/**\n * Resolve a raw chain id (e.g. from wagmi's `useChainId()`, or an injected\n * wallet's `eth_chainId`) to its {@link PepuChain} definition, if it's one\n * of PEPU's. Pure lookup over {@link pepuChains} — makes no network call\n * and holds no state beyond memoizing the result.\n */\nexport function usePepuChain(chainId: number | undefined): UsePepuChainResult {\n return useMemo(() => {\n const chain = pepuChains.find((candidate) => candidate.id === chainId);\n return { chain, isPepuChain: chain !== undefined };\n }, [chainId]);\n}\n","import { useMemo } from \"react\";\n\nimport { getSponsorshipStatus } from \"../aa/status.js\";\nimport type { GetSponsorshipStatusOptions, SponsorshipStatus } from \"../aa/status.js\";\n\n/**\n * React wrapper around {@link getSponsorshipStatus} — reports whether PEPU\n * gas sponsorship is available. **Deprecated: always reports unavailable.**\n * The hosted bundler and paymaster service are live and sponsorship is proven\n * on mainnet, but the ERC-7677 URL embeds a project token, so availability can\n * only be answered by a live probe. Use `usePepuSponsorship()` from\n * `@pepu-chain/sdk/aa/react` (it wraps `checkSponsorship`) instead. This hook\n * stays so 0.1 callers keep compiling.\n */\n/**\n * @deprecated Always reports unavailable. Use `usePepuSponsorship()` from\n * `@pepu-chain/sdk/aa/react` (live probe). Kept for 0.1 callers.\n */\nexport function useSponsorshipStatus(\n options?: GetSponsorshipStatusOptions,\n): SponsorshipStatus {\n const bundlerUrl = options?.bundlerUrl;\n return useMemo(\n () => getSponsorshipStatus(bundlerUrl === undefined ? undefined : { bundlerUrl }),\n [bundlerUrl],\n );\n}\n"]}
|