From 406931f51a6db43df44dafcad9c369690eb6389b Mon Sep 17 00:00:00 2001 From: Doug Richar Date: Wed, 11 Nov 2026 13:21:18 -0500 Subject: [PATCH] refactor(client): stop disabling Tinyman v1 and deprecate its options The router no longer supports Tinyman v1, and it ignores unknown names in disabledProtocols. So fetchQuote() no longer adds Tinyman to that list, and the composer's Tinyman v1 checks in addTransaction/addMethodCall are gone. _allowNonComposableSwaps and DEPRECATED_PROTOCOLS are kept, marked @deprecated, so this isn't a breaking change. The option is ignored and no longer throws. Both will be removed in the next major version. --- .claude/CLAUDE.md | 2 +- examples/node-cli/README.md | 2 +- packages/haystack/src/client.ts | 31 +--- packages/haystack/src/composer.ts | 30 ---- packages/haystack/src/constants.ts | 5 +- packages/haystack/src/types.ts | 28 +--- packages/haystack/tests/client.test.ts | 177 ++++++++-------------- packages/haystack/tests/composer.test.ts | 78 +--------- packages/haystack/tests/constants.test.ts | 4 +- 9 files changed, 78 insertions(+), 279 deletions(-) diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index 81afb0e..5363e03 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -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. diff --git a/examples/node-cli/README.md b/examples/node-cli/README.md index a2a5b25..c8f026c 100644 --- a/examples/node-cli/README.md +++ b/examples/node-cli/README.md @@ -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! diff --git a/packages/haystack/src/client.ts b/packages/haystack/src/client.ts index ecc481f..3e829b3 100644 --- a/packages/haystack/src/client.ts +++ b/packages/haystack/src/client.ts @@ -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' @@ -155,7 +154,6 @@ export class RouterClient { address, slippage, signerType, - _allowNonComposableSwaps = false, } = params if (slippage !== undefined) { @@ -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) { @@ -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()) @@ -370,15 +356,6 @@ export class RouterClient { * ``` */ async newQuote(params: FetchQuoteParams): Promise { - // 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 } diff --git a/packages/haystack/src/composer.ts b/packages/haystack/src/composer.ts index 5ea4727..ce1fb59 100644 --- a/packages/haystack/src/composer.ts +++ b/packages/haystack/src/composer.ts @@ -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 @@ -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, diff --git a/packages/haystack/src/constants.ts b/packages/haystack/src/constants.ts index 6ef81d2..f9d2bfc 100644 --- a/packages/haystack/src/constants.ts +++ b/packages/haystack/src/constants.ts @@ -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 diff --git a/packages/haystack/src/types.ts b/packages/haystack/src/types.ts index 98be610..03c3ed0 100644 --- a/packages/haystack/src/types.ts +++ b/packages/haystack/src/types.ts @@ -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 } diff --git a/packages/haystack/tests/client.test.ts b/packages/haystack/tests/client.test.ts index ef8ac0f..470c60f 100644 --- a/packages/haystack/tests/client.test.ts +++ b/packages/haystack/tests/client.test.ts @@ -175,13 +175,13 @@ describe('RouterClient', () => { expect(callUrl).toContain('toASAID=31566704') expect(callUrl).toContain('amount=1000000') expect(callUrl).toContain('type=fixed-output') - expect(callUrl).toContain('disabledProtocols=Tinyman%2CTinymanV2') + expect(callUrl).toContain('disabledProtocols=TinymanV2&') expect(callUrl).toContain('maxGroupSize=12') expect(callUrl).toContain('maxDepth=3') expect(callUrl).toContain('optIn=true') }) - it('should include deprecated protocols in disabled list', async () => { + it('should not disable any protocols by default', async () => { const mockQuote: Partial = { fromASAID: 0, toASAID: 31566704, @@ -200,8 +200,7 @@ describe('RouterClient', () => { }) const callUrl = mockRequest.mock.calls?.[0]?.[0] as string - expect(callUrl).toContain('disabledProtocols=Tinyman&') - expect(callUrl).not.toContain('Humble') + expect(callUrl).toContain('disabledProtocols=&') }) it('should use custom apiBaseUrl when provided', async () => { @@ -527,76 +526,57 @@ describe('RouterClient', () => { }) }) - describe('_allowNonComposableSwaps parameter', () => { - it('should allow Tinyman v1 routing when _allowNonComposableSwaps is true', async () => { - const mockQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - } - - mockRequest.mockResolvedValue(mockQuote) - - await client.fetchQuote({ - fromASAID: 0, - toASAID: 31566704, - amount: 1_000_000, - _allowNonComposableSwaps: true, - }) + describe('_allowNonComposableSwaps parameter (deprecated)', () => { + const mockQuote: Partial = { + fromASAID: 0, + toASAID: 31566704, + quote: '1000000', + route: [], + txnPayload: { iv: 'test-iv', data: 'test-data' }, + requiredAppOptIns: [], + } - const callUrl = mockRequest.mock.calls?.[0]?.[0] as string - // Should NOT include Tinyman when _allowNonComposableSwaps is true - expect(callUrl).not.toContain('Tinyman') - expect(callUrl).not.toContain('Humble') - }) + it.each([true, false])( + 'should not change disabledProtocols when set to %s', + async (value) => { + mockRequest.mockResolvedValue(mockQuote) - it('should include deprecated protocols by default when _allowNonComposableSwaps is false', async () => { - const mockQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - } + await client.fetchQuote({ + fromASAID: 0, + toASAID: 31566704, + amount: 1_000_000, + disabledProtocols: [Protocol.Pact], + _allowNonComposableSwaps: value, + }) + + const callUrl = mockRequest.mock.calls?.[0]?.[0] as string + expect(callUrl).toContain('disabledProtocols=Pact&') + expect(callUrl).not.toContain('Tinyman') + expect(callUrl).not.toContain('_allowNonComposableSwaps') + }, + ) + it('should not throw when combined with optIn: true', async () => { mockRequest.mockResolvedValue(mockQuote) await client.fetchQuote({ fromASAID: 0, toASAID: 31566704, amount: 1_000_000, - _allowNonComposableSwaps: false, + _allowNonComposableSwaps: true, + optIn: true, }) const callUrl = mockRequest.mock.calls?.[0]?.[0] as string - // Should include deprecated protocols - expect(callUrl).toContain('Tinyman') - expect(callUrl).not.toContain('Humble') - }) - - it('should throw error when _allowNonComposableSwaps is used with optIn: true', async () => { - await expect( - client.fetchQuote({ - fromASAID: 0, - toASAID: 31566704, - amount: 1_000_000, - _allowNonComposableSwaps: true, - optIn: true, - }), - ).rejects.toThrow( - 'Cannot use _allowNonComposableSwaps with optIn or autoOptIn', - ) + expect(callUrl).toContain('optIn=true') }) - it('should throw error when _allowNonComposableSwaps is used with autoOptIn enabled', async () => { + it('should not throw when autoOptIn is enabled', async () => { const clientWithAutoOptIn = new RouterClient({ ...validConfig, autoOptIn: true, }) + mockRequest.mockResolvedValue(mockQuote) await expect( clientWithAutoOptIn.fetchQuote({ @@ -605,57 +585,7 @@ describe('RouterClient', () => { amount: 1_000_000, _allowNonComposableSwaps: true, }), - ).rejects.toThrow( - 'Cannot use _allowNonComposableSwaps with optIn or autoOptIn', - ) - }) - - it('should allow _allowNonComposableSwaps when optIn is false', async () => { - const mockQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - } - - mockRequest.mockResolvedValue(mockQuote) - - await client.fetchQuote({ - fromASAID: 0, - toASAID: 31566704, - amount: 1_000_000, - _allowNonComposableSwaps: true, - optIn: false, - }) - - const callUrl = mockRequest.mock.calls?.[0]?.[0] as string - expect(callUrl).not.toContain('Tinyman') - expect(callUrl).toContain('optIn=false') - }) - - it('should allow _allowNonComposableSwaps when optIn is undefined and autoOptIn is disabled', async () => { - const mockQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - } - - mockRequest.mockResolvedValue(mockQuote) - - await client.fetchQuote({ - fromASAID: 0, - toASAID: 31566704, - amount: 1_000_000, - _allowNonComposableSwaps: true, - }) - - const callUrl = mockRequest.mock.calls?.[0]?.[0] as string - expect(callUrl).not.toContain('Tinyman') + ).resolves.toBeDefined() }) }) }) @@ -919,17 +849,28 @@ describe('RouterClient', () => { expect(callUrl).toContain('toASAID=31566704') }) - it('should throw error when _allowNonComposableSwaps is used with newQuote', async () => { - await expect( - client.newQuote({ - fromASAID: 0, - toASAID: 31566704, - amount: 1_000_000, - _allowNonComposableSwaps: true, - }), - ).rejects.toThrow( - 'The _allowNonComposableSwaps parameter is not supported with newQuote()', - ) + it('should ignore the deprecated _allowNonComposableSwaps parameter', async () => { + const mockQuoteResponse: Partial = { + fromASAID: 0, + toASAID: 31566704, + quote: '5000000', + type: 'fixed-input', + route: [], + txnPayload: { iv: 'test-iv', data: 'test-data' }, + requiredAppOptIns: [], + } + + mockRequest.mockResolvedValue(mockQuoteResponse) + + await client.newQuote({ + fromASAID: 0, + toASAID: 31566704, + amount: 1_000_000, + _allowNonComposableSwaps: true, + }) + + const callUrl = mockRequest.mock.calls?.[0]?.[0] as string + expect(callUrl).toContain('disabledProtocols=&') }) }) diff --git a/packages/haystack/tests/composer.test.ts b/packages/haystack/tests/composer.test.ts index 34c8498..3d1f2cc 100644 --- a/packages/haystack/tests/composer.test.ts +++ b/packages/haystack/tests/composer.test.ts @@ -326,34 +326,7 @@ describe('SwapComposer', () => { ) }) - it('should throw error when trying to compose with Tinyman v1 swap', () => { - const tinymanQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - flattenedRoute: { - Tinyman: 1.0, // 100% Tinyman v1 routing - }, - } - - const composer = new SwapComposer({ - quote: tinymanQuote as FetchQuoteResponse, - swapTxns: [createMockSwapTxn()], - algodClient: mockAlgodClient, - address: validAddress, - signer: async (txns: algosdk.Transaction[]) => - txns.map(() => new Uint8Array(0)), - }) - - expect(() => composer.addTransaction(createMockTransaction())).toThrow( - 'Cannot add transactions to a swap group that uses Tinyman v1', - ) - }) - - it('should allow adding transactions when NOT using Tinyman v1', () => { + it('should allow adding transactions when the quote has a flattenedRoute', () => { const nonTinymanQuote: Partial = { fromASAID: 0, toASAID: 31566704, @@ -588,54 +561,7 @@ describe('SwapComposer', () => { expect(result).toBe(composer) }) - it('should throw error when trying to add method call to Tinyman v1 swap', () => { - const tinymanQuote: Partial = { - fromASAID: 0, - toASAID: 31566704, - quote: '1000000', - route: [], - txnPayload: { iv: 'test-iv', data: 'test-data' }, - requiredAppOptIns: [], - flattenedRoute: { - Tinyman: 1.0, // 100% Tinyman v1 routing - }, - } - - const composer = new SwapComposer({ - quote: tinymanQuote as FetchQuoteResponse, - swapTxns: [createMockSwapTxn()], - algodClient: mockAlgodClient, - address: validAddress, - signer: async () => [new Uint8Array([1])], - }) - - const methodCall = { - appID: 123456, - method: new algosdk.ABIMethod({ - name: 'test', - args: [], - returns: { type: 'void' }, - }), - sender: validAddress, - suggestedParams: { - fee: 1000, - firstValid: 1000, - lastValid: 2000, - genesisID: 'testnet-v1.0', - genesisHash: Buffer.from( - 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', - 'base64', - ), - minFee: 1000, - }, - } - - expect(() => composer.addMethodCall(methodCall)).toThrow( - 'Cannot add method calls to a swap group that uses Tinyman v1', - ) - }) - - it('should allow adding method calls when NOT using Tinyman v1', () => { + it('should allow adding method calls when the quote has a flattenedRoute', () => { const nonTinymanQuote: Partial = { fromASAID: 0, toASAID: 31566704, diff --git a/packages/haystack/tests/constants.test.ts b/packages/haystack/tests/constants.test.ts index 3ac977b..7335986 100644 --- a/packages/haystack/tests/constants.test.ts +++ b/packages/haystack/tests/constants.test.ts @@ -32,8 +32,8 @@ describe('constants', () => { }) }) - describe('DEPRECATED_PROTOCOLS', () => { - it('should include Tinyman but not Humble', () => { + describe('DEPRECATED_PROTOCOLS (deprecated, unused)', () => { + it('should keep its value until the next major version', () => { expect(DEPRECATED_PROTOCOLS).toContain('Tinyman') expect(DEPRECATED_PROTOCOLS).not.toContain('Humble') })