Skip to content

Commit

Permalink
Fix net emissions not happening due to extra emitted HNT for HIP-138 (#…
Browse files Browse the repository at this point in the history
…750)

* Fix net emissions not happening due to extra emitted HNT for HIP-138

* Fix tests
  • Loading branch information
ChewingGlass authored Dec 7, 2024
1 parent 772881c commit af2f896
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/helium-sub-daos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helium-sub-daos"
version = "0.1.11"
version = "0.1.12"
description = "Created with Anchor"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down
13 changes: 11 additions & 2 deletions programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn handler(ctx: Context<IssueRewardsV0>, 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()
Expand Down Expand Up @@ -225,7 +225,16 @@ pub fn handler(ctx: Context<IssueRewardsV0>, 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);
Expand Down

0 comments on commit af2f896

Please sign in to comment.