getPriceImpact

function getPriceImpact(
    uint256 _tokenAmount,
    address[] memory _path
) public view returns (uint256 priceImpact)

μœ λ™μ„±ν’€μ˜ 영ν–₯도λ₯Ό ꡬ할 λ•Œ μ‚¬μš©

(Swap μ‹œ κΈ°λ³Έ 5%둜 μ„€μ •)

Parameters

Return Values

β€» Reservesλ₯Ό ν†΅ν•œ μ—°μ‚° 방법

//수수료 μ‚¬μš© μœ λ¬΄μ— 따라 swapFee 지정(30 = 0.03%)
uint amountInWithFee = amountIn*(10000-swapFee)
uint numerator = amountInWithFee*(reserveOut);
uint denominator = (reserveIn*10000)+amountInWithFee;
destAmount = numerator / denominator;


amountA = (amountIn*(10000-swapFee))/(10000)      
amountInFee = (amountA*reserveB) / reserveA
if (amountInFee <= destAmount) {
    priceImpact = 0;
} else {
    priceImpact = (((amountInFee - destAmount) * 10000) / amountInFee);
}

Example

// 영ν–₯도 μ–»κΈ°
await routerContract.getPriceImpact(
    10000,
    [mockToken0Contract.address, mockToken1Contract.address]
)

// κ²°κ³Ό (0.02%의 영ν–₯도)
BigNumber { value: "2" }    

2023.01.10

Last updated