@pafi-dev/core 0.20.1 → 0.23.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 +54 -0
- package/dist/index.cjs +60 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -2
- package/dist/index.d.ts +97 -2
- package/dist/index.js +59 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -270,6 +270,60 @@ EIP-7702 (no raw `secp256k1_sign` exposed). User pays ~$0.01–0.10 ETH gas.
|
|
|
270
270
|
|
|
271
271
|
---
|
|
272
272
|
|
|
273
|
+
## EIP-7702 — `attachDelegationIfNeeded` (atomic activation, v0.21+)
|
|
274
|
+
|
|
275
|
+
Merge the 7702 SetCode authorization into the user's FIRST action UserOp
|
|
276
|
+
instead of running a separate delegate transaction. Pimlico bundles both
|
|
277
|
+
into ONE bundler tx — no "setup" step for the user.
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { attachDelegationIfNeeded } from "@pafi-dev/core";
|
|
281
|
+
import { useSign7702Authorization } from "@privy-io/react-auth";
|
|
282
|
+
|
|
283
|
+
const { signAuthorization } = useSign7702Authorization();
|
|
284
|
+
|
|
285
|
+
// Before EVERY sponsored UserOp (mint / swap / transfer / perp-deposit):
|
|
286
|
+
const authPart = await attachDelegationIfNeeded({
|
|
287
|
+
rpc: publicClient, // viem PublicClient
|
|
288
|
+
account: userAddress, // user's EOA
|
|
289
|
+
expectedDelegate: "0xe6Cae83BdE06E4c305530e199D7217f42808555B", // BatchExecutor
|
|
290
|
+
chainId: 8453, // Base mainnet
|
|
291
|
+
signAuthorization, // Privy hook result
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Spread into permissionless smartClient.sendTransaction — the field is
|
|
295
|
+
// stripped + forwarded to Pimlico as `eip7702Auth` automatically.
|
|
296
|
+
await smartClient.sendTransaction({
|
|
297
|
+
to: pointToken,
|
|
298
|
+
data: encodeMintCalldata(amount),
|
|
299
|
+
...(authPart ?? {}), // { authorization } when needed, nothing otherwise
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Returns `undefined` when the EOA already delegates to `expectedDelegate`
|
|
304
|
+
— caller passes no `authorization` field on subsequent UserOps.
|
|
305
|
+
|
|
306
|
+
**Compared to `delegateDirect`:**
|
|
307
|
+
|
|
308
|
+
| Trait | `delegateDirect` | `attachDelegationIfNeeded` |
|
|
309
|
+
|---|---|---|
|
|
310
|
+
| Number of on-chain txs | 2 (delegate + action) | 1 (atomic) |
|
|
311
|
+
| User signs `signAuthorization` | once per session | once per session |
|
|
312
|
+
| Submits UserOp itself | no — only delegates | no — caller does it |
|
|
313
|
+
| Gas mode | user-paid ETH | works with paymaster + EOA-paid fallback |
|
|
314
|
+
| Best for | one-shot pre-onboarding | every action call |
|
|
315
|
+
|
|
316
|
+
**Concurrency-safe**: parallel calls for the same `(chainId, account)`
|
|
317
|
+
join the same in-flight promise — exactly ONE Privy popup is shown even
|
|
318
|
+
when React re-fires the callback or the user double-clicks. The cache
|
|
319
|
+
auto-evicts when settled so retries always re-check on-chain state.
|
|
320
|
+
|
|
321
|
+
**Wrong-impl handling**: if the EOA already delegates to a *different*
|
|
322
|
+
contract (e.g. an older Coinbase 7702 impl), the helper signs a new
|
|
323
|
+
authorization to switch the delegate — atomically, with the next action.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
273
327
|
## Sponsor-auth signing
|
|
274
328
|
|
|
275
329
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -900,11 +900,23 @@ var CONTRACT_ADDRESSES = {
|
|
|
900
900
|
// top-level export.
|
|
901
901
|
permit2: "0xEB450d21ae68D3303Cf5775A54Cc84EE7c3fC8eC",
|
|
902
902
|
// ── Stablecoins ───────────────────────────────────────────────
|
|
903
|
-
//
|
|
904
|
-
|
|
905
|
-
//
|
|
906
|
-
//
|
|
907
|
-
|
|
903
|
+
// Canonical Base stables — the PT pools team deploys against these
|
|
904
|
+
// (verified on-chain: pool `0xB135E06E…` LTR/USDC and `0x6348D133…`
|
|
905
|
+
// JLB/USDC both list `token = 0x833589fC…` = canonical USDC). The
|
|
906
|
+
// earlier PAFI custom-deploy USDT/USDC (MockUSDT `0x3F7e71…` +
|
|
907
|
+
// PAFI V2 USDC `0xf0Fa9eB0…`) were unused by production pools and
|
|
908
|
+
// caused sponsor-relayer's `isStableFeeToken` to fall through to
|
|
909
|
+
// the PT quoter, producing 1e12× INSUFFICIENT_FEE rejects on every
|
|
910
|
+
// swap. See addresses.ts history before 2026-06-16 if archeology
|
|
911
|
+
// is needed.
|
|
912
|
+
//
|
|
913
|
+
// Canonical Tether USDT on Base (Tether's official native deploy,
|
|
914
|
+
// symbol="USDT", name="Tether USD", 6 decimals).
|
|
915
|
+
usdt: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2",
|
|
916
|
+
// Canonical Circle USDC on Base (Coinbase official deploy,
|
|
917
|
+
// symbol="USDC", 6 decimals). Paired with the USDC/USD Chainlink
|
|
918
|
+
// feed below.
|
|
919
|
+
usdc: "0x833589fCD6EDb6E08f4c7C32D4f71b54bdA02913",
|
|
908
920
|
chainlinkUsdcUsd: "0xEE86BfD4E2B3A1e71a1b45f750791D67e735e4a7",
|
|
909
921
|
// ── V2 core registries (replaces v1.6) ────────────────────────
|
|
910
922
|
issuerRegistry: "0x3e82647b0f716f80e65d311354E2C4F0DcFd6997",
|
|
@@ -1048,6 +1060,46 @@ function normalizeHex32(value) {
|
|
|
1048
1060
|
return "0x" + stripped.padStart(64, "0");
|
|
1049
1061
|
}
|
|
1050
1062
|
|
|
1063
|
+
// src/delegation/attachDelegationIfNeeded.ts
|
|
1064
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
1065
|
+
function cacheKey(chainId, account) {
|
|
1066
|
+
return `${chainId}:${account.toLowerCase()}`;
|
|
1067
|
+
}
|
|
1068
|
+
async function attachDelegationIfNeeded(params) {
|
|
1069
|
+
const key = cacheKey(params.chainId, params.account);
|
|
1070
|
+
const existing = inFlight.get(key);
|
|
1071
|
+
if (existing) return existing;
|
|
1072
|
+
const promise = doAttach(params).finally(() => {
|
|
1073
|
+
inFlight.delete(key);
|
|
1074
|
+
});
|
|
1075
|
+
inFlight.set(key, promise);
|
|
1076
|
+
return promise;
|
|
1077
|
+
}
|
|
1078
|
+
async function doAttach(params) {
|
|
1079
|
+
const { rpc, account, expectedDelegate, chainId, signAuthorization } = params;
|
|
1080
|
+
if (await isDelegatedTo(rpc, account, expectedDelegate)) {
|
|
1081
|
+
return void 0;
|
|
1082
|
+
}
|
|
1083
|
+
const nonce = await rpc.getTransactionCount({ address: account });
|
|
1084
|
+
const rawAuth = await signAuthorization({
|
|
1085
|
+
contractAddress: expectedDelegate,
|
|
1086
|
+
chainId,
|
|
1087
|
+
nonce
|
|
1088
|
+
});
|
|
1089
|
+
const authorization = {
|
|
1090
|
+
chainId: toHexQuantity(rawAuth.chainId),
|
|
1091
|
+
address: _nullishCoalesce(_nullishCoalesce(rawAuth.contractAddress, () => ( rawAuth.address)), () => ( expectedDelegate)),
|
|
1092
|
+
nonce: toHexQuantity(BigInt(rawAuth.nonce)),
|
|
1093
|
+
r: rawAuth.r,
|
|
1094
|
+
s: rawAuth.s,
|
|
1095
|
+
yParity: typeof rawAuth.yParity === "string" ? rawAuth.yParity.startsWith("0x") ? rawAuth.yParity : `0x${rawAuth.yParity}` : `0x${rawAuth.yParity}`
|
|
1096
|
+
};
|
|
1097
|
+
return { authorization };
|
|
1098
|
+
}
|
|
1099
|
+
function toHexQuantity(n) {
|
|
1100
|
+
return `0x${BigInt(n).toString(16)}`;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1051
1103
|
// src/transport/proxyTransport.ts
|
|
1052
1104
|
|
|
1053
1105
|
function createPafiProxyTransport(params) {
|
|
@@ -1107,7 +1159,7 @@ async function sendWithPaymasterFallback(params) {
|
|
|
1107
1159
|
|
|
1108
1160
|
// src/subgraph/pools.ts
|
|
1109
1161
|
|
|
1110
|
-
var PAFI_SUBGRAPH_URL = "https://graph-base-mainnet.pacificfinance.org/subgraphs/name/pafi-subgraph-
|
|
1162
|
+
var PAFI_SUBGRAPH_URL = "https://graph-base-mainnet.pacificfinance.org/subgraphs/name/pafi-subgraph-v1";
|
|
1111
1163
|
var POOL_QUERY = `
|
|
1112
1164
|
query GetPoolForPointToken($id: ID!) {
|
|
1113
1165
|
pafiToken(id: $id) {
|
|
@@ -1891,5 +1943,6 @@ var PafiSDK = class {
|
|
|
1891
1943
|
|
|
1892
1944
|
|
|
1893
1945
|
|
|
1894
|
-
|
|
1946
|
+
|
|
1947
|
+
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 = _chunk3ZT7KTN4cjs.COMMON_POOLS; exports.COMMON_TOKENS = _chunk3ZT7KTN4cjs.COMMON_TOKENS; exports.CONTRACT_ADDRESSES = CONTRACT_ADDRESSES; exports.ConfigurationError = ConfigurationError; exports.DUMMY_SIGNATURE_V07 = DUMMY_SIGNATURE_V07; exports.ENTRY_POINT_V07 = _chunk3ZT7KTN4cjs.ENTRY_POINT_V07; exports.ENTRY_POINT_V08 = _chunk3ZT7KTN4cjs.ENTRY_POINT_V08; exports.Eip712DomainMismatchError = _chunk3ZT7KTN4cjs.Eip712DomainMismatchError; 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_SERVICE_URLS = PAFI_SERVICE_URLS; exports.PAFI_SUBGRAPH_URL = PAFI_SUBGRAPH_URL; exports.PERMIT2_ADDRESS = _chunk3ZT7KTN4cjs.PERMIT2_ADDRESS; exports.POINT_TOKEN_ABI = POINT_TOKEN_ABI; exports.POINT_TOKEN_BEACON_ADDRESSES = POINT_TOKEN_BEACON_ADDRESSES; exports.POINT_TOKEN_BURN_SIG_ABI = POINT_TOKEN_BURN_SIG_ABI; exports.POINT_TOKEN_FACTORY_ADDRESSES = POINT_TOKEN_FACTORY_ADDRESSES; exports.POINT_TOKEN_IMPL_ADDRESSES = POINT_TOKEN_IMPL_ADDRESSES; exports.POINT_TOKEN_MINT_SIG_ABI = POINT_TOKEN_MINT_SIG_ABI; exports.POINT_TOKEN_POOLS = _chunk3ZT7KTN4cjs.POINT_TOKEN_POOLS; exports.PafiSDK = PafiSDK; exports.PafiSdkError = PafiSdkError; exports.QUOTER_V2_ADDRESSES = _chunk3ZT7KTN4cjs.QUOTER_V2_ADDRESSES; exports.SCENARIO_GAS_UNITS = SCENARIO_GAS_UNITS; exports.SDK_ERROR_HTTP_STATUS_CODE = SDK_ERROR_HTTP_STATUS_CODE; exports.SIMPLE_7702_IMPL_BASE_MAINNET = SIMPLE_7702_IMPL_BASE_MAINNET; exports.SPONSOR_AUTH_DOMAIN_ANCHOR_BASE_MAINNET = _chunk75JWR5SAcjs.SPONSOR_AUTH_DOMAIN_ANCHOR_BASE_MAINNET; exports.SPONSOR_AUTH_DOMAIN_NAME = _chunk75JWR5SAcjs.SPONSOR_AUTH_DOMAIN_NAME; exports.SPONSOR_AUTH_TYPES = _chunk75JWR5SAcjs.SPONSOR_AUTH_TYPES; exports.SUPPORTED_CHAINS = _chunk3ZT7KTN4cjs.SUPPORTED_CHAINS; exports.SigningError = SigningError; exports.SimulationError = SimulationError; exports.Source = _chunkDQKCPH6Bcjs.Source; exports.TOKEN_HASHES = TOKEN_HASHES; exports.UNIVERSAL_ROUTER_ADDRESSES = _chunk3ZT7KTN4cjs.UNIVERSAL_ROUTER_ADDRESSES; exports.V3_FACTORY_ADDRESSES = _chunk3ZT7KTN4cjs.V3_FACTORY_ADDRESSES; exports.V3_POOL_INIT_CODE_HASH = _chunk3ZT7KTN4cjs.V3_POOL_INIT_CODE_HASH; exports.V3_SWAP_ROUTER_ADDRESSES = _chunk3ZT7KTN4cjs.V3_SWAP_ROUTER_ADDRESSES; exports.VAULT_BEACON_ADDRESSES = VAULT_BEACON_ADDRESSES; exports.ValidationError = ValidationError; exports.ZERO_VALUE = ZERO_VALUE; exports.assembleUserOperation = assembleUserOperation; exports.assertDomainMatchesContract = _chunk3ZT7KTN4cjs.assertDomainMatchesContract; exports.attachDelegationIfNeeded = attachDelegationIfNeeded; exports.buildAndSignSponsorAuth = _chunk75JWR5SAcjs.buildAndSignSponsorAuth; exports.buildBurnRequestTypedData = _chunk3ZT7KTN4cjs.buildBurnRequestTypedData; exports.buildDelegationUserOp = buildDelegationUserOp; exports.buildDomain = _chunk3ZT7KTN4cjs.buildDomain; exports.buildEip7702Authorization = buildEip7702Authorization; exports.buildErc20TransferUserOp = buildErc20TransferUserOp; exports.buildMintRequestTypedData = _chunk3ZT7KTN4cjs.buildMintRequestTypedData; exports.buildPartialUserOperation = buildPartialUserOperation; exports.buildPerpDepositViaRelay = buildPerpDepositViaRelay; exports.buildPerpDepositWithGasDeduction = buildPerpDepositWithGasDeduction; exports.buildSponsorAuthDomain = _chunk75JWR5SAcjs.buildSponsorAuthDomain; exports.buildSponsorAuthTypedData = _chunk75JWR5SAcjs.buildSponsorAuthTypedData; exports.buildUserOpTypedData = buildUserOpTypedData; exports.burnRequestTypes = _chunk3ZT7KTN4cjs.burnRequestTypes; exports.checkDelegation = checkDelegation; exports.checkEthAndBranch = checkEthAndBranch; exports.computeAccountId = computeAccountId; exports.computeAuthorizationHash = computeAuthorizationHash; exports.computeCallDataHash = _chunk75JWR5SAcjs.computeCallDataHash; exports.computeEquityCap = _chunkDQKCPH6Bcjs.computeEquityCap; exports.computeUserOpHash = computeUserOpHash; exports.computeV3PoolAddress = computeV3PoolAddress; exports.createLoginMessage = _chunk75JWR5SAcjs.createLoginMessage; exports.createPafiProxyTransport = createPafiProxyTransport; exports.decodeBatchExecuteCalls = decodeBatchExecuteCalls; exports.defaultErrorTypeForStatus = defaultErrorTypeForStatus; exports.delegateDirect = delegateDirect; exports.detectDelegateImpl = detectDelegateImpl; exports.encodeBatchExecute = encodeBatchExecute; exports.encodeV3Path = encodeV3Path; exports.encodeV3PathReversed = encodeV3PathReversed; exports.erc20Abi = _chunk2DVM77Y2cjs.erc20Abi; exports.erc20ApproveOp = erc20ApproveOp; exports.erc20BurnOp = erc20BurnOp; exports.erc20TransferOp = erc20TransferOp; exports.fetchPafiPools = fetchPafiPools; exports.generateSponsorAuthNonce = _chunk75JWR5SAcjs.generateSponsorAuthNonce; exports.getAaNonce = getAaNonce; exports.getBurnRequestNonce = _chunkDQKCPH6Bcjs.getBurnRequestNonce; exports.getContractAddresses = getContractAddresses; exports.getDummySignatureFor7702 = getDummySignatureFor7702; exports.getIssuer = _chunkDQKCPH6Bcjs.getIssuer2; exports.getMintFeeBps = _chunkDQKCPH6Bcjs.getMintFeeBps; exports.getMintFeeRecipients = _chunkDQKCPH6Bcjs.getMintFeeRecipients; exports.getMintRequestNonce = _chunkDQKCPH6Bcjs.getMintRequestNonce; exports.getOracleRegistries = _chunkDQKCPH6Bcjs.getOracleRegistries; exports.getPafiServiceUrls = getPafiServiceUrls; exports.getPafiWebModalAdapter = getPafiWebModalAdapter; exports.getPointTokenBalance = _chunkDQKCPH6Bcjs.getPointTokenBalance; exports.getPointTokenIssuerAddress = _chunkDQKCPH6Bcjs.getIssuer; exports.getSponsorAuthDomainAnchor = _chunk75JWR5SAcjs.getSponsorAuthDomainAnchor; exports.getTokenName = _chunkDQKCPH6Bcjs.getTokenName; exports.isActiveIssuer = _chunkDQKCPH6Bcjs.isActiveIssuer; exports.isDelegatedTo = isDelegatedTo; exports.isDelegatedToTarget = isDelegatedToTarget; exports.isMinter = _chunkDQKCPH6Bcjs.isMinter; exports.isPaymasterError = isPaymasterError; exports.issuerRegistryAbi = _chunk2CU7ZH2Acjs.issuerRegistryAbi; exports.issuerRegistryGetIssuerFlatAbi = _chunkDQKCPH6Bcjs.issuerRegistryGetIssuerFlatAbi; exports.mintFeeWrapperAbi = _chunk2CU7ZH2Acjs.mintFeeWrapperAbi; exports.mintRequestTypes = _chunk3ZT7KTN4cjs.mintRequestTypes; exports.mintingOracleAbi = _chunk2CU7ZH2Acjs.mintingOracleAbi; exports.openPafiWebModal = openPafiWebModal; exports.openWebPopup = openWebPopup; exports.parseEip7702DelegatedAddress = parseEip7702DelegatedAddress; exports.parseLoginMessage = _chunk75JWR5SAcjs.parseLoginMessage; exports.permit2Abi = _chunk2DVM77Y2cjs.permit2Abi; exports.pointModuleCoreAbi = _chunk2DVM77Y2cjs.pointModuleCoreAbi; exports.pointTokenAbi = _chunk245YA3CQcjs.pointTokenAbi; exports.pointTokenFactoryAbi = _chunk2DVM77Y2cjs.pointTokenFactoryAbi; exports.quoteOperatorFeeForTransfer = quoteOperatorFeeForTransfer; exports.quoteOperatorFeePt = quoteOperatorFeePt; exports.quoteOperatorFeeUsdt = quoteOperatorFeeUsdt; exports.rawCallOp = rawCallOp; exports.sendWithPaymasterFallback = sendWithPaymasterFallback; exports.serializeUserOpToJsonRpc = serializeUserOpToJsonRpc; exports.setPafiWebModalAdapter = setPafiWebModalAdapter; exports.settlementVaultAbi = _chunk2DVM77Y2cjs.settlementVaultAbi; exports.signBurnRequest = _chunk3ZT7KTN4cjs.signBurnRequest; exports.signMintRequest = _chunk3ZT7KTN4cjs.signMintRequest; exports.signSponsorAuth = _chunk75JWR5SAcjs.signSponsorAuth; exports.splitAuthorizationSig = splitAuthorizationSig; exports.tokenRegistryAbi = _chunk2DVM77Y2cjs.tokenRegistryAbi; exports.universalRouterAbi = _chunk2DVM77Y2cjs.universalRouterAbi; exports.v3QuoterV2Abi = _chunk2DVM77Y2cjs.v3QuoterV2Abi; exports.vaultFactoryAbi = _chunk2DVM77Y2cjs.vaultFactoryAbi; exports.vaultRegistryAbi = _chunk2DVM77Y2cjs.vaultRegistryAbi; exports.verifyBurnRequest = _chunk3ZT7KTN4cjs.verifyBurnRequest; exports.verifyEquityMint = _chunkDQKCPH6Bcjs.verifyEquityMint; exports.verifyIssuerOperative = _chunkDQKCPH6Bcjs.verifyIssuerOperative; exports.verifyLoginMessage = _chunk75JWR5SAcjs.verifyLoginMessage; exports.verifyMint = _chunkDQKCPH6Bcjs.verifyMint; exports.verifyMintRequest = _chunk3ZT7KTN4cjs.verifyMintRequest; exports.verifySponsorAuth = _chunk75JWR5SAcjs.verifySponsorAuth; exports.webPopupAdapter = webPopupAdapter;
|
|
1895
1948
|
//# sourceMappingURL=index.cjs.map
|