@pafi-dev/issuer 0.3.0-beta.2 → 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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Address, Hex, PublicClient, Chain } from 'viem';
2
- import { PointTokenDomainConfig, MintRequest, EIP712Signature, MintParams, SwapParams, MintRequestV2, SignatureStruct, PartialUserOperation, BurnConsent, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
2
+ import { PointTokenDomainConfig, MintRequest, EIP712Signature, MintParams, SwapParams, PartialUserOperation, BurnConsent, SignatureStruct, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
3
3
  export { encodeExtData } from '@pafi-dev/core';
4
4
 
5
5
  /**
@@ -579,6 +579,19 @@ declare class RelayService {
579
579
  * - paymaster sponsorship (PAFI Backend)
580
580
  * - user signature (Privy)
581
581
  */
582
+ /**
583
+ * Build an unsigned UserOp for Scenario 1 (Mint) — direct
584
+ * `PointToken.mint(amount)` flow (v1.4 post-Relayer-removal).
585
+ *
586
+ * `msg.sender` inside the batch = user EOA via EIP-7702 delegation.
587
+ * `PointToken.mint` checks the caller is on its `minters` allowlist
588
+ * (gg56 BE pre-validates this off-chain to avoid wasted gas).
589
+ *
590
+ * Optional PT fee transfer is appended after the mint when
591
+ * `feeAmount > 0` — this is application-level fee recovery (no
592
+ * Relayer doing it for us). The user must end up with `amount - fee`
593
+ * net PT after the batch executes.
594
+ */
582
595
  prepareMint(params: PrepareMintParams): PartialUserOperation;
583
596
  /**
584
597
  * Build an unsigned UserOp for Scenario 2 (Burn/Redeem).
@@ -594,23 +607,36 @@ declare class RelayService {
594
607
  */
595
608
  prepareBurn(params: PrepareBurnParams): PartialUserOperation;
596
609
  }
610
+ /**
611
+ * v1.4 — direct PointToken.mint() flow (no Relayer, no MintRequest sig).
612
+ *
613
+ * Backend (gg56) validates off-chain:
614
+ * - User is on `PointToken.minters[]` allowlist
615
+ * - User has enough off-chain points to claim
616
+ * - Policy passes (KYC, cap, cooldown)
617
+ *
618
+ * Then locks the off-chain balance and returns this UserOp for the FE
619
+ * to sponsor + submit. On confirmation, PointIndexer watches the
620
+ * `Transfer(0x0, user, amount)` event and resolves the lock.
621
+ */
597
622
  interface PrepareMintParams {
598
623
  /** User EOA that will send the UserOp (via EIP-7702 delegation). */
599
624
  userAddress: Address;
600
- /** ERC-4337 account nonce (not the MintRequest nonce — different namespace). */
625
+ /** ERC-4337 account nonce. Caller fetches from EntryPoint v0.7. */
601
626
  aaNonce: bigint;
602
- /** Deployed Relayer v2 contract address (chain-specific). */
603
- relayerAddress: Address;
604
627
  /** BatchExecutor delegation target (chain-specific). */
605
628
  batchExecutorAddress: Address;
606
- /** PointToken being minted used for optional fee transfer call. */
629
+ /** PointToken contractthe call target. */
607
630
  pointTokenAddress: Address;
608
- /** EIP-712-signed MintRequest fields. */
609
- mintRequest: MintRequestV2;
610
- /** User's EIP-712 signature over `mintRequest`. */
611
- userSignature: SignatureStruct;
612
- /** Issuer's EIP-712 signature over `mintRequest`. */
613
- issuerSignature: SignatureStruct;
631
+ /** PT amount to mint to `userAddress` (= msg.sender via EIP-7702). */
632
+ amount: bigint;
633
+ /**
634
+ * Optional — application-level fee transfer appended after mint.
635
+ * Set both `feeAmount` and `feeRecipient` together. Skipped when
636
+ * `feeAmount` is undefined or 0.
637
+ */
638
+ feeAmount?: bigint;
639
+ feeRecipient?: Address;
614
640
  /** Gas limits — defaults are conservative; caller can tighten. */
615
641
  callGasLimit?: bigint;
616
642
  verificationGasLimit?: bigint;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Address, Hex, PublicClient, Chain } from 'viem';
2
- import { PointTokenDomainConfig, MintRequest, EIP712Signature, MintParams, SwapParams, MintRequestV2, SignatureStruct, PartialUserOperation, BurnConsent, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
2
+ import { PointTokenDomainConfig, MintRequest, EIP712Signature, MintParams, SwapParams, PartialUserOperation, BurnConsent, SignatureStruct, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
3
3
  export { encodeExtData } from '@pafi-dev/core';
4
4
 
5
5
  /**
@@ -579,6 +579,19 @@ declare class RelayService {
579
579
  * - paymaster sponsorship (PAFI Backend)
580
580
  * - user signature (Privy)
581
581
  */
582
+ /**
583
+ * Build an unsigned UserOp for Scenario 1 (Mint) — direct
584
+ * `PointToken.mint(amount)` flow (v1.4 post-Relayer-removal).
585
+ *
586
+ * `msg.sender` inside the batch = user EOA via EIP-7702 delegation.
587
+ * `PointToken.mint` checks the caller is on its `minters` allowlist
588
+ * (gg56 BE pre-validates this off-chain to avoid wasted gas).
589
+ *
590
+ * Optional PT fee transfer is appended after the mint when
591
+ * `feeAmount > 0` — this is application-level fee recovery (no
592
+ * Relayer doing it for us). The user must end up with `amount - fee`
593
+ * net PT after the batch executes.
594
+ */
582
595
  prepareMint(params: PrepareMintParams): PartialUserOperation;
583
596
  /**
584
597
  * Build an unsigned UserOp for Scenario 2 (Burn/Redeem).
@@ -594,23 +607,36 @@ declare class RelayService {
594
607
  */
595
608
  prepareBurn(params: PrepareBurnParams): PartialUserOperation;
596
609
  }
610
+ /**
611
+ * v1.4 — direct PointToken.mint() flow (no Relayer, no MintRequest sig).
612
+ *
613
+ * Backend (gg56) validates off-chain:
614
+ * - User is on `PointToken.minters[]` allowlist
615
+ * - User has enough off-chain points to claim
616
+ * - Policy passes (KYC, cap, cooldown)
617
+ *
618
+ * Then locks the off-chain balance and returns this UserOp for the FE
619
+ * to sponsor + submit. On confirmation, PointIndexer watches the
620
+ * `Transfer(0x0, user, amount)` event and resolves the lock.
621
+ */
597
622
  interface PrepareMintParams {
598
623
  /** User EOA that will send the UserOp (via EIP-7702 delegation). */
599
624
  userAddress: Address;
600
- /** ERC-4337 account nonce (not the MintRequest nonce — different namespace). */
625
+ /** ERC-4337 account nonce. Caller fetches from EntryPoint v0.7. */
601
626
  aaNonce: bigint;
602
- /** Deployed Relayer v2 contract address (chain-specific). */
603
- relayerAddress: Address;
604
627
  /** BatchExecutor delegation target (chain-specific). */
605
628
  batchExecutorAddress: Address;
606
- /** PointToken being minted used for optional fee transfer call. */
629
+ /** PointToken contractthe call target. */
607
630
  pointTokenAddress: Address;
608
- /** EIP-712-signed MintRequest fields. */
609
- mintRequest: MintRequestV2;
610
- /** User's EIP-712 signature over `mintRequest`. */
611
- userSignature: SignatureStruct;
612
- /** Issuer's EIP-712 signature over `mintRequest`. */
613
- issuerSignature: SignatureStruct;
631
+ /** PT amount to mint to `userAddress` (= msg.sender via EIP-7702). */
632
+ amount: bigint;
633
+ /**
634
+ * Optional — application-level fee transfer appended after mint.
635
+ * Set both `feeAmount` and `feeRecipient` together. Skipped when
636
+ * `feeAmount` is undefined or 0.
637
+ */
638
+ feeAmount?: bigint;
639
+ feeRecipient?: Address;
614
640
  /** Gas limits — defaults are conservative; caller can tighten. */
615
641
  callGasLimit?: bigint;
616
642
  verificationGasLimit?: bigint;
package/dist/index.js CHANGED
@@ -582,13 +582,15 @@ var RelayError = class extends Error {
582
582
  };
583
583
 
584
584
  // src/relay/relayService.ts
585
- import { encodeFunctionData } from "viem";
585
+ import {
586
+ encodeFunctionData,
587
+ erc20Abi
588
+ } from "viem";
586
589
  import {
587
590
  relayAbi,
588
591
  encodeMintAndSwap,
589
592
  simulateMintAndSwap as coreSimulateMintAndSwap,
590
593
  SimulationError,
591
- RELAYER_V2_ABI,
592
594
  POINT_TOKEN_V2_ABI,
593
595
  buildPartialUserOperation
594
596
  } from "@pafi-dev/core";
@@ -742,10 +744,20 @@ var RelayService = class {
742
744
  * - paymaster sponsorship (PAFI Backend)
743
745
  * - user signature (Privy)
744
746
  */
747
+ /**
748
+ * Build an unsigned UserOp for Scenario 1 (Mint) — direct
749
+ * `PointToken.mint(amount)` flow (v1.4 post-Relayer-removal).
750
+ *
751
+ * `msg.sender` inside the batch = user EOA via EIP-7702 delegation.
752
+ * `PointToken.mint` checks the caller is on its `minters` allowlist
753
+ * (gg56 BE pre-validates this off-chain to avoid wasted gas).
754
+ *
755
+ * Optional PT fee transfer is appended after the mint when
756
+ * `feeAmount > 0` — this is application-level fee recovery (no
757
+ * Relayer doing it for us). The user must end up with `amount - fee`
758
+ * net PT after the batch executes.
759
+ */
745
760
  prepareMint(params) {
746
- if (!params.relayerAddress) {
747
- throw new RelayError("ENCODE_FAILED", "prepareMint: relayerAddress required");
748
- }
749
761
  if (!params.batchExecutorAddress) {
750
762
  throw new RelayError(
751
763
  "ENCODE_FAILED",
@@ -755,36 +767,50 @@ var RelayService = class {
755
767
  if (!params.userAddress) {
756
768
  throw new RelayError("ENCODE_FAILED", "prepareMint: userAddress required");
757
769
  }
770
+ if (!params.pointTokenAddress) {
771
+ throw new RelayError(
772
+ "ENCODE_FAILED",
773
+ "prepareMint: pointTokenAddress required"
774
+ );
775
+ }
776
+ if (params.amount <= 0n) {
777
+ throw new RelayError("ENCODE_FAILED", "prepareMint: amount must be positive");
778
+ }
758
779
  let mintCallData;
759
780
  try {
760
781
  mintCallData = encodeFunctionData({
761
- abi: RELAYER_V2_ABI,
782
+ abi: POINT_TOKEN_V2_ABI,
762
783
  functionName: "mint",
763
- args: [params.mintRequest, params.userSignature, params.issuerSignature]
784
+ args: [params.amount]
764
785
  });
765
786
  } catch (err) {
766
787
  throw new RelayError(
767
788
  "ENCODE_FAILED",
768
- `prepareMint: failed to encode Relayer.mint: ${errorMessage(err)}`,
789
+ `prepareMint: failed to encode PointToken.mint: ${errorMessage(err)}`,
769
790
  err
770
791
  );
771
792
  }
772
793
  const operations = [
773
794
  {
774
- target: params.relayerAddress,
795
+ target: params.pointTokenAddress,
775
796
  value: 0n,
776
797
  data: mintCallData
777
798
  }
778
799
  ];
779
- if (params.mintRequest.feeAmount > 0n) {
800
+ if (params.feeAmount && params.feeAmount > 0n) {
801
+ if (!params.feeRecipient) {
802
+ throw new RelayError(
803
+ "ENCODE_FAILED",
804
+ "prepareMint: feeRecipient required when feeAmount > 0"
805
+ );
806
+ }
780
807
  operations.push({
781
808
  target: params.pointTokenAddress,
782
809
  value: 0n,
783
810
  data: encodeFunctionData({
784
- abi: POINT_TOKEN_V2_ABI,
785
- functionName: "balanceOf",
786
- // placeholder — real impl uses transfer
787
- args: [params.mintRequest.feeRecipient]
811
+ abi: erc20Abi,
812
+ functionName: "transfer",
813
+ args: [params.feeRecipient, params.feeAmount]
788
814
  })
789
815
  });
790
816
  }
@@ -793,7 +819,7 @@ var RelayService = class {
793
819
  nonce: params.aaNonce,
794
820
  operations,
795
821
  gasLimits: {
796
- callGasLimit: params.callGasLimit ?? 500000n,
822
+ callGasLimit: params.callGasLimit ?? 300000n,
797
823
  verificationGasLimit: params.verificationGasLimit ?? 150000n,
798
824
  preVerificationGas: params.preVerificationGas ?? 50000n
799
825
  }