BalancerV2PriceProvider
BalancerV2PriceProvider
Price provider contract that reads prices from BalancerV2
Methods
acceptOwnership
Transfers ownership of the contract to a pending owner Can only be called by the pending owner.
assetSupported
Informs if PriceProvider is setup for asset. It does not means PriceProvider can provide price right away. Some providers implementations need time to "build" buffor for TWAP price, so price may not be available yet but this method will return true.
Parameters
Name | Type | Description |
---|---|---|
_asset | address | asset in question |
Returns
Name | Type | Description |
---|---|---|
_0 | bool | TRUE if asset has been setup, otherwise false |
assetsPools
Maps asset address to BalancerPool struct
Parameters
Name | Type | Description |
---|---|---|
_0 | address | undefined |
Returns
Name | Type | Description |
---|---|---|
poolId | bytes32 | undefined |
priceOracle | address | undefined |
token0isAsset | bool | undefined |
changePeriodForAvgPrice
Change period for average price
Parameters
Name | Type | Description |
---|---|---|
_period | uint32 | period in seconds for TWAP price, ie. 1800 means 30 min |
changeSecondsAgo
Change number of seconds in the past where calcualtions starts for average price
Parameters
Name | Type | Description |
---|---|---|
_ago | uint32 | new seconds ago value in seconds, ie. 1800 means 30 min |
changeSettings
Change period for average price and number of seconds in the past where calcualtions starts for average price
Parameters
Name | Type | Description |
---|---|---|
_period | uint32 | period in seconds for TWAP price, ie. 1800 means 30 min |
_ago | uint32 | new seconds ago value in seconds, ie. 1800 means 30 min |
getPoolQuoteLiquidity
Gets amount of quote token deposited in the pool
Parameters
Name | Type | Description |
---|---|---|
_poolId | bytes32 | must be valid pool for asset, balancer will throw BAL#500 if it's not |
Returns
Name | Type | Description |
---|---|---|
_0 | uint256 | amount of quote token in the pool |
getPrice
Returns price for a given asset
Balancer docs: | Some pools (WeightedPool2Tokens and MetaStable Pools) have optional Oracle functionality. | This means that they can be used as sources of on-chain price data. | Note from balancer docs: that you can only call getWeightedTimeAverage after the buffer is full, | or it will revert with ORACLE_NOT_INITIALIZED. If you call getSample(1023) and it returns 0's, | that means the buffer's not full yet. We are using Resilient way (recommended by balancer for lending protocols), Less up-to-date but more resilient to manipulation
Parameters
Name | Type | Description |
---|---|---|
_asset | address | asset address |
Returns
Name | Type | Description |
---|---|---|
price | uint256 | of asset in 18 decimals |
owner
Returns the address of the current owner.
Returns
Name | Type | Description |
---|---|---|
_0 | address | undefined |
pendingOwner
Returns the address of the pending owner.
Returns
Name | Type | Description |
---|---|---|
_0 | address | undefined |
periodForAvgPrice
Information for a Time Weighted Average query.
Each query computes the average over a window of duration secs
seconds that ended ago
seconds ago. For example, the average over the past 30 minutes is computed by settings secs to 1800 and ago to 0. If secs is 1800 and ago is 1800 as well, the average between 60 and 30 minutes ago is computed instead.
Returns
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
priceBufferReady
Checks if price buffer is ready for a BalancerV2 pool assigned to an asset
Parameters
Name | Type | Description |
---|---|---|
_asset | address | asset address |
Returns
Name | Type | Description |
---|---|---|
_0 | bool | true if buffer ready, otherwise false |
priceProviderPing
Helper method that allows easily detects, if contract is PriceProvider
this can save us from simple human errors, in case we use invalid address but this should NOT be treated as security check
Returns
Name | Type | Description |
---|---|---|
_0 | bool | always true |
priceProvidersRepository
PriceProvidersRepository address
Returns
Name | Type | Description |
---|---|---|
_0 | contract IPriceProvidersRepository | undefined |
quoteToken
Token address which prices are quoted in. Must be the same as PriceProvidersRepository.quoteToken
Returns
Name | Type | Description |
---|---|---|
_0 | address | undefined |
renounceOwnership
Leaves the contract without owner. It will not be possible to call onlyOwner
functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.
resolvePoolAddress
Returns the address of a Pool's contract.
Due to how Pool IDs are created, this is done with no storage accesses and costs little gas.
Parameters
Name | Type | Description |
---|---|---|
_poolId | bytes32 | valid pool for asset |
Returns
Name | Type | Description |
---|---|---|
_0 | address | pool address |
secondsAgo
Information for a Time Weighted Average query
Each query computes the average over a window of duration secs
seconds that ended ago
seconds ago.
Returns
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
setupAsset
Setup pool for asset. Use it also for update.
Parameters
Name | Type | Description |
---|---|---|
_asset | address | asset address |
_poolId | bytes32 | BalancerV2 pool ID |
transferOwnership
Transfers ownership of the contract to a new account (newOwner
). Can only be called by the current owner.
Parameters
Name | Type | Description |
---|---|---|
newOwner | address | undefined |
transferPendingOwnership
Transfers pending ownership of the contract to a new account (newPendingOwner
). Can only be called by the current owner.
Parameters
Name | Type | Description |
---|---|---|
newPendingOwner | address | undefined |
vault
main BalancerV2 contract, something like router for Uniswap but much more
Returns
Name | Type | Description |
---|---|---|
_0 | contract IVault | undefined |
verifyPool
Checks if provided _poolId
is valid pool for _asset
NOTICE: keep in ming anyone can register pool in balancer Vault https://github.com/balancer-labs/balancer-v2-monorepo /blob/09c69ed5dc4715a0076c1dc87a81c0b6c2669b5a/pkg/vault/contracts/PoolRegistry.sol#L67 Only some pools (WeightedPool2Tokens and MetaStable Pools) provides oracle functionality. To be 100% sure, if pool has build-in oracle, we need to do call for getLargestSafeQueryWindow() and see if it fails or not.
Parameters
Name | Type | Description |
---|---|---|
_poolId | bytes32 | balancer poolId |
_asset | address | token address for which we want to check the pool |
Returns
Name | Type | Description |
---|---|---|
tokens | contract IERC20[] | IERC20[] pool tokens in original order, throws when pool is invalid |
Events
NewPeriod
Emitted when TWAP period changes
Parameters
Name | Type | Description |
---|---|---|
period | uint32 | new period in seconds, ie. 1800 means 30 min |
NewSecondsAgo
Emitted when seconds ago changes
Parameters
Name | Type | Description |
---|---|---|
ago | uint32 | new seconds ago value in seconds, ie. 1800 means 30 min |
OwnershipPending
Parameters
Name | Type | Description |
---|---|---|
previousOwner | address | undefined |
newOwner | address | undefined |
OwnershipTransferred
Parameters
Name | Type | Description |
---|---|---|
previousOwner | address | undefined |
newOwner | address | undefined |
PoolForAsset
Emitted when BalancerV2 pool is set for asset
Parameters
Name | Type | Description |
---|---|---|
asset | address | asset address |
poolId | bytes32 | BalancerV2 pool ID |
Last updated