Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: ens provider #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions dist/score/ens-dao-score.provider.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { DefaultDaoScoreProvider } from "./default-dao-score.provider";
import { DelegateStat } from "./interfaces";
export declare class EnsDaoScoreProvider extends DefaultDaoScoreProvider {
import { BaseProvider, DelegateStat, DelegateStatPeriod, GetDaoScore, ScoreBreakdownCalc, ScoreMultiplier } from "./interfaces";
export declare class EnsDaoScoreProvider extends BaseProvider implements GetDaoScore {
private readonly resourceName?;
weights: ScoreMultiplier;
constructor(resourceName?: string);
preload(resourceName?: string): Promise<void>;
getForumScore(stat: Partial<DelegateStat>): number;
getKarmaScore(stat: Partial<DelegateStat>, median: number): number;
getKarmaScoreProps(): (keyof Partial<DelegateStat> | "median")[];
getScoreBreakdownCalc(stat: Partial<DelegateStat>, period?: DelegateStatPeriod, type?: "forum" | "score"): ScoreBreakdownCalc;
}
111 changes: 107 additions & 4 deletions dist/score/ens-dao-score.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnsDaoScoreProvider = void 0;
const get_weights_1 = require("../util/get-weights");
const default_dao_score_provider_1 = require("./default-dao-score.provider");
class EnsDaoScoreProvider extends default_dao_score_provider_1.DefaultDaoScoreProvider {
const interfaces_1 = require("./interfaces");
class EnsDaoScoreProvider extends interfaces_1.BaseProvider {
constructor(resourceName) {
super(resourceName);
this.resourceName = resourceName;
}
async preload(resourceName) {
this.weights = await (0, get_weights_1.getWeights)(resourceName || this.resourceName || "ens");
}
getForumScore(stat) {
const { forumScore: { lifetime = {} }, } = this.weights;
const totalWeight = (0, get_weights_1.getTotalWeight)(lifetime);
return Math.round((((0, get_weights_1.coalesce)(stat.proposalsInitiatedPercentile, 0) *
return Math.round((((0, get_weights_1.coalesce)(stat.proposalsInitiated, 0) *
(0, get_weights_1.coalesce)(lifetime.proposalsInitiated, 1) +
(0, get_weights_1.coalesce)(stat.proposalsDiscussed, 0) *
(0, get_weights_1.coalesce)(lifetime.proposalsDiscussed, 1) +
Expand Down Expand Up @@ -38,11 +45,107 @@ class EnsDaoScoreProvider extends default_dao_score_provider_1.DefaultDaoScorePr
}
getKarmaScoreProps() {
return [
"forumActivityScore",
"offChainVotesPct",
"onChainVotesPct",
"delegatedVotes",
"discordMessagesCount",
];
}
getScoreBreakdownCalc(stat, period, type = "score") {
const { score: { lifetime: score }, forumScore: { lifetime: forum }, } = this.weights;
if (type == "forum")
return [
{
label: "Max Score Setting",
value: 100,
weight: 1,
childrenOp: "*",
children: [
{
label: "Proposals Initiated",
value: (0, get_weights_1.coalesce)(stat.proposalsInitiated),
weight: (0, get_weights_1.coalesce)(forum.proposalsInitiated, 1),
op: "*",
},
{
label: "Proposals Discussed",
value: (0, get_weights_1.coalesce)(stat.proposalsDiscussed),
weight: (0, get_weights_1.coalesce)(forum.proposalsDiscussed, 1),
op: "+",
},
{
label: "Forum Post Count",
value: (0, get_weights_1.coalesce)(stat.forumPostCount),
weight: (0, get_weights_1.coalesce)(forum.forumPostCount, 1),
op: "+",
},
{
label: "Forum Topic Count ",
value: (0, get_weights_1.coalesce)(stat.forumTopicCount),
weight: (0, get_weights_1.coalesce)(forum.forumTopicCount, 1),
op: "+",
},
{
label: "Forum Likes Received",
value: (0, get_weights_1.coalesce)(stat.forumLikesReceived),
weight: (0, get_weights_1.coalesce)(forum.forumLikesReceived, 1),
op: "+",
},
{
label: "Forum Posts Read Count",
value: (0, get_weights_1.coalesce)(stat.forumPostsReadCount),
weight: (0, get_weights_1.coalesce)(forum.forumPostsReadCount, 1),
op: "+",
},
],
},
{
label: "Sum of Weights times Max Score Setting",
value: (0, get_weights_1.getTotalWeight)(forum),
weight: 1,
op: "/",
},
];
return [
{
label: "Max Score Setting",
value: 100,
weight: 1,
childrenOp: "*",
children: [
{
label: "Forum Activity Score",
value: (0, get_weights_1.coalesce)(stat.forumActivityScore),
weight: (0, get_weights_1.coalesce)(score.forumActivityScore, 1),
op: "*",
},
{
label: "Off-chain Votes %",
value: (0, get_weights_1.coalesce)(stat.offChainVotesPct),
weight: (0, get_weights_1.coalesce)(score.offChainVotesPct, 1),
op: "+",
},
{
label: "On-chain Votes %",
value: (0, get_weights_1.coalesce)(stat.onChainVotesPct),
weight: (0, get_weights_1.coalesce)(score.onChainVotesPct, 1),
op: "+",
},
{
label: "Discord Messages %",
value: (0, get_weights_1.coalesce)(stat.discordMessagesCount),
weight: (0, get_weights_1.coalesce)(score.discordMessagesCount, 1),
op: "+",
},
],
},
{
label: "Sum of Weights times Max Score Setting",
value: (0, get_weights_1.getTotalWeight)(score),
weight: 1,
op: "/",
},
];
}
}
exports.EnsDaoScoreProvider = EnsDaoScoreProvider;
135 changes: 131 additions & 4 deletions src/score/ens-dao-score.provider.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import { coalesce, getTotalWeight } from "../util/get-weights";
import { coalesce, getTotalWeight, getWeights } from "../util/get-weights";
import { DefaultDaoScoreProvider } from "./default-dao-score.provider";
import {
BaseProvider,
DelegateStat,
DelegateStatPeriod,
GetDaoScore,
ScoreBreakdownCalc,
ScoreMultiplier,
} from "./interfaces";

export class EnsDaoScoreProvider extends DefaultDaoScoreProvider {
export class EnsDaoScoreProvider extends
BaseProvider
implements GetDaoScore
{

weights: ScoreMultiplier;


constructor(private readonly resourceName?: string) {
super(resourceName);
}


async preload(resourceName?: string): Promise<void> {
this.weights = await getWeights(
resourceName || this.resourceName || "ens"
);
}

getForumScore(stat: Partial<DelegateStat>): number {
const {
forumScore: { lifetime = {} },
} = this.weights;
const totalWeight = getTotalWeight(lifetime);
return Math.round(
((coalesce(stat.proposalsInitiatedPercentile, 0) *
((coalesce(stat.proposalsInitiated, 0) *
coalesce(lifetime.proposalsInitiated, 1) +
coalesce(stat.proposalsDiscussed, 0) *
coalesce(lifetime.proposalsDiscussed, 1) +
Expand Down Expand Up @@ -51,10 +72,116 @@ export class EnsDaoScoreProvider extends DefaultDaoScoreProvider {

getKarmaScoreProps(): (keyof Partial<DelegateStat> | "median")[] {
return [
"forumActivityScore",
"offChainVotesPct",
"onChainVotesPct",
"delegatedVotes",
"discordMessagesCount",
];
}

getScoreBreakdownCalc(
stat: Partial<DelegateStat>,
period?: DelegateStatPeriod,
type: "forum" | "score" = "score"
): ScoreBreakdownCalc {
const {
score: { lifetime: score },
forumScore: { lifetime: forum },
} = this.weights;

if (type == "forum")
return [
{
label: "Max Score Setting",
value: 100,
weight: 1,
childrenOp: "*",
children: [
{
label: "Proposals Initiated",
value: coalesce(stat.proposalsInitiated),
weight: coalesce(forum.proposalsInitiated, 1),
op: "*",
},
{
label: "Proposals Discussed",
value: coalesce(stat.proposalsDiscussed),
weight: coalesce(forum.proposalsDiscussed, 1),
op: "+",
},
{
label: "Forum Post Count",
value: coalesce(stat.forumPostCount),
weight: coalesce(forum.forumPostCount, 1),
op: "+",
},
{
label: "Forum Topic Count ",
value: coalesce(stat.forumTopicCount),
weight: coalesce(forum.forumTopicCount, 1),
op: "+",
},
{
label: "Forum Likes Received",
value: coalesce(stat.forumLikesReceived),
weight: coalesce(forum.forumLikesReceived, 1),
op: "+",
},
{
label: "Forum Posts Read Count",
value: coalesce(stat.forumPostsReadCount),
weight: coalesce(forum.forumPostsReadCount, 1),
op: "+",
},
],
},
{
label: "Sum of Weights times Max Score Setting",
value: getTotalWeight(forum),
weight: 1,
op: "/",
},
];

return [
{
label: "Max Score Setting",
value: 100,
weight: 1,
childrenOp: "*",
children: [
{
label: "Forum Activity Score",
value: coalesce(stat.forumActivityScore),
weight: coalesce(score.forumActivityScore, 1),
op: "*",
},
{
label: "Off-chain Votes %",
value: coalesce(stat.offChainVotesPct),
weight: coalesce(score.offChainVotesPct, 1),
op: "+",
},
{
label: "On-chain Votes %",
value: coalesce(stat.onChainVotesPct),
weight: coalesce(score.onChainVotesPct, 1),
op: "+",
},
{
label: "Discord Messages %",
value: coalesce(stat.discordMessagesCount),
weight: coalesce(score.discordMessagesCount, 1),
op: "+",
},
],
},
{
label: "Sum of Weights times Max Score Setting",
value: getTotalWeight(score),
weight: 1,
op: "/",
},
];
}
}