Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitoring and repairs for 138 delegation expirations #770

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading