GNSPriceAggregator

Facet #10: Price aggregator (does the requests to the Chainlink DON, takes the median, and executes callbacks)

Methods

addOracle

function addOracle(address _a) external nonpayable

Adds an oracle

Parameters

NameTypeDescription

_a

address

new value

function claimBackLink() external nonpayable

Claims back LINK tokens, called by gov fund

fulfill

function fulfill(bytes32 _requestId, uint256 _priceData) external nonpayable

Fulfills price request, called by chainlink oracles

Parameters

NameTypeDescription

_requestId

bytes32

request id

_priceData

uint256

price data

getChainlinkToken

function getChainlinkToken() external view returns (address)

Returns chainlink token address

Returns

NameTypeDescription

_0

address

getCollateralFromUsdNormalizedValue

function getCollateralFromUsdNormalizedValue(uint8 _collateralIndex, uint256 _normalizedValue) external view returns (uint256)

Returns collateral value (collateral precision) from USD normalized value

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

_normalizedValue

uint256

normalized value (1e18 USD)

Returns

NameTypeDescription

_0

uint256

getCollateralGnsUniV3Pool

function getCollateralGnsUniV3Pool(uint8 _collateralIndex) external view returns (struct IPriceAggregator.UniV3PoolInfo)

Returns collateral/gns uni v3 pool info

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

Returns

NameTypeDescription

_0

getCollateralPriceUsd

function getCollateralPriceUsd(uint8 _collateralIndex) external view returns (uint256)

Returns collateral/USD price

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

Returns

NameTypeDescription

_0

uint256

getCollateralUsdPriceFeed

function getCollateralUsdPriceFeed(uint8 _collateralIndex) external view returns (contract IChainlinkFeed)

Returns collateral/usd chainlink price feed

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

Returns

NameTypeDescription

_0

contract IChainlinkFeed

getGnsPriceCollateralAddress

function getGnsPriceCollateralAddress(address _collateral) external view returns (uint256)

Returns GNS/collateral price

Parameters

NameTypeDescription

_collateral

address

address of the collateral

Returns

NameTypeDescription

_0

uint256

getGnsPriceCollateralIndex

function getGnsPriceCollateralIndex(uint8 _collateralIndex) external view returns (uint256)

Returns GNS/collateral price

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

Returns

NameTypeDescription

_0

uint256

getGnsPriceUsd

function getGnsPriceUsd(uint8 _collateralIndex, uint256 _gnsPriceCollateral) external view returns (uint256)

Returns GNS/USD price based on GNS/collateral price

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

_gnsPriceCollateral

uint256

GNS/collateral price (1e10)

Returns

NameTypeDescription

_0

uint256

getGnsPriceUsd

function getGnsPriceUsd(uint8 _collateralIndex) external view returns (uint256)

Returns GNS/USD price based on GNS/collateral price

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

Returns

NameTypeDescription

_0

uint256

getLimitJobId

function getLimitJobId() external view returns (bytes32)

Returns the limit job id

Returns

NameTypeDescription

_0

bytes32

getLinkFee

function getLinkFee(uint8 _collateralIndex, uint16 _pairIndex, uint256 _positionSizeCollateral) external view returns (uint256)

Returns LINK fee for price request

Parameters

NameTypeDescription

_collateralIndex

uint8

collateral index

_pairIndex

uint16

pair index

_positionSizeCollateral

uint256

position size in collateral tokens (collateral precision)

Returns

NameTypeDescription

_0

uint256

getLinkUsdPriceFeed

function getLinkUsdPriceFeed() external view returns (IChainlinkFeed)

Returns the link/usd price feed address

Returns

NameTypeDescription

_0

contract IChainlinkFeed

getMarketJobId

function getMarketJobId() external view returns (bytes32)

Returns the market job id

Returns

NameTypeDescription

_0

bytes32

getMinAnswers

function getMinAnswers() external view returns (uint8)

Returns the minimum answers to execute an order and take the median

Returns

NameTypeDescription

_0

uint8

getOracle

function getOracle(uint256 _index) external view returns (address)

Returns a specific oracle

Parameters

NameTypeDescription

_index

uint256

index of the oracle

Returns

NameTypeDescription

_0

address

getOracles

function getOracles() external view returns (address[])

Returns all oracles

Returns

NameTypeDescription

_0

address[]

getPendingRequest

function getPendingRequest(bytes32 _id) external view returns (address)

Returns pendingRequests mapping entry (used by ChainlinkClientUtils)

Parameters

NameTypeDescription

_id

bytes32

Returns

NameTypeDescription

_0

address

getPrice

function getPrice(uint8 _collateralIndex, uint16 _pairIndex, ITradingStorage.Id _orderId, enum ITradingStorage.PendingOrderType _orderType, uint256 _positionSizeCollateral, uint256 _fromBlock) external nonpayable

Parameters

NameTypeDescription

_collateralIndex

uint8

_pairIndex

uint16

_orderId

_orderType

_positionSizeCollateral

uint256

_fromBlock

uint256

getPriceAggregatorOrder

function getPriceAggregatorOrder(bytes32 _requestId) external view returns (struct IPriceAggregator.Order)

Returns order data

Parameters

NameTypeDescription

_requestId

bytes32

index of collateral

Returns

NameTypeDescription

_0

getPriceAggregatorOrderAnswers

function getPriceAggregatorOrderAnswers(ITradingStorage.Id _orderId) external view returns (struct IPriceAggregator.OrderAnswer[])

Parameters

NameTypeDescription

_orderId

Returns

NameTypeDescription

_0

getRequestCount

function getRequestCount() external view returns (uint256)

Returns requestCount (used by ChainlinkClientUtils)

Returns

NameTypeDescription

_0

uint256

getTwapInterval

function getTwapInterval() external view returns (uint24)

Returns the twap interval in seconds

Returns

NameTypeDescription

_0

uint24

getUsdNormalizedValue

function getUsdNormalizedValue(uint8 _collateralIndex, uint256 _collateralValue) external view returns (uint256)

Returns USD normalized value from collateral value

Parameters

NameTypeDescription

_collateralIndex

uint8

index of collateral

_collateralValue

uint256

collateral value (collateral precision)

Returns

NameTypeDescription

_0

uint256

initializePriceAggregator

function initializePriceAggregator(address _linkToken, contract IChainlinkFeed _linkUsdPriceFeed, uint24 _twapInterval, uint8 _minAnswers, address[] _nodes, bytes32[2] _jobIds, uint8[] _collateralIndices, contract IUniswapV3Pool[] _gnsCollateralUniV3Pools, contract IChainlinkFeed[] _collateralUsdPriceFeeds) external nonpayable

Initializes price aggregator facet

Parameters

NameTypeDescription

_linkToken

address

LINK token address

_linkUsdPriceFeed

contract IChainlinkFeed

LINK/USD price feed address

_twapInterval

uint24

TWAP interval (seconds)

_minAnswers

uint8

answers count at which a trade is executed with median

_nodes

address[]

_jobIds

bytes32[2]

chainlink job ids (market/lookback)

_collateralIndices

uint8[]

collateral indices

_gnsCollateralUniV3Pools

contract IUniswapV3Pool[]

corresponding GNS/collateral Uniswap V3 pools addresses

_collateralUsdPriceFeeds

contract IChainlinkFeed[]

corresponding collateral/USD chainlink price feeds

removeOracle

function removeOracle(uint256 _index) external nonpayable

Removes an oracle

Parameters

NameTypeDescription

_index

uint256

oracle index

replaceOracle

function replaceOracle(uint256 _index, address _a) external nonpayable

Replaces an oracle

Parameters

NameTypeDescription

_index

uint256

oracle index

_a

address

new value

setLimitJobId

function setLimitJobId(bytes32 _jobId) external nonpayable

Updates lookback job id

Parameters

NameTypeDescription

_jobId

bytes32

new value

setMarketJobId

function setMarketJobId(bytes32 _jobId) external nonpayable

Updates market job id

Parameters

NameTypeDescription

_jobId

bytes32

new value

updateCollateralGnsUniV3Pool

function updateCollateralGnsUniV3Pool(uint8 _collateralIndex, contract IUniswapV3Pool _uniV3Pool) external nonpayable

Updates collateral/GNS Uniswap V3 pool

Parameters

NameTypeDescription

_collateralIndex

uint8

collateral index

_uniV3Pool

contract IUniswapV3Pool

new value

updateCollateralUsdPriceFeed

function updateCollateralUsdPriceFeed(uint8 _collateralIndex, contract IChainlinkFeed _value) external nonpayable

Updates collateral/USD chainlink price feed

Parameters

NameTypeDescription

_collateralIndex

uint8

collateral index

_value

contract IChainlinkFeed

new value

updateLinkUsdPriceFeed

function updateLinkUsdPriceFeed(contract IChainlinkFeed _value) external nonpayable

Updates LINK/USD chainlink price feed

Parameters

NameTypeDescription

_value

contract IChainlinkFeed

new value

updateMinAnswers

function updateMinAnswers(uint8 _value) external nonpayable

Updates minimum answers count

Parameters

NameTypeDescription

_value

uint8

new value

updateTwapInterval

function updateTwapInterval(uint24 _twapInterval) external nonpayable

Updates TWAP interval

Parameters

NameTypeDescription

_twapInterval

uint24

new value (seconds)

Events

ChainlinkFulfilled

event ChainlinkFulfilled(bytes32 indexed id)

Parameters

NameTypeDescription

id indexed

bytes32

ChainlinkRequested

event ChainlinkRequested(bytes32 indexed id)

Parameters

NameTypeDescription

id indexed

bytes32

CollateralGnsUniV3PoolUpdated

event CollateralGnsUniV3PoolUpdated(uint8 collateralIndex, IPriceAggregator.UniV3PoolInfo newValue)

Emitted when collateral/GNS Uniswap V3 pool is updated

Parameters

NameTypeDescription

collateralIndex

uint8

collateral index

newValue

new value

CollateralUsdPriceFeedUpdated

event CollateralUsdPriceFeedUpdated(uint8 collateralIndex, address value)

Emitted when collateral/USD price feed is updated

Parameters

NameTypeDescription

collateralIndex

uint8

collateral index

value

address

new value

JobIdUpdated

event JobIdUpdated(uint256 index, bytes32 jobId)

Emitted when market job id is updated

Parameters

NameTypeDescription

index

uint256

index

jobId

bytes32

new value

LinkClaimedBack

event LinkClaimedBack(uint256 amountLink)

Emitted when LINK tokens are claimed back by gov fund

Parameters

NameTypeDescription

amountLink

uint256

amount of LINK tokens claimed back

LinkRequestCreated

event LinkRequestCreated(Chainlink.Request request)

Emitted when a chainlink request is created

Parameters

NameTypeDescription

request

Chainlink.Request

link request details

LinkUsdPriceFeedUpdated

event LinkUsdPriceFeedUpdated(address value)

Emitted when LINK/USD price feed is updated

Parameters

NameTypeDescription

value

address

new value

MinAnswersUpdated

event MinAnswersUpdated(uint8 value)

Emitted when minimum answers count is updated

Parameters

NameTypeDescription

value

uint8

new value

OracleAdded

event OracleAdded(uint256 index, address value)

Emitted when an oracle is added

Parameters

NameTypeDescription

index

uint256

new oracle index

value

address

value

OracleRemoved

event OracleRemoved(uint256 index, address oldOracle)

Emitted when an oracle is removed

Parameters

NameTypeDescription

index

uint256

oracle index

oldOracle

address

old value

OracleReplaced

event OracleReplaced(uint256 index, address oldOracle, address newOracle)

Emitted when an oracle is replaced

Parameters

NameTypeDescription

index

uint256

oracle index

oldOracle

address

old value

newOracle

address

new value

PriceReceived

event PriceReceived(ITradingStorage.Id orderId, uint16 indexed pairIndex, bytes32 request, uint256 priceData, bool isLookback, bool usedInMedian)

Emitted when a price is received from the oracles

Parameters

NameTypeDescription

orderId

pending order id

pairIndex indexed

uint16

trading pair index

request

bytes32

chainlink request id

priceData

uint256

OrderAnswer compressed into uint256

isLookback

bool

true if lookback

usedInMedian

bool

false if order already executed because min answers count was already reached

PriceRequested

event PriceRequested(uint8 collateralIndex, ITradingStorage.Id pendingOrderId, enum ITradingStorage.PendingOrderType indexed orderType, uint256 indexed pairIndex, bytes32 indexed job, uint256 nodesCount, uint256 linkFeePerNode, uint256 fromBlock, bool isLookback)

Emitted when a price is requested to the oracles

Parameters

NameTypeDescription

collateralIndex

uint8

collateral index

pendingOrderId

pending order id

orderType indexed

order type (market open/market close/limit open/stop open/etc.)

pairIndex indexed

uint256

trading pair index

job indexed

bytes32

chainlink job id (market/lookback)

nodesCount

uint256

amount of nodes to fetch prices from

linkFeePerNode

uint256

link fee distributed per node (1e18 precision)

fromBlock

uint256

block number from which to start fetching prices (for lookbacks)

isLookback

bool

true if lookback

TradingCallbackExecuted

event TradingCallbackExecuted(ITradingCallbacks.AggregatorAnswer a, enum ITradingStorage.PendingOrderType orderType)

Emitted when a trading callback is called from the price aggregator

Parameters

NameTypeDescription

a

aggregator answer data

orderType

order type

TwapIntervalUpdated

event TwapIntervalUpdated(uint32 newValue)

Emitted when TWAP interval is updated

Parameters

NameTypeDescription

newValue

uint32

new value

Errors

AboveMax

error AboveMax()

AlreadyExists

error AlreadyExists()

BelowMin

error BelowMin()

BlockOrder

error BlockOrder()

DoesntExist

error DoesntExist()

InitError

error InitError()

InvalidAddresses

error InvalidAddresses()

InvalidCandle

error InvalidCandle()

InvalidCollateralIndex

error InvalidCollateralIndex()

InvalidInputLength

error InvalidInputLength()

NotAllowed

error NotAllowed()

NotAuthorized

error NotAuthorized()

OracleAlreadyListed

error OracleAlreadyListed()

Overflow

error Overflow()

Paused

error Paused()

RequestAlreadyPending

error RequestAlreadyPending()

SourceNotOracleOfRequest

error SourceNotOracleOfRequest()

T

error T()

TransferAndCallToOracleFailed

error TransferAndCallToOracleFailed()

WrongAccess

error WrongAccess()

WrongCollateralUsdDecimals

error WrongCollateralUsdDecimals()

WrongIndex

error WrongIndex()

WrongLength

error WrongLength()

WrongOrder

error WrongOrder()

WrongParams

error WrongParams()

WrongTradeType

error WrongTradeType()

ZeroAddress

error ZeroAddress()

ZeroValue

error ZeroValue()

Last updated