@pafi-dev/issuer 0.5.35 → 0.5.37
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 +153 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +187 -91
- package/dist/index.d.ts +187 -91
- package/dist/index.js +150 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2375,6 +2375,150 @@ var PerpDepositHandler = class {
|
|
|
2375
2375
|
}
|
|
2376
2376
|
};
|
|
2377
2377
|
|
|
2378
|
+
// src/api/delegateHandler.ts
|
|
2379
|
+
import {
|
|
2380
|
+
ENTRY_POINT_V08 as ENTRY_POINT_V082,
|
|
2381
|
+
buildEip7702Authorization,
|
|
2382
|
+
encodeBatchExecute,
|
|
2383
|
+
getContractAddresses as getContractAddresses5,
|
|
2384
|
+
serializeUserOpToJsonRpc as serializeUserOpToJsonRpc2
|
|
2385
|
+
} from "@pafi-dev/core";
|
|
2386
|
+
var DEFAULT_DELEGATE_GAS = {
|
|
2387
|
+
callGasLimit: 100000n,
|
|
2388
|
+
verificationGasLimit: 150000n,
|
|
2389
|
+
preVerificationGas: 50000n
|
|
2390
|
+
};
|
|
2391
|
+
async function handleDelegateSubmit(params) {
|
|
2392
|
+
const { batchExecutor } = getContractAddresses5(params.chainId);
|
|
2393
|
+
const callData = encodeBatchExecute([]);
|
|
2394
|
+
const userOp = {
|
|
2395
|
+
sender: params.userAddress,
|
|
2396
|
+
nonce: params.aaNonce,
|
|
2397
|
+
callData,
|
|
2398
|
+
callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_DELEGATE_GAS.callGasLimit,
|
|
2399
|
+
verificationGasLimit: params.gasLimits?.verificationGasLimit ?? DEFAULT_DELEGATE_GAS.verificationGasLimit,
|
|
2400
|
+
preVerificationGas: params.gasLimits?.preVerificationGas ?? DEFAULT_DELEGATE_GAS.preVerificationGas,
|
|
2401
|
+
maxFeePerGas: params.fees.maxFeePerGas ?? 0n,
|
|
2402
|
+
maxPriorityFeePerGas: params.fees.maxPriorityFeePerGas ?? 0n
|
|
2403
|
+
};
|
|
2404
|
+
const paymasterFields = await requestPaymaster({
|
|
2405
|
+
client: params.pafiBackendClient,
|
|
2406
|
+
chainId: params.chainId,
|
|
2407
|
+
scenario: "delegate",
|
|
2408
|
+
userOp,
|
|
2409
|
+
pointTokenAddress: batchExecutor,
|
|
2410
|
+
onWarning: params.onWarning
|
|
2411
|
+
});
|
|
2412
|
+
const merged = {
|
|
2413
|
+
...userOp,
|
|
2414
|
+
...paymasterFields ?? {}
|
|
2415
|
+
};
|
|
2416
|
+
const userOpJson = serializeUserOpToJsonRpc2(
|
|
2417
|
+
{
|
|
2418
|
+
sender: merged.sender,
|
|
2419
|
+
nonce: merged.nonce,
|
|
2420
|
+
callData: merged.callData,
|
|
2421
|
+
callGasLimit: merged.callGasLimit,
|
|
2422
|
+
verificationGasLimit: merged.verificationGasLimit,
|
|
2423
|
+
preVerificationGas: merged.preVerificationGas,
|
|
2424
|
+
maxFeePerGas: merged.maxFeePerGas,
|
|
2425
|
+
maxPriorityFeePerGas: merged.maxPriorityFeePerGas,
|
|
2426
|
+
paymaster: paymasterFields?.paymaster,
|
|
2427
|
+
paymasterVerificationGasLimit: paymasterFields?.paymasterVerificationGasLimit,
|
|
2428
|
+
paymasterPostOpGasLimit: paymasterFields?.paymasterPostOpGasLimit,
|
|
2429
|
+
paymasterData: paymasterFields?.paymasterData
|
|
2430
|
+
},
|
|
2431
|
+
// Delegation UserOp is submitted unsigned — the EIP-7702 authorization
|
|
2432
|
+
// is the user's "consent"; no separate AA signature is needed.
|
|
2433
|
+
"0x"
|
|
2434
|
+
);
|
|
2435
|
+
const authorization = buildEip7702Authorization({
|
|
2436
|
+
chainId: params.chainId,
|
|
2437
|
+
address: batchExecutor,
|
|
2438
|
+
nonce: params.delegationNonce,
|
|
2439
|
+
authSig: params.authSig
|
|
2440
|
+
});
|
|
2441
|
+
const result = await relayUserOp({
|
|
2442
|
+
client: params.pafiBackendClient,
|
|
2443
|
+
userOp: userOpJson,
|
|
2444
|
+
entryPoint: ENTRY_POINT_V082,
|
|
2445
|
+
eip7702Auth: authorization
|
|
2446
|
+
});
|
|
2447
|
+
return {
|
|
2448
|
+
userOpHash: result.userOpHash,
|
|
2449
|
+
isSponsored: !!paymasterFields,
|
|
2450
|
+
authorization
|
|
2451
|
+
};
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
// src/api/quoteHelper.ts
|
|
2455
|
+
import {
|
|
2456
|
+
findBestQuote as findBestQuote2,
|
|
2457
|
+
getContractAddresses as getContractAddresses6
|
|
2458
|
+
} from "@pafi-dev/core";
|
|
2459
|
+
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
2460
|
+
async function quotePointTokenToUsdt(params) {
|
|
2461
|
+
const now = params.now ?? (() => Date.now());
|
|
2462
|
+
const suggestedDeadline = Math.floor(now() / 1e3) + (params.deadlineSeconds ?? DEFAULT_DEADLINE_SECONDS);
|
|
2463
|
+
if (params.pointAmount === 0n) {
|
|
2464
|
+
return {
|
|
2465
|
+
estimatedUsdtOut: 0n,
|
|
2466
|
+
netUsdtOut: 0n,
|
|
2467
|
+
exchangeRate: "0.00000000",
|
|
2468
|
+
gasEstimate: 0n,
|
|
2469
|
+
suggestedDeadline
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
if (params.pools.length === 0) {
|
|
2473
|
+
return {
|
|
2474
|
+
estimatedUsdtOut: 0n,
|
|
2475
|
+
netUsdtOut: 0n,
|
|
2476
|
+
exchangeRate: "0.00000000",
|
|
2477
|
+
gasEstimate: 0n,
|
|
2478
|
+
suggestedDeadline,
|
|
2479
|
+
quoteError: "QUOTE_UNAVAILABLE"
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
const { usdt: usdtAddress } = getContractAddresses6(params.chainId);
|
|
2483
|
+
let estimatedUsdtOut = 0n;
|
|
2484
|
+
let gasEstimate = 0n;
|
|
2485
|
+
try {
|
|
2486
|
+
const best = await findBestQuote2(
|
|
2487
|
+
params.provider,
|
|
2488
|
+
params.chainId,
|
|
2489
|
+
params.pointTokenAddress,
|
|
2490
|
+
usdtAddress,
|
|
2491
|
+
params.pointAmount,
|
|
2492
|
+
params.pools
|
|
2493
|
+
);
|
|
2494
|
+
estimatedUsdtOut = best.bestRoute.amountOut;
|
|
2495
|
+
gasEstimate = best.bestRoute.gasEstimate;
|
|
2496
|
+
} catch {
|
|
2497
|
+
return {
|
|
2498
|
+
estimatedUsdtOut: 0n,
|
|
2499
|
+
netUsdtOut: 0n,
|
|
2500
|
+
exchangeRate: "0.00000000",
|
|
2501
|
+
gasEstimate: 0n,
|
|
2502
|
+
suggestedDeadline,
|
|
2503
|
+
quoteError: "QUOTE_UNAVAILABLE"
|
|
2504
|
+
};
|
|
2505
|
+
}
|
|
2506
|
+
const netUsdtOut = estimatedUsdtOut > params.gasFeeUsdt ? estimatedUsdtOut - params.gasFeeUsdt : 0n;
|
|
2507
|
+
const quoteError = estimatedUsdtOut > 0n && netUsdtOut === 0n ? "AMOUNT_TOO_SMALL_FOR_GAS" : void 0;
|
|
2508
|
+
const rateNum = estimatedUsdtOut > 0n ? Number(
|
|
2509
|
+
estimatedUsdtOut * 1000000n * 10n ** 18n / params.pointAmount
|
|
2510
|
+
) / 1e6 : 0;
|
|
2511
|
+
const exchangeRate = rateNum.toFixed(8);
|
|
2512
|
+
return {
|
|
2513
|
+
estimatedUsdtOut,
|
|
2514
|
+
netUsdtOut,
|
|
2515
|
+
exchangeRate,
|
|
2516
|
+
gasEstimate,
|
|
2517
|
+
suggestedDeadline,
|
|
2518
|
+
...quoteError ? { quoteError } : {}
|
|
2519
|
+
};
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2378
2522
|
// src/pools/subgraphPoolsProvider.ts
|
|
2379
2523
|
import { isAddress } from "viem";
|
|
2380
2524
|
import { PAFI_SUBGRAPH_URL } from "@pafi-dev/core";
|
|
@@ -2994,7 +3138,7 @@ var PafiBackendClient = class {
|
|
|
2994
3138
|
|
|
2995
3139
|
// src/config.ts
|
|
2996
3140
|
import { getAddress as getAddress9 } from "viem";
|
|
2997
|
-
import { getContractAddresses as
|
|
3141
|
+
import { getContractAddresses as getContractAddresses7 } from "@pafi-dev/core";
|
|
2998
3142
|
function createIssuerService(config) {
|
|
2999
3143
|
if (!config.provider) {
|
|
3000
3144
|
throw new Error("createIssuerService: provider is required");
|
|
@@ -3064,7 +3208,7 @@ function createIssuerService(config) {
|
|
|
3064
3208
|
indexers.set(tokenAddress, new PointIndexer(indexerConfig));
|
|
3065
3209
|
}
|
|
3066
3210
|
const firstIndexer = indexers.get(tokenAddresses[0]);
|
|
3067
|
-
const chainAddresses =
|
|
3211
|
+
const chainAddresses = getContractAddresses7(config.chainId);
|
|
3068
3212
|
const resolvedContracts = {
|
|
3069
3213
|
batchExecutor: chainAddresses.batchExecutor,
|
|
3070
3214
|
usdt: chainAddresses.usdt,
|
|
@@ -3116,7 +3260,7 @@ import { getAddress as getAddress10 } from "viem";
|
|
|
3116
3260
|
import {
|
|
3117
3261
|
POINT_TOKEN_V2_ABI as POINT_TOKEN_V2_ABI3,
|
|
3118
3262
|
issuerRegistryGetIssuerFlatAbi,
|
|
3119
|
-
getContractAddresses as
|
|
3263
|
+
getContractAddresses as getContractAddresses8
|
|
3120
3264
|
} from "@pafi-dev/core";
|
|
3121
3265
|
var ISSUER_RECORD_TTL_MS = 3e4;
|
|
3122
3266
|
var IssuerStateValidator = class _IssuerStateValidator {
|
|
@@ -3134,7 +3278,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3134
3278
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
3135
3279
|
*/
|
|
3136
3280
|
static forChain(provider, chainId) {
|
|
3137
|
-
const { issuerRegistry } =
|
|
3281
|
+
const { issuerRegistry } = getContractAddresses8(chainId);
|
|
3138
3282
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
3139
3283
|
}
|
|
3140
3284
|
/**
|
|
@@ -3313,11 +3457,13 @@ export {
|
|
|
3313
3457
|
createSubgraphNativeUsdtQuoter,
|
|
3314
3458
|
createSubgraphPoolsProvider,
|
|
3315
3459
|
handleClaimStatus,
|
|
3460
|
+
handleDelegateSubmit,
|
|
3316
3461
|
handleMobilePrepare,
|
|
3317
3462
|
handleMobileSubmit,
|
|
3318
3463
|
handleRedeemStatus,
|
|
3319
3464
|
mergePaymasterFields,
|
|
3320
3465
|
prepareMobileUserOp,
|
|
3466
|
+
quotePointTokenToUsdt,
|
|
3321
3467
|
relayUserOp,
|
|
3322
3468
|
requestPaymaster,
|
|
3323
3469
|
serializeEntryToJsonRpc,
|