Compare commits

...

2 Commits

Author SHA1 Message Date
Ladd Hoffman 1e67f80808 copy ABIs to contract-config dir on deploy
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 29s Details
2024-03-17 12:30:12 -05:00
Ladd Hoffman 3846ec5d08 only automatically stake for pools initated by Work1 2024-03-17 12:29:17 -05:00
14 changed files with 1032 additions and 996 deletions

View File

@ -11,10 +11,11 @@ import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Stack from 'react-bootstrap/Stack';
import DAOArtifact from 'contract-config/DAO.json';
import work1Artifact from 'contract-config/Work1.json';
import { getContractByChainId } from './contract-config';
import Web3Context from './Web3Context';
import DAOArtifact from './assets/DAO.json';
import work1Artifact from './assets/Work1.json';
import AvailabilityStakes from './AvailabilityStakes';
import WorkRequests from './WorkRequests';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import contractAddresses from '../../contract-addresses.json';
import contractAddresses from 'contract-config/addresses.json';
const networks = {
localhost: '0x539',

679
contract-config/DAO.json Normal file

File diff suppressed because one or more lines are too long

305
contract-config/Work1.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"localhost": {
"DAO": "0x76Dfe9F47f06112a1b78960bf37d87CfbB6D6133",
"Work1": "0xd2845aE812Ee42cF024fB4C55c052365792aBd78"
"DAO": "0xee46C48314Db1cd91DfaDc4f2f2cb12DE3B0Ec54",
"Work1": "0x37C7d46CC4Ae5a12402811B763998db4248C7069"
},
"sepolia": {
"DAO": "0x39B7522Ee1A5B13aE5580C40114239D4cE0e7D29",

View File

@ -0,0 +1,11 @@
{
"name": "contract-config",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

View File

@ -22,6 +22,7 @@ struct Stake {
struct ValidationPool {
uint id;
uint postIndex;
address sender;
mapping(uint => Stake) stakes;
uint stakeCount;
uint256 fee;
@ -82,6 +83,7 @@ contract DAO is ERC20("Reputation", "REP") {
require(post.author != address(0), "Target post not found");
poolIndex = validationPoolCount++;
ValidationPool storage pool = validationPools[poolIndex];
pool.sender = msg.sender;
pool.postIndex = postIndex;
pool.fee = msg.value;
pool.duration = duration;

View File

@ -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) => {

View File

@ -1,4 +1,4 @@
const contractAddresses = require('../../contract-addresses.json');
const contractAddresses = require('contract-config/addresses.json');
const networks = {
localhost: '0x539',

View File

@ -1,10 +1,9 @@
const { ethers } = require('hardhat');
const fs = require('fs');
const contractAddresses = require('../../contract-addresses.json');
const contractAddressesWritePath = '../contract-addresses.json';
const contractAddresses = require('contract-config/addresses.json');
const contractAddressesWritePath = '../contract-config/addresses.json';
const network = process.env.HARDHAT_NETWORK;
async function main() {
@ -23,6 +22,9 @@ async function main() {
fs.writeFileSync(contractAddressesWritePath, JSON.stringify(contractAddresses, null, 2));
console.log('Wrote file', fs.realpathSync(contractAddressesWritePath));
fs.copyFileSync('./artifacts/contracts/DAO.sol/DAO.json', '../contract-config/DAO.json');
fs.copyFileSync('./artifacts/contracts/Work1.sol/Work1.json', '../contract-config/Work1.json');
}
// We recommend this pattern to be able to use async/await everywhere

View File

@ -85,6 +85,7 @@ describe('DAO', () => {
expect(pool.duration).to.equal(POOL_DURATION);
expect(pool.postIndex).to.equal(0);
expect(pool.resolved).to.be.false;
expect(pool.sender).to.equal(account1);
});
});

View File

@ -233,6 +233,9 @@ describe('Work1', () => {
const post = await dao.posts(1);
expect(post.author).to.equal(account1);
expect(post.sender).to.equal(work1.target);
const pool = await dao.validationPools(1);
expect(pool.fee).to.equal(WORK1_PRICE);
expect(pool.sender).to.equal(work1.target);
});
it('should be able to submit work disapproval', async () => {