DeFi Llama
Search…
Speedrun
Just a bunch of adapter examples so you can try to speedrun by pattern-matching
The adapter is just a function that takes a timestamp and block-height (on Ethereum) and returns the balances of tokens locked in your protocol's smart contracts at that point in time:

TrueFi

Code
ABI
Calls
CLI
projects/truefi/index.js
1
const sdk = require('@defillama/sdk');
2
const abi = require('./abi.json');
3
4
const POOL = '0xa1e72267084192db7387c8cc1328fade470e4149';
5
const stkTRU = '0x23696914Ca9737466D8553a2d619948f548Ee424';
6
const TRU = '0x4C19596f5aAfF459fA38B0f7eD92F11AE6543784';
7
const TUSD = '0x0000000000085d4780B73119b644AE5ecd22b376';
8
9
10
async function tvl(timestamp, block) {
11
let balances = {};
12
13
const poolTVL = await sdk.api.abi.call({
14
target: POOL,
15
abi: abi['poolValue'],
16
block: block
17
});
18
const truTVL = await sdk.api.abi.call({
19
target: stkTRU,
20
abi: abi['stakeSupply'],
21
block: block
22
});
23
24
balances[TUSD] = poolTVL.output;
25
balances[TRU] = truTVL.output;
26
27
return balances;
28
}
29
30
module.exports = {
31
ethereum:{
32
tvl,
33
},
34
tvl
35
}
Copied!
projects/truefi/index.js
1
{
2
"poolValue": {
3
"inputs": [],
4
"name": "poolValue",
5
"outputs": [
6
{
7
"internalType": "uint256",
8
"name": "",
9
"type": "uint256"
10
}
11
],
12
"stateMutability": "view",
13
"type": "function"
14
},
15
"stakeSupply": {
16
"inputs": [],
17
"name": "stakeSupply",
18
"outputs": [
19
{
20
"internalType": "uint256",
21
"name": "",
22
"type": "uint256"
23
}
24
],
25
"stateMutability": "view",
26
"type": "function"
27
}
28
}
Copied!
1
Input 1: (1616784572, 12116367)
2
3
Output 1:
4
{
5
'0x0000000000085d4780B73119b644AE5ecd22b376': '63673889181720756238069312',
6
'0x4C19596f5aAfF459fA38B0f7eD92F11AE6543784': '6631227042218918'
7
}
8
9
Input 2: (1615453837, 12016392)
10
11
Output 2:
12
{
13
'0x0000000000085d4780B73119b644AE5ecd22b376': '46862724247312775912594739',
14
'0x4C19596f5aAfF459fA38B0f7eD92F11AE6543784': '5726346484318134'
15
}
16
17
Input 3: (1614123633, 11916399)
18
19
Output 3:
20
{
21
'0x0000000000085d4780B73119b644AE5ecd22b376': '50438152493838773769557145',
22
'0x4C19596f5aAfF459fA38B0f7eD92F11AE6543784': '3848190457433238'
23
}
24
25
Input 4: (1603507428, 11116398)
26
27
Output 4:
28
{} // Contracts didn't exist
Copied!
1
$ npx @defillama/sdk projects/truefi/index.js
2
3
TUSD 63.59 M
4
TRU 26.03 M
5
Total: 89.62 M
Copied!

Pool Together

Code
ABI
Calls
CLI
projects/pooltogether/index.js
1
const sdk = require("@defillama/sdk");
2
const { request, gql } = require("graphql-request");
3
const abi = require('./abi.json')
4
5
const graphUrls = [
6
'https://api.thegraph.com/subgraphs/name/pooltogether/pooltogether-v3_1_0',
7
'https://api.thegraph.com/subgraphs/name/pooltogether/pooltogether-v3_3_2'
8
]
9
const graphQuery = gql`
10
query GET_POOLS($block: Int) {
11
prizePools(
12
block: { number: $block }
13
) {
14
id
15
underlyingCollateralSymbol
16
underlyingCollateralToken
17
compoundPrizePool{
18
cToken
19
}
20
}
21
}
22
`;
23
24
async function tvl(timestamp, block) {
25
let balances = {};
26
27
let allPrizePools = []
28
for (const graphUrl of graphUrls) {
29
const { prizePools } = await request(
30
graphUrl,
31
graphQuery,
32
{
33
block,
34
}
35
);
36
allPrizePools = allPrizePools.concat(prizePools)
37
}
38
const lockedTokens = await sdk.api.abi.multiCall({
39
abi: abi['accountedBalance'],
40
calls: allPrizePools.map(pool => ({
41
target: pool.id
42
})),
43
block
44
})
45
lockedTokens.output.forEach(call => {
46
const underlyingToken =
47
allPrizePools.find(pool => pool.id === call.input.target)
48
.underlyingCollateralToken;
49
const underlyingTokenBalance = call.output
50
sdk.util.sumSingleBalance(balances, underlyingToken, underlyingTokenBalance)
51
})
52
return balances
53
}
54
55
56
module.exports = {
57
ethereum:{
58
tvl,
59
},
60
tvl
61
}
Copied!
projects/pooltogether/abi.json
1
{
2
"accountedBalance": {
3
"inputs": [],
4
"name": "accountedBalance",
5
"outputs": [
6
{
7
"internalType": "uint256",
8
"name": "",
9
"type": "uint256"
10
}
11
],
12
"stateMutability": "view",
13
"type": "function"
14
}
15
}
Copied!
1
Input 1: (1616785431, 12116436)
2
3
Output 1:
4
{
5
'0x0d8775f648430679a709e98d2b0cb6250d2887ef': '106905291853415622153',
6
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': '550930210187159868576758',
7
'0x6b175474e89094c44da98b954eedeac495271d0f': '49090672849737076366112325',
8
'0xdac17f958d2ee523a2206206994597c13d831ec7': '0',
9
'0x0cb42d5c9c4661fee5d2ecfcbad5bccefa0727a9': '2571305570268888809939',
10
'0x3449fc1cd036255ba1eb19d65ff4ba2b8903a69a': '948456261968725066468',
11
'0x58014f7eef95bcaaf84b8f4aa07507e1664e40b2': '1000000000000000000',
12
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': '0',
13
'0x6b3595068778dd592e39a122f4f5a5cf09c90fe2': '9784581049508251225',
14
'0xd2dda223b2617cb616c1580db421e4cfae6a8a85': '141130243431856096745605',
15
'0x56687cf29ac9751ce2a4e764680b6ad7e668942e': '0',
16
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '56990267448502',
17
'0x57bc752ec42238bb60a6e65b0de82ef44013225d': '722305738252165754257',
18
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': '10684189',
19
'0xa323fc62c71b210e54171887445d7fca569d8430': '64131624673594797066',
20
'0x334cbb5858417aee161b53ee0d5349ccf54514cf': '0',
21
'0xe41d2489571d322189246dafa5ebde1f4699f498': '144912629676243436495284',
22
'0x57ab1ec28d129707052df4df418d58a2d46d5f51': '0',
23
'0x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b': '1911234433441576710220',
24
'0x0000000000095413afc295d19edeb1ad7b71c952': '5382329275853684605192',
25
'0xc00e94cb662c3520282e6f5717214004a7f26888': '15415779749925621232272',
26
'0x0391d2021f89dc339f60fff84546ea23e337750f': '14324003410385851045633',
27
'0x03ab458634910aad20ef5f1c8ee96f1d6ac54919': '2195597081860488093659',
28
'0xb0dfd28d3cf7a5897c694904ace292539242f858': '5470600000000000000000',
29
'0x3472a5a71965499acd81997a54bba8d852c6e53d': '0',
30
'0x0cec1a9154ff802e7934fc916ed7ca50bde6844e': '335400609558747166862488',
31
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': '18033361926134999892'
32
}
33
34
Input 2: (1614124163, 11916434)
35
36
Output 2:
37
{
38
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': '607534430161781994697635',
39
'0x6b175474e89094c44da98b954eedeac495271d0f': '33933834806526125987455748',
40
'0x3449fc1cd036255ba1eb19d65ff4ba2b8903a69a': '948456261968725066468',
41
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': '0',
42
'0x6b3595068778dd592e39a122f4f5a5cf09c90fe2': '0',
43
'0x56687cf29ac9751ce2a4e764680b6ad7e668942e': '0',
44
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '36389198274305',
45
'0x57bc752ec42238bb60a6e65b0de82ef44013225d': '74305738252165754257',
46
'0x334cbb5858417aee161b53ee0d5349ccf54514cf': '0',
47
'0x57ab1ec28d129707052df4df418d58a2d46d5f51': '0',
48
'0x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b': '0',
49
'0xc00e94cb662c3520282e6f5717214004a7f26888': '13347137704383655139121',
50
'0x0391d2021f89dc339f60fff84546ea23e337750f': '6571262578549837484949',
51
'0x03ab458634910aad20ef5f1c8ee96f1d6ac54919': '70426514325056410426985',
52
'0xb0dfd28d3cf7a5897c694904ace292539242f858': '8546600000000000000000'
53
}
Copied!
1
$ npx @defillama/sdk projects/pooltogether/index.js
2
3
Couldn't find the price of token at 0x0cb42d5c9c4661fee5d2ecfcbad5bccefa0727a9, assuming a price of 0 for it...
4
Couldn't find the price of token at 0x58014f7eef95bcaaf84b8f4aa07507e1664e40b2, assuming a price of 0 for it...
5
Couldn't find the price of token at 0x57bc752ec42238bb60a6e65b0de82ef44013225d, assuming a price of 0 for it...
6
Couldn't find the price of token at 0xa323fc62c71b210e54171887445d7fca569d8430, assuming a price of 0 for it...
7
Couldn't find the price of token at 0x334cbb5858417aee161b53ee0d5349ccf54514cf, assuming a price of 0 for it...
8
BAT 113.31960936462058
9
UNI 15.65 M
10
DAI 49.09 M
11
USDT 0
12
EM3 0
13
BAC 275.1357801219835
14
IDT 0
15
AAVE 0
16
SUSHI 161.93481636936156
17
BONDLY 66.85 k
18
JAMM 0
19
USDC 56.98 M
20
ARTO 0
21
WBTC 5.73 k
22
UNI-V2 0
23
PcDAI 0
24
ZRX 198.53 k
25
sUSD 0
26
DPI 751.94 k
27
LON 36.01 k
28
COMP 5.76 M
29
BOND 745.42 k
30
RAI 6.52 k
31
LOTTO 1.20 k
32
BADGER 0
33
POOL 8.69 M
34
WETH 29.87 k
35
Total: 138.01 M
Copied!

Alpha Homora (BSC)

Code
Calls
CLI
projects/alpha-homora/index.js
1
const sdk = require("@defillama/sdk");
2
const BigNumber = require("bignumber.js");
3
const { request, gql } = require("graphql-request");
4
const { unwrapUniswapLPs } = require("../helper/unwrapLPs")
5
6
const GET_GOBLIN_SUMMARIES = gql`
7
query GET_GOBLIN_SUMMARIES($block: Int) {
8
goblinSummaries(block: { number: $block }) {
9
id
10
totalLPToken
11
}
12
}
13
`;
14
const wBNB = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
15
16
function getBSCAddress(address) {
17
return `bsc:${address}`
18
}
19
20
async function tvl(timestamp, blockETH, chainBlocks) {
21
const block = chainBlocks["bsc"];
22
const balances = {}
23
const {
24
goblinSummaries
25
} = await request('https://api.thegraph.com/subgraphs/name/hermioneeth/alpha-homora-bank-bsc', GET_GOBLIN_SUMMARIES, {
26
block,
27
});
28
const lpTokens = (await sdk.api.abi.multiCall({
29
block,
30
abi: { "constant": true, "inputs": [], "name": "lpToken", "outputs": [{ "internalType": "contract IUniswapV2Pair", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" },
31
calls: goblinSummaries.map(goblin => ({
32
target: goblin.id
33
})),
34
chain: 'bsc'
35
})).output
36
await unwrapUniswapLPs(balances, goblinSummaries.map(goblin => {
37
const lpToken = lpTokens.find(call => call.input.target === goblin.id).output;
38
return {
39
token: lpToken,
40
balance: goblin.totalLPToken
41
}
42
}),
43
block,
44
'bsc',
45
(addr) => `bsc:${addr}`)
46
const unusedBNB = await sdk.api.eth.getBalance({
47
target: '0x3bB5f6285c312fc7E1877244103036ebBEda193d',
48
block,
49
chain: 'bsc'
50
})
51
balances[getBSCAddress(wBNB)] = BigNumber(balances[getBSCAddress(wBNB)] || 0).plus(BigNumber(unusedBNB.output)).toFixed(0)
52
return balances
53
}
54
55
module.exports = {
56
bsc:{
57
tvl,
58
},
59
tvl,
60
};
61
Copied!
1
Input 1: (1616785946, 12116483)
2
3
Output 1:
4
{
5
'bsc:0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c': '558286715809884029214427',
6
'bsc:0xF8A0BF9cF54Bb92F17374d9e9A321E6a111a51bD': '6541688163793370635285',
7
'bsc:0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56': '19291091455439572439988346',
8
'bsc:0x2170Ed0880ac9A755fd29B2688956BD959F933F8': '12368452624118152630273',
9
'bsc:0x88f1A5ae2A3BF98AEAF342D26B30a79438c9142e': '414899373065096234',
10
'bsc:0x55d398326f99059fF775485246999027B3197955': '21036251365092442220343193',
11
'bsc:0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c': '776608041991790197333',
12
'bsc:0xa1faa113cbE53436Df28FF0aEe54275c13B40975': '4144144112086134531012116',
13
'bsc:0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82': '867542163078831908999094',
14
'bsc:0xAD6cAEb32CD2c308980a548bD0Bc5AA4306c6c18': '152970232357957589510610',
15
'bsc:0xBf5140A22578168FD562DCcF235E5D43A02ce9B1': '8361293755666516877876'
16
}
Copied!
1
$ npx @defillama/sdk projects/alpha-homora/index.js
2
3
Couldn't find the price of token at bsc:0x88f1A5ae2A3BF98AEAF342D26B30a79438c9142e, assuming a price of 0 for it...
4
Couldn't find the price of token at bsc:0xAD6cAEb32CD2c308980a548bD0Bc5AA4306c6c18, assuming a price of 0 for it...
5
WBNB 139.28 M
6
LINK 175.78 k
7
BUSD 19.28 M
8
ETH 20.50 M
9
YFI 0
10
USDT 21.04 M
11
BTCB 41.56 M
12
ALPHA 7.87 M
13
Cake 12.48 M
14
BAND 0
15
UNI 236.37 k
16
Total: 262.42 M
17
Copied!

WBTC

Code
Calls
CLI
projects/wbtc/index.js
1
const sdk = require('@defillama/sdk');
2
const wbtcContract = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
3
4
async function tvl(timestamp, block) {
5
const totalSupply = (await sdk.api.erc20.totalSupply({
6
block,
7
target: wbtcContract,
8
})).output;
9
10
return { [wbtcContract]: totalSupply };
11
}
12
13
module.exports = {
14
ethereum:{
15
tvl,
16
},
17
tvl,
18
};
Copied!
1
Input 1: (1616786616, 12116526)
2
3
Output 1:
4
{
5
'0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599': '13790365865712'
6
}
Copied!
1
$ npx @defillama/sdk projects/wbtc/index.js
2
3
WBTC 7.41 B
4
Total: 7.41 B
Copied!
Last modified 6mo ago
Copy link