From 69d91a6accd348374dc2c25f8f50bba40b1e916a Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 26 Mar 2024 12:13:23 -0500 Subject: [PATCH] Automatic staking checks work evidence post content --- ethereum/scripts/automatic-staking.js | 34 ++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ethereum/scripts/automatic-staking.js b/ethereum/scripts/automatic-staking.js index 19e0242..5b25bed 100644 --- a/ethereum/scripts/automatic-staking.js +++ b/ethereum/scripts/automatic-staking.js @@ -78,18 +78,22 @@ const poolIsActive = (pool) => { return true; }; -const poolIsValid = async (pool) => { +const poolIsValid = (pool) => { switch (pool.sender) { case getContractAddressByNetworkName(network, 'Work1'): { - // TODO: Read content of post for this pool and verify that it conforms to protocol - console.log(`post ${pool.post.id} content: ${pool.post.content}`); - if (pool.post.content) return true; - return true; + // If this is a valid work evidence + // TODO: Can we decode from the post, a reference to the work request? + // The work request does have its own contentId, the work contract has that + // under availabilityStakes + const expectedContent = 'This is a work evidence post'; + return pool.post.content.startsWith(expectedContent); + } + case getContractAddressByNetworkName(network, 'Onboarding'): { + const expectedContent = 'This is an onboarding work evidence post'; + return pool.post.content.startsWith(expectedContent); } - case getContractAddressByNetworkName(network, 'Onboarding'): - // TODO: Read content of post for this pool and verify that it conforms to protocol - return true; default: + console.log('Unrecognized sender %s', pool.sender); return false; } }; @@ -120,7 +124,10 @@ async function main() { await initialize(); validationPools.forEach((pool) => { - console.log(`pool ${pool.id.toString()}, status: ${getPoolStatus(pool)}, post content: ${pool.post?.content}`); + console.log(`pool ${pool.id.toString()}, ` + + `status: ${getPoolStatus(pool)}, ` + + `is valid: ${poolIsValid(pool)}, ` + + `post content: ${pool.post?.content}`); }); // Stake half of available reputation on any active pools @@ -137,13 +144,8 @@ async function main() { await fetchReputation(); if (!reputation) return; const amountToStake = reputation / BigInt(2); - if (await poolIsValid(pool)) { - // Stake half of available reputation on this validation pool - await stake(pool, amountToStake, true); - } else { - console.log(`pool sender ${pool.sender} is not recognized`); - await stake(pool, amountToStake, false); - } + const inFavor = await poolIsValid(pool); + await stake(pool, amountToStake, inFavor); }); dao.on('ValidationPoolResolved', async (poolIndex, votePasses) => {