dao-governance-framework/forum-network/src/classes/dao/dao.js

75 lines
2.4 KiB
JavaScript

import { Forum } from './forum.js';
import { ReputationTokenContract } from '../reputation/reputation-token.js';
import { ValidationPool } from './validation-pool.js';
import { Availability } from './availability.js';
import { Business } from './business.js';
import { Actor } from '../display/actor.js';
/**
* Purpose:
* - Forum: Maintain a directed, acyclic, graph of positively and negatively weighted citations.
* and the value accrued via each post and citation.
* - Reputation: Keep track of reputation accrued to each expert
*/
export class DAO extends Actor {
constructor(name, scene, options) {
super(name, scene, options);
/* Contracts */
this.forum = new Forum(this, 'Forum', scene);
this.availability = new Availability(this, 'Availability', scene);
this.business = new Business(this, 'Business', scene);
this.reputation = new ReputationTokenContract();
/* Data */
this.validationPools = new Map();
this.experts = new Map();
this.actions = {
};
}
listValidationPools() {
Array.from(this.validationPools.values());
}
listActiveVoters({ activeVoterThreshold } = {}) {
return Array.from(this.experts.values()).filter((voter) => {
const hasVoted = !!voter.dateLastVote;
const withinThreshold = !activeVoterThreshold
|| new Date() - voter.dateLastVote >= activeVoterThreshold;
return hasVoted && withinThreshold;
});
}
getActiveReputation() {
return this.listActiveVoters()
.map(({ reputationPublicKey }) => this.reputation.valueOwnedBy(reputationPublicKey))
.reduce((acc, cur) => (acc += cur), 0);
}
getActiveAvailableReputation() {
return this.listActiveVoters()
.map(({ reputationPublicKey }) => this.reputation.availableValueOwnedBy(reputationPublicKey))
.reduce((acc, cur) => (acc += cur), 0);
}
async initiateValidationPool(fromActor, poolOptions, stakeOptions) {
const validationPoolNumber = this.validationPools.size + 1;
const name = `Pool${validationPoolNumber}`;
const pool = new ValidationPool(this, poolOptions, name, this.scene, fromActor);
this.validationPools.set(pool.id, pool);
if (stakeOptions) {
const { reputationPublicKey, tokenId, authorStakeAmount } = stakeOptions;
await pool.stake(reputationPublicKey, {
tokenId,
position: true,
amount: authorStakeAmount,
});
}
return pool;
}
}