From 7b720c73253d494d66b68bf4a402dee7b91bef15 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 9 Apr 2024 05:09:27 -0500 Subject: [PATCH] WIP auto staking legislative process --- ethereum/scripts/automatic-staking.js | 39 ++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/ethereum/scripts/automatic-staking.js b/ethereum/scripts/automatic-staking.js index a5df662..a185ee4 100644 --- a/ethereum/scripts/automatic-staking.js +++ b/ethereum/scripts/automatic-staking.js @@ -1,8 +1,10 @@ const { ethers } = require('hardhat'); +const { execSync } = require('child_process'); const { getContractAddressByNetworkName } = require('./contract-config'); const readFromApi = require('./util/read-from-api'); const network = process.env.HARDHAT_NETWORK; +let currentVersionProposalId; let dao; let work1; @@ -11,6 +13,22 @@ let account; let validationPools; let reputation; let posts; +let proposalsContract; +let proposals; + +const getCurrentVersion = () => { + const currentCommit = execSync('git rev-parse HEAD'); + return currentCommit.toString(); +}; + +const fetchCurrentVersionProposal = async () => { + const p = await proposalsContract. +}; + +const getLatestVersion = () => { + const latestVersion = 'TBD'; + return latestVersion; +}; const fetchReputation = async () => { reputation = await dao.balanceOf(account); @@ -57,6 +75,22 @@ const fetchValidationPools = async () => { await Promise.all(promises); }; +const fetchProposal = async (proposalIndex) => { + const proposal = await proposalsContract.proposals(proposalIndex); + proposals[proposalIndex] = proposal; +}; + +const fetchProposals = async () => { + const count = await proposalsContract.proposalCount(); + console.log(`proposal count: ${count}`); + const promises = []; + proposals = []; + for (let i = 0; i < count; i += 1) { + promises.push(fetchProposal(i)); + } + await Promise.all(promises); +}; + const initialize = async () => { const getContract = (name) => ethers.getContractAt( name, @@ -65,12 +99,14 @@ const initialize = async () => { dao = await getContract('DAO'); work1 = await getContract('Work1'); onboarding = await getContract('Onboarding'); + proposalsContract = await getContract('Proposals'); [account] = await ethers.getSigners(); const address = await account.getAddress(); console.log(`account: ${address}`); posts = []; await fetchReputation(); await fetchValidationPools(); + await fetchProposals(); }; const poolIsActive = (pool) => { @@ -121,7 +157,6 @@ const conditionalStake = async (pool, amountToStake) => { // We could consider automatic followup staking, // as a convenience if you decide early to favor a proposal } else { - console.log('Unrecognized sender %s', pool.sender); await stake(pool, amountToStake, false); } }; @@ -144,6 +179,8 @@ const printPool = (pool) => { }; async function main() { + console.log('Current version:', getCurrentVersion()); + await initialize(); validationPools.forEach(printPool);