forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
194 lines (163 loc) · 5.23 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { Balances, ChainApi, util } from '@defillama/sdk';
const { blocks: { getChainBlocks } } = util
export type ChainBlocks = Awaited<ReturnType<typeof getChainBlocks>>
export type ChainEndpoints = {
[chain: string]: string
}
export type FetchResultBase = {
timestamp: number;
block?: number;
};
export type FetchResultV2 = {
[key: string]: FetchResponseValue | undefined;
};
export type FetchResultGeneric = FetchResultBase & {
[key: string]: FetchResponseValue | undefined;
}
export type FetchOptions = {
createBalances: () => Balances;
getBlock: (timestamp: number, chain: string, chainBlocks: ChainBlocks) => Promise<number>;
getLogs: (params: FetchGetLogsOptions) => Promise<any[]>;
toTimestamp: number;
fromTimestamp: number;
startOfDay: number;
getFromBlock: () => Promise<number>;
getToBlock: () => Promise<number>;
chain: string,
api: ChainApi,
fromApi: ChainApi,
toApi: ChainApi,
startTimestamp: number,
endTimestamp: number,
getStartBlock: () => Promise<number>,
getEndBlock: () => Promise<number>,
}
export type FetchGetLogsOptions = {
eventAbi?: string,
topic?: string,
target?: string,
targets?: string[],
onlyArgs?: boolean,
fromBlock?: number,
toBlock?: number,
flatten?: boolean,
cacheInCloud?: boolean,
entireLog?: boolean,
skipCacheRead?: boolean,
topics?: string[],
}
export type Fetch = (
timestamp: number,
chainBlocks: ChainBlocks,
options: FetchOptions,
) => Promise<FetchResult>;
export type FetchV2 = (
options: FetchOptions,
) => Promise<FetchResultV2>;
export type IStartTimestamp = () => Promise<number>
export type BaseAdapter = {
[chain: string]: {
start?: IStartTimestamp | number | string; // date can be in "YYYY-MM-DD" format
fetch: Fetch | FetchV2;
runAtCurrTime?: boolean;
customBackfill?: Fetch | FetchV2;
meta?: {
methodology?: string | IJSON<string>
hallmarks?: [number, string][]
}
}
};
export const DISABLED_ADAPTER_KEY = 'DISABLED_ADAPTER'
export enum ProtocolType {
CHAIN = 'chain',
PROTOCOL = 'protocol',
COLLECTION = 'collection',
}
export type AdapterBase = {
timetravel?: boolean
isExpensiveAdapter?: boolean,
protocolType?: ProtocolType;
version?: number;
}
export type SimpleAdapter = AdapterBase & {
adapter: BaseAdapter
}
export type BreakdownAdapter = AdapterBase & {
breakdown: {
[version: string]: BaseAdapter
};
};
export type Adapter = SimpleAdapter | BreakdownAdapter;
export type FetchResponseValue = string | number | Balances;
/**
* Include here new adaptors types
*/
// VOLUME
export type FetchResultVolume = FetchResultBase & {
dailyVolume?: FetchResponseValue
totalVolume?: FetchResponseValue
dailyShortOpenInterest?: FetchResponseValue
dailyLongOpenInterest?: FetchResponseValue
dailyOpenInterest?: FetchResponseValue
dailyBridgeVolume?: FetchResponseValue
totalBridgeVolume?: FetchResponseValue
};
// FEES
export type FetchResultFees = FetchResultBase & {
totalFees?: FetchResponseValue;
dailyFees?: FetchResponseValue;
dailyUserFees?: FetchResponseValue;
totalRevenue?: FetchResponseValue;
dailyRevenue?: FetchResponseValue;
dailyProtocolRevenue?: FetchResponseValue;
dailyHoldersRevenue?: FetchResponseValue;
dailySupplySideRevenue?: FetchResponseValue;
totalProtocolRevenue?: FetchResponseValue;
totalSupplySideRevenue?: FetchResponseValue;
totalUserFees?: FetchResponseValue;
dailyBribesRevenue?: FetchResponseValue;
dailyTokenTaxes?: FetchResponseValue;
};
// INCENTIVES
export type FetchResultIncentives = FetchResultBase & {
tokenIncentives?: FetchResponseValue
};
// AGGREGATORS
export type FetchResultAggregators = FetchResultBase & {
dailyVolume?: FetchResponseValue
totalVolume?: FetchResponseValue
};
// OPTIONS
export type FetchResultOptions = FetchResultBase & {
totalPremiumVolume?: FetchResponseValue
totalNotionalVolume?: FetchResponseValue
dailyPremiumVolume?: FetchResponseValue
dailyNotionalVolume?: FetchResponseValue
dailyShortOpenInterest?: FetchResponseValue
dailyLongOpenInterest?: FetchResponseValue
dailyOpenInterest?: FetchResponseValue
};
export enum AdapterType {
FEES = 'fees',
DEXS = 'dexs',
INCENTIVES = 'incentives',
AGGREGATORS = 'aggregators',
DERIVATIVES = 'derivatives',
OPTIONS = 'options',
PROTOCOLS = 'protocols',
ROYALTIES = 'royalties',
AGGREGATOR_DERIVATIVES = 'aggregator-derivatives',
BRIDGE_AGGREGATORS = 'bridge-aggregators',
}
export type FetchResult = FetchResultVolume & FetchResultFees & FetchResultAggregators & FetchResultOptions & FetchResultIncentives
export const whitelistedDimensionKeys = new Set([
'startTimestamp', 'chain', 'timestamp','block',
'dailyVolume', 'totalVolume', 'dailyShortOpenInterest', 'dailyLongOpenInterest', 'dailyOpenInterest', 'dailyBridgeVolume', 'totalBridgeVolume',
'totalFees', 'dailyFees', 'dailyUserFees', 'totalRevenue', 'dailyRevenue', 'dailyProtocolRevenue', 'dailyHoldersRevenue', 'dailySupplySideRevenue', 'totalProtocolRevenue', 'totalSupplySideRevenue', 'totalUserFees', 'dailyBribesRevenue', 'dailyTokenTaxes', 'totalHoldersRevenue',
'tokenIncentives',
'totalPremiumVolume', 'totalNotionalVolume', 'dailyPremiumVolume', 'dailyNotionalVolume',
])
// End of specific adaptors type
export interface IJSON<T> {
[key: string]: T
}