import { DynamicBondingCurveClient } from '@meteora-ag/dynamic-bonding-curve-sdk';
import { BaseFeeMode, CollectFeeMode } from '@meteora-ag/dynamic-bonding-curve-sdk';
import { Connection } from '@solana/web3.js';
import BN from 'bn.js';
const RPC_URL = "";
const SOLANA_CONNECTION = new Connection(RPC_URL);
const BONDING_CURVE_CLIENT = new DynamicBondingCurveClient(SOLANA_CONNECTION, 'processed');
const SQRT_START_PRICE = new BN('3141367320245630');
const MIGRATION_QUOTE_THRESHOLD = new BN(85000000000);
const BASE_FEE_CLIFF_FEE_NUMERATOR = new BN('20000000');
const BASE_FEE_FIRST_FACTOR = 0;
const BASE_FEE_SECOND_FACTOR = new BN('0');
const BASE_FEE_THIRD_FACTOR = new BN('0');
const BASE_FEE_MODE = BaseFeeMode.FeeSchedulerLinear;
const COLLECT_FEE_MODE = CollectFeeMode.QuoteToken;
const CURVE = [
{
sqrtPrice: new BN('6401204812200420'),
liquidity: new BN('3929368168768468756200000000000000'),
},
{
sqrtPrice: new BN('13043817825332782'),
liquidity: new BN('2425988008058820449100000000000000'),
},
];
export const getOutputAmountOfInitialBuy = async (initialBuyIn: string): Promise<string | null> => {
try {
const quote = await BONDING_CURVE_CLIENT.pool.swapQuote({
virtualPool: {
quoteReserve: new BN(0),
sqrtPrice: SQRT_START_PRICE,
activationPoint: new BN(0),
volatilityTracker: {
volatilityAccumulator: new BN(0),
},
} as any,
config: {
collectFeeMode: COLLECT_FEE_MODE,
migrationQuoteThreshold: MIGRATION_QUOTE_THRESHOLD,
poolFees: {
baseFee: {
cliffFeeNumerator: BASE_FEE_CLIFF_FEE_NUMERATOR,
firstFactor: BASE_FEE_FIRST_FACTOR,
secondFactor: BASE_FEE_SECOND_FACTOR,
thirdFactor: BASE_FEE_THIRD_FACTOR,
baseFeeMode: BASE_FEE_MODE,
},
dynamicFee: {
initilized: new BN(0),
},
},
curve: [
{
sqrtPrice: CURVE[0].sqrtPrice,
liquidity: CURVE[0].liquidity,
},
{
sqrtPrice: CURVE[1].sqrtPrice,
liquidity: CURVE[1].liquidity,
},
],
} as any,
swapBaseForQuote: false,
amountIn: new BN(initialBuyIn),
slippageBps: 0,
hasReferral: false,
currentPoint: new BN(0),
});
return quote.outputAmount.div(new BN(10 ** 9)).toString();
} catch (err) {
console.error(err);
return null;
}
};