@pafi-dev/core 0.20.1 → 0.22.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 +43 -2
- 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 +42 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
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
|
@@ -1048,6 +1048,46 @@ function normalizeHex32(value) {
|
|
|
1048
1048
|
return "0x" + stripped.padStart(64, "0");
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
|
+
// src/delegation/attachDelegationIfNeeded.ts
|
|
1052
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
1053
|
+
function cacheKey(chainId, account) {
|
|
1054
|
+
return `${chainId}:${account.toLowerCase()}`;
|
|
1055
|
+
}
|
|
1056
|
+
async function attachDelegationIfNeeded(params) {
|
|
1057
|
+
const key = cacheKey(params.chainId, params.account);
|
|
1058
|
+
const existing = inFlight.get(key);
|
|
1059
|
+
if (existing) return existing;
|
|
1060
|
+
const promise = doAttach(params).finally(() => {
|
|
1061
|
+
inFlight.delete(key);
|
|
1062
|
+
});
|
|
1063
|
+
inFlight.set(key, promise);
|
|
1064
|
+
return promise;
|
|
1065
|
+
}
|
|
1066
|
+
async function doAttach(params) {
|
|
1067
|
+
const { rpc, account, expectedDelegate, chainId, signAuthorization } = params;
|
|
1068
|
+
if (await isDelegatedTo(rpc, account, expectedDelegate)) {
|
|
1069
|
+
return void 0;
|
|
1070
|
+
}
|
|
1071
|
+
const nonce = await rpc.getTransactionCount({ address: account });
|
|
1072
|
+
const rawAuth = await signAuthorization({
|
|
1073
|
+
contractAddress: expectedDelegate,
|
|
1074
|
+
chainId,
|
|
1075
|
+
nonce
|
|
1076
|
+
});
|
|
1077
|
+
const authorization = {
|
|
1078
|
+
chainId: toHexQuantity(rawAuth.chainId),
|
|
1079
|
+
address: _nullishCoalesce(_nullishCoalesce(rawAuth.contractAddress, () => ( rawAuth.address)), () => ( expectedDelegate)),
|
|
1080
|
+
nonce: toHexQuantity(BigInt(rawAuth.nonce)),
|
|
1081
|
+
r: rawAuth.r,
|
|
1082
|
+
s: rawAuth.s,
|
|
1083
|
+
yParity: typeof rawAuth.yParity === "string" ? rawAuth.yParity.startsWith("0x") ? rawAuth.yParity : `0x${rawAuth.yParity}` : `0x${rawAuth.yParity}`
|
|
1084
|
+
};
|
|
1085
|
+
return { authorization };
|
|
1086
|
+
}
|
|
1087
|
+
function toHexQuantity(n) {
|
|
1088
|
+
return `0x${BigInt(n).toString(16)}`;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1051
1091
|
// src/transport/proxyTransport.ts
|
|
1052
1092
|
|
|
1053
1093
|
function createPafiProxyTransport(params) {
|
|
@@ -1107,7 +1147,7 @@ async function sendWithPaymasterFallback(params) {
|
|
|
1107
1147
|
|
|
1108
1148
|
// src/subgraph/pools.ts
|
|
1109
1149
|
|
|
1110
|
-
var PAFI_SUBGRAPH_URL = "https://graph-base-mainnet.pacificfinance.org/subgraphs/name/pafi-subgraph-
|
|
1150
|
+
var PAFI_SUBGRAPH_URL = "https://graph-base-mainnet.pacificfinance.org/subgraphs/name/pafi-subgraph-v1";
|
|
1111
1151
|
var POOL_QUERY = `
|
|
1112
1152
|
query GetPoolForPointToken($id: ID!) {
|
|
1113
1153
|
pafiToken(id: $id) {
|
|
@@ -1891,5 +1931,6 @@ var PafiSDK = class {
|
|
|
1891
1931
|
|
|
1892
1932
|
|
|
1893
1933
|
|
|
1894
|
-
|
|
1934
|
+
|
|
1935
|
+
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
1936
|
//# sourceMappingURL=index.cjs.map
|