Published
Edited
Sep 4, 2020
2 forks
Insert cell
md`# MakerDAO Ledger Inspection`
Insert cell
sc = (await require("sourcecred")).default
Insert cell
async function loadCredView(repo) {
const credResultFile = `https://raw.githubusercontent.com/${repo}/gh-pages/output/credResult.json`;
const credResultRaw = await (await fetch(credResultFile)).json()
const credResult = sc.analysis.credResult.fromJSON(credResultRaw)
const credView = new sc.analysis.credView.CredView(credResult)
return credView;
}
Insert cell
async function loadLedger(repo) {
const ledgerFile = `https://raw.githubusercontent.com/${repo}/gh-pages/data/ledger.json`;
const ledgerRaw = await (await fetch(ledgerFile)).text();
return sc.ledger.ledger.Ledger.parse(ledgerRaw);
}
Insert cell
ledger = loadLedger("sourcecred/makerdao-cred")
Insert cell
G = sc.ledger.grain
Insert cell
totalGrain = {
let totalGrain = "0"
for (const {balance} of ledger.accounts()) {
totalGrain = G.add(totalGrain, balance)
}
return totalGrain
}
Insert cell
G.format(totalGrain)
Insert cell
START_TS = +new Date("2020-08-01")
Insert cell
END_TS = +new Date("2020-09-01")
Insert cell
distributions = {
const logs = ledger.eventLog();
return logs
.filter(x => x.ledgerTimestamp < END_TS && x.ledgerTimestamp > START_TS)
.filter(x => x.action.type === "DISTRIBUTE_GRAIN");
}
Insert cell
allocations = {
const allocs = [];
for (const { action } of distributions) {
const distribution = action.distribution;
for (const alloc of distribution.allocations) {
allocs.push(alloc);
}
}
return allocs;
}
Insert cell
allocationByType = {
const byType = { SPECIAL: "0", BALANCED: 0, IMMEDIATE: 0 };
for (const { policy } of allocations) {
byType[policy.policyType] = G.add(byType[policy.policyType], policy.budget);
}
return byType;
}
Insert cell
G.format(allocationByType["SPECIAL"])
Insert cell
G.format(allocationByType["IMMEDIATE"])
Insert cell
G.format(allocationByType["BALANCED"])
Insert cell
specialAllocs = allocations.filter(x => x.policy.policyType === "SPECIAL")
Insert cell
specialAllocs.map(x => ({
name: ledger.account(x.policy.recipient).identity.name,
amt: G.format(x.policy.budget),
memo: x.policy.memo
}))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more