Skip to main content

Oracle

Overview​

This Oracle contract calculates a 1 day TWAP for a constant product (xy=k) Astroport pool, from the pool's cumulative prices. It is a demo contract: it isn't part of Astroport's deployed contracts. To read prices on chain, you can also use a pool's own cumulative_prices query, or observe on stableswap and PCL pools (see Swap Pairs).

InstantiateMsg​

Instantiates the oracle for the pool of the given assets. The pool must be a constant product pool registered in the factory.

json
oracle.rs
Copy

_15
{
_15
"factory_contract": "terra14x9fr055x5hvr48hzy2t4q7kvjvfttsvxusa4xsdcy702mnzsvuqprer8r",
_15
"asset_infos": [
_15
{
_15
"native_token": {
_15
"denom": "uluna"
_15
}
_15
},
_15
{
_15
"native_token": {
_15
"denom": "ibc/E8481AD838C31D4FC12A504B10F9B4E2F830F8818D2735C2FFC707579B5FA60B"
_15
}
_15
}
_15
]
_15
}

ParamsTypeDescription
factory_contractStringThe factory contract address
asset_infosVec<AssetInfo>The assets of the pool this oracle provides prices for

ExecuteMsg​

update​

Updates the TWAP from the pool's cumulative prices. It can only run once a full period (1 day) has passed since the last update. Anyone can call it.

json
oracle.rs
Copy

_3
{
_3
"update": {}
_3
}

QueryMsg​

consult​

Multiplies a token amount (of a token in the target pool) by the latest TWAP for that token. Returns a vector of (AssetInfo, Uint256): the other asset and the amount.

json
oracle.rs
Copy

_10
{
_10
"consult": {
_10
"token": {
_10
"native_token": {
_10
"denom": "uluna"
_10
}
_10
},
_10
"amount": "1000000"
_10
}
_10
}

ParamsTypeDescription
tokenAssetInfoThe asset to price
amountUint128The amount of that asset