From 62741ead017724500178cb77d0f72c05eb8c5c10 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 30 Apr 2024 17:53:57 -0500 Subject: [PATCH] enable staking --- backend/src/api/import-from-matrix.js | 7 ++----- backend/src/topics/validation-pools.js | 12 ++++++++++-- backend/src/util/wallet.js | 11 +++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 backend/src/util/wallet.js diff --git a/backend/src/api/import-from-matrix.js b/backend/src/api/import-from-matrix.js index 52447c9..f41efc4 100644 --- a/backend/src/api/import-from-matrix.js +++ b/backend/src/api/import-from-matrix.js @@ -1,16 +1,13 @@ -const ethers = require('ethers'); - const { getClient } = require('../matrix-bot'); const { matrixUserToAuthorAddress } = require('../util/db'); const write = require('../util/forum/write'); -const { dao, getProvider } = require('../util/contracts'); +const { dao } = require('../util/contracts'); const { ETH_NETWORK, - ETH_PRIVATE_KEY, } = process.env; -const wallet = new ethers.Wallet(ETH_PRIVATE_KEY, getProvider()); +const wallet = require('../util/wallet'); const addPostWithRetry = async (authors, hash, citations, retryDelay = 5000) => { try { diff --git a/backend/src/topics/validation-pools.js b/backend/src/topics/validation-pools.js index 8ce0fb3..82ee5f6 100644 --- a/backend/src/topics/validation-pools.js +++ b/backend/src/topics/validation-pools.js @@ -3,6 +3,7 @@ const Promise = require('bluebird'); const { dao } = require('../util/contracts'); const read = require('../util/forum/read'); const gateByProposal = require('../util/gate-by-proposal'); +const wallet = require('../util/wallet'); const { ENABLE_STAKING, @@ -49,8 +50,15 @@ const start = async () => { if (!enableStaking) { return; } - console.log(`WOULD STAKE ${inFavor ? 'in favor of' : 'against'} pool ${poolIndex}`); - // TODO: Stake half of available reputation + // Stake all available reputation + console.log(`STAKING ${inFavor ? 'in favor of' : 'against'} pool ${poolIndex}`); + const currentRep = await dao.balanceOf(wallet.getAddress()); + try { + await dao.stakeOnValidationPool(poolIndex, currentRep, inFavor); + } catch (e) { + // Maybe the end time passed? + console.error(`STAKING ${inFavor ? 'in favor of' : 'against'} pool ${poolIndex} failed, reason: ${e.reason}`); + } }); }; diff --git a/backend/src/util/wallet.js b/backend/src/util/wallet.js new file mode 100644 index 0000000..2a6fb29 --- /dev/null +++ b/backend/src/util/wallet.js @@ -0,0 +1,11 @@ +const ethers = require('ethers'); + +const { getProvider } = require('./contracts'); + +const { + ETH_PRIVATE_KEY, +} = process.env; + +const wallet = new ethers.Wallet(ETH_PRIVATE_KEY, getProvider()); + +module.exports = wallet;