@pafi-dev/core 0.7.0 → 0.7.1
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/index.cjs +61 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -6
- package/dist/index.d.ts +43 -6
- package/dist/index.js +52 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,16 @@ var ApiError = class extends PafiSDKError {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
};
|
|
105
|
+
var OracleStaleError = class extends PafiSDKError {
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
constructor(source, reason) {
|
|
109
|
+
super(`Oracle ${source} unavailable: ${reason}`);
|
|
110
|
+
this.name = "OracleStaleError";
|
|
111
|
+
this.source = source;
|
|
112
|
+
this.reason = reason;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
105
115
|
|
|
106
116
|
// src/perp/buildPerpDepositWithGasDeduction.ts
|
|
107
117
|
|
|
@@ -594,11 +604,9 @@ function parseEip7702DelegatedAddress(code) {
|
|
|
594
604
|
if (!code || code === "0x" || code === "0x0") return null;
|
|
595
605
|
const normalized = code.toLowerCase();
|
|
596
606
|
const magic = EIP7702_MAGIC.toLowerCase();
|
|
597
|
-
|
|
598
|
-
if (
|
|
599
|
-
|
|
600
|
-
if (raw.length !== 40) return null;
|
|
601
|
-
return `0x${raw}`;
|
|
607
|
+
if (!normalized.startsWith(magic)) return null;
|
|
608
|
+
if (normalized.length !== magic.length + 40) return null;
|
|
609
|
+
return `0x${normalized.slice(magic.length)}`;
|
|
602
610
|
}
|
|
603
611
|
async function checkDelegation(client, address) {
|
|
604
612
|
const code = await client.getCode({ address });
|
|
@@ -727,9 +735,24 @@ function createPafiProxyTransport(params) {
|
|
|
727
735
|
}
|
|
728
736
|
|
|
729
737
|
// src/transport/paymasterFallback.ts
|
|
738
|
+
var PAYMASTER_HTTP_STATUSES = /* @__PURE__ */ new Set([401, 403, 429, 503]);
|
|
739
|
+
var PAYMASTER_PATTERNS = [
|
|
740
|
+
/\bAA3[1-4]\b/i,
|
|
741
|
+
/\bpaymaster\b/i,
|
|
742
|
+
/\bsponsorship\b/i,
|
|
743
|
+
/\bpm_\w+/i,
|
|
744
|
+
/\brate ?limit\b/i,
|
|
745
|
+
/\bunauthorized\b/i
|
|
746
|
+
];
|
|
730
747
|
function isPaymasterError(err) {
|
|
731
|
-
|
|
732
|
-
|
|
748
|
+
if (err == null || typeof err !== "object") return false;
|
|
749
|
+
const e = err;
|
|
750
|
+
const status = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(e.status, () => ( e.statusCode)), () => ( _optionalChain([e, 'access', _30 => _30.response, 'optionalAccess', _31 => _31.status]))), () => ( _optionalChain([e, 'access', _32 => _32.cause, 'optionalAccess', _33 => _33.status])));
|
|
751
|
+
if (typeof status === "number" && PAYMASTER_HTTP_STATUSES.has(status)) {
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
const msg = _nullishCoalesce(e.message, () => ( String(err)));
|
|
755
|
+
return PAYMASTER_PATTERNS.some((re) => re.test(msg));
|
|
733
756
|
}
|
|
734
757
|
async function sendWithPaymasterFallback(params) {
|
|
735
758
|
const { primaryClient, fallbackClient, txParams, txParamsFallback, onFallback } = params;
|
|
@@ -737,8 +760,8 @@ async function sendWithPaymasterFallback(params) {
|
|
|
737
760
|
return await primaryClient.sendTransaction(txParams);
|
|
738
761
|
} catch (err) {
|
|
739
762
|
if (isPaymasterError(err) && fallbackClient) {
|
|
740
|
-
const msg = _nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
741
|
-
_optionalChain([onFallback, 'optionalCall',
|
|
763
|
+
const msg = _nullishCoalesce(_optionalChain([err, 'optionalAccess', _34 => _34.message]), () => ( String(err)));
|
|
764
|
+
_optionalChain([onFallback, 'optionalCall', _35 => _35(msg)]);
|
|
742
765
|
return await fallbackClient.sendTransaction(_nullishCoalesce(txParamsFallback, () => ( txParams)));
|
|
743
766
|
}
|
|
744
767
|
throw err;
|
|
@@ -796,7 +819,7 @@ async function fetchPafiPools(_chainId, pointTokenAddress, subgraphUrl = PAFI_SU
|
|
|
796
819
|
);
|
|
797
820
|
return [];
|
|
798
821
|
}
|
|
799
|
-
const pool = _optionalChain([json, 'access',
|
|
822
|
+
const pool = _optionalChain([json, 'access', _36 => _36.data, 'optionalAccess', _37 => _37.pafiToken, 'optionalAccess', _38 => _38.pool]);
|
|
800
823
|
if (!pool) return [];
|
|
801
824
|
if (!_viem.isAddress.call(void 0, pool.hooks) || !_viem.isAddress.call(void 0, pool.token0.id) || !_viem.isAddress.call(void 0, pool.token1.id) || !Number.isFinite(Number(pool.feeTier)) || !Number.isFinite(Number(pool.tickSpacing))) {
|
|
802
825
|
console.error("[fetchPafiPools] invalid pool data in subgraph response \u2014 skipping");
|
|
@@ -899,6 +922,7 @@ async function quoteOperatorFeeUsdt(config) {
|
|
|
899
922
|
gasUnits = DEFAULT_GAS_UNITS,
|
|
900
923
|
premiumBps = DEFAULT_PREMIUM_BPS,
|
|
901
924
|
usdtDecimals = DEFAULT_USDT_DECIMALS,
|
|
925
|
+
allowStaleFallback = false,
|
|
902
926
|
fallbackEthPriceUsd = 3e3
|
|
903
927
|
} = config;
|
|
904
928
|
const chainlinkFeedAddress = _nullishCoalesce(config.chainlinkFeedAddress, () => ( getContractAddresses(chainId).chainlinkEthUsd));
|
|
@@ -908,7 +932,7 @@ async function quoteOperatorFeeUsdt(config) {
|
|
|
908
932
|
const ethPrice8dec = await getEthPrice8dec(
|
|
909
933
|
provider,
|
|
910
934
|
chainlinkFeedAddress,
|
|
911
|
-
fallbackEthPriceUsd
|
|
935
|
+
allowStaleFallback ? fallbackEthPriceUsd : null
|
|
912
936
|
);
|
|
913
937
|
const denomExp = 18 + 8 - usdtDecimals;
|
|
914
938
|
return withPremium * ethPrice8dec / 10n ** BigInt(denomExp);
|
|
@@ -922,6 +946,7 @@ async function quoteOperatorFeePt(config) {
|
|
|
922
946
|
premiumBps = DEFAULT_PREMIUM_BPS,
|
|
923
947
|
subgraphUrl = PAFI_SUBGRAPH_URL,
|
|
924
948
|
usdtDecimals = DEFAULT_USDT_DECIMALS,
|
|
949
|
+
allowStaleFallback = false,
|
|
925
950
|
fallbackEthPriceUsd = 3e3,
|
|
926
951
|
fallbackPtPriceUsdt = 0.1,
|
|
927
952
|
fetchImpl = globalThis.fetch
|
|
@@ -931,12 +956,16 @@ async function quoteOperatorFeePt(config) {
|
|
|
931
956
|
const nativeCost = gasPrice * gasUnits;
|
|
932
957
|
const withPremium = nativeCost * BigInt(premiumBps) / 10000n;
|
|
933
958
|
const [ethPrice8dec, ptPerUsdt18dec] = await Promise.all([
|
|
934
|
-
getEthPrice8dec(
|
|
959
|
+
getEthPrice8dec(
|
|
960
|
+
provider,
|
|
961
|
+
chainlinkFeedAddress,
|
|
962
|
+
allowStaleFallback ? fallbackEthPriceUsd : null
|
|
963
|
+
),
|
|
935
964
|
getPtPerUsdt18dec(
|
|
936
965
|
fetchImpl,
|
|
937
966
|
subgraphUrl,
|
|
938
967
|
pointTokenAddress,
|
|
939
|
-
fallbackPtPriceUsdt
|
|
968
|
+
allowStaleFallback ? fallbackPtPriceUsdt : null
|
|
940
969
|
)
|
|
941
970
|
]);
|
|
942
971
|
return withPremium * ethPrice8dec * ptPerUsdt18dec / 10n ** 26n;
|
|
@@ -957,9 +986,13 @@ async function getEthPrice8dec(provider, feed, fallback) {
|
|
|
957
986
|
}
|
|
958
987
|
return answer;
|
|
959
988
|
} catch (err) {
|
|
989
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
990
|
+
if (fallback === null) {
|
|
991
|
+
throw new OracleStaleError("chainlink", reason);
|
|
992
|
+
}
|
|
960
993
|
console.warn(
|
|
961
|
-
"[
|
|
962
|
-
|
|
994
|
+
"[quoteOperatorFee] Chainlink unavailable, using opt-in fallback:",
|
|
995
|
+
reason
|
|
963
996
|
);
|
|
964
997
|
return BigInt(Math.round(fallback * 1e8));
|
|
965
998
|
}
|
|
@@ -976,10 +1009,10 @@ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fall
|
|
|
976
1009
|
});
|
|
977
1010
|
if (!response.ok) throw new Error(`subgraph HTTP ${response.status}`);
|
|
978
1011
|
const json = await response.json();
|
|
979
|
-
if (_optionalChain([json, 'access',
|
|
1012
|
+
if (_optionalChain([json, 'access', _39 => _39.errors, 'optionalAccess', _40 => _40.length])) {
|
|
980
1013
|
throw new Error(json.errors.map((e) => e.message).join("; "));
|
|
981
1014
|
}
|
|
982
|
-
const pool = _optionalChain([json, 'access',
|
|
1015
|
+
const pool = _optionalChain([json, 'access', _41 => _41.data, 'optionalAccess', _42 => _42.pafiToken, 'optionalAccess', _43 => _43.pool]);
|
|
983
1016
|
if (!pool) throw new Error("pafiToken or pool not found");
|
|
984
1017
|
const isPtToken0 = pool.token0.id.toLowerCase() === pointTokenAddress.toLowerCase();
|
|
985
1018
|
const priceStr = isPtToken0 ? pool.token0Price : pool.token1Price;
|
|
@@ -992,9 +1025,13 @@ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fall
|
|
|
992
1025
|
}
|
|
993
1026
|
return 10n ** 24n / raw;
|
|
994
1027
|
} catch (err) {
|
|
1028
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
1029
|
+
if (fallbackPtPriceUsdt === null) {
|
|
1030
|
+
throw new OracleStaleError("subgraph", reason);
|
|
1031
|
+
}
|
|
995
1032
|
console.warn(
|
|
996
|
-
"[quoteOperatorFeePt] subgraph unavailable, using fallback:",
|
|
997
|
-
|
|
1033
|
+
"[quoteOperatorFeePt] subgraph unavailable, using opt-in fallback:",
|
|
1034
|
+
reason
|
|
998
1035
|
);
|
|
999
1036
|
const ptPerUsdtHuman = 1 / fallbackPtPriceUsdt;
|
|
1000
1037
|
return parseBigDecimalTo18(ptPerUsdtHuman.toFixed(18));
|
|
@@ -1024,8 +1061,8 @@ function openWebPopup(url, options = {}) {
|
|
|
1024
1061
|
const width = _nullishCoalesce(options.width, () => ( DEFAULT_WIDTH));
|
|
1025
1062
|
const height = _nullishCoalesce(options.height, () => ( DEFAULT_HEIGHT));
|
|
1026
1063
|
const name = _nullishCoalesce(options.windowName, () => ( DEFAULT_NAME));
|
|
1027
|
-
const screenW = _nullishCoalesce(_optionalChain([window, 'access',
|
|
1028
|
-
const screenH = _nullishCoalesce(_optionalChain([window, 'access',
|
|
1064
|
+
const screenW = _nullishCoalesce(_optionalChain([window, 'access', _44 => _44.screen, 'optionalAccess', _45 => _45.availWidth]), () => ( window.innerWidth));
|
|
1065
|
+
const screenH = _nullishCoalesce(_optionalChain([window, 'access', _46 => _46.screen, 'optionalAccess', _47 => _47.availHeight]), () => ( window.innerHeight));
|
|
1029
1066
|
const left = Math.max(0, Math.floor((screenW - width) / 2));
|
|
1030
1067
|
const top = Math.max(0, Math.floor((screenH - height) / 2));
|
|
1031
1068
|
const features = [
|
|
@@ -1058,7 +1095,7 @@ function openWebPopup(url, options = {}) {
|
|
|
1058
1095
|
window.removeEventListener("message", messageListener);
|
|
1059
1096
|
messageListener = null;
|
|
1060
1097
|
}
|
|
1061
|
-
_optionalChain([options, 'access',
|
|
1098
|
+
_optionalChain([options, 'access', _48 => _48.onClose, 'optionalCall', _49 => _49()]);
|
|
1062
1099
|
};
|
|
1063
1100
|
pollId = setInterval(() => {
|
|
1064
1101
|
if (popup.closed) {
|
|
@@ -1409,5 +1446,6 @@ var PafiSDK = class {
|
|
|
1409
1446
|
|
|
1410
1447
|
|
|
1411
1448
|
|
|
1412
|
-
|
|
1449
|
+
|
|
1450
|
+
exports.ApiError = ApiError; exports.BATCH_EXECUTOR_7702_IMPL = BATCH_EXECUTOR_7702_IMPL; exports.BATCH_EXECUTOR_ABI = BATCH_EXECUTOR_ABI; exports.BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = BATCH_EXECUTOR_ADDRESS_BASE_MAINNET; exports.BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA; exports.BROKER_HASHES = BROKER_HASHES; exports.COMMON_POOLS = _chunk3QDZFDELcjs.COMMON_POOLS; exports.COMMON_TOKENS = _chunk3QDZFDELcjs.COMMON_TOKENS; exports.CONTRACT_ADDRESSES = CONTRACT_ADDRESSES; exports.ConfigurationError = ConfigurationError; exports.DUMMY_SIGNATURE_V07 = DUMMY_SIGNATURE_V07; exports.ENTRY_POINT_V07 = _chunk3QDZFDELcjs.ENTRY_POINT_V07; exports.ENTRY_POINT_V08 = _chunk3QDZFDELcjs.ENTRY_POINT_V08; exports.ORDERLY_RELAY_ABI = ORDERLY_RELAY_ABI; exports.ORDERLY_VAULT_ABI = ORDERLY_VAULT_ABI; exports.ORDERLY_VAULT_ADDRESSES = ORDERLY_VAULT_ADDRESSES; exports.ORDERLY_VAULT_BASE_MAINNET = ORDERLY_VAULT_BASE_MAINNET; exports.OracleStaleError = OracleStaleError; exports.PAFI_SUBGRAPH_URL = PAFI_SUBGRAPH_URL; exports.PERMIT2_ADDRESS = _chunk3QDZFDELcjs.PERMIT2_ADDRESS; exports.POINT_TOKEN_FACTORY_ADDRESSES = POINT_TOKEN_FACTORY_ADDRESSES; exports.POINT_TOKEN_IMPL_ADDRESSES = POINT_TOKEN_IMPL_ADDRESSES; exports.POINT_TOKEN_POOLS = _chunk3QDZFDELcjs.POINT_TOKEN_POOLS; exports.POINT_TOKEN_V2_ABI = _chunkLRHY7GORcjs.pointTokenAbi; exports.PafiSDK = PafiSDK; exports.PafiSDKError = PafiSDKError; exports.SIMPLE_7702_IMPL_BASE_MAINNET = SIMPLE_7702_IMPL_BASE_MAINNET; exports.SPONSOR_AUTH_DOMAIN_NAME = _chunkRZDG6SRRcjs.SPONSOR_AUTH_DOMAIN_NAME; exports.SPONSOR_AUTH_TYPES = _chunkRZDG6SRRcjs.SPONSOR_AUTH_TYPES; exports.SUPPORTED_CHAINS = _chunk3QDZFDELcjs.SUPPORTED_CHAINS; exports.SigningError = SigningError; exports.SimulationError = SimulationError; exports.TOKEN_HASHES = TOKEN_HASHES; exports.UNIVERSAL_ROUTER_ADDRESSES = _chunk3QDZFDELcjs.UNIVERSAL_ROUTER_ADDRESSES; exports.V4_QUOTER_ADDRESSES = _chunk3QDZFDELcjs.V4_QUOTER_ADDRESSES; exports.ZERO_VALUE = ZERO_VALUE; exports._resetPaymasterConfigForTests = _resetPaymasterConfigForTests; exports.assembleUserOperation = assembleUserOperation; exports.buildAndSignSponsorAuth = _chunkRZDG6SRRcjs.buildAndSignSponsorAuth; exports.buildBurnRequestTypedData = _chunk3QDZFDELcjs.buildBurnRequestTypedData; exports.buildDelegationUserOp = buildDelegationUserOp; exports.buildDomain = _chunk3QDZFDELcjs.buildDomain; exports.buildEip7702Authorization = buildEip7702Authorization; exports.buildMintRequestTypedData = _chunk3QDZFDELcjs.buildMintRequestTypedData; exports.buildPartialUserOperation = buildPartialUserOperation; exports.buildPerpDepositViaRelay = buildPerpDepositViaRelay; exports.buildPerpDepositWithGasDeduction = buildPerpDepositWithGasDeduction; exports.buildReceiverConsentTypedData = _chunk3QDZFDELcjs.buildReceiverConsentTypedData; exports.buildSponsorAuthDomain = _chunkRZDG6SRRcjs.buildSponsorAuthDomain; exports.buildSponsorAuthTypedData = _chunkRZDG6SRRcjs.buildSponsorAuthTypedData; exports.buildUserOpTypedData = buildUserOpTypedData; exports.burnRequestTypes = _chunk3QDZFDELcjs.burnRequestTypes; exports.checkDelegation = checkDelegation; exports.checkEthAndBranch = checkEthAndBranch; exports.computeAccountId = computeAccountId; exports.computeAuthorizationHash = computeAuthorizationHash; exports.computeCallDataHash = _chunkRZDG6SRRcjs.computeCallDataHash; exports.computeUserOpHash = computeUserOpHash; exports.createLoginMessage = _chunkRZDG6SRRcjs.createLoginMessage; exports.createPafiProxyTransport = createPafiProxyTransport; exports.decodeBatchExecuteCalls = decodeBatchExecuteCalls; exports.detectDelegateImpl = detectDelegateImpl; exports.encodeBatchExecute = encodeBatchExecute; exports.erc20Abi = _chunkQ6WCDZXIcjs.erc20Abi; exports.erc20ApproveOp = erc20ApproveOp; exports.erc20BurnOp = erc20BurnOp; exports.erc20TransferOp = erc20TransferOp; exports.fetchPafiPools = fetchPafiPools; exports.getAaNonce = getAaNonce; exports.getBurnRequestNonce = _chunkCLPRSQT2cjs.getBurnRequestNonce; exports.getContractAddresses = getContractAddresses; exports.getDummySignatureFor7702 = getDummySignatureFor7702; exports.getIssuer = _chunkCLPRSQT2cjs.getIssuer2; exports.getMintRequestNonce = _chunkCLPRSQT2cjs.getMintRequestNonce; exports.getPafiWebModalAdapter = getPafiWebModalAdapter; exports.getPaymasterConfig = getPaymasterConfig; exports.getPointTokenBalance = _chunkCLPRSQT2cjs.getPointTokenBalance; exports.getPointTokenIssuer = _chunkCLPRSQT2cjs.getPointTokenIssuer; exports.getPointTokenIssuerAddress = _chunkCLPRSQT2cjs.getIssuer; exports.getReceiverConsentNonce = _chunkCLPRSQT2cjs.getReceiverConsentNonce; exports.getTokenName = _chunkCLPRSQT2cjs.getTokenName; exports.isActiveIssuer = _chunkCLPRSQT2cjs.isActiveIssuer; exports.isDelegatedTo = isDelegatedTo; exports.isDelegatedToTarget = isDelegatedToTarget; exports.isMinter = _chunkCLPRSQT2cjs.isMinter; exports.isPaymasterConfigured = isPaymasterConfigured; exports.isPaymasterError = isPaymasterError; exports.issuerRegistryAbi = _chunkLRHY7GORcjs.issuerRegistryAbi; exports.issuerRegistryGetIssuerFlatAbi = _chunkCLPRSQT2cjs.issuerRegistryGetIssuerFlatAbi; exports.mintRequestTypes = _chunk3QDZFDELcjs.mintRequestTypes; exports.mintingOracleAbi = _chunkLRHY7GORcjs.mintingOracleAbi; exports.openPafiWebModal = openPafiWebModal; exports.openWebPopup = openWebPopup; exports.parseEip7702DelegatedAddress = parseEip7702DelegatedAddress; exports.parseLoginMessage = _chunkRZDG6SRRcjs.parseLoginMessage; exports.permit2Abi = _chunkQ6WCDZXIcjs.permit2Abi; exports.pointTokenAbi = _chunkLRHY7GORcjs.pointTokenAbi; exports.pointTokenFactoryAbi = _chunkQ6WCDZXIcjs.pointTokenFactoryAbi; exports.quoteOperatorFeePt = quoteOperatorFeePt; exports.quoteOperatorFeeUsdt = quoteOperatorFeeUsdt; exports.rawCallOp = rawCallOp; exports.receiverConsentTypes = _chunk3QDZFDELcjs.receiverConsentTypes; exports.sendWithPaymasterFallback = sendWithPaymasterFallback; exports.serializeUserOpToJsonRpc = serializeUserOpToJsonRpc; exports.setPafiWebModalAdapter = setPafiWebModalAdapter; exports.setPaymasterConfig = setPaymasterConfig; exports.signBurnRequest = _chunk3QDZFDELcjs.signBurnRequest; exports.signMintRequest = _chunk3QDZFDELcjs.signMintRequest; exports.signReceiverConsent = _chunk3QDZFDELcjs.signReceiverConsent; exports.signSponsorAuth = _chunkRZDG6SRRcjs.signSponsorAuth; exports.splitAuthorizationSig = splitAuthorizationSig; exports.universalRouterAbi = _chunkQ6WCDZXIcjs.universalRouterAbi; exports.v4QuoterAbi = _chunkQ6WCDZXIcjs.v4QuoterAbi; exports.verifyBurnRequest = _chunk3QDZFDELcjs.verifyBurnRequest; exports.verifyLoginMessage = _chunkRZDG6SRRcjs.verifyLoginMessage; exports.verifyMintCap = _chunkCLPRSQT2cjs.verifyMintCap; exports.verifyMintRequest = _chunk3QDZFDELcjs.verifyMintRequest; exports.verifyReceiverConsent = _chunk3QDZFDELcjs.verifyReceiverConsent; exports.verifySponsorAuth = _chunkRZDG6SRRcjs.verifySponsorAuth; exports.webPopupAdapter = webPopupAdapter;
|
|
1413
1451
|
//# sourceMappingURL=index.cjs.map
|