Links

BalancerV2PriceProvider

BalancerV2PriceProvider
Price provider contract that reads prices from BalancerV2

Methods

acceptOwnership

function acceptOwnership() external nonpayable
Transfers ownership of the contract to a pending owner Can only be called by the pending owner.

assetSupported

function assetSupported(address _asset) external view returns (bool)
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

function assetsPools(address) external view returns (bytes32 poolId, address priceOracle, bool token0isAsset)
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

function changePeriodForAvgPrice(uint32 _period) external nonpayable
Change period for average price

Parameters

Name
Type
Description
_period
uint32
period in seconds for TWAP price, ie. 1800 means 30 min

changeSecondsAgo

function changeSecondsAgo(uint32 _ago) external nonpayable
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

function changeSettings(uint32 _period, uint32 _ago) external nonpayable
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

function getPoolQuoteLiquidity(bytes32 _poolId) external view returns (uint256)
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

function getPrice(address _asset) external view returns (uint256 price)
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

function owner() external view returns (address)
Returns the address of the current owner.

Returns

Name
Type
Description
_0
address
undefined

pendingOwner

function pendingOwner() external view returns (address)
Returns the address of the pending owner.

Returns

Name
Type
Description
_0
address
undefined

periodForAvgPrice

function periodForAvgPrice() external view returns (uint256)
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

function priceBufferReady(address _asset) external view returns (bool)
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

function priceProviderPing() external pure returns (bool)
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

function priceProvidersRepository() external view returns (contract IPriceProvidersRepository)
PriceProvidersRepository address

Returns

Name
Type
Description
_0
contract IPriceProvidersRepository
undefined

quoteToken

function quoteToken() external view returns (address)
Token address which prices are quoted in. Must be the same as PriceProvidersRepository.quoteToken

Returns

Name
Type
Description
_0
address
undefined

renounceOwnership

function renounceOwnership() external nonpayable
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

function resolvePoolAddress(bytes32 _poolId) external pure returns (address)
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

function secondsAgo() external view returns (uint256)
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

function setupAsset(address _asset, bytes32 _poolId) external nonpayable
Setup pool for asset. Use it also for update.

Parameters

Name
Type
Description
_asset
address
asset address
_poolId
bytes32
BalancerV2 pool ID

transferOwnership

function transferOwnership(address newOwner) external nonpayable
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

function transferPendingOwnership(address newPendingOwner) external nonpayable
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

function vault() external view returns (contract IVault)
main BalancerV2 contract, something like router for Uniswap but much more

Returns

Name
Type
Description
_0
contract IVault
undefined

verifyPool

function verifyPool(bytes32 _poolId, address _asset) external view returns (contract IERC20[] tokens)
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

event NewPeriod(uint32 period)
Emitted when TWAP period changes

Parameters

Name
Type
Description
period
uint32
new period in seconds, ie. 1800 means 30 min

NewSecondsAgo

event NewSecondsAgo(uint32 ago)
Emitted when seconds ago changes

Parameters

Name
Type
Description
ago
uint32
new seconds ago value in seconds, ie. 1800 means 30 min

OwnershipPending

event OwnershipPending(address indexed previousOwner, address indexed newOwner)

Parameters

Name
Type
Description
previousOwner indexed
address
undefined
newOwner indexed
address
undefined

OwnershipTransferred

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)

Parameters

Name
Type
Description
previousOwner indexed
address
undefined
newOwner indexed
address
undefined

PoolForAsset

event PoolForAsset(address asset, bytes32 poolId)
Emitted when BalancerV2 pool is set for asset

Parameters

Name
Type
Description
asset
address
asset address
poolId
bytes32
BalancerV2 pool ID