only automatically stake for pools initated by Work1
This commit is contained in:
parent
7e13449514
commit
3846ec5d08
|
@ -1,6 +1,8 @@
|
|||
const { ethers } = require('hardhat');
|
||||
const { getContractByNetworkName } = require('./contract-config');
|
||||
|
||||
const network = process.env.HARDHAT_NETWORK;
|
||||
|
||||
let dao;
|
||||
let account;
|
||||
let validationPools;
|
||||
|
@ -29,7 +31,6 @@ const fetchValidationPools = async () => {
|
|||
};
|
||||
|
||||
const initialize = async () => {
|
||||
const network = process.env.HARDHAT_NETWORK;
|
||||
const DAOAddress = getContractByNetworkName(network, 'DAO');
|
||||
dao = await ethers.getContractAt('DAO', DAOAddress);
|
||||
[account] = await ethers.getSigners();
|
||||
|
@ -45,6 +46,11 @@ const poolIsActive = (pool) => {
|
|||
return true;
|
||||
};
|
||||
|
||||
const poolIsValid = (pool) => {
|
||||
const Work1Address = getContractByNetworkName(network, 'Work1');
|
||||
return pool.sender === Work1Address;
|
||||
};
|
||||
|
||||
const stake = async (pool, amount) => {
|
||||
console.log(`staking ${amount} in favor of pool ${pool.id.toString()}`);
|
||||
await dao.stake(pool.id, amount, true);
|
||||
|
@ -71,11 +77,11 @@ async function main() {
|
|||
console.log(`pool ${pool.id.toString()}, status: ${status}`);
|
||||
});
|
||||
|
||||
// Stake half of available reputation on any active validation pools
|
||||
const activePools = validationPools.filter(poolIsActive);
|
||||
if (activePools.length && reputation > 0) {
|
||||
const amountPerPool = reputation / BigInt(2) / BigInt(activePools.length);
|
||||
await stakeEach(activePools, amountPerPool);
|
||||
// Stake half of available reputation on any active, valid pools
|
||||
const activeValidPools = validationPools.filter(poolIsActive).filter(poolIsValid);
|
||||
if (activeValidPools.length && reputation > 0) {
|
||||
const amountPerPool = reputation / BigInt(2) / BigInt(activeValidPools.length);
|
||||
await stakeEach(activeValidPools, amountPerPool);
|
||||
}
|
||||
|
||||
// Listen for new validation pools
|
||||
|
@ -83,10 +89,15 @@ async function main() {
|
|||
console.log(`pool ${poolIndex} started`);
|
||||
await fetchValidationPool(poolIndex);
|
||||
await fetchReputation();
|
||||
const pool = validationPools[poolIndex];
|
||||
|
||||
if (poolIsValid(pool)) {
|
||||
// Stake half of available reputation on this validation pool
|
||||
const amount = reputation / BigInt(2);
|
||||
await stake(poolIndex, amount, true);
|
||||
const amount = reputation / BigInt(2);
|
||||
await stake(poolIndex, amount, true);
|
||||
} else {
|
||||
console.log(`pool sender ${pool.sender} is not recognized`);
|
||||
}
|
||||
});
|
||||
|
||||
dao.on('ValidationPoolResolved', async (poolIndex, votePasses) => {
|
||||
|
|
Loading…
Reference in New Issue