forked from muxprotocol/solana-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
24 lines (21 loc) · 981 Bytes
/
Copy pathutils.ts
File metadata and controls
24 lines (21 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { struct, u64, bool } from '@coral-xyz/borsh'; // или используй обычный Buffer.read
import { PublicKey } from '@solana/web3.js';
// Структура данных Bonding Curve на Pump.fun
export const BONDING_CURVE_STRUCT = struct([
u64('virtualTokenReserves'),
u64('virtualSolReserves'),
u64('realTokenReserves'),
u64('realSolReserves'),
u64('tokenTotalSupply'),
bool('complete'),
]);
export function decodeBondingCurve(data: Buffer) {
// Пропускаем первые 8 байт (дискриминатор Anchor)
return BONDING_CURVE_STRUCT.decode(data.slice(8));
}
export function computeSolOutForTokens(curve: any, tokensIn: bigint): bigint {
// Упрощенная формула цены x * y = k
// Цена = (Virtual SOL Reserves / Virtual Token Reserves) * tokensIn
const solOut = (BigInt(curve.virtualSolReserves) * tokensIn) / BigInt(curve.virtualTokenReserves);
return solOut;
}