getSwapAmountsOut

function getSwapAmountsOut(
    uint _amountIn, 
    address[] memory _path
) public view virtual returns (uint[] memory amounts)

Swap ์‹œ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ฐœ์ˆ˜๋ฅผ ์–ป์„ ๋•Œ ์‚ฌ์šฉ (FROM->TO)

Parameters

Return Values

โ€ปReserves๋ฅผ ํ†ตํ•œ ์—ฐ์‚ฐ ๋ฐฉ๋ฒ•

//์ˆ˜์ˆ˜๋ฃŒ ์‚ฌ์šฉ ์œ ๋ฌด์— ๋”ฐ๋ผ swapFee ์ง€์ •(30 = 0.03%)
uint amountInWithFee = amountIn*(10000-swapFee)
uint numerator = amountInWithFee*(reserveOut);
uint denominator = (reserveIn*10000)+amountInWithFee;        
amountOut = numerator / denominator;

Example

// swap ํ† ํฐ ๊ฐœ์ˆ˜ ์–ป๊ธฐ
await routerContract.getSwapAmountsOut(
    10000
    [mockToken0Contract.address, mockToken1Contract.address]
)

// ๊ฒฐ๊ณผ
[ BigNumber { value: "10000" }, BigNumber { value: "4984" } ]

2023.01.02

Last updated