getSwapAmountsIn


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

Swap μ‹œ 받을 수 μžˆλŠ” 토큰 개수λ₯Ό 넣을 μ‹œ λ³€κ²½λ˜μ–΄μ•Ό ν•  토큰 개수λ₯Ό 얻을 λ•Œ μ‚¬μš© 
(TO->FROM)

Parameters
TypeValueDescription

uint

_amountOut

swap μ‹œ 얻을 토큰 개수

address[]

_path

토큰 개수λ₯Ό 확인 ν•  토큰 쌍 μ£Όμ†Œ


Return Values
TypeValueDescription

uint[]

amounts

swap μ‹œ In/Out 토큰 개수


β€»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