Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This is a pnpm workspace monorepo. All packages and examples share dependencies
### Prerequisites

- **Deflex API Key** - Request an API key by emailing [support@txnlab.dev](mailto:support@txnlab.dev)
- algosdk 3.0.0 or later (peer dependency)
- Node.js >= 20
- pnpm 10.20.0 or later

Expand Down Expand Up @@ -91,7 +92,7 @@ pnpm dev
Install the SDK in your project:

```bash
npm install @txnlab/deflex
npm install @txnlab/deflex algosdk
```

Basic usage:
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ All examples use the local SDK package via pnpm workspaces. This means changes t
### Prerequisites

- **Deflex API Key** - Request an API key by emailing [support@txnlab.dev](mailto:support@txnlab.dev)
- algosdk 3.0.0 or later (peer dependency)
- Node.js >= 20
- pnpm 10.20.0 or later

Expand Down
1 change: 1 addition & 0 deletions examples/node-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This example demonstrates how to use the Deflex SDK in a Node.js command-line ap
## Prerequisites

- **Deflex API Key** - Request an API key by emailing [support@txnlab.dev](mailto:support@txnlab.dev)
- algosdk 3.0.0 or later (peer dependency)
- Node.js >= 20
- pnpm 10.20.0 or later

Expand Down
5 changes: 4 additions & 1 deletion packages/deflex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ TypeScript/JavaScript SDK for [Deflex Order Router](https://txnlab.gitbook.io/de
## Prerequisites

- **Deflex API Key** - Request an API key by emailing [support@txnlab.dev](mailto:support@txnlab.dev)
- algosdk 3.0.0 or later

## Installation

```bash
npm install @txnlab/deflex
npm install @txnlab/deflex algosdk
```

> **Note**: `algosdk` is a peer dependency and must be installed alongside `@txnlab/deflex`.

## Quick Start

```typescript
Expand Down
6 changes: 3 additions & 3 deletions packages/deflex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"devDependencies": {
"@types/node": "24.9.1",
"@vitest/coverage-v8": "4.0.5",
"algosdk": "3.5.2",
"publint": "0.3.15",
"tsdown": "0.15.12",
"typescript": "5.9.3",
"vitest": "4.0.5"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "9.1.2",
"algosdk": "3.5.2"
"peerDependencies": {
"algosdk": "^3.0.0"
}
}
23 changes: 10 additions & 13 deletions packages/deflex/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
import { isValidAddress, type TransactionSigner } from 'algosdk'
import { Algodv2, isValidAddress, type TransactionSigner } from 'algosdk'
import { SwapComposer, type SignerFunction } from './composer'
import {
DEFAULT_ALGOD_PORT,
Expand Down Expand Up @@ -55,7 +54,7 @@ import type {
*/
export class DeflexClient {
private readonly config: DeflexConfig
private readonly algorand: AlgorandClient
private readonly algodClient: Algodv2

/**
* Create a new DeflexClient instance
Expand Down Expand Up @@ -85,14 +84,12 @@ export class DeflexClient {
autoOptIn: config.autoOptIn ?? DEFAULT_AUTO_OPT_IN,
}

// Create AlgorandClient
this.algorand = AlgorandClient.fromConfig({
algodConfig: {
server: this.config.algodUri,
port: this.config.algodPort,
token: this.config.algodToken,
},
})
// Create Algodv2 client
this.algodClient = new Algodv2(
this.config.algodToken,
this.config.algodUri,
this.config.algodPort,
)
}

/**
Expand Down Expand Up @@ -216,7 +213,7 @@ export class DeflexClient {
assetId: number | bigint,
): Promise<boolean> {
// Fetch account information
const accountInfo = await this.algorand.account.getInformation(address)
const accountInfo = await this.algodClient.accountInformation(address).do()

// Check if asset opt-in is required
return (
Expand Down Expand Up @@ -377,7 +374,7 @@ export class DeflexClient {
const composer = new SwapComposer({
quote,
deflexTxns: swapResponse.txns,
algorand: this.algorand,
algodClient: this.algodClient,
address,
signer,
})
Expand Down
32 changes: 16 additions & 16 deletions packages/deflex/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
msgpackRawDecode,
Transaction,
waitForConfirmation,
type Algodv2,
type TransactionSigner,
} from 'algosdk'
import { DEFAULT_CONFIRMATION_ROUNDS } from './constants'
import type {
Expand All @@ -18,8 +20,6 @@ import type {
DeflexSignature,
DeflexQuote,
} from './types'
import type { AlgorandClient } from '@algorandfoundation/algokit-utils'
import type { TransactionSigner } from 'algosdk'

/**
* A transaction signer function that supports both standard algosdk.TransactionSigner
Expand Down Expand Up @@ -62,8 +62,8 @@ export interface SwapComposerConfig {
readonly quote: FetchQuoteResponse | DeflexQuote
/** The swap transactions from fetchSwapTransactions() */
readonly deflexTxns: DeflexTransaction[]
/** AlgorandClient instance for blockchain operations */
readonly algorand: AlgorandClient
/** Algodv2 client instance */
readonly algodClient: Algodv2
/** The address of the account that will sign transactions */
readonly address: string
/** Transaction signer function */
Expand Down Expand Up @@ -100,7 +100,7 @@ export class SwapComposer {

private readonly requiredAppOptIns: number[]
private readonly deflexTxns: DeflexTransaction[]
private readonly algorand: AlgorandClient
private readonly algodClient: Algodv2
private readonly address: string
private readonly signer: TransactionSigner | SignerFunction

Expand All @@ -113,7 +113,7 @@ export class SwapComposer {
* @param config - Configuration for the composer
* @param config.requiredAppOptIns - The quote response from fetchQuote()
* @param config.deflexTxns - The swap transactions from fetchSwapTransactions()
* @param config.algorand - AlgorandClient instance for blockchain operations
* @param config.algodClient - Algodv2 client instance
* @param config.address - The address of the account that will sign transactions
* @param config.signer - Transaction signer function
*/
Expand All @@ -128,16 +128,16 @@ export class SwapComposer {
if (config.deflexTxns.length === 0) {
throw new Error('Swap transactions array cannot be empty')
}
if (!config.algorand) {
throw new Error('AlgorandClient instance is required')
if (!config.algodClient) {
throw new Error('Algodv2 client instance is required')
}
if (!config.signer) {
throw new Error('Signer is required')
}

this.requiredAppOptIns = config.quote.requiredAppOptIns
this.deflexTxns = config.deflexTxns
this.algorand = config.algorand
this.algodClient = config.algodClient
this.address = this.validateAddress(config.address)
this.signer = config.signer
}
Expand Down Expand Up @@ -337,7 +337,7 @@ export class SwapComposer {
}

const stxns = await this.sign()
await this.algorand.client.algod.sendRawTransaction(stxns).do()
await this.algodClient.sendRawTransaction(stxns).do()

this.status = SwapComposerStatus.SUBMITTED
return this.txIds
Expand Down Expand Up @@ -374,7 +374,7 @@ export class SwapComposer {
const txIds = await this.submit()

const confirmedTxnInfo = await waitForConfirmation(
this.algorand.client.algod,
this.algodClient,
txIds[0]!,
waitRounds,
)
Expand All @@ -384,7 +384,7 @@ export class SwapComposer {
const confirmedRound = confirmedTxnInfo.confirmedRound!

return {
confirmedRound,
confirmedRound: BigInt(confirmedRound),
txIds,
}
}
Expand Down Expand Up @@ -447,7 +447,9 @@ export class SwapComposer {
*/
private async processRequiredAppOptIns(): Promise<SwapTransaction[]> {
// Fetch account information
const accountInfo = await this.algorand.account.getInformation(this.address)
const accountInfo = await this.algodClient
.accountInformation(this.address)
.do()

// Check app opt-ins
const userApps =
Expand All @@ -459,9 +461,7 @@ export class SwapComposer {
// Create opt-in transactions if needed
const appOptInTxns: Transaction[] = []
if (appsToOptIn.length > 0) {
const suggestedParams = await this.algorand.client.algod
.getTransactionParams()
.do()
const suggestedParams = await this.algodClient.getTransactionParams().do()

for (const appId of appsToOptIn) {
const optInTxn = makeApplicationOptInTxnFromObject({
Expand Down
Loading