Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The public API is whatever `src/index.ts` re-exports: client, composer, constant

### Invariants and gotchas

- **Tinyman v1 is non-composable.** `DEPRECATED_PROTOCOLS` (`Tinyman`, `Humble`) are always added to `disabledProtocols`. `_allowNonComposableSwaps` re-enables Tinyman v1 only through `fetchQuote()`, can't be combined with opt-in, and is rejected by `newQuote()`. `addTransaction`/`addMethodCall` throw if `quote.flattenedRoute.Tinyman > 0`.
- **Tinyman v1 is gone.** The router dropped it and routes through Humble again, so the SDK disables no protocols by default. `DEPRECATED_PROTOCOLS` and `FetchQuoteParams._allowNonComposableSwaps` are kept as deprecated no-ops so removing them isn't breaking. Delete both in the next major.
- `SwapComposerStatus` is cast directly from the ATC status, so its member order must match algosdk's `AtomicTransactionComposerStatus`.
- `Logger` is a static singleton. Each `RouterClient`/`SwapComposer` constructor overwrites the global level. Its `sanitize()` redacts `apiKey`, `algodToken`, signature values and `txnPayload`. Keep that redaction when you add log calls.
- Asset and app IDs, and amounts, are `bigint` in `QuoteContext`/`SwapContext`/`SwapQuote`. The raw API response uses numbers and strings.
Expand Down
2 changes: 1 addition & 1 deletion examples/node-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The CLI will:
USD In: $1.00
USD Out: $0.99
Route paths: 2
Flattened route: { 'Tinyman': 0.6, 'Folks': 0.4 }
Flattened route: { 'tinyman-V2': 0.6, 'folks': 0.4 }

🔄 Executing swap...
✨ Swap completed successfully!
Expand Down
31 changes: 4 additions & 27 deletions packages/haystack/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
DEFAULT_FEE_BPS,
DEFAULT_MAX_DEPTH,
DEFAULT_MAX_GROUP_SIZE,
DEPRECATED_PROTOCOLS,
MAX_FEE_BPS,
} from './constants'
import { toSwapFirstStageQuote } from './firststage'
Expand Down Expand Up @@ -155,7 +154,6 @@ export class RouterClient {
address,
slippage,
signerType,
_allowNonComposableSwaps = false,
} = params

if (slippage !== undefined) {
Expand All @@ -172,21 +170,6 @@ export class RouterClient {
)
}

// Validate incompatible parameter combinations
if (_allowNonComposableSwaps && (optIn === true || this.config.autoOptIn)) {
throw new Error(
'Cannot use _allowNonComposableSwaps with optIn or autoOptIn. ' +
'When allowing non-composable swaps (Tinyman v1), you must handle ' +
'asset opt-ins and opt-outs in separate transaction groups.',
)
}

// Always disable the deprecated protocols (Tinyman v1), unless
// _allowNonComposableSwaps opts into Tinyman v1
const allDisabledProtocols = _allowNonComposableSwaps
? [...new Set(disabledProtocols)]
: [...new Set([...DEPRECATED_PROTOCOLS, ...disabledProtocols])]

let includeOptIn = optIn
if (includeOptIn === undefined && this.config.autoOptIn) {
if (address) {
Expand All @@ -211,7 +194,10 @@ export class RouterClient {
url.searchParams.append('toASAID', BigInt(toASAID).toString())
url.searchParams.append('amount', BigInt(amount).toString())
url.searchParams.append('type', type)
url.searchParams.append('disabledProtocols', allDisabledProtocols.join(','))
url.searchParams.append(
'disabledProtocols',
[...new Set(disabledProtocols)].join(','),
)
url.searchParams.append('maxGroupSize', maxGroupSize.toString())
url.searchParams.append('maxDepth', maxDepth.toString())

Expand Down Expand Up @@ -370,15 +356,6 @@ export class RouterClient {
* ```
*/
async newQuote(params: FetchQuoteParams): Promise<SwapQuote> {
// Block usage of _allowNonComposableSwaps with newQuote (middleware path)
if (params._allowNonComposableSwaps) {
throw new Error(
'The _allowNonComposableSwaps parameter is not supported with newQuote(). ' +
'This parameter is only available with fetchQuote() for advanced use cases. ' +
'The newQuote() method is designed for composable swaps with middleware support.',
)
}

// Apply middleware transformations to quote params
let adjustedParams = { ...params }

Expand Down
30 changes: 0 additions & 30 deletions packages/haystack/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,8 @@ export class SwapComposer {
* @returns This composer instance for chaining
* @throws Error if the composer is not in the BUILDING status
* @throws Error if the maximum group size is exceeded
* @throws Error if attempting to compose with a non-composable swap (Tinyman v1)
*/
addTransaction(transaction: Transaction, signer = this.defaultSigner): this {
// Check if the quote uses Tinyman v1 (non-composable protocol)
const usesTinymanV1 =
this.quote.flattenedRoute?.['Tinyman'] !== undefined &&
this.quote.flattenedRoute['Tinyman'] > 0

if (usesTinymanV1) {
throw new Error(
'Cannot add transactions to a swap group that uses Tinyman v1. ' +
'Tinyman v1 produces non-composable transaction groups. ' +
'Asset opt-ins, opt-outs, and other transactions must be sent in separate groups. ' +
'If you need to support Tinyman v1 swaps, you must handle multi-group coordination manually.',
)
}

this.atc.addTransaction({ txn: transaction, signer })
this.trackSignerFee(transaction.sender, transaction)
return this
Expand All @@ -366,23 +351,8 @@ export class SwapComposer {
* @param methodCall - The method call to add
* @param signer - The signer to use for the method call (defaults to constructor signer)
* @returns This composer instance for chaining
* @throws Error if attempting to compose with a non-composable swap (Tinyman v1)
*/
addMethodCall(methodCall: MethodCall, signer = this.defaultSigner): this {
// Check if the quote uses Tinyman v1 (non-composable protocol)
const usesTinymanV1 =
this.quote.flattenedRoute?.['Tinyman'] !== undefined &&
this.quote.flattenedRoute['Tinyman'] > 0

if (usesTinymanV1) {
throw new Error(
'Cannot add method calls to a swap group that uses Tinyman v1. ' +
'Tinyman v1 produces non-composable transaction groups. ' +
'Asset opt-ins, opt-outs, and other transactions must be sent in separate groups. ' +
'If you need to support Tinyman v1 swaps, you must handle multi-group coordination manually.',
)
}

this.atc.addMethodCall({
...methodCall,
signer: methodCall.signer ?? signer,
Expand Down
5 changes: 4 additions & 1 deletion packages/haystack/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export enum Protocol {
}

/**
* Deprecated protocols that are automatically excluded from routing
* Protocols the SDK used to exclude from routing automatically
*
* @deprecated The router no longer supports Tinyman v1, so the SDK no longer
* excludes it and this constant is unused. It will be removed in the next
* major version.
* @internal
*/
export const DEPRECATED_PROTOCOLS = ['Tinyman'] as const
Expand Down
28 changes: 5 additions & 23 deletions packages/haystack/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,12 @@ export interface FetchQuoteParams {
readonly signerType?: SignerType

/**
* ⚠️ **ADVANCED USE ONLY - NON-COMPOSABLE SWAPS** ⚠️
* Formerly re-enabled Tinyman v1, which produces non-composable swap groups.
*
* When set to `true`, removes the automatic exclusion of Tinyman v1 from routing,
* allowing the API to route swaps through protocols that produce **non-composable**
* transaction groups.
*
* **Critical Limitations:**
* - You CANNOT add transactions before/after swap transactions in the atomic group
* - Asset opt-ins and opt-outs MUST be sent in separate transaction groups
* - The SwapComposer will throw errors if you attempt to compose additional transactions
* - This parameter CANNOT be used with `optIn: true` or `config.autoOptIn: true`
* - This parameter is NOT supported in `newQuote()` (only `fetchQuote()`)
*
* **When to use this:**
* Only use this if you have built custom infrastructure to:
* 1. Detect when the route uses non-composable protocols (Tinyman v1)
* 2. Handle opt-in/opt-out transactions separately from the swap group
* 3. Coordinate multiple transaction groups instead of composing a single atomic group
*
* **This breaks the standard SDK workflow.** The default behavior of always excluding
* Tinyman v1 ensures all swaps are composable, which is the recommended approach.
*
* @default false
* @internal This is not a supported public API feature
* @deprecated The router no longer supports Tinyman v1, so every route is
* composable and this option is ignored. It will be removed in the next
* major version.
* @internal
*/
readonly _allowNonComposableSwaps?: boolean
}
Expand Down
Loading
Loading