-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Implement oracle data protocol #2727
Conversation
jolestar
commented
Jul 20, 2021
•
edited
Loading
edited
- 只考虑了数据格式的定义和更新
- 如果要实现去中心化 Oracle 协议,可以把 UpdatePriceCapability 托管到另外的Module 中,然后设计更新协议。
- 只实现了简单的一种聚合方法,未考虑历史数据的获取和更新。
public fun register_price_oracle<DataT: copy+store+drop>(signer: &signer, precision: u8, description: vector<u8>){ | ||
//TODO implement a global register by contact account. | ||
CoreAddresses::assert_genesis_address(signer); | ||
move_to(signer, PriceOracleInfo<DataT> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we define a constant to limit the range of precision? like MAX_DECIMALS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不好确定 MAX_DECIMALS 的值,理论上 Math::pow(10, precision) < u128::max_value() 就可以吧
Codecov Report
@@ Coverage Diff @@
## master #2727 +/- ##
==========================================
- Coverage 31.78% 31.70% -0.08%
==========================================
Files 508 508
Lines 44755 44769 +14
Branches 19901 19911 +10
==========================================
- Hits 14222 14190 -32
- Misses 16617 16752 +135
+ Partials 13916 13827 -89
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Benchmark for bc63bf0Click to view benchmark
|
|
||
public fun read_price_data<DataT:copy+store+drop>(addr: address): PriceData acquires PriceFeed{ | ||
let price_feed = borrow_global<PriceFeed<DataT>>(addr); | ||
*&price_feed.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this return value should be a struct containing the precision and the number after pow.
Like struct Num { value: u64, dec: u64 }
. .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PriceData.price 保存的是原始数据,precision 是用来展示分数的时候才需要的
Benchmark for 695fd2dClick to view benchmark
|
Can it be generalized to store any data, instead of only num value. Then on top of it, we can do another abstraction, like price oracle to do price related oracle, merkle root oracle to do block changing oracle。 |
我开始也是这样想的,但那样设计通用的方法比较困难。我尝试另外一个思路。 |
Benchmark for 7a5e897Click to view benchmark
|
#2732 中提供了另外一种实现 |