From af1df36b65019566fa08e1f363fdac783dfa7e56 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Thu, 9 Jan 2025 08:44:44 -0800 Subject: [PATCH 1/2] Fix logic to add expiration to delegation --- .../vote_service_example.json | 12 ++++++++++++ .../src/add-expiration-to-delegations.ts | 6 +++--- .../instructions/delegation/close_delegation_v0.rs | 9 ++++++++- .../src/instructions/delegation/delegate_v0.rs | 2 +- .../delegation/extend_expiration_ts_v0.rs | 6 +++++- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/account-postgres-sink-service/vote_service_example.json b/packages/account-postgres-sink-service/vote_service_example.json index df65a17f4..1b851d54c 100644 --- a/packages/account-postgres-sink-service/vote_service_example.json +++ b/packages/account-postgres-sink-service/vote_service_example.json @@ -29,6 +29,18 @@ "schema": "public" } ] + }, + { + "programId": "hdaoVTCqhfHHo75XdAMxBKdUqvq1i5bF23sisBqVgGR", + "accounts": [ + { "type": "SubDaoV0", "table": "sub_daos", "schema": "public" }, + { "type": "DaoV0", "table": "daos", "schema": "public" }, + { + "type": "DelegatedPositionV0", + "table": "delegated_positions", + "schema": "public" + } + ] } ], "indexConfigs": [] diff --git a/packages/helium-admin-cli/src/add-expiration-to-delegations.ts b/packages/helium-admin-cli/src/add-expiration-to-delegations.ts index 1749738f9..7c9d53cd4 100644 --- a/packages/helium-admin-cli/src/add-expiration-to-delegations.ts +++ b/packages/helium-admin-cli/src/add-expiration-to-delegations.ts @@ -51,11 +51,11 @@ export async function run(args: any = process.argv) { const delegations = await hsdProgram.account.delegatedPositionV0.all() const needsMigration = delegations.filter(d => d.account.expirationTs.isZero()); const positionKeys = needsMigration.map(d => d.account.position); - const coder = hsdProgram.coder.accounts + const coder = vsrProgram.coder.accounts const positionAccs = (await getMultipleAccounts({ connection: provider.connection, keys: positionKeys, - })).map(a => coder.decode("positionV0", a.data)); + })).map(a => coder.decode("PositionV0", a.data)); const currTs = await getSolanaUnixTimestamp(provider); const currTsBN = new anchor.BN(currTs.toString()); @@ -88,7 +88,7 @@ export async function run(args: any = process.argv) { )[0], genesisEndSubDaoEpochInfo: subDaoEpochInfoKey( subDao, - position.genesisEnd + position.genesisEnd.isZero() ? min(position.lockup.endTs, proxyEndTs!) : position.genesisEnd )[0], proxyConfig: registrar.proxyConfig, systemProgram: SystemProgram.programId, diff --git a/programs/helium-sub-daos/src/instructions/delegation/close_delegation_v0.rs b/programs/helium-sub-daos/src/instructions/delegation/close_delegation_v0.rs index b361c6f7b..27677038c 100644 --- a/programs/helium-sub-daos/src/instructions/delegation/close_delegation_v0.rs +++ b/programs/helium-sub-daos/src/instructions/delegation/close_delegation_v0.rs @@ -88,7 +88,14 @@ pub struct CloseDelegationV0<'info> { // no need to pass an extra account here. Just pass the closing time sdei and // do not change it. if position.genesis_end <= registrar.clock_unix_timestamp() { - position.lockup.end_ts + min( + position.lockup.end_ts, + if delegated_position.expiration_ts == 0 { + position.lockup.end_ts + } else { + min(position.lockup.end_ts, delegated_position.expiration_ts) + } + ) } else { position.genesis_end } diff --git a/programs/helium-sub-daos/src/instructions/delegation/delegate_v0.rs b/programs/helium-sub-daos/src/instructions/delegation/delegate_v0.rs index 60b310468..135d16fd9 100644 --- a/programs/helium-sub-daos/src/instructions/delegation/delegate_v0.rs +++ b/programs/helium-sub-daos/src/instructions/delegation/delegate_v0.rs @@ -81,7 +81,7 @@ pub struct DelegateV0<'info> { // Avoid passing an extra account if the end is 0 (no genesis on this position). // Pass instead closing time epoch info, txn account deduplication will reduce the overall tx size if position.genesis_end <= registrar.clock_unix_timestamp() { - position.lockup.end_ts + min(position.lockup.end_ts, proxy_config.get_current_season(registrar.clock_unix_timestamp()).unwrap().end) } else { position.genesis_end } diff --git a/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs b/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs index ff5519802..61ca90caa 100644 --- a/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs +++ b/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs @@ -81,7 +81,11 @@ pub struct ExtendExpirationTsV0<'info> { // no need to pass an extra account here. Just pass the closing time sdei and // do not change it. if position.genesis_end <= registrar.clock_unix_timestamp() { - position.lockup.end_ts + if delegated_position.expiration_ts == 0 { + position.lockup.end_ts + } else { + min(position.lockup.end_ts, delegated_position.expiration_ts) + } } else { position.genesis_end } From 6238fa1d7a18eb4613720fb5eadd6d566cd66fd3 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Thu, 9 Jan 2025 09:02:50 -0800 Subject: [PATCH 2/2] More bugfixes --- programs/helium-sub-daos/src/state.rs | 2 +- programs/helium-sub-daos/src/utils.rs | 8 +++++++- utils/vehnt/Cargo.lock | 1 + utils/vehnt/src/cli/delegated.rs | 8 +++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/programs/helium-sub-daos/src/state.rs b/programs/helium-sub-daos/src/state.rs index 8076c23c5..699fcc208 100644 --- a/programs/helium-sub-daos/src/state.rs +++ b/programs/helium-sub-daos/src/state.rs @@ -283,7 +283,7 @@ pub struct SubDaoEpochInfoV0 { } impl SubDaoEpochInfoV0 { - pub const SIZE: usize = 60 + 8 + std::mem::size_of::() - 8 - 8 - 8 - 4; // subtract 8 the extra u64 we added to vehnt, dc onboarding fees paid, hnt rewards issued, and prev percentage + pub const SIZE: usize = 60 + 8 + std::mem::size_of::() - 8 - 8 - 8; // subtract 8 the extra u64 we added to vehnt, dc onboarding fees paid, hnt rewards issued, and prev percentage } impl SubDaoEpochInfoV0 { pub fn start_ts(&self) -> i64 { diff --git a/programs/helium-sub-daos/src/utils.rs b/programs/helium-sub-daos/src/utils.rs index f9e013a61..4e157da50 100644 --- a/programs/helium-sub-daos/src/utils.rs +++ b/programs/helium-sub-daos/src/utils.rs @@ -310,6 +310,8 @@ pub fn caclulate_vhnt_info( .unwrap(), ) .unwrap() + } else if expiration_ts == 0 { + position.lockup.seconds_left(curr_ts) } else { min( u64::try_from(expiration_ts.checked_sub(curr_ts).unwrap()).unwrap(), @@ -328,7 +330,11 @@ pub fn caclulate_vhnt_info( } else { position.voting_power_precise(voting_mint_config, curr_ts)? }; - let delegation_end_ts = min(expiration_ts, position.lockup.end_ts); + let delegation_end_ts = if expiration_ts == 0 { + position.lockup.end_ts + } else { + min(expiration_ts, position.lockup.end_ts) + }; let vehnt_at_delegation_end = position.voting_power_precise(voting_mint_config, delegation_end_ts)?; diff --git a/utils/vehnt/Cargo.lock b/utils/vehnt/Cargo.lock index a37c2ad16..19247b690 100644 --- a/utils/vehnt/Cargo.lock +++ b/utils/vehnt/Cargo.lock @@ -1981,6 +1981,7 @@ dependencies = [ "default-env", "mpl-token-metadata", "nft-proxy", + "proposal", "shared-utils", "solana-security-txt", "time 0.3.36", diff --git a/utils/vehnt/src/cli/delegated.rs b/utils/vehnt/src/cli/delegated.rs index b9afcb901..944a21dc8 100644 --- a/utils/vehnt/src/cli/delegated.rs +++ b/utils/vehnt/src/cli/delegated.rs @@ -165,10 +165,12 @@ impl Delegated { epoch_infos_by_subdao_and_epoch .insert(Pubkey::from_str(MOBILE_SUBDAO).unwrap(), HashMap::new()); for info in infos { + if info.1.sub_dao == Pubkey::from_str(IOT_SUBDAO).unwrap() || info.1.sub_dao == Pubkey::from_str(MOBILE_SUBDAO).unwrap() { epoch_infos_by_subdao_and_epoch - .get_mut(&info.1.sub_dao) - .unwrap() - .insert(info.1.epoch, info); + .get_mut(&info.1.sub_dao) + .unwrap() + .insert(info.1.epoch, info); + } } let mut new_epoch_infos_by_subdao_and_epoch: HashMap< Pubkey,