@pafi-dev/core 0.3.0-beta.9 → 0.4.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.
- package/README.md +99 -1118
- package/dist/auth/index.cjs +16 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +93 -2
- package/dist/auth/index.d.ts +93 -2
- package/dist/auth/index.js +17 -3
- package/dist/{chunk-W23EJNYG.js → chunk-543IPI6E.js} +11 -3
- package/dist/chunk-543IPI6E.js.map +1 -0
- package/dist/{chunk-GWLEEXM4.cjs → chunk-FNJZUNK3.cjs} +90 -2
- package/dist/chunk-FNJZUNK3.cjs.map +1 -0
- package/dist/{chunk-EDR5SFJN.cjs → chunk-TYIEMGMY.cjs} +10 -2
- package/dist/chunk-TYIEMGMY.cjs.map +1 -0
- package/dist/{chunk-O4SMTUOY.js → chunk-W6VULMCO.js} +90 -2
- package/dist/chunk-W6VULMCO.js.map +1 -0
- package/dist/{index-B06IJlHe.d.ts → index-C1FGQ004.d.ts} +22 -33
- package/dist/{index-B7pGBych.d.cts → index-CzBaRIqs.d.cts} +22 -33
- package/dist/index.cjs +126 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -6
- package/dist/index.d.ts +182 -6
- package/dist/index.js +113 -6
- package/dist/index.js.map +1 -1
- package/dist/swap/index.cjs +2 -2
- package/dist/swap/index.d.cts +1 -1
- package/dist/swap/index.d.ts +1 -1
- package/dist/swap/index.js +1 -1
- package/package.json +12 -12
- package/dist/chunk-EDR5SFJN.cjs.map +0 -1
- package/dist/chunk-GWLEEXM4.cjs.map +0 -1
- package/dist/chunk-O4SMTUOY.js.map +0 -1
- package/dist/chunk-W23EJNYG.js.map +0 -1
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-
|
|
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-
|
|
8
|
+
import { P as PartialUserOperation, O as Operation, U as UserOperation, S as SwapSimulationResult } from './index-C1FGQ004.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-C1FGQ004.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 [{
|
|
@@ -117,7 +117,7 @@ declare class ApiError extends PafiSDKError {
|
|
|
117
117
|
*
|
|
118
118
|
* ## Sponsored vs direct
|
|
119
119
|
*
|
|
120
|
-
*
|
|
120
|
+
* ERC-4337 paymasters sponsor GAS, not `msg.value`. Even on the
|
|
121
121
|
* sponsored path the user MUST hold enough native ETH on Base to cover
|
|
122
122
|
* `getDepositFee()` (typically ~0.0002 ETH at quiet times).
|
|
123
123
|
*/
|
|
@@ -538,6 +538,182 @@ interface CheckEthAndBranchParams {
|
|
|
538
538
|
*/
|
|
539
539
|
declare function checkEthAndBranch(params: CheckEthAndBranchParams): Promise<SubmissionPath>;
|
|
540
540
|
|
|
541
|
+
/**
|
|
542
|
+
* Parse the implementation address out of an EIP-7702 delegation designator.
|
|
543
|
+
*
|
|
544
|
+
* Returns `null` when:
|
|
545
|
+
* - `code` is undefined / empty / `"0x"` (plain EOA, no code)
|
|
546
|
+
* - `code` does not contain the EIP-7702 magic prefix (regular contract)
|
|
547
|
+
*
|
|
548
|
+
* @param code - bytecode returned by `eth_getCode` / `client.getCode()`
|
|
549
|
+
* @returns the 20-byte implementation address (checksummed), or `null`
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* const code = await client.getCode({ address });
|
|
553
|
+
* const impl = parseEip7702DelegatedAddress(code);
|
|
554
|
+
* // null → not delegated
|
|
555
|
+
* // '0x7702cb554e6bFb442cb743A7dF23154544a7176C' → delegated to BatchExecutor
|
|
556
|
+
*/
|
|
557
|
+
declare function parseEip7702DelegatedAddress(code: Hex | string | null | undefined): Address | null;
|
|
558
|
+
/**
|
|
559
|
+
* Read the EIP-7702 delegation status of an EOA from the chain.
|
|
560
|
+
*
|
|
561
|
+
* @param client - viem PublicClient (any provider — only `eth_getCode` is called)
|
|
562
|
+
* @param address - EOA address to inspect
|
|
563
|
+
* @returns the implementation address the EOA is delegated to, or `null`
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* const impl = await checkDelegation(publicClient, userAddress);
|
|
567
|
+
* if (impl === null) {
|
|
568
|
+
* // show "Setup Wallet" button
|
|
569
|
+
* } else {
|
|
570
|
+
* // EOA already delegated; safe to send UserOps
|
|
571
|
+
* }
|
|
572
|
+
*/
|
|
573
|
+
declare function checkDelegation(client: PublicClient, address: Address): Promise<Address | null>;
|
|
574
|
+
/**
|
|
575
|
+
* Return `true` when the EOA at `address` is currently delegated to `target`.
|
|
576
|
+
*
|
|
577
|
+
* Useful for asserting that the delegation points specifically at the expected
|
|
578
|
+
* BatchExecutor rather than some other implementation (e.g. old deployment).
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* import { BATCH_EXECUTOR_ADDRESS_BASE_MAINNET } from '@pafi-dev/core';
|
|
582
|
+
* const ok = await isDelegatedTo(client, userAddress, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET);
|
|
583
|
+
*/
|
|
584
|
+
declare function isDelegatedTo(client: PublicClient, address: Address, target: Address): Promise<boolean>;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Parameters for building a delegation-only UserOperation.
|
|
588
|
+
*
|
|
589
|
+
* This UserOp carries no calldata — its sole purpose is to anchor the
|
|
590
|
+
* EIP-7702 authorization (signed externally via `signAuthorization`) into
|
|
591
|
+
* a sponsored transaction so the user doesn't need native ETH to delegate.
|
|
592
|
+
*/
|
|
593
|
+
interface BuildDelegationUserOpParams {
|
|
594
|
+
/** User EOA to delegate. */
|
|
595
|
+
userAddress: Address;
|
|
596
|
+
/** ERC-4337 account nonce — fetched from EntryPoint. Pass 0n on first ever op. */
|
|
597
|
+
aaNonce: bigint;
|
|
598
|
+
gasLimits?: {
|
|
599
|
+
callGasLimit?: bigint;
|
|
600
|
+
verificationGasLimit?: bigint;
|
|
601
|
+
preVerificationGas?: bigint;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Build the minimal `PartialUserOperation` used to sponsor the one-time
|
|
606
|
+
* EIP-7702 delegation.
|
|
607
|
+
*
|
|
608
|
+
* The caller must:
|
|
609
|
+
* 1. Sign the EIP-7702 authorization via `signAuthorization()` (Privy hook).
|
|
610
|
+
* 2. Pass the authorization as `authorization` alongside `calls` (or alone)
|
|
611
|
+
* to `smartClient.sendTransaction()`.
|
|
612
|
+
*
|
|
613
|
+
* The permissionless SDK + Pimlico bundler handle the rest: they detect the
|
|
614
|
+
* `authorization` field and submit an EIP-7702 type-4 transaction that sets
|
|
615
|
+
* the EOA's bytecode to `0xef0100<batchExecutorAddress>`.
|
|
616
|
+
*
|
|
617
|
+
* This builder is a convenience wrapper — in practice you can also pass
|
|
618
|
+
* `{ to: userAddress, value: 0n, data: '0x', authorization }` directly to
|
|
619
|
+
* `smartClient.sendTransaction()` without calling this function at all.
|
|
620
|
+
* Use it when you need a `PartialUserOperation` struct for inspection or
|
|
621
|
+
* custom paymaster flows.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* // Typical flow — no need to call this builder directly:
|
|
625
|
+
* const nonce = await publicClient.getTransactionCount({ address, blockTag: 'pending' });
|
|
626
|
+
* const authorization = await signAuthorization({ contractAddress: BATCH_EXECUTOR, chainId: 8453, nonce });
|
|
627
|
+
* const txHash = await smartClient.sendTransaction({
|
|
628
|
+
* to: address,
|
|
629
|
+
* value: 0n,
|
|
630
|
+
* data: '0x',
|
|
631
|
+
* authorization,
|
|
632
|
+
* paymasterContext: { sponsorshipPolicyId },
|
|
633
|
+
* });
|
|
634
|
+
*/
|
|
635
|
+
declare function buildDelegationUserOp(params: BuildDelegationUserOpParams): PartialUserOperation;
|
|
636
|
+
/**
|
|
637
|
+
* Fetch the AA nonce for a user EOA from the EntryPoint v0.7.
|
|
638
|
+
*
|
|
639
|
+
* Convenience helper so callers don't need to import the EntryPoint ABI
|
|
640
|
+
* themselves when building the delegation UserOp.
|
|
641
|
+
*
|
|
642
|
+
* @param client - viem PublicClient
|
|
643
|
+
* @param userAddress - EOA to query
|
|
644
|
+
* @returns bigint nonce (0n on first-ever UserOp)
|
|
645
|
+
*/
|
|
646
|
+
declare function getAaNonce(client: PublicClient, userAddress: Address): Promise<bigint>;
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Parameters for `createPafiProxyTransport`.
|
|
650
|
+
*/
|
|
651
|
+
interface PafiProxyTransportParams {
|
|
652
|
+
/**
|
|
653
|
+
* Full URL of the PAFI sponsor-relayer Pimlico proxy endpoint.
|
|
654
|
+
* @example "https://sponsor-relayer.pacificfinance.org/pimlico"
|
|
655
|
+
* @example "http://localhost:4000/pimlico"
|
|
656
|
+
*/
|
|
657
|
+
proxyUrl: string;
|
|
658
|
+
/**
|
|
659
|
+
* Called on every request to get the current Privy identity token.
|
|
660
|
+
* Use a getter (or a ref's `.current`) so the transport always sends
|
|
661
|
+
* the latest token without needing to be rebuilt when it rotates.
|
|
662
|
+
*
|
|
663
|
+
* @example () => identityTokenRef.current
|
|
664
|
+
* @example () => privyHook.identityToken
|
|
665
|
+
*/
|
|
666
|
+
getIdentityToken: () => string | null | undefined;
|
|
667
|
+
/**
|
|
668
|
+
* Issuer ID sent as `X-Issuer-Id` header.
|
|
669
|
+
* sponsor-relayer uses this to look up per-issuer rate limits and policy.
|
|
670
|
+
* Obtain from PAFI team during onboarding.
|
|
671
|
+
*/
|
|
672
|
+
issuerId: string;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Create a viem `HttpTransport` that proxies all Pimlico JSON-RPC calls
|
|
676
|
+
* through the PAFI sponsor-relayer (`POST /pimlico`).
|
|
677
|
+
*
|
|
678
|
+
* The transport:
|
|
679
|
+
* - Sets `Authorization: Bearer <identityToken>` on every request
|
|
680
|
+
* - Sets `X-Issuer-Id: <issuerId>` on every request
|
|
681
|
+
* - Reads the identity token lazily via `getIdentityToken()` so it is
|
|
682
|
+
* always fresh without rebuilding the SmartAccountClient on each rotation
|
|
683
|
+
*
|
|
684
|
+
* Pass the returned transport to both `createPimlicoClient` and
|
|
685
|
+
* `createSmartAccountClient` so ALL Pimlico RPC calls (paymaster + bundler)
|
|
686
|
+
* go through the proxy with auth headers attached.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* import { createPafiProxyTransport, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET } from '@pafi-dev/core';
|
|
691
|
+
* import { createSmartAccountClient } from 'permissionless';
|
|
692
|
+
* import { createPimlicoClient } from 'permissionless/clients/pimlico';
|
|
693
|
+
* import { useIdentityToken } from '@privy-io/react-auth';
|
|
694
|
+
*
|
|
695
|
+
* const { identityToken } = useIdentityToken();
|
|
696
|
+
* const identityTokenRef = useRef<string | null>(null);
|
|
697
|
+
* useEffect(() => { identityTokenRef.current = identityToken; }, [identityToken]);
|
|
698
|
+
*
|
|
699
|
+
* const proxyTransport = createPafiProxyTransport({
|
|
700
|
+
* proxyUrl: process.env.NEXT_PUBLIC_PIMLICO_PROXY_URL!,
|
|
701
|
+
* getIdentityToken: () => identityTokenRef.current,
|
|
702
|
+
* issuerId: process.env.NEXT_PUBLIC_ISSUER_ID!,
|
|
703
|
+
* });
|
|
704
|
+
*
|
|
705
|
+
* const pimlicoClient = createPimlicoClient({ chain: base, transport: proxyTransport });
|
|
706
|
+
* const smartClient = createSmartAccountClient({
|
|
707
|
+
* client: publicClient,
|
|
708
|
+
* chain: base,
|
|
709
|
+
* account,
|
|
710
|
+
* paymaster: pimlicoClient,
|
|
711
|
+
* bundlerTransport: proxyTransport,
|
|
712
|
+
* });
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
declare function createPafiProxyTransport(params: PafiProxyTransportParams): HttpTransport;
|
|
716
|
+
|
|
541
717
|
/**
|
|
542
718
|
* Real `PointToken` ABI — matches the contract deployed on Base mainnet
|
|
543
719
|
* (POINT at `0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e`). Sourced from
|
|
@@ -1293,4 +1469,4 @@ declare class PafiSDK {
|
|
|
1293
1469
|
signLoginMessage(message: string): Promise<Hex>;
|
|
1294
1470
|
}
|
|
1295
1471
|
|
|
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 };
|
|
1472
|
+
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, 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, 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,17 @@ 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
|
-
|
|
8
|
-
|
|
12
|
+
signSponsorAuth,
|
|
13
|
+
verifyLoginMessage,
|
|
14
|
+
verifySponsorAuth
|
|
15
|
+
} from "./chunk-W6VULMCO.js";
|
|
9
16
|
import {
|
|
10
17
|
getIssuer,
|
|
11
18
|
getIssuer2,
|
|
@@ -83,7 +90,7 @@ import {
|
|
|
83
90
|
erc20TransferOp,
|
|
84
91
|
rawCallOp,
|
|
85
92
|
simulateSwap
|
|
86
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-543IPI6E.js";
|
|
87
94
|
import {
|
|
88
95
|
erc20Abi,
|
|
89
96
|
permit2Abi,
|
|
@@ -91,14 +98,14 @@ import {
|
|
|
91
98
|
} from "./chunk-2PIXFXA2.js";
|
|
92
99
|
|
|
93
100
|
// src/index.ts
|
|
94
|
-
import { createPublicClient, http } from "viem";
|
|
101
|
+
import { createPublicClient, http as http2 } from "viem";
|
|
95
102
|
|
|
96
103
|
// src/perp/buildPerpDepositWithGasDeduction.ts
|
|
97
104
|
import { encodeFunctionData } from "viem";
|
|
98
105
|
|
|
99
106
|
// src/contracts/real/orderlyVault.ts
|
|
100
107
|
import { keccak256, encodePacked, encodeAbiParameters } from "viem";
|
|
101
|
-
var ORDERLY_VAULT_BASE_MAINNET = "
|
|
108
|
+
var ORDERLY_VAULT_BASE_MAINNET = "0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9";
|
|
102
109
|
var ORDERLY_VAULT_ADDRESSES = {
|
|
103
110
|
8453: ORDERLY_VAULT_BASE_MAINNET
|
|
104
111
|
};
|
|
@@ -280,6 +287,93 @@ async function checkEthAndBranch(params) {
|
|
|
280
287
|
return balance >= required ? "normal" : "paymaster";
|
|
281
288
|
}
|
|
282
289
|
|
|
290
|
+
// src/delegation/checkDelegation.ts
|
|
291
|
+
var EIP7702_MAGIC = "0xef0100";
|
|
292
|
+
function parseEip7702DelegatedAddress(code) {
|
|
293
|
+
if (!code || code === "0x" || code === "0x0") return null;
|
|
294
|
+
const normalized = code.toLowerCase();
|
|
295
|
+
const magic = EIP7702_MAGIC.toLowerCase();
|
|
296
|
+
const idx = normalized.indexOf(magic);
|
|
297
|
+
if (idx === -1) return null;
|
|
298
|
+
const raw = normalized.slice(idx + magic.length, idx + magic.length + 40);
|
|
299
|
+
if (raw.length !== 40) return null;
|
|
300
|
+
return `0x${raw}`;
|
|
301
|
+
}
|
|
302
|
+
async function checkDelegation(client, address) {
|
|
303
|
+
const code = await client.getCode({ address });
|
|
304
|
+
return parseEip7702DelegatedAddress(code);
|
|
305
|
+
}
|
|
306
|
+
async function isDelegatedTo(client, address, target) {
|
|
307
|
+
const impl = await checkDelegation(client, address);
|
|
308
|
+
if (!impl) return false;
|
|
309
|
+
return impl.toLowerCase() === target.toLowerCase();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/delegation/buildDelegationUserOp.ts
|
|
313
|
+
function buildDelegationUserOp(params) {
|
|
314
|
+
return buildPartialUserOperation({
|
|
315
|
+
sender: params.userAddress,
|
|
316
|
+
nonce: params.aaNonce,
|
|
317
|
+
operations: [
|
|
318
|
+
{
|
|
319
|
+
// Self-call with no data — triggers EIP-7702 delegation without
|
|
320
|
+
// executing any inner logic. The BatchExecutor.execute([]) call with
|
|
321
|
+
// an empty array would revert, so we target the EOA itself (which
|
|
322
|
+
// forwards to BatchExecutor that then no-ops on empty input).
|
|
323
|
+
target: params.userAddress,
|
|
324
|
+
value: 0n,
|
|
325
|
+
data: "0x"
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
gasLimits: {
|
|
329
|
+
callGasLimit: params.gasLimits?.callGasLimit ?? 50000n,
|
|
330
|
+
verificationGasLimit: params.gasLimits?.verificationGasLimit ?? 150000n,
|
|
331
|
+
preVerificationGas: params.gasLimits?.preVerificationGas ?? 50000n
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
async function getAaNonce(client, userAddress) {
|
|
336
|
+
const ENTRY_POINT = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
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,
|
|
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([
|
|
@@ -513,7 +607,7 @@ var PafiSDK = class {
|
|
|
513
607
|
this._provider = config.provider;
|
|
514
608
|
} else if (config.rpcUrl) {
|
|
515
609
|
this._provider = createPublicClient({
|
|
516
|
-
transport:
|
|
610
|
+
transport: http2(config.rpcUrl)
|
|
517
611
|
});
|
|
518
612
|
}
|
|
519
613
|
}
|
|
@@ -706,6 +800,8 @@ export {
|
|
|
706
800
|
PafiSDK,
|
|
707
801
|
PafiSDKError,
|
|
708
802
|
SETTLE_ALL,
|
|
803
|
+
SPONSOR_AUTH_DOMAIN_NAME,
|
|
804
|
+
SPONSOR_AUTH_TYPES,
|
|
709
805
|
SUPPORTED_CHAINS,
|
|
710
806
|
SWAP_EXACT_IN,
|
|
711
807
|
SigningError,
|
|
@@ -720,6 +816,7 @@ export {
|
|
|
720
816
|
assembleUserOperation,
|
|
721
817
|
buildAllPaths,
|
|
722
818
|
buildBurnRequestTypedData,
|
|
819
|
+
buildDelegationUserOp,
|
|
723
820
|
buildDomain,
|
|
724
821
|
buildErc20ApprovalCalldata,
|
|
725
822
|
buildMintRequestTypedData,
|
|
@@ -727,22 +824,28 @@ export {
|
|
|
727
824
|
buildPermit2ApprovalCalldata,
|
|
728
825
|
buildPerpDepositWithGasDeduction,
|
|
729
826
|
buildReceiverConsentTypedData,
|
|
827
|
+
buildSponsorAuthDomain,
|
|
828
|
+
buildSponsorAuthTypedData,
|
|
730
829
|
buildSwapFromQuote,
|
|
731
830
|
buildSwapWithGasDeduction,
|
|
732
831
|
buildUniversalRouterExecuteArgs,
|
|
733
832
|
buildV4SwapInput,
|
|
734
833
|
burnRequestTypes,
|
|
735
834
|
checkAllowance,
|
|
835
|
+
checkDelegation,
|
|
736
836
|
checkEthAndBranch,
|
|
737
837
|
combineRoutes,
|
|
738
838
|
computeAccountId,
|
|
839
|
+
computeCallDataHash,
|
|
739
840
|
createLoginMessage,
|
|
841
|
+
createPafiProxyTransport,
|
|
740
842
|
encodeBatchExecute,
|
|
741
843
|
erc20Abi,
|
|
742
844
|
erc20ApproveOp,
|
|
743
845
|
erc20BurnOp,
|
|
744
846
|
erc20TransferOp,
|
|
745
847
|
findBestQuote,
|
|
848
|
+
getAaNonce,
|
|
746
849
|
getContractAddresses,
|
|
747
850
|
getIssuer2 as getIssuer,
|
|
748
851
|
getMintRequestNonce,
|
|
@@ -754,6 +857,7 @@ export {
|
|
|
754
857
|
getReceiverConsentNonce,
|
|
755
858
|
getTokenName,
|
|
756
859
|
isActiveIssuer,
|
|
860
|
+
isDelegatedTo,
|
|
757
861
|
isMinter,
|
|
758
862
|
isPaymasterConfigured,
|
|
759
863
|
issuerRegistryAbi,
|
|
@@ -761,6 +865,7 @@ export {
|
|
|
761
865
|
mintingOracleAbi,
|
|
762
866
|
openPafiWebModal,
|
|
763
867
|
openWebPopup,
|
|
868
|
+
parseEip7702DelegatedAddress,
|
|
764
869
|
parseLoginMessage,
|
|
765
870
|
permit2Abi,
|
|
766
871
|
pointTokenAbi,
|
|
@@ -775,6 +880,7 @@ export {
|
|
|
775
880
|
signBurnRequest,
|
|
776
881
|
signMintRequest,
|
|
777
882
|
signReceiverConsent,
|
|
883
|
+
signSponsorAuth,
|
|
778
884
|
simulateSwap,
|
|
779
885
|
universalRouterAbi,
|
|
780
886
|
v4QuoterAbi,
|
|
@@ -783,6 +889,7 @@ export {
|
|
|
783
889
|
verifyMintCap,
|
|
784
890
|
verifyMintRequest,
|
|
785
891
|
verifyReceiverConsent,
|
|
892
|
+
verifySponsorAuth,
|
|
786
893
|
webPopupAdapter
|
|
787
894
|
};
|
|
788
895
|
//# sourceMappingURL=index.js.map
|