diff --git a/mobile_verifier/src/rewarder.rs b/mobile_verifier/src/rewarder.rs index e1a77de73..995e3ca01 100644 --- a/mobile_verifier/src/rewarder.rs +++ b/mobile_verifier/src/rewarder.rs @@ -313,7 +313,7 @@ where boosted_poc_bones_per_reward_share: Some(helium_proto::Decimal { value: poc_dc_shares.boost.to_string(), }), - sp_allocations: service_provider::reward_data_sp_allocations(), + sp_allocations: service_provider::reward_data_sp_allocations(&self.pool).await?, }; self.reward_manifests .write( diff --git a/mobile_verifier/src/service_provider/mod.rs b/mobile_verifier/src/service_provider/mod.rs index d45aa4138..9a6f90885 100644 --- a/mobile_verifier/src/service_provider/mod.rs +++ b/mobile_verifier/src/service_provider/mod.rs @@ -4,6 +4,7 @@ use chrono::{DateTime, Utc}; use helium_proto::ServiceProviderAllocation; pub use promotions::daemon::PromotionDaemon; pub use reward::ServiceProviderRewardInfos; +use sqlx::PgPool; pub mod dc_sessions; pub mod promotions; @@ -25,7 +26,18 @@ pub fn get_scheduled_tokens(reward_period: &Range>) -> rust_decima crate::reward_shares::get_scheduled_tokens_for_service_providers(duration) } -pub fn reward_data_sp_allocations() -> Vec { - // TODO: How do you go from a service provider id to the payer key? - vec![] +pub async fn reward_data_sp_allocations( + pool: &PgPool, +) -> anyhow::Result> { + let funds = db::fetch_promotion_funds(pool).await?; + let mut sp_allocations = vec![]; + + for (sp_id, bps) in funds.0.into_iter() { + sp_allocations.push(ServiceProviderAllocation { + service_provider: sp_id, + incentive_escrow_fund_bps: bps as u32, + }); + } + + Ok(sp_allocations) } diff --git a/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs b/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs index 71cf82f0a..336bd57d3 100644 --- a/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs +++ b/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs @@ -236,10 +236,10 @@ async fn test_service_provider_promotion_rewards(pool: PgPool) -> anyhow::Result // Ensure the cleanup job can run let mut txn = pool.begin().await?; - service_provider::promotions::rewards::clear_promotion_rewards(&mut txn, &Utc::now()).await?; + service_provider::db::clear_promotion_rewards(&mut txn, &Utc::now()).await?; txn.commit().await?; - let promos = service_provider::promotions::rewards::fetch_promotion_rewards( + let promos = service_provider::db::fetch_promotion_rewards( &pool, &carrier_client, &(epoch.start..Utc::now()), @@ -247,6 +247,15 @@ async fn test_service_provider_promotion_rewards(pool: PgPool) -> anyhow::Result .await?; assert!(promos.is_empty()); + let sp_allocations = service_provider::reward_data_sp_allocations(&pool).await?; + assert_eq!( + vec![helium_proto::ServiceProviderAllocation { + service_provider: 0, + incentive_escrow_fund_bps: 1500 + }], + sp_allocations + ); + Ok(()) }