getShareOfPool

function getShareOfPool( 
   address _tokenA, 
   address _tokenB, 
   uint _amountADesired, 
   uint _amountBDesired, 
   bool _owned
)external view returns (uint poolRatio)

์œ ๋™์„ฑ ํ’€์˜ ์ง€๋ถ„์œจ ๊ตฌํ•  ๋•Œ ์‚ฌ์šฉ

Parameters

TypeValueDescription

address

_tokenA

LP ํ† ํฐA ์ฃผ์†Œ

address

_tokenB

LP ํ† ํฐB ์ฃผ์†Œ

uint

_amountADesired

LP ํ† ํฐA ๊ฐœ์ˆ˜

uint

_admoutBDesired

LP ํ† ํฐB ๊ฐœ์ˆ˜

bool

_owned

์†Œ์œ ์ค‘์ธ ์œ ๋™์„ฑ ํ’€ ์ง€๋ถ„์œจ ํ™•์ธ ์—ฌ๋ถ€ true : ์†Œ์œ ์ค‘์ธ ์œ ๋™์„ฑ ํ’€ ์ง€๋ถ„์œจ false : ๊ฐ’์— ์˜ํ•œ ์œ ๋™์„ฑ ํ’€ ์ง€๋ถ„

Return Values

TypeValueDescription

uint

poolRatio

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

โ€ป Reserves๋ฅผ ํ†ตํ•œ ์—ฐ์‚ฐ ๋ฐฉ๋ฒ•

// totalLiquidity์˜ ๊ฒฝ์šฐ pairContract totalSupply()๋ฅผ ํ†ตํ•ด ํš๋“

liquidity = Math.min((amount0*totalLiquidity) / _reserve0, (amount1*totalLiquidity) / _reserve1);
totalLiquidity = totalLiquidity+liquidity;

// 1๋งŒ์ž๋ฆฌ ์—ฐ์‚ฐ์„ ์œ„ํ•ด..
uint _numerator  = liquidity * (10 ** 5);
uint _quotient =  ((_numerator / (totalLiquidity)) + 5) / 10;

if( liquidity > 0 )
    return _quotient >= 10000 ? 10000 : _quotient;
else
    return 0;

Example

// ์ง€๋ถ„์œจ ์–ป๊ธฐ(๊ฐ’์— ์˜ํ•œ)
await routerContract.getShareOfPool(
    mockToken0Contract.address, 
    mockToken1Contract.address, 
    ethers.utils.parseEther("10.0"), 
    ethers.utils.parseEther("5.0"),
    false
)

// ๊ฒฐ๊ณผ (9.09%์˜ ์˜ํ–ฅ๋„)
BigNumber { value: "909" }

    
// ์ง€๋ถ„์œจ ์–ป๊ธฐ(์†Œ์œ ์ค‘์ธ)
await routerContract..getShareOfPool(
    mockToken0Contract.address,
    mockToken1Contract.address,
    0,
    0,
    true
)
    
// ๊ฒฐ๊ณผ (100%์˜ ์˜ํ–ฅ๋„)
BigNumber { value: "10000" }

2023.01.11

Last updated