Skip to main content

Reference

Interfaces, signatures, parameters, and generated references.

Lookup friendly
TOC available

Pair

constructor(tokenAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount)

The Pair entity represents a Ring pair with a balance of each of its pair tokens. In Ring Swap, those pair tokens are often FewToken addresses rather than the original ERC-20 assets shown in your UI.

Example

import { ChainId, Token, CurrencyAmount } from '@ring-protocol/sdk-core'
import { Pair, getFewTokenFromOriginalToken } from '@ring-protocol/v2-sdk'

const HOT = new Token(ChainId.MAINNET, '0xc0FFee0000000000000000000000000000000000', 18, 'HOT', 'Caffeine')
const NOT = new Token(ChainId.MAINNET, '0xDeCAf00000000000000000000000000000000000', 18, 'NOT', 'Caffeine')
const fewHOT = getFewTokenFromOriginalToken(HOT, ChainId.MAINNET)
const fewNOT = getFewTokenFromOriginalToken(NOT, ChainId.MAINNET)

const pair = new Pair(
CurrencyAmount.fromRawAmount(fewHOT, '2000000000000000000'),
CurrencyAmount.fromRawAmount(fewNOT, '1000000000000000000')
)

Static Methods

getAddress

getAddress(tokenA: Token, tokenB: Token): string

Computes the pair address for the passed Tokens. Pass the actual pair tokens used in the pool, which are often FewToken addresses in Ring Swap. See Pair Addresses.

Properties

liquidityToken

liquidityToken: Token

A Token representing the liquidity token for the pair. See Pair (ERC-20).

token0

token0: Token

See Token0.

token1

token1: Token

See Token1.

reserve0

reserve0: CurrencyAmount

The reserve of token0.

reserve1

reserve1: CurrencyAmount

The reserve of token1.

Methods

reserveOf

reserveOf(token: Token): CurrencyAmount

Returns reserve0 or reserve1, depending on whether token0 or token1 is passed in.

getOutputAmount

getOutputAmount(inputAmount: CurrencyAmount): [CurrencyAmount, Pair]

Pricing function for exact input amounts. Returns maximum output amount based on current reserves and the new Pair that would exist if the trade were executed.

getInputAmount

getInputAmount(outputAmount: CurrencyAmount): [CurrencyAmount, Pair]

Pricing function for exact output amounts. Returns minimum input amount based on current reserves and the new Pair that would exist if the trade were executed.

getLiquidityMinted

getLiquidityMinted(totalSupply: CurrencyAmount, tokenAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount): CurrencyAmount

Calculates the exact amount of liquidity tokens minted from a given amount of token0 and token1.

  • totalSupply must be looked up on-chain.
  • The value returned from this function cannot be used as an input to getLiquidityValue.

getLiquidityValue

getLiquidityValue(
token: Token,
totalSupply: CurrencyAmount,
liquidity: CurrencyAmount,
feeOn: boolean = false,
kLast?: BigintIsh
): CurrencyAmount

Calculates the exact amount of token0 or token1 that the given amount of liquidity tokens represent.

  • totalSupply must be looked up on-chain.
  • If the protocol charge is on, feeOn must be set to true, and kLast must be provided from an on-chain lookup.
  • Values returned from this function cannot be used as inputs to getLiquidityMinted.