Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

feat: refactor SwapComposer to use AtomicTransactionComposer internally#17

Merged
drichar merged 8 commits intomainfrom
feat/atomic-transaction-composer-integration
Nov 4, 2025
Merged

feat: refactor SwapComposer to use AtomicTransactionComposer internally#17
drichar merged 8 commits intomainfrom
feat/atomic-transaction-composer-integration

Conversation

@drichar
Copy link
Contributor

@drichar drichar commented Nov 4, 2025

Summary

Refactor SwapComposer to use Algorand SDK's AtomicTransactionComposer (ATC) internally instead of reimplementing transaction group management. This architectural change improves maintainability, reliability, and adds support for ABI method calls in swap transaction groups.

Changes

SwapComposer Refactoring

  • Delegate transaction management to ATC instead of custom implementation
  • Remove manual group ID assignment, signing coordination, and status tracking
  • Simplify sign(), submit(), and execute() to delegate to ATC methods
  • Add auto-add swap transactions logic to submit() and execute() for backward compatibility

New Features

  • buildGroup(): Expose ATC's buildGroup method with comprehensive JSDoc
  • addMethodCall(methodCall, signer?): Enable ABI method calls in swap groups
    • Follows two-argument pattern from addTransaction()
    • Three-tier signer resolution: inline → parameter → constructor
  • MethodCall interface: Type definition for ABI method call parameters

Enhanced Features

  • addTransaction(transaction, signer?): Added optional signer parameter with fallback to constructor signer
  • execute() return type: Added methodResults: ABIResult[] for ABI method call support

Type Changes

  • Import TransactionWithSigner and ABIResult from algosdk
  • Deprecate SwapTransaction type (still exported, use TransactionWithSigner instead)
  • Add MethodCall interface based on ATC's inline definition with signer made optional to support fallback behavior

Test Updates

  • Refactor tests to spy on ATC methods instead of testing internal implementation
  • Focus on testing SwapComposer's behavior (delegation, auto-add, parameter passing)
  • Add comprehensive tests for addMethodCall() signer fallback logic
  • Add error handling tests for invalid signature structures
  • Remove waitForConfirmation mock and unused algodClient methods
  • Improve test coverage from 91.89% to 94.59%
  • All 112 tests passing

Documentation

  • Update README with ABI method call examples in advanced composition section
  • Add addMethodCall() and buildGroup() to API reference table
  • Fix execute() return type documentation to show inline type with methodResults
  • Improve JSDoc examples with accurate parameter usage

Breaking Changes

None - All changes are internal, additive, or backward compatible.

Compatibility Details:

  • addTransaction() - Optional signer parameter added (backward compatible)
  • execute() - Added methodResults field to return object (additive, backward compatible)
  • SwapTransaction - Deprecated but still exported (not removed)
  • All existing public methods maintain same signatures and behavior

Benefits

  • Reduced complexity: Leverage battle-tested ATC implementation instead of custom code
  • Better maintainability: Less code to maintain, fewer edge cases to handle
  • ABI method call support: Native support for composing swaps with ABI method calls
  • Improved reliability: Tests focus on behavior rather than implementation details
  • Better performance: Tests run faster (77ms vs previous 145ms for composer tests)

Testing

  • ✅ All 112 tests passing (49 composer, 32 client, 21 constants, 10 utils)
  • ✅ Test coverage improved from 91.89% to 94.59%
  • ✅ Comprehensive tests for new signer fallback logic
  • ✅ Error handling tests for edge cases

Replace custom transaction group management with algosdk's
`AtomicTransactionComposer` (ATC) to improve reliability and maintainability.

Changes:

`SwapComposer` Refactoring
- Delegate transaction management to ATC instead of reimplementing group logic
- Add public `buildGroup()` method with JSDoc documentation
- Add auto-add swap transactions logic to `submit()` and `execute()` for
  backward compatibility
- Remove manual group ID assignment, signing coordination, and status
  management
- Simplify `sign()`, `submit()`, and `execute()` to delegate to ATC methods

Internal Method Updates
- `createDeflexSigner()`: New method that wraps Deflex pre-signed transaction
  logic in `TransactionSigner` function
- `defaultSigner`: New wrapper for configured signer that filters out null values
  (ARC-1 compliance)
- `processSwapTransactions()`: Refactored to return `TransactionWithSigner[]`
  instead of `SwapTransaction[]`
- `processRequiredAppOptIns()`: Refactored to return `TransactionWithSigner[]`
  instead of `SwapTransaction[]`

Type Changes
- Import `TransactionWithSigner` and `ABIResult` types from algosdk
- Deprecate `SwapTransaction` type in favor of `algosdk.TransactionWithSigner`
- Add `methodResults` to `execute()` return type for ABI method call support

Test Updates
- Refactor tests to spy on ATC methods instead of testing internal implementation
- Focus on testing SwapComposer's behavior (delegation, auto-add, parameter
  passing)
- Add error handling tests for invalid signature structures
- Remove `waitForConfirmation` mock and unused `algodClient` methods
- Add helper for creating valid signed transaction blobs
- Improve test coverage from 91.89% to 94.59%

There are no breaking changes to the public API. All changes are internal or additive.

Benefits:
- Reduced code complexity and maintenance burden
- Leverage battle-tested ATC implementation
- Better support for future features (ABI method calls, etc.)
- Improved test reliability and execution speed
Add support for including ABI method calls in swap transaction groups by
exposing AtomicTransactionComposer's `addMethodCall` functionality.

Changes:

SwapComposer API
- Add `addMethodCall()` method as pass-through to ATC's `addMethodCall()`
- Returns `this` for method chaining consistency with other add methods
- Includes JSDoc documentation

Type Definitions
- Add `MethodCall` interface copied from ATC's inline parameter definition
- Includes all 21 parameters from ATC's method call configuration
- Update imports in `types.ts` to use named imports from algosdk for better
  tree-shaking

Benefits:
- Enables users to compose swap transactions with ABI method calls
- Maintains consistency with ATC's API surface
- Prepares for advanced use cases like flash loans, multi-step DeFi operations, etc.
Update code examples to reflect correct API usage and provide more practical
output examples.

Changes:
- Add `signer` parameter to `newSwap()` examples for accuracy
- Fix `execute()` call to remove incorrect `signer` parameter
- Enhance `buildGroup()` example to show practical output (group ID, length,
  status)
Update `addMethodCall()` to follow the two-argument pattern established by `addTransaction()`, providing flexibility in how signers are specified.

Changes:
- Add optional `signer` parameter to `addMethodCall()` that defaults to
  `this.defaultSigner`
- Make `signer` property optional in `MethodCall` interface
- Implement fallback logic: `methodCall.signer` → parameter signer →
  constructor signer
- Add JSDoc documentation explaining the signer resolution order
- Keep `sender` required to avoid implicit assumptions about transaction origin

Benefits:
- Consistent API pattern across `addTransaction()` and `addMethodCall()`
- Flexibility to specify signer inline, as parameter, or use default
- Explicit about sender while providing sensible signer defaults
Update README to showcase the new ABI method call functionality in SwapComposer.

Changes:
- Add `addMethodCall()` to Advanced Transaction Composition example
- Show how to define and use a MethodCall in the composition flow
- Update SwapComposer API reference table to include `addMethodCall()` and
  `buildGroup()`
- Add optional `signer` parameter documentation for `addTransaction()`
- Fix `getStatus()` return type
Update the `execute()` method's return type to accurately reflect the inline type
definition that includes `methodResults`.

Changes:
- Replace generic `PendingTransactionResponse` with actual return type
- Show `{ confirmedRound: bigint, txIds: string[], methodResults: ABIResult[] }` inline
- Aligns documentation with the ATC integration changes
Add comprehensive tests for the three-tier signer resolution in `addMethodCall()`.

Tests cover:
- Using `methodCall.signer` when provided (highest priority)
- Using parameter `signer` when `methodCall.signer` is undefined
- Using constructor's `defaultSigner` when neither is provided (lowest priority)
- Method chaining behavior

All 112 tests passing.
Reorder methods so `addMethodCall()` follows `addTransaction()` and
precedes `addSwapTransactions()`, grouping the "add" methods together in
a logical sequence.
@drichar drichar merged commit cebb16c into main Nov 4, 2025
1 check passed
@drichar drichar deleted the feat/atomic-transaction-composer-integration branch November 4, 2025 14:13
github-actions bot added a commit that referenced this pull request Nov 4, 2025
# [1.2.0](v1.1.0...v1.2.0) (2025-11-04)

### Features

* refactor SwapComposer to use AtomicTransactionComposer internally ([#17](#17)) ([cebb16c](cebb16c))
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant