@pafi-dev/core 0.1.0 → 0.1.1
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 +45 -45
- package/dist/abi/index.cjs +2 -2
- package/dist/abi/index.cjs.map +1 -1
- package/dist/abi/index.js +3 -3
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @pafi/core
|
|
1
|
+
# @pafi-dev/core
|
|
2
2
|
|
|
3
3
|
The core TypeScript SDK for the PAFI point token system. Provides EIP-712
|
|
4
4
|
signing and verification, EIP-4361 (Sign-In with Ethereum) helpers,
|
|
5
5
|
contract ABIs, Relay calldata encoding, on-chain quoting, and swap
|
|
6
6
|
building.
|
|
7
7
|
|
|
8
|
-
**`@pafi/core` is HTTP-client-free on purpose.** It covers only the
|
|
8
|
+
**`@pafi-dev/core` is HTTP-client-free on purpose.** It covers only the
|
|
9
9
|
primitives that need a signer or a provider (or neither) — never the
|
|
10
10
|
HTTP wire. The HTTP contract (routes, request/response types) is owned
|
|
11
11
|
by [`@pafi/issuer`](../issuer/README.md) as the single source of truth,
|
|
@@ -20,7 +20,7 @@ pull in server code like `jose` or `node:crypto`.
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
pnpm add @pafi/core viem
|
|
23
|
+
pnpm add @pafi-dev/core viem
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
`viem ^2.0.0` is a peer dependency and must be installed alongside this package.
|
|
@@ -32,7 +32,7 @@ pnpm add @pafi/core viem
|
|
|
32
32
|
```ts
|
|
33
33
|
import { createPublicClient, createWalletClient, http } from "viem";
|
|
34
34
|
import { privateKeyToAccount } from "viem/accounts";
|
|
35
|
-
import { PafiSDK } from "@pafi/core";
|
|
35
|
+
import { PafiSDK } from "@pafi-dev/core";
|
|
36
36
|
|
|
37
37
|
const account = privateKeyToAccount("0x...");
|
|
38
38
|
|
|
@@ -68,14 +68,14 @@ Every module is available both from the root entry and via its own sub-path expo
|
|
|
68
68
|
|
|
69
69
|
| Sub-path | Contents |
|
|
70
70
|
|---|---|
|
|
71
|
-
| `@pafi/core` | All exports (PafiSDK class + everything below) |
|
|
72
|
-
| `@pafi/core/eip712` | `buildMintRequestTypedData`, `buildReceiverConsentTypedData`, `signMintRequest`, `verifyMintRequest`, `signReceiverConsent`, `verifyReceiverConsent`, `buildDomain` |
|
|
73
|
-
| `@pafi/core/relay` | `encodeMintAndSwap`, `decodeMintAndSwap`, `buildRelaySwapParams`, `encodeExtData`, `decodeExtData` |
|
|
74
|
-
| `@pafi/core/contract` | `getMintRequestNonce`, `getReceiverConsentNonce`, `isMinter`, `getTokenName`, `getIssuer`, `isActiveIssuer`, `verifyMintCap`, `getPointTokenIssuer`, `getFeeBasisPoints`, `getSlippageBasisPoints`, `getUsdt` |
|
|
75
|
-
| `@pafi/core/quoting` | `quoteExactInput`, `quoteExactInputSingle`, `quoteBestRoute`, `findBestQuote`, `buildAllPaths`, `combineRoutes` |
|
|
76
|
-
| `@pafi/core/swap` | `checkAllowance`, `buildErc20ApprovalCalldata`, `buildPermit2ApprovalCalldata`, `buildUniversalRouterExecuteArgs`, `buildSwapFromQuote`, `buildV4SwapInput` |
|
|
77
|
-
| `@pafi/core/auth` | `createLoginMessage`, `parseLoginMessage`, `verifyLoginMessage` (EIP-4361) |
|
|
78
|
-
| `@pafi/core/abi` | All contract ABIs |
|
|
71
|
+
| `@pafi-dev/core` | All exports (PafiSDK class + everything below) |
|
|
72
|
+
| `@pafi-dev/core/eip712` | `buildMintRequestTypedData`, `buildReceiverConsentTypedData`, `signMintRequest`, `verifyMintRequest`, `signReceiverConsent`, `verifyReceiverConsent`, `buildDomain` |
|
|
73
|
+
| `@pafi-dev/core/relay` | `encodeMintAndSwap`, `decodeMintAndSwap`, `buildRelaySwapParams`, `encodeExtData`, `decodeExtData` |
|
|
74
|
+
| `@pafi-dev/core/contract` | `getMintRequestNonce`, `getReceiverConsentNonce`, `isMinter`, `getTokenName`, `getIssuer`, `isActiveIssuer`, `verifyMintCap`, `getPointTokenIssuer`, `getFeeBasisPoints`, `getSlippageBasisPoints`, `getUsdt` |
|
|
75
|
+
| `@pafi-dev/core/quoting` | `quoteExactInput`, `quoteExactInputSingle`, `quoteBestRoute`, `findBestQuote`, `buildAllPaths`, `combineRoutes` |
|
|
76
|
+
| `@pafi-dev/core/swap` | `checkAllowance`, `buildErc20ApprovalCalldata`, `buildPermit2ApprovalCalldata`, `buildUniversalRouterExecuteArgs`, `buildSwapFromQuote`, `buildV4SwapInput` |
|
|
77
|
+
| `@pafi-dev/core/auth` | `createLoginMessage`, `parseLoginMessage`, `verifyLoginMessage` (EIP-4361) |
|
|
78
|
+
| `@pafi-dev/core/abi` | All contract ABIs |
|
|
79
79
|
|
|
80
80
|
---
|
|
81
81
|
|
|
@@ -88,7 +88,7 @@ The `PafiSDK` class is a convenience wrapper around all pure functions. All meth
|
|
|
88
88
|
#### Constructor
|
|
89
89
|
|
|
90
90
|
```ts
|
|
91
|
-
import { PafiSDK } from "@pafi/core";
|
|
91
|
+
import { PafiSDK } from "@pafi-dev/core";
|
|
92
92
|
|
|
93
93
|
const sdk = new PafiSDK(config: PafiSDKConfig);
|
|
94
94
|
```
|
|
@@ -127,7 +127,7 @@ await sdk.getDomain(): Promise<PointTokenDomainConfig>
|
|
|
127
127
|
|
|
128
128
|
### EIP-712 Signing
|
|
129
129
|
|
|
130
|
-
#### Pure functions (from `@pafi/core/eip712`)
|
|
130
|
+
#### Pure functions (from `@pafi-dev/core/eip712`)
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
133
|
import {
|
|
@@ -136,7 +136,7 @@ import {
|
|
|
136
136
|
verifyMintRequest,
|
|
137
137
|
signReceiverConsent,
|
|
138
138
|
verifyReceiverConsent,
|
|
139
|
-
} from "@pafi/core/eip712";
|
|
139
|
+
} from "@pafi-dev/core/eip712";
|
|
140
140
|
```
|
|
141
141
|
|
|
142
142
|
##### `buildDomain`
|
|
@@ -217,7 +217,7 @@ All four methods automatically resolve the domain from on-chain state via `getDo
|
|
|
217
217
|
|
|
218
218
|
### Relay Calldata
|
|
219
219
|
|
|
220
|
-
#### Pure functions (from `@pafi/core/relay`)
|
|
220
|
+
#### Pure functions (from `@pafi-dev/core/relay`)
|
|
221
221
|
|
|
222
222
|
```ts
|
|
223
223
|
import {
|
|
@@ -225,7 +225,7 @@ import {
|
|
|
225
225
|
decodeMintAndSwap,
|
|
226
226
|
encodeMintAndSwapV2,
|
|
227
227
|
decodeMintAndSwapV2,
|
|
228
|
-
} from "@pafi/core/relay";
|
|
228
|
+
} from "@pafi-dev/core/relay";
|
|
229
229
|
```
|
|
230
230
|
|
|
231
231
|
##### V1 (Relay.sol)
|
|
@@ -251,7 +251,7 @@ function decodeMintAndSwapV2(calldata: Hex): { mint: MintParams; swap: SwapParam
|
|
|
251
251
|
#### Example
|
|
252
252
|
|
|
253
253
|
```ts
|
|
254
|
-
import { encodeMintAndSwap } from "@pafi/core/relay";
|
|
254
|
+
import { encodeMintAndSwap } from "@pafi-dev/core/relay";
|
|
255
255
|
|
|
256
256
|
const calldata = encodeMintAndSwap(
|
|
257
257
|
{
|
|
@@ -290,7 +290,7 @@ sdk.buildRelaySwapParams({ quote, minAmountOut, feeInUsdt, deadline }): { swapPa
|
|
|
290
290
|
|
|
291
291
|
### Contract Reads
|
|
292
292
|
|
|
293
|
-
#### PointToken (from `@pafi/core/contract`)
|
|
293
|
+
#### PointToken (from `@pafi-dev/core/contract`)
|
|
294
294
|
|
|
295
295
|
```ts
|
|
296
296
|
import {
|
|
@@ -299,7 +299,7 @@ import {
|
|
|
299
299
|
isMinter,
|
|
300
300
|
getTokenName,
|
|
301
301
|
getPointTokenIssuerAddress,
|
|
302
|
-
} from "@pafi/core/contract";
|
|
302
|
+
} from "@pafi-dev/core/contract";
|
|
303
303
|
```
|
|
304
304
|
|
|
305
305
|
| Function | Signature | Description |
|
|
@@ -313,7 +313,7 @@ import {
|
|
|
313
313
|
#### IssuerRegistry
|
|
314
314
|
|
|
315
315
|
```ts
|
|
316
|
-
import { getIssuer, isActiveIssuer } from "@pafi/core/contract";
|
|
316
|
+
import { getIssuer, isActiveIssuer } from "@pafi-dev/core/contract";
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
| Function | Signature | Description |
|
|
@@ -324,7 +324,7 @@ import { getIssuer, isActiveIssuer } from "@pafi/core/contract";
|
|
|
324
324
|
#### MintingOracle
|
|
325
325
|
|
|
326
326
|
```ts
|
|
327
|
-
import { verifyMintCap, getPointTokenIssuer } from "@pafi/core/contract";
|
|
327
|
+
import { verifyMintCap, getPointTokenIssuer } from "@pafi-dev/core/contract";
|
|
328
328
|
```
|
|
329
329
|
|
|
330
330
|
| Function | Signature | Description |
|
|
@@ -335,7 +335,7 @@ import { verifyMintCap, getPointTokenIssuer } from "@pafi/core/contract";
|
|
|
335
335
|
#### Relay helpers
|
|
336
336
|
|
|
337
337
|
```ts
|
|
338
|
-
import { getFeeBasisPoints, getSlippageBasisPoints, getUsdt } from "@pafi/core/contract";
|
|
338
|
+
import { getFeeBasisPoints, getSlippageBasisPoints, getUsdt } from "@pafi-dev/core/contract";
|
|
339
339
|
```
|
|
340
340
|
|
|
341
341
|
| Function | Signature | Description |
|
|
@@ -371,7 +371,7 @@ sdk.encodeExtData(minAmountOut, feeInUsdt): Hex
|
|
|
371
371
|
|
|
372
372
|
### Quoting
|
|
373
373
|
|
|
374
|
-
#### Pure functions (from `@pafi/core/quoting`)
|
|
374
|
+
#### Pure functions (from `@pafi-dev/core/quoting`)
|
|
375
375
|
|
|
376
376
|
```ts
|
|
377
377
|
import {
|
|
@@ -381,7 +381,7 @@ import {
|
|
|
381
381
|
findBestQuote,
|
|
382
382
|
buildAllPaths,
|
|
383
383
|
combineRoutes,
|
|
384
|
-
} from "@pafi/core/quoting";
|
|
384
|
+
} from "@pafi-dev/core/quoting";
|
|
385
385
|
```
|
|
386
386
|
|
|
387
387
|
##### `quoteExactInput`
|
|
@@ -471,7 +471,7 @@ Merges `POINT_TOKEN_POOLS[chainId][pointTokenAddress]` and `COMMON_POOLS[chainId
|
|
|
471
471
|
#### Example
|
|
472
472
|
|
|
473
473
|
```ts
|
|
474
|
-
import { findBestQuote } from "@pafi/core/quoting";
|
|
474
|
+
import { findBestQuote } from "@pafi-dev/core/quoting";
|
|
475
475
|
|
|
476
476
|
// Provide only your token-specific pools — COMMON_POOLS are merged automatically
|
|
477
477
|
const pointTokenPools = [
|
|
@@ -495,7 +495,7 @@ console.log(`Found ${allRoutes.length} valid routes`);
|
|
|
495
495
|
|
|
496
496
|
### Swap Building
|
|
497
497
|
|
|
498
|
-
#### Pure functions (from `@pafi/core/swap`)
|
|
498
|
+
#### Pure functions (from `@pafi-dev/core/swap`)
|
|
499
499
|
|
|
500
500
|
```ts
|
|
501
501
|
import {
|
|
@@ -504,7 +504,7 @@ import {
|
|
|
504
504
|
buildPermit2ApprovalCalldata,
|
|
505
505
|
buildUniversalRouterExecuteArgs,
|
|
506
506
|
buildV4SwapInput,
|
|
507
|
-
} from "@pafi/core/swap";
|
|
507
|
+
} from "@pafi-dev/core/swap";
|
|
508
508
|
```
|
|
509
509
|
|
|
510
510
|
##### `checkAllowance`
|
|
@@ -586,8 +586,8 @@ Build UniversalRouter execute args directly from a `QuoteResult` (returned by `f
|
|
|
586
586
|
#### Example
|
|
587
587
|
|
|
588
588
|
```ts
|
|
589
|
-
import { findBestQuote } from "@pafi/core/quoting";
|
|
590
|
-
import { buildSwapFromQuote } from "@pafi/core/swap";
|
|
589
|
+
import { findBestQuote } from "@pafi-dev/core/quoting";
|
|
590
|
+
import { buildSwapFromQuote } from "@pafi-dev/core/swap";
|
|
591
591
|
|
|
592
592
|
// 1. Quote
|
|
593
593
|
const { bestRoute } = await findBestQuote(client, 8453, tokenIn, USDC, amountIn, myPools);
|
|
@@ -609,14 +609,14 @@ const { commands, inputs } = buildSwapFromQuote({
|
|
|
609
609
|
|
|
610
610
|
### Auth helpers (EIP-4361 — Sign-In With Ethereum)
|
|
611
611
|
|
|
612
|
-
#### Pure functions (from `@pafi/core/auth`)
|
|
612
|
+
#### Pure functions (from `@pafi-dev/core/auth`)
|
|
613
613
|
|
|
614
614
|
```ts
|
|
615
615
|
import {
|
|
616
616
|
createLoginMessage,
|
|
617
617
|
parseLoginMessage,
|
|
618
618
|
verifyLoginMessage,
|
|
619
|
-
} from "@pafi/core/auth";
|
|
619
|
+
} from "@pafi-dev/core/auth";
|
|
620
620
|
```
|
|
621
621
|
|
|
622
622
|
These are stateless helpers — they build, parse, and verify EIP-4361
|
|
@@ -680,7 +680,7 @@ const { token, userAddress } = await fetch(`${ISSUER_URL}/auth/login`, {
|
|
|
680
680
|
}).then(r => r.json());
|
|
681
681
|
|
|
682
682
|
// 4. Store the JWT and attach it to subsequent protected requests
|
|
683
|
-
// (handled by the frontend's own state management — @pafi/core does
|
|
683
|
+
// (handled by the frontend's own state management — @pafi-dev/core does
|
|
684
684
|
// not manage tokens)
|
|
685
685
|
```
|
|
686
686
|
|
|
@@ -695,7 +695,7 @@ const { token, userAddress } = await fetch(`${ISSUER_URL}/auth/login`, {
|
|
|
695
695
|
|
|
696
696
|
### ABIs
|
|
697
697
|
|
|
698
|
-
All ABIs are available from `@pafi/core/abi` or from the root import.
|
|
698
|
+
All ABIs are available from `@pafi-dev/core/abi` or from the root import.
|
|
699
699
|
|
|
700
700
|
```ts
|
|
701
701
|
import {
|
|
@@ -709,7 +709,7 @@ import {
|
|
|
709
709
|
universalRouterAbi,
|
|
710
710
|
permit2Abi,
|
|
711
711
|
v4QuoterAbi,
|
|
712
|
-
} from "@pafi/core/abi";
|
|
712
|
+
} from "@pafi-dev/core/abi";
|
|
713
713
|
```
|
|
714
714
|
|
|
715
715
|
| Export | Contract |
|
|
@@ -737,7 +737,7 @@ import {
|
|
|
737
737
|
POINT_TOKEN_POOLS,
|
|
738
738
|
mintRequestTypes,
|
|
739
739
|
receiverConsentTypes,
|
|
740
|
-
} from "@pafi/core";
|
|
740
|
+
} from "@pafi-dev/core";
|
|
741
741
|
```
|
|
742
742
|
|
|
743
743
|
| Constant | Type | Description |
|
|
@@ -758,7 +758,7 @@ import {
|
|
|
758
758
|
All errors extend `PafiSDKError`, which extends `Error`.
|
|
759
759
|
|
|
760
760
|
```ts
|
|
761
|
-
import { PafiSDKError, ConfigurationError, SigningError, ApiError } from "@pafi/core";
|
|
761
|
+
import { PafiSDKError, ConfigurationError, SigningError, ApiError } from "@pafi-dev/core";
|
|
762
762
|
```
|
|
763
763
|
|
|
764
764
|
| Class | Thrown when |
|
|
@@ -771,7 +771,7 @@ import { PafiSDKError, ConfigurationError, SigningError, ApiError } from "@pafi/
|
|
|
771
771
|
#### Example
|
|
772
772
|
|
|
773
773
|
```ts
|
|
774
|
-
import { ConfigurationError, SigningError } from "@pafi/core";
|
|
774
|
+
import { ConfigurationError, SigningError } from "@pafi-dev/core";
|
|
775
775
|
|
|
776
776
|
try {
|
|
777
777
|
await sdk.signMintRequest(message);
|
|
@@ -959,9 +959,9 @@ interface BestQuote {
|
|
|
959
959
|
Use this when a user wants to swap tokens directly (not through the PAFI Relay).
|
|
960
960
|
|
|
961
961
|
```ts
|
|
962
|
-
import { PafiSDK } from "@pafi/core";
|
|
963
|
-
import { UNIVERSAL_ROUTER_ADDRESSES } from "@pafi/core";
|
|
964
|
-
import { universalRouterAbi } from "@pafi/core/abi";
|
|
962
|
+
import { PafiSDK } from "@pafi-dev/core";
|
|
963
|
+
import { UNIVERSAL_ROUTER_ADDRESSES } from "@pafi-dev/core";
|
|
964
|
+
import { universalRouterAbi } from "@pafi-dev/core/abi";
|
|
965
965
|
|
|
966
966
|
const sdk = new PafiSDK({
|
|
967
967
|
chainId: 8453,
|
|
@@ -1015,7 +1015,7 @@ The SDK builds the EIP-712 typed data object. You can sign it with any signer:
|
|
|
1015
1015
|
- **Privy / WalletConnect / external** — use `sdk.buildReceiverConsentTypedData()` to get the typed data, then pass it to the external signer's `signTypedData`
|
|
1016
1016
|
|
|
1017
1017
|
```ts
|
|
1018
|
-
import { PafiSDK } from "@pafi/core";
|
|
1018
|
+
import { PafiSDK } from "@pafi-dev/core";
|
|
1019
1019
|
|
|
1020
1020
|
const sdk = new PafiSDK({
|
|
1021
1021
|
chainId: 8453,
|
|
@@ -1054,7 +1054,7 @@ const receiverSig = await privy.signTypedData(typedData);
|
|
|
1054
1054
|
// 4b. Or sign with viem WalletClient (if signer is set on SDK)
|
|
1055
1055
|
// const { serialized: receiverSig } = await sdk.signReceiverConsent(consentMessage);
|
|
1056
1056
|
|
|
1057
|
-
// 5. Send to issuer backend (HTTP — not part of @pafi/core)
|
|
1057
|
+
// 5. Send to issuer backend (HTTP — not part of @pafi-dev/core)
|
|
1058
1058
|
await fetch(`${ISSUER_URL}/claim-and-swap`, {
|
|
1059
1059
|
method: "POST",
|
|
1060
1060
|
headers: { "Content-Type": "application/json" },
|
|
@@ -1076,8 +1076,8 @@ The backend can sign with a viem WalletClient, or use `buildMintRequestTypedData
|
|
|
1076
1076
|
to get the typed data for an external signer (HSM/KMS).
|
|
1077
1077
|
|
|
1078
1078
|
```ts
|
|
1079
|
-
import { PafiSDK } from "@pafi/core";
|
|
1080
|
-
import { relayAbi } from "@pafi/core/abi";
|
|
1079
|
+
import { PafiSDK } from "@pafi-dev/core";
|
|
1080
|
+
import { relayAbi } from "@pafi-dev/core/abi";
|
|
1081
1081
|
|
|
1082
1082
|
const sdk = new PafiSDK({
|
|
1083
1083
|
chainId: 8453,
|
package/dist/abi/index.cjs
CHANGED
|
@@ -11,12 +11,12 @@ var _chunkS2XRFFP3cjs = require('../chunk-S2XRFFP3.cjs');
|
|
|
11
11
|
var _chunkCL3QSI4Ocjs = require('../chunk-CL3QSI4O.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
var _chunk27V32VNMcjs = require('../chunk-27V32VNM.cjs');
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
var _chunkIPXARZ6Fcjs = require('../chunk-IPXARZ6F.cjs');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkIPXARZ6Fcjs = require('../chunk-IPXARZ6F.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
package/dist/abi/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/abi/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACE;
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/abi/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wgBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/abi/index.cjs"}
|
package/dist/abi/index.js
CHANGED
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
v4QuoterAbi
|
|
11
11
|
} from "../chunk-KFWZRL7I.js";
|
|
12
|
+
import {
|
|
13
|
+
relayAbi
|
|
14
|
+
} from "../chunk-4RYBJLF3.js";
|
|
12
15
|
import {
|
|
13
16
|
erc20Abi,
|
|
14
17
|
permit2Abi,
|
|
15
18
|
universalRouterAbi
|
|
16
19
|
} from "../chunk-2PIXFXA2.js";
|
|
17
|
-
import {
|
|
18
|
-
relayAbi
|
|
19
|
-
} from "../chunk-4RYBJLF3.js";
|
|
20
20
|
export {
|
|
21
21
|
erc20Abi,
|
|
22
22
|
issuerRegistryAbi,
|
package/dist/index.cjs
CHANGED
|
@@ -60,28 +60,28 @@ var _chunkCWP4PFOPcjs = require('./chunk-CWP4PFOP.cjs');
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
var _chunk4QOWQQCHcjs = require('./chunk-4QOWQQCH.cjs');
|
|
63
64
|
|
|
64
65
|
|
|
66
|
+
var _chunk27V32VNMcjs = require('./chunk-27V32VNM.cjs');
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
|
|
68
|
-
var _chunkO7LQKCBTcjs = require('./chunk-O7LQKCBT.cjs');
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
|
|
73
|
-
var _chunkIPXARZ6Fcjs = require('./chunk-IPXARZ6F.cjs');
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
var _chunkO7LQKCBTcjs = require('./chunk-O7LQKCBT.cjs');
|
|
79
80
|
|
|
80
81
|
|
|
81
|
-
var _chunk4QOWQQCHcjs = require('./chunk-4QOWQQCH.cjs');
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
var
|
|
84
|
+
var _chunkIPXARZ6Fcjs = require('./chunk-IPXARZ6F.cjs');
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,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AM,QAAA,EAAU,IAAA,CAAK,cAAA,CAAe,CAAA;AACpC,IAAA,MAAM,QAAA,EAAU,MAAA,CAAO,OAAA;AACvB,IAAA,GAAA,CAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,yCAAA,CAAmB,gCAAgC,CAAA;AAAA,IAC/D;AACA,IAAA,OAAO,kDAAA,EAAqB,GAAG,MAAA,EAAQ,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAS,QAAQ,CAAC,CAAA;AAAA,EAC5E;AAAA;AAAA,EAGA,MAAM,gBAAA,CAAiB,OAAA,EAA+B;AACpD,IAAA,MAAM,OAAA,EAAS,IAAA,CAAK,aAAA,CAAc,CAAA;AAClC,IAAA,MAAM,QAAA,EAAU,MAAA,CAAO,OAAA;AACvB,IAAA,GAAA,CAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,yCAAA,CAAmB,gCAAgC,CAAA;AAAA,IAC/D;AACA,IAAA,OAAO,MAAA,CAAO,WAAA,CAAY,EAAE,OAAA,EAAS,QAAQ,CAAC,CAAA;AAAA,EAChD;AACF,CAAA;AD3DA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,igIAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/index.cjs","sourcesContent":[null,"import { createPublicClient, http } from \"viem\";\nimport type { Address, Hex, PublicClient, WalletClient } from \"viem\";\n\n// -------------------------------------------------------------------------\n// Re-export all sub-modules\n// -------------------------------------------------------------------------\nexport * from \"./types\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./abi/index\";\nexport * from \"./eip712/index\";\nexport * from \"./relay/index\";\nexport * from \"./contract/index\";\nexport * from \"./quoting/index\";\nexport * from \"./swap/index\";\nexport * from \"./auth/index\";\n\n// -------------------------------------------------------------------------\n// Internal imports for PafiSDK class\n// -------------------------------------------------------------------------\nimport { buildMintRequestTypedData, signMintRequest, verifyMintRequest } from \"./eip712/mintRequest\";\nimport {\n buildReceiverConsentTypedData,\n signReceiverConsent,\n verifyReceiverConsent,\n} from \"./eip712/receiverConsent\";\nimport {\n getMintRequestNonce,\n getReceiverConsentNonce,\n getTokenName,\n} from \"./contract/pointToken\";\nimport {\n encodeMintAndSwap,\n decodeMintAndSwap,\n encodeExtData,\n buildRelaySwapParams,\n} from \"./relay/calldata\";\nimport { findBestQuote } from \"./quoting/quote\";\nimport {\n buildSwapFromQuote,\n buildUniversalRouterExecuteArgs,\n} from \"./swap/universalRouter\";\nimport { simulateMintAndSwap } from \"./relay/simulate\";\nimport { simulateSwap } from \"./swap/simulate\";\nimport type { SimulationResult } from \"./relay/simulate\";\nimport type { SwapSimulationResult } from \"./swap/simulate\";\nimport { createLoginMessage } from \"./auth/loginMessage\";\nimport type { LoginMessageParams } from \"./auth/types\";\nimport { ConfigurationError } from \"./errors\";\nimport type {\n BestQuote,\n EIP712Signature,\n MintParams,\n MintRequest,\n PafiSDKConfig,\n PathKey,\n PointTokenDomainConfig,\n PoolKey,\n QuoteResult,\n ReceiverConsent,\n SignatureVerification,\n SwapParams,\n} from \"./types\";\n\n// -------------------------------------------------------------------------\n// PafiSDK — convenience class wrapping all contract + crypto primitives.\n//\n// This class is HTTP-client-free on purpose. It covers signing, verifying,\n// contract reads, and calldata encoding — the things that need a signer\n// or a provider but no HTTP layer. The issuer backend defines its own HTTP\n// contract via `@pafi/issuer`; frontends build `fetch()` calls against\n// those types directly.\n// -------------------------------------------------------------------------\n\nexport class PafiSDK {\n private _pointTokenAddress?: Address;\n private _relayContractAddress?: Address;\n private _signer?: WalletClient;\n private _provider?: PublicClient;\n private _chainId?: number;\n\n constructor(config: PafiSDKConfig) {\n this._pointTokenAddress = config.pointTokenAddress;\n this._relayContractAddress = config.relayContractAddress;\n this._signer = config.signer;\n this._chainId = config.chainId;\n\n if (config.provider) {\n this._provider = config.provider;\n } else if (config.rpcUrl) {\n this._provider = createPublicClient({\n transport: http(config.rpcUrl),\n });\n }\n }\n\n // -------------------------------------------------------------------------\n // Setters\n // -------------------------------------------------------------------------\n\n setPointTokenAddress(address: Address): void {\n this._pointTokenAddress = address;\n }\n\n setRelayContractAddress(address: Address): void {\n this._relayContractAddress = address;\n }\n\n setSigner(signer: WalletClient): void {\n this._signer = signer;\n }\n\n setProvider(provider: PublicClient): void {\n this._provider = provider;\n }\n\n // -------------------------------------------------------------------------\n // Private guards\n // -------------------------------------------------------------------------\n\n private requirePointToken(): Address {\n if (!this._pointTokenAddress) {\n throw new ConfigurationError(\"pointTokenAddress not set\");\n }\n return this._pointTokenAddress;\n }\n\n private requireProvider(): PublicClient {\n if (!this._provider) {\n throw new ConfigurationError(\"provider not set\");\n }\n return this._provider;\n }\n\n private requireSigner(): WalletClient {\n if (!this._signer) {\n throw new ConfigurationError(\"signer not set\");\n }\n return this._signer;\n }\n\n private requireChainId(): number {\n if (this._chainId === undefined) {\n throw new ConfigurationError(\"chainId not set\");\n }\n return this._chainId;\n }\n\n // -------------------------------------------------------------------------\n // Domain\n // -------------------------------------------------------------------------\n\n async getDomain(): Promise<PointTokenDomainConfig> {\n const provider = this.requireProvider();\n const pointToken = this.requirePointToken();\n const chainId = this.requireChainId();\n const name = await getTokenName(provider, pointToken);\n return { name, verifyingContract: pointToken, chainId };\n }\n\n // -------------------------------------------------------------------------\n // EIP-712 — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Build the EIP-712 typed data for a MintRequest.\n * Pass the result to any external signer (Privy, WalletConnect, etc.).\n */\n async buildMintRequestTypedData(message: MintRequest) {\n const domain = await this.getDomain();\n return buildMintRequestTypedData(domain, message);\n }\n\n /**\n * Build the EIP-712 typed data for a ReceiverConsent.\n * Pass the result to any external signer (Privy, WalletConnect, etc.).\n */\n async buildReceiverConsentTypedData(message: ReceiverConsent) {\n const domain = await this.getDomain();\n return buildReceiverConsentTypedData(domain, message);\n }\n\n async signMintRequest(message: MintRequest): Promise<EIP712Signature> {\n const domain = await this.getDomain();\n return signMintRequest(this.requireSigner(), domain, message);\n }\n\n async verifyMintRequest(\n message: MintRequest,\n signature: Hex,\n expectedMinter: Address,\n ): Promise<SignatureVerification> {\n const domain = await this.getDomain();\n return verifyMintRequest(domain, message, signature, expectedMinter);\n }\n\n async signReceiverConsent(\n message: ReceiverConsent,\n ): Promise<EIP712Signature> {\n const domain = await this.getDomain();\n return signReceiverConsent(this.requireSigner(), domain, message);\n }\n\n async verifyReceiverConsent(\n message: ReceiverConsent,\n signature: Hex,\n expectedReceiver: Address,\n ): Promise<SignatureVerification> {\n const domain = await this.getDomain();\n return verifyReceiverConsent(domain, message, signature, expectedReceiver);\n }\n\n // -------------------------------------------------------------------------\n // Contract reads\n // -------------------------------------------------------------------------\n\n async getMintRequestNonce(receiver: Address): Promise<bigint> {\n return getMintRequestNonce(\n this.requireProvider(),\n this.requirePointToken(),\n receiver,\n );\n }\n\n async getReceiverConsentNonce(receiver: Address): Promise<bigint> {\n return getReceiverConsentNonce(\n this.requireProvider(),\n this.requirePointToken(),\n receiver,\n );\n }\n\n // -------------------------------------------------------------------------\n // Relay calldata — delegates to pure functions\n // -------------------------------------------------------------------------\n\n encodeMintAndSwap(mint: MintParams, swap: SwapParams): Hex {\n return encodeMintAndSwap(mint, swap);\n }\n\n decodeMintAndSwap(calldata: Hex): { mint: MintParams; swap: SwapParams } {\n return decodeMintAndSwap(calldata);\n }\n\n // -------------------------------------------------------------------------\n // Quoting — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Find the best swap route from `tokenIn` to `tokenOut`.\n * Merges `pools` with COMMON_POOLS for the configured chain, builds all\n * paths, and quotes via a single multicall RPC call.\n */\n async findBestQuote(\n tokenIn: Address,\n tokenOut: Address,\n exactAmount: bigint,\n pools: PoolKey[] = [],\n quoterAddress?: Address,\n maxHops?: number,\n ): Promise<BestQuote> {\n return findBestQuote(\n this.requireProvider(),\n this.requireChainId(),\n tokenIn,\n tokenOut,\n exactAmount,\n pools,\n quoterAddress,\n maxHops,\n );\n }\n\n // -------------------------------------------------------------------------\n // Swap building — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Build UniversalRouter execute args from a quote result.\n * The caller provides `minAmountOut` after applying their own slippage.\n */\n buildSwapFromQuote(params: {\n quote: QuoteResult;\n currencyIn: Address;\n currencyOut: Address;\n amountIn: bigint;\n minAmountOut: bigint;\n }): { commands: Hex; inputs: Hex[] } {\n return buildSwapFromQuote(params);\n }\n\n /**\n * Build Relay SwapParams + extData from a quote result.\n * Returns ready-to-use args for `Relay.mintAndSwap`.\n */\n buildRelaySwapParams(params: {\n quote: { path: PathKey[] };\n minAmountOut: bigint;\n feeInUsdt: bigint;\n deadline: bigint;\n }): { swapParams: SwapParams; extData: Hex } {\n return buildRelaySwapParams(params);\n }\n\n /**\n * Encode extData for ReceiverConsent and MintParams.\n * extData = abi.encode(minAmountOut, feeInUsdt)\n */\n encodeExtData(minAmountOut: bigint, feeInUsdt: bigint): Hex {\n return encodeExtData(minAmountOut, feeInUsdt);\n }\n\n // -------------------------------------------------------------------------\n // Simulation — dry-run via eth_call (no gas spent)\n // -------------------------------------------------------------------------\n\n /**\n * Simulate a Relay.mintAndSwap call. Catches reverts (bad signatures,\n * expired deadlines, insufficient mint cap, pool errors) before submitting.\n *\n * @param relayAddress - Relay contract address\n * @param mint - MintParams with real signatures\n * @param swap - SwapParams (path + deadline)\n * @param from - Relayer address that will submit the tx\n */\n async simulateMintAndSwap(\n relayAddress: Address,\n mint: MintParams,\n swap: SwapParams,\n from: Address,\n ): Promise<SimulationResult> {\n return simulateMintAndSwap(\n this.requireProvider(),\n relayAddress,\n mint,\n swap,\n from,\n );\n }\n\n /**\n * Simulate a UniversalRouter.execute swap call. Catches reverts (bad\n * approvals, insufficient balance, pool errors) before submitting.\n *\n * @param routerAddress - UniversalRouter contract address\n * @param commands - Packed command bytes (from buildSwapFromQuote)\n * @param inputs - Encoded inputs (from buildSwapFromQuote)\n * @param deadline - Unix timestamp\n * @param from - Address that will execute the swap\n */\n async simulateSwap(\n routerAddress: Address,\n commands: Hex,\n inputs: Hex[],\n deadline: bigint,\n from: Address,\n ): Promise<SwapSimulationResult> {\n return simulateSwap(\n this.requireProvider(),\n routerAddress,\n commands,\n inputs,\n deadline,\n from,\n );\n }\n\n // -------------------------------------------------------------------------\n // Auth — EIP-4361 login helpers (offline, stateless)\n //\n // These are convenience wrappers around the pure functions in\n // `./auth/loginMessage.ts`. They do NOT hit the network — the caller is\n // responsible for fetching the nonce, POSTing the signed message, and\n // storing the JWT returned by the issuer backend.\n // -------------------------------------------------------------------------\n\n /**\n * Build an EIP-4361 login message for the current signer + chain. The\n * caller supplies the issuer-specific fields (domain, nonce, uri); the SDK\n * fills in the wallet address and chain id from its own config.\n */\n async createLoginMessage(\n params: Omit<LoginMessageParams, \"address\" | \"chainId\">,\n ): Promise<string> {\n const signer = this.requireSigner();\n const chainId = this.requireChainId();\n const account = signer.account;\n if (!account) {\n throw new ConfigurationError(\"signer has no account attached\");\n }\n return createLoginMessage({ ...params, address: account.address, chainId });\n }\n\n /** Sign a login message string with the current signer (personal_sign) */\n async signLoginMessage(message: string): Promise<Hex> {\n const signer = this.requireSigner();\n const account = signer.account;\n if (!account) {\n throw new ConfigurationError(\"signer has no account attached\");\n }\n return signer.signMessage({ account, message });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE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acific-Finance/pafi-backend/pafi-sdk/packages/core/dist/index.cjs","sourcesContent":[null,"import { createPublicClient, http } from \"viem\";\nimport type { Address, Hex, PublicClient, WalletClient } from \"viem\";\n\n// -------------------------------------------------------------------------\n// Re-export all sub-modules\n// -------------------------------------------------------------------------\nexport * from \"./types\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./abi/index\";\nexport * from \"./eip712/index\";\nexport * from \"./relay/index\";\nexport * from \"./contract/index\";\nexport * from \"./quoting/index\";\nexport * from \"./swap/index\";\nexport * from \"./auth/index\";\n\n// -------------------------------------------------------------------------\n// Internal imports for PafiSDK class\n// -------------------------------------------------------------------------\nimport { buildMintRequestTypedData, signMintRequest, verifyMintRequest } from \"./eip712/mintRequest\";\nimport {\n buildReceiverConsentTypedData,\n signReceiverConsent,\n verifyReceiverConsent,\n} from \"./eip712/receiverConsent\";\nimport {\n getMintRequestNonce,\n getReceiverConsentNonce,\n getTokenName,\n} from \"./contract/pointToken\";\nimport {\n encodeMintAndSwap,\n decodeMintAndSwap,\n encodeExtData,\n buildRelaySwapParams,\n} from \"./relay/calldata\";\nimport { findBestQuote } from \"./quoting/quote\";\nimport {\n buildSwapFromQuote,\n buildUniversalRouterExecuteArgs,\n} from \"./swap/universalRouter\";\nimport { simulateMintAndSwap } from \"./relay/simulate\";\nimport { simulateSwap } from \"./swap/simulate\";\nimport type { SimulationResult } from \"./relay/simulate\";\nimport type { SwapSimulationResult } from \"./swap/simulate\";\nimport { createLoginMessage } from \"./auth/loginMessage\";\nimport type { LoginMessageParams } from \"./auth/types\";\nimport { ConfigurationError } from \"./errors\";\nimport type {\n BestQuote,\n EIP712Signature,\n MintParams,\n MintRequest,\n PafiSDKConfig,\n PathKey,\n PointTokenDomainConfig,\n PoolKey,\n QuoteResult,\n ReceiverConsent,\n SignatureVerification,\n SwapParams,\n} from \"./types\";\n\n// -------------------------------------------------------------------------\n// PafiSDK — convenience class wrapping all contract + crypto primitives.\n//\n// This class is HTTP-client-free on purpose. It covers signing, verifying,\n// contract reads, and calldata encoding — the things that need a signer\n// or a provider but no HTTP layer. The issuer backend defines its own HTTP\n// contract via `@pafi/issuer`; frontends build `fetch()` calls against\n// those types directly.\n// -------------------------------------------------------------------------\n\nexport class PafiSDK {\n private _pointTokenAddress?: Address;\n private _relayContractAddress?: Address;\n private _signer?: WalletClient;\n private _provider?: PublicClient;\n private _chainId?: number;\n\n constructor(config: PafiSDKConfig) {\n this._pointTokenAddress = config.pointTokenAddress;\n this._relayContractAddress = config.relayContractAddress;\n this._signer = config.signer;\n this._chainId = config.chainId;\n\n if (config.provider) {\n this._provider = config.provider;\n } else if (config.rpcUrl) {\n this._provider = createPublicClient({\n transport: http(config.rpcUrl),\n });\n }\n }\n\n // -------------------------------------------------------------------------\n // Setters\n // -------------------------------------------------------------------------\n\n setPointTokenAddress(address: Address): void {\n this._pointTokenAddress = address;\n }\n\n setRelayContractAddress(address: Address): void {\n this._relayContractAddress = address;\n }\n\n setSigner(signer: WalletClient): void {\n this._signer = signer;\n }\n\n setProvider(provider: PublicClient): void {\n this._provider = provider;\n }\n\n // -------------------------------------------------------------------------\n // Private guards\n // -------------------------------------------------------------------------\n\n private requirePointToken(): Address {\n if (!this._pointTokenAddress) {\n throw new ConfigurationError(\"pointTokenAddress not set\");\n }\n return this._pointTokenAddress;\n }\n\n private requireProvider(): PublicClient {\n if (!this._provider) {\n throw new ConfigurationError(\"provider not set\");\n }\n return this._provider;\n }\n\n private requireSigner(): WalletClient {\n if (!this._signer) {\n throw new ConfigurationError(\"signer not set\");\n }\n return this._signer;\n }\n\n private requireChainId(): number {\n if (this._chainId === undefined) {\n throw new ConfigurationError(\"chainId not set\");\n }\n return this._chainId;\n }\n\n // -------------------------------------------------------------------------\n // Domain\n // -------------------------------------------------------------------------\n\n async getDomain(): Promise<PointTokenDomainConfig> {\n const provider = this.requireProvider();\n const pointToken = this.requirePointToken();\n const chainId = this.requireChainId();\n const name = await getTokenName(provider, pointToken);\n return { name, verifyingContract: pointToken, chainId };\n }\n\n // -------------------------------------------------------------------------\n // EIP-712 — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Build the EIP-712 typed data for a MintRequest.\n * Pass the result to any external signer (Privy, WalletConnect, etc.).\n */\n async buildMintRequestTypedData(message: MintRequest) {\n const domain = await this.getDomain();\n return buildMintRequestTypedData(domain, message);\n }\n\n /**\n * Build the EIP-712 typed data for a ReceiverConsent.\n * Pass the result to any external signer (Privy, WalletConnect, etc.).\n */\n async buildReceiverConsentTypedData(message: ReceiverConsent) {\n const domain = await this.getDomain();\n return buildReceiverConsentTypedData(domain, message);\n }\n\n async signMintRequest(message: MintRequest): Promise<EIP712Signature> {\n const domain = await this.getDomain();\n return signMintRequest(this.requireSigner(), domain, message);\n }\n\n async verifyMintRequest(\n message: MintRequest,\n signature: Hex,\n expectedMinter: Address,\n ): Promise<SignatureVerification> {\n const domain = await this.getDomain();\n return verifyMintRequest(domain, message, signature, expectedMinter);\n }\n\n async signReceiverConsent(\n message: ReceiverConsent,\n ): Promise<EIP712Signature> {\n const domain = await this.getDomain();\n return signReceiverConsent(this.requireSigner(), domain, message);\n }\n\n async verifyReceiverConsent(\n message: ReceiverConsent,\n signature: Hex,\n expectedReceiver: Address,\n ): Promise<SignatureVerification> {\n const domain = await this.getDomain();\n return verifyReceiverConsent(domain, message, signature, expectedReceiver);\n }\n\n // -------------------------------------------------------------------------\n // Contract reads\n // -------------------------------------------------------------------------\n\n async getMintRequestNonce(receiver: Address): Promise<bigint> {\n return getMintRequestNonce(\n this.requireProvider(),\n this.requirePointToken(),\n receiver,\n );\n }\n\n async getReceiverConsentNonce(receiver: Address): Promise<bigint> {\n return getReceiverConsentNonce(\n this.requireProvider(),\n this.requirePointToken(),\n receiver,\n );\n }\n\n // -------------------------------------------------------------------------\n // Relay calldata — delegates to pure functions\n // -------------------------------------------------------------------------\n\n encodeMintAndSwap(mint: MintParams, swap: SwapParams): Hex {\n return encodeMintAndSwap(mint, swap);\n }\n\n decodeMintAndSwap(calldata: Hex): { mint: MintParams; swap: SwapParams } {\n return decodeMintAndSwap(calldata);\n }\n\n // -------------------------------------------------------------------------\n // Quoting — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Find the best swap route from `tokenIn` to `tokenOut`.\n * Merges `pools` with COMMON_POOLS for the configured chain, builds all\n * paths, and quotes via a single multicall RPC call.\n */\n async findBestQuote(\n tokenIn: Address,\n tokenOut: Address,\n exactAmount: bigint,\n pools: PoolKey[] = [],\n quoterAddress?: Address,\n maxHops?: number,\n ): Promise<BestQuote> {\n return findBestQuote(\n this.requireProvider(),\n this.requireChainId(),\n tokenIn,\n tokenOut,\n exactAmount,\n pools,\n quoterAddress,\n maxHops,\n );\n }\n\n // -------------------------------------------------------------------------\n // Swap building — delegates to pure functions\n // -------------------------------------------------------------------------\n\n /**\n * Build UniversalRouter execute args from a quote result.\n * The caller provides `minAmountOut` after applying their own slippage.\n */\n buildSwapFromQuote(params: {\n quote: QuoteResult;\n currencyIn: Address;\n currencyOut: Address;\n amountIn: bigint;\n minAmountOut: bigint;\n }): { commands: Hex; inputs: Hex[] } {\n return buildSwapFromQuote(params);\n }\n\n /**\n * Build Relay SwapParams + extData from a quote result.\n * Returns ready-to-use args for `Relay.mintAndSwap`.\n */\n buildRelaySwapParams(params: {\n quote: { path: PathKey[] };\n minAmountOut: bigint;\n feeInUsdt: bigint;\n deadline: bigint;\n }): { swapParams: SwapParams; extData: Hex } {\n return buildRelaySwapParams(params);\n }\n\n /**\n * Encode extData for ReceiverConsent and MintParams.\n * extData = abi.encode(minAmountOut, feeInUsdt)\n */\n encodeExtData(minAmountOut: bigint, feeInUsdt: bigint): Hex {\n return encodeExtData(minAmountOut, feeInUsdt);\n }\n\n // -------------------------------------------------------------------------\n // Simulation — dry-run via eth_call (no gas spent)\n // -------------------------------------------------------------------------\n\n /**\n * Simulate a Relay.mintAndSwap call. Catches reverts (bad signatures,\n * expired deadlines, insufficient mint cap, pool errors) before submitting.\n *\n * @param relayAddress - Relay contract address\n * @param mint - MintParams with real signatures\n * @param swap - SwapParams (path + deadline)\n * @param from - Relayer address that will submit the tx\n */\n async simulateMintAndSwap(\n relayAddress: Address,\n mint: MintParams,\n swap: SwapParams,\n from: Address,\n ): Promise<SimulationResult> {\n return simulateMintAndSwap(\n this.requireProvider(),\n relayAddress,\n mint,\n swap,\n from,\n );\n }\n\n /**\n * Simulate a UniversalRouter.execute swap call. Catches reverts (bad\n * approvals, insufficient balance, pool errors) before submitting.\n *\n * @param routerAddress - UniversalRouter contract address\n * @param commands - Packed command bytes (from buildSwapFromQuote)\n * @param inputs - Encoded inputs (from buildSwapFromQuote)\n * @param deadline - Unix timestamp\n * @param from - Address that will execute the swap\n */\n async simulateSwap(\n routerAddress: Address,\n commands: Hex,\n inputs: Hex[],\n deadline: bigint,\n from: Address,\n ): Promise<SwapSimulationResult> {\n return simulateSwap(\n this.requireProvider(),\n routerAddress,\n commands,\n inputs,\n deadline,\n from,\n );\n }\n\n // -------------------------------------------------------------------------\n // Auth — EIP-4361 login helpers (offline, stateless)\n //\n // These are convenience wrappers around the pure functions in\n // `./auth/loginMessage.ts`. They do NOT hit the network — the caller is\n // responsible for fetching the nonce, POSTing the signed message, and\n // storing the JWT returned by the issuer backend.\n // -------------------------------------------------------------------------\n\n /**\n * Build an EIP-4361 login message for the current signer + chain. The\n * caller supplies the issuer-specific fields (domain, nonce, uri); the SDK\n * fills in the wallet address and chain id from its own config.\n */\n async createLoginMessage(\n params: Omit<LoginMessageParams, \"address\" | \"chainId\">,\n ): Promise<string> {\n const signer = this.requireSigner();\n const chainId = this.requireChainId();\n const account = signer.account;\n if (!account) {\n throw new ConfigurationError(\"signer has no account attached\");\n }\n return createLoginMessage({ ...params, address: account.address, chainId });\n }\n\n /** Sign a login message string with the current signer (personal_sign) */\n async signLoginMessage(message: string): Promise<Hex> {\n const signer = this.requireSigner();\n const account = signer.account;\n if (!account) {\n throw new ConfigurationError(\"signer has no account attached\");\n }\n return signer.signMessage({ account, message });\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,17 @@ import {
|
|
|
53
53
|
mintRequestTypes,
|
|
54
54
|
receiverConsentTypes
|
|
55
55
|
} from "./chunk-R4L66ZR5.js";
|
|
56
|
+
import {
|
|
57
|
+
buildRelaySwapParams,
|
|
58
|
+
decodeExtData,
|
|
59
|
+
decodeMintAndSwap,
|
|
60
|
+
encodeExtData,
|
|
61
|
+
encodeMintAndSwap,
|
|
62
|
+
simulateMintAndSwap
|
|
63
|
+
} from "./chunk-DSCUHT3F.js";
|
|
64
|
+
import {
|
|
65
|
+
relayAbi
|
|
66
|
+
} from "./chunk-4RYBJLF3.js";
|
|
56
67
|
import {
|
|
57
68
|
SETTLE_ALL,
|
|
58
69
|
SWAP_EXACT_IN,
|
|
@@ -71,17 +82,6 @@ import {
|
|
|
71
82
|
permit2Abi,
|
|
72
83
|
universalRouterAbi
|
|
73
84
|
} from "./chunk-2PIXFXA2.js";
|
|
74
|
-
import {
|
|
75
|
-
buildRelaySwapParams,
|
|
76
|
-
decodeExtData,
|
|
77
|
-
decodeMintAndSwap,
|
|
78
|
-
encodeExtData,
|
|
79
|
-
encodeMintAndSwap,
|
|
80
|
-
simulateMintAndSwap
|
|
81
|
-
} from "./chunk-DSCUHT3F.js";
|
|
82
|
-
import {
|
|
83
|
-
relayAbi
|
|
84
|
-
} from "./chunk-4RYBJLF3.js";
|
|
85
85
|
import {
|
|
86
86
|
ApiError,
|
|
87
87
|
ConfigurationError,
|