Move all params to validation-pool.js
This commit is contained in:
parent
36c827a40f
commit
b02efb66ad
|
@ -1,4 +1,3 @@
|
|||
import params from '../../params.js';
|
||||
import { Forum } from './forum.js';
|
||||
import { ReputationTokenContract } from '../reputation/reputation-token.js';
|
||||
import { ValidationPool } from './validation-pool.js';
|
||||
|
@ -34,11 +33,11 @@ export class DAO extends Actor {
|
|||
Array.from(this.validationPools.values());
|
||||
}
|
||||
|
||||
listActiveVoters() {
|
||||
listActiveVoters({ activeVoterThreshold } = {}) {
|
||||
return Array.from(this.experts.values()).filter((voter) => {
|
||||
const hasVoted = !!voter.dateLastVote;
|
||||
const withinThreshold = !params.activeVoterThreshold
|
||||
|| new Date() - voter.dateLastVote >= params.activeVoterThreshold;
|
||||
const withinThreshold = !activeVoterThreshold
|
||||
|| new Date() - voter.dateLastVote >= activeVoterThreshold;
|
||||
return hasVoted && withinThreshold;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { WDAG } from '../supporting/wdag.js';
|
||||
import { Action } from '../display/action.js';
|
||||
import { Actor } from '../display/actor.js';
|
||||
import params from '../../params.js';
|
||||
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
||||
import { displayNumber } from '../../util/helpers.js';
|
||||
import {
|
||||
|
@ -21,25 +20,6 @@ class Post extends Actor {
|
|||
this.authors = postContent.authors;
|
||||
this.citations = postContent.citations;
|
||||
this.title = postContent.title;
|
||||
const leachingTotal = this.citations
|
||||
.filter(({ weight }) => weight < 0)
|
||||
.reduce((total, { weight }) => total += -weight, 0);
|
||||
const donationTotal = this.citations
|
||||
.filter(({ weight }) => weight > 0)
|
||||
.reduce((total, { weight }) => total += weight, 0);
|
||||
|
||||
// TODO: Move evaluation of these parameters to Validation Pool
|
||||
if (leachingTotal > params.revaluationLimit) {
|
||||
throw new Error('Post leaching total exceeds revaluation limit '
|
||||
+ `(${leachingTotal} > ${params.revaluationLimit})`);
|
||||
}
|
||||
if (donationTotal > params.revaluationLimit) {
|
||||
throw new Error('Post donation total exceeds revaluation limit '
|
||||
+ `(${donationTotal} > ${params.revaluationLimit})`);
|
||||
}
|
||||
if (this.citations.some(({ weight }) => Math.abs(weight) > params.revaluationLimit)) {
|
||||
throw new Error(`Each citation magnitude must not exceed revaluation limit ${params.revaluationLimit}`);
|
||||
}
|
||||
}
|
||||
|
||||
getLabel() {
|
||||
|
@ -110,7 +90,7 @@ export class Forum extends ReputationHolder {
|
|||
// getContract(type) { }
|
||||
|
||||
async onValidate({
|
||||
pool, postId, tokenId,
|
||||
pool, postId, tokenId, referenceChainLimit, leachingValue,
|
||||
}) {
|
||||
console.log('onValidate', { pool, postId, tokenId });
|
||||
const initialValue = this.dao.reputation.valueOf(tokenId);
|
||||
|
@ -160,7 +140,12 @@ export class Forum extends ReputationHolder {
|
|||
// Compute reputation rewards
|
||||
await this.propagateValue(
|
||||
{ to: postVertex, from: { data: pool } },
|
||||
{ rewardsAccumulator, increment: initialValue },
|
||||
{
|
||||
rewardsAccumulator,
|
||||
increment: initialValue,
|
||||
referenceChainLimit,
|
||||
leachingValue,
|
||||
},
|
||||
);
|
||||
|
||||
// Apply computed rewards to update values of tokens
|
||||
|
@ -200,17 +185,22 @@ export class Forum extends ReputationHolder {
|
|||
* @param {Object} opaqueData
|
||||
*/
|
||||
async propagateValue(edge, {
|
||||
rewardsAccumulator, increment, depth = 0, initialNegative = false,
|
||||
rewardsAccumulator,
|
||||
increment,
|
||||
depth = 0,
|
||||
initialNegative = false,
|
||||
referenceChainLimit,
|
||||
leachingValue
|
||||
}) {
|
||||
const postVertex = edge.to;
|
||||
const post = postVertex.data;
|
||||
this.actions.propagate.log(edge.from.data, post, `(${increment})`);
|
||||
|
||||
if (!!params.referenceChainLimit && depth > params.referenceChainLimit) {
|
||||
if (!!referenceChainLimit && depth > referenceChainLimit) {
|
||||
this.actions.propagate.log(
|
||||
edge.from.data,
|
||||
post,
|
||||
`referenceChainLimit (${params.referenceChainLimit}) reached`,
|
||||
`referenceChainLimit (${referenceChainLimit}) reached`,
|
||||
null,
|
||||
'-x',
|
||||
);
|
||||
|
@ -269,6 +259,8 @@ export class Forum extends ReputationHolder {
|
|||
increment: outboundAmount,
|
||||
depth: depth + 1,
|
||||
initialNegative: initialNegative || (depth === 0 && outboundAmount < 0),
|
||||
referenceChainLimit,
|
||||
leachingValue
|
||||
});
|
||||
|
||||
// Any excess (negative) amount that could not be propagated,
|
||||
|
@ -290,7 +282,7 @@ export class Forum extends ReputationHolder {
|
|||
this.actions.confirm.log(
|
||||
citationEdge.to.data,
|
||||
citationEdge.from.data,
|
||||
`(refund: ${displayNumber(refundFromOutbound)}, leach: ${outboundAmount * params.leachingValue})`,
|
||||
`(refund: ${displayNumber(refundFromOutbound)}, leach: ${outboundAmount * leachingValue})`,
|
||||
undefined,
|
||||
'-->>',
|
||||
);
|
||||
|
@ -301,11 +293,11 @@ export class Forum extends ReputationHolder {
|
|||
|
||||
// First, leach value via negative citations
|
||||
const totalLeachingAmount = await propagate(false);
|
||||
increment -= totalLeachingAmount * params.leachingValue;
|
||||
increment -= totalLeachingAmount * leachingValue;
|
||||
|
||||
// Now propagate value via positive citations
|
||||
const totalDonationAmount = await propagate(true);
|
||||
increment -= totalDonationAmount * params.leachingValue;
|
||||
increment -= totalDonationAmount * leachingValue;
|
||||
|
||||
// Apply the remaining increment to the present post
|
||||
const rawNewValue = post.value + increment;
|
||||
|
|
|
@ -63,8 +63,30 @@ export class ValidationPool extends ReputationHolder {
|
|||
}]; got ${duration}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.dao = dao;
|
||||
this.postId = postId;
|
||||
const post = this.dao.forum.graph.getVertexData(postId);
|
||||
|
||||
const leachingTotal = post.citations
|
||||
.filter(({ weight }) => weight < 0)
|
||||
.reduce((total, { weight }) => total += -weight, 0);
|
||||
const donationTotal = post.citations
|
||||
.filter(({ weight }) => weight > 0)
|
||||
.reduce((total, { weight }) => total += weight, 0);
|
||||
|
||||
if (leachingTotal > params.revaluationLimit) {
|
||||
throw new Error('Post leaching total exceeds revaluation limit '
|
||||
+ `(${leachingTotal} > ${params.revaluationLimit})`);
|
||||
}
|
||||
if (donationTotal > params.revaluationLimit) {
|
||||
throw new Error('Post donation total exceeds revaluation limit '
|
||||
+ `(${donationTotal} > ${params.revaluationLimit})`);
|
||||
}
|
||||
if (post.citations.some(({ weight }) => Math.abs(weight) > params.revaluationLimit)) {
|
||||
throw new Error(`Each citation magnitude must not exceed revaluation limit ${params.revaluationLimit}`);
|
||||
}
|
||||
|
||||
this.state = ValidationPoolStates.OPEN;
|
||||
this.setStatus('Open');
|
||||
this.stakes = new Set();
|
||||
|
@ -136,7 +158,7 @@ export class ValidationPool extends ReputationHolder {
|
|||
*/
|
||||
getTotalStakedOnPost(outcome) {
|
||||
return this.getStakes(outcome, { excludeSystem: false })
|
||||
.map((stake) => stake.getStakeValue())
|
||||
.map((stake) => stake.getStakeValue({ lockingTimeExponent: params.lockingTimeExponent }))
|
||||
.reduce((acc, cur) => (acc += cur), 0);
|
||||
}
|
||||
|
||||
|
@ -262,7 +284,7 @@ export class ValidationPool extends ReputationHolder {
|
|||
// Compute rewards for the winning voters, in proportion to the value of their stakes.
|
||||
for (const stake of winningEntries) {
|
||||
const { tokenId, amount } = stake;
|
||||
const value = stake.getStakeValue();
|
||||
const value = stake.getStakeValue({ lockingTimeExponent: params.lockingTimeExponent });
|
||||
const reward = tokensForWinners * (value / totalValueOfStakesForWin);
|
||||
// Also return each winning voter their staked amount
|
||||
const reputationPublicKey = this.dao.reputation.ownerOf(tokenId);
|
||||
|
@ -287,6 +309,8 @@ export class ValidationPool extends ReputationHolder {
|
|||
pool: this,
|
||||
postId: this.postId,
|
||||
tokenId: this.tokenId,
|
||||
referenceChainLimit: params.referenceChainLimit,
|
||||
leachingValue: params.leachingValue,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import params from '../../params.js';
|
||||
|
||||
export class Stake {
|
||||
constructor({
|
||||
tokenId, position, amount, lockingTime,
|
||||
|
@ -10,7 +8,7 @@ export class Stake {
|
|||
this.lockingTime = lockingTime;
|
||||
}
|
||||
|
||||
getStakeValue() {
|
||||
return this.amount * this.lockingTime ** params.lockingTimeExponent;
|
||||
getStakeValue({ lockingTimeExponent } = {}) {
|
||||
return this.amount * this.lockingTime ** lockingTimeExponent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<title>VM</title>
|
||||
<title>All Tests</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
||||
<link type="text/css" rel="stylesheet" href="../index.css" />
|
||||
|
|
Loading…
Reference in New Issue