diff --git a/packages/account-postgres-sink-service/vehnt.sql b/packages/account-postgres-sink-service/vehnt.sql index 66a4d56ca..abe65dfee 100644 --- a/packages/account-postgres-sink-service/vehnt.sql +++ b/packages/account-postgres-sink-service/vehnt.sql @@ -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 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 7c9d53cd4..c62042e87 100644 --- a/packages/helium-admin-cli/src/add-expiration-to-delegations.ts +++ b/packages/helium-admin-cli/src/add-expiration-to-delegations.ts @@ -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; @@ -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 = ( @@ -80,7 +83,9 @@ 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, @@ -88,7 +93,9 @@ export async function run(args: any = process.argv) { )[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, diff --git a/packages/monitor-service/src/monitors/vehnt.ts b/packages/monitor-service/src/monitors/vehnt.ts index 4a9a82907..cc0bb2d5e 100644 --- a/packages/monitor-service/src/monitors/vehnt.ts +++ b/packages/monitor-service/src/monitors/vehnt.ts @@ -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