function getPriceImpact(
uint256 _tokenAmount,
address[] memory _path
) public view returns (uint256 priceImpact)
//수수료 사용 유무에 따라 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);
}
// 영향도 얻기
await routerContract.getPriceImpact(
10000,
[mockToken0Contract.address, mockToken1Contract.address]
)
// 결과 (0.02%의 영향도)
BigNumber { value: "2" }