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;