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