Skip to content

Commit

Permalink
Fix logic to add expiration to delegation (#768)
Browse files Browse the repository at this point in the history
* Fix logic to add expiration to delegation

* More bugfixes
  • Loading branch information
ChewingGlass authored Jan 9, 2025
1 parent d79d10b commit 8a13de7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
12 changes: 12 additions & 0 deletions packages/account-postgres-sink-service/vote_service_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion programs/helium-sub-daos/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub struct SubDaoEpochInfoV0 {
}

impl SubDaoEpochInfoV0 {
pub const SIZE: usize = 60 + 8 + std::mem::size_of::<SubDaoEpochInfoV0>() - 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::<SubDaoEpochInfoV0>() - 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 {
Expand Down
8 changes: 7 additions & 1 deletion programs/helium-sub-daos/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)?;

Expand Down
1 change: 1 addition & 0 deletions utils/vehnt/Cargo.lock

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

8 changes: 5 additions & 3 deletions utils/vehnt/src/cli/delegated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8a13de7

Please sign in to comment.