Skip to content
Open
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
52 changes: 52 additions & 0 deletions projects/brain-fun/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const FACTORIES = [
"0xBa270A620cafAA69a97AbcC4d83C850297ca05B2", // V1 — legacy factory
"0x3EDFEdaFa3dAd70a3F72EdB8be8e818d1922E04c", // V2 — current factory
];

async function tvl(api) {
// Get token count from each factory in parallel
const tokenCounts = await api.multiCall({
abi: "function getTokenCount() view returns (uint256)",
calls: FACTORIES,
});

// Build (factory, tokenId) call list across all factories
const tokenIdCalls = [];
FACTORIES.forEach((factory, i) => {
const count = Number(tokenCounts[i]);
for (let id = 1; id <= count; id++) {
tokenIdCalls.push({ target: factory, params: [id] });
}
});

if (tokenIdCalls.length === 0) return;

// Resolve every token address from every factory in one batch
const tokenAddresses = await api.multiCall({
abi: "function getToken(uint256) view returns (address)",
calls: tokenIdCalls,
});

// Read realTaoReserve from each token (native TAO locked in bonding curves).
// permitFailure lets us degrade gracefully if a single token read reverts or
// a node misbehaves, instead of failing the whole TVL computation.
const reserves = await api.multiCall({
abi: "function realTaoReserve() view returns (uint256)",
calls: tokenAddresses,
permitFailure: true,
});

// Sum all successful reserves as native gas token (TAO); skip failed reads.
reserves.forEach((reserve) => {
if (reserve != null) api.addGasToken(reserve);
});
}

module.exports = {
methodology:
"TVL is the sum of realTaoReserve (native TAO locked in the bonding curve) across all tokens deployed by the brain.fun factory contracts (V1 + V2).",
start: 1774915200, // 2026-03-31 — first token deploy
bittensor_evm: {
tvl,
},
};