New integrations:
- src/venues/adrena.ts: Adrena Protocol perp venue (funding rates + market data)
- scripts/vault-ops/: 15 multi-protocol vault management scripts from client-scripts
- Admin: init vault, add strategies, harvest fees, direct withdraw
- Manager: deposit/withdraw across Drift + Jupiter + Kamino strategies
- User: deposit, withdraw, query positions
Engine upgrade:
- Cross-venue funding comparison now checks Drift vs Flash vs Adrena (3 venues)
- Finds arb when spread > 5% APY across venues
- Logs: "Short on {best venue}, long on {worst venue}"
Stats:
- 5 venue modules: Drift, Flash, Adrena, Orca, Meteora
- 96 scripts across vault-ops, lending, raydium-clmm, rebalance-bot
- 20/20 test suites, 181/181 tests pass
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
// NOTE: THIS ASSUMES THE USER HAS REQUESTED A WITHDRAWAL, THROWS ERROR IF NOT
|
|
import {
|
|
Connection,
|
|
Keypair,
|
|
PublicKey,
|
|
TransactionInstruction,
|
|
} from "@solana/web3.js";
|
|
import * as fs from "fs";
|
|
import { sendAndConfirmOptimisedTx } from "../utils/helper";
|
|
import {
|
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
createCloseAccountInstruction,
|
|
getAssociatedTokenAddressSync,
|
|
NATIVE_MINT,
|
|
} from "@solana/spl-token";
|
|
import { VoltrClient } from "@voltr/vault-sdk";
|
|
import {
|
|
userFilePath,
|
|
vaultAddress,
|
|
assetMintAddress,
|
|
heliusRpcUrl,
|
|
assetTokenProgram,
|
|
} from "../variables";
|
|
|
|
const userKpFile = fs.readFileSync(userFilePath, "utf-8");
|
|
const userKpData = JSON.parse(userKpFile);
|
|
const userSecret = Uint8Array.from(userKpData);
|
|
const userKp = Keypair.fromSecretKey(userSecret);
|
|
const user = userKp.publicKey;
|
|
|
|
const vault = new PublicKey(vaultAddress);
|
|
const vaultAssetMint = new PublicKey(assetMintAddress);
|
|
|
|
const connection = new Connection(heliusRpcUrl);
|
|
const vc = new VoltrClient(connection);
|
|
|
|
const withdrawVaultHandler = async () => {
|
|
let ixs: TransactionInstruction[] = [];
|
|
const userAssetAta = getAssociatedTokenAddressSync(vaultAssetMint, user);
|
|
const createUserAssetAtaIx =
|
|
createAssociatedTokenAccountIdempotentInstruction(
|
|
user,
|
|
userAssetAta,
|
|
user,
|
|
vaultAssetMint
|
|
);
|
|
ixs.push(createUserAssetAtaIx);
|
|
|
|
const withdrawVaultIx = await vc.createWithdrawVaultIx({
|
|
vault,
|
|
userTransferAuthority: user,
|
|
vaultAssetMint,
|
|
assetTokenProgram: new PublicKey(assetTokenProgram),
|
|
});
|
|
ixs.push(withdrawVaultIx);
|
|
|
|
if (vaultAssetMint.equals(NATIVE_MINT)) {
|
|
// Create close account instruction to convert wSOL back to SOL
|
|
const closeWsolAccountIx = createCloseAccountInstruction(
|
|
userAssetAta, // Account to close
|
|
user, // Destination account (SOL will be sent here)
|
|
user, // Authority
|
|
[] // No multisig signers
|
|
);
|
|
ixs.push(closeWsolAccountIx);
|
|
}
|
|
|
|
const txSig = await sendAndConfirmOptimisedTx(ixs, heliusRpcUrl, userKp);
|
|
console.log("Withdraw Vault Tx Sig: ", txSig);
|
|
};
|
|
|
|
withdrawVaultHandler();
|