@pepu-chain/sdk 0.2.1 → 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 +1 -2
- package/dist/aa/kernel.cjs +10 -9
- package/dist/aa/kernel.js +5 -4
- package/dist/aa/react-direct.cjs +10 -9
- package/dist/aa/react-direct.cjs.map +1 -1
- package/dist/aa/react-direct.js +5 -4
- package/dist/aa/react-direct.js.map +1 -1
- package/dist/aa/react.cjs +5 -4
- package/dist/aa/react.cjs.map +1 -1
- package/dist/aa/react.js +3 -2
- package/dist/aa/react.js.map +1 -1
- package/dist/aa.cjs +18 -17
- package/dist/aa.js +5 -4
- 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-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-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-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-BGALSKAF.cjs → chunk-VYMAZVIK.cjs} +4 -4
- package/dist/{chunk-BGALSKAF.cjs.map → chunk-VYMAZVIK.cjs.map} +1 -1
- package/dist/{chunk-F2R473FR.js → chunk-XR5ONV2Y.js} +3 -3
- package/dist/{chunk-F2R473FR.js.map → chunk-XR5ONV2Y.js.map} +1 -1
- package/dist/combo/react.cjs +61 -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 +1 -1
- package/dist/combo/react.js +58 -11
- package/dist/combo/react.js.map +1 -1
- package/dist/combo.cjs +41 -26
- package/dist/combo.cjs.map +1 -1
- package/dist/combo.d.cts +11 -0
- package/dist/combo.d.ts +11 -0
- package/dist/combo.js +31 -16
- package/dist/combo.js.map +1 -1
- package/dist/index.cjs +10 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/paymaster.cjs +37 -36
- package/dist/paymaster.cjs.map +1 -1
- package/dist/paymaster.js +3 -2
- package/dist/paymaster.js.map +1 -1
- package/dist/react.cjs +4 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +3 -2
- package/dist/react.js.map +1 -1
- package/dist/session/kernel.cjs +18 -17
- package/dist/session/kernel.js +6 -5
- package/package.json +1 -1
- package/dist/chunk-A5LP2UCS.cjs.map +0 -1
- package/dist/chunk-D52PADVY.js.map +0 -1
- package/dist/chunk-IY3ALPUJ.js.map +0 -1
- package/dist/chunk-WANILJZQ.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -337,8 +337,7 @@ only. The per-user free tier (100 PEPU/day and 50 PEPU/hour, TapScore only for
|
|
|
337
337
|
now) needs a verified Privy token from PEPU's own Privy app, so third-party
|
|
338
338
|
apps use a project. See [/paymaster](../../docs/sdk/paymaster.md) and
|
|
339
339
|
[/aa](../../docs/sdk/aa.md). The Google login + Kernel session key +
|
|
340
|
-
sponsorship combination is proven
|
|
341
|
-
run by a person.
|
|
340
|
+
sponsorship combination is proven live in a browser on mainnet (2026-10-14) against the hosted bundler and v2 paymaster.
|
|
342
341
|
|
|
343
342
|
```ts
|
|
344
343
|
import {
|
package/dist/aa/kernel.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* @pepu-chain/peer-guard */(function(){var p=["@zerodev/sdk","@zerodev/ecdsa-validator"];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/aa/kernel needs peer packages that are not installed: @zerodev/sdk @zerodev/ecdsa-validator. Install with: npm i @zerodev/sdk @zerodev/ecdsa-validator (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var chunkUQH4ZAXD_cjs = require('../chunk-UQH4ZAXD.cjs');
|
|
5
|
+
require('../chunk-DNWWZWUW.cjs');
|
|
6
6
|
var chunkAJS4UFQX_cjs = require('../chunk-AJS4UFQX.cjs');
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-4GEC7GUU.cjs');
|
|
8
|
+
require('../chunk-HTCX46RJ.cjs');
|
|
9
|
+
require('../chunk-65Y5UCQ7.cjs');
|
|
9
10
|
require('../chunk-4GINFJO6.cjs');
|
|
10
11
|
require('../chunk-VF3D6KLQ.cjs');
|
|
11
12
|
require('../chunk-DPCZJLB3.cjs');
|
|
@@ -15,23 +16,23 @@ require('../chunk-YQL7NISX.cjs');
|
|
|
15
16
|
|
|
16
17
|
Object.defineProperty(exports, "KERNEL_VERSION", {
|
|
17
18
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
19
|
+
get: function () { return chunkUQH4ZAXD_cjs.KERNEL_VERSION; }
|
|
19
20
|
});
|
|
20
21
|
Object.defineProperty(exports, "createPepuSponsoredClient", {
|
|
21
22
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
23
|
+
get: function () { return chunkUQH4ZAXD_cjs.createPepuSponsoredClient; }
|
|
23
24
|
});
|
|
24
25
|
Object.defineProperty(exports, "getKernelAddress", {
|
|
25
26
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
27
|
+
get: function () { return chunkUQH4ZAXD_cjs.getKernelAddress; }
|
|
27
28
|
});
|
|
28
29
|
Object.defineProperty(exports, "sendSponsored", {
|
|
29
30
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
31
|
+
get: function () { return chunkUQH4ZAXD_cjs.sendSponsored; }
|
|
31
32
|
});
|
|
32
33
|
Object.defineProperty(exports, "toPepuKernelAccount", {
|
|
33
34
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
35
|
+
get: function () { return chunkUQH4ZAXD_cjs.toPepuKernelAccount; }
|
|
35
36
|
});
|
|
36
37
|
Object.defineProperty(exports, "encodeKernelExecute", {
|
|
37
38
|
enumerable: true,
|
package/dist/aa/kernel.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export { KERNEL_VERSION, createPepuSponsoredClient, getKernelAddress, sendSponsored, toPepuKernelAccount } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { KERNEL_VERSION, createPepuSponsoredClient, getKernelAddress, sendSponsored, toPepuKernelAccount } from '../chunk-QIDMFFAQ.js';
|
|
2
|
+
import '../chunk-QZKUPCUD.js';
|
|
3
3
|
export { encodeKernelExecute } from '../chunk-VBH3JLQ5.js';
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-RSPAN44L.js';
|
|
5
|
+
import '../chunk-GFKIM7HT.js';
|
|
6
|
+
import '../chunk-GIZNH65Q.js';
|
|
6
7
|
import '../chunk-J6UXXHBE.js';
|
|
7
8
|
import '../chunk-XC4IBCI2.js';
|
|
8
9
|
import '../chunk-VTQIHMF3.js';
|
package/dist/aa/react-direct.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* @pepu-chain/peer-guard */(function(){var p=["react","@privy-io/react-auth","@zerodev/sdk","@zerodev/ecdsa-validator"];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/aa/react-direct needs peer packages that are not installed: react @privy-io/react-auth @zerodev/sdk @zerodev/ecdsa-validator. Install with: npm i react @privy-io/react-auth @zerodev/sdk @zerodev/ecdsa-validator (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var chunkUQH4ZAXD_cjs = require('../chunk-UQH4ZAXD.cjs');
|
|
5
|
+
require('../chunk-DNWWZWUW.cjs');
|
|
6
6
|
require('../chunk-AJS4UFQX.cjs');
|
|
7
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-4GEC7GUU.cjs');
|
|
8
8
|
var chunkRCMKPJZO_cjs = require('../chunk-RCMKPJZO.cjs');
|
|
9
|
-
var
|
|
9
|
+
var chunkHTCX46RJ_cjs = require('../chunk-HTCX46RJ.cjs');
|
|
10
10
|
require('../chunk-K7JSQPZO.cjs');
|
|
11
|
+
require('../chunk-65Y5UCQ7.cjs');
|
|
11
12
|
var chunkC7IC36XS_cjs = require('../chunk-C7IC36XS.cjs');
|
|
12
13
|
require('../chunk-4GINFJO6.cjs');
|
|
13
14
|
require('../chunk-VF3D6KLQ.cjs');
|
|
@@ -33,7 +34,7 @@ function useDirectSmartAccount() {
|
|
|
33
34
|
react.useEffect(() => {
|
|
34
35
|
if (!owner) return;
|
|
35
36
|
let cancelled = false;
|
|
36
|
-
|
|
37
|
+
chunkUQH4ZAXD_cjs.getKernelAddress(publicClient(), owner).then((address) => {
|
|
37
38
|
if (!cancelled) setDerived({ owner, address });
|
|
38
39
|
}).catch(() => {
|
|
39
40
|
});
|
|
@@ -78,8 +79,8 @@ function useDirectSponsoredSend(o = {}) {
|
|
|
78
79
|
transport: viem.custom(provider)
|
|
79
80
|
});
|
|
80
81
|
const token = await getAccessToken();
|
|
81
|
-
const account = await
|
|
82
|
-
const kernel =
|
|
82
|
+
const account = await chunkUQH4ZAXD_cjs.toPepuKernelAccount({ publicClient: pc, owner });
|
|
83
|
+
const kernel = chunkUQH4ZAXD_cjs.createPepuSponsoredClient({
|
|
83
84
|
account,
|
|
84
85
|
publicClient: pc,
|
|
85
86
|
...o.bundlerUrl !== void 0 ? { bundlerUrl: o.bundlerUrl } : {},
|
|
@@ -87,12 +88,12 @@ function useDirectSponsoredSend(o = {}) {
|
|
|
87
88
|
...token ? { paymasterContext: chunkRCMKPJZO_cjs.buildPaymasterContext({ privyAccessToken: token }) } : {}
|
|
88
89
|
});
|
|
89
90
|
setStatus("submitting");
|
|
90
|
-
const out = await
|
|
91
|
+
const out = await chunkUQH4ZAXD_cjs.sendSponsored({ client: kernel, calls });
|
|
91
92
|
setResult(out);
|
|
92
93
|
setStatus("confirmed");
|
|
93
94
|
return out;
|
|
94
95
|
} catch (caught) {
|
|
95
|
-
const err = chunkYQL7NISX_cjs.toPepuError(caught) === caught ? caught :
|
|
96
|
+
const err = chunkYQL7NISX_cjs.toPepuError(caught) === caught ? caught : chunkHTCX46RJ_cjs.describeUserOpFailure(caught);
|
|
96
97
|
setError(err);
|
|
97
98
|
setStatus("error");
|
|
98
99
|
throw err;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/aa/react-direct.ts"],"names":["getPublicClient","pepuMainnet","useWallets","useState","useEffect","getKernelAddress","usePrivy","useRef","useCallback","PepuConfigError","createWalletClient","custom","toPepuKernelAccount","createPepuSponsoredClient","buildPaymasterContext","sendSponsored","toPepuError","describeUserOpFailure"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/aa/react-direct.ts"],"names":["getPublicClient","pepuMainnet","useWallets","useState","useEffect","getKernelAddress","usePrivy","useRef","useCallback","PepuConfigError","createWalletClient","custom","toPepuKernelAccount","createPepuSponsoredClient","buildPaymasterContext","sendSponsored","toPepuError","describeUserOpFailure"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiBA,kCAAgBC,6BAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAEA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAIC,oBAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAUO,SAAS,qBAAA,GAAqF;AACnG,EAAA,MAAM,WAAW,iBAAA,EAAkB;AACnC,EAAA,MAAM,QAAQ,QAAA,EAAU,OAAA;AACxB,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIC,cAAA,EAA2D;AAEzF,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,KAAA,EAAO;AACZ,IAAA,IAAI,SAAA,GAAY,KAAA;AAChB,IAAAC,kCAAA,CAAiB,cAAa,EAAG,KAAK,CAAA,CACnC,IAAA,CAAK,CAAC,OAAA,KAAY;A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A,SAAA,CAAU,GAAG,CAAA;AACb,QAAA,SAAA,CAAU,WAAW,CAAA;AACrB,QAAA,OAAO,GAAA;AAAA,MACT,SAAS,MAAA,EAAQ;AACf,QAAA,MAAM,MAAMC,6BAAA,CAAY,MAAM,MAAM,MAAA,GAAU,MAAA,GAAuBC,wCAAsB,MAAM,CAAA;AACjG,QAAA,QAAA,CAAS,GAAG,CAAA;AACZ,QAAA,SAAA,CAAU,OAAO,CAAA;AACjB,QAAA,MAAM,GAAA;AAAA,MACR,CAAA,SAAE;AACA,QAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAAA,MACrB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,QAAA,EAAU,cAAA,EAAgB,CAAA,CAAE,UAAA,EAAY,EAAE,YAAY;AAAA,GACzD;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,GAAI,MAAA,GAAS,EAAE,MAAA,EAAO,GAAI,EAAC,EAAI,GAAI,KAAA,GAAQ,EAAE,KAAA,EAAM,GAAI,EAAC,EAAG;AACpF","file":"react-direct.cjs","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react-direct: React hooks for sponsored transactions that\n * go through your own bundler and paymaster (no Privy Smart Wallets).\n *\n * Needs `react`, `@privy-io/react-auth` and the optional peers `@zerodev/sdk`\n * and `@zerodev/ecdsa-validator`. It builds a Kernel account for the Privy\n * embedded wallet and passes the Privy access token as paymaster context for\n * the free tier. Apps on Privy Smart Wallets use `@pepu-chain/sdk/aa/react`\n * instead, which never resolves ZeroDev.\n */\nimport { usePrivy, useWallets } from \"@privy-io/react-auth\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { createWalletClient, custom } from \"viem\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { buildPaymasterContext } from \"../erc7677.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { getKernelAddress, createPepuSponsoredClient, sendSponsored, toPepuKernelAccount } from \"./kernel.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model for the direct transport: `owner` is the Privy\n * embedded wallet (an EOA that signs), `smartAccount` is the Kernel address\n * derived from it with {@link getKernelAddress} (a read).\n *\n * @example\n * const { owner, smartAccount, ready } = useDirectSmartAccount();\n */\nexport function useDirectSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const owner = embedded?.address as Address | undefined;\n const [derived, setDerived] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner) return;\n let cancelled = false;\n getKernelAddress(publicClient(), owner)\n .then((address) => {\n if (!cancelled) setDerived({ owner, address });\n })\n .catch(() => {\n // Derivation is best effort; `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner]);\n\n const smartAccount = derived && derived.owner === owner ? derived.address : undefined;\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useDirectSponsoredSend} send. */\nexport type DirectSponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useDirectSponsoredSend}. */\nexport interface UseDirectSponsoredSendOptions {\n bundlerUrl?: string;\n paymasterUrl?: string;\n}\n\n/**\n * Send calls with gas sponsored through your own bundler and paymaster. Builds\n * a Kernel account for the embedded wallet and passes the Privy access token\n * as paymaster context for the free tier. One send at a time: a second call\n * while one is in flight is ignored.\n *\n * @example\n * const { send, status, result, error } = useDirectSponsoredSend();\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useDirectSponsoredSend(o: UseDirectSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: DirectSponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { getAccessToken } = usePrivy();\n const embedded = useEmbeddedWallet();\n const [status, setStatus] = useState<DirectSponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n if (!embedded) {\n throw new PepuConfigError(\"WALLET_NOT_PROVISIONED\", \"No Privy embedded wallet to own the smart account.\");\n }\n const pc = publicClient();\n const provider = await embedded.getEthereumProvider();\n const owner = createWalletClient({\n account: embedded.address as Address,\n chain: pepuMainnet,\n transport: custom(provider),\n });\n const token = await getAccessToken();\n const account = await toPepuKernelAccount({ publicClient: pc, owner });\n const kernel = createPepuSponsoredClient({\n account,\n publicClient: pc,\n ...(o.bundlerUrl !== undefined ? { bundlerUrl: o.bundlerUrl } : {}),\n ...(o.paymasterUrl !== undefined ? { paymasterUrl: o.paymasterUrl } : {}),\n ...(token ? { paymasterContext: buildPaymasterContext({ privyAccessToken: token }) } : {}),\n });\n setStatus(\"submitting\");\n const out = await sendSponsored({ client: kernel, calls });\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [embedded, getAccessToken, o.bundlerUrl, o.paymasterUrl],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n"]}
|
package/dist/aa/react-direct.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { getKernelAddress, toPepuKernelAccount, createPepuSponsoredClient, sendSponsored } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { getKernelAddress, toPepuKernelAccount, createPepuSponsoredClient, sendSponsored } from '../chunk-QIDMFFAQ.js';
|
|
2
|
+
import '../chunk-QZKUPCUD.js';
|
|
3
3
|
import '../chunk-VBH3JLQ5.js';
|
|
4
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-RSPAN44L.js';
|
|
5
5
|
import { buildPaymasterContext } from '../chunk-7PVR7QSE.js';
|
|
6
|
-
import { describeUserOpFailure } from '../chunk-
|
|
6
|
+
import { describeUserOpFailure } from '../chunk-GFKIM7HT.js';
|
|
7
7
|
import '../chunk-KJYNF5KH.js';
|
|
8
|
+
import '../chunk-GIZNH65Q.js';
|
|
8
9
|
import { getPublicClient } from '../chunk-OH3QMAIB.js';
|
|
9
10
|
import '../chunk-J6UXXHBE.js';
|
|
10
11
|
import '../chunk-XC4IBCI2.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/aa/react-direct.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/aa/react-direct.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA0BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiB,gBAAgB,WAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAEA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,UAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAUO,SA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A,CAAA,GAAY,EAAE,YAAA,EAAc,CAAA,CAAE,YAAA,EAAa,GAAI,EAAC;AAAA,UACvE,GAAI,KAAA,GAAQ,EAAE,gBAAA,EAAkB,qBAAA,CAAsB,EAAE,gBAAA,EAAkB,KAAA,EAAO,CAAA,EAAE,GAAI;AAAC,SACzF,CAAA;AACD,QAAA,SAAA,CAAU,YAAY,CAAA;AACtB,QAAA,MAAM,MAAM,MAAM,aAAA,CAAc,EAAE,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA;AACzD,QAAA,SAAA,CAAU,GAAG,CAAA;AACb,QAAA,SAAA,CAAU,WAAW,CAAA;AACrB,QAAA,OAAO,GAAA;AAAA,MACT,SAAS,MAAA,EAAQ;AACf,QAAA,MAAM,MAAM,WAAA,CAAY,MAAM,MAAM,MAAA,GAAU,MAAA,GAAuB,sBAAsB,MAAM,CAAA;AACjG,QAAA,QAAA,CAAS,GAAG,CAAA;AACZ,QAAA,SAAA,CAAU,OAAO,CAAA;AACjB,QAAA,MAAM,GAAA;AAAA,MACR,CAAA,SAAE;AACA,QAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAAA,MACrB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,QAAA,EAAU,cAAA,EAAgB,CAAA,CAAE,UAAA,EAAY,EAAE,YAAY;AAAA,GACzD;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,GAAI,MAAA,GAAS,EAAE,MAAA,EAAO,GAAI,EAAC,EAAI,GAAI,KAAA,GAAQ,EAAE,KAAA,EAAM,GAAI,EAAC,EAAG;AACpF","file":"react-direct.js","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react-direct: React hooks for sponsored transactions that\n * go through your own bundler and paymaster (no Privy Smart Wallets).\n *\n * Needs `react`, `@privy-io/react-auth` and the optional peers `@zerodev/sdk`\n * and `@zerodev/ecdsa-validator`. It builds a Kernel account for the Privy\n * embedded wallet and passes the Privy access token as paymaster context for\n * the free tier. Apps on Privy Smart Wallets use `@pepu-chain/sdk/aa/react`\n * instead, which never resolves ZeroDev.\n */\nimport { usePrivy, useWallets } from \"@privy-io/react-auth\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { createWalletClient, custom } from \"viem\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { buildPaymasterContext } from \"../erc7677.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { getKernelAddress, createPepuSponsoredClient, sendSponsored, toPepuKernelAccount } from \"./kernel.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model for the direct transport: `owner` is the Privy\n * embedded wallet (an EOA that signs), `smartAccount` is the Kernel address\n * derived from it with {@link getKernelAddress} (a read).\n *\n * @example\n * const { owner, smartAccount, ready } = useDirectSmartAccount();\n */\nexport function useDirectSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const owner = embedded?.address as Address | undefined;\n const [derived, setDerived] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner) return;\n let cancelled = false;\n getKernelAddress(publicClient(), owner)\n .then((address) => {\n if (!cancelled) setDerived({ owner, address });\n })\n .catch(() => {\n // Derivation is best effort; `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner]);\n\n const smartAccount = derived && derived.owner === owner ? derived.address : undefined;\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useDirectSponsoredSend} send. */\nexport type DirectSponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useDirectSponsoredSend}. */\nexport interface UseDirectSponsoredSendOptions {\n bundlerUrl?: string;\n paymasterUrl?: string;\n}\n\n/**\n * Send calls with gas sponsored through your own bundler and paymaster. Builds\n * a Kernel account for the embedded wallet and passes the Privy access token\n * as paymaster context for the free tier. One send at a time: a second call\n * while one is in flight is ignored.\n *\n * @example\n * const { send, status, result, error } = useDirectSponsoredSend();\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useDirectSponsoredSend(o: UseDirectSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: DirectSponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { getAccessToken } = usePrivy();\n const embedded = useEmbeddedWallet();\n const [status, setStatus] = useState<DirectSponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n if (!embedded) {\n throw new PepuConfigError(\"WALLET_NOT_PROVISIONED\", \"No Privy embedded wallet to own the smart account.\");\n }\n const pc = publicClient();\n const provider = await embedded.getEthereumProvider();\n const owner = createWalletClient({\n account: embedded.address as Address,\n chain: pepuMainnet,\n transport: custom(provider),\n });\n const token = await getAccessToken();\n const account = await toPepuKernelAccount({ publicClient: pc, owner });\n const kernel = createPepuSponsoredClient({\n account,\n publicClient: pc,\n ...(o.bundlerUrl !== undefined ? { bundlerUrl: o.bundlerUrl } : {}),\n ...(o.paymasterUrl !== undefined ? { paymasterUrl: o.paymasterUrl } : {}),\n ...(token ? { paymasterContext: buildPaymasterContext({ privyAccessToken: token }) } : {}),\n });\n setStatus(\"submitting\");\n const out = await sendSponsored({ client: kernel, calls });\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [embedded, getAccessToken, o.bundlerUrl, o.paymasterUrl],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n"]}
|
package/dist/aa/react.cjs
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/* @pepu-chain/peer-guard */(function(){var p=["react","@privy-io/react-auth","permissionless"];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/aa/react needs peer packages that are not installed: react @privy-io/react-auth permissionless. Install with: npm i react @privy-io/react-auth permissionless (or let create-pepu-app scaffold everything).";var x=new Error(m);x.code="PEPU_MISSING_PEER";throw x}}}})();
|
|
3
3
|
|
|
4
4
|
var chunkAJS4UFQX_cjs = require('../chunk-AJS4UFQX.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var chunkVYMAZVIK_cjs = require('../chunk-VYMAZVIK.cjs');
|
|
6
|
+
var chunkHTCX46RJ_cjs = require('../chunk-HTCX46RJ.cjs');
|
|
7
7
|
require('../chunk-K7JSQPZO.cjs');
|
|
8
|
+
require('../chunk-65Y5UCQ7.cjs');
|
|
8
9
|
var chunkC7IC36XS_cjs = require('../chunk-C7IC36XS.cjs');
|
|
9
10
|
var chunk4GINFJO6_cjs = require('../chunk-4GINFJO6.cjs');
|
|
10
11
|
require('../chunk-VF3D6KLQ.cjs');
|
|
@@ -94,7 +95,7 @@ function useSponsoredSend(_options = {}) {
|
|
|
94
95
|
setStatus("confirmed");
|
|
95
96
|
return out;
|
|
96
97
|
} catch (caught) {
|
|
97
|
-
const err = chunkYQL7NISX_cjs.toPepuError(caught) === caught ? caught :
|
|
98
|
+
const err = chunkYQL7NISX_cjs.toPepuError(caught) === caught ? caught : chunkHTCX46RJ_cjs.describeUserOpFailure(caught);
|
|
98
99
|
setError(err);
|
|
99
100
|
setStatus("error");
|
|
100
101
|
throw err;
|
|
@@ -121,7 +122,7 @@ function usePepuSponsorship(o = {}) {
|
|
|
121
122
|
let cancelled = false;
|
|
122
123
|
const run = async () => {
|
|
123
124
|
try {
|
|
124
|
-
const r = await
|
|
125
|
+
const r = await chunkVYMAZVIK_cjs.checkSponsorship({
|
|
125
126
|
publicClient: publicClient(),
|
|
126
127
|
...bundlerUrl !== void 0 ? { bundlerUrl } : {},
|
|
127
128
|
...paymasterUrl !== void 0 ? { paymasterUrl } : {}
|
package/dist/aa/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/aa/react.ts"],"names":["getPublicClient","pepuMainnet","useWallets","useSmartWallets","useRef","useState","useEffect","useCallback","PepuConfigError","normalizeCalls","userOpEventFromReceipt","txUrl","toPepuError","describeUserOpFailure","checkSponsorship"],"mappings":";;;;;;;;;;;;;;;AA+BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiBA,kCAAgBC,6BAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAGA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAIC,oBAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAaO,SAAS,mBAAA,GAAmF;AACjG,EAAA,MAAM,WAAW,iBAAA,EAAkB;AACnC,EAAA,MAAM,EAAE,MAAA,EAAQ,iBAAA,EA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AG,IAAA,EAAM,SAAA,EAAW,OAAO,MAAA,EAAQF,6BAAA,CAAY,CAAC,CAAA,CAAE,OAAA,EAAS,OAAO,CAACA,6BAAA,CAAY,CAAC,CAAA,CAAE,IAAI,GAAE,CAAE,CAAA;AAAA,QACnH;AAAA,MACF,CAAA,SAAE;AACA,QAAA,IAAI,CAAC,SAAA,EAAW,UAAA,CAAW,KAAK,CAAA;AAAA,MAClC;AAAA,IACF,CAAA;AACA,IAAA,KAAK,GAAA,EAAI;AACT,IAAA,MAAM,EAAA,GAAK,SAAS,CAAA,GAAI,WAAA,CAAY,MAAM,KAAK,GAAA,EAAI,EAAG,MAAM,CAAA,GAAI,MAAA;AAChE,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,IAAI,EAAA,KAAO,MAAA,EAAW,aAAA,CAAc,EAAE,CAAA;AAAA,IACxC,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,UAAA,EAAY,YAAY,CAAC,CAAA;AAErC,EAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAQ;AAC9B","file":"react.cjs","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react: React hooks for sponsored transactions with Privy\n * Smart Wallets.\n *\n * Needs `react`, `@privy-io/react-auth` and, because Privy's smart-wallets\n * module requires it, `permissionless`. It never references `@zerodev/*`,\n * statically or dynamically, so a bundler resolving it needs no ZeroDev. The\n * transport reads bundler and paymaster URLs from the Privy dashboard. To use\n * your own bundler and paymaster instead, see `@pepu-chain/sdk/aa/react-direct`.\n *\n * Flow ported from `templates/sponsored-demo/components/sponsored-tap-demo.tsx`\n * (smart-wallet client, in-flight guard, real error text via describeUserOpFailure).\n */\nimport { useWallets } from \"@privy-io/react-auth\";\nimport { useSmartWallets } from \"@privy-io/react-auth/smart-wallets\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { txUrl } from \"../explorer.js\";\nimport { normalizeCalls, userOpEventFromReceipt } from \"./calls.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { checkSponsorship } from \"./status.js\";\nimport type { SponsorshipReport } from \"./status.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\n/** The Privy embedded wallet, the owner of the smart account. */\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model made explicit: `owner` is the Privy embedded wallet\n * (an EOA that signs), `smartAccount` is the Kernel account that sends and\n * holds assets. With Privy Smart Wallets the smart account comes from the\n * provider: `useSmartWallets().client`, or, while that is still unset,\n * `getClientForChain({ id: 97741 })`. For an address derived without Privy\n * Smart Wallets, use `useDirectSmartAccount` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { owner, smartAccount, ready } = usePepuSmartAccount();\n */\nexport function usePepuSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const { client, getClientForChain } = useSmartWallets();\n const getClientRef = useRef(getClientForChain);\n getClientRef.current = getClientForChain;\n const owner = embedded?.address as Address | undefined;\n const fromProvider = client?.account?.address as Address | undefined;\n const [resolved, setResolved] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner || fromProvider) return;\n let cancelled = false;\n // Privy's per-chain client may populate after `client`.\n Promise.resolve(getClientRef.current?.({ id: pepuMainnet.id }))\n .then((c) => {\n const address = c?.account?.address as Address | undefined;\n if (!cancelled && address) setResolved({ owner, address });\n })\n .catch(() => {\n // Smart Wallets not configured for this chain: `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner, fromProvider]);\n\n const smartAccount = fromProvider ?? (resolved && resolved.owner === owner ? resolved.address : undefined);\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useSponsoredSend} send. */\nexport type SponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useSponsoredSend}. */\nexport interface UseSponsoredSendOptions {\n /** The only transport here. Your own bundler and paymaster: `useDirectSponsoredSend` in `@pepu-chain/sdk/aa/react-direct`. */\n transport?: \"privy-smart-wallets\";\n}\n\n/**\n * Send calls with gas sponsored through Privy's smart-wallet client (bundler\n * and paymaster URLs come from the Privy dashboard). One send at a time: a\n * second call while one is in flight is ignored. For your own bundler and\n * paymaster, use `useDirectSponsoredSend` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { send, status, result, error } = useSponsoredSend({ transport: \"privy-smart-wallets\" });\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useSponsoredSend(_options: UseSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: SponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { client, getClientForChain } = useSmartWallets();\n const [status, setStatus] = useState<SponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n const encoded = normalizeCalls(calls);\n const pc = publicClient();\n\n\n const sw = client ?? (await getClientForChain({ id: pepuMainnet.id }));\n if (!sw) {\n throw new PepuConfigError(\n \"CONFIG_PRIVY_DASHBOARD\",\n \"No Privy smart-wallet client is available.\",\n { hint: 'Enable \"Smart Wallets\" for chain 97741 in the Privy dashboard and wrap the app in SmartWalletsProvider.' },\n );\n }\n setStatus(\"submitting\");\n const hash =\n encoded.length === 1 && encoded[0]\n ? await sw.sendTransaction({ to: encoded[0].to, data: encoded[0].data, value: encoded[0].value })\n : await sw.sendTransaction({ calls: encoded });\n const receipt = await pc.waitForTransactionReceipt({ hash });\n const paid = userOpEventFromReceipt(receipt, sw.account.address as Address);\n const out: SponsoredResult = {\n userOpHash: paid?.userOpHash ?? null,\n transactionHash: hash,\n success: paid?.success ?? receipt.status === \"success\",\n paymaster: paid?.paymaster ?? null,\n actualGasCostWei: paid?.actualGasCost ?? 0n,\n explorerUrl: txUrl(pepuMainnet, hash),\n };\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [client, getClientForChain],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n\n/**\n * Live sponsorship status, polled. The live replacement for the deprecated\n * `useSponsorshipStatus` (which always said unavailable).\n *\n * @example\n * const s = usePepuSponsorship({ pollMs: 15000 });\n * if (!s.loading && !s.available) console.log(s.reason, s.fixes);\n */\nexport function usePepuSponsorship(\n o: { pollMs?: number; bundlerUrl?: string; paymasterUrl?: string } = {},\n): SponsorshipReport & { loading: boolean } {\n const [report, setReport] = useState<SponsorshipReport>({\n available: false,\n transport: \"none\",\n bundler: { configured: false },\n paymaster: { configured: false },\n reason: \"Checking sponsorship status.\",\n fixes: [],\n });\n const [loading, setLoading] = useState(true);\n const { pollMs = 30_000, bundlerUrl, paymasterUrl } = o;\n\n useEffect(() => {\n let cancelled = false;\n const run = async (): Promise<void> => {\n try {\n const r = await checkSponsorship({\n publicClient: publicClient(),\n ...(bundlerUrl !== undefined ? { bundlerUrl } : {}),\n ...(paymasterUrl !== undefined ? { paymasterUrl } : {}),\n });\n if (!cancelled) setReport(r);\n } catch (e) {\n if (!cancelled) {\n setReport((prev) => ({ ...prev, available: false, reason: toPepuError(e).message, fixes: [toPepuError(e).hint] }));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n void run();\n const id = pollMs > 0 ? setInterval(() => void run(), pollMs) : undefined;\n return () => {\n cancelled = true;\n if (id !== undefined) clearInterval(id);\n };\n }, [pollMs, bundlerUrl, paymasterUrl]);\n\n return { ...report, loading };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/aa/react.ts"],"names":["getPublicClient","pepuMainnet","useWallets","useSmartWallets","useRef","useState","useEffect","useCallback","PepuConfigError","normalizeCalls","userOpEventFromReceipt","txUrl","toPepuError","describeUserOpFailure","checkSponsorship"],"mappings":";;;;;;;;;;;;;;;;AA+BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiBA,kCAAgBC,6BAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAGA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAIC,oBAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAaO,SAAS,mBAAA,GAAmF;AACjG,EAAA,MAAM,WAAW,iBAAA,EAAkB;AACnC,EAAA,MAAM,EAAE,MAAA,EAAQ,iBAAA,EAAkB,GAAIC,4BAAA,EAAgB;AACtD,EAAA,MAAM,YAAA,GAAeC,aAAO,iBAAiB,CAAA;AAC7C,EAAA,YAAA,CAAa,OAAA,GAAU,iBAAA;AACvB,EAAA,MAAM,QAAQ,QAAA,EAAU,OAAA;AACxB,EAAA,MAAM,YAAA,GA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AACA,QAAA,IAAI,CAAC,SAAA,EAAW,UAAA,CAAW,KAAK,CAAA;AAAA,MAClC;AAAA,IACF,CAAA;AACA,IAAA,KAAK,GAAA,EAAI;AACT,IAAA,MAAM,EAAA,GAAK,SAAS,CAAA,GAAI,WAAA,CAAY,MAAM,KAAK,GAAA,EAAI,EAAG,MAAM,CAAA,GAAI,MAAA;AAChE,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,IAAI,EAAA,KAAO,MAAA,EAAW,aAAA,CAAc,EAAE,CAAA;AAAA,IACxC,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,UAAA,EAAY,YAAY,CAAC,CAAA;AAErC,EAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAQ;AAC9B","file":"react.cjs","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react: React hooks for sponsored transactions with Privy\n * Smart Wallets.\n *\n * Needs `react`, `@privy-io/react-auth` and, because Privy's smart-wallets\n * module requires it, `permissionless`. It never references `@zerodev/*`,\n * statically or dynamically, so a bundler resolving it needs no ZeroDev. The\n * transport reads bundler and paymaster URLs from the Privy dashboard. To use\n * your own bundler and paymaster instead, see `@pepu-chain/sdk/aa/react-direct`.\n *\n * Flow ported from `templates/sponsored-demo/components/sponsored-tap-demo.tsx`\n * (smart-wallet client, in-flight guard, real error text via describeUserOpFailure).\n */\nimport { useWallets } from \"@privy-io/react-auth\";\nimport { useSmartWallets } from \"@privy-io/react-auth/smart-wallets\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { txUrl } from \"../explorer.js\";\nimport { normalizeCalls, userOpEventFromReceipt } from \"./calls.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { checkSponsorship } from \"./status.js\";\nimport type { SponsorshipReport } from \"./status.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\n/** The Privy embedded wallet, the owner of the smart account. */\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model made explicit: `owner` is the Privy embedded wallet\n * (an EOA that signs), `smartAccount` is the Kernel account that sends and\n * holds assets. With Privy Smart Wallets the smart account comes from the\n * provider: `useSmartWallets().client`, or, while that is still unset,\n * `getClientForChain({ id: 97741 })`. For an address derived without Privy\n * Smart Wallets, use `useDirectSmartAccount` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { owner, smartAccount, ready } = usePepuSmartAccount();\n */\nexport function usePepuSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const { client, getClientForChain } = useSmartWallets();\n const getClientRef = useRef(getClientForChain);\n getClientRef.current = getClientForChain;\n const owner = embedded?.address as Address | undefined;\n const fromProvider = client?.account?.address as Address | undefined;\n const [resolved, setResolved] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner || fromProvider) return;\n let cancelled = false;\n // Privy's per-chain client may populate after `client`.\n Promise.resolve(getClientRef.current?.({ id: pepuMainnet.id }))\n .then((c) => {\n const address = c?.account?.address as Address | undefined;\n if (!cancelled && address) setResolved({ owner, address });\n })\n .catch(() => {\n // Smart Wallets not configured for this chain: `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner, fromProvider]);\n\n const smartAccount = fromProvider ?? (resolved && resolved.owner === owner ? resolved.address : undefined);\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useSponsoredSend} send. */\nexport type SponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useSponsoredSend}. */\nexport interface UseSponsoredSendOptions {\n /** The only transport here. Your own bundler and paymaster: `useDirectSponsoredSend` in `@pepu-chain/sdk/aa/react-direct`. */\n transport?: \"privy-smart-wallets\";\n}\n\n/**\n * Send calls with gas sponsored through Privy's smart-wallet client (bundler\n * and paymaster URLs come from the Privy dashboard). One send at a time: a\n * second call while one is in flight is ignored. For your own bundler and\n * paymaster, use `useDirectSponsoredSend` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { send, status, result, error } = useSponsoredSend({ transport: \"privy-smart-wallets\" });\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useSponsoredSend(_options: UseSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: SponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { client, getClientForChain } = useSmartWallets();\n const [status, setStatus] = useState<SponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n const encoded = normalizeCalls(calls);\n const pc = publicClient();\n\n\n const sw = client ?? (await getClientForChain({ id: pepuMainnet.id }));\n if (!sw) {\n throw new PepuConfigError(\n \"CONFIG_PRIVY_DASHBOARD\",\n \"No Privy smart-wallet client is available.\",\n { hint: 'Enable \"Smart Wallets\" for chain 97741 in the Privy dashboard and wrap the app in SmartWalletsProvider.' },\n );\n }\n setStatus(\"submitting\");\n const hash =\n encoded.length === 1 && encoded[0]\n ? await sw.sendTransaction({ to: encoded[0].to, data: encoded[0].data, value: encoded[0].value })\n : await sw.sendTransaction({ calls: encoded });\n const receipt = await pc.waitForTransactionReceipt({ hash });\n const paid = userOpEventFromReceipt(receipt, sw.account.address as Address);\n const out: SponsoredResult = {\n userOpHash: paid?.userOpHash ?? null,\n transactionHash: hash,\n success: paid?.success ?? receipt.status === \"success\",\n paymaster: paid?.paymaster ?? null,\n actualGasCostWei: paid?.actualGasCost ?? 0n,\n explorerUrl: txUrl(pepuMainnet, hash),\n };\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [client, getClientForChain],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n\n/**\n * Live sponsorship status, polled. The live replacement for the deprecated\n * `useSponsorshipStatus` (which always said unavailable).\n *\n * @example\n * const s = usePepuSponsorship({ pollMs: 15000 });\n * if (!s.loading && !s.available) console.log(s.reason, s.fixes);\n */\nexport function usePepuSponsorship(\n o: { pollMs?: number; bundlerUrl?: string; paymasterUrl?: string } = {},\n): SponsorshipReport & { loading: boolean } {\n const [report, setReport] = useState<SponsorshipReport>({\n available: false,\n transport: \"none\",\n bundler: { configured: false },\n paymaster: { configured: false },\n reason: \"Checking sponsorship status.\",\n fixes: [],\n });\n const [loading, setLoading] = useState(true);\n const { pollMs = 30_000, bundlerUrl, paymasterUrl } = o;\n\n useEffect(() => {\n let cancelled = false;\n const run = async (): Promise<void> => {\n try {\n const r = await checkSponsorship({\n publicClient: publicClient(),\n ...(bundlerUrl !== undefined ? { bundlerUrl } : {}),\n ...(paymasterUrl !== undefined ? { paymasterUrl } : {}),\n });\n if (!cancelled) setReport(r);\n } catch (e) {\n if (!cancelled) {\n setReport((prev) => ({ ...prev, available: false, reason: toPepuError(e).message, fixes: [toPepuError(e).hint] }));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n void run();\n const id = pollMs > 0 ? setInterval(() => void run(), pollMs) : undefined;\n return () => {\n cancelled = true;\n if (id !== undefined) clearInterval(id);\n };\n }, [pollMs, bundlerUrl, paymasterUrl]);\n\n return { ...report, loading };\n}\n"]}
|
package/dist/aa/react.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { normalizeCalls, userOpEventFromReceipt } from '../chunk-VBH3JLQ5.js';
|
|
2
|
-
import { checkSponsorship } from '../chunk-
|
|
3
|
-
import { describeUserOpFailure } from '../chunk-
|
|
2
|
+
import { checkSponsorship } from '../chunk-XR5ONV2Y.js';
|
|
3
|
+
import { describeUserOpFailure } from '../chunk-GFKIM7HT.js';
|
|
4
4
|
import '../chunk-KJYNF5KH.js';
|
|
5
|
+
import '../chunk-GIZNH65Q.js';
|
|
5
6
|
import { getPublicClient } from '../chunk-OH3QMAIB.js';
|
|
6
7
|
import { txUrl } from '../chunk-J6UXXHBE.js';
|
|
7
8
|
import '../chunk-XC4IBCI2.js';
|
package/dist/aa/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/aa/react.ts"],"names":[],"mappings":";;;;;;;;;;;;;AA+BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiB,gBAAgB,WAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAGA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,UAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAaO,SAAS,mBAAA,GAAmF;AACjG,EAAA,MAAM,WAAW,iBAAA,EAAkB;AACnC,EAAA,MAAM,EAAE,MAAA,EAAQ,iBAAA,EA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Q,WAAA,CAAY,CAAC,CAAA,CAAE,OAAA,EAAS,OAAO,CAAC,WAAA,CAAY,CAAC,CAAA,CAAE,IAAI,GAAE,CAAE,CAAA;AAAA,QACnH;AAAA,MACF,CAAA,SAAE;AACA,QAAA,IAAI,CAAC,SAAA,EAAW,UAAA,CAAW,KAAK,CAAA;AAAA,MAClC;AAAA,IACF,CAAA;AACA,IAAA,KAAK,GAAA,EAAI;AACT,IAAA,MAAM,EAAA,GAAK,SAAS,CAAA,GAAI,WAAA,CAAY,MAAM,KAAK,GAAA,EAAI,EAAG,MAAM,CAAA,GAAI,MAAA;AAChE,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,IAAI,EAAA,KAAO,MAAA,EAAW,aAAA,CAAc,EAAE,CAAA;AAAA,IACxC,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,UAAA,EAAY,YAAY,CAAC,CAAA;AAErC,EAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAQ;AAC9B","file":"react.js","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react: React hooks for sponsored transactions with Privy\n * Smart Wallets.\n *\n * Needs `react`, `@privy-io/react-auth` and, because Privy's smart-wallets\n * module requires it, `permissionless`. It never references `@zerodev/*`,\n * statically or dynamically, so a bundler resolving it needs no ZeroDev. The\n * transport reads bundler and paymaster URLs from the Privy dashboard. To use\n * your own bundler and paymaster instead, see `@pepu-chain/sdk/aa/react-direct`.\n *\n * Flow ported from `templates/sponsored-demo/components/sponsored-tap-demo.tsx`\n * (smart-wallet client, in-flight guard, real error text via describeUserOpFailure).\n */\nimport { useWallets } from \"@privy-io/react-auth\";\nimport { useSmartWallets } from \"@privy-io/react-auth/smart-wallets\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { txUrl } from \"../explorer.js\";\nimport { normalizeCalls, userOpEventFromReceipt } from \"./calls.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { checkSponsorship } from \"./status.js\";\nimport type { SponsorshipReport } from \"./status.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\n/** The Privy embedded wallet, the owner of the smart account. */\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model made explicit: `owner` is the Privy embedded wallet\n * (an EOA that signs), `smartAccount` is the Kernel account that sends and\n * holds assets. With Privy Smart Wallets the smart account comes from the\n * provider: `useSmartWallets().client`, or, while that is still unset,\n * `getClientForChain({ id: 97741 })`. For an address derived without Privy\n * Smart Wallets, use `useDirectSmartAccount` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { owner, smartAccount, ready } = usePepuSmartAccount();\n */\nexport function usePepuSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const { client, getClientForChain } = useSmartWallets();\n const getClientRef = useRef(getClientForChain);\n getClientRef.current = getClientForChain;\n const owner = embedded?.address as Address | undefined;\n const fromProvider = client?.account?.address as Address | undefined;\n const [resolved, setResolved] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner || fromProvider) return;\n let cancelled = false;\n // Privy's per-chain client may populate after `client`.\n Promise.resolve(getClientRef.current?.({ id: pepuMainnet.id }))\n .then((c) => {\n const address = c?.account?.address as Address | undefined;\n if (!cancelled && address) setResolved({ owner, address });\n })\n .catch(() => {\n // Smart Wallets not configured for this chain: `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner, fromProvider]);\n\n const smartAccount = fromProvider ?? (resolved && resolved.owner === owner ? resolved.address : undefined);\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useSponsoredSend} send. */\nexport type SponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useSponsoredSend}. */\nexport interface UseSponsoredSendOptions {\n /** The only transport here. Your own bundler and paymaster: `useDirectSponsoredSend` in `@pepu-chain/sdk/aa/react-direct`. */\n transport?: \"privy-smart-wallets\";\n}\n\n/**\n * Send calls with gas sponsored through Privy's smart-wallet client (bundler\n * and paymaster URLs come from the Privy dashboard). One send at a time: a\n * second call while one is in flight is ignored. For your own bundler and\n * paymaster, use `useDirectSponsoredSend` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { send, status, result, error } = useSponsoredSend({ transport: \"privy-smart-wallets\" });\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useSponsoredSend(_options: UseSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: SponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { client, getClientForChain } = useSmartWallets();\n const [status, setStatus] = useState<SponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n const encoded = normalizeCalls(calls);\n const pc = publicClient();\n\n\n const sw = client ?? (await getClientForChain({ id: pepuMainnet.id }));\n if (!sw) {\n throw new PepuConfigError(\n \"CONFIG_PRIVY_DASHBOARD\",\n \"No Privy smart-wallet client is available.\",\n { hint: 'Enable \"Smart Wallets\" for chain 97741 in the Privy dashboard and wrap the app in SmartWalletsProvider.' },\n );\n }\n setStatus(\"submitting\");\n const hash =\n encoded.length === 1 && encoded[0]\n ? await sw.sendTransaction({ to: encoded[0].to, data: encoded[0].data, value: encoded[0].value })\n : await sw.sendTransaction({ calls: encoded });\n const receipt = await pc.waitForTransactionReceipt({ hash });\n const paid = userOpEventFromReceipt(receipt, sw.account.address as Address);\n const out: SponsoredResult = {\n userOpHash: paid?.userOpHash ?? null,\n transactionHash: hash,\n success: paid?.success ?? receipt.status === \"success\",\n paymaster: paid?.paymaster ?? null,\n actualGasCostWei: paid?.actualGasCost ?? 0n,\n explorerUrl: txUrl(pepuMainnet, hash),\n };\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [client, getClientForChain],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n\n/**\n * Live sponsorship status, polled. The live replacement for the deprecated\n * `useSponsorshipStatus` (which always said unavailable).\n *\n * @example\n * const s = usePepuSponsorship({ pollMs: 15000 });\n * if (!s.loading && !s.available) console.log(s.reason, s.fixes);\n */\nexport function usePepuSponsorship(\n o: { pollMs?: number; bundlerUrl?: string; paymasterUrl?: string } = {},\n): SponsorshipReport & { loading: boolean } {\n const [report, setReport] = useState<SponsorshipReport>({\n available: false,\n transport: \"none\",\n bundler: { configured: false },\n paymaster: { configured: false },\n reason: \"Checking sponsorship status.\",\n fixes: [],\n });\n const [loading, setLoading] = useState(true);\n const { pollMs = 30_000, bundlerUrl, paymasterUrl } = o;\n\n useEffect(() => {\n let cancelled = false;\n const run = async (): Promise<void> => {\n try {\n const r = await checkSponsorship({\n publicClient: publicClient(),\n ...(bundlerUrl !== undefined ? { bundlerUrl } : {}),\n ...(paymasterUrl !== undefined ? { paymasterUrl } : {}),\n });\n if (!cancelled) setReport(r);\n } catch (e) {\n if (!cancelled) {\n setReport((prev) => ({ ...prev, available: false, reason: toPepuError(e).message, fixes: [toPepuError(e).hint] }));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n void run();\n const id = pollMs > 0 ? setInterval(() => void run(), pollMs) : undefined;\n return () => {\n cancelled = true;\n if (id !== undefined) clearInterval(id);\n };\n }, [pollMs, bundlerUrl, paymasterUrl]);\n\n return { ...report, loading };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/aa/react.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AA+BA,IAAI,YAAA;AACJ,SAAS,YAAA,GAA6B;AACpC,EAAA,YAAA,KAAiB,gBAAgB,WAAW,CAAA;AAC5C,EAAA,OAAO,YAAA;AACT;AAGA,SAAS,iBAAA,GAAoB;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,UAAA,EAAW;AAC/B,EAAA,OAAO,QAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,qBAAqB,OAAO,CAAA;AAC3D;AAaO,SAAS,mBAAA,GAAmF;AACjG,EAAA,MAAM,WAAW,iBAAA,EAAkB;AACnC,EAAA,MAAM,EAAE,MAAA,EAAQ,iBAAA,EAAkB,GAAI,eAAA,EAAgB;AACtD,EAAA,MAAM,YAAA,GAAe,OAAO,iBAAiB,CAAA;AAC7C,EAAA,YAAA,CAAa,OAAA,GAAU,iBAAA;AACvB,EAAA,MAAM,QAAQ,QAAA,EAAU,OAAA;AACxB,EAAA,MAAM,YAAA,GAAe,QAAQ,OAAA,EAAS,OAAA;AACtC,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,QAAA,EAA2D;AAE3F,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,SAAS,YAAA,EAAc;AAC5B,IAAA,I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AAA;AAChE,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,IAAI,EAAA,KAAO,MAAA,EAAW,aAAA,CAAc,EAAE,CAAA;AAAA,IACxC,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,UAAA,EAAY,YAAY,CAAC,CAAA;AAErC,EAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAQ;AAC9B","file":"react.js","sourcesContent":["/**\n * @pepu-chain/sdk/aa/react: React hooks for sponsored transactions with Privy\n * Smart Wallets.\n *\n * Needs `react`, `@privy-io/react-auth` and, because Privy's smart-wallets\n * module requires it, `permissionless`. It never references `@zerodev/*`,\n * statically or dynamically, so a bundler resolving it needs no ZeroDev. The\n * transport reads bundler and paymaster URLs from the Privy dashboard. To use\n * your own bundler and paymaster instead, see `@pepu-chain/sdk/aa/react-direct`.\n *\n * Flow ported from `templates/sponsored-demo/components/sponsored-tap-demo.tsx`\n * (smart-wallet client, in-flight guard, real error text via describeUserOpFailure).\n */\nimport { useWallets } from \"@privy-io/react-auth\";\nimport { useSmartWallets } from \"@privy-io/react-auth/smart-wallets\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Address, PublicClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { getPublicClient } from \"../client.js\";\nimport { PepuConfigError, toPepuError } from \"../errors.js\";\nimport type { PepuError } from \"../errors.js\";\nimport { txUrl } from \"../explorer.js\";\nimport { normalizeCalls, userOpEventFromReceipt } from \"./calls.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport { checkSponsorship } from \"./status.js\";\nimport type { SponsorshipReport } from \"./status.js\";\nimport type { Call, SponsoredResult } from \"./types.js\";\n\nexport type { Call, SponsoredResult } from \"./types.js\";\n\nlet sharedClient: PublicClient | undefined;\nfunction publicClient(): PublicClient {\n sharedClient ??= getPublicClient(pepuMainnet) as unknown as PublicClient;\n return sharedClient;\n}\n\n/** The Privy embedded wallet, the owner of the smart account. */\nfunction useEmbeddedWallet() {\n const { wallets } = useWallets();\n return wallets.find((w) => w.walletClientType === \"privy\");\n}\n\n/**\n * The two-address model made explicit: `owner` is the Privy embedded wallet\n * (an EOA that signs), `smartAccount` is the Kernel account that sends and\n * holds assets. With Privy Smart Wallets the smart account comes from the\n * provider: `useSmartWallets().client`, or, while that is still unset,\n * `getClientForChain({ id: 97741 })`. For an address derived without Privy\n * Smart Wallets, use `useDirectSmartAccount` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { owner, smartAccount, ready } = usePepuSmartAccount();\n */\nexport function usePepuSmartAccount(): { owner?: Address; smartAccount?: Address; ready: boolean } {\n const embedded = useEmbeddedWallet();\n const { client, getClientForChain } = useSmartWallets();\n const getClientRef = useRef(getClientForChain);\n getClientRef.current = getClientForChain;\n const owner = embedded?.address as Address | undefined;\n const fromProvider = client?.account?.address as Address | undefined;\n const [resolved, setResolved] = useState<{ owner: Address; address: Address } | undefined>();\n\n useEffect(() => {\n if (!owner || fromProvider) return;\n let cancelled = false;\n // Privy's per-chain client may populate after `client`.\n Promise.resolve(getClientRef.current?.({ id: pepuMainnet.id }))\n .then((c) => {\n const address = c?.account?.address as Address | undefined;\n if (!cancelled && address) setResolved({ owner, address });\n })\n .catch(() => {\n // Smart Wallets not configured for this chain: `ready` stays false.\n });\n return () => {\n cancelled = true;\n };\n }, [owner, fromProvider]);\n\n const smartAccount = fromProvider ?? (resolved && resolved.owner === owner ? resolved.address : undefined);\n return {\n ...(owner ? { owner } : {}),\n ...(smartAccount ? { smartAccount } : {}),\n ready: owner !== undefined && smartAccount !== undefined,\n };\n}\n\n/** Status of a {@link useSponsoredSend} send. */\nexport type SponsoredSendStatus = \"idle\" | \"signing\" | \"submitting\" | \"confirmed\" | \"error\";\n\n/** Options for {@link useSponsoredSend}. */\nexport interface UseSponsoredSendOptions {\n /** The only transport here. Your own bundler and paymaster: `useDirectSponsoredSend` in `@pepu-chain/sdk/aa/react-direct`. */\n transport?: \"privy-smart-wallets\";\n}\n\n/**\n * Send calls with gas sponsored through Privy's smart-wallet client (bundler\n * and paymaster URLs come from the Privy dashboard). One send at a time: a\n * second call while one is in flight is ignored. For your own bundler and\n * paymaster, use `useDirectSponsoredSend` from `@pepu-chain/sdk/aa/react-direct`.\n *\n * @example\n * const { send, status, result, error } = useSponsoredSend({ transport: \"privy-smart-wallets\" });\n * await send([{ to: tapScore, abi: tapScoreAbi, functionName: \"tap\" }]);\n */\nexport function useSponsoredSend(_options: UseSponsoredSendOptions = {}): {\n send: (calls: Call[]) => Promise<SponsoredResult>;\n status: SponsoredSendStatus;\n result?: SponsoredResult;\n error?: PepuError;\n} {\n const { client, getClientForChain } = useSmartWallets();\n const [status, setStatus] = useState<SponsoredSendStatus>(\"idle\");\n const [result, setResult] = useState<SponsoredResult | undefined>();\n const [error, setError] = useState<PepuError | undefined>();\n const inFlight = useRef(false);\n\n const send = useCallback(\n async (calls: Call[]): Promise<SponsoredResult> => {\n if (inFlight.current) {\n throw new PepuConfigError(\"UNKNOWN\", \"A sponsored send is already in progress.\", {\n hint: \"Wait for the current send to finish.\",\n });\n }\n inFlight.current = true;\n setStatus(\"signing\");\n setError(undefined);\n setResult(undefined);\n try {\n const encoded = normalizeCalls(calls);\n const pc = publicClient();\n\n\n const sw = client ?? (await getClientForChain({ id: pepuMainnet.id }));\n if (!sw) {\n throw new PepuConfigError(\n \"CONFIG_PRIVY_DASHBOARD\",\n \"No Privy smart-wallet client is available.\",\n { hint: 'Enable \"Smart Wallets\" for chain 97741 in the Privy dashboard and wrap the app in SmartWalletsProvider.' },\n );\n }\n setStatus(\"submitting\");\n const hash =\n encoded.length === 1 && encoded[0]\n ? await sw.sendTransaction({ to: encoded[0].to, data: encoded[0].data, value: encoded[0].value })\n : await sw.sendTransaction({ calls: encoded });\n const receipt = await pc.waitForTransactionReceipt({ hash });\n const paid = userOpEventFromReceipt(receipt, sw.account.address as Address);\n const out: SponsoredResult = {\n userOpHash: paid?.userOpHash ?? null,\n transactionHash: hash,\n success: paid?.success ?? receipt.status === \"success\",\n paymaster: paid?.paymaster ?? null,\n actualGasCostWei: paid?.actualGasCost ?? 0n,\n explorerUrl: txUrl(pepuMainnet, hash),\n };\n setResult(out);\n setStatus(\"confirmed\");\n return out;\n } catch (caught) {\n const err = toPepuError(caught) === caught ? (caught as PepuError) : describeUserOpFailure(caught);\n setError(err);\n setStatus(\"error\");\n throw err;\n } finally {\n inFlight.current = false;\n }\n },\n [client, getClientForChain],\n );\n\n return { send, status, ...(result ? { result } : {}), ...(error ? { error } : {}) };\n}\n\n/**\n * Live sponsorship status, polled. The live replacement for the deprecated\n * `useSponsorshipStatus` (which always said unavailable).\n *\n * @example\n * const s = usePepuSponsorship({ pollMs: 15000 });\n * if (!s.loading && !s.available) console.log(s.reason, s.fixes);\n */\nexport function usePepuSponsorship(\n o: { pollMs?: number; bundlerUrl?: string; paymasterUrl?: string } = {},\n): SponsorshipReport & { loading: boolean } {\n const [report, setReport] = useState<SponsorshipReport>({\n available: false,\n transport: \"none\",\n bundler: { configured: false },\n paymaster: { configured: false },\n reason: \"Checking sponsorship status.\",\n fixes: [],\n });\n const [loading, setLoading] = useState(true);\n const { pollMs = 30_000, bundlerUrl, paymasterUrl } = o;\n\n useEffect(() => {\n let cancelled = false;\n const run = async (): Promise<void> => {\n try {\n const r = await checkSponsorship({\n publicClient: publicClient(),\n ...(bundlerUrl !== undefined ? { bundlerUrl } : {}),\n ...(paymasterUrl !== undefined ? { paymasterUrl } : {}),\n });\n if (!cancelled) setReport(r);\n } catch (e) {\n if (!cancelled) {\n setReport((prev) => ({ ...prev, available: false, reason: toPepuError(e).message, fixes: [toPepuError(e).hint] }));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n void run();\n const id = pollMs > 0 ? setInterval(() => void run(), pollMs) : undefined;\n return () => {\n cancelled = true;\n if (id !== undefined) clearInterval(id);\n };\n }, [pollMs, bundlerUrl, paymasterUrl]);\n\n return { ...report, loading };\n}\n"]}
|
package/dist/aa.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDNWWZWUW_cjs = require('./chunk-DNWWZWUW.cjs');
|
|
4
4
|
var chunkAJS4UFQX_cjs = require('./chunk-AJS4UFQX.cjs');
|
|
5
|
-
require('./chunk-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
require('./chunk-4GEC7GUU.cjs');
|
|
6
|
+
var chunkVYMAZVIK_cjs = require('./chunk-VYMAZVIK.cjs');
|
|
7
|
+
var chunkHTCX46RJ_cjs = require('./chunk-HTCX46RJ.cjs');
|
|
8
8
|
require('./chunk-K7JSQPZO.cjs');
|
|
9
|
+
require('./chunk-65Y5UCQ7.cjs');
|
|
9
10
|
require('./chunk-VF3D6KLQ.cjs');
|
|
10
11
|
require('./chunk-DPCZJLB3.cjs');
|
|
11
12
|
require('./chunk-YQL7NISX.cjs');
|
|
@@ -14,19 +15,19 @@ require('./chunk-YQL7NISX.cjs');
|
|
|
14
15
|
|
|
15
16
|
Object.defineProperty(exports, "ENTRY_POINT_V07", {
|
|
16
17
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkDNWWZWUW_cjs.ENTRY_POINT_V07; }
|
|
18
19
|
});
|
|
19
20
|
Object.defineProperty(exports, "createPepuBundlerClient", {
|
|
20
21
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkDNWWZWUW_cjs.createPepuBundlerClient; }
|
|
22
23
|
});
|
|
23
24
|
Object.defineProperty(exports, "createPepuPaymasterClient", {
|
|
24
25
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkDNWWZWUW_cjs.createPepuPaymasterClient; }
|
|
26
27
|
});
|
|
27
28
|
Object.defineProperty(exports, "estimatePepuUserOpFees", {
|
|
28
29
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkDNWWZWUW_cjs.estimatePepuUserOpFees; }
|
|
30
31
|
});
|
|
31
32
|
Object.defineProperty(exports, "encodeKernelExecute", {
|
|
32
33
|
enumerable: true,
|
|
@@ -46,39 +47,39 @@ Object.defineProperty(exports, "userOpEventsFromReceipt", {
|
|
|
46
47
|
});
|
|
47
48
|
Object.defineProperty(exports, "checkSponsorship", {
|
|
48
49
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
50
|
+
get: function () { return chunkVYMAZVIK_cjs.checkSponsorship; }
|
|
50
51
|
});
|
|
51
52
|
Object.defineProperty(exports, "getKernelAccountAddress", {
|
|
52
53
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunkVYMAZVIK_cjs.getKernelAccountAddress; }
|
|
54
55
|
});
|
|
55
56
|
Object.defineProperty(exports, "getPaymasterDeposit", {
|
|
56
57
|
enumerable: true,
|
|
57
|
-
get: function () { return
|
|
58
|
+
get: function () { return chunkVYMAZVIK_cjs.getPaymasterDeposit; }
|
|
58
59
|
});
|
|
59
60
|
Object.defineProperty(exports, "getPepuKernelStack", {
|
|
60
61
|
enumerable: true,
|
|
61
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunkVYMAZVIK_cjs.getPepuKernelStack; }
|
|
62
63
|
});
|
|
63
64
|
Object.defineProperty(exports, "getSponsorshipStatus", {
|
|
64
65
|
enumerable: true,
|
|
65
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunkVYMAZVIK_cjs.getSponsorshipStatus; }
|
|
66
67
|
});
|
|
67
68
|
Object.defineProperty(exports, "probeBundler", {
|
|
68
69
|
enumerable: true,
|
|
69
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunkVYMAZVIK_cjs.probeBundler; }
|
|
70
71
|
});
|
|
71
72
|
Object.defineProperty(exports, "probePaymaster", {
|
|
72
73
|
enumerable: true,
|
|
73
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunkVYMAZVIK_cjs.probePaymaster; }
|
|
74
75
|
});
|
|
75
76
|
Object.defineProperty(exports, "describeUserOpFailure", {
|
|
76
77
|
enumerable: true,
|
|
77
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunkHTCX46RJ_cjs.describeUserOpFailure; }
|
|
78
79
|
});
|
|
79
80
|
Object.defineProperty(exports, "redactSecrets", {
|
|
80
81
|
enumerable: true,
|
|
81
|
-
get: function () { return
|
|
82
|
+
get: function () { return chunkHTCX46RJ_cjs.redactSecrets; }
|
|
82
83
|
});
|
|
83
84
|
//# sourceMappingURL=aa.cjs.map
|
|
84
85
|
//# sourceMappingURL=aa.cjs.map
|
package/dist/aa.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { ENTRY_POINT_V07, createPepuBundlerClient, createPepuPaymasterClient, estimatePepuUserOpFees } from './chunk-
|
|
1
|
+
export { ENTRY_POINT_V07, createPepuBundlerClient, createPepuPaymasterClient, estimatePepuUserOpFees } from './chunk-QZKUPCUD.js';
|
|
2
2
|
export { encodeKernelExecute, normalizeCalls, userOpEventFromReceipt, userOpEventsFromReceipt } from './chunk-VBH3JLQ5.js';
|
|
3
|
-
import './chunk-
|
|
4
|
-
export { checkSponsorship, getKernelAccountAddress, getPaymasterDeposit, getPepuKernelStack, getSponsorshipStatus, probeBundler, probePaymaster } from './chunk-
|
|
5
|
-
export { describeUserOpFailure, redactSecrets } from './chunk-
|
|
3
|
+
import './chunk-RSPAN44L.js';
|
|
4
|
+
export { checkSponsorship, getKernelAccountAddress, getPaymasterDeposit, getPepuKernelStack, getSponsorshipStatus, probeBundler, probePaymaster } from './chunk-XR5ONV2Y.js';
|
|
5
|
+
export { describeUserOpFailure, redactSecrets } from './chunk-GFKIM7HT.js';
|
|
6
6
|
import './chunk-KJYNF5KH.js';
|
|
7
|
+
import './chunk-GIZNH65Q.js';
|
|
7
8
|
import './chunk-XC4IBCI2.js';
|
|
8
9
|
import './chunk-VTQIHMF3.js';
|
|
9
10
|
import './chunk-6DSZ4Z2N.js';
|