@pafi-dev/core 0.5.8 → 0.5.10
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 +127 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +132 -1
- package/dist/index.d.ts +132 -1
- package/dist/index.js +115 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -341,6 +341,122 @@ interface BuildPerpDepositWithGasDeductionParams {
|
|
|
341
341
|
*/
|
|
342
342
|
declare function buildPerpDepositWithGasDeduction(params: BuildPerpDepositWithGasDeductionParams): PartialUserOperation;
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Minimal ABI for the Orderly perp-deposit Relay (deployed at
|
|
346
|
+
* `CONTRACT_ADDRESSES[chainId].orderlyRelay`).
|
|
347
|
+
*
|
|
348
|
+
* The Relay holds an ETH reserve and pays Orderly's LayerZero msg.value
|
|
349
|
+
* out of it. Users only need USDC + the Relay-charged USDC fee — they
|
|
350
|
+
* never hold ETH for msg.value, which unblocks the ERC-4337 sponsored
|
|
351
|
+
* gas path for perp deposits (paymaster covers gas, NOT msg.value).
|
|
352
|
+
*/
|
|
353
|
+
declare const ORDERLY_RELAY_ABI: readonly [{
|
|
354
|
+
readonly type: "function";
|
|
355
|
+
readonly name: "deposit";
|
|
356
|
+
readonly stateMutability: "nonpayable";
|
|
357
|
+
readonly inputs: readonly [{
|
|
358
|
+
readonly name: "req";
|
|
359
|
+
readonly type: "tuple";
|
|
360
|
+
readonly components: readonly [{
|
|
361
|
+
readonly name: "token";
|
|
362
|
+
readonly type: "address";
|
|
363
|
+
}, {
|
|
364
|
+
readonly name: "receiver";
|
|
365
|
+
readonly type: "address";
|
|
366
|
+
}, {
|
|
367
|
+
readonly name: "brokerHash";
|
|
368
|
+
readonly type: "bytes32";
|
|
369
|
+
}, {
|
|
370
|
+
readonly name: "totalAmount";
|
|
371
|
+
readonly type: "uint128";
|
|
372
|
+
}, {
|
|
373
|
+
readonly name: "maxFee";
|
|
374
|
+
readonly type: "uint128";
|
|
375
|
+
}];
|
|
376
|
+
}];
|
|
377
|
+
readonly outputs: readonly [];
|
|
378
|
+
}, {
|
|
379
|
+
readonly type: "function";
|
|
380
|
+
readonly name: "quoteTokenFee";
|
|
381
|
+
readonly stateMutability: "view";
|
|
382
|
+
readonly inputs: readonly [{
|
|
383
|
+
readonly name: "req";
|
|
384
|
+
readonly type: "tuple";
|
|
385
|
+
readonly components: readonly [{
|
|
386
|
+
readonly name: "token";
|
|
387
|
+
readonly type: "address";
|
|
388
|
+
}, {
|
|
389
|
+
readonly name: "receiver";
|
|
390
|
+
readonly type: "address";
|
|
391
|
+
}, {
|
|
392
|
+
readonly name: "brokerHash";
|
|
393
|
+
readonly type: "bytes32";
|
|
394
|
+
}, {
|
|
395
|
+
readonly name: "totalAmount";
|
|
396
|
+
readonly type: "uint128";
|
|
397
|
+
}, {
|
|
398
|
+
readonly name: "maxFee";
|
|
399
|
+
readonly type: "uint128";
|
|
400
|
+
}];
|
|
401
|
+
}];
|
|
402
|
+
readonly outputs: readonly [{
|
|
403
|
+
readonly name: "";
|
|
404
|
+
readonly type: "uint128";
|
|
405
|
+
}];
|
|
406
|
+
}];
|
|
407
|
+
/**
|
|
408
|
+
* `Relay.DepositRequest` — the struct passed to `deposit()` and
|
|
409
|
+
* `quoteTokenFee()`. The Relay pulls `totalAmount` of `token` from
|
|
410
|
+
* `msg.sender`, computes a token-denominated fee (capped at `maxFee`)
|
|
411
|
+
* to cover the LayerZero msg.value out of its ETH reserve, and forwards
|
|
412
|
+
* `(totalAmount - tokenFee)` to Orderly Vault on behalf of `receiver`.
|
|
413
|
+
*/
|
|
414
|
+
interface OrderlyRelayDepositRequest {
|
|
415
|
+
/** ERC-20 to deposit (must be registered + enabled on the Relay). */
|
|
416
|
+
token: Address;
|
|
417
|
+
/** Orderly account owner — typically the user's EOA. */
|
|
418
|
+
receiver: Address;
|
|
419
|
+
/** Orderly broker hash (e.g. `BROKER_HASHES.woofi_pro`). */
|
|
420
|
+
brokerHash: Hex;
|
|
421
|
+
/** Total amount the user is sending to the Relay (raw token units, uint128). */
|
|
422
|
+
totalAmount: bigint;
|
|
423
|
+
/** Max acceptable token fee — slippage cap on the Relay's USD-pricing. */
|
|
424
|
+
maxFee: bigint;
|
|
425
|
+
}
|
|
426
|
+
interface BuildPerpDepositViaRelayParams {
|
|
427
|
+
/** User EOA (msg.sender via EIP-7702 delegation). */
|
|
428
|
+
userAddress: Address;
|
|
429
|
+
/** ERC-4337 account nonce. */
|
|
430
|
+
aaNonce: bigint;
|
|
431
|
+
/** Relay contract address — `getContractAddresses(chainId).orderlyRelay`. */
|
|
432
|
+
relayAddress: Address;
|
|
433
|
+
/** Deposit request (token, receiver, brokerHash, totalAmount, maxFee). */
|
|
434
|
+
request: OrderlyRelayDepositRequest;
|
|
435
|
+
/**
|
|
436
|
+
* Optional PT gas-fee transfer prepended to the batch. Set both
|
|
437
|
+
* `gasFeePtRecipient` and `gasFeePt` together for sponsored flows
|
|
438
|
+
* (PAFI gas reimbursement). Pass `0n` / `undefined` for the fallback
|
|
439
|
+
* path where the user pays ERC-4337 gas in ETH directly.
|
|
440
|
+
*/
|
|
441
|
+
pointTokenAddress?: Address;
|
|
442
|
+
gasFeePt?: bigint;
|
|
443
|
+
gasFeePtRecipient?: Address;
|
|
444
|
+
gasLimits?: {
|
|
445
|
+
callGasLimit?: bigint;
|
|
446
|
+
verificationGasLimit?: bigint;
|
|
447
|
+
preVerificationGas?: bigint;
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Build a UserOp for Orderly perp deposit via the PAFI Relay.
|
|
452
|
+
*
|
|
453
|
+
* Sponsored ops: `[PT.transfer(feeRecipient, gasFeePt), USDC.approve(relay, total), Relay.deposit(req)]`
|
|
454
|
+
* Fallback ops: `[ USDC.approve(relay, total), Relay.deposit(req)]`
|
|
455
|
+
*
|
|
456
|
+
* No `msg.value` — the Relay covers LayerZero out of its own ETH reserve.
|
|
457
|
+
*/
|
|
458
|
+
declare function buildPerpDepositViaRelay(params: BuildPerpDepositViaRelayParams): PartialUserOperation;
|
|
459
|
+
|
|
344
460
|
/**
|
|
345
461
|
* Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch
|
|
346
462
|
* to move fee tokens from the user to the fee recipient atomically with
|
|
@@ -912,6 +1028,21 @@ interface ContractAddresses {
|
|
|
912
1028
|
pafiHook: Address;
|
|
913
1029
|
/** Chainlink ETH/USD price feed — used by FeeManager to convert gas cost to USDT. */
|
|
914
1030
|
chainlinkEthUsd: Address;
|
|
1031
|
+
/**
|
|
1032
|
+
* Orderly perp-deposit Relay — holds an ETH reserve to cover the
|
|
1033
|
+
* LayerZero msg.value, charges a USDC token-fee reimbursement.
|
|
1034
|
+
* Lets perp deposits ride the ERC-4337 sponsored gas path without
|
|
1035
|
+
* the user holding ETH for msg.value.
|
|
1036
|
+
*/
|
|
1037
|
+
orderlyRelay: Address;
|
|
1038
|
+
/**
|
|
1039
|
+
* PAFI fee recipient — receives PT gas-reimbursement transfers from
|
|
1040
|
+
* the user on the sponsored path of every scenario (mint, burn,
|
|
1041
|
+
* swap, perp deposit). This is PAFI-controlled, NOT issuer-controlled,
|
|
1042
|
+
* because PAFI pays the ERC-4337 gas via the paymaster — issuers
|
|
1043
|
+
* shouldn't be able to redirect this fee to themselves.
|
|
1044
|
+
*/
|
|
1045
|
+
pafiFeeRecipient: Address;
|
|
915
1046
|
}
|
|
916
1047
|
declare const CONTRACT_ADDRESSES: Record<number, ContractAddresses>;
|
|
917
1048
|
/**
|
|
@@ -1307,4 +1438,4 @@ declare class PafiSDK {
|
|
|
1307
1438
|
signLoginMessage(message: string): Promise<Hex>;
|
|
1308
1439
|
}
|
|
1309
1440
|
|
|
1310
|
-
export { ApiError, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, ENTRY_POINT_V07, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildPartialUserOperation, buildPerpDepositWithGasDeduction, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
|
|
1441
|
+
export { ApiError, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, ENTRY_POINT_V07, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
|
package/dist/index.js
CHANGED
|
@@ -244,6 +244,113 @@ function buildPerpDepositWithGasDeduction(params) {
|
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
// src/perp/buildPerpDepositViaRelay.ts
|
|
248
|
+
import { encodeFunctionData as encodeFunctionData2, erc20Abi as erc20Abi2 } from "viem";
|
|
249
|
+
var ORDERLY_RELAY_ABI = [
|
|
250
|
+
{
|
|
251
|
+
type: "function",
|
|
252
|
+
name: "deposit",
|
|
253
|
+
stateMutability: "nonpayable",
|
|
254
|
+
inputs: [
|
|
255
|
+
{
|
|
256
|
+
name: "req",
|
|
257
|
+
type: "tuple",
|
|
258
|
+
components: [
|
|
259
|
+
{ name: "token", type: "address" },
|
|
260
|
+
{ name: "receiver", type: "address" },
|
|
261
|
+
{ name: "brokerHash", type: "bytes32" },
|
|
262
|
+
{ name: "totalAmount", type: "uint128" },
|
|
263
|
+
{ name: "maxFee", type: "uint128" }
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
],
|
|
267
|
+
outputs: []
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
type: "function",
|
|
271
|
+
name: "quoteTokenFee",
|
|
272
|
+
stateMutability: "view",
|
|
273
|
+
inputs: [
|
|
274
|
+
{
|
|
275
|
+
name: "req",
|
|
276
|
+
type: "tuple",
|
|
277
|
+
components: [
|
|
278
|
+
{ name: "token", type: "address" },
|
|
279
|
+
{ name: "receiver", type: "address" },
|
|
280
|
+
{ name: "brokerHash", type: "bytes32" },
|
|
281
|
+
{ name: "totalAmount", type: "uint128" },
|
|
282
|
+
{ name: "maxFee", type: "uint128" }
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
outputs: [{ name: "", type: "uint128" }]
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
function buildPerpDepositViaRelay(params) {
|
|
290
|
+
if (params.request.totalAmount <= 0n) {
|
|
291
|
+
throw new Error("buildPerpDepositViaRelay: totalAmount must be positive");
|
|
292
|
+
}
|
|
293
|
+
if (params.request.maxFee < 0n) {
|
|
294
|
+
throw new Error("buildPerpDepositViaRelay: maxFee cannot be negative");
|
|
295
|
+
}
|
|
296
|
+
if (!params.relayAddress) {
|
|
297
|
+
throw new Error("buildPerpDepositViaRelay: relayAddress required");
|
|
298
|
+
}
|
|
299
|
+
const operations = [];
|
|
300
|
+
if (params.gasFeePt && params.gasFeePt > 0n) {
|
|
301
|
+
if (!params.pointTokenAddress) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
"buildPerpDepositViaRelay: pointTokenAddress required when gasFeePt > 0"
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (!params.gasFeePtRecipient) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
"buildPerpDepositViaRelay: gasFeePtRecipient required when gasFeePt > 0"
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
operations.push({
|
|
312
|
+
target: params.pointTokenAddress,
|
|
313
|
+
value: 0n,
|
|
314
|
+
data: encodeFunctionData2({
|
|
315
|
+
abi: erc20Abi2,
|
|
316
|
+
functionName: "transfer",
|
|
317
|
+
args: [params.gasFeePtRecipient, params.gasFeePt]
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
operations.push(
|
|
322
|
+
erc20ApproveOp(
|
|
323
|
+
params.request.token,
|
|
324
|
+
params.relayAddress,
|
|
325
|
+
params.request.totalAmount
|
|
326
|
+
)
|
|
327
|
+
);
|
|
328
|
+
const depositCallData = encodeFunctionData2({
|
|
329
|
+
abi: ORDERLY_RELAY_ABI,
|
|
330
|
+
functionName: "deposit",
|
|
331
|
+
args: [
|
|
332
|
+
{
|
|
333
|
+
token: params.request.token,
|
|
334
|
+
receiver: params.request.receiver,
|
|
335
|
+
brokerHash: params.request.brokerHash,
|
|
336
|
+
totalAmount: params.request.totalAmount,
|
|
337
|
+
maxFee: params.request.maxFee
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
});
|
|
341
|
+
operations.push(rawCallOp(params.relayAddress, depositCallData));
|
|
342
|
+
return buildPartialUserOperation({
|
|
343
|
+
sender: params.userAddress,
|
|
344
|
+
nonce: params.aaNonce,
|
|
345
|
+
operations,
|
|
346
|
+
gasLimits: {
|
|
347
|
+
callGasLimit: params.gasLimits?.callGasLimit ?? 800000n,
|
|
348
|
+
verificationGasLimit: params.gasLimits?.verificationGasLimit ?? 150000n,
|
|
349
|
+
preVerificationGas: params.gasLimits?.preVerificationGas ?? 50000n
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
247
354
|
// src/userop/types.ts
|
|
248
355
|
var ZERO_VALUE = 0n;
|
|
249
356
|
|
|
@@ -520,7 +627,9 @@ var CONTRACT_ADDRESSES = {
|
|
|
520
627
|
issuerRegistry: "0xda2D3338CF70F462Ac175F5f2edfa45660CA4f31",
|
|
521
628
|
mintingOracle: "0xD85165939C700E51c8a45099316C6482634C2Ab9",
|
|
522
629
|
pafiHook: "0x870cAF9882d3160602AaC1769C2B264A2d8EC044",
|
|
523
|
-
chainlinkEthUsd: "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70"
|
|
630
|
+
chainlinkEthUsd: "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
|
|
631
|
+
orderlyRelay: "0xDA082DAce1522c185aeB5A713FcA6fa6B6E99e7f",
|
|
632
|
+
pafiFeeRecipient: "0xa3F71eadEd101513a0151007590020dCFD7C495e"
|
|
524
633
|
},
|
|
525
634
|
// Base Sepolia — not in active use; placeholders kept so the map
|
|
526
635
|
// compiles for tooling that enumerates chains.
|
|
@@ -531,7 +640,9 @@ var CONTRACT_ADDRESSES = {
|
|
|
531
640
|
issuerRegistry: PLACEHOLDER_DEAD("dead"),
|
|
532
641
|
mintingOracle: PLACEHOLDER_DEAD("dead"),
|
|
533
642
|
pafiHook: PLACEHOLDER_DEAD("dead"),
|
|
534
|
-
chainlinkEthUsd: PLACEHOLDER_DEAD("de02")
|
|
643
|
+
chainlinkEthUsd: PLACEHOLDER_DEAD("de02"),
|
|
644
|
+
orderlyRelay: PLACEHOLDER_DEAD("de03"),
|
|
645
|
+
pafiFeeRecipient: PLACEHOLDER_DEAD("de04")
|
|
535
646
|
}
|
|
536
647
|
};
|
|
537
648
|
var POINT_TOKEN_FACTORY_ADDRESSES = {
|
|
@@ -974,6 +1085,7 @@ export {
|
|
|
974
1085
|
CONTRACT_ADDRESSES,
|
|
975
1086
|
ConfigurationError,
|
|
976
1087
|
ENTRY_POINT_V07,
|
|
1088
|
+
ORDERLY_RELAY_ABI,
|
|
977
1089
|
ORDERLY_VAULT_ABI,
|
|
978
1090
|
ORDERLY_VAULT_ADDRESSES,
|
|
979
1091
|
ORDERLY_VAULT_BASE_MAINNET,
|
|
@@ -1008,6 +1120,7 @@ export {
|
|
|
1008
1120
|
buildMintRequestTypedData,
|
|
1009
1121
|
buildPartialUserOperation,
|
|
1010
1122
|
buildPermit2ApprovalCalldata,
|
|
1123
|
+
buildPerpDepositViaRelay,
|
|
1011
1124
|
buildPerpDepositWithGasDeduction,
|
|
1012
1125
|
buildReceiverConsentTypedData,
|
|
1013
1126
|
buildSponsorAuthDomain,
|