@txnlab/haystack-router 2.0.5 → 3.1.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 +39 -1
- package/dist/{debug-HbNpLAoU.mjs → debug-CIH6Nv9G.mjs} +4 -6
- package/dist/{debug-HbNpLAoU.mjs.map → debug-CIH6Nv9G.mjs.map} +1 -1
- package/dist/index.d.mts +158 -66
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +217 -86
- package/dist/index.mjs.map +1 -1
- package/dist/{logger-DUVOA2Oo.mjs → logger-BtesQ-um.mjs} +18 -28
- package/dist/{logger-DUVOA2Oo.mjs.map → logger-BtesQ-um.mjs.map} +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ TypeScript/JavaScript SDK for [Haystack Order Router](https://txnlab.gitbook.io/
|
|
|
26
26
|
npm install @txnlab/haystack-router algosdk
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
> **Note**: `algosdk` is a peer dependency and must be installed alongside `@txnlab/haystack-router`.
|
|
29
|
+
> **Note**: Requires Node.js 22 or later. `algosdk` is a peer dependency and must be installed alongside `@txnlab/haystack-router`.
|
|
30
30
|
|
|
31
31
|
## Quick Start
|
|
32
32
|
|
|
@@ -149,6 +149,41 @@ console.log('Input transaction ID:', inputTxId)
|
|
|
149
149
|
|
|
150
150
|
The `note` is applied only to the user-signed payment or asset transfer transaction (not pre-signed or middleware transactions). The transaction ID is available after calling `buildGroup()`, `sign()`, or `execute()`.
|
|
151
151
|
|
|
152
|
+
### Launch Tokens (Pre-Bonding)
|
|
153
|
+
|
|
154
|
+
API keys with launch-token access can swap any asset into or out of a HayLaunch token that is still on its bonding curve. Quote it like any other asset, as a `fixed-input` swap, and pass the same `slippage` you will execute with:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const quote = await router.newQuote({
|
|
158
|
+
fromASAID: 31566704, // USDC
|
|
159
|
+
toASAID: launchTokenAssetId, // pre-bonding launch token
|
|
160
|
+
amount: 10_000_000,
|
|
161
|
+
slippage: 1, // same value as newSwap() below
|
|
162
|
+
address: activeAddress,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (quote.launch) {
|
|
166
|
+
// quote.quote: launch tokens out (buy) or output asset (sell)
|
|
167
|
+
// quote.launch.bondingSurplus: bonding asset left in the wallet
|
|
168
|
+
// quote.launch.refund: bonding asset refunded when a buy completes bonding
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const swap = await router.newSwap({
|
|
172
|
+
quote,
|
|
173
|
+
address: activeAddress,
|
|
174
|
+
signer: transactionSigner,
|
|
175
|
+
slippage: 1,
|
|
176
|
+
})
|
|
177
|
+
await swap.execute()
|
|
178
|
+
|
|
179
|
+
const summary = swap.getSummary()
|
|
180
|
+
// summary.outputAmount: launch tokens credited (buy)
|
|
181
|
+
// summary.inputAmount: launch tokens sold (sell)
|
|
182
|
+
// summary.launch: the curve call's ID, bonding amount and refund
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
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.
|
|
186
|
+
|
|
152
187
|
### Transaction Signing
|
|
153
188
|
|
|
154
189
|
The SDK supports both standard `algosdk.TransactionSigner` and ARC-1 compliant signer functions.
|
|
@@ -409,6 +444,7 @@ async newQuote(params: FetchQuoteParams): Promise<SwapQuote>
|
|
|
409
444
|
| `maxGroupSize` | Maximum transactions in atomic group | `number` | `16` |
|
|
410
445
|
| `maxDepth` | Maximum swap hops | `number` | `4` |
|
|
411
446
|
| `optIn` | Override auto opt-in behavior | `boolean` | `undefined` |
|
|
447
|
+
| `slippage` | Slippage % you will execute with, in [0, 100); required for accurate launch token quotes | `number` | `undefined` |
|
|
412
448
|
|
|
413
449
|
#### RouterClient.newSwap()
|
|
414
450
|
|
|
@@ -450,6 +486,8 @@ Plain object returned by [`newQuote()`](#routerclientnewquote). Extends the raw
|
|
|
450
486
|
| `quote` | Quoted amount (coerced to `bigint`) | `bigint` |
|
|
451
487
|
| `amount` | Original request amount | `bigint` |
|
|
452
488
|
| `address` | User address (if provided) | `string \| undefined` |
|
|
489
|
+
| `slippage` | Slippage sent with the quote request (if provided) | `number \| undefined` |
|
|
490
|
+
| `launch` | Bonding-curve details for a pre-bonding launch token (amounts as `bigint`) | `SwapLaunchQuote \| undefined` |
|
|
453
491
|
| `createdAt` | Timestamp when quote was created | `number` |
|
|
454
492
|
|
|
455
493
|
**All properties from API response:**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as Logger } from "./logger-
|
|
2
|
-
|
|
3
|
-
//#region src/debug.ts
|
|
1
|
+
import { t as Logger } from "./logger-BtesQ-um.mjs";
|
|
2
|
+
// src/debug.ts
|
|
4
3
|
/**
|
|
5
4
|
* Debug utilities for swap execution failures
|
|
6
5
|
* @internal
|
|
@@ -33,7 +32,6 @@ function logSwapExecutionFailure(context, error) {
|
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
35
|
export { logSwapExecutionFailure };
|
|
39
|
-
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=debug-CIH6Nv9G.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-
|
|
1
|
+
{"version":3,"file":"debug-CIH6Nv9G.mjs","names":[],"sources":["../src/debug.ts"],"sourcesContent":["/**\n * Debug utilities for swap execution failures\n * @internal\n */\n\nimport { Logger } from './logger'\nimport type { SwapQuote, FetchQuoteResponse } from './types'\n\n/**\n * Context for swap execution debugging\n */\nexport interface SwapExecutionContext {\n quote: SwapQuote | FetchQuoteResponse\n address: string\n slippage: number\n transactionCount: number\n middlewareCount: number\n groupSize: number\n}\n\n/**\n * Log detailed context when a swap execution fails\n * Only logs when debug level is enabled\n */\nexport function logSwapExecutionFailure(\n context: SwapExecutionContext,\n error: unknown,\n): void {\n Logger.debug('Swap execution failed', {\n error: error instanceof Error ? error.message : String(error),\n quote: {\n fromASAID: context.quote.fromASAID,\n toASAID: context.quote.toASAID,\n type: context.quote.type,\n amount:\n 'amount' in context.quote ? context.quote.amount.toString() : undefined,\n quote: context.quote.quote.toString(),\n requiredAppOptIns: context.quote.requiredAppOptIns,\n route: context.quote.route?.map((r) => ({\n percentage: r.percentage,\n path: r.path.map((p) => p.name).join(' → '),\n })),\n },\n swap: {\n address: context.address,\n slippage: context.slippage,\n transactionCount: context.transactionCount,\n middlewareCount: context.middlewareCount,\n groupSize: context.groupSize,\n },\n })\n}\n"],"mappings":";;;;;;;;;;AAwBA,SAAgB,wBACd,SACA,OACM;CACN,OAAO,MAAM,yBAAyB;EACpC,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC5D,OAAO;GACL,WAAW,QAAQ,MAAM;GACzB,SAAS,QAAQ,MAAM;GACvB,MAAM,QAAQ,MAAM;GACpB,QACE,YAAY,QAAQ,QAAQ,QAAQ,MAAM,OAAO,SAAS,IAAI,KAAA;GAChE,OAAO,QAAQ,MAAM,MAAM,SAAS;GACpC,mBAAmB,QAAQ,MAAM;GACjC,OAAO,QAAQ,MAAM,OAAO,KAAK,OAAO;IACtC,YAAY,EAAE;IACd,MAAM,EAAE,KAAK,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK;GAC5C,EAAE;EACJ;EACA,MAAM;GACJ,SAAS,QAAQ;GACjB,UAAU,QAAQ;GAClB,kBAAkB,QAAQ;GAC1B,iBAAiB,QAAQ;GACzB,WAAW,QAAQ;EACrB;CACF,CAAC;AACH"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,51 +1,48 @@
|
|
|
1
1
|
import { ABIArgument, ABIMethod, ABIResult, Address, Algodv2, BoxReference, OnApplicationComplete, ResourceReference, SuggestedParams, Transaction, TransactionSigner, TransactionWithSigner } from "algosdk";
|
|
2
|
-
|
|
3
|
-
//#region src/constants.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Supported DEX protocols for swap routing
|
|
6
4
|
*/
|
|
7
|
-
declare enum Protocol {
|
|
5
|
+
export declare enum Protocol {
|
|
8
6
|
TinymanV2 = "TinymanV2",
|
|
7
|
+
Humble = "Humble",
|
|
9
8
|
Algofi = "Algofi",
|
|
10
9
|
Algomint = "Algomint",
|
|
11
10
|
Pact = "Pact",
|
|
12
11
|
Folks = "Folks",
|
|
13
|
-
TAlgo = "TAlgo"
|
|
12
|
+
TAlgo = "TAlgo"
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Deprecated protocols that are automatically excluded from routing
|
|
17
16
|
*
|
|
18
17
|
* @internal
|
|
19
18
|
*/
|
|
20
|
-
declare const DEPRECATED_PROTOCOLS: readonly ["
|
|
19
|
+
export declare const DEPRECATED_PROTOCOLS: readonly ["Tinyman"];
|
|
21
20
|
/** Default Algod node URI for mainnet */
|
|
22
|
-
declare const DEFAULT_ALGOD_URI = "https://mainnet-api.4160.nodely.dev/";
|
|
21
|
+
export declare const DEFAULT_ALGOD_URI = "https://mainnet-api.4160.nodely.dev/";
|
|
23
22
|
/** Default Algod node token (empty for public nodes) */
|
|
24
|
-
declare const DEFAULT_ALGOD_TOKEN = "";
|
|
23
|
+
export declare const DEFAULT_ALGOD_TOKEN = "";
|
|
25
24
|
/** Default Algod node port */
|
|
26
|
-
declare const DEFAULT_ALGOD_PORT = 443;
|
|
25
|
+
export declare const DEFAULT_ALGOD_PORT = 443;
|
|
27
26
|
/** Default Haystack Router API base URL */
|
|
28
|
-
declare const DEFAULT_API_BASE_URL = "https://hayrouter.txnlab.dev/api";
|
|
27
|
+
export declare const DEFAULT_API_BASE_URL = "https://hayrouter.txnlab.dev/api";
|
|
29
28
|
/** Default fee in basis points (0.10%) */
|
|
30
|
-
declare const DEFAULT_FEE_BPS = 10;
|
|
29
|
+
export declare const DEFAULT_FEE_BPS = 10;
|
|
31
30
|
/** Maximum allowed fee in basis points (3.00%) */
|
|
32
|
-
declare const MAX_FEE_BPS = 300;
|
|
31
|
+
export declare const MAX_FEE_BPS = 300;
|
|
33
32
|
/** Default maximum transaction group size */
|
|
34
|
-
declare const DEFAULT_MAX_GROUP_SIZE = 16;
|
|
33
|
+
export declare const DEFAULT_MAX_GROUP_SIZE = 16;
|
|
35
34
|
/** Default maximum routing depth (number of hops) */
|
|
36
|
-
declare const DEFAULT_MAX_DEPTH = 4;
|
|
35
|
+
export declare const DEFAULT_MAX_DEPTH = 4;
|
|
37
36
|
/** Default auto opt-in setting (automatic asset/app opt-in detection) */
|
|
38
|
-
declare const DEFAULT_AUTO_OPT_IN = false;
|
|
37
|
+
export declare const DEFAULT_AUTO_OPT_IN = false;
|
|
39
38
|
/** Default debug level (no debug logging) */
|
|
40
|
-
declare const DEFAULT_DEBUG_LEVEL: "none";
|
|
39
|
+
export declare const DEFAULT_DEBUG_LEVEL: "none";
|
|
41
40
|
/** Default number of rounds to wait for transaction confirmation */
|
|
42
|
-
declare const DEFAULT_CONFIRMATION_ROUNDS = 10;
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/types.d.ts
|
|
41
|
+
export declare const DEFAULT_CONFIRMATION_ROUNDS = 10;
|
|
45
42
|
/**
|
|
46
43
|
* Configuration parameters for initializing RouterClient
|
|
47
44
|
*/
|
|
48
|
-
interface ConfigParams {
|
|
45
|
+
export interface ConfigParams {
|
|
49
46
|
/** API key for Haystack Router API (required) */
|
|
50
47
|
readonly apiKey: string;
|
|
51
48
|
/** Base URL for the Haystack Router API (default: https://hayrouter.txnlab.dev) */
|
|
@@ -77,18 +74,18 @@ interface ConfigParams {
|
|
|
77
74
|
*
|
|
78
75
|
* @internal
|
|
79
76
|
*/
|
|
80
|
-
type Config = Omit<Required<ConfigParams>, 'referrerAddress' | 'debugLevel'> & {
|
|
77
|
+
export type Config = Omit<Required<ConfigParams>, 'referrerAddress' | 'debugLevel'> & {
|
|
81
78
|
readonly referrerAddress: string | undefined;
|
|
82
79
|
readonly debugLevel: 'none' | 'info' | 'debug' | 'trace';
|
|
83
80
|
};
|
|
84
81
|
/**
|
|
85
82
|
* Swap quote type determining which amount is fixed
|
|
86
83
|
*/
|
|
87
|
-
type QuoteType = 'fixed-input' | 'fixed-output';
|
|
84
|
+
export type QuoteType = 'fixed-input' | 'fixed-output';
|
|
88
85
|
/**
|
|
89
86
|
* Parameters for requesting a swap quote from the Haystack Router API (raw API method)
|
|
90
87
|
*/
|
|
91
|
-
interface FetchQuoteParams {
|
|
88
|
+
export interface FetchQuoteParams {
|
|
92
89
|
/** Input asset ID */
|
|
93
90
|
readonly fromASAID: bigint | number;
|
|
94
91
|
/** Output asset ID */
|
|
@@ -107,6 +104,15 @@ interface FetchQuoteParams {
|
|
|
107
104
|
readonly optIn?: boolean;
|
|
108
105
|
/** Address of the account that will perform the swap (required if autoOptIn is enabled) */
|
|
109
106
|
readonly address?: string | null;
|
|
107
|
+
/**
|
|
108
|
+
* Slippage tolerance as a percentage (e.g., 1 for 1%), in [0, 100)
|
|
109
|
+
*
|
|
110
|
+
* Pass the same value you will pass to `newSwap()`. Quotes for pre-bonding
|
|
111
|
+
* HayLaunch tokens use it to price the bonding curve on the amount the route
|
|
112
|
+
* actually pays it; without it, those quotes overstate the output by about
|
|
113
|
+
* the slippage. Other quotes ignore it.
|
|
114
|
+
*/
|
|
115
|
+
readonly slippage?: number;
|
|
110
116
|
/**
|
|
111
117
|
* ⚠️ **ADVANCED USE ONLY - NON-COMPOSABLE SWAPS** ⚠️
|
|
112
118
|
*
|
|
@@ -138,7 +144,7 @@ interface FetchQuoteParams {
|
|
|
138
144
|
/**
|
|
139
145
|
* Asset information from the Haystack Router API
|
|
140
146
|
*/
|
|
141
|
-
interface Asset {
|
|
147
|
+
export interface Asset {
|
|
142
148
|
/** Asset ID */
|
|
143
149
|
readonly id: number;
|
|
144
150
|
/** Number of decimal places */
|
|
@@ -155,7 +161,7 @@ interface Asset {
|
|
|
155
161
|
/**
|
|
156
162
|
* Profit information for a swap
|
|
157
163
|
*/
|
|
158
|
-
interface Profit {
|
|
164
|
+
export interface Profit {
|
|
159
165
|
/** Profit amount in base units */
|
|
160
166
|
readonly amount: number;
|
|
161
167
|
/** The asset in which profit is denominated */
|
|
@@ -164,7 +170,7 @@ interface Profit {
|
|
|
164
170
|
/**
|
|
165
171
|
* A single step in a swap route path
|
|
166
172
|
*/
|
|
167
|
-
interface PathElement {
|
|
173
|
+
export interface PathElement {
|
|
168
174
|
/** Protocol name and fee tier */
|
|
169
175
|
readonly name: string;
|
|
170
176
|
/** Protocol class identifier */
|
|
@@ -177,7 +183,7 @@ interface PathElement {
|
|
|
177
183
|
/**
|
|
178
184
|
* A route with its percentage of the total swap amount
|
|
179
185
|
*/
|
|
180
|
-
interface Route {
|
|
186
|
+
export interface Route {
|
|
181
187
|
/** Percentage of total swap amount routed through this path */
|
|
182
188
|
readonly percentage: number;
|
|
183
189
|
/** The sequence of swaps in this route */
|
|
@@ -186,7 +192,7 @@ interface Route {
|
|
|
186
192
|
/**
|
|
187
193
|
* Quote from a specific DEX protocol
|
|
188
194
|
*/
|
|
189
|
-
interface DexQuote {
|
|
195
|
+
export interface DexQuote {
|
|
190
196
|
/** Protocol name and fee tier */
|
|
191
197
|
readonly name: string;
|
|
192
198
|
/** Protocol class */
|
|
@@ -197,16 +203,46 @@ interface DexQuote {
|
|
|
197
203
|
/**
|
|
198
204
|
* Encrypted transaction payload from the quote
|
|
199
205
|
*/
|
|
200
|
-
interface TxnPayload {
|
|
206
|
+
export interface TxnPayload {
|
|
201
207
|
/** Initialization vector for decryption */
|
|
202
208
|
readonly iv: string;
|
|
203
209
|
/** Encrypted transaction data */
|
|
204
210
|
readonly data: string;
|
|
205
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Bonding-curve details for a quote that buys or sells a pre-bonding HayLaunch token
|
|
214
|
+
*
|
|
215
|
+
* Amounts are in base units of the bonding asset.
|
|
216
|
+
*/
|
|
217
|
+
export interface LaunchQuote {
|
|
218
|
+
/** `'buy'` when the launch token is the output, `'sell'` when it is the input */
|
|
219
|
+
readonly side: 'buy' | 'sell';
|
|
220
|
+
/** HayLaunch token number */
|
|
221
|
+
readonly tokenNum: number;
|
|
222
|
+
/** Asset the token is bonded in (0 for ALGO) */
|
|
223
|
+
readonly bondingTokenId: number;
|
|
224
|
+
/** Bonding asset expected to be left in the wallet after the trade */
|
|
225
|
+
readonly bondingSurplus: number;
|
|
226
|
+
/** Bonding asset refunded when a buy completes bonding (omitted otherwise) */
|
|
227
|
+
readonly refund?: number;
|
|
228
|
+
/** Whether a buy completes bonding (omitted otherwise) */
|
|
229
|
+
readonly graduates?: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Normalized bonding-curve details on a SwapQuote, with amounts coerced to bigint
|
|
233
|
+
*/
|
|
234
|
+
export type SwapLaunchQuote = Omit<LaunchQuote, 'bondingSurplus' | 'refund' | 'graduates'> & {
|
|
235
|
+
/** Bonding asset expected to be left in the wallet after the trade */
|
|
236
|
+
readonly bondingSurplus: bigint;
|
|
237
|
+
/** Bonding asset refunded when a buy completes bonding (0n otherwise) */
|
|
238
|
+
readonly refund: bigint;
|
|
239
|
+
/** Whether a buy completes bonding */
|
|
240
|
+
readonly graduates: boolean;
|
|
241
|
+
};
|
|
206
242
|
/**
|
|
207
243
|
* Quote response from the Haystack Router API
|
|
208
244
|
*/
|
|
209
|
-
interface FetchQuoteResponse {
|
|
245
|
+
export interface FetchQuoteResponse {
|
|
210
246
|
/** The quoted output amount or input amount (depending on quote type) */
|
|
211
247
|
readonly quote: string | number;
|
|
212
248
|
/** Profit information for the swap */
|
|
@@ -241,13 +277,18 @@ interface FetchQuoteResponse {
|
|
|
241
277
|
readonly type: string;
|
|
242
278
|
/** Performance timing data */
|
|
243
279
|
readonly timing?: unknown;
|
|
280
|
+
/**
|
|
281
|
+
* Bonding-curve details, present only when one side is a pre-bonding HayLaunch token.
|
|
282
|
+
* For a buy, `quote` is launch tokens out; for a sell, it is the output asset.
|
|
283
|
+
*/
|
|
284
|
+
readonly launch?: LaunchQuote;
|
|
244
285
|
}
|
|
245
286
|
/**
|
|
246
287
|
* Enhanced quote result returned by RouterClient.newQuote()
|
|
247
288
|
*
|
|
248
289
|
* Extends the raw API response with additional metadata and type normalization.
|
|
249
290
|
*/
|
|
250
|
-
type SwapQuote = Omit<FetchQuoteResponse, 'quote'> & {
|
|
291
|
+
export type SwapQuote = Omit<FetchQuoteResponse, 'quote' | 'launch'> & {
|
|
251
292
|
/**
|
|
252
293
|
* The quoted output amount or input amount (coerced to bigint)
|
|
253
294
|
*
|
|
@@ -259,13 +300,17 @@ type SwapQuote = Omit<FetchQuoteResponse, 'quote'> & {
|
|
|
259
300
|
readonly amount: bigint;
|
|
260
301
|
/** The address parameter from the quote request (if provided) */
|
|
261
302
|
readonly address?: string;
|
|
303
|
+
/** The slippage sent with the quote request (if provided) */
|
|
304
|
+
readonly slippage?: number;
|
|
305
|
+
/** Bonding-curve details, present only when one side is a pre-bonding HayLaunch token */
|
|
306
|
+
readonly launch?: SwapLaunchQuote;
|
|
262
307
|
/** Timestamp when the quote was created (in milliseconds) */
|
|
263
308
|
readonly createdAt: number;
|
|
264
309
|
};
|
|
265
310
|
/**
|
|
266
311
|
* Transaction signature from the Haystack Router API
|
|
267
312
|
*/
|
|
268
|
-
interface Signature {
|
|
313
|
+
export interface Signature {
|
|
269
314
|
/** Signature type */
|
|
270
315
|
readonly type: 'logic_signature' | 'secret_key';
|
|
271
316
|
/** Signature data */
|
|
@@ -274,7 +319,7 @@ interface Signature {
|
|
|
274
319
|
/**
|
|
275
320
|
* Transaction data from the Haystack Router API
|
|
276
321
|
*/
|
|
277
|
-
interface SwapTransaction {
|
|
322
|
+
export interface SwapTransaction {
|
|
278
323
|
/** Base64-encoded transaction data */
|
|
279
324
|
readonly data: string;
|
|
280
325
|
/** Group ID for the transaction */
|
|
@@ -287,7 +332,7 @@ interface SwapTransaction {
|
|
|
287
332
|
/**
|
|
288
333
|
* Parameters for fetching executable swap transactions
|
|
289
334
|
*/
|
|
290
|
-
interface FetchSwapTxnsParams {
|
|
335
|
+
export interface FetchSwapTxnsParams {
|
|
291
336
|
/** Quote response from fetchQuote() or newQuote() */
|
|
292
337
|
readonly quote: FetchQuoteResponse | SwapQuote;
|
|
293
338
|
/** Algorand address that will sign the transactions */
|
|
@@ -300,7 +345,7 @@ interface FetchSwapTxnsParams {
|
|
|
300
345
|
*
|
|
301
346
|
* @internal
|
|
302
347
|
*/
|
|
303
|
-
interface FetchSwapTxnsBody {
|
|
348
|
+
export interface FetchSwapTxnsBody {
|
|
304
349
|
/** API key for authentication */
|
|
305
350
|
readonly apiKey: string;
|
|
306
351
|
/** Address of the account that will sign the transactions */
|
|
@@ -313,24 +358,49 @@ interface FetchSwapTxnsBody {
|
|
|
313
358
|
/**
|
|
314
359
|
* Response from fetching swap transactions
|
|
315
360
|
*/
|
|
316
|
-
interface FetchSwapTxnsResponse {
|
|
361
|
+
export interface FetchSwapTxnsResponse {
|
|
317
362
|
/** Array of transaction data */
|
|
318
363
|
readonly txns: SwapTransaction[];
|
|
319
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Bonding-curve leg of an executed pre-bonding HayLaunch swap
|
|
367
|
+
*/
|
|
368
|
+
export interface LaunchSummary {
|
|
369
|
+
/** `'buy'` when the launch token was the output, `'sell'` when it was the input */
|
|
370
|
+
side: 'buy' | 'sell';
|
|
371
|
+
/** HayLaunch token number */
|
|
372
|
+
tokenNum: bigint;
|
|
373
|
+
/** Transaction ID of the curve buy or sell call */
|
|
374
|
+
curveTxnId: string;
|
|
375
|
+
/**
|
|
376
|
+
* Bonding asset that went through the curve, in base units: the payment into
|
|
377
|
+
* the curve on a buy, or the curve's payout on a sell. Undefined if it
|
|
378
|
+
* couldn't be determined.
|
|
379
|
+
*/
|
|
380
|
+
bondingAmount?: bigint;
|
|
381
|
+
/** Bonding asset refunded by a buy that completed bonding (0n otherwise) */
|
|
382
|
+
refund: bigint;
|
|
383
|
+
}
|
|
320
384
|
/**
|
|
321
385
|
* Summary of a swap transaction group after execution
|
|
322
386
|
*
|
|
323
387
|
* Contains the exact input/output amounts and total transaction fees.
|
|
324
388
|
* Only available after calling execute() on a SwapComposer instance.
|
|
325
389
|
*/
|
|
326
|
-
interface SwapSummary {
|
|
390
|
+
export interface SwapSummary {
|
|
327
391
|
/** Input asset ID (0 for ALGO) */
|
|
328
392
|
inputAssetId: bigint;
|
|
329
393
|
/** Output asset ID (0 for ALGO) */
|
|
330
394
|
outputAssetId: bigint;
|
|
331
|
-
/**
|
|
395
|
+
/**
|
|
396
|
+
* Exact input amount in base units, from the user-signed transaction.
|
|
397
|
+
* For a launch sell, the launch tokens sold.
|
|
398
|
+
*/
|
|
332
399
|
inputAmount: bigint;
|
|
333
|
-
/**
|
|
400
|
+
/**
|
|
401
|
+
* Exact output amount received in base units, from the inner transaction.
|
|
402
|
+
* For a launch buy, the launch tokens credited by the curve.
|
|
403
|
+
*/
|
|
334
404
|
outputAmount: bigint;
|
|
335
405
|
/** Quote type */
|
|
336
406
|
type: QuoteType;
|
|
@@ -338,19 +408,27 @@ interface SwapSummary {
|
|
|
338
408
|
totalFees: bigint;
|
|
339
409
|
/** Number of transactions in the group */
|
|
340
410
|
transactionCount: number;
|
|
341
|
-
/**
|
|
411
|
+
/**
|
|
412
|
+
* Transaction ID of the user-signed input transaction (payment/asset transfer).
|
|
413
|
+
* For a launch sell, the curve sell call.
|
|
414
|
+
*/
|
|
342
415
|
inputTxnId: string;
|
|
343
|
-
/**
|
|
416
|
+
/**
|
|
417
|
+
* Transaction ID of the app call containing the output transfer as an inner transaction.
|
|
418
|
+
* For a launch buy, the curve buy call.
|
|
419
|
+
*/
|
|
344
420
|
outputTxnId: string;
|
|
345
421
|
/** Address that sent the input asset (the user) */
|
|
346
422
|
inputSender: string;
|
|
347
|
-
/** Address that sent the output asset to the user */
|
|
423
|
+
/** Address that sent the output asset to the user (the HayLaunch app on a launch buy) */
|
|
348
424
|
outputSender: string;
|
|
425
|
+
/** Bonding-curve details, present only for a pre-bonding HayLaunch swap */
|
|
426
|
+
launch?: LaunchSummary;
|
|
349
427
|
}
|
|
350
428
|
/**
|
|
351
429
|
* Method call to be executed as part of the swap
|
|
352
430
|
*/
|
|
353
|
-
interface MethodCall {
|
|
431
|
+
export interface MethodCall {
|
|
354
432
|
/** The ID of the smart contract to call. Set this to 0 to indicate an application creation call. */
|
|
355
433
|
appID: number | bigint;
|
|
356
434
|
/** The method to call on the smart contract */
|
|
@@ -398,12 +476,10 @@ interface MethodCall {
|
|
|
398
476
|
/** A transaction signer that can authorize this application call from sender */
|
|
399
477
|
signer?: TransactionSigner;
|
|
400
478
|
}
|
|
401
|
-
//#endregion
|
|
402
|
-
//#region src/middleware.d.ts
|
|
403
479
|
/**
|
|
404
480
|
* Context provided to middleware shouldApply hook
|
|
405
481
|
*/
|
|
406
|
-
interface QuoteContext {
|
|
482
|
+
export interface QuoteContext {
|
|
407
483
|
/** Input asset ID (always bigint for precision and future-proofing) */
|
|
408
484
|
readonly fromASAID: bigint;
|
|
409
485
|
/** Output asset ID (always bigint for precision and future-proofing) */
|
|
@@ -420,7 +496,7 @@ interface QuoteContext {
|
|
|
420
496
|
/**
|
|
421
497
|
* Context provided to middleware hooks during swap composition
|
|
422
498
|
*/
|
|
423
|
-
interface SwapContext {
|
|
499
|
+
export interface SwapContext {
|
|
424
500
|
/** The quote result from newQuote() */
|
|
425
501
|
readonly quote: SwapQuote;
|
|
426
502
|
/** The address of the account performing the swap */
|
|
@@ -470,7 +546,7 @@ interface SwapContext {
|
|
|
470
546
|
* }
|
|
471
547
|
* ```
|
|
472
548
|
*/
|
|
473
|
-
interface SwapMiddleware {
|
|
549
|
+
export interface SwapMiddleware {
|
|
474
550
|
/** Unique identifier for the middleware */
|
|
475
551
|
readonly name: string;
|
|
476
552
|
/** Semantic version of the middleware */
|
|
@@ -619,7 +695,7 @@ interface SwapMiddleware {
|
|
|
619
695
|
/**
|
|
620
696
|
* Configuration options for AutoOptOutMiddleware
|
|
621
697
|
*/
|
|
622
|
-
interface AutoOptOutConfig {
|
|
698
|
+
export interface AutoOptOutConfig {
|
|
623
699
|
/**
|
|
624
700
|
* Array of asset IDs that should be excluded from automatic opt-out behavior
|
|
625
701
|
* @default []
|
|
@@ -653,7 +729,7 @@ interface AutoOptOutConfig {
|
|
|
653
729
|
* })
|
|
654
730
|
* ```
|
|
655
731
|
*/
|
|
656
|
-
declare class AutoOptOutMiddleware implements SwapMiddleware {
|
|
732
|
+
export declare class AutoOptOutMiddleware implements SwapMiddleware {
|
|
657
733
|
readonly name = "AutoOptOut";
|
|
658
734
|
readonly version = "1.0.0";
|
|
659
735
|
private readonly excludedAssets;
|
|
@@ -662,8 +738,6 @@ declare class AutoOptOutMiddleware implements SwapMiddleware {
|
|
|
662
738
|
adjustQuoteParams(params: FetchQuoteParams): Promise<FetchQuoteParams>;
|
|
663
739
|
afterSwap(context: SwapContext): Promise<TransactionWithSigner[]>;
|
|
664
740
|
}
|
|
665
|
-
//#endregion
|
|
666
|
-
//#region src/composer.d.ts
|
|
667
741
|
/**
|
|
668
742
|
* A transaction signer function that supports both standard algosdk.TransactionSigner
|
|
669
743
|
* and ARC-1 compliant signers that may return null for unsigned transactions.
|
|
@@ -672,11 +746,11 @@ declare class AutoOptOutMiddleware implements SwapMiddleware {
|
|
|
672
746
|
* @param indexesToSign - Array of indexes indicating which transactions need signing
|
|
673
747
|
* @returns Array of signed transactions (may include nulls for ARC-1 compliant wallets)
|
|
674
748
|
*/
|
|
675
|
-
type SignerFunction = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<(Uint8Array | null)[]>;
|
|
749
|
+
export type SignerFunction = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<(Uint8Array | null)[]>;
|
|
676
750
|
/**
|
|
677
751
|
* Status of the SwapComposer transaction group lifecycle
|
|
678
752
|
*/
|
|
679
|
-
declare enum SwapComposerStatus {
|
|
753
|
+
export declare enum SwapComposerStatus {
|
|
680
754
|
/** The atomic group is still under construction. */
|
|
681
755
|
BUILDING = 0,
|
|
682
756
|
/** The atomic group has been finalized, but not yet signed. */
|
|
@@ -686,12 +760,12 @@ declare enum SwapComposerStatus {
|
|
|
686
760
|
/** The atomic group has been finalized, signed, and submitted to the network. */
|
|
687
761
|
SUBMITTED = 3,
|
|
688
762
|
/** The atomic group has been finalized, signed, submitted, and successfully committed to a block. */
|
|
689
|
-
COMMITTED = 4
|
|
763
|
+
COMMITTED = 4
|
|
690
764
|
}
|
|
691
765
|
/**
|
|
692
766
|
* Configuration for creating a SwapComposer instance
|
|
693
767
|
*/
|
|
694
|
-
interface SwapComposerConfig {
|
|
768
|
+
export interface SwapComposerConfig {
|
|
695
769
|
/** The quote response from fetchQuote() or newQuote() */
|
|
696
770
|
readonly quote: FetchQuoteResponse | SwapQuote;
|
|
697
771
|
/** The swap transactions from fetchSwapTransactions() */
|
|
@@ -727,7 +801,7 @@ interface SwapComposerConfig {
|
|
|
727
801
|
* .execute()
|
|
728
802
|
* ```
|
|
729
803
|
*/
|
|
730
|
-
declare class SwapComposer {
|
|
804
|
+
export declare class SwapComposer {
|
|
731
805
|
/** The ATC used to compose the group */
|
|
732
806
|
private atc;
|
|
733
807
|
/** The maximum size of an atomic transaction group. */
|
|
@@ -744,6 +818,7 @@ declare class SwapComposer {
|
|
|
744
818
|
private readonly note?;
|
|
745
819
|
private inputTransactionIndex?;
|
|
746
820
|
private outputTransactionIndex?;
|
|
821
|
+
private curveTransactionIndex?;
|
|
747
822
|
/** Summary data built incrementally during swap composition */
|
|
748
823
|
private summaryData?;
|
|
749
824
|
/**
|
|
@@ -961,6 +1036,21 @@ declare class SwapComposer {
|
|
|
961
1036
|
* Also initializes summaryData with input transaction details and output transaction ID
|
|
962
1037
|
*/
|
|
963
1038
|
private processSwapTransactions;
|
|
1039
|
+
/**
|
|
1040
|
+
* Finds the swap's input transaction: the user's payment or asset transfer
|
|
1041
|
+
* to the router app, whose address comes from the router's pre-signed app
|
|
1042
|
+
* calls. Falls back to the last user-signed transaction for groups without
|
|
1043
|
+
* a router app call.
|
|
1044
|
+
*/
|
|
1045
|
+
private findInputTransactionIndex;
|
|
1046
|
+
/**
|
|
1047
|
+
* For a launch quote, finds the user-signed curve buy or sell call and
|
|
1048
|
+
* records the curve leg in summaryData. On a sell, the input amount becomes
|
|
1049
|
+
* the launch tokens sold.
|
|
1050
|
+
*
|
|
1051
|
+
* @returns The curve call's index within the swap transactions, if found
|
|
1052
|
+
*/
|
|
1053
|
+
private initLaunchSummary;
|
|
964
1054
|
/**
|
|
965
1055
|
* Creates opt-in transactions for apps the user hasn't opted into yet
|
|
966
1056
|
*/
|
|
@@ -985,12 +1075,12 @@ declare class SwapComposer {
|
|
|
985
1075
|
* Extract the actual output amount from the confirmed output transaction's inner transactions
|
|
986
1076
|
*
|
|
987
1077
|
* Analyzes only the output transaction (last app call in the swap) to find the
|
|
988
|
-
* inner transaction that transfers the output asset to the user.
|
|
1078
|
+
* inner transaction that transfers the output asset to the user. On a launch
|
|
1079
|
+
* buy the output is a balance on the HayLaunch app, so it is read from the
|
|
1080
|
+
* curve buy call's return value instead.
|
|
989
1081
|
*/
|
|
990
1082
|
private extractActualOutputAmount;
|
|
991
1083
|
}
|
|
992
|
-
//#endregion
|
|
993
|
-
//#region src/client.d.ts
|
|
994
1084
|
/**
|
|
995
1085
|
* Client for interacting with the Haystack order router API
|
|
996
1086
|
*
|
|
@@ -1019,7 +1109,7 @@ declare class SwapComposer {
|
|
|
1019
1109
|
* })
|
|
1020
1110
|
* ```
|
|
1021
1111
|
*/
|
|
1022
|
-
declare class RouterClient {
|
|
1112
|
+
export declare class RouterClient {
|
|
1023
1113
|
private readonly config;
|
|
1024
1114
|
private readonly algodClient;
|
|
1025
1115
|
private readonly middleware;
|
|
@@ -1060,6 +1150,7 @@ declare class RouterClient {
|
|
|
1060
1150
|
* - If true: API reduces maxGroupSize by 1 and includes opt-in (always included, even if not needed)
|
|
1061
1151
|
* - If false: No opt-in transaction included
|
|
1062
1152
|
* - If undefined: Falls back to `config.autoOptIn` behavior with account check (if `params.address` is provided)
|
|
1153
|
+
* @param params.slippage - Slippage tolerance as a percentage, in [0, 100). Pass the value you will execute with; required for accurate pre-bonding launch token quotes
|
|
1063
1154
|
* @returns A FetchQuoteResponse object with routing information
|
|
1064
1155
|
*
|
|
1065
1156
|
* @example
|
|
@@ -1130,6 +1221,7 @@ declare class RouterClient {
|
|
|
1130
1221
|
* @param params.maxDepth - The maximum depth (default: 4)
|
|
1131
1222
|
* @param params.address - The address of the account that will perform the swap (recommended when using `config.autoOptIn` or `params.optIn`)
|
|
1132
1223
|
* @param params.optIn - Whether to include asset opt-in transaction
|
|
1224
|
+
* @param params.slippage - Slippage tolerance as a percentage, in [0, 100). Pass the value you will execute with; required for accurate pre-bonding launch token quotes
|
|
1133
1225
|
* @returns A SwapQuote enhanced quote result
|
|
1134
1226
|
*
|
|
1135
1227
|
* @example
|
|
@@ -1213,17 +1305,19 @@ declare class RouterClient {
|
|
|
1213
1305
|
* Validates an Algorand address
|
|
1214
1306
|
*/
|
|
1215
1307
|
private validateAddress;
|
|
1308
|
+
/**
|
|
1309
|
+
* Validates a slippage percentage (0 <= slippage < 100)
|
|
1310
|
+
*/
|
|
1311
|
+
private validateSlippage;
|
|
1216
1312
|
/**
|
|
1217
1313
|
* Validates the fee in basis points (max 300 = 3.00%)
|
|
1218
1314
|
*/
|
|
1219
1315
|
private validateFeeBps;
|
|
1220
1316
|
}
|
|
1221
|
-
//#endregion
|
|
1222
|
-
//#region src/utils.d.ts
|
|
1223
1317
|
/**
|
|
1224
1318
|
* HTTP error with status code and response data
|
|
1225
1319
|
*/
|
|
1226
|
-
declare class HTTPError extends Error {
|
|
1320
|
+
export declare class HTTPError extends Error {
|
|
1227
1321
|
status: number;
|
|
1228
1322
|
statusText: string;
|
|
1229
1323
|
data: unknown;
|
|
@@ -1240,7 +1334,5 @@ declare class HTTPError extends Error {
|
|
|
1240
1334
|
* @returns Parsed JSON response
|
|
1241
1335
|
* @throws HTTPError if the response status is not ok
|
|
1242
1336
|
*/
|
|
1243
|
-
declare function request<T>(url: string, options?: RequestInit): Promise<T>;
|
|
1244
|
-
//#endregion
|
|
1245
|
-
export { Asset, AutoOptOutConfig, AutoOptOutMiddleware, Config, ConfigParams, DEFAULT_ALGOD_PORT, DEFAULT_ALGOD_TOKEN, DEFAULT_ALGOD_URI, DEFAULT_API_BASE_URL, DEFAULT_AUTO_OPT_IN, DEFAULT_CONFIRMATION_ROUNDS, DEFAULT_DEBUG_LEVEL, DEFAULT_FEE_BPS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_GROUP_SIZE, DEPRECATED_PROTOCOLS, DexQuote, FetchQuoteParams, FetchQuoteResponse, FetchSwapTxnsBody, FetchSwapTxnsParams, FetchSwapTxnsResponse, HTTPError, MAX_FEE_BPS, MethodCall, PathElement, Profit, Protocol, QuoteContext, QuoteType, Route, RouterClient, Signature, SignerFunction, SwapComposer, SwapComposerConfig, SwapComposerStatus, SwapContext, SwapMiddleware, SwapQuote, SwapSummary, SwapTransaction, TxnPayload, request };
|
|
1337
|
+
export declare function request<T>(url: string, options?: RequestInit): Promise<T>;
|
|
1246
1338
|
//# sourceMappingURL=index.d.mts.map
|