From 682d83562328709c10716b0815863be046eab996 Mon Sep 17 00:00:00 2001 From: Calcifer1001 Date: Tue, 3 Sep 2024 13:07:34 -0300 Subject: [PATCH] feat: set vote lock filters --- src/contracts/mpdao-vote.ts | 8 +++++++ src/main.ts | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/contracts/mpdao-vote.ts b/src/contracts/mpdao-vote.ts index 132c4c4..48b3f09 100644 --- a/src/contracts/mpdao-vote.ts +++ b/src/contracts/mpdao-vote.ts @@ -115,4 +115,12 @@ export class MpDaoVoteContract extends SmartContract { return this.call("migration_set_associated_data", { data: usersData }); } + async get_lock_in_vote_filters() { + return this.view("get_lock_in_vote_filters") + } + + async set_lock_in_vote_filters(end_timestamp_ms: number, votable_numeric_id: number, votable_address?: string) { + return this.call("set_lock_in_vote_filters", { end_timestamp_ms, votable_numeric_id, votable_address }) + } + } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index af3d746..f88d8a8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,6 +20,8 @@ import { showClaimsStNear } from "./claims/show-claims-stnear"; import { computeAsDate } from "./compute-as-date"; import { homedir } from "os"; import { generateDelegatorTableDataSince, generateTableDataByDelegatorSince, getENOsContracts } from "./ENOs/delegators"; +import { FolderData, MetaPipelineContract } from "./contracts/meta-pipeline"; +import { getCredentials } from "./util/near"; type ByContractAndRoundInfoType = { @@ -547,6 +549,46 @@ export async function updateDbPg(dbRows: VotersRow[], byContractRows: VotersByCo } } +async function ensureLockVoteContract() { + try { + let mpDaoVote = new MpDaoVoteContract(MPDAO_VOTE_CONTRACT_ID) + const nowMs = Date.now() + const lockInVoteFilters = await mpDaoVote.get_lock_in_vote_filters() + if(lockInVoteFilters.lock_votes_in_end_timestamp_ms > nowMs) { + console.log("Vote filters already set") + return + } + + const metaPipelineContract = new MetaPipelineContract(META_PIPELINE_CONTRACT_ID) + const foldersDataArray: FolderData[] = await metaPipelineContract.getFolders() + const pastThresholdMs = 2 * 24 * 60 * 60 * 1000 // 2 days in milliseconds + const futureThresholdMs = 20 * 24 * 60 * 60 * 1000 // 20 days in milliseconds + for (let i = 0; i < foldersDataArray.length; i++) { + const folderData = foldersDataArray[i] + const endVoteTimestampMs = folderData.end_vote_timestamp * 1000 + if(nowMs > endVoteTimestampMs - pastThresholdMs && endVoteTimestampMs + futureThresholdMs > nowMs) { + console.log("Setting vote filters for folder id", folderData.folder_id, "grants #", folderData.folder_id+1) + console.log("With params", endVoteTimestampMs + futureThresholdMs, folderData.folder_id + 1, 'initiatives') + await mpDaoVote.set_lock_in_vote_filters( + endVoteTimestampMs + futureThresholdMs, + folderData.folder_id + 1, + 'initiatives' + ) + } + } + } catch (err) { + console.error(err) + } + // Check it hasn't been set already (endTime is in the past) + // Get folders data + // Check if a folder is within the last 48 hours + // Call meta-vote.set_lock_in_vote_filters({ + // end_timestamp_ms: u64, = folder.endTimestamp + 20 days + // votable_numeric_id: u16, = folder.id || folder.id+1 + // votable_address: Option, = 'initiatives' + // }) +} + async function prepareDB(client: sq3.CommonSQLClient) { await client.query(CREATE_TABLE_APP_DEB_VERSION); @@ -798,6 +840,8 @@ async function mainAsyncProcess() { await updateDbSqLite(dbRows, dbRows2, availableClaimsRows) // update remote pgDB await updateDbPg(dbRows, dbRows2, availableClaimsRows) + + await ensureLockVoteContract() } catch (err) { console.error(err) }