Skip to content

Feat/fl actions improvements#12

Closed
k0beLeenders wants to merge 11 commits into
mainfrom
feat/fl-actions-improvements
Closed

Feat/fl actions improvements#12
k0beLeenders wants to merge 11 commits into
mainfrom
feat/fl-actions-improvements

Conversation

@k0beLeenders
Copy link
Copy Markdown
Collaborator

SDK: Titan Swap Provider + Transaction Optimization

Summary

Adds Titan as a swap provider alongside Jupiter, implements transaction size and account lock validation, and enhances error handling in flashloan operations.

Version: 2.2.0-beta.0 (published under @beta tag)


🎯 Key Features

1. Titan Swap Provider

  • Vendored WebSocket client at src/vendor/titan/ (no external npm dependency)
    • client.ts: WebSocket connection with msgpack encoding
    • types.ts: Protocol types (cherry-picked from @titanexchange/sdk-ts)
    • helpers.ts: Deserialization and route selection utilities
  • Fee account validation: Checks ATA existence, strips fees if missing
  • Consistent API: Refactored to match Jupiter's quoteParams structure

New Files:

src/vendor/titan/
├── client.ts (369 lines)
├── types.ts (192 lines)
├── helpers.ts (146 lines)
└── index.ts

src/services/account/utils/
└── titan.utils.ts (421 lines)

2. Transaction Size Optimization

Added validation for Solana's transaction limits.

New Helper:

// src/services/transaction/helpers/tx-size.ts
export function getTotalAccountKeys(tx: VersionedTransaction | Transaction): number {
  // Counts static + LUT-resolved accounts
}

New Utility:

// src/services/account/utils/flashloan-size.utils.ts (704 lines)
export async function computeFlashloanSwapConstraints({
  program,
  marginfiAccount,
  bankMap,
  // ...
}): Promise<{
  sizeConstraint: number;
  maxSwapWritableAccounts: number;
  maxSwapTotalAccounts: number;
}>

Applied to all flashloan actions:

  • src/services/account/actions/loop.ts
  • src/services/account/actions/repay.ts
  • src/services/account/actions/swap-collateral.ts
  • src/services/account/actions/swap-debt.ts

Each action now validates before simulation:

const txSize = getTxSize(flashloanTx);
const writableKeys = getWritableAccountKeys(flashloanTx);
const totalKeys = getTotalAccountKeys(flashloanTx);

if (txSize > MAX_TX_SIZE || writableKeys > MAX_WRITABLE_ACCOUNTS || totalKeys > MAX_ACCOUNT_LOCKS) {
  throw TransactionBuildingError.swapSizeExceeded*(txSize, writableKeys, provider);
}

3. Enhanced Error Handling

  • Fixed error passthrough: TransactionBuildingError now properly propagates through swap provider fallback loops
  • Swap provider routing: Automatic fallback from Titan → Jupiter with typed errors
  • New error types: 15+ typed error constructors for different failure scenarios

Provider Fallback:

// src/services/account/utils/swap.utils.ts
for (const { provider, apiConfig } of attempts) {
  try {
    const fn = getSwapProviderFn({ attemptProvider: provider, ... });
    return await fn(apiConfig);
  } catch (err) {
    if (err instanceof TransactionBuildingError) throw err; // Proper passthrough
    lastError = err;
  }
}

🔗 Related

  • Web App PR: Companion changes for Titan HTTP proxy and error handling
  • Version: 2.2.0-beta.0 published under @beta tag (does not affect latest)

@k0beLeenders k0beLeenders force-pushed the feat/fl-actions-improvements branch from 7a3fb22 to 0339162 Compare April 17, 2026 09:08
@k0beLeenders k0beLeenders requested review from borcherd and chambaz and removed request for chambaz April 22, 2026 08:24
Comment thread examples/rnd-flashloan-size.ts
Comment thread src/errors/transaction-building.errors.ts
Comment thread src/services/account/actions/repay.ts
Comment thread src/services/account/actions/flash-loan.ts
Comment thread src/services/account/actions/swap-debt.ts
Comment thread src/vendor/titan/client.ts
Comment thread src/services/account/utils/titan.utils.ts
Comment thread src/services/account/utils/titan.utils.ts
Comment thread src/services/account/utils/swap.utils.ts

// --- LUT resolution ---

export async function resolveLookupTables(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a comment claude made, i dont really understand but maybe you do. just want to flag

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accountInfo === null LUTs are silently filtered out. If Titan returns a LUT address that doesn't resolve (RPC slot lag, wrong cluster, stale address), the swap IXs still reference accounts that were supposed to come from that LUT — the V0 compiler then either promotes them to static keys (→ misleading "tx size exceeded" error), or the TX fails on-chain with Invalid account index. Suggest throwing with the list of missing LUT pubkeys so the provider router's catch falls through to Jupiter cleanly instead of handing a broken IX set to makeFlashLoanTx.

@k0beLeenders k0beLeenders force-pushed the feat/fl-actions-improvements branch 3 times, most recently from cce275a to 2969f70 Compare April 28, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants