caelum0x bafe1da2d1 Full-stack integration: 5 Rust programs, 13 venue/yield modules, 181 tests pass
On-chain (programs/):
- driftbear_custom_adaptor (1,058 lines, deployed devnet)
- drift_vaults (15,243 lines)
- raydium_clmm (20,909 lines)
- drift_rs_sdk (55,940 lines)
- ctoken_market_program + mock (673 lines)

New TypeScript modules (ported from 19 plugins):
- JIT maker (sniper+shotgun from jit-proxy)
- Filler bot (DLOB fills from keeper-bots-v2)
- FloatingMaker (slot-based from keeper-bots-v2)
- Executor upgrades (tx simulation, Jito bundles, ALTs)
- Event stream (WebSocket + Yellowstone gRPC)
- DLOB orderbook + price impact + funding TWAP
- Ranger Data API (funding arbs, liquidation signals)
- Ranger SOR (full API: quotes, withdraw, deposit collateral)
- Sanctum LST (swap, APY, best LST selection)
- Lulo lending aggregator
- Pyth oracle cross-validation
- Helius DAS API + smart priority fees
- Flash Trade, Orca, Meteora, deBridge venue clients
- Voltr vault strategy client
- Drift insurance fund staking
- Adaptor CPI client for on-chain program
- Raydium LP strategy

All wired into strategy engine runCycle():
- 11 data sources called every cycle
- 3 background execution modules (JIT, Filler, FloatingMaker)
- Multi-venue funding rate comparison
- Lending yield optimizer across protocols
- LP yield scanning (Orca + Meteora)
- Auto-deploy idle capital to best lending protocol
- Pyth oracle cross-validation
- Realistic backtest mode (0.30% round-trip costs)

Tests: 20/20 suites, 181/181 pass
Build: zero TypeScript errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 00:40:22 +03:00

199 lines
5.2 KiB
TypeScript

import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
import {
createAssociatedTokenAccountIdempotentInstruction,
getAssociatedTokenAddressSync,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import {
AddressLookupTableAccount,
AddressLookupTableProgram,
ComputeBudgetProgram,
Connection,
Keypair,
PublicKey,
TransactionConfirmationStrategy,
TransactionInstruction,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
export const sendAndConfirmOptimisedTx = async (
instructions: TransactionInstruction[],
heliusRpcUrl: string,
payerKp: Keypair,
signers: Keypair[] = [],
addressLookupTableAccounts: AddressLookupTableAccount[] = []
) => {
const connection = new Connection(heliusRpcUrl);
const testInstructions = [
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
...instructions,
];
const cuTransaction = new VersionedTransaction(
new TransactionMessage({
instructions: testInstructions,
payerKey: payerKp.publicKey,
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
}).compileToV0Message(addressLookupTableAccounts)
);
cuTransaction.sign([payerKp, ...signers]);
const rpcResponse = await connection.simulateTransaction(cuTransaction, {
replaceRecentBlockhash: true,
sigVerify: false,
});
const requiredCUs = rpcResponse.value.unitsConsumed;
if (!requiredCUs) {
throw new Error("Failed to get required CUs");
}
const optimalCUs = requiredCUs * 1.2;
const computeUnitIx = ComputeBudgetProgram.setComputeUnitLimit({
units: optimalCUs,
});
instructions.push(computeUnitIx);
const feTransaction = new VersionedTransaction(
new TransactionMessage({
instructions,
payerKey: payerKp.publicKey,
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
}).compileToV0Message(addressLookupTableAccounts)
);
feTransaction.sign([payerKp, ...signers]);
const response = await fetch(heliusRpcUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: "1",
method: "getPriorityFeeEstimate",
params: [
{
transaction: bs58.encode(feTransaction.serialize()), // Pass the serialized transaction in Base58
options: { priorityLevel: "High" },
},
],
}),
});
const data = await response.json();
const feeEstimate = data.result;
if (!feeEstimate) {
throw new Error("Failed to get fee estimate");
}
const computePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: feeEstimate.priorityFeeEstimate,
});
instructions.push(computePriceIx);
const transaction = new VersionedTransaction(
new TransactionMessage({
instructions,
payerKey: payerKp.publicKey,
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
}).compileToV0Message(addressLookupTableAccounts)
);
transaction.sign([payerKp, ...signers]);
const txSig = await connection.sendTransaction(transaction, {
skipPreflight: false,
preflightCommitment: "confirmed",
maxRetries: 5,
});
const confirmationStrategy: TransactionConfirmationStrategy = {
signature: txSig,
blockhash: (await connection.getLatestBlockhash()).blockhash,
lastValidBlockHeight: (await connection.getLatestBlockhash())
.lastValidBlockHeight,
};
await connection.confirmTransaction(confirmationStrategy, "confirmed");
return txSig;
};
export const setupTokenAccount = async (
connection: Connection,
payer: PublicKey,
mint: PublicKey,
owner: PublicKey,
txIxs: TransactionInstruction[],
programId: PublicKey = TOKEN_PROGRAM_ID
) => {
const tokenAccount = getAssociatedTokenAddressSync(
mint,
owner,
true,
programId
);
const tokenAccountInfo = await connection.getAccountInfo(tokenAccount);
if (!tokenAccountInfo) {
const createTokenAccountIx =
createAssociatedTokenAccountIdempotentInstruction(
payer,
tokenAccount,
owner,
mint,
programId
);
txIxs.push(createTokenAccountIx);
}
return tokenAccount;
};
export const setupAddressLookupTable = async (
connection: Connection,
authority: PublicKey,
payer: PublicKey,
addresses: string[],
txIxs: TransactionInstruction[],
lookupTable?: PublicKey
) => {
let lut: PublicKey;
const lutAddressesStr: string[] = [];
if (lookupTable) {
lut = lookupTable;
const lutData = await connection.getAddressLookupTable(lut);
lutAddressesStr.push(
...(lutData.value?.state.addresses.map((a) => a.toBase58()) ?? [])
);
} else {
const [createLUTIx, lutTemp] = AddressLookupTableProgram.createLookupTable({
authority,
payer,
recentSlot: await connection.getSlot(),
});
lut = lutTemp;
txIxs.push(createLUTIx);
}
const filteredUniqueIxsPubkeys = addresses
.filter((pubkey) => !lutAddressesStr.includes(pubkey))
.map((pubkey) => new PublicKey(pubkey));
if (filteredUniqueIxsPubkeys.length > 0) {
txIxs.push(
AddressLookupTableProgram.extendLookupTable({
lookupTable: lut,
authority: payer,
addresses: filteredUniqueIxsPubkeys,
payer,
})
);
}
return lut;
};