getPriceImpact

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

์œ ๋™์„ฑํ’€์˜ ์˜ํ–ฅ๋„๋ฅผ ๊ตฌํ•  ๋•Œ ์‚ฌ์šฉ

(Swap ์‹œ ๊ธฐ๋ณธ 5%๋กœ ์„ค์ •)

Parameters

TypeValueExplain

uint256

_tokenAmount

๊ตํ™˜ ํ•  ํ† ํฐ ๊ฐœ์ˆ˜

address[]

_path

์˜ํ–ฅ๋„๋ฅผ ํ™•์ธ ํ•  ํ† ํฐ ์Œ ์ฃผ์†Œ

Return Values

TypeValueExplain

uint256

priceImpact

์˜ํ–ฅ๋„ % 1๋งŒ์ž๋ฆฌ(๋ฐฑ๋ถ„์œจ, ์†Œ์ˆ˜์ 2๊นŒ์ง€ ํ‘œํ˜„)

โ€ป 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