Refactor to clarify input parameters for validation pool
This commit is contained in:
parent
e602466800
commit
7e74773242
|
@ -1,5 +1,4 @@
|
||||||
import { Action } from '../display/action.js';
|
import { Action } from '../display/action.js';
|
||||||
import { PostMessage } from '../forum-network/message.js';
|
|
||||||
import { CryptoUtil } from '../supporting/crypto.js';
|
import { CryptoUtil } from '../supporting/crypto.js';
|
||||||
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
||||||
import { EdgeTypes } from '../../util/constants.js';
|
import { EdgeTypes } from '../../util/constants.js';
|
||||||
|
@ -18,7 +17,6 @@ export class Expert extends ReputationHolder {
|
||||||
getAssignedWork: new Action('get assigned work', scene),
|
getAssignedWork: new Action('get assigned work', scene),
|
||||||
submitWork: new Action('submit work evidence', scene),
|
submitWork: new Action('submit work evidence', scene),
|
||||||
};
|
};
|
||||||
this.validationPools = new Map();
|
|
||||||
this.tokens = [];
|
this.tokens = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,21 +47,23 @@ export class Expert extends ReputationHolder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitPostWithFee(postContent, poolOptions) {
|
async submitPostWithFee(postContent, { fee }, params) {
|
||||||
const post = await this.dao.forum.addPost(this.reputationPublicKey, postContent);
|
const post = await this.dao.forum.addPost(this.reputationPublicKey, postContent);
|
||||||
await this.actions.submitPost.log(this, post);
|
await this.actions.submitPost.log(this, post);
|
||||||
const postId = post.id;
|
const postId = post.id;
|
||||||
const pool = await this.initiateValidationPool({ ...poolOptions, postId });
|
const pool = await this.initiateValidationPool({ fee, postId }, params);
|
||||||
this.tokens.push(pool.tokenId);
|
this.tokens.push(pool.tokenId);
|
||||||
return { postId, pool };
|
return { postId, pool };
|
||||||
}
|
}
|
||||||
|
|
||||||
async initiateValidationPool(poolOptions) {
|
async initiateValidationPool({ postId, fee }, params) {
|
||||||
// For now, make direct call rather than network
|
// For now, make direct call rather than network
|
||||||
poolOptions.reputationPublicKey = this.reputationPublicKey;
|
const pool = await this.dao.initiateValidationPool(this, {
|
||||||
const pool = await this.dao.initiateValidationPool(this, poolOptions);
|
reputationPublicKey: this.reputationPublicKey,
|
||||||
|
postId,
|
||||||
|
fee,
|
||||||
|
}, params);
|
||||||
this.tokens.push(pool.tokenId);
|
this.tokens.push(pool.tokenId);
|
||||||
this.validationPools.set(pool.id, poolOptions);
|
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,12 +80,16 @@ export class Business extends Actor {
|
||||||
const pool = await this.dao.initiateValidationPool(this, {
|
const pool = await this.dao.initiateValidationPool(this, {
|
||||||
postId,
|
postId,
|
||||||
fee: request.fee,
|
fee: request.fee,
|
||||||
|
reputationPublicKey,
|
||||||
|
}, {
|
||||||
duration,
|
duration,
|
||||||
tokenLossRatio,
|
tokenLossRatio,
|
||||||
}, {
|
});
|
||||||
reputationPublicKey,
|
|
||||||
authorStakeAmount: request.worker.stakeAmount,
|
await pool.stake(reputationPublicKey, {
|
||||||
tokenId: request.worker.tokenId,
|
tokenId: request.worker.tokenId,
|
||||||
|
amount: request.worker.stakeAmount,
|
||||||
|
position: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// When the validation pool concludes,
|
// When the validation pool concludes,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { ReputationTokenContract } from '../reputation/reputation-token.js';
|
||||||
import { ValidationPool } from './validation-pool.js';
|
import { ValidationPool } from './validation-pool.js';
|
||||||
import { Availability } from './availability.js';
|
import { Availability } from './availability.js';
|
||||||
import { Business } from './business.js';
|
import { Business } from './business.js';
|
||||||
|
import { Voter } from '../supporting/voter.js';
|
||||||
import { Actor } from '../display/actor.js';
|
import { Actor } from '../display/actor.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +34,12 @@ export class DAO extends Actor {
|
||||||
Array.from(this.validationPools.values());
|
Array.from(this.validationPools.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addVoteRecord(reputationPublicKey, validationPool) {
|
||||||
|
const voter = this.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
||||||
|
voter.addVoteRecord(validationPool);
|
||||||
|
this.experts.set(reputationPublicKey, voter);
|
||||||
|
}
|
||||||
|
|
||||||
listActiveVoters({ activeVoterThreshold } = {}) {
|
listActiveVoters({ activeVoterThreshold } = {}) {
|
||||||
return Array.from(this.experts.values()).filter((voter) => {
|
return Array.from(this.experts.values()).filter((voter) => {
|
||||||
const hasVoted = !!voter.dateLastVote;
|
const hasVoted = !!voter.dateLastVote;
|
||||||
|
@ -54,21 +61,14 @@ export class DAO extends Actor {
|
||||||
.reduce((acc, cur) => (acc += cur), 0);
|
.reduce((acc, cur) => (acc += cur), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initiateValidationPool(fromActor, poolOptions, stakeOptions) {
|
async initiateValidationPool(fromActor, { postId, reputationPublicKey, fee }, params) {
|
||||||
const validationPoolNumber = this.validationPools.size + 1;
|
const validationPoolNumber = this.validationPools.size + 1;
|
||||||
const name = `Pool${validationPoolNumber}`;
|
const name = `Pool${validationPoolNumber}`;
|
||||||
const pool = new ValidationPool(this, poolOptions, name, this.scene, fromActor);
|
const pool = new ValidationPool(this, {
|
||||||
|
postId, reputationPublicKey, fee,
|
||||||
|
}, params, name, this.scene, fromActor);
|
||||||
this.validationPools.set(pool.id, pool);
|
this.validationPools.set(pool.id, pool);
|
||||||
|
|
||||||
if (stakeOptions) {
|
|
||||||
const { reputationPublicKey, tokenId, authorStakeAmount } = stakeOptions;
|
|
||||||
await pool.stake(reputationPublicKey, {
|
|
||||||
tokenId,
|
|
||||||
position: true,
|
|
||||||
amount: authorStakeAmount,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
||||||
import { Stake } from '../supporting/stake.js';
|
import { Stake } from '../supporting/stake.js';
|
||||||
import { Voter } from '../supporting/voter.js';
|
|
||||||
import { Action } from '../display/action.js';
|
import { Action } from '../display/action.js';
|
||||||
import { displayNumber } from '../../util/helpers.js';
|
import { displayNumber } from '../../util/helpers.js';
|
||||||
|
|
||||||
|
@ -47,6 +46,8 @@ export class ValidationPool extends ReputationHolder {
|
||||||
postId,
|
postId,
|
||||||
reputationPublicKey,
|
reputationPublicKey,
|
||||||
fee,
|
fee,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration,
|
duration,
|
||||||
tokenLossRatio,
|
tokenLossRatio,
|
||||||
contentiousDebate = false,
|
contentiousDebate = false,
|
||||||
|
@ -147,9 +148,7 @@ export class ValidationPool extends ReputationHolder {
|
||||||
this.actions.mint.log(this, this, `(${this.mintedValue})`);
|
this.actions.mint.log(this, this, `(${this.mintedValue})`);
|
||||||
|
|
||||||
// Keep a record of voters and their votes
|
// Keep a record of voters and their votes
|
||||||
const voter = this.dao.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
this.dao.addVoteRecord(reputationPublicKey, this);
|
||||||
voter.addVoteRecord(this);
|
|
||||||
this.dao.experts.set(reputationPublicKey, voter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTokenLossRatio() {
|
getTokenLossRatio() {
|
||||||
|
@ -232,12 +231,10 @@ export class ValidationPool extends ReputationHolder {
|
||||||
|
|
||||||
// Keep a record of voters and their votes
|
// Keep a record of voters and their votes
|
||||||
if (reputationPublicKey !== this.id) {
|
if (reputationPublicKey !== this.id) {
|
||||||
const voter = this.dao.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
this.dao.addVoteRecord(reputationPublicKey, this);
|
||||||
voter.addVoteRecord(this);
|
|
||||||
this.dao.experts.set(reputationPublicKey, voter);
|
|
||||||
|
|
||||||
// Update computed display values
|
// Update computed display values
|
||||||
const actor = this.scene?.findActor((a) => a.reputationPublicKey === voter.reputationPublicKey);
|
const actor = this.scene?.findActor((a) => a.reputationPublicKey === reputationPublicKey);
|
||||||
await actor.computeDisplayValues();
|
await actor.computeDisplayValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ const setup = async () => {
|
||||||
new PostContent({ hello: 'there' }).setTitle('Post 1'),
|
new PostContent({ hello: 'there' }).setTitle('Post 1'),
|
||||||
{
|
{
|
||||||
fee: 10,
|
fee: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration: POOL_DURATION,
|
duration: POOL_DURATION,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
},
|
},
|
||||||
|
@ -68,6 +70,8 @@ const setup = async () => {
|
||||||
.addCitation(postId1, 0.5),
|
.addCitation(postId1, 0.5),
|
||||||
{
|
{
|
||||||
fee: 10,
|
fee: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration: POOL_DURATION,
|
duration: POOL_DURATION,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,6 +42,8 @@ export class ForumTest {
|
||||||
postContent,
|
postContent,
|
||||||
{
|
{
|
||||||
fee,
|
fee,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration: this.options.poolDurationMs,
|
duration: this.options.poolDurationMs,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,6 +57,7 @@ describe('Validation Pool', function tests() {
|
||||||
await scene.sequence.startSection();
|
await scene.sequence.startSection();
|
||||||
const { pool } = await experts[0].submitPostWithFee(new PostContent(), {
|
const { pool } = await experts[0].submitPostWithFee(new PostContent(), {
|
||||||
fee: 7,
|
fee: 7,
|
||||||
|
}, {
|
||||||
duration: POOL_DURATION_MS,
|
duration: POOL_DURATION_MS,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
});
|
});
|
||||||
|
@ -84,6 +85,7 @@ describe('Validation Pool', function tests() {
|
||||||
try {
|
try {
|
||||||
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
||||||
fee: 1,
|
fee: 1,
|
||||||
|
}, {
|
||||||
duration: POOL_DURATION_MS,
|
duration: POOL_DURATION_MS,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
});
|
});
|
||||||
|
@ -98,6 +100,7 @@ describe('Validation Pool', function tests() {
|
||||||
it('Second expert must be approved by first expert', async () => {
|
it('Second expert must be approved by first expert', async () => {
|
||||||
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
||||||
fee: 1,
|
fee: 1,
|
||||||
|
}, {
|
||||||
duration: POOL_DURATION_MS,
|
duration: POOL_DURATION_MS,
|
||||||
tokenLossRatio: 1,
|
tokenLossRatio: 1,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue