Oracle Finance
Methods
current_era_num
fn current_era_num() -> EraIndex
To get the current era, you need to consider that if the era-length changes, you still need to guarantee that the vector of time zones increases.
get_earliest_reward_era
fn get_earliest_reward_era() -> Option<EraIndex>
Get the earliest reward era.
calculate_fee_of_ask_quantity
fn calculate_fee_of_ask_quantity(price_count: u32) -> BalanceOf<T>
Input in a price_count to calculate the cost of the purchase.
- params
price_count: Expected count of aggregate trade-pairs.
reserve_for_ask_quantity
fn reserve_for_ask_quantity(
who: T::AccountId,
p_id: PurchaseId,
price_count: u32
) -> OcwPaymentResult<BalanceOf<T>, PurchaseId>
Keep the balance for the purchase.
- params
who: Origin account id.
p_id: Purchase order id.
price_count: Expected count of aggregate trade-pairs.
unreserve_ask
fn unreserve_ask(p_id: PurchaseId) -> Result<(), Error<T>>
Release the funds reserved for the purchase, which occurs after the failure of the ask-price.
p_id: Purchase order id.
pay_to_ask
fn pay_to_ask(p_id: PurchaseId, agg_count: usize) -> Result<(), Error<T>>
Execute the payment, which will transfer the user’s balance to the Pallet
p_id: Purchase order id.
price_count: The count of actual aggregate trade-pairs
record_submit_point
fn record_submit_point(
who: T::AccountId,
p_id: PurchaseId,
bn: T::BlockNumber,
ask_point: AskPointNum
) -> Result<(), Error<T>>
Record the Points of the validator under an order
who: A validator id.
p_id: Purchase order id.
bn: The corresponding block when the order is generated.
ask_point: A number of u32
get_record_point
fn get_record_point(
ask_era: u32,
who: T::AccountId,
p_id: PurchaseId
) -> Option<AskPointNum>
Get the Point of the record
ask_era: Era of the reward.
who: A validator id.
p_id: Purchase order id.
take_reward
fn take_reward(
ask_era: EraIndex,
who: T::AccountId
) -> Result<BalanceOf<T>, Error<T>>
Claim all rewards under a given era
ask_era: Era of the reward.
who: A validator id.
get_era_income
fn get_era_income(ask_era: EraIndex) -> BalanceOf<T>
Get total income balance for an era.
ask_era: Era of the reward.
get_era_point
fn get_era_point(ask_era: EraIndex) -> AskPointNum
Read the total balance for an era.
ask_era: Era of the reward.
check_and_slash_expired_rewards
fn check_and_slash_expired_rewards(ask_era: EraIndex) -> Option<BalanceOf<T>>
Check for expired rewards and destroy them if overdue
Tx method
take_purchase_reward
Validators get rewards corresponding to eras.
Note: An era cannot be the current unfinished era, and rewards are not permanently stored. If the reward exceeds the depth defined by T::HistoryDepth, you will not be able to claim it.
The dispatch origin for this call must be Signed
Earliest reward Era = Current-Era - T::HistoryDepth
ask_era: Era number is a u32
- Fields of take_purchase_reward
ask_era: EraIndex
take_all_purchase_reward
Validators get rewards, it will help validators get all available rewards
Note: An era cannot be the current unfinished era, and rewards are not permanently stored. If the reward exceeds the depth defined by T::HistoryDepth, you will not be able to claim it.
The dispatch origin for this call must be Signed
Earliest reward Era = Current-Era - T::HistoryDepth
Workflow
Reward Generation
Payment is through the
Trait
provided byIForPrice
. It is necessary to callreserve_for_ask_quantity
to reserve the part balance of asker and associate it with the order-id.Through the Trait implementation provided by
IForReporter
, callrecord_submit_point
to save the point. The block height needs to be passed in, and the pallet will convert it to the corresponding era and record it under an order-id.After the price-response is successful, call
pay_to_ask
to release the Balance reserved above, and pay the actual ask fee to the oracle-finance pallet.
Claim Reward
- Rewards are claimed by era, and rewards cannot be obtained for unfinished eras. You need to calculate
the 'Balance' corresponding to each point in the corresponding era. Algorithm:
Single Point Bonus
=Total Revenue
/Total Points
on era. - The validator needs to use the
Controller
account to perform the claim operation, This is for security reasons. The total amount received is equal to:Validator Points
*Single Point Bonus
. - Rewards are transferred to the validator's Stash account via
oracle-finance
pallet.