Skip to content
Merged
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
5 changes: 4 additions & 1 deletion adapters/balance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ let res: number;
export async function latest(
adapter: string,
timestampDeployed: number,
backfill: boolean = false
): Promise<number> {
if (backfill) return timestampDeployed
if (!res) {
let r;
try {
Expand All @@ -37,12 +39,13 @@ export async function balance(
chain: any,
adapter: string,
timestampDeployed: number,
backfill: boolean = false
): Promise<CliffAdapterResult[]> {
let trackedTimestamp: number;
let decimals: number;

[trackedTimestamp, decimals] = await Promise.all([
latest(adapter, timestampDeployed),
latest(adapter, timestampDeployed, backfill),
target == GAS_TOKEN
? 18
: call({
Expand Down
15 changes: 9 additions & 6 deletions protocols/across.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ const across: Protocol = {
Airdrop: manualCliff(start, qty * 0.125),
"Strategic Partnerships": [
manualCliff("2025-06-30", qty * 0.1),
() =>
(backfill: boolean) =>
balance(
["0x8180D59b7175d4064bDFA8138A58e9baBFFdA44a"],
"0x44108f0223A3C3028F5Fe7AEC7f9bb2E66beF82F",
"ethereum",
"across",
1669939200,
backfill
),
],
"DAO Treasury": () =>
"DAO Treasury": (backfill: boolean) =>
balance(
["0xB524735356985D2f267FA010D681f061DfF03715"],
"0x44108f0223A3C3028F5Fe7AEC7f9bb2E66beF82F",
"ethereum",
"across",
1669642200,
backfill
),
"Protocol Rewards": () =>
"Protocol Rewards": (backfill: boolean) =>
balance(
["0x9040e41eF5E8b281535a96D9a48aCb8cfaBD9a48"],
"0x44108f0223A3C3028F5Fe7AEC7f9bb2E66beF82F",
"ethereum",
"across",
1669642200,
backfill
),
meta: {
notes: [
Expand All @@ -46,17 +49,17 @@ const across: Protocol = {
total: qty,
incompleteSections: [
{
lastRecord: () => latest("across", 1669642200),
lastRecord: (backfill: boolean) => latest("across", 1669642200, backfill),
key: "DAO Treasury",
allocation: qty * 0.525,
},
{
lastRecord: () => latest("across", 1669642200),
lastRecord: (backfill: boolean) => latest("across", 1669642200, backfill),
key: "Protocol Rewards",
allocation: qty * 0.1,
},
{
lastRecord: () => latest("across", 1669939200),
lastRecord: (backfill: boolean) => latest("across", 1669939200, backfill),
key: "Strategic Partnerships",
allocation: qty * 0.25,
},
Expand Down
28 changes: 16 additions & 12 deletions utils/convertToChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function createChartData(
endTime: number;
},
replaces: string[],
backfill: boolean = false
): Promise<{ realTimeData: ChartSection[]; documentedData: ChartSection[] }> {
const realTimeData = await iterateThroughSections(data.rawSections);
let documentedData = await iterateThroughSections(data.documented);
Expand Down Expand Up @@ -87,7 +88,7 @@ export async function createChartData(

nullFinder(chartData, "preappend");
// nulls come from the following function
await appendMissingDataSections(chartData, protocol, data);
await appendMissingDataSections(chartData, protocol, data, backfill);
const consolidated = consolidateDuplicateKeys(chartData);
return consolidated;
}
Expand All @@ -107,22 +108,25 @@ async function appendMissingDataSections(
startTime: number;
endTime: number;
},
backfill: boolean
) {
const incompleteSections = data.metadata.incompleteSections;
if (incompleteSections == null || incompleteSections.length == 0) return;

let res: any = [];
try {
res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) =>
r.json(),
);
} catch {}
let body = res.body ? JSON.parse(res.body) : [];
res =
body && body.documentedData?.data.length
? body.documentedData?.data ?? body.data
: [];

if (!backfill) {
try {
res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) =>
r.json(),
);
} catch {}
let body = res.body ? JSON.parse(res.body) : [];
res =
body && body.documentedData?.data.length
? body.documentedData?.data ?? body.data
: [];
}

if (nullsInApiData(res)) {
await sendMessage(
`${protocol} has nulls in API res`,
Expand Down
7 changes: 4 additions & 3 deletions utils/convertToRawData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const excludedKeys = ["meta", "categories", "documented"];

export async function createRawSections(
adapter: Protocol,
backfill: boolean = false
): Promise<SectionData> {
let startTime: number = 10000000000;
let endTime: number = 0;
Expand All @@ -36,7 +37,7 @@ export async function createRawSections(
await Promise.all(
Object.entries(a[1].incompleteSections).map(async (c: any) => {
a[1].incompleteSections[c[0]].lastRecord =
await a[1].incompleteSections[c[0]].lastRecord();
await a[1].incompleteSections[c[0]].lastRecord(backfill);
}),
);
}
Expand All @@ -59,12 +60,12 @@ export async function createRawSections(
async function sectionToRaw(key: RawSection[], entry: any[]) {
const section: string = entry[0];
if (typeof entry[1] === "function") {
entry[1] = entry[1]();
entry[1] = entry[1](backfill);
}
let adapterResults = await entry[1];
if (adapterResults.length == null) adapterResults = [adapterResults];
adapterResults = adapterResults.map((r: any) =>
typeof r === "function" ? r().then() : r,
typeof r === "function" ? r(backfill).then() : r,
);
adapterResults = await Promise.all(adapterResults);

Expand Down
Loading