Skip to content

Commit 60e9cdd

Browse files
authored
feat: add lockup-based TVL (DefiLlama#15189)
1 parent 448297b commit 60e9cdd

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

projects/xphere/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const CHAIN = 'xp';
2+
const LOCKUP = '0x43A15af1D18B8159bA06df4ec66190451e1f4D70';
3+
const NATIVE_ADDR = '0x8c290B96768210Dc1Ab64970Ff62F0F97be00431';
4+
const BATCH_SIZE = 100;
5+
6+
const ABI = {
7+
getLockedAccountsCount: 'uint256:getLockedAccountsCount',
8+
getLockedAccounts: 'function getLockedAccounts(uint256 offset, uint256 limit) view returns (address[])',
9+
};
10+
11+
async function tvl(_ts, _eb, _cb, { api }) {
12+
const total = Number(await api.call({
13+
target: LOCKUP,
14+
abi: ABI.getLockedAccountsCount,
15+
}));
16+
17+
const owners = [];
18+
for (let i = 0; i < total; i += BATCH_SIZE) {
19+
const batch = await api.call({
20+
target: LOCKUP,
21+
abi: ABI.getLockedAccounts,
22+
params: [i, BATCH_SIZE],
23+
});
24+
owners.push(...batch);
25+
}
26+
27+
let sum = 0n;
28+
for (const addr of owners) {
29+
const balance = await api.provider.getBalance(addr);
30+
console.log(`Address: ${addr}, Balance: ${balance}`);
31+
sum += BigInt(balance.toString());
32+
}
33+
34+
return {
35+
[`${CHAIN}:${NATIVE_ADDR}`]: sum.toString()
36+
};
37+
}
38+
39+
module.exports = {
40+
timetravel: true,
41+
start: 1744859889,
42+
methodology: `
43+
1. Retrieve all locked user addresses by calling getLockedAccountsCount and getLockedAccounts from the Lockup contract.
44+
2. For each address, fetch the current XP balance using api.provider.getBalance, which reflects both the locked amount and accrued rewards.
45+
3. Sum all balances to calculate the total value of native XP held across the locked accounts, and return this as the protocol’s TVL.
46+
`,
47+
[CHAIN]: { tvl },
48+
};

0 commit comments

Comments
 (0)