Skip to content

Commit

Permalink
Fix monitoring and repairs for 138 delegation expirations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Jan 9, 2025
1 parent 34ab3ae commit 103e93b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
11 changes: 9 additions & 2 deletions packages/account-postgres-sink-service/vehnt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ WITH
FROM positions_with_vehnt p
JOIN delegated_positions d on d.position = p.address
JOIN sub_daos s on s.address = d.sub_dao
-- Remove positions getting purged this epoch
WHERE (lockup_kind = 'constant' or end_ts > (floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)) + 60 * 60 * 24)
-- Remove positions getting purged this epoch or expired this epoch
WHERE
(
lockup_kind = 'constant'
or end_ts > (
floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)
) + 60 * 60 * 24
)
AND d.expiration_ts > (floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)) + 60 * 60 * 24
GROUP BY s.dnt_mint, s.vehnt_fall_rate, s.vehnt_delegated, s.vehnt_last_calculated_ts, s.vehnt_last_calculated_ts
)
SELECT
Expand Down
29 changes: 18 additions & 11 deletions packages/helium-admin-cli/src/add-expiration-to-delegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export async function run(args: any = process.argv) {
const vsrProgram = await initVsr(provider);
const hsdProgram = await initHsd(provider);


const hntMint = new PublicKey(argv.hntMint);
const dao = daoKey(hntMint)[0];
const registrarK = (await hsdProgram.account.daoV0.fetch(dao)).registrar;
Expand All @@ -48,18 +47,22 @@ export async function run(args: any = process.argv) {
);

const instructions: TransactionInstruction[] = [];
const delegations = await hsdProgram.account.delegatedPositionV0.all()
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 = vsrProgram.coder.accounts
const positionAccs = (await getMultipleAccounts({
connection: provider.connection,
keys: positionKeys,
})).map(a => coder.decode("PositionV0", a.data));
const positionKeys = needsMigration.map((d) => d.account.position);
const coder = vsrProgram.coder.accounts;
const positionAccs = (
await getMultipleAccounts({
connection: provider.connection,
keys: positionKeys,
})
).map((a) => coder.decode("PositionV0", a.data));

const currTs = await getSolanaUnixTimestamp(provider);
const currTsBN = new anchor.BN(currTs.toString());
const proxyEndTs = proxyConfig.seasons.reverse().find(s => currTsBN.gte(s.start))?.end;
const proxyEndTs = proxyConfig.seasons
.reverse()
.find((s) => currTsBN.gte(s.start))?.end;
for (const [delegation, position] of zip(needsMigration, positionAccs)) {
const subDao = delegation.account.subDao;
const positionTokenAccount = (
Expand All @@ -80,15 +83,19 @@ export async function run(args: any = process.argv) {
subDao: delegation.account.subDao,
oldClosingTimeSubDaoEpochInfo: subDaoEpochInfoKey(
subDao,
position.lockup.endTs
delegation.account.expirationTs.isZero()
? position.lockup.endTs
: min(position.lockup.endTs, delegation.account.expirationTs)
)[0],
closingTimeSubDaoEpochInfo: subDaoEpochInfoKey(
subDao,
min(position.lockup.endTs, proxyEndTs!)
)[0],
genesisEndSubDaoEpochInfo: subDaoEpochInfoKey(
subDao,
position.genesisEnd.isZero() ? min(position.lockup.endTs, proxyEndTs!) : position.genesisEnd
position.genesisEnd.isZero()
? min(position.lockup.endTs, proxyEndTs!)
: position.genesisEnd
)[0],
proxyConfig: registrar.proxyConfig,
systemProgram: SystemProgram.programId,
Expand Down
11 changes: 9 additions & 2 deletions packages/monitor-service/src/monitors/vehnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,15 @@ WITH
FROM positions_with_vehnt p
JOIN delegated_positions d on d.position = p.address
JOIN sub_daos s on s.address = d.sub_dao
-- Remove positions getting purged this epoch
WHERE (lockup_kind = 'constant' or end_ts > (floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)) + 60 * 60 * 24)
-- Remove positions getting purged this epoch or expired this epoch
WHERE
(
lockup_kind = 'constant'
or end_ts > (
floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)
) + 60 * 60 * 24
)
AND d.expiration_ts > (floor(current_ts / (60 * 60 * 24)) * (60 * 60 * 24)) + 60 * 60 * 24
GROUP BY s.dnt_mint, s.vehnt_fall_rate, s.vehnt_delegated, s.vehnt_last_calculated_ts, s.vehnt_last_calculated_ts
)
SELECT
Expand Down
2 changes: 1 addition & 1 deletion utils/vehnt/src/cli/delegated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Delegated {
Pubkey,
HashMap<u64, (Pubkey, SubDaoEpochInfoV0)>,
> = HashMap::new();
new_epoch_infos_by_subdao_and_epoch
new_epoch_infos_by_subdao_and_epochr
.insert(Pubkey::from_str(IOT_SUBDAO).unwrap(), HashMap::new());
new_epoch_infos_by_subdao_and_epoch
.insert(Pubkey::from_str(MOBILE_SUBDAO).unwrap(), HashMap::new());
Expand Down

0 comments on commit 103e93b

Please sign in to comment.