getSwapAmountsOut

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

Swap ė‹œ 받ė„ ėˆ˜ ėžˆëŠ” 개ėˆ˜ëĨž ė–ŧė„ 때 ė‚ŽėšĐ (FROM->TO)

Parameters

TypeValueDescription

uint

_amountIn

swap ė‹œ 바ęŋ€ 토큰 개ėˆ˜

address[]

_path

토큰 개ėˆ˜ëĨž 확ėļ 할 토큰 ėŒ ėĢžė†Œ

Return Values

TypeValueDescription

uint[]

amounts

swap ė‹œ In/Out 토큰 개ėˆ˜

â€ŧ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