Skip to content

Commit

Permalink
Fix price oracle conversion in mobile verifier (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Plant authored Apr 15, 2023
1 parent 8fa4cec commit 22afc52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TransferRewards {
}

pub async fn from_transfer_sessions(
mobile_price: Decimal,
mobile_bone_price: Decimal,
transfer_sessions: impl Stream<Item = ValidDataTransferSession>,
epoch: &Range<DateTime<Utc>>,
) -> Self {
Expand All @@ -69,7 +69,7 @@ impl TransferRewards {
.into_iter()
// Calculate rewards per hotspot
.map(|(pub_key, dc_amount)| {
let bones = dc_to_mobile_bones(dc_amount, mobile_price);
let bones = dc_to_mobile_bones(dc_amount, mobile_bone_price);
reward_sum += bones;
(pub_key, bones)
})
Expand Down Expand Up @@ -108,9 +108,9 @@ impl TransferRewards {
}

/// Returns the equivalent amount of Mobile bones for a specified amount of Data Credits
pub fn dc_to_mobile_bones(dc_amount: Decimal, mobile_price: Decimal) -> Decimal {
pub fn dc_to_mobile_bones(dc_amount: Decimal, mobile_bone_price: Decimal) -> Decimal {
let dc_in_usd = dc_amount * DC_USD_PRICE;
(dc_in_usd / mobile_price)
(dc_in_usd / mobile_bone_price)
.round_dp_with_strategy(DEFAULT_PREC, RoundingStrategy::ToPositiveInfinity)
}

Expand Down
6 changes: 4 additions & 2 deletions mobile_verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ impl VerifierDaemon {
.price(&helium_proto::BlockchainTokenTypeV1::Mobile)
.await?;
// Mobile prices are supplied in 10^6, so we must convert them to Decimal
let mobile_price = Decimal::from(mobile_price) / dec!(1_000_000);
let mobile_bone_price = Decimal::from(mobile_price)
/ dec!(1_000_000) // Per Mobile token
/ dec!(1_000_000); // Per Bone
let transfer_rewards = TransferRewards::from_transfer_sessions(
mobile_price,
mobile_bone_price,
ingest::ingest_valid_data_transfers(
&self.data_transfer_ingest,
&scheduler.reward_period,
Expand Down

0 comments on commit 22afc52

Please sign in to comment.