Skip to content

Commit 17ace52

Browse files
authored
Merge pull request #107 from ReynardoEW/fix_events
fix events generation
2 parents cdecaf3 + f005eae commit 17ace52

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

protocols/trump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Protocol } from "../types/adapters";
22
import { manualCliff, manualStep } from "../adapters/manual";
33
import { periodToSeconds } from "../utils/time";
44

5-
const start = 1705536000; // January 18, 2025
5+
const start = 1737133200; // January 18, 2025
66

77
const trump: Protocol = {
88
"Public Distribution": [

utils/events.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,42 @@ export function addResultToEvents(
3131
});
3232

3333
linears.map((l: LinearAdapterResult, i: number) => {
34-
if (i == linears.length) return;
35-
const l2 = linears[i];
36-
const thisRate = i == 0 ? 0 : ratePerPeriod(l, precision);
37-
const nextRate = ratePerPeriod(l2, precision);
38-
if (Math.abs(Number(thisRate) - Number(nextRate)) / thisRate < 0.001)
39-
return;
40-
if (!metadata.events) metadata.events = [];
41-
metadata.events.push({
42-
description: `Linear unlock ${isFuture(l.start) ? "will" : "was"} ${
43-
Number(thisRate) > Number(nextRate) ? "decrease" : "increase"
44-
}${
45-
isFuture(l.start) ? "" : "d"
46-
} from {tokens[0]} to {tokens[1]} tokens per week from ${section} on {timestamp}`,
47-
timestamp: l.start,
48-
noOfTokens: [thisRate, nextRate],
49-
});
34+
// compare current with the next one if it exists
35+
if (i < linears.length - 1) {
36+
const l2 = linears[i + 1];
37+
const thisRate = ratePerPeriod(l, precision);
38+
const nextRate = ratePerPeriod(l2, precision);
39+
40+
if (Math.abs(Number(thisRate) - Number(nextRate)) / (thisRate || 1) >= 0.001) {
41+
if (!metadata.events) metadata.events = [];
42+
metadata.events.push({
43+
description: `Linear unlock ${isFuture(l2.start) ? "will" : "was"} ${
44+
Number(thisRate) > Number(nextRate) ? "decrease" : "increase"
45+
}${
46+
isFuture(l2.start) ? "" : "d"
47+
} from {tokens[0]} to {tokens[1]} tokens per week from ${section} on {timestamp}`,
48+
timestamp: l2.start,
49+
noOfTokens: [thisRate, nextRate],
50+
});
51+
}
52+
}
53+
54+
// handle first linear period to show the initial rate increase from 0
55+
if (i === 0) {
56+
const initialRate = ratePerPeriod(l, precision);
57+
if (initialRate > 0) {
58+
if (!metadata.events) metadata.events = [];
59+
metadata.events.push({
60+
description: `Linear unlock ${isFuture(l.start) ? "will" : "was"} ${
61+
0 > Number(initialRate) ? "decrease" : "increase"
62+
}${
63+
isFuture(l.start) ? "" : "d"
64+
} from {tokens[0]} to {tokens[1]} tokens per week from ${section} on {timestamp}`,
65+
timestamp: l.start,
66+
noOfTokens: [0, initialRate],
67+
});
68+
}
69+
}
5070
});
5171

5272
steps.map((s: StepAdapterResult) => {

0 commit comments

Comments
 (0)