Oracle
An Oracle contract that collects price reports from several feeds and ensures they are within a price range and time limit.
Structs
Oracle
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
. ThisOwnerCap
will 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.feeds
can report a price in theRequest
hot 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
feeds
vector has repeated values.time_limit
must be higher than 0 milliseconds.deviation
must be higher than 0.
share
Shares the Oracle
object.
@param self: The
Oracle
.
request
Creates a Request
hot potato.
@param self: The
Request
will require all feeds fromOracle
to be reported.@return
Request
.
Aborts
self.feed
is empty.
report
Adds a price Report
to the Request
.
@param request:
Request
hot 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
price
value.@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
Oracle
that theRequest
was sent from.@param request: The
Request
.@param c: The shared
sui::clock::Clock
object.@return
Price
.
Aborts
The
Request.oracle
does 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
deviation
range.
destroy_price
Destroys an Oracle
object.
@param self: The
Oracle
that theRequest
was sent from.@param cap: The
suitears::owner::OwnerCap
that owns theself
.
Aborts
the
cap
is not the owner ofself
.
feeds
Returns a vector of the Oracle.feeds
.
@param self: An
Oracle
object.@return vector
feeds
Returns a vector of the Oracle.feeds
.
@param self: An
Oracle
object.@return vector
time_limit
Returns a time limit set in the Oracle
.
@param self: An
Oracle
object.@return vector
deviation
Returns the price deviation set in the Oracle
.
@param self: An
Oracle
object.@return u256
uid
Allows extensions to read dynamic fields.
@param self: An
Oracle
object.@return
sui::object::UID
oracle
Returns the sui::object::ID
of a Price's oracle.
@param price: A
Price
potato.@return
sui::object::ID
price
Returns the price value of a Price
hot potato.
@param price: A
Price
potato.@return u256
decimals
Returns the decimal houses of the price value.
@param price: A
Price
potato.@return u8
timestamp
Returns the timestamp of the a Price
.
@param price: A
Price
potato.@return u64
uid_mut
Allows extensions to add/remove dynamic fields.
@param self: An
Oracle
object.@param cap: The
suitears::owner::OwnerCap
that owns theself
.@return
sui::object::UID
Aborts
The
cap
is not the owner ofself
.
add
Adds a feed Witness to an Oracle
.
@param self: An
Oracle
object.@param cap: The
suitears::owner::OwnerCap
that owns theself
.@param feed: A Witness feed.
Aborts
The
cap
is not the owner ofself
.A duplicated
feed
is added.
remove
Removes a feed Witness to an Oracle
.
@param self: An
Oracle
object.@param cap: The
suitears::owner::OwnerCap
that owns theself
.@param feed: A Witness feed.
Aborts
The
cap
is not the owner ofself
.The
Oracle
has 1 feed left.
update_time_limit
Updates the time_limit of an Oracle
.
@param self: An
Oracle
object.@param cap: The
suitears::owner::OwnerCap
that owns theself
.@param time_limit: The new time_limit.
Aborts
The
cap
is not the owner ofself
.The
time_limit
cannot be zero.
update_deviation
Updates the deviation of an Oracle
.
@param self: An
Oracle
object.@param cap: The
suitears::owner::OwnerCap
that owns theself
.@param deviation: The new deviation.
Aborts
The
cap
is not the owner ofself
.The
time_limit
cannot be zero.
new_price_for_testing
Creates a Price
for testing purposes only. Only available in tests.
@param oracle:
sui::object::ID
of theOracle
this 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