Oracle
An Oracle contract that collects price reports from several feeds and ensures they are within a price range and time limit.
Structs
Oracle
struct Oracle<phantom Witness: drop> has key, store {
id: UID,
// Set of module Witnesses that are allowed to report prices.
feeds: VecSet<TypeName>,
// Reported prices must have a timestamp earlier than `current_timestamp - time_limit`.
// It is in milliseconds.
time_limit: u64,
// Reported prices must be within the following range: `leader_price + deviation % >= reported_price >= leader_price - deviation %`.
deviation: u256
} feeds - Set of module Witnesses that are allowed to report prices.
time_limit - Reported prices must have a timestamp earlier than `current_timestamp - time_limit`. It is in milliseconds.
deviation - Reported prices must be within the following range: `leader_price + deviation % >= reported_price >= leader_price - deviation %`.
Report
price - Price has 18 decimals.
timestamp - Timestamp in milliseconds.
Price
oracle - the `sui::object::ID` of the Oracle this request was sent from.
price - The first reported price after all checks.
decimals - It is always 18.
timestamp - The time at which this price was reported.
Interface
new
Creates an Oracle with a set of feeds.
@param cap: An owner cap from
suitears::owner. ThisOwnerCapwill be the owner of the newOracle.@param wit: A Witness from the module that will manage this
Oracle.@param feeds: Feed Witnesses. Only modules in the
Oracle.feedscan report a price in theRequesthot potato.@param time_limit: A time in milliseconds that determines how old a price timestamp can be.
@param deviation: A percentage that determines an acceptable price range for all reported prices.
@return Oracle<Witness>.
Aborts
feedsvector has repeated values.time_limitmust be higher than 0 milliseconds.deviationmust be higher than 0.
share
Shares the Oracle object.
@param self: The
Oracle.
request
Creates a Request hot potato.
@param self: The
Requestwill require all feeds fromOracleto be reported.@return
Request.
Aborts
self.feedis empty.
report
Adds a price Report to the Request.
@param request:
Requesthot potato.@param _ : A Witness to verify the reporters.
@param timestamp: The timestamp of the price feed.
@param price: The price
@param decimals: The decimal houses of the
pricevalue.@return
Request.
Aborts
a feed reports more than once.
destroy_request
Destroy the Request potato and verify the price values and timestamps.
@param self: The
Oraclethat theRequestwas sent from.@param request: The
Request.@param c: The shared
sui::clock::Clockobject.@return
Price.
Aborts
The
Request.oracledoes not match theself.id.The number of reports does not match the number of feeds in the
Oracle.feeds.The report witnesses do not match the required feed witnesses.
The reported price is outside the
time_limit.The price falls outside the outside
deviationrange.
destroy_price
Destroys an Oracle object.
@param self: The
Oraclethat theRequestwas sent from.@param cap: The
suitears::owner::OwnerCapthat owns theself.
Aborts
the
capis not the owner ofself.
feeds
Returns a vector of the Oracle.feeds.
@param self: An
Oracleobject.@return vector
feeds
Returns a vector of the Oracle.feeds.
@param self: An
Oracleobject.@return vector
time_limit
Returns a time limit set in the Oracle.
@param self: An
Oracleobject.@return vector
deviation
Returns the price deviation set in the Oracle.
@param self: An
Oracleobject.@return u256
uid
Allows extensions to read dynamic fields.
@param self: An
Oracleobject.@return
sui::object::UID
oracle
Returns the sui::object::ID of a Price's oracle.
@param price: A
Pricepotato.@return
sui::object::ID
price
Returns the price value of a Price hot potato.
@param price: A
Pricepotato.@return u256
decimals
Returns the decimal houses of the price value.
@param price: A
Pricepotato.@return u8
timestamp
Returns the timestamp of the a Price.
@param price: A
Pricepotato.@return u64
uid_mut
Allows extensions to add/remove dynamic fields.
@param self: An
Oracleobject.@param cap: The
suitears::owner::OwnerCapthat owns theself.@return
sui::object::UID
Aborts
The
capis not the owner ofself.
add
Adds a feed Witness to an Oracle.
@param self: An
Oracleobject.@param cap: The
suitears::owner::OwnerCapthat owns theself.@param feed: A Witness feed.
Aborts
The
capis not the owner ofself.A duplicated
feedis added.
remove
Removes a feed Witness to an Oracle.
@param self: An
Oracleobject.@param cap: The
suitears::owner::OwnerCapthat owns theself.@param feed: A Witness feed.
Aborts
The
capis not the owner ofself.The
Oraclehas 1 feed left.
update_time_limit
Updates the time_limit of an Oracle.
@param self: An
Oracleobject.@param cap: The
suitears::owner::OwnerCapthat owns theself.@param time_limit: The new time_limit.
Aborts
The
capis not the owner ofself.The
time_limitcannot be zero.
update_deviation
Updates the deviation of an Oracle.
@param self: An
Oracleobject.@param cap: The
suitears::owner::OwnerCapthat owns theself.@param deviation: The new deviation.
Aborts
The
capis not the owner ofself.The
time_limitcannot be zero.
new_price_for_testing
Creates a Price for testing purposes only. Only available in tests.
@param oracle:
sui::object::IDof theOraclethis request was sent from.@param price: The reported price.
@param decimals: The decimals precision of
price.@param timestamp: The timestamp in milliseconds in which the price was recorded.
Last updated
Was this helpful?