Skip to main content
Interface for GNSPriceAggregator facet (inherits types and also contains functions, events, and custom errors)

initializePriceAggregator

function initializePriceAggregator(address _linkToken, contract IChainlinkFeed _linkUsdPriceFeed, uint24 _twapInterval, uint8 _minAnswers, address[] _oracles, bytes32[2] _jobIds, uint8[] _collateralIndices, struct IPriceAggregator.LiquidityPoolInput[] _gnsCollateralLiquidityPools, contract IChainlinkFeed[] _collateralUsdPriceFeeds) external
Initializes price aggregator facet

Parameters

NameTypeDescription
_linkTokenaddressLINK token address
_linkUsdPriceFeedcontract IChainlinkFeedLINK/USD price feed address
_twapIntervaluint24TWAP interval (seconds)
_minAnswersuint8answers count at which a trade is executed with median
_oraclesaddress[]chainlink oracle addresses
_jobIdsbytes32[2]chainlink job ids (market/lookback)
_collateralIndicesuint8[]collateral indices
_gnsCollateralLiquidityPoolsIPriceAggregator.LiquidityPoolInput[]corresponding GNS/collateral liquidity pool values
_collateralUsdPriceFeedscontract IChainlinkFeed[]corresponding collateral/USD chainlink price feeds

updateLinkUsdPriceFeed

function updateLinkUsdPriceFeed(contract IChainlinkFeed _value) external
Updates LINK/USD chainlink price feed

Parameters

NameTypeDescription
_valuecontract IChainlinkFeednew value

updateCollateralUsdPriceFeed

function updateCollateralUsdPriceFeed(uint8 _collateralIndex, contract IChainlinkFeed _value) external
Updates collateral/USD chainlink price feed

Parameters

NameTypeDescription
_collateralIndexuint8collateral index
_valuecontract IChainlinkFeednew value

updateCollateralGnsLiquidityPool

function updateCollateralGnsLiquidityPool(uint8 _collateralIndex, struct IPriceAggregator.LiquidityPoolInput _liquidityPoolInput) external
Updates collateral/GNS liquidity pool

Parameters

NameTypeDescription
_collateralIndexuint8collateral index
_liquidityPoolInputIPriceAggregator.LiquidityPoolInputnew values

updateTwapInterval

function updateTwapInterval(uint24 _twapInterval) external
Updates TWAP interval

Parameters

NameTypeDescription
_twapIntervaluint24new value (seconds)

updateMinAnswers

function updateMinAnswers(uint8 _value) external
Updates minimum answers count

Parameters

NameTypeDescription
_valueuint8new value

addOracle

function addOracle(address _a) external
Adds an oracle

Parameters

NameTypeDescription
_aaddressnew value

replaceOracle

function replaceOracle(uint256 _index, address _a) external
Replaces an oracle

Parameters

NameTypeDescription
_indexuint256oracle index
_aaddressnew value

removeOracle

function removeOracle(uint256 _index) external
Removes an oracle

Parameters

NameTypeDescription
_indexuint256oracle index

setMarketJobId

function setMarketJobId(bytes32 _jobId) external
Updates market job id

Parameters

NameTypeDescription
_jobIdbytes32new value

setLimitJobId

function setLimitJobId(bytes32 _jobId) external
Updates lookback job id

Parameters

NameTypeDescription
_jobIdbytes32new value

getPrice

function getPrice(uint8 _collateralIndex, uint16 _pairIndex, struct ITradingStorage.Id _tradeId, struct ITradingStorage.Id _orderId, enum ITradingStorage.PendingOrderType _orderType, uint256 _positionSizeCollateral, uint256 _fromBlock) external
Requests price from oracles

Parameters

NameTypeDescription
_collateralIndexuint8collateral index
_pairIndexuint16pair index
_tradeIdITradingStorage.Idtrade id
_orderIdITradingStorage.Idorder id
_orderTypeenum ITradingStorage.PendingOrderTypeorder type
_positionSizeCollateraluint256position size (collateral precision)
_fromBlockuint256block number from which to start fetching prices (for lookbacks)

fulfill

function fulfill(bytes32 _requestId, uint256 _priceData) external
Fulfills price request, called by chainlink oracles

Parameters

NameTypeDescription
_requestIdbytes32request id
_priceDatauint256price data
function claimBackLink() external
Claims back LINK tokens, called by gov fund

getLinkFee

function getLinkFee(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint256 _positionSizeCollateral) external view returns (uint256)
Returns LINK fee for price request

Parameters

NameTypeDescription
_collateralIndexuint8collateral index
_traderaddresstrader address
_pairIndexuint16pair index
_positionSizeCollateraluint256position size in collateral tokens (collateral precision)

getCollateralPriceUsd

function getCollateralPriceUsd(uint8 _collateralIndex) external view returns (uint256)
Returns collateral/USD price

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral

getUsdNormalizedValue

function getUsdNormalizedValue(uint8 _collateralIndex, uint256 _collateralValue) external view returns (uint256)
Returns USD normalized value from collateral value

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral
_collateralValueuint256collateral value (collateral precision)

getCollateralFromUsdNormalizedValue

function getCollateralFromUsdNormalizedValue(uint8 _collateralIndex, uint256 _normalizedValue) external view returns (uint256)
Returns collateral value (collateral precision) from USD normalized value

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral
_normalizedValueuint256normalized value (1e18 USD)

getGnsPriceUsd

function getGnsPriceUsd(uint8 _collateralIndex) external view returns (uint256)
Returns GNS/USD price based on GNS/collateral price

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral

getGnsPriceUsd

function getGnsPriceUsd(uint8 _collateralIndex, uint256 _gnsPriceCollateral) external view returns (uint256)
Returns GNS/USD price based on GNS/collateral price

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral
_gnsPriceCollateraluint256GNS/collateral price (1e10)

getGnsPriceCollateralIndex

function getGnsPriceCollateralIndex(uint8 _collateralIndex) external view returns (uint256)
Returns GNS/collateral price

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral

getGnsPriceCollateralAddress

function getGnsPriceCollateralAddress(address _collateral) external view returns (uint256)
Returns GNS/collateral price

Parameters

NameTypeDescription
_collateraladdressaddress of the collateral

getLinkUsdPriceFeed

function getLinkUsdPriceFeed() external view returns (contract IChainlinkFeed)
Returns the link/usd price feed address

getTwapInterval

function getTwapInterval() external view returns (uint24)
Returns the twap interval in seconds

getMinAnswers

function getMinAnswers() external view returns (uint8)
Returns the minimum answers to execute an order and take the median

getMarketJobId

function getMarketJobId() external view returns (bytes32)
Returns the market job id

getLimitJobId

function getLimitJobId() external view returns (bytes32)
Returns the limit job id

getOracle

function getOracle(uint256 _index) external view returns (address)
Returns a specific oracle

Parameters

NameTypeDescription
_indexuint256index of the oracle

getOracles

function getOracles() external view returns (address[])
Returns all oracles

getCollateralGnsLiquidityPool

function getCollateralGnsLiquidityPool(uint8 _collateralIndex) external view returns (struct IPriceAggregator.LiquidityPoolInfo)
Returns collateral/gns liquidity pool info

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral

getCollateralUsdPriceFeed

function getCollateralUsdPriceFeed(uint8 _collateralIndex) external view returns (contract IChainlinkFeed)
Returns collateral/usd chainlink price feed

Parameters

NameTypeDescription
_collateralIndexuint8index of collateral

getPriceAggregatorOrder

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

Parameters

NameTypeDescription
_requestIdbytes32index of collateral

getPriceAggregatorOrderAnswers

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

Parameters

NameTypeDescription
_orderIdITradingStorage.Idorder id

getChainlinkToken

function getChainlinkToken() external view returns (address)
Returns chainlink token address

getRequestCount

function getRequestCount() external view returns (uint256)
Returns requestCount (used by ChainlinkClientUtils)

getPendingRequest

function getPendingRequest(bytes32 _id) external view returns (address)
Returns pendingRequests mapping entry (used by ChainlinkClientUtils)

LinkUsdPriceFeedUpdated

event LinkUsdPriceFeedUpdated(address value)
Emitted when LINK/USD price feed is updated

Parameters

NameTypeDescription
valueaddressnew value

CollateralUsdPriceFeedUpdated

event CollateralUsdPriceFeedUpdated(uint8 collateralIndex, address value)
Emitted when collateral/USD price feed is updated

Parameters

NameTypeDescription
collateralIndexuint8collateral index
valueaddressnew value

CollateralGnsLiquidityPoolUpdated

event CollateralGnsLiquidityPoolUpdated(uint8 collateralIndex, struct IPriceAggregator.LiquidityPoolInfo newValue)
Emitted when collateral/GNS Uniswap V3 pool is updated

Parameters

NameTypeDescription
collateralIndexuint8collateral index
newValuestruct IPriceAggregator.LiquidityPoolInfonew value

TwapIntervalUpdated

event TwapIntervalUpdated(uint32 newValue)
Emitted when TWAP interval is updated

Parameters

NameTypeDescription
newValueuint32new value

MinAnswersUpdated

event MinAnswersUpdated(uint8 value)
Emitted when minimum answers count is updated

Parameters

NameTypeDescription
valueuint8new value

OracleAdded

event OracleAdded(uint256 index, address value)
Emitted when an oracle is added

Parameters

NameTypeDescription
indexuint256new oracle index
valueaddressvalue

OracleReplaced

event OracleReplaced(uint256 index, address oldOracle, address newOracle)
Emitted when an oracle is replaced

Parameters

NameTypeDescription
indexuint256oracle index
oldOracleaddressold value
newOracleaddressnew value

OracleRemoved

event OracleRemoved(uint256 index, address oldOracle)
Emitted when an oracle is removed

Parameters

NameTypeDescription
indexuint256oracle index
oldOracleaddressold value

JobIdUpdated

event JobIdUpdated(uint256 index, bytes32 jobId)
Emitted when market job id is updated

Parameters

NameTypeDescription
indexuint256index
jobIdbytes32new value

LinkRequestCreated

event LinkRequestCreated(struct Chainlink.Request request)
Emitted when a chainlink request is created

Parameters

NameTypeDescription
requeststruct Chainlink.Requestlink request details

PriceRequested

event PriceRequested(uint8 collateralIndex, uint256 pairIndex, struct ITradingStorage.Id tradeId, struct ITradingStorage.Id pendingOrderId, enum ITradingStorage.PendingOrderType orderType, uint256 fromBlock, bool isLookback, bytes32 job, uint256 linkFeePerNode, uint256 nodesCount)
Emitted when a price is requested to the oracles

Parameters

NameTypeDescription
collateralIndexuint8collateral index
pairIndexuint256trading pair index
tradeIdstruct ITradingStorage.Idtrader id
pendingOrderIdstruct ITradingStorage.Idpending order id
orderTypeenum ITradingStorage.PendingOrderTypeorder type (market open/market close/limit open/stop open/etc.)
fromBlockuint256block number from which to start fetching prices (for lookbacks)
isLookbackbooltrue if lookback
jobbytes32chainlink job id (market/lookback)
linkFeePerNodeuint256link fee distributed per node (1e18 precision)
nodesCountuint256amount of nodes to fetch prices from

TradingCallbackExecuted

event TradingCallbackExecuted(struct ITradingCallbacks.AggregatorAnswer a, enum ITradingStorage.PendingOrderType orderType)
Emitted when a trading callback is called from the price aggregator

Parameters

NameTypeDescription
astruct ITradingCallbacks.AggregatorAnsweraggregator answer data
orderTypeenum ITradingStorage.PendingOrderTypeorder type

PriceReceived

event PriceReceived(struct ITradingStorage.Id orderId, uint16 pairIndex, bytes32 request, uint256 priceData, bool isLookback, bool usedInMedian)
Emitted when a price is received from the oracles

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idpending order id
pairIndexuint16trading pair index
requestbytes32chainlink request id
priceDatauint256OrderAnswer compressed into uint256
isLookbackbooltrue if lookback
usedInMedianboolfalse if order already executed because min answers count was already reached

LinkClaimedBack

event LinkClaimedBack(uint256 amountLink)
Emitted when LINK tokens are claimed back by gov fund

Parameters

NameTypeDescription
amountLinkuint256amount of LINK tokens claimed back

TransferAndCallToOracleFailed

error TransferAndCallToOracleFailed()

SourceNotOracleOfRequest

error SourceNotOracleOfRequest()

RequestAlreadyPending

error RequestAlreadyPending()

OracleAlreadyListed

error OracleAlreadyListed()

InvalidCandle

error InvalidCandle()

WrongCollateralUsdDecimals

error WrongCollateralUsdDecimals()

InvalidPoolType

error InvalidPoolType()