chainstacklabs / raydium-sdk-swap-example-typescript

An example to swap tokens on Solana using the Raydium SDK, TypeScript, and Chainstack
MIT License
99 stars 35 forks source link

The calculated exchange amount is sometimes small #11

Closed jsmzr closed 1 month ago

jsmzr commented 4 months ago

Should I also check the price and get a new pool info if it differs too much from expectations

Log at exception time, Liquidity.computeAmountOut

[DEBUG] slippage: 5%
[DEBUG] input side: base
[DEBUG] currentPrice: 1 UNKNOWN ≈ 146.953173 UNKNOWN
[DEBUG] currentPrice invert: 1 UNKNOWN ≈ 0.006804889 UNKNOWN
[DEBUG] amountOut: 0.418642
[DEBUG] minAmountOut: 0.398706
[DEBUG] executionPrice: 1 UNKNOWN ≈ 20.984561 UNKNOWN
[DEBUG] executionPrice invert: 1 UNKNOWN ≈ 0.047654082 UNKNOWN
[DEBUG] priceImpact: 85.72%

Normal time logs, Liquidity.computeAmountOut

[DEBUG] slippage: 5%
[DEBUG] input side: base
[DEBUG] currentPrice: 1 UNKNOWN ≈ 147.345628 UNKNOWN
[DEBUG] currentPrice invert: 1 UNKNOWN ≈ 0.006786764 UNKNOWN
[DEBUG] amountOut: 2.927112
[DEBUG] minAmountOut: 2.787725
[DEBUG] executionPrice: 1 UNKNOWN ≈ 146.722406 UNKNOWN
[DEBUG] executionPrice invert: 1 UNKNOWN ≈ 0.006815592 UNKNOWN
[DEBUG] priceImpact: 0.42297%
cc-l-x commented 1 month ago

hello. sir。I can't see any print info in this function Liquidity.computeAmountOut,but I can see a lot of logger.debug like this logger.debug('baseReserve:', baseReserve.toString()) logger.debug('quoteReserve:', quoteReserve.toString()). so. how can i see the log print like above?

cc-l-x commented 1 month ago

兄弟。有空吗 能不能帮忙解释一下为啥我的运行结果里面没有那些log的打印呢

jsmzr commented 1 month ago

兄弟。有空吗 能不能帮忙解释一下为啥我的运行结果里面没有那些log的打印呢

使用 @raydium-io/raydium-sdk 你可以通过 Logger 进行设置

import { Logger } from "@raydium-io/raydium-sdk";

Logger.setLogLevel('Liquidity', 'DEBUG');

如果你使用的是 @raydium-io/raydium-sdk-v2,你可以使用 setLoggerLevel 设置

import { setLoggerLevel, LogLevel } from '@raydium-io/raydium-sdk-v2';

setLoggerLevel('Raydium', LogLevel.Debug);