From 27076bf70296bafcaeb487c3ca9c6c8d0e2768d1 Mon Sep 17 00:00:00 2001 From: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:05:30 -0800 Subject: [PATCH] More bugfixes for HIP-138 (#758) * Bugfixes for 138 * More bugfixes for HIP-138 --- packages/helium-admin-cli/src/create-dao.ts | 2 +- .../src/migrate-to-hip-138.ts | 3 +-- .../calculate_utility_score_v0.rs | 20 ++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/helium-admin-cli/src/create-dao.ts b/packages/helium-admin-cli/src/create-dao.ts index da73a7994..d991b4ab3 100644 --- a/packages/helium-admin-cli/src/create-dao.ts +++ b/packages/helium-admin-cli/src/create-dao.ts @@ -542,7 +542,7 @@ export async function run(args: any = process.argv) { netEmissionsCap: null, proposalNamespace: organizationKey("Helium")[0], delegatorRewardsPercent: delegatorRewardsPercent(argv.delegatorRewardsPercent), - rewardsEscrow, + rewardsEscrow: rewardsEscrow ? rewardsEscrow : null, }) .accounts({ dao, diff --git a/packages/helium-admin-cli/src/migrate-to-hip-138.ts b/packages/helium-admin-cli/src/migrate-to-hip-138.ts index bc1bb8615..0eafd2a4e 100644 --- a/packages/helium-admin-cli/src/migrate-to-hip-138.ts +++ b/packages/helium-admin-cli/src/migrate-to-hip-138.ts @@ -193,7 +193,7 @@ export async function run(args: any = process.argv) { .instruction() ); - if (!daoAcc.rewardsEscrow || daoAcc.rewardsEscrow.equals(PublicKey.default)) { + if (!daoAcc.delegatorPool || daoAcc.delegatorPool.equals(PublicKey.default)) { instructions.push( await hsdProgram.methods .initializeHntDelegatorPool() @@ -201,7 +201,6 @@ export async function run(args: any = process.argv) { dao, payer: daoAcc.authority, delegatorPool: getAssociatedTokenAddressSync(hntMint, dao, true), - rewardsEscrow: getAssociatedTokenAddressSync(hntMint, ld, true), authority: daoAcc.authority, }) .instruction() 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 27d77d89f..062f64950 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 @@ -154,6 +154,9 @@ pub fn handler( // Apply a 90 day smooth let utility_score_prec = vehnt_staked + // Add 12 decimals of precision + .checked_mul(&PreciseNumber::new(1000000000000_u128).unwrap()) // First convert vehnt to 12 decimals + .unwrap() .checked_div(&PreciseNumber::new(90_u128).unwrap()) .unwrap() .checked_add( @@ -165,21 +168,20 @@ pub fn handler( .prev_sub_dao_epoch_info .utility_score .and_then(PreciseNumber::new) - .unwrap_or(vehnt_staked), + .unwrap_or_else(|| { + vehnt_staked + // Add 12 decimals of precision + .checked_mul(&PreciseNumber::new(1000000000000_u128).unwrap()) + .unwrap() + }), ) .unwrap() .checked_div(&PreciseNumber::new(90_u128).unwrap()) .unwrap(), ) .unwrap(); - // Convert to u128 with 12 decimals of precision - let utility_score = utility_score_prec - .checked_mul( - &PreciseNumber::new(1000000000000_u128).unwrap(), // u128 with 12 decimal places - ) - .unwrap() - .to_imprecise() - .unwrap(); + + let utility_score = utility_score_prec.to_imprecise().unwrap(); // Store utility scores epoch_info.utility_score = Some(utility_score);