From 9e8431636fbc977e8d53ec92e458e164b2b7a965 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Mon, 16 Dec 2024 12:04:35 -0300 Subject: [PATCH 1/2] Bugfixes for 138 --- packages/helium-admin-cli/src/create-dao.ts | 1 + .../src/migrate-to-hip-138.ts | 56 ++++++++++--------- packages/helium-admin-cli/src/update-dao.ts | 1 + .../initialize_hnt_delegator_pool.rs | 5 -- .../src/instructions/update_dao_v0.rs | 5 ++ tests/helium-sub-daos.ts | 1 + 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/packages/helium-admin-cli/src/create-dao.ts b/packages/helium-admin-cli/src/create-dao.ts index c48c2341c..da73a7994 100644 --- a/packages/helium-admin-cli/src/create-dao.ts +++ b/packages/helium-admin-cli/src/create-dao.ts @@ -542,6 +542,7 @@ export async function run(args: any = process.argv) { netEmissionsCap: null, proposalNamespace: organizationKey("Helium")[0], delegatorRewardsPercent: delegatorRewardsPercent(argv.delegatorRewardsPercent), + rewardsEscrow, }) .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 88425cdcb..cfd9a55a2 100644 --- a/packages/helium-admin-cli/src/migrate-to-hip-138.ts +++ b/packages/helium-admin-cli/src/migrate-to-hip-138.ts @@ -3,9 +3,12 @@ import { ThresholdType } from "@helium/circuit-breaker-sdk"; import { daoKey, delegatorRewardsPercent, - init as initHsd + init as initHsd, } from "@helium/helium-sub-daos-sdk"; -import { init as initLazy, lazyDistributorKey } from "@helium/lazy-distributor-sdk"; +import { + init as initLazy, + lazyDistributorKey, +} from "@helium/lazy-distributor-sdk"; import { organizationKey } from "@helium/organization-sdk"; import { oracleSignerKey } from "@helium/rewards-oracle-sdk"; import { @@ -102,29 +105,29 @@ export async function run(args: any = process.argv) { const dao = daoKey(hntMint)[0]; const resizes: TransactionInstruction[] = []; - resizes.push( - await hsdProgram.methods - .tempResizeAccount() - .accounts({ - account: dao, - payer: wallet.publicKey, - }) - .instruction() - ); - const daoEpochInfos = await hsdProgram.account.daoEpochInfoV0.all(); - for (const daoEpochInfo of daoEpochInfos) { - resizes.push( - await hsdProgram.methods - .tempResizeAccount() - .accounts({ - account: daoEpochInfo.publicKey, - payer: wallet.publicKey, - }) - .instruction() - ); - } + // resizes.push( + // await hsdProgram.methods + // .tempResizeAccount() + // .accounts({ + // account: dao, + // payer: wallet.publicKey, + // }) + // .instruction() + // ); + // const daoEpochInfos = await hsdProgram.account.daoEpochInfoV0.all(); + // for (const daoEpochInfo of daoEpochInfos) { + // resizes.push( + // await hsdProgram.methods + // .tempResizeAccount() + // .accounts({ + // account: daoEpochInfo.publicKey, + // payer: wallet.publicKey, + // }) + // .instruction() + // ); + // } console.log("Resizing accounts"); - await batchParallelInstructionsWithPriorityFee(provider, resizes);`` + // await batchParallelInstructionsWithPriorityFee(provider, resizes); const daoAcc = await hsdProgram.account.daoV0.fetch(dao); const authority = daoAcc.authority; @@ -180,6 +183,7 @@ export async function run(args: any = process.argv) { hstPool: null, proposalNamespace: organizationKey("Helium")[0], delegatorRewardsPercent: delegatorRewardsPercent(6), + rewardsEscrow: getAssociatedTokenAddressSync(hntMint, ld, true), }) .accounts({ dao, @@ -189,7 +193,7 @@ export async function run(args: any = process.argv) { .instruction() ); - if (!daoAcc.rewardsEscrow) { + if (!daoAcc.rewardsEscrow || daoAcc.rewardsEscrow.equals(PublicKey.default)) { instructions.push( await hsdProgram.methods .initializeHntDelegatorPool() @@ -197,6 +201,8 @@ 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/packages/helium-admin-cli/src/update-dao.ts b/packages/helium-admin-cli/src/update-dao.ts index a5734c24d..190f1fac6 100644 --- a/packages/helium-admin-cli/src/update-dao.ts +++ b/packages/helium-admin-cli/src/update-dao.ts @@ -132,6 +132,7 @@ export async function run(args: any = process.argv) { delegatorRewardsPercent: argv.delegatorRewardsPercent ? delegatorRewardsPercent(argv.delegatorRewardsPercent) : null, + rewardsEscrow: null, }) .accounts({ dao, diff --git a/programs/helium-sub-daos/src/instructions/initialize_hnt_delegator_pool.rs b/programs/helium-sub-daos/src/instructions/initialize_hnt_delegator_pool.rs index 62ff6b91d..007e38199 100644 --- a/programs/helium-sub-daos/src/instructions/initialize_hnt_delegator_pool.rs +++ b/programs/helium-sub-daos/src/instructions/initialize_hnt_delegator_pool.rs @@ -39,11 +39,6 @@ pub struct InitializeHntDelegatorPool<'info> { associated_token::authority = dao, )] pub delegator_pool: Box>, - #[account( - token::mint = hnt_mint, - )] - pub rewards_escrow: Box>, - pub system_program: Program<'info, System>, pub token_program: Program<'info, Token>, pub circuit_breaker_program: Program<'info, CircuitBreaker>, diff --git a/programs/helium-sub-daos/src/instructions/update_dao_v0.rs b/programs/helium-sub-daos/src/instructions/update_dao_v0.rs index a3c722987..942b9bc46 100644 --- a/programs/helium-sub-daos/src/instructions/update_dao_v0.rs +++ b/programs/helium-sub-daos/src/instructions/update_dao_v0.rs @@ -12,6 +12,7 @@ pub struct UpdateDaoArgsV0 { pub net_emissions_cap: Option, pub proposal_namespace: Option, pub delegator_rewards_percent: Option, + pub rewards_escrow: Option, } #[derive(Accounts)] @@ -36,6 +37,10 @@ pub fn handler(ctx: Context, args: UpdateDaoArgsV0) -> Result<()> { ctx.accounts.dao.authority = new_authority; } + if let Some(rewards_escrow) = args.rewards_escrow { + ctx.accounts.dao.rewards_escrow = rewards_escrow; + } + if let Some(hst_emission_schedule) = args.hst_emission_schedule { ctx.accounts.dao.hst_emission_schedule = hst_emission_schedule; should_resize = true; diff --git a/tests/helium-sub-daos.ts b/tests/helium-sub-daos.ts index e122ee3ad..5f6cd2ec9 100644 --- a/tests/helium-sub-daos.ts +++ b/tests/helium-sub-daos.ts @@ -278,6 +278,7 @@ describe("helium-sub-daos", () => { netEmissionsCap: null, proposalNamespace: null, delegatorRewardsPercent: null, + rewardsEscrow: null, }) .accounts({ dao, From 18e2fcea558e6a6171b7594c0cf227194f5d2d05 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Mon, 16 Dec 2024 12:54:49 -0300 Subject: [PATCH 2/2] More bugfixes for HIP-138 --- packages/helium-admin-cli/src/create-dao.ts | 2 +- .../src/migrate-to-hip-138.ts | 47 +++++++++---------- .../calculate_utility_score_v0.rs | 20 ++++---- 3 files changed, 35 insertions(+), 34 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 cfd9a55a2..0eafd2a4e 100644 --- a/packages/helium-admin-cli/src/migrate-to-hip-138.ts +++ b/packages/helium-admin-cli/src/migrate-to-hip-138.ts @@ -105,29 +105,29 @@ export async function run(args: any = process.argv) { const dao = daoKey(hntMint)[0]; const resizes: TransactionInstruction[] = []; - // resizes.push( - // await hsdProgram.methods - // .tempResizeAccount() - // .accounts({ - // account: dao, - // payer: wallet.publicKey, - // }) - // .instruction() - // ); - // const daoEpochInfos = await hsdProgram.account.daoEpochInfoV0.all(); - // for (const daoEpochInfo of daoEpochInfos) { - // resizes.push( - // await hsdProgram.methods - // .tempResizeAccount() - // .accounts({ - // account: daoEpochInfo.publicKey, - // payer: wallet.publicKey, - // }) - // .instruction() - // ); - // } + resizes.push( + await hsdProgram.methods + .tempResizeAccount() + .accounts({ + account: dao, + payer: wallet.publicKey, + }) + .instruction() + ); + const daoEpochInfos = await hsdProgram.account.daoEpochInfoV0.all(); + for (const daoEpochInfo of daoEpochInfos) { + resizes.push( + await hsdProgram.methods + .tempResizeAccount() + .accounts({ + account: daoEpochInfo.publicKey, + payer: wallet.publicKey, + }) + .instruction() + ); + } console.log("Resizing accounts"); - // await batchParallelInstructionsWithPriorityFee(provider, resizes); + await batchParallelInstructionsWithPriorityFee(provider, resizes); const daoAcc = await hsdProgram.account.daoV0.fetch(dao); const authority = daoAcc.authority; @@ -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);