BiPoolManager
Last updated
Last updated
BiPoolManager is the first implementation of an which manages virtual asset pools that consist of two assets. It is responsible for managing pools and using their state to price swaps. It also checks if trading is allowed or suspended as decided by the on-chain circuit breaker via the contract.
The PoolExchange
and PoolConfig
structures are the underlying data structures used by the BiPoolManager to implement a vAMM bi-pool (i.e. a pool with two assets).
asset0
address
ERC20 token address of the 1st asset in the pair. This can only be a StableToken registered with the Reserve.
asset1
address
ERC20 token address of the 2nd asset in the pair. This can be either a StableToken or any Mento Collateral asset registered with the Reserve.
pricingModule
IPricingModule
bucket0
uint256
The amount of asset0 tokens in the pool, updates as a result of swaps and bucket resets.
bucket1
uint256
The amount of asset1 tokens in the pool, updates as a result of swaps and bucket resets.
lastBucketUpdate
uint256
Timestamp of the last bucket reset.
config
PoolConfig
Some extra configuration items are stored in a separate struct because of Solidity version limitations.
spread
FixidityLib.Fraction
The spread or fee charged on swaps
referenceRateFeedID
address
The oracle rateFeedID used as a reference rate for the asset0/asset1
pair.
referenceRateResetFrequency
uint256
How often the buckets reset to the reference rate.
minimumReports
uint256
The amount of on-chain reports required in order to trust the reference rate.
stablePoolResetSize
uint256
The value that bucket0 resets to when a bucket update happens.
This returns the generic exchange structures that are shared between all implementers of the IExchangeProvider interface, this is why the assets
is an array, to account for potential 3-asset pools in the future.
You can then also query the internal representation:
There is also getAmountIn
which calculates the required input tokens needed to receive a given amount of output tokens.
This function executes, in that it prices the swap and updates the virtual bucket sizes of the PoolExchange. The Broker uses the return value to determine how many output tokens to transfer to the initiator for the input tokens received. Similarly, there's a swapOut
function which fixes the output tokens and returns a variable amount of input tokens required.
The vAMM pricing function, a contract that implements , like or
This function calculates the expected output tokens you will receive for a given amount of input tokens. It is what the Broker uses internally in its own .