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