@flipflop-sdk/cli
Version:
FlipFlop CLI tool for common operations
58 lines ⢠3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.estimateVolumeCommand = void 0;
const anchor_1 = require("@coral-xyz/anchor");
const node_1 = require("@flipflop-sdk/node");
const spl_token_1 = require("@solana/spl-token");
const web3_js_1 = require("@solana/web3.js");
const estimateVolumeCommand = async (options) => {
const { rpc, mint, maxSlippage, action } = options;
try {
const result = await (0, node_1.estimateVolume)({
rpc,
tokenAMint: new web3_js_1.PublicKey(mint),
tokenBMint: spl_token_1.NATIVE_MINT,
maxSlippage: parseFloat(maxSlippage), // 0-100
action,
});
if (!result.success || !result.data) {
console.error('ā Error: ', result.message);
return;
}
// Display formatted volume estimation results
console.log('\nš Volume Estimation Results');
console.log('ā'.repeat(50));
// Basic information
console.log(`Action Type: ${result.data.action || action}`);
console.log(`Current Price: ${result.data.currentPrice}`);
console.log(`Actual Slippage: ${(result.data.maxSlippage).toFixed(4)}%`);
console.log(`Token Amount: ${result.data.tokenAAmount.div(new anchor_1.BN(web3_js_1.LAMPORTS_PER_SOL)).toNumber()}`);
// Reserve information
console.log('\nš Pool Reserves');
console.log('ā'.repeat(30));
console.log(`Base Reserve: ${(result.data.baseReserve.toNumber() / web3_js_1.LAMPORTS_PER_SOL)} SOL`);
console.log(`Quote Reserve: ${result.data.quoteReserve.div(new anchor_1.BN(web3_js_1.LAMPORTS_PER_SOL)).toNumber()} Tokens`);
// console.log(`Constant Product (k): ${result.data.k.toString()}`);
// Optional fields
if (result.data.requiredAmount) {
const actionText = result.data.action === 'buy' ? 'Required SOL' : 'Expected Receive SOL';
console.log(`\nš° ${actionText}`);
console.log('ā'.repeat(30));
console.log(`Amount: ${result.data.requiredAmount.toNumber() / web3_js_1.LAMPORTS_PER_SOL} SOL`);
}
if (result.data.actualPrice) {
console.log('\nš± Actual Trading Price');
console.log('ā'.repeat(30));
console.log(`Price: ${result.data.actualPrice}`);
// Calculate price impact
const priceImpact = ((result.data.actualPrice - result.data.currentPrice) / result.data.currentPrice) * 100;
console.log(`Price Impact: ${Math.abs(priceImpact).toFixed(4)}%`);
}
console.log('\nā
Volume estimation completed successfully');
}
catch (error) {
console.error('ā Error: ', error instanceof Error ? error.message : 'Unknown error');
}
};
exports.estimateVolumeCommand = estimateVolumeCommand;
//# sourceMappingURL=estimate-volume.js.map