@pafi-dev/core 0.7.1 → 0.7.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.
Files changed (43) hide show
  1. package/dist/abi/index.cjs +1 -0
  2. package/dist/abi/index.cjs.map +1 -1
  3. package/dist/abi/index.js +1 -0
  4. package/dist/auth/index.cjs +5 -2
  5. package/dist/auth/index.cjs.map +1 -1
  6. package/dist/auth/index.d.cts +10 -1
  7. package/dist/auth/index.d.ts +10 -1
  8. package/dist/auth/index.js +4 -1
  9. package/dist/{chunk-RZDG6SRR.cjs → chunk-5254AG3Z.cjs} +36 -5
  10. package/dist/chunk-5254AG3Z.cjs.map +1 -0
  11. package/dist/{chunk-QGXJLLKF.js → chunk-6UX2IFA2.js} +34 -3
  12. package/dist/chunk-6UX2IFA2.js.map +1 -0
  13. package/dist/chunk-DGUM43GV.js +11 -0
  14. package/dist/chunk-DGUM43GV.js.map +1 -0
  15. package/dist/chunk-JEQ2X3Z6.cjs +11 -0
  16. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  17. package/dist/{chunk-3QDZFDEL.cjs → chunk-M5ULOZ3A.cjs} +3 -3
  18. package/dist/chunk-M5ULOZ3A.cjs.map +1 -0
  19. package/dist/{chunk-UOKI5GG6.js → chunk-WJSIB5GF.js} +2 -2
  20. package/dist/chunk-WJSIB5GF.js.map +1 -0
  21. package/dist/contract/index.cjs +1 -0
  22. package/dist/contract/index.cjs.map +1 -1
  23. package/dist/contract/index.d.cts +1 -1
  24. package/dist/contract/index.d.ts +1 -1
  25. package/dist/contract/index.js +1 -0
  26. package/dist/eip712/index.cjs +3 -2
  27. package/dist/eip712/index.cjs.map +1 -1
  28. package/dist/eip712/index.d.cts +10 -5
  29. package/dist/eip712/index.d.ts +10 -5
  30. package/dist/eip712/index.js +2 -1
  31. package/dist/index.cjs +56 -19
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +88 -18
  34. package/dist/index.d.ts +88 -18
  35. package/dist/index.js +43 -6
  36. package/dist/index.js.map +1 -1
  37. package/dist/{types-JyuXUM8C.d.cts → types-BAkmxgVo.d.cts} +10 -0
  38. package/dist/{types-JyuXUM8C.d.ts → types-BAkmxgVo.d.ts} +10 -0
  39. package/package.json +1 -1
  40. package/dist/chunk-3QDZFDEL.cjs.map +0 -1
  41. package/dist/chunk-QGXJLLKF.js.map +0 -1
  42. package/dist/chunk-RZDG6SRR.cjs.map +0 -1
  43. package/dist/chunk-UOKI5GG6.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Address, Hex, TypedDataDomain, PublicClient, HttpTransport, WalletClient } from 'viem';
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 } from './types-JyuXUM8C.cjs';
3
- export { B as BestQuote, c as BurnRequest, I as Issuer, d as PathKey, Q as QuoteResult } from './types-JyuXUM8C.cjs';
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 } from './types-BAkmxgVo.cjs';
3
+ export { B as BestQuote, c as BurnRequest, I as Issuer, d as PathKey, Q as QuoteResult } from './types-BAkmxgVo.cjs';
4
4
  export { pointTokenAbi as POINT_TOKEN_V2_ABI, erc20Abi, issuerRegistryAbi, mintingOracleAbi, permit2Abi, pointTokenAbi, pointTokenFactoryAbi, universalRouterAbi, v4QuoterAbi } from './abi/index.cjs';
5
5
  export { buildBurnRequestTypedData, buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signBurnRequest, signMintRequest, signReceiverConsent, verifyBurnRequest, verifyMintRequest, verifyReceiverConsent } from './eip712/index.cjs';
6
6
  export { getBurnRequestNonce, getIssuer, getMintRequestNonce, getPointTokenBalance, getPointTokenIssuer, getPointTokenIssuerAddress, getReceiverConsentNonce, getTokenName, isActiveIssuer, isMinter, issuerRegistryGetIssuerFlatAbi, verifyMintCap } from './contract/index.cjs';
7
7
  import { LoginMessageParams } from './auth/index.cjs';
8
- export { BuildSponsorAuthParams, BuiltSponsorAuth, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, SponsorAuthPayload, SponsorAuthVerifyResult, VerifyLoginResult, buildAndSignSponsorAuth, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth } from './auth/index.cjs';
8
+ export { BuildSponsorAuthParams, BuiltSponsorAuth, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, SponsorAuthPayload, SponsorAuthVerifyResult, VerifyLoginResult, buildAndSignSponsorAuth, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, generateSponsorAuthNonce, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth } from './auth/index.cjs';
9
9
 
10
10
  declare const mintRequestTypes: {
11
11
  readonly MintRequest: readonly [{
@@ -82,6 +82,36 @@ declare const ENTRY_POINT_V08: Address;
82
82
  /** Permit2 — Uniswap's universal approval contract, same address on all EVM chains. */
83
83
  declare const PERMIT2_ADDRESS: Address;
84
84
 
85
+ /**
86
+ * v0.7.1 — unified error base for the entire SDK (core + issuer +
87
+ * trading). Subclasses declare `code` (machine-readable) and
88
+ * `httpStatus` (recommended HTTP status for issuer's controller).
89
+ *
90
+ * Issuer's `createSdkErrorMapper` routes any `PafiSdkError` instance
91
+ * through framework-specific exception factories; non-PafiSdkError
92
+ * still becomes 500.
93
+ *
94
+ * See SDK_CORE_TRADING_AUDIT.md H3.
95
+ */
96
+ type SdkErrorHttpStatus = "not_found" | "forbidden" | "unprocessable" | "service_unavailable";
97
+ declare abstract class PafiSdkError extends Error {
98
+ abstract readonly code: string;
99
+ /**
100
+ * `true` when the FE should consider a retry safe — typically because
101
+ * the failure is transient.
102
+ */
103
+ readonly safeToRetry: boolean;
104
+ readonly details?: unknown;
105
+ abstract readonly httpStatus: SdkErrorHttpStatus;
106
+ constructor(message: string);
107
+ }
108
+ /**
109
+ * @deprecated v0.7.1 — use `PafiSdkError` (capital S, lowercase dk).
110
+ * The two classes existed in parallel ("PafiSDKError" in core,
111
+ * "PafiSdkError" in issuer) due to historical drift; consolidating
112
+ * here. Kept as alias for back-compat through v0.7.x; will be removed
113
+ * in v0.8. See SDK_CORE_TRADING_AUDIT.md H3.
114
+ */
85
115
  declare class PafiSDKError extends Error {
86
116
  constructor(message: string);
87
117
  }
@@ -106,16 +136,35 @@ declare class ApiError extends PafiSDKError {
106
136
  * caller did not opt in to the hardcoded fallback prices.
107
137
  *
108
138
  * v0.7.1 — previously `quoteOperatorFeePt` silently fell back to
109
- * ETH=$3000 / PT=$0.10 with `console.warn`. That caused mass
110
- * `INSUFFICIENT_FEE` rejects during Chainlink incidents, or worse,
111
- * accepted under-priced fees. Now opt-in via
139
+ * ETH=$3000 / PT=$0.10 with `console.warn`. Now opt-in via
112
140
  * `allowStaleFallback: true`. See SDK_CORE_TRADING_AUDIT.md C2.
141
+ *
142
+ * Extends the unified `PafiSdkError` so issuer's `createSdkErrorMapper`
143
+ * routes it to 503 instead of leaking as a 500.
113
144
  */
114
- declare class OracleStaleError extends PafiSDKError {
145
+ declare class OracleStaleError extends PafiSdkError {
146
+ readonly httpStatus: "service_unavailable";
147
+ readonly code: "ORACLE_STALE";
115
148
  readonly source: "chainlink" | "subgraph";
116
149
  readonly reason: string;
117
150
  constructor(source: "chainlink" | "subgraph", reason: string);
118
151
  }
152
+ /**
153
+ * Generic 4xx-class validation failure for input checks at any SDK
154
+ * boundary (core helpers, trading handlers, etc.). Issuer's
155
+ * `createSdkErrorMapper` routes to 422.
156
+ *
157
+ * Uses an instance `details` field so subclasses can override the
158
+ * declaration; matches the issuer-side shape that pre-existed here.
159
+ *
160
+ * v0.7.4 — added per SDK_CORE_TRADING_AUDIT.md H2/H13.
161
+ */
162
+ declare class ValidationError extends PafiSdkError {
163
+ readonly httpStatus: "unprocessable";
164
+ readonly code: string;
165
+ readonly details?: Record<string, unknown>;
166
+ constructor(code: string, message: string, details?: Record<string, unknown>);
167
+ }
119
168
 
120
169
  /**
121
170
  * Orderly Network Vault — entrypoint for **perp deposit** flow on
@@ -875,16 +924,15 @@ interface PaymasterConfig {
875
924
  type SponsorshipScenario = "mint" | "burn" | "swap" | "perp-deposit";
876
925
 
877
926
  /**
927
+ * @deprecated v0.7.1 — see file comment.
928
+ *
878
929
  * Set the application-wide paymaster config. Safe to call multiple
879
930
  * times (later calls override earlier). Throws if required fields
880
931
  * are missing.
881
932
  */
882
933
  declare function setPaymasterConfig(config: PaymasterConfig): void;
883
934
  /**
884
- * Get the current paymaster config. Throws if `setPaymasterConfig()`
885
- * has not been called yet — this surfaces boot-order bugs early
886
- * instead of failing with "paymaster.feeRecipient is undefined" at
887
- * the point of use.
935
+ * @deprecated v0.7.1 see file comment.
888
936
  */
889
937
  declare function getPaymasterConfig(): PaymasterConfig;
890
938
  /** Test helper — clear the singleton. */
@@ -1249,15 +1297,35 @@ interface SendWithPaymasterFallbackParams {
1249
1297
  */
1250
1298
  declare function sendWithPaymasterFallback(params: SendWithPaymasterFallbackParams): Promise<Hex>;
1251
1299
 
1300
+ /**
1301
+ * Per-scenario gas budgets (callGasLimit + verificationGas + preVerify)
1302
+ * used by `quoteOperatorFee*`. Defaults are calibrated against the
1303
+ * actual UserOps the issuer + trading SDKs build:
1304
+ *
1305
+ * mint — `RelayService.prepareMint` callGasLimit 300k → 500k margin
1306
+ * burn — `RelayService.prepareBurn` 300k → 500k margin
1307
+ * swap — `buildSwapUserOp` callGasLimit 700k (UR.execute heavy)
1308
+ * perp-deposit — `buildPerpDepositViaRelay` 800k (LayerZero msg)
1309
+ * delegate — minimal no-op self-call, 200k margin
1310
+ *
1311
+ * Pass an explicit `gasUnits` to override. v0.7.4 — added per
1312
+ * SDK_CORE_TRADING_AUDIT.md H12.
1313
+ */
1314
+ type FeeScenario = "mint" | "burn" | "swap" | "perp-deposit" | "delegate";
1252
1315
  interface QuoteOperatorFeePtConfig {
1253
1316
  provider: PublicClient;
1254
1317
  chainId: number;
1255
1318
  pointTokenAddress: Address;
1256
1319
  /**
1257
- * ERC-4337 gas units the UserOp will consume on chain. Default
1258
- * 500_000n covers the common scenarios (mint, swap, perp deposit
1259
- * via Relay) with margin. Pass a tighter number when you have a
1260
- * Pimlico estimate to feed in.
1320
+ * Scenario tag picks default `gasUnits` from `SCENARIO_GAS_UNITS`.
1321
+ * Ignored when `gasUnits` is explicit. Default `"mint"` for back-
1322
+ * compat (matches the legacy 500_000 constant).
1323
+ */
1324
+ scenario?: FeeScenario;
1325
+ /**
1326
+ * ERC-4337 gas units the UserOp will consume on chain. Defaults to
1327
+ * `SCENARIO_GAS_UNITS[scenario]`, falling back to 500_000n. Pass a
1328
+ * tighter number when you have a Pimlico estimate to feed in.
1261
1329
  */
1262
1330
  gasUnits?: bigint;
1263
1331
  /**
@@ -1298,6 +1366,8 @@ interface QuoteOperatorFeePtConfig {
1298
1366
  interface QuoteOperatorFeeUsdtConfig {
1299
1367
  provider: PublicClient;
1300
1368
  chainId: number;
1369
+ /** See `QuoteOperatorFeePtConfig.scenario`. v0.7.4. */
1370
+ scenario?: FeeScenario;
1301
1371
  gasUnits?: bigint;
1302
1372
  premiumBps?: number;
1303
1373
  chainlinkFeedAddress?: Address;
@@ -1686,7 +1756,7 @@ declare class PafiSDK {
1686
1756
  buildMintRequestTypedData(message: MintRequest): Promise<{
1687
1757
  domain: {
1688
1758
  name: string;
1689
- version: "1";
1759
+ version: string;
1690
1760
  chainId: number;
1691
1761
  verifyingContract: `0x${string}`;
1692
1762
  };
@@ -1711,7 +1781,7 @@ declare class PafiSDK {
1711
1781
  buildReceiverConsentTypedData(message: ReceiverConsent): Promise<{
1712
1782
  domain: {
1713
1783
  name: string;
1714
- version: "1";
1784
+ version: string;
1715
1785
  chainId: number;
1716
1786
  verifyingContract: `0x${string}`;
1717
1787
  };
@@ -1750,4 +1820,4 @@ declare class PafiSDK {
1750
1820
  signLoginMessage(message: string): Promise<Hex>;
1751
1821
  }
1752
1822
 
1753
- export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, OracleStaleError, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
1823
+ export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, OracleStaleError, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, PafiSdkError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SdkErrorHttpStatus, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, ValidationError, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Address, Hex, TypedDataDomain, PublicClient, HttpTransport, WalletClient } from 'viem';
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 } from './types-JyuXUM8C.js';
3
- export { B as BestQuote, c as BurnRequest, I as Issuer, d as PathKey, Q as QuoteResult } from './types-JyuXUM8C.js';
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 } from './types-BAkmxgVo.js';
3
+ export { B as BestQuote, c as BurnRequest, I as Issuer, d as PathKey, Q as QuoteResult } from './types-BAkmxgVo.js';
4
4
  export { pointTokenAbi as POINT_TOKEN_V2_ABI, 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 { getBurnRequestNonce, getIssuer, getMintRequestNonce, getPointTokenBalance, getPointTokenIssuer, getPointTokenIssuerAddress, getReceiverConsentNonce, getTokenName, isActiveIssuer, isMinter, issuerRegistryGetIssuerFlatAbi, verifyMintCap } from './contract/index.js';
7
7
  import { LoginMessageParams } from './auth/index.js';
8
- export { BuildSponsorAuthParams, BuiltSponsorAuth, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, SponsorAuthPayload, SponsorAuthVerifyResult, VerifyLoginResult, buildAndSignSponsorAuth, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth } from './auth/index.js';
8
+ export { BuildSponsorAuthParams, BuiltSponsorAuth, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, SponsorAuthPayload, SponsorAuthVerifyResult, VerifyLoginResult, buildAndSignSponsorAuth, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, generateSponsorAuthNonce, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth } from './auth/index.js';
9
9
 
10
10
  declare const mintRequestTypes: {
11
11
  readonly MintRequest: readonly [{
@@ -82,6 +82,36 @@ declare const ENTRY_POINT_V08: Address;
82
82
  /** Permit2 — Uniswap's universal approval contract, same address on all EVM chains. */
83
83
  declare const PERMIT2_ADDRESS: Address;
84
84
 
85
+ /**
86
+ * v0.7.1 — unified error base for the entire SDK (core + issuer +
87
+ * trading). Subclasses declare `code` (machine-readable) and
88
+ * `httpStatus` (recommended HTTP status for issuer's controller).
89
+ *
90
+ * Issuer's `createSdkErrorMapper` routes any `PafiSdkError` instance
91
+ * through framework-specific exception factories; non-PafiSdkError
92
+ * still becomes 500.
93
+ *
94
+ * See SDK_CORE_TRADING_AUDIT.md H3.
95
+ */
96
+ type SdkErrorHttpStatus = "not_found" | "forbidden" | "unprocessable" | "service_unavailable";
97
+ declare abstract class PafiSdkError extends Error {
98
+ abstract readonly code: string;
99
+ /**
100
+ * `true` when the FE should consider a retry safe — typically because
101
+ * the failure is transient.
102
+ */
103
+ readonly safeToRetry: boolean;
104
+ readonly details?: unknown;
105
+ abstract readonly httpStatus: SdkErrorHttpStatus;
106
+ constructor(message: string);
107
+ }
108
+ /**
109
+ * @deprecated v0.7.1 — use `PafiSdkError` (capital S, lowercase dk).
110
+ * The two classes existed in parallel ("PafiSDKError" in core,
111
+ * "PafiSdkError" in issuer) due to historical drift; consolidating
112
+ * here. Kept as alias for back-compat through v0.7.x; will be removed
113
+ * in v0.8. See SDK_CORE_TRADING_AUDIT.md H3.
114
+ */
85
115
  declare class PafiSDKError extends Error {
86
116
  constructor(message: string);
87
117
  }
@@ -106,16 +136,35 @@ declare class ApiError extends PafiSDKError {
106
136
  * caller did not opt in to the hardcoded fallback prices.
107
137
  *
108
138
  * v0.7.1 — previously `quoteOperatorFeePt` silently fell back to
109
- * ETH=$3000 / PT=$0.10 with `console.warn`. That caused mass
110
- * `INSUFFICIENT_FEE` rejects during Chainlink incidents, or worse,
111
- * accepted under-priced fees. Now opt-in via
139
+ * ETH=$3000 / PT=$0.10 with `console.warn`. Now opt-in via
112
140
  * `allowStaleFallback: true`. See SDK_CORE_TRADING_AUDIT.md C2.
141
+ *
142
+ * Extends the unified `PafiSdkError` so issuer's `createSdkErrorMapper`
143
+ * routes it to 503 instead of leaking as a 500.
113
144
  */
114
- declare class OracleStaleError extends PafiSDKError {
145
+ declare class OracleStaleError extends PafiSdkError {
146
+ readonly httpStatus: "service_unavailable";
147
+ readonly code: "ORACLE_STALE";
115
148
  readonly source: "chainlink" | "subgraph";
116
149
  readonly reason: string;
117
150
  constructor(source: "chainlink" | "subgraph", reason: string);
118
151
  }
152
+ /**
153
+ * Generic 4xx-class validation failure for input checks at any SDK
154
+ * boundary (core helpers, trading handlers, etc.). Issuer's
155
+ * `createSdkErrorMapper` routes to 422.
156
+ *
157
+ * Uses an instance `details` field so subclasses can override the
158
+ * declaration; matches the issuer-side shape that pre-existed here.
159
+ *
160
+ * v0.7.4 — added per SDK_CORE_TRADING_AUDIT.md H2/H13.
161
+ */
162
+ declare class ValidationError extends PafiSdkError {
163
+ readonly httpStatus: "unprocessable";
164
+ readonly code: string;
165
+ readonly details?: Record<string, unknown>;
166
+ constructor(code: string, message: string, details?: Record<string, unknown>);
167
+ }
119
168
 
120
169
  /**
121
170
  * Orderly Network Vault — entrypoint for **perp deposit** flow on
@@ -875,16 +924,15 @@ interface PaymasterConfig {
875
924
  type SponsorshipScenario = "mint" | "burn" | "swap" | "perp-deposit";
876
925
 
877
926
  /**
927
+ * @deprecated v0.7.1 — see file comment.
928
+ *
878
929
  * Set the application-wide paymaster config. Safe to call multiple
879
930
  * times (later calls override earlier). Throws if required fields
880
931
  * are missing.
881
932
  */
882
933
  declare function setPaymasterConfig(config: PaymasterConfig): void;
883
934
  /**
884
- * Get the current paymaster config. Throws if `setPaymasterConfig()`
885
- * has not been called yet — this surfaces boot-order bugs early
886
- * instead of failing with "paymaster.feeRecipient is undefined" at
887
- * the point of use.
935
+ * @deprecated v0.7.1 see file comment.
888
936
  */
889
937
  declare function getPaymasterConfig(): PaymasterConfig;
890
938
  /** Test helper — clear the singleton. */
@@ -1249,15 +1297,35 @@ interface SendWithPaymasterFallbackParams {
1249
1297
  */
1250
1298
  declare function sendWithPaymasterFallback(params: SendWithPaymasterFallbackParams): Promise<Hex>;
1251
1299
 
1300
+ /**
1301
+ * Per-scenario gas budgets (callGasLimit + verificationGas + preVerify)
1302
+ * used by `quoteOperatorFee*`. Defaults are calibrated against the
1303
+ * actual UserOps the issuer + trading SDKs build:
1304
+ *
1305
+ * mint — `RelayService.prepareMint` callGasLimit 300k → 500k margin
1306
+ * burn — `RelayService.prepareBurn` 300k → 500k margin
1307
+ * swap — `buildSwapUserOp` callGasLimit 700k (UR.execute heavy)
1308
+ * perp-deposit — `buildPerpDepositViaRelay` 800k (LayerZero msg)
1309
+ * delegate — minimal no-op self-call, 200k margin
1310
+ *
1311
+ * Pass an explicit `gasUnits` to override. v0.7.4 — added per
1312
+ * SDK_CORE_TRADING_AUDIT.md H12.
1313
+ */
1314
+ type FeeScenario = "mint" | "burn" | "swap" | "perp-deposit" | "delegate";
1252
1315
  interface QuoteOperatorFeePtConfig {
1253
1316
  provider: PublicClient;
1254
1317
  chainId: number;
1255
1318
  pointTokenAddress: Address;
1256
1319
  /**
1257
- * ERC-4337 gas units the UserOp will consume on chain. Default
1258
- * 500_000n covers the common scenarios (mint, swap, perp deposit
1259
- * via Relay) with margin. Pass a tighter number when you have a
1260
- * Pimlico estimate to feed in.
1320
+ * Scenario tag picks default `gasUnits` from `SCENARIO_GAS_UNITS`.
1321
+ * Ignored when `gasUnits` is explicit. Default `"mint"` for back-
1322
+ * compat (matches the legacy 500_000 constant).
1323
+ */
1324
+ scenario?: FeeScenario;
1325
+ /**
1326
+ * ERC-4337 gas units the UserOp will consume on chain. Defaults to
1327
+ * `SCENARIO_GAS_UNITS[scenario]`, falling back to 500_000n. Pass a
1328
+ * tighter number when you have a Pimlico estimate to feed in.
1261
1329
  */
1262
1330
  gasUnits?: bigint;
1263
1331
  /**
@@ -1298,6 +1366,8 @@ interface QuoteOperatorFeePtConfig {
1298
1366
  interface QuoteOperatorFeeUsdtConfig {
1299
1367
  provider: PublicClient;
1300
1368
  chainId: number;
1369
+ /** See `QuoteOperatorFeePtConfig.scenario`. v0.7.4. */
1370
+ scenario?: FeeScenario;
1301
1371
  gasUnits?: bigint;
1302
1372
  premiumBps?: number;
1303
1373
  chainlinkFeedAddress?: Address;
@@ -1686,7 +1756,7 @@ declare class PafiSDK {
1686
1756
  buildMintRequestTypedData(message: MintRequest): Promise<{
1687
1757
  domain: {
1688
1758
  name: string;
1689
- version: "1";
1759
+ version: string;
1690
1760
  chainId: number;
1691
1761
  verifyingContract: `0x${string}`;
1692
1762
  };
@@ -1711,7 +1781,7 @@ declare class PafiSDK {
1711
1781
  buildReceiverConsentTypedData(message: ReceiverConsent): Promise<{
1712
1782
  domain: {
1713
1783
  name: string;
1714
- version: "1";
1784
+ version: string;
1715
1785
  chainId: number;
1716
1786
  verifyingContract: `0x${string}`;
1717
1787
  };
@@ -1750,4 +1820,4 @@ declare class PafiSDK {
1750
1820
  signLoginMessage(message: string): Promise<Hex>;
1751
1821
  }
1752
1822
 
1753
- export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, OracleStaleError, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
1823
+ export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, OracleStaleError, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, PafiSdkError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SdkErrorHttpStatus, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, ValidationError, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
package/dist/index.js CHANGED
@@ -13,11 +13,12 @@ import {
13
13
  buildSponsorAuthTypedData,
14
14
  computeCallDataHash,
15
15
  createLoginMessage,
16
+ generateSponsorAuthNonce,
16
17
  parseLoginMessage,
17
18
  signSponsorAuth,
18
19
  verifyLoginMessage,
19
20
  verifySponsorAuth
20
- } from "./chunk-QGXJLLKF.js";
21
+ } from "./chunk-6UX2IFA2.js";
21
22
  import {
22
23
  getBurnRequestNonce,
23
24
  getIssuer,
@@ -60,12 +61,25 @@ import {
60
61
  verifyBurnRequest,
61
62
  verifyMintRequest,
62
63
  verifyReceiverConsent
63
- } from "./chunk-UOKI5GG6.js";
64
+ } from "./chunk-WJSIB5GF.js";
65
+ import "./chunk-DGUM43GV.js";
64
66
 
65
67
  // src/index.ts
66
68
  import { createPublicClient, http as http2 } from "viem";
67
69
 
68
70
  // src/errors.ts
71
+ var PafiSdkError = class extends Error {
72
+ /**
73
+ * `true` when the FE should consider a retry safe — typically because
74
+ * the failure is transient.
75
+ */
76
+ safeToRetry = false;
77
+ details;
78
+ constructor(message) {
79
+ super(message);
80
+ this.name = new.target.name;
81
+ }
82
+ };
69
83
  var PafiSDKError = class extends Error {
70
84
  constructor(message) {
71
85
  super(message);
@@ -102,16 +116,27 @@ var ApiError = class extends PafiSDKError {
102
116
  }
103
117
  status;
104
118
  };
105
- var OracleStaleError = class extends PafiSDKError {
119
+ var OracleStaleError = class extends PafiSdkError {
120
+ httpStatus = "service_unavailable";
121
+ code = "ORACLE_STALE";
106
122
  source;
107
123
  reason;
108
124
  constructor(source, reason) {
109
125
  super(`Oracle ${source} unavailable: ${reason}`);
110
- this.name = "OracleStaleError";
111
126
  this.source = source;
112
127
  this.reason = reason;
113
128
  }
114
129
  };
130
+ var ValidationError = class extends PafiSdkError {
131
+ httpStatus = "unprocessable";
132
+ code;
133
+ details;
134
+ constructor(code, message, details) {
135
+ super(message);
136
+ this.code = code;
137
+ this.details = details;
138
+ }
139
+ };
115
140
 
116
141
  // src/perp/buildPerpDepositWithGasDeduction.ts
117
142
  import { encodeFunctionData as encodeFunctionData3 } from "viem";
@@ -912,6 +937,13 @@ var POOL_PRICE_QUERY = `
912
937
  }
913
938
  }
914
939
  `;
940
+ var SCENARIO_GAS_UNITS = {
941
+ mint: 500000n,
942
+ burn: 500000n,
943
+ swap: 700000n,
944
+ "perp-deposit": 800000n,
945
+ delegate: 200000n
946
+ };
915
947
  var DEFAULT_GAS_UNITS = 500000n;
916
948
  var DEFAULT_PREMIUM_BPS = 12e3;
917
949
  var DEFAULT_USDT_DECIMALS = 6;
@@ -919,7 +951,8 @@ async function quoteOperatorFeeUsdt(config) {
919
951
  const {
920
952
  provider,
921
953
  chainId,
922
- gasUnits = DEFAULT_GAS_UNITS,
954
+ scenario = "mint",
955
+ gasUnits = SCENARIO_GAS_UNITS[scenario] ?? DEFAULT_GAS_UNITS,
923
956
  premiumBps = DEFAULT_PREMIUM_BPS,
924
957
  usdtDecimals = DEFAULT_USDT_DECIMALS,
925
958
  allowStaleFallback = false,
@@ -942,7 +975,8 @@ async function quoteOperatorFeePt(config) {
942
975
  provider,
943
976
  chainId,
944
977
  pointTokenAddress,
945
- gasUnits = DEFAULT_GAS_UNITS,
978
+ scenario = "mint",
979
+ gasUnits = SCENARIO_GAS_UNITS[scenario] ?? DEFAULT_GAS_UNITS,
946
980
  premiumBps = DEFAULT_PREMIUM_BPS,
947
981
  subgraphUrl = PAFI_SUBGRAPH_URL,
948
982
  usdtDecimals = DEFAULT_USDT_DECIMALS,
@@ -1353,6 +1387,7 @@ export {
1353
1387
  pointTokenAbi as POINT_TOKEN_V2_ABI,
1354
1388
  PafiSDK,
1355
1389
  PafiSDKError,
1390
+ PafiSdkError,
1356
1391
  SIMPLE_7702_IMPL_BASE_MAINNET,
1357
1392
  SPONSOR_AUTH_DOMAIN_NAME,
1358
1393
  SPONSOR_AUTH_TYPES,
@@ -1362,6 +1397,7 @@ export {
1362
1397
  TOKEN_HASHES,
1363
1398
  UNIVERSAL_ROUTER_ADDRESSES,
1364
1399
  V4_QUOTER_ADDRESSES,
1400
+ ValidationError,
1365
1401
  ZERO_VALUE,
1366
1402
  _resetPaymasterConfigForTests,
1367
1403
  assembleUserOperation,
@@ -1395,6 +1431,7 @@ export {
1395
1431
  erc20BurnOp,
1396
1432
  erc20TransferOp,
1397
1433
  fetchPafiPools,
1434
+ generateSponsorAuthNonce,
1398
1435
  getAaNonce,
1399
1436
  getBurnRequestNonce,
1400
1437
  getContractAddresses,