getSwapAmountsIn


function getSwapAmountsIn(    uint _amountOut,     address[] memory _path) public view virtual returns (uint[] memory amounts)

Swap ์‹œ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ† ํฐ ๊ฐœ์ˆ˜๋ฅผ ๋„ฃ์„ ์‹œ ๋ณ€๊ฒฝ๋˜์–ด์•ผ ํ•  ํ† ํฐ ๊ฐœ์ˆ˜๋ฅผ ์–ป์„ ๋•Œ ์‚ฌ์šฉ 
(TO->FROM)

Parameters

Return Values

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

Example
// swap ํ† ํฐ ๊ฐœ์ˆ˜ ์–ป๊ธฐawait routerContract.getSwapAmountsIn(    5000    [mockToken0Contract.address, mockToken1Contract.address])// ๊ฒฐ๊ณผ[ BigNumber { value: "10031" }, BigNumber { value: "5000" } ]

2023.01.02

Last updated