Class MarketExchangeRate

This class is for convenient conversion between pt <-> asset and yt <-> asset, with a given market's exchange rate.

Market's exchange rate can be obtained from MarketEntity#getMarketInfo().exchangeRate, divided by ONE (10^18)

The exchange rate ($x$) is the rate of converting the underlying asset into pt, that is

 1 asset = x PT                      (1.1)
1 PT = 1/x asset (1.2)

From here we can have the formula for converting asset <-> PT

For converting asset <-> YT, we need the following formula from the yield tokenization model

 1 asset = 1 PT + 1 YT               (2)

From (1.2) and (2), we have:

 1 asset = 1/x asset + 1 YT

<=> 1 asset = x / (x - 1) YT (3.1) and 1 YT = (1 - 1 / x) asset (3.2)

Constructors

Properties

exchangeRate: BN

Note that, in the above formula, x = this.exchangeRate / ONE

Methods

  • See formula (3.1)

    1 asset = x / (x - 1) / YT = (this.exchangeRate / ONE) / (this.exchangeRate / ONE - 1) YT = this.exchangeRate / (this.exchangeRate - ONE) YT

    So if we have k = assetAmount k asset = k * this.exchangeRate / (this.exchangeRate - ONE) YT

    Parameters

    Returns BN

  • See formula (3.2) 1 YT = (1 - 1/x) asset = (x - 1) / x asset = (this.exchangeRate / ONE - 1) / (this.exchangeRate / ONE) asset = (this.exchangeRate - ONE) / this.exchangeRate asset

    So if we have k = ytAmount k YT = k * (this.exchangeRate - ONE) / this.exchangeRate asset

    Parameters

    Returns BN

Generated using TypeDoc