Fixup, distribute rewards to voters

This commit is contained in:
Ladd Hoffman 2023-01-08 20:28:54 -06:00
parent 6cc1c25b37
commit e777a0ee85
2 changed files with 10 additions and 7 deletions

View File

@ -84,8 +84,6 @@ export class Forum extends Actor {
const post = this.getPost(postId);
post.setStatus('Validated');
const rewards = await this.propagateValue(pool, post, initialValue);
const totalRewards = Array.from(rewards.values()).reduce((total, value) => total += value, 0);
console.log('total awards from forum:', totalRewards);
// Apply computed rewards
for (const [id, value] of rewards) {
bench.reputations.addTokens(id, value);
@ -114,7 +112,7 @@ export class Forum extends Actor {
await this.setPostValue(post, post.value + adjustedIncrement);
// Award reputation to post author
console.log('reward for post author', post.authorPublicKey, adjustedIncrement);
console.log(`reward for post author ${post.authorPublicKey}`, adjustedIncrement);
addReward(post.authorPublicKey, adjustedIncrement);
// Recursively distribute reputation to citations, according to weights

View File

@ -230,14 +230,19 @@ export class ValidationPool extends Actor {
const { reputationPublicKey } = this.voters.get(signingPublicKey);
const reward = (tokensForWinners * stake) / getTotalStaked(votePasses);
rewards.set(reputationPublicKey, reward);
console.log(`reward for winning voter ${reputationPublicKey}:`, reward);
}
const awardsFromVoting = Array.from(rewards.values()).reduce((total, value) => total += value, 0);
console.log('total awards from voting:', awardsFromVoting);
const authorReputationPublicKey = this.voters.get(this.authorSigningPublicKey).reputationPublicKey;
// Distribute awards to voters other than the author
for (const [id, value] of rewards) {
if (id !== authorReputationPublicKey) {
this.bench.reputations.addTokens(id, value);
console.log(`reward for winning voter ${id}:`, value);
}
}
if (votePasses) {
const authorReputationPublicKey = this.voters.get(this.authorSigningPublicKey).reputationPublicKey;
// Distribute awards to author via the forum
const tokensForAuthor = this.tokensMinted * params.stakeForAuthor + rewards.get(authorReputationPublicKey);
if (votePasses && !!this.forum) {