-
Notifications
You must be signed in to change notification settings - Fork 809
/
index.ts
175 lines (163 loc) · 5 KB
/
index.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
import { Chain } from "@defillama/sdk/build/general";
import { BreakdownAdapter, FetchResultGeneric, BaseAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getStartTimestamp } from "../../helpers/getStartTimestamp";
import {
getGraphDimensions,
DEFAULT_DAILY_VOLUME_FACTORY,
DEFAULT_TOTAL_VOLUME_FIELD,
} from "../../helpers/getUniSubgraph"
import { type } from "os";
const v1Endpoints = {
[CHAIN.ETHEREUM]: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap",
};
const v2Endpoints = {
[CHAIN.ETHEREUM]: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v2-dev",
};
const blacklisted = {
[CHAIN.ETHEREUM]: [
'0x637f415687b7b2545ef2cd8dcc1614e1cc175850',
'0xb94acdf8662cd955f137e0c9c9fba535c87b57b4',
'0xb504035a11e672e12a099f32b1672b9c4a78b22f'
]
}
const v3Endpoints = {
[CHAIN.ETHEREUM]: "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3",
[CHAIN.OPTIMISM]: "https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis?source=uniswap",
[CHAIN.ARBITRUM]: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-arbitrum-one",
[CHAIN.POLYGON]: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon",
[CHAIN.CELO]: "https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo",
[CHAIN.BSC]: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-bsc",
[CHAIN.AVAX]: "https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax",
[CHAIN.BASE]: "https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-base",
[CHAIN.ERA]: "https://api.thegraph.com/subgraphs/name/freakyfractal/uniswap-v3-zksync-era"
};
const VOLUME_USD = "volumeUSD";
// fees results are in eth, needs to be converted to a balances objects
const ETH_ADDRESS = "ethereum:0x0000000000000000000000000000000000000000";
const v1Graph = getGraphDimensions({
graphUrls: v1Endpoints,
totalVolume: {
factory: "uniswaps",
},
dailyVolume: {
field: "dailyVolumeInUSD",
},
dailyFees: {
factory: "exchangeHistoricalData",
field: "feeInEth"
},
feesPercent: {
type: "fees",
UserFees: 100,
ProtocolRevenue: 0,
SupplySideRevenue: 100,
HoldersRevenue: 0,
Revenue: 0,
Fees: 100
}
});
const v2Graph = getGraphDimensions({
graphUrls: v2Endpoints,
feesPercent: {
type: "volume",
UserFees: 0.3,
ProtocolRevenue: 0,
SupplySideRevenue: 0.3,
HoldersRevenue: 0,
Revenue: 0,
Fees: 0.3
},
blacklistTokens: blacklisted
});
const v3Graphs = getGraphDimensions({
graphUrls: v3Endpoints,
totalVolume: {
factory: "factories",
field: DEFAULT_TOTAL_VOLUME_FIELD,
},
dailyVolume: {
factory: DEFAULT_DAILY_VOLUME_FACTORY,
field: VOLUME_USD,
},
feesPercent: {
type: "fees",
ProtocolRevenue: 0,
HoldersRevenue: 0,
UserFees: 100, // User fees are 100% of collected fees
SupplySideRevenue: 100, // 100% of fees are going to LPs
Revenue: 0 // Revenue is 100% of collected fees
}
});
const methodology = {
UserFees: "User pays 0.3% fees on each swap.",
ProtocolRevenue: "Protocol have no revenue.",
SupplySideRevenue: "All user fees are distributed among LPs.",
HoldersRevenue: "Holders have no revenue."
}
type TStartTime = {
[key: string]: number;
}
const startTimeV3:TStartTime = {
[CHAIN.ETHEREUM]: 1620172800,
[CHAIN.OPTIMISM]: 1636675200,
[CHAIN.ARBITRUM]: 1630368000,
[CHAIN.POLYGON]: 1640044800,
[CHAIN.CELO]: 1657324800,
[CHAIN.BSC]: 1678665600,
[CHAIN.AVAX]: 1689033600,
[CHAIN.BASE]: 1691280000,
[CHAIN.ERA]: 1693440000
}
const adapter: BreakdownAdapter = {
breakdown: {
v1: {
[CHAIN.ETHEREUM]: {
fetch: async (timestamp, chainBlocks) => {
const response = await v1Graph(CHAIN.ETHEREUM)(timestamp, chainBlocks)
return {
...response,
...["dailyUserFees", "dailyProtocolRevenue", "dailySupplySideRevenue", "dailyHoldersRevenue", "dailyRevenue", "dailyFees"].reduce((acc, resultType) => {
const valueInEth = response[resultType]
if (typeof valueInEth === 'string')
acc[resultType] = {
[ETH_ADDRESS]: valueInEth
}
return acc
}, {} as FetchResultGeneric)
} as FetchResultGeneric
},
start: async () => 1541203200,
meta: {
methodology
},
},
},
v2: {
[CHAIN.ETHEREUM]: {
fetch: v2Graph(CHAIN.ETHEREUM),
start: getStartTimestamp({
endpoints: v2Endpoints,
chain: CHAIN.ETHEREUM,
}),
meta: {
methodology
},
},
},
v3: Object.keys(v3Endpoints).reduce((acc, chain) => {
acc[chain] = {
fetch: v3Graphs(chain as Chain),
start: async () => startTimeV3[chain],
meta: {
methodology: {
...methodology,
UserFees: "User pays 0.05%, 0.30%, or 1% on each swap."
}
}
}
return acc
}, {} as BaseAdapter)
}
}
export default adapter;