@txnlab/deflex 1.1.0 → 1.2.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 +37 -20
- package/dist/index.d.ts +104 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +99 -81
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Deflex SDK
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@txnlab/deflex)
|
|
4
|
+
[](https://bundlejs.com/?q=%40txnlab%2Fdeflex%40latest&treeshake=%5B*%5D)
|
|
5
|
+
[](https://github.com/TxnLab/deflex-js/actions/workflows/ci.yml)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
3
9
|
TypeScript/JavaScript SDK for [Deflex Order Router](https://txnlab.gitbook.io/deflex-api) - smart order routing and DEX aggregation on Algorand.
|
|
4
10
|
|
|
5
11
|
## Prerequisites
|
|
@@ -174,6 +180,7 @@ await swap.execute()
|
|
|
174
180
|
```
|
|
175
181
|
|
|
176
182
|
The signer function supports two return patterns:
|
|
183
|
+
|
|
177
184
|
- **Pattern 1** (Pera, Defly, algosdk): Returns only the signed transactions as `Uint8Array[]`
|
|
178
185
|
- **Pattern 2** (Lute, ARC-1 compliant): Returns an array matching the transaction group length with `null` for unsigned transactions as `(Uint8Array | null)[]`
|
|
179
186
|
|
|
@@ -181,17 +188,25 @@ Both patterns are automatically handled by the SDK.
|
|
|
181
188
|
|
|
182
189
|
### Advanced Transaction Composition
|
|
183
190
|
|
|
184
|
-
Build the transaction group by adding custom transactions before or after the swap using the [`SwapComposer`](#swapcomposer) instance:
|
|
191
|
+
Build the transaction group by adding custom transactions and ABI method calls before or after the swap using the [`SwapComposer`](#swapcomposer) instance:
|
|
185
192
|
|
|
186
193
|
```typescript
|
|
187
|
-
import { Transaction } from 'algosdk'
|
|
194
|
+
import { ABIMethod, Transaction } from 'algosdk'
|
|
188
195
|
import { useWallet } from '@txnlab/use-wallet-*' // react, vue, solid, or svelte
|
|
189
196
|
|
|
190
197
|
const { activeAddress, transactionSigner } = useWallet()
|
|
191
198
|
|
|
192
199
|
// Create your custom transactions
|
|
193
|
-
const
|
|
194
|
-
|
|
200
|
+
const customTxn = new Transaction({...})
|
|
201
|
+
|
|
202
|
+
// Define an ABI method call
|
|
203
|
+
const methodCall = {
|
|
204
|
+
appID: 123456,
|
|
205
|
+
method: new ABIMethod({...}),
|
|
206
|
+
methodArgs: [...],
|
|
207
|
+
sender: activeAddress,
|
|
208
|
+
suggestedParams: await algodClient.getTransactionParams().do(),
|
|
209
|
+
}
|
|
195
210
|
|
|
196
211
|
// Build and execute the transaction group
|
|
197
212
|
const swap = await deflex.newSwap({
|
|
@@ -202,9 +217,9 @@ const swap = await deflex.newSwap({
|
|
|
202
217
|
})
|
|
203
218
|
|
|
204
219
|
const result = await swap
|
|
205
|
-
.addTransaction(
|
|
220
|
+
.addTransaction(customTxn) // Add transaction before swap
|
|
206
221
|
.addSwapTransactions() // Add swap transactions
|
|
207
|
-
.
|
|
222
|
+
.addMethodCall(methodCall) // Add ABI method call after swap
|
|
208
223
|
.execute() // Sign and execute entire group
|
|
209
224
|
```
|
|
210
225
|
|
|
@@ -310,11 +325,11 @@ Returns a [`SwapComposer`](#swapcomposer) instance for building and executing sw
|
|
|
310
325
|
async newSwap(config: SwapComposerConfig): Promise<SwapComposer>
|
|
311
326
|
```
|
|
312
327
|
|
|
313
|
-
| Parameter | Description | Type
|
|
314
|
-
| ---------- | ------------------------------------------------- |
|
|
315
|
-
| `quote` | Quote result or raw API response | `DeflexQuote \| FetchQuoteResponse`
|
|
316
|
-
| `address` | Signer address | `string`
|
|
317
|
-
| `slippage` | Slippage tolerance as percentage (e.g., 1 for 1%) | `number`
|
|
328
|
+
| Parameter | Description | Type |
|
|
329
|
+
| ---------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
330
|
+
| `quote` | Quote result or raw API response | `DeflexQuote \| FetchQuoteResponse` |
|
|
331
|
+
| `address` | Signer address | `string` |
|
|
332
|
+
| `slippage` | Slippage tolerance as percentage (e.g., 1 for 1%) | `number` |
|
|
318
333
|
| `signer` | Transaction signer function | `algosdk.TransactionSigner \| ((txnGroup: Transaction[], indexesToSign: number[]) => Promise<(Uint8Array \| null)[]>)` |
|
|
319
334
|
|
|
320
335
|
#### DeflexClient.needsAssetOptIn()
|
|
@@ -368,15 +383,17 @@ Plain object returned by [`newQuote()`](#deflexclientnewquote). Extends the raw
|
|
|
368
383
|
|
|
369
384
|
Builder for constructing and executing atomic swap transaction groups, returned by [`newSwap()`](#deflexclientnewswap).
|
|
370
385
|
|
|
371
|
-
| Method
|
|
372
|
-
|
|
|
373
|
-
| `addTransaction(transaction)` | Add a transaction to the atomic group | `transaction: algosdk.Transaction` | `SwapComposer`
|
|
374
|
-
| `
|
|
375
|
-
| `
|
|
376
|
-
| `
|
|
377
|
-
| `
|
|
378
|
-
| `
|
|
379
|
-
| `
|
|
386
|
+
| Method | Description | Parameters | Returns |
|
|
387
|
+
| -------------------------------------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
388
|
+
| `addTransaction(transaction, signer?)` | Add a transaction to the atomic group | `transaction: algosdk.Transaction, signer?: TransactionSigner` | `SwapComposer` |
|
|
389
|
+
| `addMethodCall(methodCall, signer?)` | Add an ABI method call to the atomic group | `methodCall: MethodCall, signer?: TransactionSigner` | `SwapComposer` |
|
|
390
|
+
| `addSwapTransactions()` | Add swap transactions to the group (includes required app opt-ins) | None | `Promise<SwapComposer>` |
|
|
391
|
+
| `buildGroup()` | Build the transaction group and assign group IDs | None | `TransactionWithSigner[]` |
|
|
392
|
+
| `sign()` | Sign the transaction group | None | `Promise<Uint8Array[]>` |
|
|
393
|
+
| `submit()` | Sign and submit the transaction group | None | `Promise<string[]>` (transaction IDs) |
|
|
394
|
+
| `execute(waitRounds?)` | Sign, submit, and wait for confirmation | `waitRounds?: number` (default: 4) | `Promise<{ confirmedRound: bigint, txIds: string[], methodResults: ABIResult[] }>` |
|
|
395
|
+
| `getStatus()` | Get current status: `BUILDING`, `BUILT`, `SIGNED`, `SUBMITTED`, or `COMMITTED` | None | `SwapComposerStatus` |
|
|
396
|
+
| `count()` | Get the number of transactions in the group | None | `number` |
|
|
380
397
|
|
|
381
398
|
## Documentation
|
|
382
399
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ABIArgument, ABIMethod, ABIResult, Address, Algodv2, BoxReference, OnApplicationComplete, ResourceReference, SuggestedParams, Transaction, TransactionSigner, TransactionWithSigner } from "algosdk";
|
|
2
2
|
|
|
3
3
|
//#region src/constants.d.ts
|
|
4
4
|
/**
|
|
@@ -281,14 +281,66 @@ interface FetchSwapTxnsResponse {
|
|
|
281
281
|
/**
|
|
282
282
|
* Processed transaction with optional pre-signature
|
|
283
283
|
*
|
|
284
|
+
* @deprecated This type is no longer used internally. Use algosdk.TransactionWithSigner instead.
|
|
284
285
|
* @internal
|
|
285
286
|
*/
|
|
286
287
|
interface SwapTransaction {
|
|
287
288
|
/** The Algorand transaction */
|
|
288
|
-
readonly txn:
|
|
289
|
+
readonly txn: Transaction;
|
|
289
290
|
/** Pre-signature from Deflex (if applicable) */
|
|
290
291
|
readonly deflexSignature?: DeflexSignature;
|
|
291
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Method call to be executed as part of the swap
|
|
295
|
+
*/
|
|
296
|
+
interface MethodCall {
|
|
297
|
+
/** The ID of the smart contract to call. Set this to 0 to indicate an application creation call. */
|
|
298
|
+
appID: number | bigint;
|
|
299
|
+
/** The method to call on the smart contract */
|
|
300
|
+
method: ABIMethod;
|
|
301
|
+
/** The arguments to include in the method call. If omitted, no arguments will be passed to the method. */
|
|
302
|
+
methodArgs?: ABIArgument[];
|
|
303
|
+
/** The address of the sender of this application call */
|
|
304
|
+
sender: string | Address;
|
|
305
|
+
/** Transactions params to use for this application call */
|
|
306
|
+
suggestedParams: SuggestedParams;
|
|
307
|
+
/** The OnComplete action to take for this application call. If omitted, OnApplicationComplete.NoOpOC will be used. */
|
|
308
|
+
onComplete?: OnApplicationComplete;
|
|
309
|
+
/** The approval program for this application call. Only set this if this is an application creation call, or if onComplete is OnApplicationComplete.UpdateApplicationOC */
|
|
310
|
+
approvalProgram?: Uint8Array;
|
|
311
|
+
/** The clear program for this application call. Only set this if this is an application creation call, or if onComplete is OnApplicationComplete.UpdateApplicationOC */
|
|
312
|
+
clearProgram?: Uint8Array;
|
|
313
|
+
/** The global integer schema size. Only set this if this is an application creation call. */
|
|
314
|
+
numGlobalInts?: number;
|
|
315
|
+
/** The global byte slice schema size. Only set this if this is an application creation call. */
|
|
316
|
+
numGlobalByteSlices?: number;
|
|
317
|
+
/** The local integer schema size. Only set this if this is an application creation call. */
|
|
318
|
+
numLocalInts?: number;
|
|
319
|
+
/** The local byte slice schema size. Only set this if this is an application creation call. */
|
|
320
|
+
numLocalByteSlices?: number;
|
|
321
|
+
/** The number of extra pages to allocate for the application's programs. Only set this if this is an application creation call. If omitted, defaults to 0. */
|
|
322
|
+
extraPages?: number;
|
|
323
|
+
/** Array of Address strings that represent external accounts supplied to this application. If accounts are provided here, the accounts specified in the method args will appear after these. */
|
|
324
|
+
appAccounts?: Array<string | Address>;
|
|
325
|
+
/** Array of App ID numbers that represent external apps supplied to this application. If apps are provided here, the apps specified in the method args will appear after these. */
|
|
326
|
+
appForeignApps?: Array<number | bigint>;
|
|
327
|
+
/** Array of Asset ID numbers that represent external assets supplied to this application. If assets are provided here, the assets specified in the method args will appear after these. */
|
|
328
|
+
appForeignAssets?: Array<number | bigint>;
|
|
329
|
+
/** The box references for this application call */
|
|
330
|
+
boxes?: BoxReference[];
|
|
331
|
+
/** The resource references for this application call */
|
|
332
|
+
access?: ResourceReference[];
|
|
333
|
+
/** The note value for this application call */
|
|
334
|
+
note?: Uint8Array;
|
|
335
|
+
/** The lease value for this application call */
|
|
336
|
+
lease?: Uint8Array;
|
|
337
|
+
/** If provided, the address that the sender will be rekeyed to at the conclusion of this application call */
|
|
338
|
+
rekeyTo?: string | Address;
|
|
339
|
+
/** The lowest application version for which this transaction should immediately fail. 0 indicates that no version check should be performed. */
|
|
340
|
+
rejectVersion?: number | bigint;
|
|
341
|
+
/** A transaction signer that can authorize this application call from sender */
|
|
342
|
+
signer?: TransactionSigner;
|
|
343
|
+
}
|
|
292
344
|
//#endregion
|
|
293
345
|
//#region src/composer.d.ts
|
|
294
346
|
/**
|
|
@@ -340,22 +392,21 @@ interface SwapComposerConfig {
|
|
|
340
392
|
* @example
|
|
341
393
|
* ```typescript
|
|
342
394
|
* const quote = await deflex.fetchQuote({ ... })
|
|
343
|
-
* const composer = await deflex.newSwap({ quote, address, slippage })
|
|
395
|
+
* const composer = await deflex.newSwap({ quote, address, slippage, signer })
|
|
344
396
|
*
|
|
345
397
|
* await composer
|
|
346
398
|
* .addTransaction(customTxn)
|
|
347
399
|
* .addSwapTransactions()
|
|
348
|
-
* .execute(
|
|
400
|
+
* .execute()
|
|
349
401
|
* ```
|
|
350
402
|
*/
|
|
351
403
|
declare class SwapComposer {
|
|
404
|
+
/** The ATC used to compose the group */
|
|
405
|
+
private atc;
|
|
352
406
|
/** The maximum size of an atomic transaction group. */
|
|
353
407
|
static MAX_GROUP_SIZE: number;
|
|
354
|
-
|
|
355
|
-
private transactions;
|
|
408
|
+
/** Whether the swap transactions have been added to the atomic group. */
|
|
356
409
|
private swapTransactionsAdded;
|
|
357
|
-
private signedTxns;
|
|
358
|
-
private txIds;
|
|
359
410
|
private readonly requiredAppOptIns;
|
|
360
411
|
private readonly deflexTxns;
|
|
361
412
|
private readonly algodClient;
|
|
@@ -403,7 +454,19 @@ declare class SwapComposer {
|
|
|
403
454
|
* @throws Error if the composer is not in the BUILDING status
|
|
404
455
|
* @throws Error if the maximum group size is exceeded
|
|
405
456
|
*/
|
|
406
|
-
addTransaction(transaction: Transaction): this;
|
|
457
|
+
addTransaction(transaction: Transaction, signer?: TransactionSigner): this;
|
|
458
|
+
/**
|
|
459
|
+
* Add a method call to the atomic group
|
|
460
|
+
*
|
|
461
|
+
* The `signer` property in the `methodCall` parameter is optional. If not provided,
|
|
462
|
+
* the signer will default to the one passed as the second parameter, or the
|
|
463
|
+
* configured signer from the constructor if no second parameter is provided.
|
|
464
|
+
*
|
|
465
|
+
* @param methodCall - The method call to add
|
|
466
|
+
* @param signer - The signer to use for the method call (defaults to constructor signer)
|
|
467
|
+
* @returns This composer instance for chaining
|
|
468
|
+
*/
|
|
469
|
+
addMethodCall(methodCall: MethodCall, signer?: TransactionSigner): this;
|
|
407
470
|
/**
|
|
408
471
|
* Add swap transactions to the atomic group
|
|
409
472
|
*
|
|
@@ -416,6 +479,30 @@ declare class SwapComposer {
|
|
|
416
479
|
* @throws Error if the maximum group size is exceeded
|
|
417
480
|
*/
|
|
418
481
|
addSwapTransactions(): Promise<this>;
|
|
482
|
+
/**
|
|
483
|
+
* Finalize the transaction group by assigning group IDs
|
|
484
|
+
*
|
|
485
|
+
* This method builds the atomic transaction group, assigning group IDs to all transactions
|
|
486
|
+
* if there is more than one transaction. After calling this method, the composer's status
|
|
487
|
+
* will be at least BUILT.
|
|
488
|
+
*
|
|
489
|
+
* @returns Array of transactions with their associated signers
|
|
490
|
+
*
|
|
491
|
+
* @throws Error if the group contains 0 transactions
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const composer = await deflex.newSwap({ quote, address, slippage, signer })
|
|
496
|
+
* composer.addTransaction(customTxn)
|
|
497
|
+
*
|
|
498
|
+
* // Build the group to inspect transactions before signing
|
|
499
|
+
* const txnsWithSigners = composer.buildGroup()
|
|
500
|
+
* console.log('Group ID:', txnsWithSigners[0].txn.group)
|
|
501
|
+
* console.log('Group length:', txnsWithSigners.length)
|
|
502
|
+
* console.log('Status:', composer.getStatus()) // BUILT
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
buildGroup(): TransactionWithSigner[];
|
|
419
506
|
/**
|
|
420
507
|
* Sign the transaction group
|
|
421
508
|
*
|
|
@@ -467,6 +554,7 @@ declare class SwapComposer {
|
|
|
467
554
|
execute(waitRounds?: number): Promise<{
|
|
468
555
|
confirmedRound: bigint;
|
|
469
556
|
txIds: string[];
|
|
557
|
+
methodResults: ABIResult[];
|
|
470
558
|
}>;
|
|
471
559
|
/**
|
|
472
560
|
* Validates an Algorand address
|
|
@@ -481,11 +569,13 @@ declare class SwapComposer {
|
|
|
481
569
|
*/
|
|
482
570
|
private processRequiredAppOptIns;
|
|
483
571
|
/**
|
|
484
|
-
*
|
|
485
|
-
|
|
486
|
-
|
|
572
|
+
* The default signer function that uses the configured signer
|
|
573
|
+
*/
|
|
574
|
+
private defaultSigner;
|
|
575
|
+
/**
|
|
576
|
+
* Creates a TransactionSigner function for Deflex pre-signed transactions
|
|
487
577
|
*/
|
|
488
|
-
private
|
|
578
|
+
private createDeflexSigner;
|
|
489
579
|
/**
|
|
490
580
|
* Re-signs a Deflex transaction using the provided logic signature or secret key
|
|
491
581
|
*/
|
|
@@ -737,5 +827,5 @@ declare class HTTPError extends Error {
|
|
|
737
827
|
*/
|
|
738
828
|
declare function request<T>(url: string, options?: RequestInit): Promise<T>;
|
|
739
829
|
//#endregion
|
|
740
|
-
export { Asset, DEFAULT_ALGOD_PORT, DEFAULT_ALGOD_TOKEN, DEFAULT_ALGOD_URI, DEFAULT_API_BASE_URL, DEFAULT_AUTO_OPT_IN, DEFAULT_CONFIRMATION_ROUNDS, DEFAULT_FEE_BPS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_GROUP_SIZE, DEPRECATED_PROTOCOLS, DeflexClient, DeflexConfig, DeflexConfigParams, DeflexQuote, DeflexSignature, DeflexTransaction, DexQuote, FetchQuoteParams, FetchQuoteResponse, FetchSwapTxnsBody, FetchSwapTxnsParams, FetchSwapTxnsResponse, HTTPError, MAX_FEE_BPS, PathElement, Profit, Protocol, QuoteType, Route, SignerFunction, SwapComposer, SwapComposerConfig, SwapComposerStatus, SwapTransaction, TxnPayload, request };
|
|
830
|
+
export { Asset, DEFAULT_ALGOD_PORT, DEFAULT_ALGOD_TOKEN, DEFAULT_ALGOD_URI, DEFAULT_API_BASE_URL, DEFAULT_AUTO_OPT_IN, DEFAULT_CONFIRMATION_ROUNDS, DEFAULT_FEE_BPS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_GROUP_SIZE, DEPRECATED_PROTOCOLS, DeflexClient, DeflexConfig, DeflexConfigParams, DeflexQuote, DeflexSignature, DeflexTransaction, DexQuote, FetchQuoteParams, FetchQuoteResponse, FetchSwapTxnsBody, FetchSwapTxnsParams, FetchSwapTxnsResponse, HTTPError, MAX_FEE_BPS, MethodCall, PathElement, Profit, Protocol, QuoteType, Route, SignerFunction, SwapComposer, SwapComposerConfig, SwapComposerStatus, SwapTransaction, TxnPayload, request };
|
|
741
831
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/constants.ts","../src/types.ts","../src/composer.ts","../src/client.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGY,aAAA,QAAA;EAcC,SAAA,GAAA,WAAqD;EAGrD,MAAA,GAAA,QAAA;EAGA,QAAA,GAAA,UAAA;EAGA,IAAA,GAAA,MAAA;EAGA,KAAA,GAAA,OAAA;EAGA,KAAA,GAAA,OAAA;AAGb;AAGA;AAGA;AAGA;AAGA;;cA9Ba;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/constants.ts","../src/types.ts","../src/composer.ts","../src/client.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGY,aAAA,QAAA;EAcC,SAAA,GAAA,WAAqD;EAGrD,MAAA,GAA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;EAyLY,eAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EA1BP,OA0BO,CAAA,OAAA,CAAA;EACC;;;;;;;;;;;;gCADD,sBACP,QAAQ;;;AC7Ob;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBDiRyB,mBAAmB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6DzC,cAAc;;;YAGb,oBAAoB;MAC1B,QAAQ;;;;;;;;;;;;;;;;;;;AHxWF,cIAC,SAAA,SAAkB,KAAA,CJAX;EAcP,MAAA,EAAA,MAAA;EAGA,UAAA,EAAA,MAAA;EAGA,IAAA,EAAA,OAAA;EAGA,WAAA,CAAA,MAAA,EAAA,MAAkB,EAAA,UAAA,EAAA,MAAA,EAAA,IAAA,EAAA,OAAA;AAG/B;AAGA;AAGA;AAGA;AAGA;AAGA;AAGA;;;;AC/BA;AA+BA;AACW,iBGvBW,OHuBX,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EGrBC,WHqBD,CAAA,EGpBR,OHoBQ,CGpBA,CHoBA,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Algodv2, LogicSigAccount, Transaction,
|
|
1
|
+
import { Algodv2, AtomicTransactionComposer, LogicSigAccount, Transaction, decodeUnsignedTransaction, isValidAddress, makeApplicationOptInTxnFromObject, msgpackRawDecode, signLogicSigTransactionObject, signTransaction } from "algosdk";
|
|
2
2
|
|
|
3
3
|
//#region src/constants.ts
|
|
4
4
|
/**
|
|
@@ -68,22 +68,21 @@ let SwapComposerStatus = /* @__PURE__ */ function(SwapComposerStatus$1) {
|
|
|
68
68
|
* @example
|
|
69
69
|
* ```typescript
|
|
70
70
|
* const quote = await deflex.fetchQuote({ ... })
|
|
71
|
-
* const composer = await deflex.newSwap({ quote, address, slippage })
|
|
71
|
+
* const composer = await deflex.newSwap({ quote, address, slippage, signer })
|
|
72
72
|
*
|
|
73
73
|
* await composer
|
|
74
74
|
* .addTransaction(customTxn)
|
|
75
75
|
* .addSwapTransactions()
|
|
76
|
-
* .execute(
|
|
76
|
+
* .execute()
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
79
|
var SwapComposer = class SwapComposer {
|
|
80
|
+
/** The ATC used to compose the group */
|
|
81
|
+
atc = new AtomicTransactionComposer();
|
|
80
82
|
/** The maximum size of an atomic transaction group. */
|
|
81
|
-
static MAX_GROUP_SIZE =
|
|
82
|
-
|
|
83
|
-
transactions = [];
|
|
83
|
+
static MAX_GROUP_SIZE = AtomicTransactionComposer.MAX_GROUP_SIZE;
|
|
84
|
+
/** Whether the swap transactions have been added to the atomic group. */
|
|
84
85
|
swapTransactionsAdded = false;
|
|
85
|
-
signedTxns = [];
|
|
86
|
-
txIds = [];
|
|
87
86
|
requiredAppOptIns;
|
|
88
87
|
deflexTxns;
|
|
89
88
|
algodClient;
|
|
@@ -120,7 +119,7 @@ var SwapComposer = class SwapComposer {
|
|
|
120
119
|
* @returns The current status of the transaction group
|
|
121
120
|
*/
|
|
122
121
|
getStatus() {
|
|
123
|
-
return this.
|
|
122
|
+
return this.atc.getStatus();
|
|
124
123
|
}
|
|
125
124
|
/**
|
|
126
125
|
* Get the number of transactions currently in this atomic group
|
|
@@ -128,7 +127,7 @@ var SwapComposer = class SwapComposer {
|
|
|
128
127
|
* @returns The number of transactions in the group
|
|
129
128
|
*/
|
|
130
129
|
count() {
|
|
131
|
-
return this.
|
|
130
|
+
return this.atc.count();
|
|
132
131
|
}
|
|
133
132
|
/**
|
|
134
133
|
* Add a transaction to the atomic group
|
|
@@ -146,10 +145,29 @@ var SwapComposer = class SwapComposer {
|
|
|
146
145
|
* @throws Error if the composer is not in the BUILDING status
|
|
147
146
|
* @throws Error if the maximum group size is exceeded
|
|
148
147
|
*/
|
|
149
|
-
addTransaction(transaction) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
addTransaction(transaction, signer = this.defaultSigner) {
|
|
149
|
+
this.atc.addTransaction({
|
|
150
|
+
txn: transaction,
|
|
151
|
+
signer
|
|
152
|
+
});
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Add a method call to the atomic group
|
|
157
|
+
*
|
|
158
|
+
* The `signer` property in the `methodCall` parameter is optional. If not provided,
|
|
159
|
+
* the signer will default to the one passed as the second parameter, or the
|
|
160
|
+
* configured signer from the constructor if no second parameter is provided.
|
|
161
|
+
*
|
|
162
|
+
* @param methodCall - The method call to add
|
|
163
|
+
* @param signer - The signer to use for the method call (defaults to constructor signer)
|
|
164
|
+
* @returns This composer instance for chaining
|
|
165
|
+
*/
|
|
166
|
+
addMethodCall(methodCall, signer = this.defaultSigner) {
|
|
167
|
+
this.atc.addMethodCall({
|
|
168
|
+
...methodCall,
|
|
169
|
+
signer: methodCall.signer ?? signer
|
|
170
|
+
});
|
|
153
171
|
return this;
|
|
154
172
|
}
|
|
155
173
|
/**
|
|
@@ -165,14 +183,40 @@ var SwapComposer = class SwapComposer {
|
|
|
165
183
|
*/
|
|
166
184
|
async addSwapTransactions() {
|
|
167
185
|
if (this.swapTransactionsAdded) throw new Error("Swap transactions have already been added");
|
|
168
|
-
if (this.
|
|
186
|
+
if (this.getStatus() !== SwapComposerStatus.BUILDING) throw new Error("Cannot add swap transactions when composer status is not BUILDING");
|
|
169
187
|
const processedTxns = await this.processSwapTransactions();
|
|
170
|
-
if (this.
|
|
171
|
-
this.
|
|
188
|
+
if (this.atc.count() + processedTxns.length > SwapComposer.MAX_GROUP_SIZE) throw new Error(`Adding swap transactions exceeds the maximum atomic group size of ${SwapComposer.MAX_GROUP_SIZE}`);
|
|
189
|
+
for (const txnWithSigner of processedTxns) this.atc.addTransaction(txnWithSigner);
|
|
172
190
|
this.swapTransactionsAdded = true;
|
|
173
191
|
return this;
|
|
174
192
|
}
|
|
175
193
|
/**
|
|
194
|
+
* Finalize the transaction group by assigning group IDs
|
|
195
|
+
*
|
|
196
|
+
* This method builds the atomic transaction group, assigning group IDs to all transactions
|
|
197
|
+
* if there is more than one transaction. After calling this method, the composer's status
|
|
198
|
+
* will be at least BUILT.
|
|
199
|
+
*
|
|
200
|
+
* @returns Array of transactions with their associated signers
|
|
201
|
+
*
|
|
202
|
+
* @throws Error if the group contains 0 transactions
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const composer = await deflex.newSwap({ quote, address, slippage, signer })
|
|
207
|
+
* composer.addTransaction(customTxn)
|
|
208
|
+
*
|
|
209
|
+
* // Build the group to inspect transactions before signing
|
|
210
|
+
* const txnsWithSigners = composer.buildGroup()
|
|
211
|
+
* console.log('Group ID:', txnsWithSigners[0].txn.group)
|
|
212
|
+
* console.log('Group length:', txnsWithSigners.length)
|
|
213
|
+
* console.log('Status:', composer.getStatus()) // BUILT
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
buildGroup() {
|
|
217
|
+
return this.atc.buildGroup();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
176
220
|
* Sign the transaction group
|
|
177
221
|
*
|
|
178
222
|
* Automatically adds swap transactions if not already added, builds the atomic group,
|
|
@@ -186,34 +230,9 @@ var SwapComposer = class SwapComposer {
|
|
|
186
230
|
* ```
|
|
187
231
|
*/
|
|
188
232
|
async sign() {
|
|
189
|
-
if (this.
|
|
233
|
+
if (this.getStatus() >= SwapComposerStatus.SIGNED) return this.atc.gatherSignatures();
|
|
190
234
|
if (!this.swapTransactionsAdded) await this.addSwapTransactions();
|
|
191
|
-
|
|
192
|
-
const txnGroup = [];
|
|
193
|
-
const indexesToSign = [];
|
|
194
|
-
for (let i = 0; i < transactions.length; i++) {
|
|
195
|
-
const item = transactions[i];
|
|
196
|
-
if (!item) continue;
|
|
197
|
-
txnGroup.push(item.txn);
|
|
198
|
-
if (!item.deflexSignature) indexesToSign.push(i);
|
|
199
|
-
}
|
|
200
|
-
const userSignedTxns = (await this.signer(txnGroup, indexesToSign)).filter((txn) => txn !== null);
|
|
201
|
-
const finalSignedTxns = [];
|
|
202
|
-
let userSignedIndex = 0;
|
|
203
|
-
for (const item of transactions) if (item.deflexSignature) {
|
|
204
|
-
const signedTxnBlob = this.signDeflexTransaction(item.txn, item.deflexSignature);
|
|
205
|
-
finalSignedTxns.push(signedTxnBlob);
|
|
206
|
-
} else {
|
|
207
|
-
const userSignedTxn = userSignedTxns[userSignedIndex];
|
|
208
|
-
if (!userSignedTxn) throw new Error(`Missing signature for user transaction at index ${userSignedIndex}`);
|
|
209
|
-
finalSignedTxns.push(userSignedTxn);
|
|
210
|
-
userSignedIndex++;
|
|
211
|
-
}
|
|
212
|
-
const txIds = this.transactions.map((t) => t.txn.txID());
|
|
213
|
-
this.signedTxns = finalSignedTxns;
|
|
214
|
-
this.txIds = txIds;
|
|
215
|
-
this.status = SwapComposerStatus.SIGNED;
|
|
216
|
-
return finalSignedTxns;
|
|
235
|
+
return await this.atc.gatherSignatures();
|
|
217
236
|
}
|
|
218
237
|
/**
|
|
219
238
|
* Submit the signed transactions to the network
|
|
@@ -231,11 +250,8 @@ var SwapComposer = class SwapComposer {
|
|
|
231
250
|
* ```
|
|
232
251
|
*/
|
|
233
252
|
async submit() {
|
|
234
|
-
if (this.
|
|
235
|
-
|
|
236
|
-
await this.algodClient.sendRawTransaction(stxns).do();
|
|
237
|
-
this.status = SwapComposerStatus.SUBMITTED;
|
|
238
|
-
return this.txIds;
|
|
253
|
+
if (!this.swapTransactionsAdded) await this.addSwapTransactions();
|
|
254
|
+
return this.atc.submit(this.algodClient);
|
|
239
255
|
}
|
|
240
256
|
/**
|
|
241
257
|
* Execute the swap
|
|
@@ -256,14 +272,11 @@ var SwapComposer = class SwapComposer {
|
|
|
256
272
|
* ```
|
|
257
273
|
*/
|
|
258
274
|
async execute(waitRounds = DEFAULT_CONFIRMATION_ROUNDS) {
|
|
259
|
-
if (this.
|
|
260
|
-
const
|
|
261
|
-
const confirmedTxnInfo = await waitForConfirmation(this.algodClient, txIds[0], waitRounds);
|
|
262
|
-
this.status = SwapComposerStatus.COMMITTED;
|
|
263
|
-
const confirmedRound = confirmedTxnInfo.confirmedRound;
|
|
275
|
+
if (!this.swapTransactionsAdded) await this.addSwapTransactions();
|
|
276
|
+
const { txIDs,...result } = await this.atc.execute(this.algodClient, waitRounds);
|
|
264
277
|
return {
|
|
265
|
-
|
|
266
|
-
txIds
|
|
278
|
+
...result,
|
|
279
|
+
txIds: txIDs
|
|
267
280
|
};
|
|
268
281
|
}
|
|
269
282
|
/**
|
|
@@ -287,9 +300,12 @@ var SwapComposer = class SwapComposer {
|
|
|
287
300
|
delete txn.group;
|
|
288
301
|
if (deflexTxn.signature !== false) swapTxns.push({
|
|
289
302
|
txn,
|
|
290
|
-
|
|
303
|
+
signer: this.createDeflexSigner(deflexTxn.signature)
|
|
304
|
+
});
|
|
305
|
+
else swapTxns.push({
|
|
306
|
+
txn,
|
|
307
|
+
signer: this.defaultSigner
|
|
291
308
|
});
|
|
292
|
-
else swapTxns.push({ txn });
|
|
293
309
|
} catch (error) {
|
|
294
310
|
throw new Error(`Failed to process swap transaction at index ${i}: ${error instanceof Error ? error.message : String(error)}`);
|
|
295
311
|
}
|
|
@@ -302,32 +318,34 @@ var SwapComposer = class SwapComposer {
|
|
|
302
318
|
async processRequiredAppOptIns() {
|
|
303
319
|
const userApps = (await this.algodClient.accountInformation(this.address).do())?.appsLocalState?.map((app) => Number(app.id)) || [];
|
|
304
320
|
const appsToOptIn = this.requiredAppOptIns.filter((appId) => !userApps.includes(appId));
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return appOptInTxns.map((txn) => ({ txn }));
|
|
321
|
+
if (appsToOptIn.length === 0) return [];
|
|
322
|
+
const suggestedParams = await this.algodClient.getTransactionParams().do();
|
|
323
|
+
return appsToOptIn.map((appId) => ({
|
|
324
|
+
txn: makeApplicationOptInTxnFromObject({
|
|
325
|
+
sender: this.address,
|
|
326
|
+
appIndex: appId,
|
|
327
|
+
suggestedParams
|
|
328
|
+
}),
|
|
329
|
+
signer: this.defaultSigner
|
|
330
|
+
}));
|
|
318
331
|
}
|
|
319
332
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* The composer's status will be at least BUILT after executing this method.
|
|
333
|
+
* The default signer function that uses the configured signer
|
|
323
334
|
*/
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
defaultSigner = async (txnGroup, indexesToSign) => {
|
|
336
|
+
return (await this.signer(txnGroup, indexesToSign)).filter((txn) => txn !== null);
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Creates a TransactionSigner function for Deflex pre-signed transactions
|
|
340
|
+
*/
|
|
341
|
+
createDeflexSigner(signature) {
|
|
342
|
+
return async (txnGroup, indexesToSign) => {
|
|
343
|
+
return indexesToSign.map((i) => {
|
|
344
|
+
const txn = txnGroup[i];
|
|
345
|
+
if (!txn) throw new Error(`Transaction at index ${i} not found`);
|
|
346
|
+
return this.signDeflexTransaction(txn, signature);
|
|
347
|
+
});
|
|
348
|
+
};
|
|
331
349
|
}
|
|
332
350
|
/**
|
|
333
351
|
* Re-signs a Deflex transaction using the provided logic signature or secret key
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["txnGroup: Transaction[]","indexesToSign: number[]","finalSignedTxns: Uint8Array[]","appOptIns: SwapTransaction[]","swapTxns: SwapTransaction[]","appOptInTxns: Transaction[]","status: number","statusText: string","data: unknown","errorData: unknown","body: FetchSwapTxnsBody"],"sources":["../src/constants.ts","../src/composer.ts","../src/utils.ts","../src/client.ts"],"sourcesContent":["/**\n * Supported DEX protocols for swap routing\n */\nexport enum Protocol {\n TinymanV2 = 'TinymanV2',\n Algofi = 'Algofi',\n Algomint = 'Algomint',\n Pact = 'Pact',\n Folks = 'Folks',\n TAlgo = 'TAlgo',\n}\n\n/**\n * Deprecated protocols that are automatically excluded from routing\n *\n * @internal\n */\nexport const DEPRECATED_PROTOCOLS = ['Humble', 'Tinyman'] as const\n\n/** Default Algod node URI for mainnet */\nexport const DEFAULT_ALGOD_URI = 'https://mainnet-api.4160.nodely.dev/'\n\n/** Default Algod node token (empty for public nodes) */\nexport const DEFAULT_ALGOD_TOKEN = ''\n\n/** Default Algod node port */\nexport const DEFAULT_ALGOD_PORT = 443\n\n/** Default Deflex API base URL */\nexport const DEFAULT_API_BASE_URL = 'https://deflex.txnlab.dev/api'\n\n/** Default fee in basis points (0.15%) */\nexport const DEFAULT_FEE_BPS = 15\n\n/** Maximum allowed fee in basis points (3.00%) */\nexport const MAX_FEE_BPS = 300\n\n/** Default maximum transaction group size */\nexport const DEFAULT_MAX_GROUP_SIZE = 16\n\n/** Default maximum routing depth (number of hops) */\nexport const DEFAULT_MAX_DEPTH = 4\n\n/** Default auto opt-in setting (automatic asset/app opt-in detection) */\nexport const DEFAULT_AUTO_OPT_IN = false\n\n/** Default number of rounds to wait for transaction confirmation */\nexport const DEFAULT_CONFIRMATION_ROUNDS = 4\n","import {\n assignGroupID,\n decodeUnsignedTransaction,\n isValidAddress,\n signLogicSigTransactionObject,\n signTransaction,\n LogicSigAccount,\n makeApplicationOptInTxnFromObject,\n msgpackRawDecode,\n Transaction,\n waitForConfirmation,\n type Algodv2,\n type TransactionSigner,\n} from 'algosdk'\nimport { DEFAULT_CONFIRMATION_ROUNDS } from './constants'\nimport type {\n FetchQuoteResponse,\n DeflexTransaction,\n SwapTransaction,\n DeflexSignature,\n DeflexQuote,\n} from './types'\n\n/**\n * A transaction signer function that supports both standard algosdk.TransactionSigner\n * and ARC-1 compliant signers that may return null for unsigned transactions.\n *\n * @param txnGroup - The complete transaction group to sign\n * @param indexesToSign - Array of indexes indicating which transactions need signing\n * @returns Array of signed transactions (may include nulls for ARC-1 compliant wallets)\n */\nexport type SignerFunction = (\n txnGroup: Transaction[],\n indexesToSign: number[],\n) => Promise<(Uint8Array | null)[]>\n\n/**\n * Status of the SwapComposer transaction group lifecycle\n */\nexport enum SwapComposerStatus {\n /** The atomic group is still under construction. */\n BUILDING,\n\n /** The atomic group has been finalized, but not yet signed. */\n BUILT,\n\n /** The atomic group has been finalized and signed, but not yet submitted to the network. */\n SIGNED,\n\n /** The atomic group has been finalized, signed, and submitted to the network. */\n SUBMITTED,\n\n /** The atomic group has been finalized, signed, submitted, and successfully committed to a block. */\n COMMITTED,\n}\n\n/**\n * Configuration for creating a SwapComposer instance\n */\nexport interface SwapComposerConfig {\n /** The quote response from fetchQuote() or newQuote() */\n readonly quote: FetchQuoteResponse | DeflexQuote\n /** The swap transactions from fetchSwapTransactions() */\n readonly deflexTxns: DeflexTransaction[]\n /** Algodv2 client instance */\n readonly algodClient: Algodv2\n /** The address of the account that will sign transactions */\n readonly address: string\n /** Transaction signer function */\n readonly signer: TransactionSigner | SignerFunction\n}\n\n/**\n * Composer for building and executing atomic swap transaction groups\n *\n * The SwapComposer allows you to build complex transaction groups by adding custom\n * transactions before and after swap transactions. It handles pre-signed transactions,\n * automatic app opt-ins, and provides a fluent API for transaction group construction.\n *\n * @example\n * ```typescript\n * const quote = await deflex.fetchQuote({ ... })\n * const composer = await deflex.newSwap({ quote, address, slippage })\n *\n * await composer\n * .addTransaction(customTxn)\n * .addSwapTransactions()\n * .execute(signer)\n * ```\n */\nexport class SwapComposer {\n /** The maximum size of an atomic transaction group. */\n static MAX_GROUP_SIZE: number = 16\n\n private status: SwapComposerStatus = SwapComposerStatus.BUILDING\n private transactions: SwapTransaction[] = []\n private swapTransactionsAdded = false\n private signedTxns: Uint8Array[] = []\n private txIds: string[] = []\n\n private readonly requiredAppOptIns: number[]\n private readonly deflexTxns: DeflexTransaction[]\n private readonly algodClient: Algodv2\n private readonly address: string\n private readonly signer: TransactionSigner | SignerFunction\n\n /**\n * Create a new SwapComposer instance\n *\n * Note: Most developers should use DeflexClient.newSwap() instead of constructing\n * this directly, as the factory method handles fetching swap transactions automatically.\n *\n * @param config - Configuration for the composer\n * @param config.requiredAppOptIns - The quote response from fetchQuote()\n * @param config.deflexTxns - The swap transactions from fetchSwapTransactions()\n * @param config.algodClient - Algodv2 client instance\n * @param config.address - The address of the account that will sign transactions\n * @param config.signer - Transaction signer function\n */\n constructor(config: SwapComposerConfig) {\n // Validate required parameters\n if (!config.quote) {\n throw new Error('Quote is required')\n }\n if (!config.deflexTxns) {\n throw new Error('Swap transactions are required')\n }\n if (config.deflexTxns.length === 0) {\n throw new Error('Swap transactions array cannot be empty')\n }\n if (!config.algodClient) {\n throw new Error('Algodv2 client instance is required')\n }\n if (!config.signer) {\n throw new Error('Signer is required')\n }\n\n this.requiredAppOptIns = config.quote.requiredAppOptIns\n this.deflexTxns = config.deflexTxns\n this.algodClient = config.algodClient\n this.address = this.validateAddress(config.address)\n this.signer = config.signer\n }\n\n /**\n * Get the status of this composer's transaction group\n *\n * @returns The current status of the transaction group\n */\n getStatus(): SwapComposerStatus {\n return this.status\n }\n\n /**\n * Get the number of transactions currently in this atomic group\n *\n * @returns The number of transactions in the group\n */\n count(): number {\n return this.transactions.length\n }\n\n /**\n * Add a transaction to the atomic group\n *\n * Transactions are added in the order methods are called. For example:\n * ```typescript\n * composer\n * .addTransaction(txn1) // Added first\n * .addSwapTransactions() // Added second\n * .addTransaction(txn2) // Added third\n * ```\n *\n * @param transaction - The transaction to add\n * @returns This composer instance for chaining\n * @throws Error if the composer is not in the BUILDING status\n * @throws Error if the maximum group size is exceeded\n */\n addTransaction(transaction: Transaction): this {\n if (this.status !== SwapComposerStatus.BUILDING) {\n throw new Error(\n 'Cannot add transactions when composer status is not BUILDING',\n )\n }\n\n if (this.transactions.length === SwapComposer.MAX_GROUP_SIZE) {\n throw new Error(\n `Adding an additional transaction exceeds the maximum atomic group size of ${SwapComposer.MAX_GROUP_SIZE}`,\n )\n }\n\n this.transactions.push({ txn: transaction })\n return this\n }\n\n /**\n * Add swap transactions to the atomic group\n *\n * This method automatically processes required app opt-ins and adds all swap\n * transactions from the quote. Can only be called once per composer instance.\n *\n * @returns This composer instance for chaining\n * @throws Error if the swap transactions have already been added\n * @throws Error if the composer is not in the BUILDING status\n * @throws Error if the maximum group size is exceeded\n */\n async addSwapTransactions(): Promise<this> {\n if (this.swapTransactionsAdded) {\n throw new Error('Swap transactions have already been added')\n }\n\n if (this.status !== SwapComposerStatus.BUILDING) {\n throw new Error(\n 'Cannot add swap transactions when composer status is not BUILDING',\n )\n }\n\n const processedTxns = await this.processSwapTransactions()\n const newLength = this.transactions.length + processedTxns.length\n\n if (newLength > SwapComposer.MAX_GROUP_SIZE) {\n throw new Error(\n `Adding swap transactions exceeds the maximum atomic group size of ${SwapComposer.MAX_GROUP_SIZE}`,\n )\n }\n\n this.transactions.push(...processedTxns)\n\n this.swapTransactionsAdded = true\n return this\n }\n\n /**\n * Sign the transaction group\n *\n * Automatically adds swap transactions if not already added, builds the atomic group,\n * and signs all transactions using the configured signer.\n *\n * @returns A promise that resolves to an array of signed transaction blobs\n *\n * @example\n * ```typescript\n * const signedTxns = await composer.sign()\n * ```\n */\n async sign(): Promise<Uint8Array[]> {\n if (this.status >= SwapComposerStatus.SIGNED) {\n return this.signedTxns\n }\n\n // Auto-add swap transactions if needed\n if (!this.swapTransactionsAdded) {\n await this.addSwapTransactions()\n }\n\n // Build the transaction group, ensure status is BUILT\n const transactions = this.buildGroup()\n\n // Collect all transactions and identify which ones need user signature\n const txnGroup: Transaction[] = []\n const indexesToSign: number[] = []\n\n for (let i = 0; i < transactions.length; i++) {\n const item = transactions[i]\n if (!item) continue\n\n txnGroup.push(item.txn)\n\n if (!item.deflexSignature) {\n // User transaction - needs user signature\n indexesToSign.push(i)\n }\n }\n\n // Sign all transactions with the complete group\n const signedTxns = await this.signer(txnGroup, indexesToSign)\n\n // Normalize signedTxns - handle both wallet patterns:\n // Pattern 1: Returns only signed txns (length < txnGroup.length)\n // Pattern 2: Returns array matching group length with nulls for non-signed (ARC-1)\n const userSignedTxns = signedTxns.filter(\n (txn): txn is Uint8Array => txn !== null,\n )\n\n // Rebuild complete group in correct order\n const finalSignedTxns: Uint8Array[] = []\n let userSignedIndex = 0\n\n for (const item of transactions) {\n if (item.deflexSignature) {\n // Pre-signed transaction - re-sign with Deflex signature\n const signedTxnBlob = this.signDeflexTransaction(\n item.txn,\n item.deflexSignature,\n )\n finalSignedTxns.push(signedTxnBlob)\n } else {\n // User transaction - use signature from signer\n const userSignedTxn = userSignedTxns[userSignedIndex]\n if (!userSignedTxn) {\n throw new Error(\n `Missing signature for user transaction at index ${userSignedIndex}`,\n )\n }\n finalSignedTxns.push(userSignedTxn)\n userSignedIndex++\n }\n }\n\n const txIds = this.transactions.map((t) => t.txn.txID())\n\n this.signedTxns = finalSignedTxns\n this.txIds = txIds\n this.status = SwapComposerStatus.SIGNED\n\n return finalSignedTxns\n }\n\n /**\n * Submit the signed transactions to the network\n *\n * This method signs the transaction group (if not already signed) and submits\n * it to the Algorand network. Does not wait for confirmation.\n *\n * @returns The transaction IDs\n * @throws Error if the transaction group has already been submitted\n *\n * @example\n * ```typescript\n * const txIds = await composer.submit()\n * console.log('Submitted transactions:', txIds)\n * ```\n */\n async submit(): Promise<string[]> {\n if (this.status > SwapComposerStatus.SUBMITTED) {\n throw new Error('Transaction group cannot be resubmitted')\n }\n\n const stxns = await this.sign()\n await this.algodClient.sendRawTransaction(stxns).do()\n\n this.status = SwapComposerStatus.SUBMITTED\n return this.txIds\n }\n\n /**\n * Execute the swap\n *\n * Signs the transaction group, submits it to the network, and waits for confirmation.\n * This is the primary method for executing swaps and combines sign(), submit(), and\n * waitForConfirmation() into a single call.\n *\n * @param waitRounds - The number of rounds to wait for confirmation (default: 4)\n * @returns Object containing the confirmed round and transaction IDs\n * @throws Error if the transaction group has already been committed\n *\n * @example\n * ```typescript\n * const result = await composer.execute()\n * console.log(`Confirmed in round ${result.confirmedRound}`)\n * console.log('Transaction IDs:', result.txIds)\n * ```\n */\n async execute(waitRounds: number = DEFAULT_CONFIRMATION_ROUNDS): Promise<{\n confirmedRound: bigint\n txIds: string[]\n }> {\n if (this.status === SwapComposerStatus.COMMITTED) {\n throw new Error(\n 'Transaction group has already been executed successfully',\n )\n }\n\n const txIds = await this.submit()\n\n const confirmedTxnInfo = await waitForConfirmation(\n this.algodClient,\n txIds[0]!,\n waitRounds,\n )\n\n this.status = SwapComposerStatus.COMMITTED\n\n const confirmedRound = confirmedTxnInfo.confirmedRound!\n\n return {\n confirmedRound: BigInt(confirmedRound),\n txIds,\n }\n }\n\n /**\n * Validates an Algorand address\n */\n private validateAddress(address: string): string {\n if (!isValidAddress(address)) {\n throw new Error(`Invalid Algorand address: ${address}`)\n }\n return address\n }\n\n /**\n * Processes app opt-ins and decodes swap transactions from API response\n */\n private async processSwapTransactions(): Promise<SwapTransaction[]> {\n // Process required app opt-ins\n const appOptIns: SwapTransaction[] = await this.processRequiredAppOptIns()\n\n // Decode and process swap transactions from API\n const swapTxns: SwapTransaction[] = []\n for (let i = 0; i < this.deflexTxns.length; i++) {\n const deflexTxn = this.deflexTxns[i]\n if (!deflexTxn) continue\n\n try {\n // Decode transaction from base64 data\n const txnBytes = Buffer.from(deflexTxn.data, 'base64')\n const txn = decodeUnsignedTransaction(txnBytes)\n\n // Remove group ID (will be reassigned later)\n delete txn.group\n\n if (deflexTxn.signature !== false) {\n // Pre-signed transaction - needs re-signing with provided signature\n swapTxns.push({\n txn,\n deflexSignature: deflexTxn.signature,\n })\n } else {\n // User transaction - needs user signature\n swapTxns.push({\n txn,\n })\n }\n } catch (error) {\n throw new Error(\n `Failed to process swap transaction at index ${i}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n\n return [...appOptIns, ...swapTxns]\n }\n\n /**\n * Creates opt-in transactions for apps the user hasn't opted into yet\n */\n private async processRequiredAppOptIns(): Promise<SwapTransaction[]> {\n // Fetch account information\n const accountInfo = await this.algodClient\n .accountInformation(this.address)\n .do()\n\n // Check app opt-ins\n const userApps =\n accountInfo?.appsLocalState?.map((app) => Number(app.id)) || []\n const appsToOptIn = this.requiredAppOptIns.filter(\n (appId) => !userApps.includes(appId),\n )\n\n // Create opt-in transactions if needed\n const appOptInTxns: Transaction[] = []\n if (appsToOptIn.length > 0) {\n const suggestedParams = await this.algodClient.getTransactionParams().do()\n\n for (const appId of appsToOptIn) {\n const optInTxn = makeApplicationOptInTxnFromObject({\n sender: this.address,\n appIndex: appId,\n suggestedParams,\n })\n appOptInTxns.push(optInTxn)\n }\n }\n\n return appOptInTxns.map((txn) => ({ txn }))\n }\n\n /**\n * Finalizes the transaction group by assigning group IDs\n *\n * The composer's status will be at least BUILT after executing this method.\n */\n private buildGroup(): SwapTransaction[] {\n if (this.status === SwapComposerStatus.BUILDING) {\n if (this.transactions.length === 0) {\n throw new Error('Cannot build a group with 0 transactions')\n }\n if (this.transactions.length > 1) {\n assignGroupID(this.transactions.map((t) => t.txn))\n }\n this.status = SwapComposerStatus.BUILT\n }\n return this.transactions\n }\n\n /**\n * Re-signs a Deflex transaction using the provided logic signature or secret key\n */\n private signDeflexTransaction(\n transaction: Transaction,\n signature: DeflexSignature,\n ): Uint8Array {\n try {\n if (signature.type === 'logic_signature') {\n // Decode the signature value to extract the logic signature\n const valueArray = signature.value as Record<string, number>\n const valueBytes = new Uint8Array(Object.values(valueArray))\n const decoded = msgpackRawDecode(valueBytes) as {\n lsig?: { l: Uint8Array; arg?: Uint8Array[] }\n }\n\n if (!decoded.lsig) {\n throw new Error('Logic signature structure missing lsig field')\n }\n\n const lsig = decoded.lsig\n const logicSigAccount = new LogicSigAccount(lsig.l, lsig.arg)\n\n const signedTxn = signLogicSigTransactionObject(\n transaction,\n logicSigAccount,\n )\n return signedTxn.blob\n } else if (signature.type === 'secret_key') {\n // Convert signature.value (Record<string, number>) to Uint8Array\n const valueArray = signature.value as Record<string, number>\n const secretKey = new Uint8Array(Object.values(valueArray))\n const signedTxn = signTransaction(transaction, secretKey)\n return signedTxn.blob\n } else {\n throw new Error(`Unsupported signature type: ${signature.type}`)\n }\n } catch (error) {\n throw new Error(\n `Failed to re-sign transaction: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n}\n","/**\n * HTTP error with status code and response data\n */\nexport class HTTPError extends Error {\n constructor(\n public status: number,\n public statusText: string,\n public data: unknown,\n ) {\n super(`HTTP ${status} ${statusText}`)\n this.name = 'HTTPError'\n }\n}\n\n/**\n * Make an HTTP request and parse JSON response\n *\n * Simple wrapper around native fetch for API calls. Throws HTTPError for\n * non-2xx responses.\n *\n * @param url - The URL to request\n * @param options - Fetch options\n * @returns Parsed JSON response\n * @throws HTTPError if the response status is not ok\n */\nexport async function request<T>(\n url: string,\n options?: RequestInit,\n): Promise<T> {\n const response = await fetch(url, options)\n\n if (!response.ok) {\n let errorData: unknown\n\n try {\n errorData = await response.json()\n } catch {\n try {\n errorData = await response.text()\n } catch {\n errorData = 'Failed to parse error response'\n }\n }\n\n throw new HTTPError(\n response.status,\n response.statusText,\n JSON.stringify(errorData),\n )\n }\n\n return response.json() as Promise<T>\n}\n","import { Algodv2, isValidAddress, type TransactionSigner } from 'algosdk'\nimport { SwapComposer, type SignerFunction } from './composer'\nimport {\n DEFAULT_ALGOD_PORT,\n DEFAULT_ALGOD_TOKEN,\n DEFAULT_ALGOD_URI,\n DEFAULT_API_BASE_URL,\n DEFAULT_AUTO_OPT_IN,\n DEFAULT_FEE_BPS,\n DEFAULT_MAX_DEPTH,\n DEFAULT_MAX_GROUP_SIZE,\n DEPRECATED_PROTOCOLS,\n MAX_FEE_BPS,\n} from './constants'\nimport { request } from './utils'\nimport type {\n FetchQuoteResponse,\n FetchSwapTxnsResponse,\n DeflexConfig,\n DeflexConfigParams,\n FetchSwapTxnsParams,\n FetchSwapTxnsBody,\n FetchQuoteParams,\n DeflexQuote,\n} from './types'\n\n/**\n * Client for interacting with the Deflex order router API\n *\n * The DeflexClient provides methods to fetch swap quotes and create transaction composers\n * for executing swaps on the Algorand blockchain. It handles API communication, transaction\n * validation, and automatic asset/app opt-in detection.\n *\n * @example\n * ```typescript\n * const deflex = new DeflexClient({\n * apiKey: 'your-api-key',\n * })\n * ```\n *\n * @example\n * ```typescript\n * const deflex = new DeflexClient({\n * apiKey: 'your-api-key',\n * apiBaseUrl: 'https://deflex.txnlab.dev',\n * algodUri: 'https://mainnet-api.4160.nodely.dev/',\n * algodToken: '',\n * algodPort: 443,\n * referrerAddress: 'REFERRER_ADDRESS...',\n * feeBps: 15,\n * autoOptIn: false,\n * })\n * ```\n */\nexport class DeflexClient {\n private readonly config: DeflexConfig\n private readonly algodClient: Algodv2\n\n /**\n * Create a new DeflexClient instance\n *\n * @param config - Configuration parameters\n * @param config.apiKey - API key for Deflex API (required)\n * @param config.apiBaseUrl - Base URL for the Deflex API (default: https://deflex.txnlab.dev)\n * @param config.algodUri - Algod node URI (default: https://mainnet-api.4160.nodely.dev/)\n * @param config.algodToken - Algod node token (default: '')\n * @param config.algodPort - Algod node port (default: 443)\n * @param config.referrerAddress - Referrer address for fee sharing (receives 25% of swap fees)\n * @param config.feeBps - Fee in basis points (default: 15 = 0.15%, max: 300 = 3.00%)\n * @param config.autoOptIn - Automatically detect and add required opt-in transactions (default: false)\n */\n constructor(config: DeflexConfigParams) {\n // Validate and set config\n this.config = {\n apiKey: this.validateApiKey(config.apiKey),\n apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,\n algodUri: config.algodUri ?? DEFAULT_ALGOD_URI,\n algodToken: config.algodToken ?? DEFAULT_ALGOD_TOKEN,\n algodPort: config.algodPort ?? DEFAULT_ALGOD_PORT,\n referrerAddress: config.referrerAddress\n ? this.validateAddress(config.referrerAddress)\n : undefined,\n feeBps: this.validateFeeBps(config.feeBps ?? DEFAULT_FEE_BPS),\n autoOptIn: config.autoOptIn ?? DEFAULT_AUTO_OPT_IN,\n }\n\n // Create Algodv2 client\n this.algodClient = new Algodv2(\n this.config.algodToken,\n this.config.algodUri,\n this.config.algodPort,\n )\n }\n\n /**\n * Fetch a swap quote from the Deflex API\n *\n * Requests optimal swap routing from the Deflex API. The quote includes routing\n * information, price impact, required opt-ins, and an encrypted transaction payload.\n *\n * @param params - Parameters for the quote request\n * @param params.fromASAID - The ID of the asset to swap from\n * @param params.toASAID - The ID of the asset to swap to\n * @param params.amount - The amount of the asset to swap in base units\n * @param params.type - The type of the quote (default: 'fixed-input')\n * @param params.disabledProtocols - List of protocols to disable (default: [])\n * @param params.maxGroupSize - The maximum group size (default: 16)\n * @param params.maxDepth - The maximum depth (default: 4)\n * @param params.address - The address of the account that will perform the swap (recommended when using `config.autoOptIn` or `params.optIn`)\n * @param params.optIn - Whether to include asset opt-in transaction\n * - If true: API reduces maxGroupSize by 1 and includes opt-in (always included, even if not needed)\n * - If false: No opt-in transaction included\n * - If undefined: Falls back to `config.autoOptIn` behavior with account check (if `params.address` is provided)\n * @returns A FetchQuoteResponse object with routing information\n *\n * @example\n * ```typescript\n * const quote = await deflex.fetchQuote({\n * address: 'ABC...',\n * fromASAID: 0, // ALGO\n * toASAID: 31566704, // USDC\n * amount: 1_000_000, // 1 ALGO\n * })\n * ```\n */\n async fetchQuote(params: FetchQuoteParams): Promise<FetchQuoteResponse> {\n const {\n fromASAID,\n toASAID,\n amount,\n type = 'fixed-input',\n disabledProtocols = [],\n maxGroupSize = DEFAULT_MAX_GROUP_SIZE,\n maxDepth = DEFAULT_MAX_DEPTH,\n optIn,\n address,\n } = params\n\n // Always include deprecated protocols in disabled list\n const allDisabledProtocols = [\n ...new Set([...DEPRECATED_PROTOCOLS, ...disabledProtocols]),\n ]\n\n let includeOptIn = optIn\n if (includeOptIn === undefined && this.config.autoOptIn) {\n if (address) {\n includeOptIn = await this.needsAssetOptIn(\n this.validateAddress(address),\n toASAID,\n )\n } else {\n console.warn(\n 'autoOptIn is enabled but no address provided to fetchQuote(). Asset opt-in check skipped.',\n )\n }\n }\n\n const url = new URL(`${this.config.apiBaseUrl}/fetchQuote`)\n\n url.searchParams.append('apiKey', this.config.apiKey)\n url.searchParams.append('algodUri', this.config.algodUri)\n url.searchParams.append('algodToken', this.config.algodToken)\n url.searchParams.append('algodPort', String(this.config.algodPort))\n url.searchParams.append('feeBps', this.config.feeBps.toString())\n url.searchParams.append('fromASAID', BigInt(fromASAID).toString())\n url.searchParams.append('toASAID', BigInt(toASAID).toString())\n url.searchParams.append('amount', BigInt(amount).toString())\n url.searchParams.append('type', type)\n url.searchParams.append('disabledProtocols', allDisabledProtocols.join(','))\n url.searchParams.append('maxGroupSize', maxGroupSize.toString())\n url.searchParams.append('maxDepth', maxDepth.toString())\n\n if (typeof includeOptIn === 'boolean') {\n url.searchParams.append('optIn', String(includeOptIn))\n }\n\n if (this.config.referrerAddress) {\n url.searchParams.append('referrerAddress', this.config.referrerAddress)\n }\n\n return request<FetchQuoteResponse>(url.toString())\n }\n\n /**\n * Check if asset opt-in is required for the output asset\n *\n * Convenience method to determine if an address needs to opt into the output asset\n * of a swap. This is useful when you want to get a quote without requiring wallet\n * connection upfront, but need to know whether to set `optIn: true` in fetchQuote()\n * to ensure proper routing (as opt-ins reduce maxGroupSize by 1).\n *\n * Note: If you enable `config.autoOptIn`, this check is handled automatically when\n * an address is provided to fetchQuote().\n *\n * @param address - The address to check\n * @param assetId - The output asset ID to check\n * @returns True if asset opt-in is required, false otherwise (always false for ALGO)\n *\n * @example\n * ```typescript\n * // Check if opt-in needed for output asset before fetching quote\n * const needsOptIn = await deflex.needsAssetOptIn(userAddress, toAssetId)\n * const quote = await deflex.fetchQuote({\n * fromAssetId,\n * toAssetId,\n * amount,\n * optIn: needsOptIn,\n * })\n * ```\n */\n async needsAssetOptIn(\n address: string,\n assetId: number | bigint,\n ): Promise<boolean> {\n // Fetch account information\n const accountInfo = await this.algodClient.accountInformation(address).do()\n\n // Check if asset opt-in is required\n return (\n BigInt(assetId) !== 0n &&\n accountInfo?.assets?.find(\n (asset) => asset.assetId === BigInt(assetId),\n ) === undefined\n )\n }\n\n /**\n * Fetch swap transactions from the Deflex API\n *\n * Decrypts the quote payload and generates executable swap transactions for the\n * specified signer address with the given slippage tolerance.\n *\n * @param params - Parameters for the swap transaction request\n * @param params.quote - The quote response from fetchQuote()\n * @param params.address - The address of the signer\n * @param params.slippage - The slippage tolerance as a percentage (e.g., 1 for 1%)\n * @returns A FetchSwapTxnsResponse object with transaction data\n */\n async fetchSwapTransactions(\n params: FetchSwapTxnsParams,\n ): Promise<FetchSwapTxnsResponse> {\n const { quote, address, slippage } = params\n\n // Validate signer address\n this.validateAddress(address)\n\n const url = new URL(`${this.config.apiBaseUrl}/fetchExecuteSwapTxns`)\n\n const body: FetchSwapTxnsBody = {\n apiKey: this.config.apiKey,\n address,\n txnPayloadJSON: quote.txnPayload,\n slippage,\n }\n\n return request<FetchSwapTxnsResponse>(url.toString(), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })\n }\n\n /**\n * Fetch a quote and return an enhanced quote result\n *\n * This is the recommended way to fetch quotes. It returns an object that\n * extends the raw API response with additional metadata and type normalization.\n *\n * @param params - Parameters for the quote request\n * @param params.fromASAID - The ID of the asset to swap from\n * @param params.toASAID - The ID of the asset to swap to\n * @param params.amount - The amount of the asset to swap in base units\n * @param params.type - The type of the quote (default: 'fixed-input')\n * @param params.disabledProtocols - List of protocols to disable (default: [])\n * @param params.maxGroupSize - The maximum group size (default: 16)\n * @param params.maxDepth - The maximum depth (default: 4)\n * @param params.address - The address of the account that will perform the swap (recommended when using `config.autoOptIn` or `params.optIn`)\n * @param params.optIn - Whether to include asset opt-in transaction\n * @returns A DeflexQuote enhanced quote result\n *\n * @example\n * ```typescript\n * const quote = await deflex.newQuote({\n * address: 'ABC...',\n * fromASAID: 0,\n * toASAID: 31566704,\n * amount: 1_000_000,\n * })\n *\n * console.log(quote.quote) // bigint - quoted amount\n * console.log(quote.fromASAID) // number - input asset ID\n * console.log(quote.toASAID) // number - output asset ID\n * console.log(quote.amount) // bigint - original request amount\n * console.log(quote.createdAt) // number - timestamp\n * ```\n */\n async newQuote(params: FetchQuoteParams): Promise<DeflexQuote> {\n const response = await this.fetchQuote(params)\n\n return {\n ...response,\n quote: response.quote === '' ? 0n : BigInt(response.quote),\n amount: BigInt(params.amount),\n address: params.address ?? undefined,\n createdAt: Date.now(),\n }\n }\n\n /**\n * Create a SwapComposer instance\n *\n * This factory method creates a composer that allows you to add custom transactions\n * before and after the swap transactions, with automatic handling of pre-signed transactions\n * and opt-ins.\n *\n * @param config.quote - The quote result from newQuote() or raw API response from fetchQuote()\n * @param config.address - The address of the signer\n * @param config.slippage - The slippage tolerance\n * @param config.signer - Transaction signer function\n * @returns A SwapComposer instance ready for building transaction groups\n *\n * @example\n * ```typescript\n * // Basic swap\n * const quote = await deflex.newQuote({ ... })\n * await deflex.newSwap({ quote, address, slippage, signer })\n * .execute()\n * ```\n *\n * @example\n * ```typescript\n * // Advanced swap with custom transactions\n * const quote = await deflex.newQuote({ ... })\n * const swap = await deflex.newSwap({\n * quote,\n * address,\n * slippage,\n * signer,\n * })\n *\n * console.log(swap.getStatus()) // BUILDING\n *\n * const signedTxns = await swap\n * .addTransaction(beforeTxn)\n * .addSwapTransactions() // Adds swap transactions to the group\n * .addTransaction(afterTxn)\n * .sign()\n *\n * console.log(swap.getStatus()) // SIGNED\n *\n * const result = await swap.execute(waitRounds)\n * console.log(result.confirmedRound, result.txIds)\n *\n * console.log(swap.getStatus()) // COMMITTED\n * ```\n */\n async newSwap(config: {\n quote: DeflexQuote | FetchQuoteResponse\n address: string\n slippage: number\n signer: TransactionSigner | SignerFunction\n }): Promise<SwapComposer> {\n const { quote, address, slippage, signer } = config\n\n const swapResponse = await this.fetchSwapTransactions({\n quote,\n address,\n slippage,\n })\n\n // Create the composer\n const composer = new SwapComposer({\n quote,\n deflexTxns: swapResponse.txns,\n algodClient: this.algodClient,\n address,\n signer,\n })\n\n return composer\n }\n\n /**\n * Validates the API key\n */\n private validateApiKey(apiKey: string): string {\n if (!apiKey) {\n throw new Error('API key is required')\n }\n return apiKey\n }\n\n /**\n * Validates an Algorand address\n */\n private validateAddress(address: string): string {\n if (!isValidAddress(address)) {\n throw new Error(`Invalid Algorand address: ${address}`)\n }\n return address\n }\n\n /**\n * Validates the fee in basis points (max 300 = 3.00%)\n */\n private validateFeeBps(feeBps: number): number {\n if (feeBps < 0 || feeBps > MAX_FEE_BPS) {\n throw new Error(\n `Invalid fee: ${feeBps} basis points (must be between 0 and ${MAX_FEE_BPS})`,\n )\n }\n return feeBps\n }\n}\n"],"mappings":";;;;;;AAGA,IAAY,gDAAL;AACL;AACA;AACA;AACA;AACA;AACA;;;;;;;;AAQF,MAAa,uBAAuB,CAAC,UAAU,UAAU;;AAGzD,MAAa,oBAAoB;;AAGjC,MAAa,sBAAsB;;AAGnC,MAAa,qBAAqB;;AAGlC,MAAa,uBAAuB;;AAGpC,MAAa,kBAAkB;;AAG/B,MAAa,cAAc;;AAG3B,MAAa,yBAAyB;;AAGtC,MAAa,oBAAoB;;AAGjC,MAAa,sBAAsB;;AAGnC,MAAa,8BAA8B;;;;;;;ACR3C,IAAY,oEAAL;;AAEL;;AAGA;;AAGA;;AAGA;;AAGA;;;;;;;;;;;;;;;;;;;;;AAqCF,IAAa,eAAb,MAAa,aAAa;;CAExB,OAAO,iBAAyB;CAEhC,AAAQ,SAA6B,mBAAmB;CACxD,AAAQ,eAAkC,EAAE;CAC5C,AAAQ,wBAAwB;CAChC,AAAQ,aAA2B,EAAE;CACrC,AAAQ,QAAkB,EAAE;CAE5B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;;;;;;;;;;;;;;CAejB,YAAY,QAA4B;AAEtC,MAAI,CAAC,OAAO,MACV,OAAM,IAAI,MAAM,oBAAoB;AAEtC,MAAI,CAAC,OAAO,WACV,OAAM,IAAI,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ACpB;GACA,gBAAgB,MAAM;GACtB;GACD;AAED,SAAO,QAA+B,IAAI,UAAU,EAAE;GACpD,QAAQ;GACR,SAAS,EACP,gBAAgB,oBACjB;GACD,MAAM,KAAK,UAAU,KAAK;GAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCJ,MAAM,SAAS,QAAgD;EAC7D,MAAM,WAAW,MAAM,KAAK,WAAW,OAAO;AAE9C,SAAO;GACL,GAAG;GACH,OAAO,SAAS,UAAU,KAAK,KAAK,OAAO,SAAS,MAAM;GAC1D,QAAQ,OAAO,OAAO,OAAO;GAC7B,SAAS,OAAO,WAAW;GAC3B,WAAW,KAAK,KAAK;GACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDH,MAAM,QAAQ,QAKY;EACxB,MAAM,EAAE,OAAO,SAAS,UAAU,WAAW;AAiB7C,SARiB,IAAI,aAAa;GAChC;GACA,aATmB,MAAM,KAAK,sBAAsB;IACpD;IACA;IACA;IACD,CAAC,EAKyB;GACzB,aAAa,KAAK;GAClB;GACA;GACD,CAAC;;;;;CAQJ,AAAQ,eAAe,QAAwB;AAC7C,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,sBAAsB;AAExC,SAAO;;;;;CAMT,AAAQ,gBAAgB,SAAyB;AAC/C,MAAI,CAAC,eAAe,QAAQ,CAC1B,OAAM,IAAI,MAAM,6BAA6B,UAAU;AAEzD,SAAO;;;;;CAMT,AAAQ,eAAe,QAAwB;AAC7C,MAAI,SAAS,KAAK,SAAS,YACzB,OAAM,IAAI,MACR,gBAAgB,OAAO,uCAAuC,YAAY,GAC3E;AAEH,SAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["swapTxns: TransactionWithSigner[]","status: number","statusText: string","data: unknown","errorData: unknown","body: FetchSwapTxnsBody"],"sources":["../src/constants.ts","../src/composer.ts","../src/utils.ts","../src/client.ts"],"sourcesContent":["/**\n * Supported DEX protocols for swap routing\n */\nexport enum Protocol {\n TinymanV2 = 'TinymanV2',\n Algofi = 'Algofi',\n Algomint = 'Algomint',\n Pact = 'Pact',\n Folks = 'Folks',\n TAlgo = 'TAlgo',\n}\n\n/**\n * Deprecated protocols that are automatically excluded from routing\n *\n * @internal\n */\nexport const DEPRECATED_PROTOCOLS = ['Humble', 'Tinyman'] as const\n\n/** Default Algod node URI for mainnet */\nexport const DEFAULT_ALGOD_URI = 'https://mainnet-api.4160.nodely.dev/'\n\n/** Default Algod node token (empty for public nodes) */\nexport const DEFAULT_ALGOD_TOKEN = ''\n\n/** Default Algod node port */\nexport const DEFAULT_ALGOD_PORT = 443\n\n/** Default Deflex API base URL */\nexport const DEFAULT_API_BASE_URL = 'https://deflex.txnlab.dev/api'\n\n/** Default fee in basis points (0.15%) */\nexport const DEFAULT_FEE_BPS = 15\n\n/** Maximum allowed fee in basis points (3.00%) */\nexport const MAX_FEE_BPS = 300\n\n/** Default maximum transaction group size */\nexport const DEFAULT_MAX_GROUP_SIZE = 16\n\n/** Default maximum routing depth (number of hops) */\nexport const DEFAULT_MAX_DEPTH = 4\n\n/** Default auto opt-in setting (automatic asset/app opt-in detection) */\nexport const DEFAULT_AUTO_OPT_IN = false\n\n/** Default number of rounds to wait for transaction confirmation */\nexport const DEFAULT_CONFIRMATION_ROUNDS = 4\n","import {\n AtomicTransactionComposer,\n decodeUnsignedTransaction,\n isValidAddress,\n LogicSigAccount,\n makeApplicationOptInTxnFromObject,\n msgpackRawDecode,\n signLogicSigTransactionObject,\n signTransaction,\n Transaction,\n type ABIResult,\n type Algodv2,\n type TransactionSigner,\n type TransactionWithSigner,\n} from 'algosdk'\nimport { DEFAULT_CONFIRMATION_ROUNDS } from './constants'\nimport type {\n FetchQuoteResponse,\n DeflexTransaction,\n DeflexSignature,\n DeflexQuote,\n MethodCall,\n} from './types'\n\n/**\n * A transaction signer function that supports both standard algosdk.TransactionSigner\n * and ARC-1 compliant signers that may return null for unsigned transactions.\n *\n * @param txnGroup - The complete transaction group to sign\n * @param indexesToSign - Array of indexes indicating which transactions need signing\n * @returns Array of signed transactions (may include nulls for ARC-1 compliant wallets)\n */\nexport type SignerFunction = (\n txnGroup: Transaction[],\n indexesToSign: number[],\n) => Promise<(Uint8Array | null)[]>\n\n/**\n * Status of the SwapComposer transaction group lifecycle\n */\nexport enum SwapComposerStatus {\n /** The atomic group is still under construction. */\n BUILDING,\n\n /** The atomic group has been finalized, but not yet signed. */\n BUILT,\n\n /** The atomic group has been finalized and signed, but not yet submitted to the network. */\n SIGNED,\n\n /** The atomic group has been finalized, signed, and submitted to the network. */\n SUBMITTED,\n\n /** The atomic group has been finalized, signed, submitted, and successfully committed to a block. */\n COMMITTED,\n}\n\n/**\n * Configuration for creating a SwapComposer instance\n */\nexport interface SwapComposerConfig {\n /** The quote response from fetchQuote() or newQuote() */\n readonly quote: FetchQuoteResponse | DeflexQuote\n /** The swap transactions from fetchSwapTransactions() */\n readonly deflexTxns: DeflexTransaction[]\n /** Algodv2 client instance */\n readonly algodClient: Algodv2\n /** The address of the account that will sign transactions */\n readonly address: string\n /** Transaction signer function */\n readonly signer: TransactionSigner | SignerFunction\n}\n\n/**\n * Composer for building and executing atomic swap transaction groups\n *\n * The SwapComposer allows you to build complex transaction groups by adding custom\n * transactions before and after swap transactions. It handles pre-signed transactions,\n * automatic app opt-ins, and provides a fluent API for transaction group construction.\n *\n * @example\n * ```typescript\n * const quote = await deflex.fetchQuote({ ... })\n * const composer = await deflex.newSwap({ quote, address, slippage, signer })\n *\n * await composer\n * .addTransaction(customTxn)\n * .addSwapTransactions()\n * .execute()\n * ```\n */\nexport class SwapComposer {\n /** The ATC used to compose the group */\n private atc = new AtomicTransactionComposer()\n\n /** The maximum size of an atomic transaction group. */\n static MAX_GROUP_SIZE: number = AtomicTransactionComposer.MAX_GROUP_SIZE\n\n /** Whether the swap transactions have been added to the atomic group. */\n private swapTransactionsAdded = false\n\n private readonly requiredAppOptIns: number[]\n private readonly deflexTxns: DeflexTransaction[]\n private readonly algodClient: Algodv2\n private readonly address: string\n private readonly signer: TransactionSigner | SignerFunction\n\n /**\n * Create a new SwapComposer instance\n *\n * Note: Most developers should use DeflexClient.newSwap() instead of constructing\n * this directly, as the factory method handles fetching swap transactions automatically.\n *\n * @param config - Configuration for the composer\n * @param config.requiredAppOptIns - The quote response from fetchQuote()\n * @param config.deflexTxns - The swap transactions from fetchSwapTransactions()\n * @param config.algodClient - Algodv2 client instance\n * @param config.address - The address of the account that will sign transactions\n * @param config.signer - Transaction signer function\n */\n constructor(config: SwapComposerConfig) {\n // Validate required parameters\n if (!config.quote) {\n throw new Error('Quote is required')\n }\n if (!config.deflexTxns) {\n throw new Error('Swap transactions are required')\n }\n if (config.deflexTxns.length === 0) {\n throw new Error('Swap transactions array cannot be empty')\n }\n if (!config.algodClient) {\n throw new Error('Algodv2 client instance is required')\n }\n if (!config.signer) {\n throw new Error('Signer is required')\n }\n\n this.requiredAppOptIns = config.quote.requiredAppOptIns\n this.deflexTxns = config.deflexTxns\n this.algodClient = config.algodClient\n this.address = this.validateAddress(config.address)\n this.signer = config.signer\n }\n\n /**\n * Get the status of this composer's transaction group\n *\n * @returns The current status of the transaction group\n */\n getStatus(): SwapComposerStatus {\n return this.atc.getStatus() as unknown as SwapComposerStatus\n }\n\n /**\n * Get the number of transactions currently in this atomic group\n *\n * @returns The number of transactions in the group\n */\n count(): number {\n return this.atc.count()\n }\n\n /**\n * Add a transaction to the atomic group\n *\n * Transactions are added in the order methods are called. For example:\n * ```typescript\n * composer\n * .addTransaction(txn1) // Added first\n * .addSwapTransactions() // Added second\n * .addTransaction(txn2) // Added third\n * ```\n *\n * @param transaction - The transaction to add\n * @returns This composer instance for chaining\n * @throws Error if the composer is not in the BUILDING status\n * @throws Error if the maximum group size is exceeded\n */\n addTransaction(transaction: Transaction, signer = this.defaultSigner): this {\n this.atc.addTransaction({ txn: transaction, signer })\n return this\n }\n\n /**\n * Add a method call to the atomic group\n *\n * The `signer` property in the `methodCall` parameter is optional. If not provided,\n * the signer will default to the one passed as the second parameter, or the\n * configured signer from the constructor if no second parameter is provided.\n *\n * @param methodCall - The method call to add\n * @param signer - The signer to use for the method call (defaults to constructor signer)\n * @returns This composer instance for chaining\n */\n addMethodCall(methodCall: MethodCall, signer = this.defaultSigner): this {\n this.atc.addMethodCall({\n ...methodCall,\n signer: methodCall.signer ?? signer,\n })\n return this\n }\n\n /**\n * Add swap transactions to the atomic group\n *\n * This method automatically processes required app opt-ins and adds all swap\n * transactions from the quote. Can only be called once per composer instance.\n *\n * @returns This composer instance for chaining\n * @throws Error if the swap transactions have already been added\n * @throws Error if the composer is not in the BUILDING status\n * @throws Error if the maximum group size is exceeded\n */\n async addSwapTransactions(): Promise<this> {\n if (this.swapTransactionsAdded) {\n throw new Error('Swap transactions have already been added')\n }\n\n if (this.getStatus() !== SwapComposerStatus.BUILDING) {\n throw new Error(\n 'Cannot add swap transactions when composer status is not BUILDING',\n )\n }\n\n const processedTxns = await this.processSwapTransactions()\n const newLength = this.atc.count() + processedTxns.length\n\n if (newLength > SwapComposer.MAX_GROUP_SIZE) {\n throw new Error(\n `Adding swap transactions exceeds the maximum atomic group size of ${SwapComposer.MAX_GROUP_SIZE}`,\n )\n }\n\n for (const txnWithSigner of processedTxns) {\n this.atc.addTransaction(txnWithSigner)\n }\n\n this.swapTransactionsAdded = true\n return this\n }\n\n /**\n * Finalize the transaction group by assigning group IDs\n *\n * This method builds the atomic transaction group, assigning group IDs to all transactions\n * if there is more than one transaction. After calling this method, the composer's status\n * will be at least BUILT.\n *\n * @returns Array of transactions with their associated signers\n *\n * @throws Error if the group contains 0 transactions\n *\n * @example\n * ```typescript\n * const composer = await deflex.newSwap({ quote, address, slippage, signer })\n * composer.addTransaction(customTxn)\n *\n * // Build the group to inspect transactions before signing\n * const txnsWithSigners = composer.buildGroup()\n * console.log('Group ID:', txnsWithSigners[0].txn.group)\n * console.log('Group length:', txnsWithSigners.length)\n * console.log('Status:', composer.getStatus()) // BUILT\n * ```\n */\n buildGroup(): TransactionWithSigner[] {\n return this.atc.buildGroup()\n }\n\n /**\n * Sign the transaction group\n *\n * Automatically adds swap transactions if not already added, builds the atomic group,\n * and signs all transactions using the configured signer.\n *\n * @returns A promise that resolves to an array of signed transaction blobs\n *\n * @example\n * ```typescript\n * const signedTxns = await composer.sign()\n * ```\n */\n async sign(): Promise<Uint8Array[]> {\n if (this.getStatus() >= SwapComposerStatus.SIGNED) {\n return this.atc.gatherSignatures()\n }\n\n // Auto-add swap transactions if needed\n if (!this.swapTransactionsAdded) {\n await this.addSwapTransactions()\n }\n\n return await this.atc.gatherSignatures()\n }\n\n /**\n * Submit the signed transactions to the network\n *\n * This method signs the transaction group (if not already signed) and submits\n * it to the Algorand network. Does not wait for confirmation.\n *\n * @returns The transaction IDs\n * @throws Error if the transaction group has already been submitted\n *\n * @example\n * ```typescript\n * const txIds = await composer.submit()\n * console.log('Submitted transactions:', txIds)\n * ```\n */\n async submit(): Promise<string[]> {\n // Auto-add swap transactions if needed (maintains backward compatibility)\n if (!this.swapTransactionsAdded) {\n await this.addSwapTransactions()\n }\n\n return this.atc.submit(this.algodClient)\n }\n\n /**\n * Execute the swap\n *\n * Signs the transaction group, submits it to the network, and waits for confirmation.\n * This is the primary method for executing swaps and combines sign(), submit(), and\n * waitForConfirmation() into a single call.\n *\n * @param waitRounds - The number of rounds to wait for confirmation (default: 4)\n * @returns Object containing the confirmed round and transaction IDs\n * @throws Error if the transaction group has already been committed\n *\n * @example\n * ```typescript\n * const result = await composer.execute()\n * console.log(`Confirmed in round ${result.confirmedRound}`)\n * console.log('Transaction IDs:', result.txIds)\n * ```\n */\n async execute(waitRounds: number = DEFAULT_CONFIRMATION_ROUNDS): Promise<{\n confirmedRound: bigint\n txIds: string[]\n methodResults: ABIResult[]\n }> {\n // Auto-add swap transactions if needed (maintains backward compatibility)\n if (!this.swapTransactionsAdded) {\n await this.addSwapTransactions()\n }\n\n const { txIDs, ...result } = await this.atc.execute(\n this.algodClient,\n waitRounds,\n )\n\n return {\n ...result,\n txIds: txIDs,\n }\n }\n\n /**\n * Validates an Algorand address\n */\n private validateAddress(address: string): string {\n if (!isValidAddress(address)) {\n throw new Error(`Invalid Algorand address: ${address}`)\n }\n return address\n }\n\n /**\n * Processes app opt-ins and decodes swap transactions from API response\n */\n private async processSwapTransactions(): Promise<TransactionWithSigner[]> {\n const appOptIns = await this.processRequiredAppOptIns()\n\n const swapTxns: TransactionWithSigner[] = []\n for (let i = 0; i < this.deflexTxns.length; i++) {\n const deflexTxn = this.deflexTxns[i]\n if (!deflexTxn) continue\n\n try {\n const txnBytes = Buffer.from(deflexTxn.data, 'base64')\n const txn = decodeUnsignedTransaction(txnBytes)\n delete txn.group\n\n if (deflexTxn.signature !== false) {\n // Pre-signed transaction - use custom Deflex signer\n swapTxns.push({\n txn,\n signer: this.createDeflexSigner(deflexTxn.signature),\n })\n } else {\n // User transaction - use configured signer\n swapTxns.push({\n txn,\n signer: this.defaultSigner,\n })\n }\n } catch (error) {\n throw new Error(\n `Failed to process swap transaction at index ${i}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n\n return [...appOptIns, ...swapTxns]\n }\n\n /**\n * Creates opt-in transactions for apps the user hasn't opted into yet\n */\n private async processRequiredAppOptIns(): Promise<TransactionWithSigner[]> {\n // Fetch account information\n const accountInfo = await this.algodClient\n .accountInformation(this.address)\n .do()\n\n // Check app opt-ins\n const userApps =\n accountInfo?.appsLocalState?.map((app) => Number(app.id)) || []\n const appsToOptIn = this.requiredAppOptIns.filter(\n (appId) => !userApps.includes(appId),\n )\n\n if (appsToOptIn.length === 0) return []\n\n const suggestedParams = await this.algodClient.getTransactionParams().do()\n\n return appsToOptIn.map((appId) => ({\n txn: makeApplicationOptInTxnFromObject({\n sender: this.address,\n appIndex: appId,\n suggestedParams,\n }),\n signer: this.defaultSigner,\n }))\n }\n\n /**\n * The default signer function that uses the configured signer\n */\n private defaultSigner: TransactionSigner = async (\n txnGroup: Transaction[],\n indexesToSign: number[],\n ) => {\n const result = await this.signer(txnGroup, indexesToSign)\n return result.filter((txn): txn is Uint8Array => txn !== null)\n }\n\n /**\n * Creates a TransactionSigner function for Deflex pre-signed transactions\n */\n private createDeflexSigner(signature: DeflexSignature): TransactionSigner {\n return async (\n txnGroup: Transaction[],\n indexesToSign: number[],\n ): Promise<Uint8Array[]> => {\n return indexesToSign.map((i) => {\n const txn = txnGroup[i]\n if (!txn) throw new Error(`Transaction at index ${i} not found`)\n return this.signDeflexTransaction(txn, signature)\n })\n }\n }\n\n /**\n * Re-signs a Deflex transaction using the provided logic signature or secret key\n */\n private signDeflexTransaction(\n transaction: Transaction,\n signature: DeflexSignature,\n ): Uint8Array {\n try {\n if (signature.type === 'logic_signature') {\n // Decode the signature value to extract the logic signature\n const valueArray = signature.value as Record<string, number>\n const valueBytes = new Uint8Array(Object.values(valueArray))\n const decoded = msgpackRawDecode(valueBytes) as {\n lsig?: { l: Uint8Array; arg?: Uint8Array[] }\n }\n\n if (!decoded.lsig) {\n throw new Error('Logic signature structure missing lsig field')\n }\n\n const lsig = decoded.lsig\n const logicSigAccount = new LogicSigAccount(lsig.l, lsig.arg)\n\n const signedTxn = signLogicSigTransactionObject(\n transaction,\n logicSigAccount,\n )\n return signedTxn.blob\n } else if (signature.type === 'secret_key') {\n // Convert signature.value (Record<string, number>) to Uint8Array\n const valueArray = signature.value as Record<string, number>\n const secretKey = new Uint8Array(Object.values(valueArray))\n const signedTxn = signTransaction(transaction, secretKey)\n return signedTxn.blob\n } else {\n throw new Error(`Unsupported signature type: ${signature.type}`)\n }\n } catch (error) {\n throw new Error(\n `Failed to re-sign transaction: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n}\n","/**\n * HTTP error with status code and response data\n */\nexport class HTTPError extends Error {\n constructor(\n public status: number,\n public statusText: string,\n public data: unknown,\n ) {\n super(`HTTP ${status} ${statusText}`)\n this.name = 'HTTPError'\n }\n}\n\n/**\n * Make an HTTP request and parse JSON response\n *\n * Simple wrapper around native fetch for API calls. Throws HTTPError for\n * non-2xx responses.\n *\n * @param url - The URL to request\n * @param options - Fetch options\n * @returns Parsed JSON response\n * @throws HTTPError if the response status is not ok\n */\nexport async function request<T>(\n url: string,\n options?: RequestInit,\n): Promise<T> {\n const response = await fetch(url, options)\n\n if (!response.ok) {\n let errorData: unknown\n\n try {\n errorData = await response.json()\n } catch {\n try {\n errorData = await response.text()\n } catch {\n errorData = 'Failed to parse error response'\n }\n }\n\n throw new HTTPError(\n response.status,\n response.statusText,\n JSON.stringify(errorData),\n )\n }\n\n return response.json() as Promise<T>\n}\n","import { Algodv2, isValidAddress, type TransactionSigner } from 'algosdk'\nimport { SwapComposer, type SignerFunction } from './composer'\nimport {\n DEFAULT_ALGOD_PORT,\n DEFAULT_ALGOD_TOKEN,\n DEFAULT_ALGOD_URI,\n DEFAULT_API_BASE_URL,\n DEFAULT_AUTO_OPT_IN,\n DEFAULT_FEE_BPS,\n DEFAULT_MAX_DEPTH,\n DEFAULT_MAX_GROUP_SIZE,\n DEPRECATED_PROTOCOLS,\n MAX_FEE_BPS,\n} from './constants'\nimport { request } from './utils'\nimport type {\n FetchQuoteResponse,\n FetchSwapTxnsResponse,\n DeflexConfig,\n DeflexConfigParams,\n FetchSwapTxnsParams,\n FetchSwapTxnsBody,\n FetchQuoteParams,\n DeflexQuote,\n} from './types'\n\n/**\n * Client for interacting with the Deflex order router API\n *\n * The DeflexClient provides methods to fetch swap quotes and create transaction composers\n * for executing swaps on the Algorand blockchain. It handles API communication, transaction\n * validation, and automatic asset/app opt-in detection.\n *\n * @example\n * ```typescript\n * const deflex = new DeflexClient({\n * apiKey: 'your-api-key',\n * })\n * ```\n *\n * @example\n * ```typescript\n * const deflex = new DeflexClient({\n * apiKey: 'your-api-key',\n * apiBaseUrl: 'https://deflex.txnlab.dev',\n * algodUri: 'https://mainnet-api.4160.nodely.dev/',\n * algodToken: '',\n * algodPort: 443,\n * referrerAddress: 'REFERRER_ADDRESS...',\n * feeBps: 15,\n * autoOptIn: false,\n * })\n * ```\n */\nexport class DeflexClient {\n private readonly config: DeflexConfig\n private readonly algodClient: Algodv2\n\n /**\n * Create a new DeflexClient instance\n *\n * @param config - Configuration parameters\n * @param config.apiKey - API key for Deflex API (required)\n * @param config.apiBaseUrl - Base URL for the Deflex API (default: https://deflex.txnlab.dev)\n * @param config.algodUri - Algod node URI (default: https://mainnet-api.4160.nodely.dev/)\n * @param config.algodToken - Algod node token (default: '')\n * @param config.algodPort - Algod node port (default: 443)\n * @param config.referrerAddress - Referrer address for fee sharing (receives 25% of swap fees)\n * @param config.feeBps - Fee in basis points (default: 15 = 0.15%, max: 300 = 3.00%)\n * @param config.autoOptIn - Automatically detect and add required opt-in transactions (default: false)\n */\n constructor(config: DeflexConfigParams) {\n // Validate and set config\n this.config = {\n apiKey: this.validateApiKey(config.apiKey),\n apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,\n algodUri: config.algodUri ?? DEFAULT_ALGOD_URI,\n algodToken: config.algodToken ?? DEFAULT_ALGOD_TOKEN,\n algodPort: config.algodPort ?? DEFAULT_ALGOD_PORT,\n referrerAddress: config.referrerAddress\n ? this.validateAddress(config.referrerAddress)\n : undefined,\n feeBps: this.validateFeeBps(config.feeBps ?? DEFAULT_FEE_BPS),\n autoOptIn: config.autoOptIn ?? DEFAULT_AUTO_OPT_IN,\n }\n\n // Create Algodv2 client\n this.algodClient = new Algodv2(\n this.config.algodToken,\n this.config.algodUri,\n this.config.algodPort,\n )\n }\n\n /**\n * Fetch a swap quote from the Deflex API\n *\n * Requests optimal swap routing from the Deflex API. The quote includes routing\n * information, price impact, required opt-ins, and an encrypted transaction payload.\n *\n * @param params - Parameters for the quote request\n * @param params.fromASAID - The ID of the asset to swap from\n * @param params.toASAID - The ID of the asset to swap to\n * @param params.amount - The amount of the asset to swap in base units\n * @param params.type - The type of the quote (default: 'fixed-input')\n * @param params.disabledProtocols - List of protocols to disable (default: [])\n * @param params.maxGroupSize - The maximum group size (default: 16)\n * @param params.maxDepth - The maximum depth (default: 4)\n * @param params.address - The address of the account that will perform the swap (recommended when using `config.autoOptIn` or `params.optIn`)\n * @param params.optIn - Whether to include asset opt-in transaction\n * - If true: API reduces maxGroupSize by 1 and includes opt-in (always included, even if not needed)\n * - If false: No opt-in transaction included\n * - If undefined: Falls back to `config.autoOptIn` behavior with account check (if `params.address` is provided)\n * @returns A FetchQuoteResponse object with routing information\n *\n * @example\n * ```typescript\n * const quote = await deflex.fetchQuote({\n * address: 'ABC...',\n * fromASAID: 0, // ALGO\n * toASAID: 31566704, // USDC\n * amount: 1_000_000, // 1 ALGO\n * })\n * ```\n */\n async fetchQuote(params: FetchQuoteParams): Promise<FetchQuoteResponse> {\n const {\n fromASAID,\n toASAID,\n amount,\n type = 'fixed-input',\n disabledProtocols = [],\n maxGroupSize = DEFAULT_MAX_GROUP_SIZE,\n maxDepth = DEFAULT_MAX_DEPTH,\n optIn,\n address,\n } = params\n\n // Always include deprecated protocols in disabled list\n const allDisabledProtocols = [\n ...new Set([...DEPRECATED_PROTOCOLS, ...disabledProtocols]),\n ]\n\n let includeOptIn = optIn\n if (includeOptIn === undefined && this.config.autoOptIn) {\n if (address) {\n includeOptIn = await this.needsAssetOptIn(\n this.validateAddress(address),\n toASAID,\n )\n } else {\n console.warn(\n 'autoOptIn is enabled but no address provided to fetchQuote(). Asset opt-in check skipped.',\n )\n }\n }\n\n const url = new URL(`${this.config.apiBaseUrl}/fetchQuote`)\n\n url.searchParams.append('apiKey', this.config.apiKey)\n url.searchParams.append('algodUri', this.config.algodUri)\n url.searchParams.append('algodToken', this.config.algodToken)\n url.searchParams.append('algodPort', String(this.config.algodPort))\n url.searchParams.append('feeBps', this.config.feeBps.toString())\n url.searchParams.append('fromASAID', BigInt(fromASAID).toString())\n url.searchParams.append('toASAID', BigInt(toASAID).toString())\n url.searchParams.append('amount', BigInt(amount).toString())\n url.searchParams.append('type', type)\n url.searchParams.append('disabledProtocols', allDisabledProtocols.join(','))\n url.searchParams.append('maxGroupSize', maxGroupSize.toString())\n url.searchParams.append('maxDepth', maxDepth.toString())\n\n if (typeof includeOptIn === 'boolean') {\n url.searchParams.append('optIn', String(includeOptIn))\n }\n\n if (this.config.referrerAddress) {\n url.searchParams.append('referrerAddress', this.config.referrerAddress)\n }\n\n return request<FetchQuoteResponse>(url.toString())\n }\n\n /**\n * Check if asset opt-in is required for the output asset\n *\n * Convenience method to determine if an address needs to opt into the output asset\n * of a swap. This is useful when you want to get a quote without requiring wallet\n * connection upfront, but need to know whether to set `optIn: true` in fetchQuote()\n * to ensure proper routing (as opt-ins reduce maxGroupSize by 1).\n *\n * Note: If you enable `config.autoOptIn`, this check is handled automatically when\n * an address is provided to fetchQuote().\n *\n * @param address - The address to check\n * @param assetId - The output asset ID to check\n * @returns True if asset opt-in is required, false otherwise (always false for ALGO)\n *\n * @example\n * ```typescript\n * // Check if opt-in needed for output asset before fetching quote\n * const needsOptIn = await deflex.needsAssetOptIn(userAddress, toAssetId)\n * const quote = await deflex.fetchQuote({\n * fromAssetId,\n * toAssetId,\n * amount,\n * optIn: needsOptIn,\n * })\n * ```\n */\n async needsAssetOptIn(\n address: string,\n assetId: number | bigint,\n ): Promise<boolean> {\n // Fetch account information\n const accountInfo = await this.algodClient.accountInformation(address).do()\n\n // Check if asset opt-in is required\n return (\n BigInt(assetId) !== 0n &&\n accountInfo?.assets?.find(\n (asset) => asset.assetId === BigInt(assetId),\n ) === undefined\n )\n }\n\n /**\n * Fetch swap transactions from the Deflex API\n *\n * Decrypts the quote payload and generates executable swap transactions for the\n * specified signer address with the given slippage tolerance.\n *\n * @param params - Parameters for the swap transaction request\n * @param params.quote - The quote response from fetchQuote()\n * @param params.address - The address of the signer\n * @param params.slippage - The slippage tolerance as a percentage (e.g., 1 for 1%)\n * @returns A FetchSwapTxnsResponse object with transaction data\n */\n async fetchSwapTransactions(\n params: FetchSwapTxnsParams,\n ): Promise<FetchSwapTxnsResponse> {\n const { quote, address, slippage } = params\n\n // Validate signer address\n this.validateAddress(address)\n\n const url = new URL(`${this.config.apiBaseUrl}/fetchExecuteSwapTxns`)\n\n const body: FetchSwapTxnsBody = {\n apiKey: this.config.apiKey,\n address,\n txnPayloadJSON: quote.txnPayload,\n slippage,\n }\n\n return request<FetchSwapTxnsResponse>(url.toString(), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })\n }\n\n /**\n * Fetch a quote and return an enhanced quote result\n *\n * This is the recommended way to fetch quotes. It returns an object that\n * extends the raw API response with additional metadata and type normalization.\n *\n * @param params - Parameters for the quote request\n * @param params.fromASAID - The ID of the asset to swap from\n * @param params.toASAID - The ID of the asset to swap to\n * @param params.amount - The amount of the asset to swap in base units\n * @param params.type - The type of the quote (default: 'fixed-input')\n * @param params.disabledProtocols - List of protocols to disable (default: [])\n * @param params.maxGroupSize - The maximum group size (default: 16)\n * @param params.maxDepth - The maximum depth (default: 4)\n * @param params.address - The address of the account that will perform the swap (recommended when using `config.autoOptIn` or `params.optIn`)\n * @param params.optIn - Whether to include asset opt-in transaction\n * @returns A DeflexQuote enhanced quote result\n *\n * @example\n * ```typescript\n * const quote = await deflex.newQuote({\n * address: 'ABC...',\n * fromASAID: 0,\n * toASAID: 31566704,\n * amount: 1_000_000,\n * })\n *\n * console.log(quote.quote) // bigint - quoted amount\n * console.log(quote.fromASAID) // number - input asset ID\n * console.log(quote.toASAID) // number - output asset ID\n * console.log(quote.amount) // bigint - original request amount\n * console.log(quote.createdAt) // number - timestamp\n * ```\n */\n async newQuote(params: FetchQuoteParams): Promise<DeflexQuote> {\n const response = await this.fetchQuote(params)\n\n return {\n ...response,\n quote: response.quote === '' ? 0n : BigInt(response.quote),\n amount: BigInt(params.amount),\n address: params.address ?? undefined,\n createdAt: Date.now(),\n }\n }\n\n /**\n * Create a SwapComposer instance\n *\n * This factory method creates a composer that allows you to add custom transactions\n * before and after the swap transactions, with automatic handling of pre-signed transactions\n * and opt-ins.\n *\n * @param config.quote - The quote result from newQuote() or raw API response from fetchQuote()\n * @param config.address - The address of the signer\n * @param config.slippage - The slippage tolerance\n * @param config.signer - Transaction signer function\n * @returns A SwapComposer instance ready for building transaction groups\n *\n * @example\n * ```typescript\n * // Basic swap\n * const quote = await deflex.newQuote({ ... })\n * await deflex.newSwap({ quote, address, slippage, signer })\n * .execute()\n * ```\n *\n * @example\n * ```typescript\n * // Advanced swap with custom transactions\n * const quote = await deflex.newQuote({ ... })\n * const swap = await deflex.newSwap({\n * quote,\n * address,\n * slippage,\n * signer,\n * })\n *\n * console.log(swap.getStatus()) // BUILDING\n *\n * const signedTxns = await swap\n * .addTransaction(beforeTxn)\n * .addSwapTransactions() // Adds swap transactions to the group\n * .addTransaction(afterTxn)\n * .sign()\n *\n * console.log(swap.getStatus()) // SIGNED\n *\n * const result = await swap.execute(waitRounds)\n * console.log(result.confirmedRound, result.txIds)\n *\n * console.log(swap.getStatus()) // COMMITTED\n * ```\n */\n async newSwap(config: {\n quote: DeflexQuote | FetchQuoteResponse\n address: string\n slippage: number\n signer: TransactionSigner | SignerFunction\n }): Promise<SwapComposer> {\n const { quote, address, slippage, signer } = config\n\n const swapResponse = await this.fetchSwapTransactions({\n quote,\n address,\n slippage,\n })\n\n // Create the composer\n const composer = new SwapComposer({\n quote,\n deflexTxns: swapResponse.txns,\n algodClient: this.algodClient,\n address,\n signer,\n })\n\n return composer\n }\n\n /**\n * Validates the API key\n */\n private validateApiKey(apiKey: string): string {\n if (!apiKey) {\n throw new Error('API key is required')\n }\n return apiKey\n }\n\n /**\n * Validates an Algorand address\n */\n private validateAddress(address: string): string {\n if (!isValidAddress(address)) {\n throw new Error(`Invalid Algorand address: ${address}`)\n }\n return address\n }\n\n /**\n * Validates the fee in basis points (max 300 = 3.00%)\n */\n private validateFeeBps(feeBps: number): number {\n if (feeBps < 0 || feeBps > MAX_FEE_BPS) {\n throw new Error(\n `Invalid fee: ${feeBps} basis points (must be between 0 and ${MAX_FEE_BPS})`,\n )\n }\n return feeBps\n }\n}\n"],"mappings":";;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AAM;GACtB;GACD;AAED,SAAO,QAA+B,IAAI,UAAU,EAAE;GACpD,QAAQ;GACR,SAAS,EACP,gBAAgB,oBACjB;GACD,MAAM,KAAK,UAAU,KAAK;GAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCJ,MAAM,SAAS,QAAgD;EAC7D,MAAM,WAAW,MAAM,KAAK,WAAW,OAAO;AAE9C,SAAO;GACL,GAAG;GACH,OAAO,SAAS,UAAU,KAAK,KAAK,OAAO,SAAS,MAAM;GAC1D,QAAQ,OAAO,OAAO,OAAO;GAC7B,SAAS,OAAO,WAAW;GAC3B,WAAW,KAAK,KAAK;GACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDH,MAAM,QAAQ,QAKY;EACxB,MAAM,EAAE,OAAO,SAAS,UAAU,WAAW;AAiB7C,SARiB,IAAI,aAAa;GAChC;GACA,aATmB,MAAM,KAAK,sBAAsB;IACpD;IACA;IACA;IACD,CAAC,EAKyB;GACzB,aAAa,KAAK;GAClB;GACA;GACD,CAAC;;;;;CAQJ,AAAQ,eAAe,QAAwB;AAC7C,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,sBAAsB;AAExC,SAAO;;;;;CAMT,AAAQ,gBAAgB,SAAyB;AAC/C,MAAI,CAAC,eAAe,QAAQ,CAC1B,OAAM,IAAI,MAAM,6BAA6B,UAAU;AAEzD,SAAO;;;;;CAMT,AAAQ,eAAe,QAAwB;AAC7C,MAAI,SAAS,KAAK,SAAS,YACzB,OAAM,IAAI,MACR,gBAAgB,OAAO,uCAAuC,YAAY,GAC3E;AAEH,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txnlab/deflex",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "TypeScript/JavaScript SDK for Deflex Order Router - smart order routing and DEX aggregation on Algorand",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"algorand",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"typecheck": "tsc --noEmit"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "
|
|
57
|
-
"@vitest/coverage-v8": "4.0.
|
|
56
|
+
"@types/node": "22.19.0",
|
|
57
|
+
"@vitest/coverage-v8": "4.0.6",
|
|
58
58
|
"algosdk": "3.5.2",
|
|
59
59
|
"publint": "0.3.15",
|
|
60
60
|
"tsdown": "0.15.12",
|
|
61
61
|
"typescript": "5.9.3",
|
|
62
|
-
"vitest": "4.0.
|
|
62
|
+
"vitest": "4.0.6"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"algosdk": "^3.0.0"
|