@pafi-dev/core 0.6.0 → 0.6.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/README.md +150 -257
- package/dist/index.cjs +23 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1247,6 +1247,42 @@ interface QuoteOperatorFeePtConfig {
|
|
|
1247
1247
|
fallbackPtPriceUsdt?: number;
|
|
1248
1248
|
fetchImpl?: typeof fetch;
|
|
1249
1249
|
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Subset of `QuoteOperatorFeePtConfig` that doesn't need the V4 pool
|
|
1252
|
+
* step — used by `quoteOperatorFeeUsdt` (FE cashout-preview / `/gas-fee`
|
|
1253
|
+
* replacement). No `pointTokenAddress`, no `subgraphUrl`, no PT-side
|
|
1254
|
+
* fallback.
|
|
1255
|
+
*/
|
|
1256
|
+
interface QuoteOperatorFeeUsdtConfig {
|
|
1257
|
+
provider: PublicClient;
|
|
1258
|
+
chainId: number;
|
|
1259
|
+
gasUnits?: bigint;
|
|
1260
|
+
premiumBps?: number;
|
|
1261
|
+
chainlinkFeedAddress?: Address;
|
|
1262
|
+
usdtDecimals?: number;
|
|
1263
|
+
fallbackEthPriceUsd?: number;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Operator fee quoted in USDT raw units (default 6 decimals). Returns
|
|
1267
|
+
* the same value the legacy `GET /gas-fee` endpoint produced —
|
|
1268
|
+
* `withPremium_wei × ethPrice / 10^(18 + 8 - usdtDecimals)`. Does NOT
|
|
1269
|
+
* convert to PT, so no V4 subgraph call needed; pure on-chain
|
|
1270
|
+
* Chainlink read + RPC `getGasPrice`.
|
|
1271
|
+
*
|
|
1272
|
+
* Use this on the FE for the cashout preview screen (or anywhere a
|
|
1273
|
+
* USDT-denominated estimate is wanted) instead of round-tripping the
|
|
1274
|
+
* issuer backend's `/gas-fee` endpoint.
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```ts
|
|
1278
|
+
* import { quoteOperatorFeeUsdt } from "@pafi-dev/core";
|
|
1279
|
+
* const gasFeeUsdt = await quoteOperatorFeeUsdt({
|
|
1280
|
+
* provider, chainId: 8453,
|
|
1281
|
+
* });
|
|
1282
|
+
* // gasFeeUsdt is a bigint in 6-decimal USDT raw units
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
declare function quoteOperatorFeeUsdt(config: QuoteOperatorFeeUsdtConfig): Promise<bigint>;
|
|
1250
1286
|
declare function quoteOperatorFeePt(config: QuoteOperatorFeePtConfig): Promise<bigint>;
|
|
1251
1287
|
|
|
1252
1288
|
declare const BATCH_EXECUTOR_ADDRESS_BASE_MAINNET: `0x${string}`;
|
|
@@ -1667,4 +1703,4 @@ declare class PafiSDK {
|
|
|
1667
1703
|
signLoginMessage(message: string): Promise<Hex>;
|
|
1668
1704
|
}
|
|
1669
1705
|
|
|
1670
|
-
export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
|
|
1706
|
+
export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1247,6 +1247,42 @@ interface QuoteOperatorFeePtConfig {
|
|
|
1247
1247
|
fallbackPtPriceUsdt?: number;
|
|
1248
1248
|
fetchImpl?: typeof fetch;
|
|
1249
1249
|
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Subset of `QuoteOperatorFeePtConfig` that doesn't need the V4 pool
|
|
1252
|
+
* step — used by `quoteOperatorFeeUsdt` (FE cashout-preview / `/gas-fee`
|
|
1253
|
+
* replacement). No `pointTokenAddress`, no `subgraphUrl`, no PT-side
|
|
1254
|
+
* fallback.
|
|
1255
|
+
*/
|
|
1256
|
+
interface QuoteOperatorFeeUsdtConfig {
|
|
1257
|
+
provider: PublicClient;
|
|
1258
|
+
chainId: number;
|
|
1259
|
+
gasUnits?: bigint;
|
|
1260
|
+
premiumBps?: number;
|
|
1261
|
+
chainlinkFeedAddress?: Address;
|
|
1262
|
+
usdtDecimals?: number;
|
|
1263
|
+
fallbackEthPriceUsd?: number;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Operator fee quoted in USDT raw units (default 6 decimals). Returns
|
|
1267
|
+
* the same value the legacy `GET /gas-fee` endpoint produced —
|
|
1268
|
+
* `withPremium_wei × ethPrice / 10^(18 + 8 - usdtDecimals)`. Does NOT
|
|
1269
|
+
* convert to PT, so no V4 subgraph call needed; pure on-chain
|
|
1270
|
+
* Chainlink read + RPC `getGasPrice`.
|
|
1271
|
+
*
|
|
1272
|
+
* Use this on the FE for the cashout preview screen (or anywhere a
|
|
1273
|
+
* USDT-denominated estimate is wanted) instead of round-tripping the
|
|
1274
|
+
* issuer backend's `/gas-fee` endpoint.
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```ts
|
|
1278
|
+
* import { quoteOperatorFeeUsdt } from "@pafi-dev/core";
|
|
1279
|
+
* const gasFeeUsdt = await quoteOperatorFeeUsdt({
|
|
1280
|
+
* provider, chainId: 8453,
|
|
1281
|
+
* });
|
|
1282
|
+
* // gasFeeUsdt is a bigint in 6-decimal USDT raw units
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
declare function quoteOperatorFeeUsdt(config: QuoteOperatorFeeUsdtConfig): Promise<bigint>;
|
|
1250
1286
|
declare function quoteOperatorFeePt(config: QuoteOperatorFeePtConfig): Promise<bigint>;
|
|
1251
1287
|
|
|
1252
1288
|
declare const BATCH_EXECUTOR_ADDRESS_BASE_MAINNET: `0x${string}`;
|
|
@@ -1667,4 +1703,4 @@ declare class PafiSDK {
|
|
|
1667
1703
|
signLoginMessage(message: string): Promise<Hex>;
|
|
1668
1704
|
}
|
|
1669
1705
|
|
|
1670
|
-
export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
|
|
1706
|
+
export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, type Eip7702AuthorizationJsonRpc, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, type Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, type PartialUserOperation, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, type QuoteOperatorFeePtConfig, type QuoteOperatorFeeUsdtConfig, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOpTypedData, type UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildEip7702Authorization, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, quoteOperatorFeePt, quoteOperatorFeeUsdt, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, splitAuthorizationSig, webPopupAdapter };
|
package/dist/index.js
CHANGED
|
@@ -899,6 +899,27 @@ var POOL_PRICE_QUERY = `
|
|
|
899
899
|
var DEFAULT_GAS_UNITS = 500000n;
|
|
900
900
|
var DEFAULT_PREMIUM_BPS = 12e3;
|
|
901
901
|
var DEFAULT_USDT_DECIMALS = 6;
|
|
902
|
+
async function quoteOperatorFeeUsdt(config) {
|
|
903
|
+
const {
|
|
904
|
+
provider,
|
|
905
|
+
chainId,
|
|
906
|
+
gasUnits = DEFAULT_GAS_UNITS,
|
|
907
|
+
premiumBps = DEFAULT_PREMIUM_BPS,
|
|
908
|
+
usdtDecimals = DEFAULT_USDT_DECIMALS,
|
|
909
|
+
fallbackEthPriceUsd = 3e3
|
|
910
|
+
} = config;
|
|
911
|
+
const chainlinkFeedAddress = config.chainlinkFeedAddress ?? getContractAddresses(chainId).chainlinkEthUsd;
|
|
912
|
+
const gasPrice = await provider.getGasPrice();
|
|
913
|
+
const nativeCost = gasPrice * gasUnits;
|
|
914
|
+
const withPremium = nativeCost * BigInt(premiumBps) / 10000n;
|
|
915
|
+
const ethPrice8dec = await getEthPrice8dec(
|
|
916
|
+
provider,
|
|
917
|
+
chainlinkFeedAddress,
|
|
918
|
+
fallbackEthPriceUsd
|
|
919
|
+
);
|
|
920
|
+
const denomExp = 18 + 8 - usdtDecimals;
|
|
921
|
+
return withPremium * ethPrice8dec / 10n ** BigInt(denomExp);
|
|
922
|
+
}
|
|
902
923
|
async function quoteOperatorFeePt(config) {
|
|
903
924
|
const {
|
|
904
925
|
provider,
|
|
@@ -1374,6 +1395,7 @@ export {
|
|
|
1374
1395
|
pointTokenAbi,
|
|
1375
1396
|
pointTokenFactoryAbi,
|
|
1376
1397
|
quoteOperatorFeePt,
|
|
1398
|
+
quoteOperatorFeeUsdt,
|
|
1377
1399
|
rawCallOp,
|
|
1378
1400
|
receiverConsentTypes,
|
|
1379
1401
|
sendWithPaymasterFallback,
|