Skip to content

Commit ffca814

Browse files
authored
Merge branch 'DefiLlama:master' into master
2 parents f056c1a + 062e456 commit ffca814

File tree

869 files changed

+29115
-7272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

869 files changed

+29115
-7272
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build dimensionModules and upload artifact
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
jobs:
8+
build-and-upload:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- uses: pnpm/action-setup@v4
17+
name: Install pnpm
18+
with:
19+
version: 10
20+
run_install: false
21+
22+
- name: Install Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: 'pnpm'
27+
28+
- name: Install dependencies
29+
run: pnpm install
30+
31+
- name: Run buildImports script
32+
run: pnpm run build
33+
34+
- name: Publish dimensionModules.json as "latest" release
35+
uses: ncipollo/release-action@v1
36+
with:
37+
tag: latest
38+
name: Latest dimensionModules
39+
artifacts: cli/dimensionModules.json
40+
allowUpdates: true

.github/workflows/getFileList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ALLOWED_ROOTS = ['volumes', 'dexs', 'options', 'derivatives', 'incentives', 'fees', 'options', 'protocols', 'aggregators','aggregator-derivatives','bridge-aggregators']
1+
const ALLOWED_ROOTS = ['volumes', 'dexs', 'options', 'derivatives', 'incentives', 'fees', 'options', 'protocols', 'aggregators','aggregator-derivatives','bridge-aggregators', 'open-interest']
22
const MODIFIED = parse(process.env.MODIFIED)
33
const ADDED = parse(process.env.ADDED)
44
const fileSet = new Set();

.github/workflows/test-adapter.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,27 @@ jobs:
99
with:
1010
output: 'json'
1111
fileOutput: 'json'
12-
- name: Check out repository code
13-
uses: actions/checkout@v2
12+
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- uses: pnpm/action-setup@v4
19+
name: Install pnpm
20+
with:
21+
version: 10
22+
run_install: false
23+
24+
- name: Install Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: 'pnpm'
29+
30+
- name: Install dependencies
31+
run: pnpm install
32+
1433
- name: Run changes files through test script
1534
run: |
1635
# Store the current commit hash in a variable
@@ -33,8 +52,6 @@ jobs:
3352
exit 0
3453
fi
3554
36-
npm ci
37-
3855
list=$(echo $RUN_FILES | tr -d '"[]' | tr "," "\n")
3956
4057
for i in ${list}

.github/workflows/ts-check.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@ jobs:
66
ts-check:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- name: Get Node.js
11-
uses: actions/setup-node@v1
12-
with:
13-
node-version: '16'
14-
- run: npm ci
15-
- name: Checking adapters
16-
run: npm run ts-check
17-
- name: Checking cli
18-
run: npm run ts-check-cli
9+
- name: Checkout repository
10+
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- uses: pnpm/action-setup@v4
15+
name: Install pnpm
16+
with:
17+
version: 10
18+
run_install: false
19+
20+
- name: Install Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
cache: 'pnpm'
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Checking adapters
30+
run: pnpm run ts-check
31+
32+
- name: Checking cli
33+
run: pnpm run ts-check-cli

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ node_modules
55
.idea
66
yarn.lock
77
test.py
8-
test.js
8+
test.js
9+
10+
cli/dimensionModules.json

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33
Find the instructions to list, write, test and submit an adapter [here](https://docs.llama.fi/list-your-project/other-dashboards)
44

5-
Example: `yarn test fees bitcoin`
5+
## Install dependencies
6+
`pnpm i`
7+
8+
## test adapter commands
9+
10+
`pnpm test fees bitcoin`
11+
12+
`pnpm test fees bitcoin 2025-10-10`

adapters/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type FetchOptions = {
4242
dateString: string,
4343
preFetchedResults?: any,
4444
moduleUID: string, // randomly generated unique identifier for the module, useful for caching
45+
startOfDayId?: string, // id used in some subgraphs to identify daily data, usually it's the startOfDay timestamp divided by 86400
4546
}
4647

4748
export type FetchGetLogsOptions = {
@@ -91,9 +92,16 @@ export enum ProtocolType {
9192
COLLECTION = 'collection',
9293
}
9394

95+
export enum Dependencies {
96+
DUNE = 'dune',
97+
ALLIUM = 'allium'
98+
}
99+
100+
94101
export type AdapterBase = {
95102
timetravel?: boolean
96103
isExpensiveAdapter?: boolean,
104+
dependencies?: Dependencies[]
97105
protocolType?: ProtocolType;
98106
version?: number;
99107
deadFrom?: string;
@@ -192,6 +200,7 @@ export enum AdapterType {
192200
DERIVATIVES = 'derivatives',
193201
OPTIONS = 'options',
194202
PROTOCOLS = 'protocols',
203+
OPEN_INTEREST = 'open-interest',
195204
// ROYALTIES = 'royalties',
196205
AGGREGATOR_DERIVATIVES = 'aggregator-derivatives',
197206
BRIDGE_AGGREGATORS = 'bridge-aggregators',
@@ -218,3 +227,5 @@ export const accumulativeKeySet = new Set([
218227
export interface IJSON<T> {
219228
[key: string]: T
220229
}
230+
231+
export const ADAPTER_TYPES = Object.values(AdapterType).filter((adapterType: any) => adapterType !== AdapterType.PROTOCOLS)

adapters/utils/runAdapter.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export async function setModuleDefaults(module: SimpleAdapter) {
7575
}
7676

7777
type AdapterRunOptions = {
78+
deadChains?: Set<string>, // chains that are dead and should be skipped
7879
module: SimpleAdapter,
7980
endTimestamp: number,
8081
name?: string,
@@ -95,19 +96,33 @@ export default async function runAdapter(options: AdapterRunOptions) {
9596

9697
if (!adapterRunResponseCache[runKey]) adapterRunResponseCache[runKey] = _runAdapter(options)
9798
else sdk.log(`[Dimensions run] Using cached results for ${runKey}`)
98-
return adapterRunResponseCache[runKey]
99+
return adapterRunResponseCache[runKey].then((res: any) => clone(res)) // clone the object to avoid accidental mutation of the cached object
100+
101+
function clone(obj: any) {
102+
return JSON.parse(JSON.stringify(obj))
103+
}
99104
}
100105

101106
function getRunKey(options: AdapterRunOptions) {
102107
let randomUID = options.module._randomUID ?? genUID(10)
103108
return `${randomUID}-${options.endTimestamp}-${options.withMetadata}`
104109
}
105110

111+
const startOfDayIdCache: { [key: string]: string } = {}
112+
113+
function getStartOfDayId(timestamp: number): string {
114+
if (!startOfDayIdCache[timestamp]) {
115+
startOfDayIdCache[timestamp] = '' + Math.floor(timestamp / 86400)
116+
}
117+
return startOfDayIdCache[timestamp]
118+
}
119+
106120

107121
async function _runAdapter({
108122
module, endTimestamp, name,
109123
isTest = false,
110124
withMetadata = false,
125+
deadChains = new Set(),
111126
}: AdapterRunOptions) {
112127
const cleanCurrentDayTimestamp = endTimestamp
113128
const adapterVersion = module.version
@@ -160,7 +175,7 @@ async function _runAdapter({
160175
const response = await Promise.all(chains.filter(chain => {
161176
const res = validStart[chain]?.canRun
162177
if (isTest && !res) console.log(`Skipping ${chain} because the configured start time is ${new Date(validStart[chain]?.startTimestamp * 1e3).toUTCString()} \n\n`)
163-
return validStart[chain]?.canRun
178+
return validStart[chain]?.canRun && !deadChains.has(chain)
164179
}).map(getChainResult))
165180

166181
Object.entries(breakdownByToken).forEach(([chain, data]: any) => {
@@ -227,6 +242,7 @@ async function _runAdapter({
227242
// if (value === undefined || value === null) throw new Error(`Value: ${value} ${recordType} is undefined or null`)
228243
if (value instanceof Balances) {
229244
const { labelBreakdown, usdTvl, usdTokenBalances, rawTokenBalances } = await value.getUSDJSONs()
245+
// if (usdTvl > 1e6) value.debug()
230246
result[recordType] = usdTvl
231247
breakdownByToken[chain] = breakdownByToken[chain] || {}
232248
breakdownByToken[chain][recordType] = { usdTvl, usdTokenBalances, rawTokenBalances }
@@ -299,7 +315,13 @@ async function _runAdapter({
299315
const fromTimestamp = toTimestamp - ONE_DAY_IN_SECONDS
300316
const getFromBlock = async () => await getBlock(fromTimestamp, chain)
301317
const getToBlock = async () => await getBlock(toTimestamp, chain, chainBlocks)
318+
const problematicChains = new Set(['sei', 'xlayer'])
319+
302320
const getLogs = async ({ target, targets, onlyArgs = true, fromBlock, toBlock, flatten = true, eventAbi, topics, topic, cacheInCloud = false, skipCacheRead = false, entireLog = false, skipIndexer, noTarget, ...rest }: FetchGetLogsOptions) => {
321+
322+
323+
if (problematicChains.has(chain)) throw new Error(`getLogs is disabled for ${chain} chain due to frequent timeouts`)
324+
303325
fromBlock = fromBlock ?? await getFromBlock()
304326
toBlock = toBlock ?? await getToBlock()
305327

@@ -343,6 +365,7 @@ async function _runAdapter({
343365
getEndBlock,
344366
dateString: getDateString(startOfDay),
345367
moduleUID,
368+
startOfDayId: getStartOfDayId(startOfDay),
346369
}
347370
}
348371

@@ -431,7 +454,7 @@ function addMissingMetrics(chain: string, result: any) {
431454
if (result.dailyFees && result.dailyFees instanceof Balances && result.dailyFees.hasBreakdownBalances()) {
432455

433456
// if we have supplySideRevenue but missing revenue, add revenue = fees - supplySideRevenue
434-
if (result.dailySupplySideRevenue && !result.dailyrevenue) {
457+
if (result.dailySupplySideRevenue && !result.dailyRevenue) {
435458
result.dailyRevenue = createBalanceFrom({ chain, timestamp: result.timestamp, amount: result.dailyFees })
436459
subtractBalance({ balance: result.dailyRevenue, amount: result.dailySupplySideRevenue })
437460
}

aggregator-derivatives/perpie/index.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Dependencies,
23
Fetch,
34
FetchOptions,
45
FetchResult,
@@ -22,15 +23,15 @@ const chainsMap: Record<string, string> = {
2223

2324
const fetchVolumeAndFees: (chain: string) => FetchV2 =
2425
(chain: string) =>
25-
async (options: FetchOptions): Promise<FetchResult> => {
26-
chain;
26+
async (options: FetchOptions): Promise<FetchResult> => {
27+
chain;
2728

28-
const daytime = new Date(options.startOfDay * 1000).toISOString();
29+
const daytime = new Date(options.startOfDay * 1000).toISOString();
2930

30-
// throw new Error('Dune query is broken, fix it by turning adapter on chain')
31-
// https://dune.com/queries/3855069
32-
let data = (
33-
await queryDuneSql(options, `
31+
// throw new Error('Dune query is broken, fix it by turning adapter on chain')
32+
// https://dune.com/queries/3855069
33+
let data = (
34+
await queryDuneSql(options, `
3435
WITH
3536
PERPIE_TRADES_DAILY AS (
3637
SELECT
@@ -86,33 +87,35 @@ const fetchVolumeAndFees: (chain: string) => FetchV2 =
8687
total_fees
8788
`
8889
)
89-
)[0] as StatRow;
90+
)[0] as StatRow;
9091

91-
return {
92-
dailyVolume: data.volume_24hr || 0,
93-
dailyRevenue: data.fees_24hr || 0,
92+
return {
93+
dailyVolume: data.volume_24hr || 0,
94+
dailyRevenue: data.fees_24hr || 0,
95+
};
9496
};
95-
};
9697

9798
const fetchAll: (chain: string) => Fetch =
9899
(chain: string) =>
99-
async (_a: any, _t: any ,options: FetchOptions): Promise<FetchResult> => {
100-
const volumeAndFees = await fetchVolumeAndFees(chain)(options);
101-
return { ...volumeAndFees } as FetchResult;
102-
};
100+
async (_a: any, _t: any, options: FetchOptions): Promise<FetchResult> => {
101+
const volumeAndFees = await fetchVolumeAndFees(chain)(options);
102+
return { ...volumeAndFees } as FetchResult;
103+
};
104+
103105
const adapter: SimpleAdapter = {
104106
deadFrom: '2024-11-24',
105107
isExpensiveAdapter: true,
108+
dependencies: [Dependencies.DUNE],
106109
adapter: {
107-
...Object.values(chainsMap).reduce((acc, chain) => {
108-
return {
109-
...acc,
110-
[(chainsMap as any)[chain] || chain]: {
111-
start: arbitrumStartTimestamp,
112-
fetch: fetchAll(chain),
113-
},
114-
};
115-
}, {}),
110+
...Object.values(chainsMap).reduce((acc, chain) => {
111+
return {
112+
...acc,
113+
[(chainsMap as any)[chain] || chain]: {
114+
start: arbitrumStartTimestamp,
115+
fetch: fetchAll(chain),
116+
},
117+
};
118+
}, {}),
116119
},
117120
};
118121

aggregator-derivatives/rage-trade/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const fetch = async (timestamp: number, _b:any, options: FetchOptions): Promise<
1818
}
1919

2020
const adapter: SimpleAdapter = {
21+
deadFrom: '2025-10-01', // Rage Trade is sunnted
2122
adapter: {
2223
[CHAIN.ARBITRUM]: {
2324
fetch,

0 commit comments

Comments
 (0)