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