@pafi-dev/core 0.3.0-beta.9 → 0.5.0

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.
Files changed (49) hide show
  1. package/README.md +165 -1084
  2. package/dist/auth/index.cjs +16 -2
  3. package/dist/auth/index.cjs.map +1 -1
  4. package/dist/auth/index.d.cts +93 -2
  5. package/dist/auth/index.d.ts +93 -2
  6. package/dist/auth/index.js +17 -3
  7. package/dist/{chunk-KJKDLD7N.cjs → chunk-2PY5RNVS.cjs} +11 -11
  8. package/dist/{chunk-KJKDLD7N.cjs.map → chunk-2PY5RNVS.cjs.map} +1 -1
  9. package/dist/{chunk-DMW67WBU.cjs → chunk-52SZJDFT.cjs} +6 -2
  10. package/dist/chunk-52SZJDFT.cjs.map +1 -0
  11. package/dist/{chunk-Z2V525IS.cjs → chunk-ARZSGP5Y.cjs} +6 -6
  12. package/dist/{chunk-Z2V525IS.cjs.map → chunk-ARZSGP5Y.cjs.map} +1 -1
  13. package/dist/{chunk-GWLEEXM4.cjs → chunk-FNJZUNK3.cjs} +90 -2
  14. package/dist/chunk-FNJZUNK3.cjs.map +1 -0
  15. package/dist/{chunk-I2P3TIP7.js → chunk-N5M3BLOV.js} +2 -2
  16. package/dist/{chunk-73CQTNLB.js → chunk-S5CCEO4O.js} +6 -2
  17. package/dist/{chunk-73CQTNLB.js.map → chunk-S5CCEO4O.js.map} +1 -1
  18. package/dist/{chunk-W23EJNYG.js → chunk-T6Y32SNK.js} +12 -2
  19. package/dist/chunk-T6Y32SNK.js.map +1 -0
  20. package/dist/{chunk-O4SMTUOY.js → chunk-W6VULMCO.js} +90 -2
  21. package/dist/chunk-W6VULMCO.js.map +1 -0
  22. package/dist/{chunk-DUY7Z2AI.js → chunk-WTWG6QXP.js} +2 -2
  23. package/dist/{chunk-EDR5SFJN.cjs → chunk-YU7MFR6Y.cjs} +12 -2
  24. package/dist/chunk-YU7MFR6Y.cjs.map +1 -0
  25. package/dist/eip712/index.cjs +3 -3
  26. package/dist/eip712/index.js +2 -2
  27. package/dist/{index-B7pGBych.d.cts → index-BEx-Q1bW.d.cts} +23 -40
  28. package/dist/{index-B06IJlHe.d.ts → index-r4xCdQO7.d.ts} +23 -40
  29. package/dist/index.cjs +178 -37
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +211 -26
  32. package/dist/index.d.ts +211 -26
  33. package/dist/index.js +176 -35
  34. package/dist/index.js.map +1 -1
  35. package/dist/quoting/index.cjs +3 -3
  36. package/dist/quoting/index.js +2 -2
  37. package/dist/swap/index.cjs +3 -2
  38. package/dist/swap/index.cjs.map +1 -1
  39. package/dist/swap/index.d.cts +1 -1
  40. package/dist/swap/index.d.ts +1 -1
  41. package/dist/swap/index.js +2 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-DMW67WBU.cjs.map +0 -1
  44. package/dist/chunk-EDR5SFJN.cjs.map +0 -1
  45. package/dist/chunk-GWLEEXM4.cjs.map +0 -1
  46. package/dist/chunk-O4SMTUOY.js.map +0 -1
  47. package/dist/chunk-W23EJNYG.js.map +0 -1
  48. /package/dist/{chunk-I2P3TIP7.js.map → chunk-N5M3BLOV.js.map} +0 -0
  49. /package/dist/{chunk-DUY7Z2AI.js.map → chunk-WTWG6QXP.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { Address, Hex, PublicClient, WalletClient } from 'viem';
1
+ import { Address, Hex, PublicClient, HttpTransport, WalletClient } from 'viem';
2
2
  import { P as PoolKey, C as ChainConfig, a as PafiSDKConfig, b as PointTokenDomainConfig, M as MintRequest, R as ReceiverConsent, E as EIP712Signature, S as SignatureVerification, B as BestQuote, Q as QuoteResult } from './types-b5_Tokjl.js';
3
3
  export { c as BurnRequest, I as Issuer, d as PathKey } from './types-b5_Tokjl.js';
4
4
  export { erc20Abi, issuerRegistryAbi, mintingOracleAbi, permit2Abi, pointTokenAbi, pointTokenFactoryAbi, universalRouterAbi, v4QuoterAbi } from './abi/index.js';
5
5
  export { buildBurnRequestTypedData, buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signBurnRequest, signMintRequest, signReceiverConsent, verifyBurnRequest, verifyMintRequest, verifyReceiverConsent } from './eip712/index.js';
6
6
  export { getIssuer, getMintRequestNonce, getPointTokenBalance, getPointTokenIssuer, getPointTokenIssuerAddress, getReceiverConsentNonce, getTokenName, isActiveIssuer, isMinter, verifyMintCap } from './contract/index.js';
7
7
  export { buildAllPaths, combineRoutes, findBestQuote, quoteBestRoute, quoteExactInput, quoteExactInputSingle } from './quoting/index.js';
8
- import { P as PartialUserOperation, O as Operation, U as UserOperation, S as SwapSimulationResult } from './index-B06IJlHe.js';
9
- export { B as BuildSwapWithGasDeductionParams, E as ENTRY_POINT_V07, a as PaymasterFields, b as SETTLE_ALL, c as SWAP_EXACT_IN, T as TAKE_ALL, d as UserOpReceipt, V as V4_SWAP, Z as ZERO_VALUE, e as buildErc20ApprovalCalldata, f as buildPermit2ApprovalCalldata, g as buildSwapFromQuote, h as buildSwapWithGasDeduction, i as buildUniversalRouterExecuteArgs, j as buildV4SwapInput, k as checkAllowance, s as simulateSwap } from './index-B06IJlHe.js';
8
+ import { P as PartialUserOperation, O as Operation, U as UserOperation, S as SwapSimulationResult } from './index-r4xCdQO7.js';
9
+ export { B as BuildSwapWithGasDeductionParams, a as PaymasterFields, b as SETTLE_ALL, c as SWAP_EXACT_IN, T as TAKE_ALL, d as UserOpReceipt, V as V4_SWAP, Z as ZERO_VALUE, e as buildErc20ApprovalCalldata, f as buildPermit2ApprovalCalldata, g as buildSwapFromQuote, h as buildSwapWithGasDeduction, i as buildUniversalRouterExecuteArgs, j as buildV4SwapInput, k as checkAllowance, s as simulateSwap } from './index-r4xCdQO7.js';
10
10
  import { LoginMessageParams } from './auth/index.js';
11
- export { VerifyLoginResult, createLoginMessage, parseLoginMessage, verifyLoginMessage } from './auth/index.js';
11
+ export { SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, SponsorAuthPayload, SponsorAuthVerifyResult, VerifyLoginResult, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth } from './auth/index.js';
12
12
 
13
13
  declare const mintRequestTypes: {
14
14
  readonly MintRequest: readonly [{
@@ -67,6 +67,10 @@ declare const UNIVERSAL_ROUTER_ADDRESSES: Record<number, Address>;
67
67
  declare const COMMON_TOKENS: Record<number, Record<string, Address>>;
68
68
  declare const COMMON_POOLS: Record<number, PoolKey[]>;
69
69
  declare const POINT_TOKEN_POOLS: Record<number, Record<Address, PoolKey[]>>;
70
+ /** ERC-4337 v0.7 EntryPoint — deployed deterministically across all EVM chains. */
71
+ declare const ENTRY_POINT_V07: Address;
72
+ /** Permit2 — Uniswap's universal approval contract, same address on all EVM chains. */
73
+ declare const PERMIT2_ADDRESS: Address;
70
74
 
71
75
  declare class PafiSDKError extends Error {
72
76
  constructor(message: string);
@@ -117,7 +121,7 @@ declare class ApiError extends PafiSDKError {
117
121
  *
118
122
  * ## Sponsored vs direct
119
123
  *
120
- * Coinbase Paymaster sponsors GAS, not `msg.value`. So even on the
124
+ * ERC-4337 paymasters sponsor GAS, not `msg.value`. Even on the
121
125
  * sponsored path the user MUST hold enough native ETH on Base to cover
122
126
  * `getDepositFee()` (typically ~0.0002 ETH at quiet times).
123
127
  */
@@ -538,6 +542,182 @@ interface CheckEthAndBranchParams {
538
542
  */
539
543
  declare function checkEthAndBranch(params: CheckEthAndBranchParams): Promise<SubmissionPath>;
540
544
 
545
+ /**
546
+ * Parse the implementation address out of an EIP-7702 delegation designator.
547
+ *
548
+ * Returns `null` when:
549
+ * - `code` is undefined / empty / `"0x"` (plain EOA, no code)
550
+ * - `code` does not contain the EIP-7702 magic prefix (regular contract)
551
+ *
552
+ * @param code - bytecode returned by `eth_getCode` / `client.getCode()`
553
+ * @returns the 20-byte implementation address (checksummed), or `null`
554
+ *
555
+ * @example
556
+ * const code = await client.getCode({ address });
557
+ * const impl = parseEip7702DelegatedAddress(code);
558
+ * // null → not delegated
559
+ * // '0x7702cb554e6bFb442cb743A7dF23154544a7176C' → delegated to BatchExecutor
560
+ */
561
+ declare function parseEip7702DelegatedAddress(code: Hex | string | null | undefined): Address | null;
562
+ /**
563
+ * Read the EIP-7702 delegation status of an EOA from the chain.
564
+ *
565
+ * @param client - viem PublicClient (any provider — only `eth_getCode` is called)
566
+ * @param address - EOA address to inspect
567
+ * @returns the implementation address the EOA is delegated to, or `null`
568
+ *
569
+ * @example
570
+ * const impl = await checkDelegation(publicClient, userAddress);
571
+ * if (impl === null) {
572
+ * // show "Setup Wallet" button
573
+ * } else {
574
+ * // EOA already delegated; safe to send UserOps
575
+ * }
576
+ */
577
+ declare function checkDelegation(client: PublicClient, address: Address): Promise<Address | null>;
578
+ /**
579
+ * Return `true` when the EOA at `address` is currently delegated to `target`.
580
+ *
581
+ * Useful for asserting that the delegation points specifically at the expected
582
+ * BatchExecutor rather than some other implementation (e.g. old deployment).
583
+ *
584
+ * @example
585
+ * import { BATCH_EXECUTOR_ADDRESS_BASE_MAINNET } from '@pafi-dev/core';
586
+ * const ok = await isDelegatedTo(client, userAddress, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET);
587
+ */
588
+ declare function isDelegatedTo(client: PublicClient, address: Address, target: Address): Promise<boolean>;
589
+
590
+ /**
591
+ * Parameters for building a delegation-only UserOperation.
592
+ *
593
+ * This UserOp carries no calldata — its sole purpose is to anchor the
594
+ * EIP-7702 authorization (signed externally via `signAuthorization`) into
595
+ * a sponsored transaction so the user doesn't need native ETH to delegate.
596
+ */
597
+ interface BuildDelegationUserOpParams {
598
+ /** User EOA to delegate. */
599
+ userAddress: Address;
600
+ /** ERC-4337 account nonce — fetched from EntryPoint. Pass 0n on first ever op. */
601
+ aaNonce: bigint;
602
+ gasLimits?: {
603
+ callGasLimit?: bigint;
604
+ verificationGasLimit?: bigint;
605
+ preVerificationGas?: bigint;
606
+ };
607
+ }
608
+ /**
609
+ * Build the minimal `PartialUserOperation` used to sponsor the one-time
610
+ * EIP-7702 delegation.
611
+ *
612
+ * The caller must:
613
+ * 1. Sign the EIP-7702 authorization via `signAuthorization()` (Privy hook).
614
+ * 2. Pass the authorization as `authorization` alongside `calls` (or alone)
615
+ * to `smartClient.sendTransaction()`.
616
+ *
617
+ * The permissionless SDK + Pimlico bundler handle the rest: they detect the
618
+ * `authorization` field and submit an EIP-7702 type-4 transaction that sets
619
+ * the EOA's bytecode to `0xef0100<batchExecutorAddress>`.
620
+ *
621
+ * This builder is a convenience wrapper — in practice you can also pass
622
+ * `{ to: userAddress, value: 0n, data: '0x', authorization }` directly to
623
+ * `smartClient.sendTransaction()` without calling this function at all.
624
+ * Use it when you need a `PartialUserOperation` struct for inspection or
625
+ * custom paymaster flows.
626
+ *
627
+ * @example
628
+ * // Typical flow — no need to call this builder directly:
629
+ * const nonce = await publicClient.getTransactionCount({ address, blockTag: 'pending' });
630
+ * const authorization = await signAuthorization({ contractAddress: BATCH_EXECUTOR, chainId: 8453, nonce });
631
+ * const txHash = await smartClient.sendTransaction({
632
+ * to: address,
633
+ * value: 0n,
634
+ * data: '0x',
635
+ * authorization,
636
+ * paymasterContext: { sponsorshipPolicyId },
637
+ * });
638
+ */
639
+ declare function buildDelegationUserOp(params: BuildDelegationUserOpParams): PartialUserOperation;
640
+ /**
641
+ * Fetch the AA nonce for a user EOA from the EntryPoint v0.7.
642
+ *
643
+ * Convenience helper so callers don't need to import the EntryPoint ABI
644
+ * themselves when building the delegation UserOp.
645
+ *
646
+ * @param client - viem PublicClient
647
+ * @param userAddress - EOA to query
648
+ * @returns bigint nonce (0n on first-ever UserOp)
649
+ */
650
+ declare function getAaNonce(client: PublicClient, userAddress: Address): Promise<bigint>;
651
+
652
+ /**
653
+ * Parameters for `createPafiProxyTransport`.
654
+ */
655
+ interface PafiProxyTransportParams {
656
+ /**
657
+ * Full URL of the PAFI sponsor-relayer Pimlico proxy endpoint.
658
+ * @example "https://sponsor-relayer.pacificfinance.org/pimlico"
659
+ * @example "http://localhost:4000/pimlico"
660
+ */
661
+ proxyUrl: string;
662
+ /**
663
+ * Called on every request to get the current Privy identity token.
664
+ * Use a getter (or a ref's `.current`) so the transport always sends
665
+ * the latest token without needing to be rebuilt when it rotates.
666
+ *
667
+ * @example () => identityTokenRef.current
668
+ * @example () => privyHook.identityToken
669
+ */
670
+ getIdentityToken: () => string | null | undefined;
671
+ /**
672
+ * Issuer ID sent as `X-Issuer-Id` header.
673
+ * sponsor-relayer uses this to look up per-issuer rate limits and policy.
674
+ * Obtain from PAFI team during onboarding.
675
+ */
676
+ issuerId: string;
677
+ }
678
+ /**
679
+ * Create a viem `HttpTransport` that proxies all Pimlico JSON-RPC calls
680
+ * through the PAFI sponsor-relayer (`POST /pimlico`).
681
+ *
682
+ * The transport:
683
+ * - Sets `Authorization: Bearer <identityToken>` on every request
684
+ * - Sets `X-Issuer-Id: <issuerId>` on every request
685
+ * - Reads the identity token lazily via `getIdentityToken()` so it is
686
+ * always fresh without rebuilding the SmartAccountClient on each rotation
687
+ *
688
+ * Pass the returned transport to both `createPimlicoClient` and
689
+ * `createSmartAccountClient` so ALL Pimlico RPC calls (paymaster + bundler)
690
+ * go through the proxy with auth headers attached.
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * import { createPafiProxyTransport, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET } from '@pafi-dev/core';
695
+ * import { createSmartAccountClient } from 'permissionless';
696
+ * import { createPimlicoClient } from 'permissionless/clients/pimlico';
697
+ * import { useIdentityToken } from '@privy-io/react-auth';
698
+ *
699
+ * const { identityToken } = useIdentityToken();
700
+ * const identityTokenRef = useRef<string | null>(null);
701
+ * useEffect(() => { identityTokenRef.current = identityToken; }, [identityToken]);
702
+ *
703
+ * const proxyTransport = createPafiProxyTransport({
704
+ * proxyUrl: process.env.NEXT_PUBLIC_PIMLICO_PROXY_URL!,
705
+ * getIdentityToken: () => identityTokenRef.current,
706
+ * issuerId: process.env.NEXT_PUBLIC_ISSUER_ID!,
707
+ * });
708
+ *
709
+ * const pimlicoClient = createPimlicoClient({ chain: base, transport: proxyTransport });
710
+ * const smartClient = createSmartAccountClient({
711
+ * client: publicClient,
712
+ * chain: base,
713
+ * account,
714
+ * paymaster: pimlicoClient,
715
+ * bundlerTransport: proxyTransport,
716
+ * });
717
+ * ```
718
+ */
719
+ declare function createPafiProxyTransport(params: PafiProxyTransportParams): HttpTransport;
720
+
541
721
  /**
542
722
  * Real `PointToken` ABI — matches the contract deployed on Base mainnet
543
723
  * (POINT at `0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e`). Sourced from
@@ -876,26 +1056,8 @@ declare const POINT_TOKEN_ABI: readonly [{
876
1056
  }];
877
1057
  }];
878
1058
 
879
- /**
880
- * BatchExecutor delegation target addresses.
881
- *
882
- * ## Status
883
- *
884
- * Base mainnet: points at **Coinbase Smart Wallet v2**
885
- * (`0x7702cb554e6bFb442cb743A7dF23154544a7176C`). Coinbase publishes
886
- * this as the canonical EIP-7702 delegation target on Base — every
887
- * user that wants gas sponsorship via Coinbase Paymaster delegates to
888
- * this single contract. One contract, all issuers.
889
- *
890
- * Base Sepolia: placeholder; Sepolia is not in active use for PAFI.
891
- *
892
- * The ABI (`execute(Call[])`) is exported from
893
- * `../../userop/batchExecute.ts` and works against the Coinbase
894
- * contract without change — Coinbase Smart Wallet v2 implements the
895
- * same call-array signature we already use.
896
- */
897
- declare const BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA: Address;
898
- declare const BATCH_EXECUTOR_ADDRESS_BASE_MAINNET: Address;
1059
+ declare const BATCH_EXECUTOR_ADDRESS_BASE_MAINNET: `0x${string}`;
1060
+ declare const BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA: `0x${string}`;
899
1061
 
900
1062
  /**
901
1063
  * Per-chain deployed contract addresses — v1.4 flow.
@@ -1186,6 +1348,29 @@ declare class PafiSDK {
1186
1348
  private _signer?;
1187
1349
  private _provider?;
1188
1350
  private _chainId?;
1351
+ readonly mint: {
1352
+ buildTypedData: PafiSDK["buildMintRequestTypedData"];
1353
+ sign: PafiSDK["signMintRequest"];
1354
+ verify: PafiSDK["verifyMintRequest"];
1355
+ getNonce: PafiSDK["getMintRequestNonce"];
1356
+ };
1357
+ readonly consent: {
1358
+ buildTypedData: PafiSDK["buildReceiverConsentTypedData"];
1359
+ sign: PafiSDK["signReceiverConsent"];
1360
+ verify: PafiSDK["verifyReceiverConsent"];
1361
+ getNonce: PafiSDK["getReceiverConsentNonce"];
1362
+ };
1363
+ readonly swap: {
1364
+ buildFromQuote: PafiSDK["buildSwapFromQuote"];
1365
+ simulate: PafiSDK["simulateSwap"];
1366
+ };
1367
+ readonly quote: {
1368
+ findBest: PafiSDK["findBestQuote"];
1369
+ };
1370
+ readonly auth: {
1371
+ createLoginMessage: PafiSDK["createLoginMessage"];
1372
+ signMessage: PafiSDK["signLoginMessage"];
1373
+ };
1189
1374
  constructor(config: PafiSDKConfig);
1190
1375
  setPointTokenAddress(address: Address): void;
1191
1376
  setSigner(signer: WalletClient): void;
@@ -1293,4 +1478,4 @@ declare class PafiSDK {
1293
1478
  signLoginMessage(message: string): Promise<Hex>;
1294
1479
  }
1295
1480
 
1296
- export { ApiError, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildPartialUserOpParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, POINT_TOKEN_ABI as POINT_TOKEN_V2_ABI, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildPartialUserOperation, buildPerpDepositWithGasDeduction, burnRequestTypes, checkEthAndBranch, computeAccountId, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, getContractAddresses, getPafiWebModalAdapter, getPaymasterConfig, isPaymasterConfigured, mintRequestTypes, openPafiWebModal, openWebPopup, rawCallOp, receiverConsentTypes, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
1481
+ export { ApiError, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, ENTRY_POINT_V07, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, POINT_TOKEN_ABI as POINT_TOKEN_V2_ABI, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildPartialUserOperation, buildPerpDepositWithGasDeduction, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, createPafiProxyTransport, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, getAaNonce, getContractAddresses, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isPaymasterConfigured, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, rawCallOp, receiverConsentTypes, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
package/dist/index.js CHANGED
@@ -2,10 +2,29 @@ import {
2
2
  pointTokenFactoryAbi
3
3
  } from "./chunk-7UBO7DY5.js";
4
4
  import {
5
+ SPONSOR_AUTH_DOMAIN_NAME,
6
+ SPONSOR_AUTH_TYPES,
7
+ buildSponsorAuthDomain,
8
+ buildSponsorAuthTypedData,
9
+ computeCallDataHash,
5
10
  createLoginMessage,
6
11
  parseLoginMessage,
7
- verifyLoginMessage
8
- } from "./chunk-O4SMTUOY.js";
12
+ signSponsorAuth,
13
+ verifyLoginMessage,
14
+ verifySponsorAuth
15
+ } from "./chunk-W6VULMCO.js";
16
+ import {
17
+ buildBurnRequestTypedData,
18
+ buildDomain,
19
+ buildMintRequestTypedData,
20
+ buildReceiverConsentTypedData,
21
+ signBurnRequest,
22
+ signMintRequest,
23
+ signReceiverConsent,
24
+ verifyBurnRequest,
25
+ verifyMintRequest,
26
+ verifyReceiverConsent
27
+ } from "./chunk-WTWG6QXP.js";
9
28
  import {
10
29
  getIssuer,
11
30
  getIssuer2,
@@ -23,18 +42,6 @@ import {
23
42
  mintingOracleAbi,
24
43
  pointTokenAbi
25
44
  } from "./chunk-FXNG4G22.js";
26
- import {
27
- buildBurnRequestTypedData,
28
- buildDomain,
29
- buildMintRequestTypedData,
30
- buildReceiverConsentTypedData,
31
- signBurnRequest,
32
- signMintRequest,
33
- signReceiverConsent,
34
- verifyBurnRequest,
35
- verifyMintRequest,
36
- verifyReceiverConsent
37
- } from "./chunk-DUY7Z2AI.js";
38
45
  import {
39
46
  buildAllPaths,
40
47
  combineRoutes,
@@ -42,21 +49,10 @@ import {
42
49
  quoteBestRoute,
43
50
  quoteExactInput,
44
51
  quoteExactInputSingle
45
- } from "./chunk-I2P3TIP7.js";
52
+ } from "./chunk-N5M3BLOV.js";
46
53
  import {
47
54
  v4QuoterAbi
48
55
  } from "./chunk-KFWZRL7I.js";
49
- import {
50
- COMMON_POOLS,
51
- COMMON_TOKENS,
52
- POINT_TOKEN_POOLS,
53
- SUPPORTED_CHAINS,
54
- UNIVERSAL_ROUTER_ADDRESSES,
55
- V4_QUOTER_ADDRESSES,
56
- burnRequestTypes,
57
- mintRequestTypes,
58
- receiverConsentTypes
59
- } from "./chunk-73CQTNLB.js";
60
56
  import {
61
57
  ApiError,
62
58
  BATCH_EXECUTOR_ABI,
@@ -83,22 +79,35 @@ import {
83
79
  erc20TransferOp,
84
80
  rawCallOp,
85
81
  simulateSwap
86
- } from "./chunk-W23EJNYG.js";
82
+ } from "./chunk-T6Y32SNK.js";
87
83
  import {
88
84
  erc20Abi,
89
85
  permit2Abi,
90
86
  universalRouterAbi
91
87
  } from "./chunk-2PIXFXA2.js";
88
+ import {
89
+ COMMON_POOLS,
90
+ COMMON_TOKENS,
91
+ ENTRY_POINT_V07,
92
+ PERMIT2_ADDRESS,
93
+ POINT_TOKEN_POOLS,
94
+ SUPPORTED_CHAINS,
95
+ UNIVERSAL_ROUTER_ADDRESSES,
96
+ V4_QUOTER_ADDRESSES,
97
+ burnRequestTypes,
98
+ mintRequestTypes,
99
+ receiverConsentTypes
100
+ } from "./chunk-S5CCEO4O.js";
92
101
 
93
102
  // src/index.ts
94
- import { createPublicClient, http } from "viem";
103
+ import { createPublicClient, http as http2 } from "viem";
95
104
 
96
105
  // src/perp/buildPerpDepositWithGasDeduction.ts
97
106
  import { encodeFunctionData } from "viem";
98
107
 
99
108
  // src/contracts/real/orderlyVault.ts
100
109
  import { keccak256, encodePacked, encodeAbiParameters } from "viem";
101
- var ORDERLY_VAULT_BASE_MAINNET = "0xDe5cE5DD048596e46Ff671b13317aCC3C5B59b01";
110
+ var ORDERLY_VAULT_BASE_MAINNET = "0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9";
102
111
  var ORDERLY_VAULT_ADDRESSES = {
103
112
  8453: ORDERLY_VAULT_BASE_MAINNET
104
113
  };
@@ -234,7 +243,6 @@ function buildPerpDepositWithGasDeduction(params) {
234
243
  }
235
244
 
236
245
  // src/userop/types.ts
237
- var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
238
246
  var ZERO_VALUE = 0n;
239
247
 
240
248
  // src/paymaster/config.ts
@@ -280,6 +288,92 @@ async function checkEthAndBranch(params) {
280
288
  return balance >= required ? "normal" : "paymaster";
281
289
  }
282
290
 
291
+ // src/delegation/checkDelegation.ts
292
+ var EIP7702_MAGIC = "0xef0100";
293
+ function parseEip7702DelegatedAddress(code) {
294
+ if (!code || code === "0x" || code === "0x0") return null;
295
+ const normalized = code.toLowerCase();
296
+ const magic = EIP7702_MAGIC.toLowerCase();
297
+ const idx = normalized.indexOf(magic);
298
+ if (idx === -1) return null;
299
+ const raw = normalized.slice(idx + magic.length, idx + magic.length + 40);
300
+ if (raw.length !== 40) return null;
301
+ return `0x${raw}`;
302
+ }
303
+ async function checkDelegation(client, address) {
304
+ const code = await client.getCode({ address });
305
+ return parseEip7702DelegatedAddress(code);
306
+ }
307
+ async function isDelegatedTo(client, address, target) {
308
+ const impl = await checkDelegation(client, address);
309
+ if (!impl) return false;
310
+ return impl.toLowerCase() === target.toLowerCase();
311
+ }
312
+
313
+ // src/delegation/buildDelegationUserOp.ts
314
+ function buildDelegationUserOp(params) {
315
+ return buildPartialUserOperation({
316
+ sender: params.userAddress,
317
+ nonce: params.aaNonce,
318
+ operations: [
319
+ {
320
+ // Self-call with no data — triggers EIP-7702 delegation without
321
+ // executing any inner logic. The BatchExecutor.execute([]) call with
322
+ // an empty array would revert, so we target the EOA itself (which
323
+ // forwards to BatchExecutor that then no-ops on empty input).
324
+ target: params.userAddress,
325
+ value: 0n,
326
+ data: "0x"
327
+ }
328
+ ],
329
+ gasLimits: {
330
+ callGasLimit: params.gasLimits?.callGasLimit ?? 50000n,
331
+ verificationGasLimit: params.gasLimits?.verificationGasLimit ?? 150000n,
332
+ preVerificationGas: params.gasLimits?.preVerificationGas ?? 50000n
333
+ }
334
+ });
335
+ }
336
+ async function getAaNonce(client, userAddress) {
337
+ const NONCE_ABI = [
338
+ {
339
+ inputs: [
340
+ { name: "sender", type: "address" },
341
+ { name: "key", type: "uint192" }
342
+ ],
343
+ name: "getNonce",
344
+ outputs: [{ name: "nonce", type: "uint256" }],
345
+ stateMutability: "view",
346
+ type: "function"
347
+ }
348
+ ];
349
+ return client.readContract({
350
+ address: ENTRY_POINT_V07,
351
+ abi: NONCE_ABI,
352
+ functionName: "getNonce",
353
+ args: [userAddress, 0n]
354
+ });
355
+ }
356
+
357
+ // src/transport/proxyTransport.ts
358
+ import { http } from "viem";
359
+ function createPafiProxyTransport(params) {
360
+ const { proxyUrl, getIdentityToken, issuerId } = params;
361
+ return http(proxyUrl, {
362
+ fetchOptions: {},
363
+ // fetchFn intercepts every fetch call the viem http transport makes,
364
+ // injecting the auth headers before the request leaves the browser.
365
+ fetchFn: (input, init) => {
366
+ const headers = new Headers(init?.headers);
367
+ const token = getIdentityToken();
368
+ if (token) {
369
+ headers.set("authorization", `Bearer ${token}`);
370
+ }
371
+ headers.set("x-issuer-id", issuerId);
372
+ return fetch(input, { ...init, headers });
373
+ }
374
+ });
375
+ }
376
+
283
377
  // src/contracts/real/pointToken.ts
284
378
  import { parseAbi } from "viem";
285
379
  var POINT_TOKEN_ABI = parseAbi([
@@ -325,10 +419,6 @@ var POINT_TOKEN_ABI = parseAbi([
325
419
  "event MintingOracleUpdated(address indexed mintingOracle)"
326
420
  ]);
327
421
 
328
- // src/contracts/real/batchExecutor.ts
329
- var BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = "0x000000000000000000000000000000000000DE01";
330
- var BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = "0x7702cb554e6bFb442cb743A7dF23154544a7176C";
331
-
332
422
  // src/contracts/real/addresses.ts
333
423
  var PLACEHOLDER_DEAD = (suffix) => `0x000000000000000000000000000000000000${suffix.toLowerCase().padStart(4, "0")}`;
334
424
  var CONTRACT_ADDRESSES = {
@@ -378,6 +468,10 @@ function getContractAddresses(chainId) {
378
468
  return addrs;
379
469
  }
380
470
 
471
+ // src/contracts/real/batchExecutor.ts
472
+ var BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = getContractAddresses(8453).batchExecutor;
473
+ var BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = getContractAddresses(84532).batchExecutor;
474
+
381
475
  // src/web-handoff/webPopup.ts
382
476
  var DEFAULT_WIDTH = 900;
383
477
  var DEFAULT_HEIGHT = 700;
@@ -505,6 +599,16 @@ var PafiSDK = class {
505
599
  _signer;
506
600
  _provider;
507
601
  _chainId;
602
+ // -------------------------------------------------------------------------
603
+ // Domain namespaces — grouped by concern for better IDE autocomplete.
604
+ // Each property is a plain object of bound methods; the underlying logic
605
+ // lives in the flat methods below so both access styles work.
606
+ // -------------------------------------------------------------------------
607
+ mint;
608
+ consent;
609
+ swap;
610
+ quote;
611
+ auth;
508
612
  constructor(config) {
509
613
  this._pointTokenAddress = config.pointTokenAddress;
510
614
  this._signer = config.signer;
@@ -513,9 +617,32 @@ var PafiSDK = class {
513
617
  this._provider = config.provider;
514
618
  } else if (config.rpcUrl) {
515
619
  this._provider = createPublicClient({
516
- transport: http(config.rpcUrl)
620
+ transport: http2(config.rpcUrl)
517
621
  });
518
622
  }
623
+ this.mint = {
624
+ buildTypedData: this.buildMintRequestTypedData.bind(this),
625
+ sign: this.signMintRequest.bind(this),
626
+ verify: this.verifyMintRequest.bind(this),
627
+ getNonce: this.getMintRequestNonce.bind(this)
628
+ };
629
+ this.consent = {
630
+ buildTypedData: this.buildReceiverConsentTypedData.bind(this),
631
+ sign: this.signReceiverConsent.bind(this),
632
+ verify: this.verifyReceiverConsent.bind(this),
633
+ getNonce: this.getReceiverConsentNonce.bind(this)
634
+ };
635
+ this.swap = {
636
+ buildFromQuote: this.buildSwapFromQuote.bind(this),
637
+ simulate: this.simulateSwap.bind(this)
638
+ };
639
+ this.quote = {
640
+ findBest: this.findBestQuote.bind(this)
641
+ };
642
+ this.auth = {
643
+ createLoginMessage: this.createLoginMessage.bind(this),
644
+ signMessage: this.signLoginMessage.bind(this)
645
+ };
519
646
  }
520
647
  // -------------------------------------------------------------------------
521
648
  // Setters
@@ -699,6 +826,7 @@ export {
699
826
  ORDERLY_VAULT_ABI,
700
827
  ORDERLY_VAULT_ADDRESSES,
701
828
  ORDERLY_VAULT_BASE_MAINNET,
829
+ PERMIT2_ADDRESS,
702
830
  POINT_TOKEN_FACTORY_ADDRESSES,
703
831
  POINT_TOKEN_IMPL_ADDRESSES,
704
832
  POINT_TOKEN_POOLS,
@@ -706,6 +834,8 @@ export {
706
834
  PafiSDK,
707
835
  PafiSDKError,
708
836
  SETTLE_ALL,
837
+ SPONSOR_AUTH_DOMAIN_NAME,
838
+ SPONSOR_AUTH_TYPES,
709
839
  SUPPORTED_CHAINS,
710
840
  SWAP_EXACT_IN,
711
841
  SigningError,
@@ -720,6 +850,7 @@ export {
720
850
  assembleUserOperation,
721
851
  buildAllPaths,
722
852
  buildBurnRequestTypedData,
853
+ buildDelegationUserOp,
723
854
  buildDomain,
724
855
  buildErc20ApprovalCalldata,
725
856
  buildMintRequestTypedData,
@@ -727,22 +858,28 @@ export {
727
858
  buildPermit2ApprovalCalldata,
728
859
  buildPerpDepositWithGasDeduction,
729
860
  buildReceiverConsentTypedData,
861
+ buildSponsorAuthDomain,
862
+ buildSponsorAuthTypedData,
730
863
  buildSwapFromQuote,
731
864
  buildSwapWithGasDeduction,
732
865
  buildUniversalRouterExecuteArgs,
733
866
  buildV4SwapInput,
734
867
  burnRequestTypes,
735
868
  checkAllowance,
869
+ checkDelegation,
736
870
  checkEthAndBranch,
737
871
  combineRoutes,
738
872
  computeAccountId,
873
+ computeCallDataHash,
739
874
  createLoginMessage,
875
+ createPafiProxyTransport,
740
876
  encodeBatchExecute,
741
877
  erc20Abi,
742
878
  erc20ApproveOp,
743
879
  erc20BurnOp,
744
880
  erc20TransferOp,
745
881
  findBestQuote,
882
+ getAaNonce,
746
883
  getContractAddresses,
747
884
  getIssuer2 as getIssuer,
748
885
  getMintRequestNonce,
@@ -754,6 +891,7 @@ export {
754
891
  getReceiverConsentNonce,
755
892
  getTokenName,
756
893
  isActiveIssuer,
894
+ isDelegatedTo,
757
895
  isMinter,
758
896
  isPaymasterConfigured,
759
897
  issuerRegistryAbi,
@@ -761,6 +899,7 @@ export {
761
899
  mintingOracleAbi,
762
900
  openPafiWebModal,
763
901
  openWebPopup,
902
+ parseEip7702DelegatedAddress,
764
903
  parseLoginMessage,
765
904
  permit2Abi,
766
905
  pointTokenAbi,
@@ -775,6 +914,7 @@ export {
775
914
  signBurnRequest,
776
915
  signMintRequest,
777
916
  signReceiverConsent,
917
+ signSponsorAuth,
778
918
  simulateSwap,
779
919
  universalRouterAbi,
780
920
  v4QuoterAbi,
@@ -783,6 +923,7 @@ export {
783
923
  verifyMintCap,
784
924
  verifyMintRequest,
785
925
  verifyReceiverConsent,
926
+ verifySponsorAuth,
786
927
  webPopupAdapter
787
928
  };
788
929
  //# sourceMappingURL=index.js.map