@txnlab/haystack-router 3.3.0 → 3.5.0
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 +70 -12
- package/dist/index.d.mts +153 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +126 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,9 +17,11 @@ TypeScript/JavaScript SDK for [Haystack Order Router](https://txnlab.gitbook.io/
|
|
|
17
17
|
|
|
18
18
|
| Tier | Key | Rate Limit | Use Case |
|
|
19
19
|
| --- | --- | --- | --- |
|
|
20
|
-
| **Free** | `
|
|
20
|
+
| **Free** | `hay_pk_4zhj33wahuxfplteyif5xpcgnm` | 60 requests/min | Development, testing, low-volume integrations |
|
|
21
21
|
| **Production** | Request from [support@txnlab.dev](mailto:support@txnlab.dev) | Higher limits | Production applications |
|
|
22
22
|
|
|
23
|
+
The previous free key, `1b72df7e-1131-4449-8ce1-29b79dd3f51e`, is deprecated: its limit falls to 10 requests/min between December 1, 2026 and March 1, 2027, and it stops working on April 1, 2027.
|
|
24
|
+
|
|
23
25
|
The SDK sends the key in the `X-API-Key` header, never in the URL, so it stays out of server logs, browser history and caches.
|
|
24
26
|
|
|
25
27
|
## Installation
|
|
@@ -40,7 +42,7 @@ const { activeAddress, transactionSigner } = useWallet()
|
|
|
40
42
|
|
|
41
43
|
// Initialize the client
|
|
42
44
|
const router = new RouterClient({
|
|
43
|
-
apiKey: '
|
|
45
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
44
46
|
})
|
|
45
47
|
|
|
46
48
|
// Get a quote
|
|
@@ -72,12 +74,12 @@ import { RouterClient } from '@txnlab/haystack-router'
|
|
|
72
74
|
|
|
73
75
|
// Basic initialization
|
|
74
76
|
const router = new RouterClient({
|
|
75
|
-
apiKey: '
|
|
77
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
76
78
|
})
|
|
77
79
|
|
|
78
80
|
// Custom Algod configuration
|
|
79
81
|
const router = new RouterClient({
|
|
80
|
-
apiKey: '
|
|
82
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
81
83
|
algodUri: 'https://mainnet-api.4160.nodely.dev/',
|
|
82
84
|
algodToken: '',
|
|
83
85
|
algodPort: 443,
|
|
@@ -86,7 +88,7 @@ const router = new RouterClient({
|
|
|
86
88
|
|
|
87
89
|
// Earn fees with the referral program
|
|
88
90
|
const router = new RouterClient({
|
|
89
|
-
apiKey: '
|
|
91
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
90
92
|
referrerAddress: 'YOUR_ALGORAND_ADDRESS', // Earns 25% of swap fees
|
|
91
93
|
feeBps: 15, // 0.15% fee (max: 300 = 3%)
|
|
92
94
|
})
|
|
@@ -186,6 +188,57 @@ const summary = swap.getSummary()
|
|
|
186
188
|
|
|
187
189
|
Without `slippage`, a launch quote overstates the output by about the slippage; `newSwap()` logs a warning when the two don't match. Fixed-output launch buys and launch-token-to-launch-token swaps aren't supported yet and return a 400.
|
|
188
190
|
|
|
191
|
+
### First Stage Taxed Tokens
|
|
192
|
+
|
|
193
|
+
First Stage tokens (MOOJ, DEAL, DUMBLY, STACKED and others) are frozen in registered holders' wallets and charge a tax to move. The router handles them itself: when a swap's input or output is one of these tokens and the holding is frozen, the swap group includes First Stage's own calls (unfreeze, the tax payment, refreeze), and the quote accounts for the tax. Pass `address`, so the router can check the holding:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const quote = await router.newQuote({
|
|
197
|
+
fromASAID: 2154668640, // MOOJ
|
|
198
|
+
toASAID: 0, // ALGO
|
|
199
|
+
amount: 1_000_000_000,
|
|
200
|
+
address: activeAddress,
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
if (quote.firstStage) {
|
|
204
|
+
// quote.quote is net of the tax
|
|
205
|
+
// quote.firstStage.fromTax: MOOJ sell tax, included in `amount`
|
|
206
|
+
// quote.firstStage.toTax: the output's buy tax (0 here)
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Without `address`, the swap is built without First Stage's calls, which fails for a frozen holding. Don't use a First Stage middleware (such as `@firststage/deflex-middleware`) with the router: its calls and the router's would be added twice, and the group fails. This applies to ORDER_ROUTER v4 swaps, and is on for API keys by default; contact TxnLab if your key's integration still wraps these swaps itself.
|
|
211
|
+
|
|
212
|
+
### Falcon (Post-Quantum) Accounts
|
|
213
|
+
|
|
214
|
+
A transaction signed with a Falcon-1024 key (passkey accounts, Pera and Lute quantum accounts) costs 3 fee units instead of 1, so the swap group's fees must cover 0.002 ALGO more for each transaction the account signs. Pass `signerType: 'falcon'`:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { getSignatureType } from '@txnlab/use-wallet'
|
|
218
|
+
|
|
219
|
+
const quote = await router.newQuote({
|
|
220
|
+
fromASAID: 0,
|
|
221
|
+
toASAID: 31566704,
|
|
222
|
+
amount: 1_000_000,
|
|
223
|
+
address: activeAddress,
|
|
224
|
+
signerType:
|
|
225
|
+
getSignatureType(activeAccount.emptySignature) === 'pqsig'
|
|
226
|
+
? 'falcon'
|
|
227
|
+
: 'ed25519',
|
|
228
|
+
})
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The router includes the extra in the fees of the transactions it builds, and the `SwapComposer` adds it for the ones it or your code adds: app opt-ins, middleware transactions, `addTransaction()` and `addMethodCall()` calls sent from `address`. It all goes on the fee of the swap's input transfer, which the account pays, before the group ID is assigned, so no transaction is added. `buildGroup()`'s fees and `getSummary().totalFees` include it.
|
|
232
|
+
|
|
233
|
+
`newSwap()` reads whether the router's transactions include it from the router's response to the swap request (its `signerType`), not from the quote. When they don't (a router that doesn't support it, or one mid-update), the composer adds it for those too.
|
|
234
|
+
|
|
235
|
+
With `fetchQuote()`, pass `signerType` to `newSwap()` as well. A router that doesn't support Falcon signers returns a quote that doesn't say it was requested for one, so the composer would otherwise compose for ed25519:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const raw = await router.fetchQuote({ ...params, signerType: 'falcon' })
|
|
239
|
+
const swap = await router.newSwap({ quote: raw, address, slippage, signer, signerType: 'falcon' })
|
|
240
|
+
```
|
|
241
|
+
|
|
189
242
|
### Transaction Signing
|
|
190
243
|
|
|
191
244
|
The SDK supports both standard `algosdk.TransactionSigner` and ARC-1 compliant signer functions.
|
|
@@ -298,25 +351,27 @@ Middleware can:
|
|
|
298
351
|
- Add transactions before the swap (e.g., unfreeze account, setup calls)
|
|
299
352
|
- Add transactions after the swap (e.g., tax payments, cleanup calls)
|
|
300
353
|
|
|
354
|
+
First Stage tokens no longer need one: the router wraps them itself (see [First Stage Taxed Tokens](#first-stage-taxed-tokens)).
|
|
355
|
+
|
|
301
356
|
```typescript
|
|
302
357
|
import { RouterClient } from '@txnlab/haystack-router'
|
|
303
|
-
import {
|
|
358
|
+
import { MyAssetMiddleware } from 'my-asset-middleware' // Example external package
|
|
304
359
|
|
|
305
360
|
// Initialize middleware
|
|
306
|
-
const
|
|
361
|
+
const myAsset = new MyAssetMiddleware({
|
|
307
362
|
contractAppId: 123456,
|
|
308
363
|
})
|
|
309
364
|
|
|
310
365
|
// Pass middleware to RouterClient
|
|
311
366
|
const router = new RouterClient({
|
|
312
|
-
apiKey: '
|
|
313
|
-
middleware: [
|
|
367
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
368
|
+
middleware: [myAsset], // Middleware is applied automatically
|
|
314
369
|
})
|
|
315
370
|
|
|
316
371
|
// Use normally - middleware handles everything
|
|
317
372
|
const quote = await router.newQuote({
|
|
318
373
|
fromASAID: 0, // ALGO
|
|
319
|
-
toASAID: 789012, // Custom asset
|
|
374
|
+
toASAID: 789012, // Custom asset
|
|
320
375
|
amount: 1_000_000,
|
|
321
376
|
address: userAddress,
|
|
322
377
|
})
|
|
@@ -337,7 +392,7 @@ const autoOptOut = new AutoOptOutMiddleware({
|
|
|
337
392
|
})
|
|
338
393
|
|
|
339
394
|
const router = new RouterClient({
|
|
340
|
-
apiKey: '
|
|
395
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
341
396
|
middleware: [autoOptOut],
|
|
342
397
|
})
|
|
343
398
|
|
|
@@ -358,7 +413,7 @@ If you're not using `autoOptIn: true`, you can manually check if opt-in is neede
|
|
|
358
413
|
|
|
359
414
|
```typescript
|
|
360
415
|
const router = new RouterClient({
|
|
361
|
-
apiKey: '
|
|
416
|
+
apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
362
417
|
autoOptIn: false, // Default if not provided
|
|
363
418
|
})
|
|
364
419
|
|
|
@@ -447,6 +502,7 @@ async newQuote(params: FetchQuoteParams): Promise<SwapQuote>
|
|
|
447
502
|
| `maxDepth` | Maximum swap hops | `number` | `4` |
|
|
448
503
|
| `optIn` | Override auto opt-in behavior | `boolean` | `undefined` |
|
|
449
504
|
| `slippage` | Slippage % you will execute with, in [0, 100); required for accurate launch token quotes | `number` | `undefined` |
|
|
505
|
+
| `signerType` | Key type `address` signs with; `'falcon'` adds a [Falcon signer's extra fees](#falcon-post-quantum-accounts) | `'ed25519' \| 'falcon'` | `'ed25519'` |
|
|
450
506
|
|
|
451
507
|
#### RouterClient.newSwap()
|
|
452
508
|
|
|
@@ -463,6 +519,7 @@ async newSwap(config: SwapComposerConfig): Promise<SwapComposer>
|
|
|
463
519
|
| `slippage` | Slippage tolerance as percentage (e.g., 1 for 1%) | `number` |
|
|
464
520
|
| `signer` | Transaction signer function | `algosdk.TransactionSigner \| ((txnGroup: Transaction[], indexesToSign: number[]) => Promise<(Uint8Array \| null)[]>)` |
|
|
465
521
|
| `note` | Optional note for the user-signed input transaction (for tracking purposes) | `Uint8Array` |
|
|
522
|
+
| `signerType` | Optional key type `address` signs with (default: the quote's, else `'ed25519'`). Pass it with a `fetchQuote()` response | `'ed25519' \| 'falcon'` |
|
|
466
523
|
|
|
467
524
|
#### RouterClient.needsAssetOptIn()
|
|
468
525
|
|
|
@@ -490,6 +547,7 @@ Plain object returned by [`newQuote()`](#routerclientnewquote). Extends the raw
|
|
|
490
547
|
| `address` | User address (if provided) | `string \| undefined` |
|
|
491
548
|
| `slippage` | Slippage sent with the quote request (if provided) | `number \| undefined` |
|
|
492
549
|
| `launch` | Bonding-curve details for a pre-bonding launch token (amounts as `bigint`) | `SwapLaunchQuote \| undefined` |
|
|
550
|
+
| `signerType` | Key type the quote was requested for (`'ed25519'` when none was) | `'ed25519' \| 'falcon' \| undefined` |
|
|
493
551
|
| `createdAt` | Timestamp when quote was created | `number` |
|
|
494
552
|
|
|
495
553
|
**All properties from API response:**
|
package/dist/index.d.mts
CHANGED
|
@@ -39,6 +39,11 @@ export declare const DEFAULT_MAX_DEPTH = 4;
|
|
|
39
39
|
export declare const DEFAULT_AUTO_OPT_IN = false;
|
|
40
40
|
/** Default debug level (no debug logging) */
|
|
41
41
|
export declare const DEFAULT_DEBUG_LEVEL: "none";
|
|
42
|
+
/**
|
|
43
|
+
* What a Falcon (post-quantum) signature adds to its transaction's fee, in
|
|
44
|
+
* microAlgos: algod charges a transaction it signs 3 fee units instead of 1
|
|
45
|
+
*/
|
|
46
|
+
export declare const FALCON_EXTRA_FEE = 2000n;
|
|
42
47
|
/** Default number of rounds to wait for transaction confirmation */
|
|
43
48
|
export declare const DEFAULT_CONFIRMATION_ROUNDS = 10;
|
|
44
49
|
/**
|
|
@@ -84,6 +89,19 @@ export type Config = Omit<Required<ConfigParams>, 'referrerAddress' | 'debugLeve
|
|
|
84
89
|
* Swap quote type determining which amount is fixed
|
|
85
90
|
*/
|
|
86
91
|
export type QuoteType = 'fixed-input' | 'fixed-output';
|
|
92
|
+
/**
|
|
93
|
+
* The kind of key the swapping account signs with
|
|
94
|
+
*
|
|
95
|
+
* - `'ed25519'`: an ordinary Algorand account (the default)
|
|
96
|
+
* - `'falcon'`: a Falcon-1024 (post-quantum) account, such as a passkey
|
|
97
|
+
* account or a Pera or Lute quantum account. Each transaction it signs costs
|
|
98
|
+
* 3 fee units (0.003 ALGO) instead of 1, which the swap group's fees must
|
|
99
|
+
* cover.
|
|
100
|
+
*
|
|
101
|
+
* A rekeyed account signs with its auth address's key. With use-wallet, an
|
|
102
|
+
* account is Falcon when `getSignatureType(account.emptySignature) === 'pqsig'`.
|
|
103
|
+
*/
|
|
104
|
+
export type SignerType = 'ed25519' | 'falcon';
|
|
87
105
|
/**
|
|
88
106
|
* Parameters for requesting a swap quote from the Haystack Router API (raw API method)
|
|
89
107
|
*/
|
|
@@ -104,7 +122,13 @@ export interface FetchQuoteParams {
|
|
|
104
122
|
readonly maxDepth?: number;
|
|
105
123
|
/** Whether to include asset opt-in transaction (overrides config.autoOptIn if set) */
|
|
106
124
|
readonly optIn?: boolean;
|
|
107
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Address of the account that will perform the swap (required if autoOptIn is enabled)
|
|
127
|
+
*
|
|
128
|
+
* Sent with the quote request: a swap of a First Stage taxed token (MOOJ and
|
|
129
|
+
* others) is quoted with its tax, and wrapped in First Stage's calls, only
|
|
130
|
+
* when this account's holding is frozen. Without it, the swap isn't wrapped.
|
|
131
|
+
*/
|
|
108
132
|
readonly address?: string | null;
|
|
109
133
|
/**
|
|
110
134
|
* Slippage tolerance as a percentage (e.g., 1 for 1%), in [0, 100)
|
|
@@ -115,6 +139,21 @@ export interface FetchQuoteParams {
|
|
|
115
139
|
* the slippage. Other quotes ignore it.
|
|
116
140
|
*/
|
|
117
141
|
readonly slippage?: number;
|
|
142
|
+
/**
|
|
143
|
+
* The kind of key the swapping account signs with (default: `'ed25519'`)
|
|
144
|
+
*
|
|
145
|
+
* Pass `'falcon'` for a Falcon (post-quantum) account. The router then
|
|
146
|
+
* includes the extra fee of every transaction it builds for the account to
|
|
147
|
+
* sign, and the SwapComposer adds it for the transactions it adds (app
|
|
148
|
+
* opt-ins, middleware, `addTransaction()`, `addMethodCall()`), all in the
|
|
149
|
+
* fee of the swap's input transfer, which the account pays. The router
|
|
150
|
+
* can't tell from the address: an unused Falcon account looks like any
|
|
151
|
+
* other.
|
|
152
|
+
*
|
|
153
|
+
* With `fetchQuote()`, pass it to `newSwap()` too: a response from a router
|
|
154
|
+
* that doesn't support it doesn't say the quote was for a Falcon signer.
|
|
155
|
+
*/
|
|
156
|
+
readonly signerType?: SignerType;
|
|
118
157
|
/**
|
|
119
158
|
* ⚠️ **ADVANCED USE ONLY - NON-COMPOSABLE SWAPS** ⚠️
|
|
120
159
|
*
|
|
@@ -241,6 +280,28 @@ export type SwapLaunchQuote = Omit<LaunchQuote, 'bondingSurplus' | 'refund' | 'g
|
|
|
241
280
|
/** Whether a buy completes bonding */
|
|
242
281
|
readonly graduates: boolean;
|
|
243
282
|
};
|
|
283
|
+
/**
|
|
284
|
+
* First Stage taxes of a quote that swaps a First Stage taxed token (MOOJ and
|
|
285
|
+
* others) out of or into a frozen holding. The router adds First Stage's own
|
|
286
|
+
* calls to the swap group; don't also use a First Stage middleware.
|
|
287
|
+
*
|
|
288
|
+
* Amounts are in base units of that side's asset.
|
|
289
|
+
*/
|
|
290
|
+
export interface FirstStageQuote {
|
|
291
|
+
/** Sell tax on the input asset (0 when the input isn't wrapped or isn't taxed) */
|
|
292
|
+
readonly fromTax: number;
|
|
293
|
+
/** Buy tax on the output asset (0 when the output isn't wrapped or isn't taxed) */
|
|
294
|
+
readonly toTax: number;
|
|
295
|
+
/** The sides the swap wraps in First Stage's calls when their holding is frozen */
|
|
296
|
+
readonly wrapped: ('from' | 'to')[];
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Normalized First Stage taxes on a SwapQuote, with amounts coerced to bigint
|
|
300
|
+
*/
|
|
301
|
+
export type SwapFirstStageQuote = Omit<FirstStageQuote, 'fromTax' | 'toTax'> & {
|
|
302
|
+
readonly fromTax: bigint;
|
|
303
|
+
readonly toTax: bigint;
|
|
304
|
+
};
|
|
244
305
|
/**
|
|
245
306
|
* Quote response from the Haystack Router API
|
|
246
307
|
*/
|
|
@@ -284,13 +345,27 @@ export interface FetchQuoteResponse {
|
|
|
284
345
|
* For a buy, `quote` is launch tokens out; for a sell, it is the output asset.
|
|
285
346
|
*/
|
|
286
347
|
readonly launch?: LaunchQuote;
|
|
348
|
+
/**
|
|
349
|
+
* First Stage taxes, present only when the swap wraps a First Stage taxed
|
|
350
|
+
* token's frozen holding. `quote` is already net of them: what the output
|
|
351
|
+
* holding keeps (fixed-input), or all the input holding sends (fixed-output).
|
|
352
|
+
*/
|
|
353
|
+
readonly firstStage?: FirstStageQuote;
|
|
354
|
+
/**
|
|
355
|
+
* `'falcon'` when the quote was requested for a Falcon signer and the
|
|
356
|
+
* router supports it. Absent otherwise, including from a router that
|
|
357
|
+
* doesn't support Falcon signers yet. Whether the swap's transactions
|
|
358
|
+
* include the extra fees is the execute response's `signerType`
|
|
359
|
+
* ({@link FetchSwapTxnsResponse}), which `newSwap()` reads.
|
|
360
|
+
*/
|
|
361
|
+
readonly signerType?: 'falcon';
|
|
287
362
|
}
|
|
288
363
|
/**
|
|
289
364
|
* Enhanced quote result returned by RouterClient.newQuote()
|
|
290
365
|
*
|
|
291
366
|
* Extends the raw API response with additional metadata and type normalization.
|
|
292
367
|
*/
|
|
293
|
-
export type SwapQuote = Omit<FetchQuoteResponse, 'quote' | 'launch'> & {
|
|
368
|
+
export type SwapQuote = Omit<FetchQuoteResponse, 'quote' | 'launch' | 'firstStage' | 'signerType'> & {
|
|
294
369
|
/**
|
|
295
370
|
* The quoted output amount or input amount (coerced to bigint)
|
|
296
371
|
*
|
|
@@ -306,6 +381,14 @@ export type SwapQuote = Omit<FetchQuoteResponse, 'quote' | 'launch'> & {
|
|
|
306
381
|
readonly slippage?: number;
|
|
307
382
|
/** Bonding-curve details, present only when one side is a pre-bonding HayLaunch token */
|
|
308
383
|
readonly launch?: SwapLaunchQuote;
|
|
384
|
+
/** First Stage taxes, present only when the swap wraps a First Stage taxed token's frozen holding */
|
|
385
|
+
readonly firstStage?: SwapFirstStageQuote;
|
|
386
|
+
/**
|
|
387
|
+
* The kind of key the quote's account signs with: what `newQuote()` was
|
|
388
|
+
* asked for (`'ed25519'` when nothing was), or `'falcon'` copied from a
|
|
389
|
+
* `fetchQuote()` response that echoes it
|
|
390
|
+
*/
|
|
391
|
+
readonly signerType?: SignerType;
|
|
309
392
|
/** Timestamp when the quote was created (in milliseconds) */
|
|
310
393
|
readonly createdAt: number;
|
|
311
394
|
};
|
|
@@ -361,6 +444,13 @@ export interface FetchSwapTxnsBody {
|
|
|
361
444
|
export interface FetchSwapTxnsResponse {
|
|
362
445
|
/** Array of transaction data */
|
|
363
446
|
readonly txns: SwapTransaction[];
|
|
447
|
+
/**
|
|
448
|
+
* `'falcon'` when the transactions' fees include a Falcon signer's extra
|
|
449
|
+
* fees for every transaction the account signs. Absent otherwise, even when
|
|
450
|
+
* the quote echoed `signerType` (a router mid-update can build without
|
|
451
|
+
* them): a Falcon signer's group then needs them all added.
|
|
452
|
+
*/
|
|
453
|
+
readonly signerType?: 'falcon';
|
|
364
454
|
}
|
|
365
455
|
/**
|
|
366
456
|
* Bonding-curve leg of an executed pre-bonding HayLaunch swap
|
|
@@ -718,7 +808,7 @@ export interface AutoOptOutConfig {
|
|
|
718
808
|
* })
|
|
719
809
|
*
|
|
720
810
|
* const router = new RouterClient({
|
|
721
|
-
* apiKey: '
|
|
811
|
+
* apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
722
812
|
* middleware: [autoOptOut],
|
|
723
813
|
* })
|
|
724
814
|
*
|
|
@@ -783,6 +873,20 @@ export interface SwapComposerConfig {
|
|
|
783
873
|
readonly middleware?: SwapMiddleware[];
|
|
784
874
|
/** Optional note field for the user-signed input transaction (payment or asset transfer) */
|
|
785
875
|
readonly note?: Uint8Array;
|
|
876
|
+
/**
|
|
877
|
+
* The kind of key `address` signs with (default: the quote's `signerType`,
|
|
878
|
+
* else `'ed25519'`). For `'falcon'`, the composer adds the extra fee of each
|
|
879
|
+
* transaction the account sends to the swap's input transfer as it builds
|
|
880
|
+
* the group.
|
|
881
|
+
*/
|
|
882
|
+
readonly signerType?: SignerType;
|
|
883
|
+
/**
|
|
884
|
+
* Whether `swapTxns`' fees already include a Falcon signer's extra fees:
|
|
885
|
+
* the `fetchSwapTransactions()` response's `signerType` is `'falcon'`. Then
|
|
886
|
+
* only the transactions the composer adds are counted. Default: false, and
|
|
887
|
+
* every transaction the account sends is.
|
|
888
|
+
*/
|
|
889
|
+
readonly signerFeesIncluded?: boolean;
|
|
786
890
|
/** Debug logging level (propagated from RouterClient) */
|
|
787
891
|
readonly debugLevel?: 'none' | 'info' | 'debug' | 'trace';
|
|
788
892
|
}
|
|
@@ -819,6 +923,15 @@ export declare class SwapComposer {
|
|
|
819
923
|
private readonly signer;
|
|
820
924
|
private readonly middleware;
|
|
821
925
|
private readonly note?;
|
|
926
|
+
private readonly signerType;
|
|
927
|
+
private readonly signerFeesIncluded;
|
|
928
|
+
/** Transactions the account sends whose Falcon fees the composer adds */
|
|
929
|
+
private signerFeeTxns;
|
|
930
|
+
/** The account's first transaction in the group, which carries them when there's no input transfer */
|
|
931
|
+
private firstUserTxn?;
|
|
932
|
+
/** The swap's input transfer, whose fee carries a Falcon signer's extra fees */
|
|
933
|
+
private inputTxn?;
|
|
934
|
+
private signerFeesAdded;
|
|
822
935
|
private inputTransactionIndex?;
|
|
823
936
|
private outputTransactionIndex?;
|
|
824
937
|
private curveTransactionIndex?;
|
|
@@ -1029,6 +1142,24 @@ export declare class SwapComposer {
|
|
|
1029
1142
|
* ```
|
|
1030
1143
|
*/
|
|
1031
1144
|
getSummary(): SwapSummary | undefined;
|
|
1145
|
+
/**
|
|
1146
|
+
* Counts a transaction from sender toward a Falcon signer's extra fees
|
|
1147
|
+
* (addSignerFees) when the account sends it, unless the router's fees
|
|
1148
|
+
* already include it (included). Every way of adding a transaction calls
|
|
1149
|
+
* it; txn is the transaction when the composer holds it (not a method call
|
|
1150
|
+
* the ATC builds), which can then carry the fees.
|
|
1151
|
+
*/
|
|
1152
|
+
private trackSignerFee;
|
|
1153
|
+
/**
|
|
1154
|
+
* Adds a Falcon signer's extra fees before the group is built: a Falcon
|
|
1155
|
+
* signature costs 3 fee units where an ed25519 one costs 1, and fees pool
|
|
1156
|
+
* across the group, so the fee of the swap's input transfer (which already
|
|
1157
|
+
* carries the router's fee budget) rises by FALCON_EXTRA_FEE for each
|
|
1158
|
+
* transaction the account sends that the router's fees don't include. The
|
|
1159
|
+
* account pays it, like every fee of the group. Runs once, while the group
|
|
1160
|
+
* is still being built.
|
|
1161
|
+
*/
|
|
1162
|
+
private addSignerFees;
|
|
1032
1163
|
/**
|
|
1033
1164
|
* Validates an Algorand address
|
|
1034
1165
|
*/
|
|
@@ -1053,6 +1184,14 @@ export declare class SwapComposer {
|
|
|
1053
1184
|
* the router precedes an ALGO input.
|
|
1054
1185
|
*/
|
|
1055
1186
|
private findInputTransactionIndex;
|
|
1187
|
+
/**
|
|
1188
|
+
* Finds the router's last app call among the API's transactions: v4's
|
|
1189
|
+
* route call or v3's finalize, which pays the output. The router's calls
|
|
1190
|
+
* are the pre-signed ones. A First Stage swap ends with the user's own tax
|
|
1191
|
+
* payment and First Stage calls after it, so the last transaction isn't
|
|
1192
|
+
* always the router's. Falls back to the last transaction.
|
|
1193
|
+
*/
|
|
1194
|
+
private findOutputTransactionIndex;
|
|
1056
1195
|
/**
|
|
1057
1196
|
* For a launch quote, finds the user-signed curve buy or sell call and
|
|
1058
1197
|
* records the curve leg in summaryData. On a sell, the input amount becomes
|
|
@@ -1103,14 +1242,14 @@ export declare class SwapComposer {
|
|
|
1103
1242
|
* @example
|
|
1104
1243
|
* ```typescript
|
|
1105
1244
|
* const router = new RouterClient({
|
|
1106
|
-
* apiKey: '
|
|
1245
|
+
* apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
1107
1246
|
* })
|
|
1108
1247
|
* ```
|
|
1109
1248
|
*
|
|
1110
1249
|
* @example
|
|
1111
1250
|
* ```typescript
|
|
1112
1251
|
* const router = new RouterClient({
|
|
1113
|
-
* apiKey: '
|
|
1252
|
+
* apiKey: 'hay_pk_4zhj33wahuxfplteyif5xpcgnm', // Free tier (60 requests/min)
|
|
1114
1253
|
* apiBaseUrl: 'https://hayrouter.txnlab.dev',
|
|
1115
1254
|
* algodUri: 'https://mainnet-api.4160.nodely.dev/',
|
|
1116
1255
|
* algodToken: '',
|
|
@@ -1314,6 +1453,15 @@ export declare class RouterClient {
|
|
|
1314
1453
|
signer: TransactionSigner | SignerFunction;
|
|
1315
1454
|
/** Optional note field for the user-signed input transaction (payment or asset transfer) */
|
|
1316
1455
|
note?: Uint8Array;
|
|
1456
|
+
/**
|
|
1457
|
+
* The kind of key `address` signs with. Defaults to the quote's
|
|
1458
|
+
* `signerType`: what `newQuote()` was asked for, or `'falcon'` when a
|
|
1459
|
+
* `fetchQuote()` response echoes it. Pass it with a `fetchQuote()`
|
|
1460
|
+
* response, which a router that doesn't support Falcon signers leaves
|
|
1461
|
+
* without it. For `'falcon'`, the composer adds the extra fees the
|
|
1462
|
+
* router's transactions don't include.
|
|
1463
|
+
*/
|
|
1464
|
+
signerType?: SignerType;
|
|
1317
1465
|
}): Promise<SwapComposer>;
|
|
1318
1466
|
/**
|
|
1319
1467
|
* Validates the API key
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants.ts","../src/types.ts","../src/middleware.ts","../src/composer.ts","../src/client.ts","../src/utils.ts"],"mappings":";;;;oBAGY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;qBAQW;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants.ts","../src/types.ts","../src/middleware.ts","../src/composer.ts","../src/client.ts","../src/utils.ts"],"mappings":";;;;oBAGY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;qBAQW;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;;;;qBAMA;;qBAGA;;;;iBC7CI;;WAEN;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;;;;;;;;WAUA;;;;;;;YAQC,SAAS,KACnB,SAAS;WAGA;WACA;;;;;YAMC;;;;;;;;;;;;;YAcA;;;;iBAKK;;WAEN;;WAGA;;WAGA;;WAGA,OAAO;;WAGP,6BAA6B;;WAG7B;;WAGA;;WAGA;;;;;;;;WASA;;;;;;;;;WAUA;;;;;;;;;;;;;;;WAgBA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;WA4Bb;;;;;iBAMM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;iBAMM;;WAEN;;WAEA,KAAK;;;;;iBAMC;;WAEN;;WAEA;;WAEA,IAAI;;WAEJ,KAAK;;;;;iBAMC;;WAEN;;WAEA,MAAM;;;;;iBAMA;;WAEN;;WAEA;;WAEA;;;;;iBAMM;;WAEN;;WAEA;;;;;;;iBAQM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;YAMC,kBAAkB,KAC5B;;WAIS;;WAEA;;WAEA;;;;;;;;;iBAUM;;WAEN;;WAEA;;WAEA;;;;;YAMC,sBAAsB,KAAK;WAC5B;WACA;;;;;iBAMM;;WAEN;;WAEA,QAAQ;;WAER;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,OAAO;;WAEP,gBAAgB;;WAEhB,QAAQ;;WAER;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