From af2f89689326be5aa4e7002d1e64987be6bb1bb1 Mon Sep 17 00:00:00 2001 From: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:53:47 -0700 Subject: [PATCH] Fix net emissions not happening due to extra emitted HNT for HIP-138 (#750) * Fix net emissions not happening due to extra emitted HNT for HIP-138 * Fix tests --- Cargo.lock | 2 +- programs/helium-sub-daos/Cargo.toml | 2 +- .../instructions/calculate_utility_score_v0.rs | 18 +++++++++++++++++- .../src/instructions/issue_rewards_v0.rs | 13 +++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6448de299..381ad39ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1964,7 +1964,7 @@ dependencies = [ [[package]] name = "helium-sub-daos" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/programs/helium-sub-daos/Cargo.toml b/programs/helium-sub-daos/Cargo.toml index 9e845d842..6cf81d707 100644 --- a/programs/helium-sub-daos/Cargo.toml +++ b/programs/helium-sub-daos/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helium-sub-daos" -version = "0.1.11" +version = "0.1.12" description = "Created with Anchor" edition = "2021" diff --git a/programs/helium-sub-daos/src/instructions/calculate_utility_score_v0.rs b/programs/helium-sub-daos/src/instructions/calculate_utility_score_v0.rs index 59d942961..a78236eb2 100644 --- a/programs/helium-sub-daos/src/instructions/calculate_utility_score_v0.rs +++ b/programs/helium-sub-daos/src/instructions/calculate_utility_score_v0.rs @@ -1,10 +1,11 @@ -use crate::{current_epoch, error::ErrorCode, state::*, update_subdao_vehnt, EPOCH_LENGTH}; use anchor_lang::prelude::*; use anchor_spl::token::{Mint, Token}; use circuit_breaker::CircuitBreaker; use shared_utils::precise_number::{PreciseNumber, FOUR_PREC, TWO_PREC}; use voter_stake_registry::state::Registrar; +use crate::{current_epoch, error::ErrorCode, state::*, update_subdao_vehnt, EPOCH_LENGTH}; + #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] pub struct CalculateUtilityScoreArgsV0 { pub epoch: u64, @@ -83,12 +84,27 @@ pub fn handler( ctx.accounts.dao.net_emissions_cap, )) .unwrap(); + ctx.accounts.dao_epoch_info.epoch = args.epoch; ctx.accounts.dao_epoch_info.current_hnt_supply = curr_supply .checked_add(ctx.accounts.dao_epoch_info.total_rewards) .unwrap(); + // Until August 1st, 2025, emit the 2.9M HNT to the treasury. + // This contract will be deployed between December 6 and December 7 at UTC midnight. + // That means this will emit payment from December 7 to August 1st, 2025 (because epochs are paid in arrears). + // This is a total of 237 days. 2.9M HNT / 237 days = 12236.28691983 HNT per day. + #[allow(clippy::inconsistent_digit_grouping)] + if !TESTING && curr_epoch * (EPOCH_LENGTH as u64) < 1754006400 { + ctx.accounts.dao_epoch_info.current_hnt_supply = ctx + .accounts + .dao_epoch_info + .current_hnt_supply + .checked_add(12_236_28691983) + .unwrap(); + } + if !TESTING && args.epoch >= curr_epoch { return Err(error!(ErrorCode::EpochNotOver)); } diff --git a/programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs b/programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs index a5cb90128..6d7ece90d 100644 --- a/programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs +++ b/programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs @@ -157,7 +157,7 @@ pub fn handler(ctx: Context, args: IssueRewardsArgsV0) -> Result .unwrap(); let total_rewards = PreciseNumber::new(emissions.into()).or_arith_error()?; let rewards_prec = percent_share.checked_mul(&total_rewards).or_arith_error()?; - let mut rewards_amount: u64 = rewards_prec + let rewards_amount: u64 = rewards_prec .floor() // Ensure we never overspend the defined rewards .or_arith_error()? .to_imprecise() @@ -225,7 +225,16 @@ pub fn handler(ctx: Context, args: IssueRewardsArgsV0) -> Result && ctx.accounts.dnt_mint.key() == Pubkey::from_str("mb1eu7TzEc71KxDpsmsKoucSSuuoGLv1drys1oP2jh6").unwrap() { - rewards_amount += 12_236_28691983; + msg!("Minting HIP-138 HNT to MOBILE treasury"); + mint_v0( + ctx + .accounts + .mint_treasury_emissions_ctx() + .with_signer(&[dao_seeds!(ctx.accounts.dao)]), + MintArgsV0 { + amount: 12_236_28691983, + }, + )?; } msg!("Minting {} to treasury", rewards_amount);