@pafi-dev/core 0.3.0-beta.1 → 0.3.0-beta.3
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 +137 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +262 -239
- package/dist/index.d.ts +262 -239
- package/dist/index.js +146 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -276,90 +276,44 @@ interface CheckEthAndBranchParams {
|
|
|
276
276
|
declare function checkEthAndBranch(params: CheckEthAndBranchParams): Promise<SubmissionPath>;
|
|
277
277
|
|
|
278
278
|
/**
|
|
279
|
-
* ⚠️ MOCK —
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
279
|
+
* ⚠️ MOCK — `PointToken` v1.4 surface (mint + burn).
|
|
280
|
+
*
|
|
281
|
+
* ## Mint (NEW direct flow — no Relayer)
|
|
282
|
+
*
|
|
283
|
+
* In v1.4 the user calls `PointToken.mint()` directly via an EIP-7702
|
|
284
|
+
* delegated UserOp — `msg.sender == user`. The contract checks the
|
|
285
|
+
* caller is on its authorized minter allowlist. **No Relayer contract,
|
|
286
|
+
* no MintRequest EIP-712 signature.** Backend (gg56) only validates
|
|
287
|
+
* off-chain (balance, policy, KYC) before returning the unsigned UserOp.
|
|
288
|
+
*
|
|
289
|
+
* The mock signature `mint(uint256 amount)` mints to `msg.sender`.
|
|
290
|
+
* SC team confirmation pending — they may pick `mint(address to,
|
|
291
|
+
* uint256 amount)` instead. Either is a 1-line ABI change here.
|
|
292
|
+
*
|
|
293
|
+
* ## Burn — two variants mocked
|
|
294
|
+
*
|
|
295
|
+
* Variant A (simpler, most likely):
|
|
296
|
+
* burn(uint256 amount)
|
|
297
|
+
* - burns from `msg.sender` (user via EIP-7702)
|
|
298
|
+
*
|
|
299
|
+
* Variant B (signature-based, if SC prefers explicit on-chain consent):
|
|
300
|
+
* burnWithSig(BurnConsent consent, Signature sig)
|
|
301
|
+
* - verifies EIP-712 signature before burning
|
|
302
|
+
*
|
|
303
|
+
* Either way the ERC-20 emits `Transfer(from, address(0), amount)` so
|
|
304
|
+
* `BurnIndexer` semantics don't change.
|
|
303
305
|
*/
|
|
304
|
-
declare const
|
|
306
|
+
declare const MOCK_POINT_TOKEN_V2_ABI: readonly [{
|
|
305
307
|
readonly name: "mint";
|
|
306
308
|
readonly type: "function";
|
|
307
309
|
readonly stateMutability: "nonpayable";
|
|
308
310
|
readonly inputs: readonly [{
|
|
309
|
-
readonly type: "
|
|
310
|
-
readonly
|
|
311
|
-
readonly type: "address";
|
|
312
|
-
readonly name: "to";
|
|
313
|
-
}, {
|
|
314
|
-
readonly type: "uint256";
|
|
315
|
-
readonly name: "amount";
|
|
316
|
-
}, {
|
|
317
|
-
readonly type: "uint256";
|
|
318
|
-
readonly name: "feeAmount";
|
|
319
|
-
}, {
|
|
320
|
-
readonly type: "address";
|
|
321
|
-
readonly name: "feeRecipient";
|
|
322
|
-
}, {
|
|
323
|
-
readonly type: "uint256";
|
|
324
|
-
readonly name: "nonce";
|
|
325
|
-
}, {
|
|
326
|
-
readonly type: "uint256";
|
|
327
|
-
readonly name: "deadline";
|
|
328
|
-
}, {
|
|
329
|
-
readonly type: "bytes";
|
|
330
|
-
readonly name: "extData";
|
|
331
|
-
}];
|
|
332
|
-
readonly name: "request";
|
|
333
|
-
}, {
|
|
334
|
-
readonly type: "tuple";
|
|
335
|
-
readonly components: readonly [{
|
|
336
|
-
readonly type: "uint8";
|
|
337
|
-
readonly name: "v";
|
|
338
|
-
}, {
|
|
339
|
-
readonly type: "bytes32";
|
|
340
|
-
readonly name: "r";
|
|
341
|
-
}, {
|
|
342
|
-
readonly type: "bytes32";
|
|
343
|
-
readonly name: "s";
|
|
344
|
-
}];
|
|
345
|
-
readonly name: "userSig";
|
|
346
|
-
}, {
|
|
347
|
-
readonly type: "tuple";
|
|
348
|
-
readonly components: readonly [{
|
|
349
|
-
readonly type: "uint8";
|
|
350
|
-
readonly name: "v";
|
|
351
|
-
}, {
|
|
352
|
-
readonly type: "bytes32";
|
|
353
|
-
readonly name: "r";
|
|
354
|
-
}, {
|
|
355
|
-
readonly type: "bytes32";
|
|
356
|
-
readonly name: "s";
|
|
357
|
-
}];
|
|
358
|
-
readonly name: "issuerSig";
|
|
311
|
+
readonly type: "uint256";
|
|
312
|
+
readonly name: "amount";
|
|
359
313
|
}];
|
|
360
314
|
readonly outputs: readonly [];
|
|
361
315
|
}, {
|
|
362
|
-
readonly name: "
|
|
316
|
+
readonly name: "minters";
|
|
363
317
|
readonly type: "function";
|
|
364
318
|
readonly stateMutability: "view";
|
|
365
319
|
readonly inputs: readonly [{
|
|
@@ -367,79 +321,9 @@ declare const MOCK_RELAYER_V2_ABI: readonly [{
|
|
|
367
321
|
readonly name: "user";
|
|
368
322
|
}];
|
|
369
323
|
readonly outputs: readonly [{
|
|
370
|
-
readonly type: "
|
|
324
|
+
readonly type: "bool";
|
|
371
325
|
}];
|
|
372
326
|
}, {
|
|
373
|
-
readonly name: "Minted";
|
|
374
|
-
readonly type: "event";
|
|
375
|
-
readonly inputs: readonly [{
|
|
376
|
-
readonly type: "address";
|
|
377
|
-
readonly name: "user";
|
|
378
|
-
readonly indexed: true;
|
|
379
|
-
}, {
|
|
380
|
-
readonly type: "uint256";
|
|
381
|
-
readonly name: "amount";
|
|
382
|
-
}, {
|
|
383
|
-
readonly type: "uint256";
|
|
384
|
-
readonly name: "feeAmount";
|
|
385
|
-
}, {
|
|
386
|
-
readonly type: "address";
|
|
387
|
-
readonly name: "feeRecipient";
|
|
388
|
-
readonly indexed: true;
|
|
389
|
-
}, {
|
|
390
|
-
readonly type: "bytes32";
|
|
391
|
-
readonly name: "requestHash";
|
|
392
|
-
}];
|
|
393
|
-
}];
|
|
394
|
-
/**
|
|
395
|
-
* Calldata function selector for `mint((...),(...),(...))` as encoded
|
|
396
|
-
* by viem against {@link MOCK_RELAYER_V2_ABI}. Callers compare against
|
|
397
|
-
* this to sanity-check decoded UserOp inner calls.
|
|
398
|
-
*
|
|
399
|
-
* Recompute when the real ABI lands — almost certainly differs.
|
|
400
|
-
*/
|
|
401
|
-
declare const MOCK_RELAYER_V2_MINT_SELECTOR: "0xMOCKED__";
|
|
402
|
-
/**
|
|
403
|
-
* Struct shape that matches {@link MOCK_RELAYER_V2_ABI}. Exported so
|
|
404
|
-
* builders can accept a typed input without `as const` gymnastics.
|
|
405
|
-
*/
|
|
406
|
-
interface MockMintRequestV2 {
|
|
407
|
-
to: Address;
|
|
408
|
-
amount: bigint;
|
|
409
|
-
feeAmount: bigint;
|
|
410
|
-
feeRecipient: Address;
|
|
411
|
-
nonce: bigint;
|
|
412
|
-
deadline: bigint;
|
|
413
|
-
extData: `0x${string}`;
|
|
414
|
-
}
|
|
415
|
-
interface MockSignatureStruct {
|
|
416
|
-
v: number;
|
|
417
|
-
r: `0x${string}`;
|
|
418
|
-
s: `0x${string}`;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* ⚠️ MOCK — `PointToken` v1.4 burn surface.
|
|
423
|
-
*
|
|
424
|
-
* Two variants mocked — SC team will pick ONE before stable; the other
|
|
425
|
-
* gets deleted during Phase B swap.
|
|
426
|
-
*
|
|
427
|
-
* Variant A (simpler, most likely):
|
|
428
|
-
* burn(uint256 amount)
|
|
429
|
-
* - burns from `msg.sender`
|
|
430
|
-
* - caller handles authorization (the user is `msg.sender` via
|
|
431
|
-
* EIP-7702 delegation, so `msg.sender == user`)
|
|
432
|
-
*
|
|
433
|
-
* Variant B (signature-based, if SC prefers explicit consent on-chain):
|
|
434
|
-
* burnWithSig(BurnConsent consent, Signature sig)
|
|
435
|
-
* - verifies EIP-712 signature before burning
|
|
436
|
-
* - used when the caller isn't the user (e.g. a relayer burns on
|
|
437
|
-
* behalf of the user)
|
|
438
|
-
*
|
|
439
|
-
* Either way the ERC-20 emits `Transfer(from, address(0), amount)` so
|
|
440
|
-
* `BurnIndexer` semantics don't change.
|
|
441
|
-
*/
|
|
442
|
-
declare const MOCK_POINT_TOKEN_V2_ABI: readonly [{
|
|
443
327
|
readonly name: "burn";
|
|
444
328
|
readonly type: "function";
|
|
445
329
|
readonly stateMutability: "nonpayable";
|
|
@@ -565,8 +449,14 @@ declare const MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET: Address;
|
|
|
565
449
|
* 3. Update `src/contracts/index.ts` re-export
|
|
566
450
|
* 4. Delete MOCK_* named exports
|
|
567
451
|
*/
|
|
452
|
+
/**
|
|
453
|
+
* Per-chain contract addresses.
|
|
454
|
+
*
|
|
455
|
+
* v1.4 update: `relayerV2` field dropped — flow now calls
|
|
456
|
+
* `PointToken.mint()` directly via EIP-7702 delegation. No Relayer
|
|
457
|
+
* contract sits between user and PointToken.
|
|
458
|
+
*/
|
|
568
459
|
interface ContractAddresses {
|
|
569
|
-
relayerV2: Address;
|
|
570
460
|
pointToken: Address;
|
|
571
461
|
batchExecutor: Address;
|
|
572
462
|
usdt: Address;
|
|
@@ -580,96 +470,6 @@ declare const MOCK_ADDRESSES: Record<number, ContractAddresses>;
|
|
|
580
470
|
*/
|
|
581
471
|
declare function getMockAddresses(chainId: number): ContractAddresses;
|
|
582
472
|
|
|
583
|
-
/**
|
|
584
|
-
* ⚠️ MOCK — `MintRequest` v2 EIP-712 types.
|
|
585
|
-
*
|
|
586
|
-
* Extends v0.2.x `MintRequest` (4 fields) with three new fields needed
|
|
587
|
-
* for the v1.4 sponsored flow:
|
|
588
|
-
*
|
|
589
|
-
* + feeAmount PT units taken from the mint for the operator
|
|
590
|
-
* + feeRecipient where the fee goes (operator or treasury)
|
|
591
|
-
* + extData arbitrary bytes for future extensions (swap path, etc.)
|
|
592
|
-
*
|
|
593
|
-
* When SC team confirms the real struct, drop this file's content into
|
|
594
|
-
* the real builder and remove the MOCK_ prefix. The function signatures
|
|
595
|
-
* below stay stable — only `MOCK_MINT_REQUEST_V2_TYPES` changes.
|
|
596
|
-
*/
|
|
597
|
-
declare const MOCK_MINT_REQUEST_V2_TYPES: {
|
|
598
|
-
readonly MintRequest: readonly [{
|
|
599
|
-
readonly name: "to";
|
|
600
|
-
readonly type: "address";
|
|
601
|
-
}, {
|
|
602
|
-
readonly name: "amount";
|
|
603
|
-
readonly type: "uint256";
|
|
604
|
-
}, {
|
|
605
|
-
readonly name: "feeAmount";
|
|
606
|
-
readonly type: "uint256";
|
|
607
|
-
}, {
|
|
608
|
-
readonly name: "feeRecipient";
|
|
609
|
-
readonly type: "address";
|
|
610
|
-
}, {
|
|
611
|
-
readonly name: "nonce";
|
|
612
|
-
readonly type: "uint256";
|
|
613
|
-
}, {
|
|
614
|
-
readonly name: "deadline";
|
|
615
|
-
readonly type: "uint256";
|
|
616
|
-
}, {
|
|
617
|
-
readonly name: "extData";
|
|
618
|
-
readonly type: "bytes";
|
|
619
|
-
}];
|
|
620
|
-
};
|
|
621
|
-
/**
|
|
622
|
-
* Build the typed-data envelope that any EIP-712 signer (viem, ethers,
|
|
623
|
-
* Privy) can consume. Callers typically pass the result to
|
|
624
|
-
* `walletClient.signTypedData()` or `privy.signTypedData()`.
|
|
625
|
-
*/
|
|
626
|
-
declare function buildMockMintRequestV2TypedData(domain: PointTokenDomainConfig, message: MockMintRequestV2): {
|
|
627
|
-
domain: {
|
|
628
|
-
name: string;
|
|
629
|
-
version: "1";
|
|
630
|
-
chainId: number;
|
|
631
|
-
verifyingContract: `0x${string}`;
|
|
632
|
-
};
|
|
633
|
-
types: {
|
|
634
|
-
readonly MintRequest: readonly [{
|
|
635
|
-
readonly name: "to";
|
|
636
|
-
readonly type: "address";
|
|
637
|
-
}, {
|
|
638
|
-
readonly name: "amount";
|
|
639
|
-
readonly type: "uint256";
|
|
640
|
-
}, {
|
|
641
|
-
readonly name: "feeAmount";
|
|
642
|
-
readonly type: "uint256";
|
|
643
|
-
}, {
|
|
644
|
-
readonly name: "feeRecipient";
|
|
645
|
-
readonly type: "address";
|
|
646
|
-
}, {
|
|
647
|
-
readonly name: "nonce";
|
|
648
|
-
readonly type: "uint256";
|
|
649
|
-
}, {
|
|
650
|
-
readonly name: "deadline";
|
|
651
|
-
readonly type: "uint256";
|
|
652
|
-
}, {
|
|
653
|
-
readonly name: "extData";
|
|
654
|
-
readonly type: "bytes";
|
|
655
|
-
}];
|
|
656
|
-
};
|
|
657
|
-
primaryType: "MintRequest";
|
|
658
|
-
message: MockMintRequestV2;
|
|
659
|
-
};
|
|
660
|
-
/**
|
|
661
|
-
* Sign a `MintRequest` v2 with a viem WalletClient — server-side flow
|
|
662
|
-
* where the issuer holds the private key directly (KMS-backed signer
|
|
663
|
-
* is the production path; see `@pafi-dev/issuer` KMSSignerAdapter).
|
|
664
|
-
*/
|
|
665
|
-
declare function signMockMintRequestV2(walletClient: WalletClient, domain: PointTokenDomainConfig, message: MockMintRequestV2): Promise<EIP712Signature>;
|
|
666
|
-
/**
|
|
667
|
-
* Verify a `MintRequest` v2 signature and check it came from the
|
|
668
|
-
* expected signer (either user or issuer depending on which side is
|
|
669
|
-
* being verified).
|
|
670
|
-
*/
|
|
671
|
-
declare function verifyMockMintRequestV2(domain: PointTokenDomainConfig, message: MockMintRequestV2, signature: Hex, expectedSigner: Address): Promise<SignatureVerification>;
|
|
672
|
-
|
|
673
473
|
/**
|
|
674
474
|
* ⚠️ MOCK — `BurnConsent` EIP-712 type for the v1.4 reverse flow.
|
|
675
475
|
*
|
|
@@ -744,6 +544,229 @@ declare function buildMockBurnConsentTypedData(domain: PointTokenDomainConfig, m
|
|
|
744
544
|
declare function signMockBurnConsent(walletClient: WalletClient, domain: PointTokenDomainConfig, message: MockBurnConsent): Promise<EIP712Signature>;
|
|
745
545
|
declare function verifyMockBurnConsent(domain: PointTokenDomainConfig, message: MockBurnConsent, signature: Hex, expectedUser: Address): Promise<SignatureVerification>;
|
|
746
546
|
|
|
547
|
+
/**
|
|
548
|
+
* Public contract surface for `@pafi-dev/core/contracts`.
|
|
549
|
+
*
|
|
550
|
+
* Consumers import contract ABIs + addresses + EIP-712 builders from
|
|
551
|
+
* this module. The re-exports below dispatch to either `./mocks/*`
|
|
552
|
+
* (current) or `./real/*` (once SC team delivers real ABIs).
|
|
553
|
+
*
|
|
554
|
+
* ## v1.4 update — Relayer removed
|
|
555
|
+
*
|
|
556
|
+
* The flow no longer routes mint through a Relayer contract. Users
|
|
557
|
+
* call `PointToken.mint()` directly via an EIP-7702 delegated UserOp
|
|
558
|
+
* (`msg.sender == user`). PointToken checks `minters[user]` for
|
|
559
|
+
* authorization. No on-chain MintRequest signature, no dual-sig
|
|
560
|
+
* verification.
|
|
561
|
+
*
|
|
562
|
+
* Exports kept:
|
|
563
|
+
* - `POINT_TOKEN_V2_ABI` — mint + burn surface
|
|
564
|
+
* - `BATCH_EXECUTOR_*` — EIP-7702 delegation target
|
|
565
|
+
* - `CONTRACT_ADDRESSES` — per-chain map (pointToken, batchExecutor, etc.)
|
|
566
|
+
* - `BURN_CONSENT_*` — EIP-712 for Scenario 2 if `burnWithSig` variant
|
|
567
|
+
*
|
|
568
|
+
* Exports removed (vs beta.2):
|
|
569
|
+
* - `RELAYER_V2_ABI`, `RELAYER_V2_MINT_SELECTOR`, `MintRequestV2`,
|
|
570
|
+
* `SignatureStruct` — Relayer contract dropped from flow
|
|
571
|
+
* - `MINT_REQUEST_V2_TYPES`, `buildMintRequestV2TypedData`,
|
|
572
|
+
* `signMintRequestV2`, `verifyMintRequestV2` — no MintRequest sig
|
|
573
|
+
*
|
|
574
|
+
* Status: MOCKS active. See `./mocks/README.md` for deletion checklist.
|
|
575
|
+
*/
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Signature struct shared by `burnWithSig` (and any future EIP-712
|
|
579
|
+
* verifier on-chain). Exported here so consumers don't need to
|
|
580
|
+
* redefine it locally.
|
|
581
|
+
*/
|
|
582
|
+
interface SignatureStruct {
|
|
583
|
+
v: number;
|
|
584
|
+
r: `0x${string}`;
|
|
585
|
+
s: `0x${string}`;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Options for opening a PAFI Web modal — passed through by all adapters.
|
|
590
|
+
* Web-only fields (width/height/windowName) are ignored by mobile
|
|
591
|
+
* adapters that can't resize a system in-app browser.
|
|
592
|
+
*/
|
|
593
|
+
interface ModalOpenOptions {
|
|
594
|
+
/** Web popup pixel width. Default 900. Ignored on mobile. */
|
|
595
|
+
width?: number;
|
|
596
|
+
/** Web popup pixel height. Default 700. Ignored on mobile. */
|
|
597
|
+
height?: number;
|
|
598
|
+
/**
|
|
599
|
+
* `window.open()` target name. Same name across calls re-uses an
|
|
600
|
+
* already-open popup. Default: `"pafi-web"`. Web-only.
|
|
601
|
+
*/
|
|
602
|
+
windowName?: string;
|
|
603
|
+
/**
|
|
604
|
+
* Called when the modal closes — either user-initiated (clicked
|
|
605
|
+
* close, swiped down on mobile) or programmatically via `handle.close()`.
|
|
606
|
+
*/
|
|
607
|
+
onClose?: () => void;
|
|
608
|
+
/**
|
|
609
|
+
* Called when the opened window posts a message back to the parent
|
|
610
|
+
* via `window.opener.postMessage(data, origin)`. PAFI Web uses this
|
|
611
|
+
* to signal "swap complete" / "perp deposit complete" back to the
|
|
612
|
+
* issuer app without needing a redirect.
|
|
613
|
+
*
|
|
614
|
+
* `origin` is the posting window's origin — caller MUST verify it
|
|
615
|
+
* matches the expected PAFI Web host before trusting `data`.
|
|
616
|
+
*/
|
|
617
|
+
onMessage?: (data: unknown, origin: string) => void;
|
|
618
|
+
/**
|
|
619
|
+
* Allowed origins for `onMessage` — messages from other origins are
|
|
620
|
+
* silently dropped. Pass the PAFI Web host(s), e.g.
|
|
621
|
+
* `["https://app.pacificfinance.org", "https://app-dev.pacificfinance.org"]`.
|
|
622
|
+
*
|
|
623
|
+
* Default: empty (all messages rejected). Set explicitly for security.
|
|
624
|
+
*/
|
|
625
|
+
allowedOrigins?: string[];
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Handle to an open PAFI Web modal. Methods are no-ops when the modal
|
|
629
|
+
* has already closed — safe to call without tracking state yourself.
|
|
630
|
+
*/
|
|
631
|
+
interface PafiWebModalHandle {
|
|
632
|
+
/** True when the modal is still open. */
|
|
633
|
+
readonly isOpen: boolean;
|
|
634
|
+
/** Close the modal. Fires `onClose` if the callback was supplied. */
|
|
635
|
+
close(): void;
|
|
636
|
+
/** Bring the modal to focus (web popup only; mobile ignores). */
|
|
637
|
+
focus(): void;
|
|
638
|
+
/**
|
|
639
|
+
* Post a message INTO the modal — useful for ping/pong handshakes
|
|
640
|
+
* with PAFI Web. The modal page must be on the same origin or
|
|
641
|
+
* explicitly listen for the message.
|
|
642
|
+
*/
|
|
643
|
+
postMessage(data: unknown): void;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Adapter that knows how to open a URL in the right UX for the host
|
|
647
|
+
* platform. Callers register one via `setPafiWebModalAdapter()`; if
|
|
648
|
+
* none is registered, the core module falls back to `openWebPopup()`
|
|
649
|
+
* (if `window` is present) or throws (in Node / React Native without
|
|
650
|
+
* an adapter set).
|
|
651
|
+
*
|
|
652
|
+
* ## Mobile adapter example (React Native)
|
|
653
|
+
*
|
|
654
|
+
* ```ts
|
|
655
|
+
* import { setPafiWebModalAdapter } from '@pafi-dev/core';
|
|
656
|
+
* import InAppBrowser from 'react-native-inappbrowser-reborn';
|
|
657
|
+
*
|
|
658
|
+
* setPafiWebModalAdapter({
|
|
659
|
+
* async open(url, options) {
|
|
660
|
+
* const result = await InAppBrowser.open(url, {
|
|
661
|
+
* // iOS: SFSafariViewController
|
|
662
|
+
* dismissButtonStyle: 'close',
|
|
663
|
+
* preferredBarTintColor: '#1a1a1a',
|
|
664
|
+
* preferredControlTintColor: 'white',
|
|
665
|
+
* // Android: Chrome Custom Tab
|
|
666
|
+
* toolbarColor: '#1a1a1a',
|
|
667
|
+
* secondaryToolbarColor: 'black',
|
|
668
|
+
* });
|
|
669
|
+
* options?.onClose?.();
|
|
670
|
+
* return {
|
|
671
|
+
* isOpen: false,
|
|
672
|
+
* close: () => InAppBrowser.close(),
|
|
673
|
+
* focus: () => {},
|
|
674
|
+
* postMessage: () => {},
|
|
675
|
+
* };
|
|
676
|
+
* },
|
|
677
|
+
* });
|
|
678
|
+
* ```
|
|
679
|
+
*
|
|
680
|
+
* ## Expo adapter example
|
|
681
|
+
*
|
|
682
|
+
* ```ts
|
|
683
|
+
* import * as WebBrowser from 'expo-web-browser';
|
|
684
|
+
*
|
|
685
|
+
* setPafiWebModalAdapter({
|
|
686
|
+
* async open(url, options) {
|
|
687
|
+
* await WebBrowser.openBrowserAsync(url);
|
|
688
|
+
* options?.onClose?.();
|
|
689
|
+
* return { isOpen: false, close: WebBrowser.dismissBrowser, focus: () => {}, postMessage: () => {} };
|
|
690
|
+
* },
|
|
691
|
+
* });
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
interface PafiWebModalAdapter {
|
|
695
|
+
open(url: string, options?: ModalOpenOptions): PafiWebModalHandle | Promise<PafiWebModalHandle>;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Web browser popup adapter. Opens the given URL in a centered
|
|
700
|
+
* `window.open()` popup, polls for close, and optionally forwards
|
|
701
|
+
* `postMessage` events back to the caller.
|
|
702
|
+
*
|
|
703
|
+
* Runtime requirement: `window.open` must exist. Throws if called
|
|
704
|
+
* under Node / SSR / React Native — use `setPafiWebModalAdapter()` to
|
|
705
|
+
* provide a platform-specific adapter in those environments.
|
|
706
|
+
*
|
|
707
|
+
* ## Popup blocking
|
|
708
|
+
*
|
|
709
|
+
* Browsers block `window.open()` unless it happens inside a user
|
|
710
|
+
* gesture (click handler). Callers MUST wire this into a direct click
|
|
711
|
+
* handler — wrapping it in a `setTimeout` or async await before the
|
|
712
|
+
* open call will trigger the blocker.
|
|
713
|
+
*/
|
|
714
|
+
declare function openWebPopup(url: string, options?: ModalOpenOptions): PafiWebModalHandle;
|
|
715
|
+
/**
|
|
716
|
+
* The web popup packaged as a {@link PafiWebModalAdapter} so callers
|
|
717
|
+
* can register it explicitly (e.g. in a test harness).
|
|
718
|
+
*/
|
|
719
|
+
declare const webPopupAdapter: PafiWebModalAdapter;
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Register the adapter used by `openPafiWebModal()`. Typically called
|
|
723
|
+
* once during app initialization — mobile apps register a
|
|
724
|
+
* SFSafariViewController / Chrome Custom Tabs adapter, desktop apps
|
|
725
|
+
* can leave it unset (web popup is the default).
|
|
726
|
+
*
|
|
727
|
+
* Pass `null` to unregister and fall back to the default.
|
|
728
|
+
*/
|
|
729
|
+
declare function setPafiWebModalAdapter(adapter: PafiWebModalAdapter | null): void;
|
|
730
|
+
/**
|
|
731
|
+
* Return the currently registered adapter, or `null` when none is set.
|
|
732
|
+
* Useful for tests that want to snapshot-and-restore the adapter.
|
|
733
|
+
*/
|
|
734
|
+
declare function getPafiWebModalAdapter(): PafiWebModalAdapter | null;
|
|
735
|
+
/**
|
|
736
|
+
* Open PAFI Web in the host platform's appropriate UX:
|
|
737
|
+
*
|
|
738
|
+
* - Browser (window.open): centered popup, 900×700 by default
|
|
739
|
+
* - React Native (with adapter registered): SFSafariViewController
|
|
740
|
+
* / Chrome Custom Tabs via `react-native-inappbrowser-reborn` or
|
|
741
|
+
* `expo-web-browser`
|
|
742
|
+
* - Desktop (with adapter registered): custom BrowserWindow / new tab
|
|
743
|
+
*
|
|
744
|
+
* Resolution order:
|
|
745
|
+
* 1. If an adapter was registered via `setPafiWebModalAdapter()`, use it.
|
|
746
|
+
* 2. Else if `window.open` is available, use the built-in web popup.
|
|
747
|
+
* 3. Else throw with a clear error pointing at the adapter registry.
|
|
748
|
+
*
|
|
749
|
+
* @example
|
|
750
|
+
* ```ts
|
|
751
|
+
* // User clicks "Trade on PAFI" button
|
|
752
|
+
* button.addEventListener('click', async () => {
|
|
753
|
+
* const modal = await openPafiWebModal('https://app.pacificfinance.org', {
|
|
754
|
+
* allowedOrigins: ['https://app.pacificfinance.org'],
|
|
755
|
+
* onMessage: (data, origin) => {
|
|
756
|
+
* if (typeof data === 'object' && data && 'txHash' in data) {
|
|
757
|
+
* console.log('Swap confirmed:', data.txHash);
|
|
758
|
+
* modal.close();
|
|
759
|
+
* }
|
|
760
|
+
* },
|
|
761
|
+
* onClose: () => {
|
|
762
|
+
* console.log('User closed modal');
|
|
763
|
+
* },
|
|
764
|
+
* });
|
|
765
|
+
* });
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
declare function openPafiWebModal(url: string, options?: ModalOpenOptions): Promise<PafiWebModalHandle>;
|
|
769
|
+
|
|
747
770
|
declare class PafiSDK {
|
|
748
771
|
private _pointTokenAddress?;
|
|
749
772
|
private _relayContractAddress?;
|
|
@@ -906,4 +929,4 @@ declare class PafiSDK {
|
|
|
906
929
|
signLoginMessage(message: string): Promise<Hex>;
|
|
907
930
|
}
|
|
908
931
|
|
|
909
|
-
export { ApiError, BATCH_EXECUTOR_ABI, MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET as BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA as BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, MOCK_BURN_CONSENT_TYPES as BURN_CONSENT_TYPES, BestQuote, type BuildPartialUserOpParams, type MockBurnConsent as BurnConsent, COMMON_POOLS, COMMON_TOKENS, MOCK_ADDRESSES as CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, LoginMessageParams,
|
|
932
|
+
export { ApiError, BATCH_EXECUTOR_ABI, MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET as BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA as BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, MOCK_BURN_CONSENT_TYPES as BURN_CONSENT_TYPES, BestQuote, type BuildPartialUserOpParams, type MockBurnConsent as BurnConsent, COMMON_POOLS, COMMON_TOKENS, MOCK_ADDRESSES as CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, EIP712Signature, LoginMessageParams, MintParams, MintRequest, type ModalOpenOptions, Operation, POINT_TOKEN_POOLS, MOCK_POINT_TOKEN_V2_ABI as POINT_TOKEN_V2_ABI, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, PathKey, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, type SignatureStruct, SignatureVerification, SigningError, SimulationError, SimulationResult, type SponsorshipScenario, type SubmissionPath, SwapParams, SwapSimulationResult, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, _resetPaymasterConfigForTests, assembleUserOperation, buildMockBurnConsentTypedData as buildBurnConsentTypedData, buildPartialUserOperation, checkEthAndBranch, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, getMockAddresses as getContractAddresses, getPafiWebModalAdapter, getPaymasterConfig, isPaymasterConfigured, mintRequestTypes, openPafiWebModal, openWebPopup, rawCallOp, receiverConsentTypes, setPafiWebModalAdapter, setPaymasterConfig, signMockBurnConsent as signBurnConsent, verifyMockBurnConsent as verifyBurnConsent, webPopupAdapter };
|