Developers
Search…
MetaStable Pool

Overview

For advantages and use cases of MetaStable Pools, please refer to the standard documentation.
For more interfaces, such as updating the amplificationParameter or querying price data from the pool oracle interface, see the MetaStablePool API.

Interfacing

Some elements to consider when interfacing with Stable Pools:
  • Using the MetaStable extension of Stable Math (be sure to see MetaStable.ts!)
  • Pools have 2 tokens
  • Pools rely on the amplificationParameter, which is defined at pool creation and can be gradually updated later.
  • Pools also rely on RateProviders for each token in the pool to determine the exchange rate. If a token's RateProvider is set to the zero address, the rate is set to 1.

Getting Pool Data

In addition to the common pool data, you will likely want the following data when interfacing with MetaStable Pools:

Amplification Parameter

The Amplification Parameter is stored at the pool level. For example, calling
1
pool.getAmplificationParameter()
Copied!
returns something resembling
1
value : 620000
2
isUpdating : False
3
precision : 1000
Copied!
where the amplification parameter is
valueprecision=6200001000=620\frac{value}{precision} = \frac{620000}{1000}=620
in this case.

Rate Providers

The RateProviders are contract addresses stored at the pool level. The pool calls these providers to get the current exchange rates between the tokens in the pool. Calling
1
pool.getRateProviders()
Copied!
returns something resembling
1
[0x72d07d7dca67b8a406ad1ec34ce969c90bfee768]
Copied!
where the contract at 0x72d07d7dca67b8a406ad1ec34ce969c90bfee768 is a RateProvider that has a function called getRate(). In this example, this MetaStable Pool has only one RateProvider. This implies that the rate is the ratio of Token1:Token2.
In other use cases, there may be multiple RateProviders that provide a price from each token to a common base. For example, the rate providers could be
Token1RateProvider returns Token1:USD
Token2RateProvider returns Token2:USD
And to find the price of Token1:Token2, you would divide Token1:USD/Token2:USD to cancel out the intermediate USD.

Price Rate Cache

MetaStable Pools cache prices from RateProviders up to a maximum duration. These cached prices are updated either manually using updatePriceRateCache() or automatically during a trade when the cache has expired.

getScalingFactors

To access the simplest form of Price Rate data, you can call
1
pool.getScalingFactors()
Copied!
which will return something resembling
1
[1047560735332976763, 1000000000000000000]
Copied!
where the values are the cached prices scaled to have appropriate decimals. For tokens that do not have a RateProvider (set to 0x0000000000000000000000000000000000000000), they will return a scalingFactor of 1000000000000000000 =
1e181e18
.
Values are ordered according to numerically sorted token addresses. In this example, these values correspond to [0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2].

getPriceRateCache

To see exactly what price rate data a MetaStable pool is currently using, call
1
pool.getPriceRateCache(tokenAddress)
Copied!
and the results will resemble one of the following:

For tokens that DO have a Price Rate

1
rate uint256 : 1047560735332976763
2
duration uint256 : 10800
3
expires uint256 : 1636558429
Copied!

For tokens that DO NOT have a Price Rate

1
rate uint256 : 0
2
duration uint256 : 0
3
expires uint256 : 0
Copied!
In these samples, you can see that the token with a Price Rate has a duration of 10800 seconds (3 hours) and an expiration timestamp. The rate is cached exactly as it comes from the RateProvider. It's possible that a token price may need to be decimal adjusted for the price rate to make sense.
For the token without a Price Rate, the rate is not actually interpreted as 0, but rather as 1000000000000000000 =
1e181e18
.

Oracle Data

To query oracle data from a MetaStable Pool, refer to the Oracle Pools interfacing page.