@pafi-dev/core 0.7.0 → 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.
- package/dist/abi/index.cjs +1 -0
- package/dist/abi/index.cjs.map +1 -1
- package/dist/abi/index.js +1 -0
- package/dist/auth/index.cjs +5 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +10 -1
- package/dist/auth/index.d.ts +10 -1
- package/dist/auth/index.js +4 -1
- package/dist/{chunk-RZDG6SRR.cjs → chunk-5254AG3Z.cjs} +36 -5
- package/dist/chunk-5254AG3Z.cjs.map +1 -0
- package/dist/{chunk-QGXJLLKF.js → chunk-6UX2IFA2.js} +34 -3
- package/dist/chunk-6UX2IFA2.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +11 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/{chunk-3QDZFDEL.cjs → chunk-M5ULOZ3A.cjs} +3 -3
- package/dist/chunk-M5ULOZ3A.cjs.map +1 -0
- package/dist/{chunk-UOKI5GG6.js → chunk-WJSIB5GF.js} +2 -2
- package/dist/chunk-WJSIB5GF.js.map +1 -0
- package/dist/contract/index.cjs +1 -0
- package/dist/contract/index.cjs.map +1 -1
- package/dist/contract/index.d.cts +1 -1
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +1 -0
- package/dist/eip712/index.cjs +3 -2
- package/dist/eip712/index.cjs.map +1 -1
- package/dist/eip712/index.d.cts +10 -5
- package/dist/eip712/index.d.ts +10 -5
- package/dist/eip712/index.js +2 -1
- package/dist/index.cjs +112 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -19
- package/dist/index.d.ts +126 -19
- package/dist/index.js +93 -18
- package/dist/index.js.map +1 -1
- package/dist/{types-JyuXUM8C.d.cts → types-BAkmxgVo.d.cts} +10 -0
- package/dist/{types-JyuXUM8C.d.ts → types-BAkmxgVo.d.ts} +10 -0
- package/package.json +1 -1
- package/dist/chunk-3QDZFDEL.cjs.map +0 -1
- package/dist/chunk-QGXJLLKF.js.map +0 -1
- package/dist/chunk-RZDG6SRR.cjs.map +0 -1
- package/dist/chunk-UOKI5GG6.js.map +0 -1
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-
|
|
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-
|
|
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,6 +116,27 @@ var ApiError = class extends PafiSDKError {
|
|
|
102
116
|
}
|
|
103
117
|
status;
|
|
104
118
|
};
|
|
119
|
+
var OracleStaleError = class extends PafiSdkError {
|
|
120
|
+
httpStatus = "service_unavailable";
|
|
121
|
+
code = "ORACLE_STALE";
|
|
122
|
+
source;
|
|
123
|
+
reason;
|
|
124
|
+
constructor(source, reason) {
|
|
125
|
+
super(`Oracle ${source} unavailable: ${reason}`);
|
|
126
|
+
this.source = source;
|
|
127
|
+
this.reason = reason;
|
|
128
|
+
}
|
|
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
|
+
};
|
|
105
140
|
|
|
106
141
|
// src/perp/buildPerpDepositWithGasDeduction.ts
|
|
107
142
|
import { encodeFunctionData as encodeFunctionData3 } from "viem";
|
|
@@ -594,11 +629,9 @@ function parseEip7702DelegatedAddress(code) {
|
|
|
594
629
|
if (!code || code === "0x" || code === "0x0") return null;
|
|
595
630
|
const normalized = code.toLowerCase();
|
|
596
631
|
const magic = EIP7702_MAGIC.toLowerCase();
|
|
597
|
-
|
|
598
|
-
if (
|
|
599
|
-
|
|
600
|
-
if (raw.length !== 40) return null;
|
|
601
|
-
return `0x${raw}`;
|
|
632
|
+
if (!normalized.startsWith(magic)) return null;
|
|
633
|
+
if (normalized.length !== magic.length + 40) return null;
|
|
634
|
+
return `0x${normalized.slice(magic.length)}`;
|
|
602
635
|
}
|
|
603
636
|
async function checkDelegation(client, address) {
|
|
604
637
|
const code = await client.getCode({ address });
|
|
@@ -727,9 +760,24 @@ function createPafiProxyTransport(params) {
|
|
|
727
760
|
}
|
|
728
761
|
|
|
729
762
|
// src/transport/paymasterFallback.ts
|
|
763
|
+
var PAYMASTER_HTTP_STATUSES = /* @__PURE__ */ new Set([401, 403, 429, 503]);
|
|
764
|
+
var PAYMASTER_PATTERNS = [
|
|
765
|
+
/\bAA3[1-4]\b/i,
|
|
766
|
+
/\bpaymaster\b/i,
|
|
767
|
+
/\bsponsorship\b/i,
|
|
768
|
+
/\bpm_\w+/i,
|
|
769
|
+
/\brate ?limit\b/i,
|
|
770
|
+
/\bunauthorized\b/i
|
|
771
|
+
];
|
|
730
772
|
function isPaymasterError(err) {
|
|
731
|
-
|
|
732
|
-
|
|
773
|
+
if (err == null || typeof err !== "object") return false;
|
|
774
|
+
const e = err;
|
|
775
|
+
const status = e.status ?? e.statusCode ?? e.response?.status ?? e.cause?.status;
|
|
776
|
+
if (typeof status === "number" && PAYMASTER_HTTP_STATUSES.has(status)) {
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
const msg = e.message ?? String(err);
|
|
780
|
+
return PAYMASTER_PATTERNS.some((re) => re.test(msg));
|
|
733
781
|
}
|
|
734
782
|
async function sendWithPaymasterFallback(params) {
|
|
735
783
|
const { primaryClient, fallbackClient, txParams, txParamsFallback, onFallback } = params;
|
|
@@ -889,6 +937,13 @@ var POOL_PRICE_QUERY = `
|
|
|
889
937
|
}
|
|
890
938
|
}
|
|
891
939
|
`;
|
|
940
|
+
var SCENARIO_GAS_UNITS = {
|
|
941
|
+
mint: 500000n,
|
|
942
|
+
burn: 500000n,
|
|
943
|
+
swap: 700000n,
|
|
944
|
+
"perp-deposit": 800000n,
|
|
945
|
+
delegate: 200000n
|
|
946
|
+
};
|
|
892
947
|
var DEFAULT_GAS_UNITS = 500000n;
|
|
893
948
|
var DEFAULT_PREMIUM_BPS = 12e3;
|
|
894
949
|
var DEFAULT_USDT_DECIMALS = 6;
|
|
@@ -896,9 +951,11 @@ async function quoteOperatorFeeUsdt(config) {
|
|
|
896
951
|
const {
|
|
897
952
|
provider,
|
|
898
953
|
chainId,
|
|
899
|
-
|
|
954
|
+
scenario = "mint",
|
|
955
|
+
gasUnits = SCENARIO_GAS_UNITS[scenario] ?? DEFAULT_GAS_UNITS,
|
|
900
956
|
premiumBps = DEFAULT_PREMIUM_BPS,
|
|
901
957
|
usdtDecimals = DEFAULT_USDT_DECIMALS,
|
|
958
|
+
allowStaleFallback = false,
|
|
902
959
|
fallbackEthPriceUsd = 3e3
|
|
903
960
|
} = config;
|
|
904
961
|
const chainlinkFeedAddress = config.chainlinkFeedAddress ?? getContractAddresses(chainId).chainlinkEthUsd;
|
|
@@ -908,7 +965,7 @@ async function quoteOperatorFeeUsdt(config) {
|
|
|
908
965
|
const ethPrice8dec = await getEthPrice8dec(
|
|
909
966
|
provider,
|
|
910
967
|
chainlinkFeedAddress,
|
|
911
|
-
fallbackEthPriceUsd
|
|
968
|
+
allowStaleFallback ? fallbackEthPriceUsd : null
|
|
912
969
|
);
|
|
913
970
|
const denomExp = 18 + 8 - usdtDecimals;
|
|
914
971
|
return withPremium * ethPrice8dec / 10n ** BigInt(denomExp);
|
|
@@ -918,10 +975,12 @@ async function quoteOperatorFeePt(config) {
|
|
|
918
975
|
provider,
|
|
919
976
|
chainId,
|
|
920
977
|
pointTokenAddress,
|
|
921
|
-
|
|
978
|
+
scenario = "mint",
|
|
979
|
+
gasUnits = SCENARIO_GAS_UNITS[scenario] ?? DEFAULT_GAS_UNITS,
|
|
922
980
|
premiumBps = DEFAULT_PREMIUM_BPS,
|
|
923
981
|
subgraphUrl = PAFI_SUBGRAPH_URL,
|
|
924
982
|
usdtDecimals = DEFAULT_USDT_DECIMALS,
|
|
983
|
+
allowStaleFallback = false,
|
|
925
984
|
fallbackEthPriceUsd = 3e3,
|
|
926
985
|
fallbackPtPriceUsdt = 0.1,
|
|
927
986
|
fetchImpl = globalThis.fetch
|
|
@@ -931,12 +990,16 @@ async function quoteOperatorFeePt(config) {
|
|
|
931
990
|
const nativeCost = gasPrice * gasUnits;
|
|
932
991
|
const withPremium = nativeCost * BigInt(premiumBps) / 10000n;
|
|
933
992
|
const [ethPrice8dec, ptPerUsdt18dec] = await Promise.all([
|
|
934
|
-
getEthPrice8dec(
|
|
993
|
+
getEthPrice8dec(
|
|
994
|
+
provider,
|
|
995
|
+
chainlinkFeedAddress,
|
|
996
|
+
allowStaleFallback ? fallbackEthPriceUsd : null
|
|
997
|
+
),
|
|
935
998
|
getPtPerUsdt18dec(
|
|
936
999
|
fetchImpl,
|
|
937
1000
|
subgraphUrl,
|
|
938
1001
|
pointTokenAddress,
|
|
939
|
-
fallbackPtPriceUsdt
|
|
1002
|
+
allowStaleFallback ? fallbackPtPriceUsdt : null
|
|
940
1003
|
)
|
|
941
1004
|
]);
|
|
942
1005
|
return withPremium * ethPrice8dec * ptPerUsdt18dec / 10n ** 26n;
|
|
@@ -957,9 +1020,13 @@ async function getEthPrice8dec(provider, feed, fallback) {
|
|
|
957
1020
|
}
|
|
958
1021
|
return answer;
|
|
959
1022
|
} catch (err) {
|
|
1023
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
1024
|
+
if (fallback === null) {
|
|
1025
|
+
throw new OracleStaleError("chainlink", reason);
|
|
1026
|
+
}
|
|
960
1027
|
console.warn(
|
|
961
|
-
"[
|
|
962
|
-
|
|
1028
|
+
"[quoteOperatorFee] Chainlink unavailable, using opt-in fallback:",
|
|
1029
|
+
reason
|
|
963
1030
|
);
|
|
964
1031
|
return BigInt(Math.round(fallback * 1e8));
|
|
965
1032
|
}
|
|
@@ -992,9 +1059,13 @@ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fall
|
|
|
992
1059
|
}
|
|
993
1060
|
return 10n ** 24n / raw;
|
|
994
1061
|
} catch (err) {
|
|
1062
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
1063
|
+
if (fallbackPtPriceUsdt === null) {
|
|
1064
|
+
throw new OracleStaleError("subgraph", reason);
|
|
1065
|
+
}
|
|
995
1066
|
console.warn(
|
|
996
|
-
"[quoteOperatorFeePt] subgraph unavailable, using fallback:",
|
|
997
|
-
|
|
1067
|
+
"[quoteOperatorFeePt] subgraph unavailable, using opt-in fallback:",
|
|
1068
|
+
reason
|
|
998
1069
|
);
|
|
999
1070
|
const ptPerUsdtHuman = 1 / fallbackPtPriceUsdt;
|
|
1000
1071
|
return parseBigDecimalTo18(ptPerUsdtHuman.toFixed(18));
|
|
@@ -1307,6 +1378,7 @@ export {
|
|
|
1307
1378
|
ORDERLY_VAULT_ABI,
|
|
1308
1379
|
ORDERLY_VAULT_ADDRESSES,
|
|
1309
1380
|
ORDERLY_VAULT_BASE_MAINNET,
|
|
1381
|
+
OracleStaleError,
|
|
1310
1382
|
PAFI_SUBGRAPH_URL,
|
|
1311
1383
|
PERMIT2_ADDRESS,
|
|
1312
1384
|
POINT_TOKEN_FACTORY_ADDRESSES,
|
|
@@ -1315,6 +1387,7 @@ export {
|
|
|
1315
1387
|
pointTokenAbi as POINT_TOKEN_V2_ABI,
|
|
1316
1388
|
PafiSDK,
|
|
1317
1389
|
PafiSDKError,
|
|
1390
|
+
PafiSdkError,
|
|
1318
1391
|
SIMPLE_7702_IMPL_BASE_MAINNET,
|
|
1319
1392
|
SPONSOR_AUTH_DOMAIN_NAME,
|
|
1320
1393
|
SPONSOR_AUTH_TYPES,
|
|
@@ -1324,6 +1397,7 @@ export {
|
|
|
1324
1397
|
TOKEN_HASHES,
|
|
1325
1398
|
UNIVERSAL_ROUTER_ADDRESSES,
|
|
1326
1399
|
V4_QUOTER_ADDRESSES,
|
|
1400
|
+
ValidationError,
|
|
1327
1401
|
ZERO_VALUE,
|
|
1328
1402
|
_resetPaymasterConfigForTests,
|
|
1329
1403
|
assembleUserOperation,
|
|
@@ -1357,6 +1431,7 @@ export {
|
|
|
1357
1431
|
erc20BurnOp,
|
|
1358
1432
|
erc20TransferOp,
|
|
1359
1433
|
fetchPafiPools,
|
|
1434
|
+
generateSponsorAuthNonce,
|
|
1360
1435
|
getAaNonce,
|
|
1361
1436
|
getBurnRequestNonce,
|
|
1362
1437
|
getContractAddresses,
|