@1delta/margin-fetcher 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -108,8 +108,8 @@ export function convertMarketsToMorphoResponse(response, chainId, additionalYiel
|
|
|
108
108
|
lltv,
|
|
109
109
|
oracle: oracleAddress,
|
|
110
110
|
irm: irmAddress,
|
|
111
|
-
collateralAddress:
|
|
112
|
-
loanAddress:
|
|
111
|
+
collateralAddress: collateralAssetAddress,
|
|
112
|
+
loanAddress: loanAssetAddress,
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
115
|
data[m].chainId = chainId;
|
|
@@ -35,7 +35,7 @@ function getUserDataConverter(lender, chainId, account, prices, pricesHist, lend
|
|
|
35
35
|
return getInitUserDataConverter(lender, chainId, account, prices, pricesHist, lenderPublicState?.data?.[lender]?.data);
|
|
36
36
|
if (isMorphoType(lender))
|
|
37
37
|
return getMorphoUserDataConverterWithlens(lender, chainId, account, params, prices, pricesHist, lenderPublicState?.data);
|
|
38
|
-
return getCompoundV3UserDataConverter(lender, chainId, account, prices, pricesHist, lenderPublicState);
|
|
38
|
+
return getCompoundV3UserDataConverter(lender, chainId, account, prices, pricesHist, lenderPublicState?.data?.[lender]?.data);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Builds the multicall calls for the given queries and returns the raw results
|
package/package.json
CHANGED
|
@@ -141,8 +141,8 @@ export function convertMarketsToMorphoResponse(
|
|
|
141
141
|
lltv,
|
|
142
142
|
oracle: oracleAddress,
|
|
143
143
|
irm: irmAddress,
|
|
144
|
-
collateralAddress:
|
|
145
|
-
loanAddress:
|
|
144
|
+
collateralAddress: collateralAssetAddress,
|
|
145
|
+
loanAddress: loanAssetAddress,
|
|
146
146
|
},
|
|
147
147
|
}
|
|
148
148
|
data[m].chainId = chainId
|
package/test/userdata.test.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll } from
|
|
1
|
+
import { describe, it, expect, beforeAll } from 'vitest'
|
|
2
2
|
import {
|
|
3
3
|
getLenderUserDataResult,
|
|
4
4
|
convertLenderUserDataResult,
|
|
5
|
-
} from
|
|
5
|
+
} from '../src/lending/user-data/fetchUserData'
|
|
6
6
|
import {
|
|
7
7
|
fetchGeneralYields,
|
|
8
8
|
fetchMainPrices,
|
|
9
9
|
getLenderPublicData,
|
|
10
|
-
} from
|
|
11
|
-
import { multicallRetry, getEvmClient } from
|
|
12
|
-
import { Chain, Lender } from
|
|
13
|
-
import { LenderUserQuery } from
|
|
14
|
-
import { getLendersForChain } from
|
|
10
|
+
} from '../src'
|
|
11
|
+
import { multicallRetry, getEvmClient } from '@1delta/providers'
|
|
12
|
+
import { Chain, Lender } from '@1delta/asset-registry'
|
|
13
|
+
import { LenderUserQuery } from '../src/lending/user-data/types'
|
|
14
|
+
import { getLendersForChain } from '../src/utils'
|
|
15
15
|
|
|
16
|
-
const TEST_ADDRESS =
|
|
17
|
-
let prices, yields
|
|
16
|
+
const TEST_ADDRESS = '0xbadA9c382165b31419F4CC0eDf0Fa84f80A3C8E5'
|
|
17
|
+
let prices, yields
|
|
18
18
|
|
|
19
19
|
async function getUserData(chainId: Chain, lenders: Lender[]) {
|
|
20
|
-
const _lenders = getLendersForChain(chainId)
|
|
20
|
+
const _lenders = getLendersForChain(chainId)
|
|
21
21
|
const publicData = {
|
|
22
22
|
data: await getLenderPublicData(
|
|
23
23
|
chainId,
|
|
24
24
|
_lenders as any,
|
|
25
25
|
prices as any,
|
|
26
26
|
yields as any,
|
|
27
|
-
multicallRetry
|
|
28
|
-
)
|
|
27
|
+
multicallRetry,
|
|
28
|
+
),
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Define user queries
|
|
32
32
|
const queries: LenderUserQuery[] = lenders.map((lender) => ({
|
|
33
33
|
lender,
|
|
34
34
|
account: TEST_ADDRESS.toLowerCase(),
|
|
35
|
-
}))
|
|
35
|
+
}))
|
|
36
36
|
|
|
37
37
|
// Fetch raw user data
|
|
38
38
|
const rawUserData = await getLenderUserDataResult(
|
|
39
39
|
chainId,
|
|
40
40
|
queries,
|
|
41
|
-
getEvmClient
|
|
42
|
-
)
|
|
41
|
+
getEvmClient,
|
|
42
|
+
)
|
|
43
43
|
|
|
44
44
|
// Convert raw data to structured format
|
|
45
45
|
const userData = convertLenderUserDataResult(
|
|
@@ -48,142 +48,170 @@ async function getUserData(chainId: Chain, lenders: Lender[]) {
|
|
|
48
48
|
rawUserData,
|
|
49
49
|
prices as any,
|
|
50
50
|
prices as any,
|
|
51
|
-
{ [chainId]: publicData }
|
|
52
|
-
)
|
|
51
|
+
{ [chainId]: publicData },
|
|
52
|
+
)
|
|
53
53
|
|
|
54
|
-
return { userData, rawUserData, publicData, queries }
|
|
54
|
+
return { userData, rawUserData, publicData, queries }
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
describe(
|
|
58
|
-
|
|
58
|
+
'user data fetching',
|
|
59
59
|
() => {
|
|
60
60
|
beforeAll(async () => {
|
|
61
|
-
[prices, yields] = await Promise.all([
|
|
61
|
+
;[prices, yields] = await Promise.all([
|
|
62
62
|
fetchMainPrices([Chain.MANTLE], getEvmClient),
|
|
63
63
|
fetchGeneralYields(),
|
|
64
|
-
])
|
|
65
|
-
}, 30000)
|
|
64
|
+
])
|
|
65
|
+
}, 30000)
|
|
66
66
|
|
|
67
67
|
it(
|
|
68
|
-
|
|
68
|
+
'should fetch user data for LENDLE PT CMETH on Mantle',
|
|
69
69
|
async () => {
|
|
70
70
|
try {
|
|
71
|
-
const { userData } = await getUserData(Chain.MANTLE, [
|
|
71
|
+
const { userData } = await getUserData(Chain.MANTLE, [
|
|
72
|
+
Lender.LENDLE_PT_CMETH,
|
|
73
|
+
])
|
|
72
74
|
|
|
73
|
-
console.log(
|
|
75
|
+
console.log(
|
|
76
|
+
'LENDLE PT CMETH Mantle user data:',
|
|
77
|
+
userData[Lender.LENDLE_PT_CMETH][TEST_ADDRESS.toLowerCase()],
|
|
78
|
+
)
|
|
74
79
|
|
|
75
80
|
// Basic validation
|
|
76
|
-
expect(userData).toBeDefined()
|
|
77
|
-
expect(typeof userData).toBe(
|
|
81
|
+
expect(userData).toBeDefined()
|
|
82
|
+
expect(typeof userData).toBe('object')
|
|
78
83
|
} catch (error) {
|
|
79
|
-
console.log(
|
|
84
|
+
console.log('Error fetching LENDLE PT CMETH Mantle data:', error)
|
|
80
85
|
}
|
|
81
86
|
},
|
|
82
|
-
{ timeout: 30000 }
|
|
83
|
-
)
|
|
87
|
+
{ timeout: 30000 },
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
it(
|
|
91
|
+
'should fetch user data for COMET on Arb',
|
|
92
|
+
async () => {
|
|
93
|
+
try {
|
|
94
|
+
const { userData } = await getUserData(Chain.ARBITRUM_ONE, [
|
|
95
|
+
Lender.COMPOUND_V3_USDC,
|
|
96
|
+
])
|
|
84
97
|
|
|
98
|
+
console.log('COMET Mantle user data:', userData[Lender.COMPOUND_V3_USDC]?.[TEST_ADDRESS.toLowerCase()])
|
|
85
99
|
|
|
100
|
+
// Basic validation
|
|
101
|
+
expect(userData).toBeDefined()
|
|
102
|
+
expect(typeof userData).toBe('object')
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.log('Error fetching INIT Mantle data:', error)
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{ timeout: 30000 },
|
|
108
|
+
)
|
|
86
109
|
|
|
87
110
|
it(
|
|
88
|
-
|
|
111
|
+
'should fetch user data for INIT on Mantle',
|
|
89
112
|
async () => {
|
|
90
113
|
try {
|
|
91
|
-
const { userData } = await getUserData(Chain.MANTLE, [Lender.INIT])
|
|
114
|
+
const { userData } = await getUserData(Chain.MANTLE, [Lender.INIT])
|
|
92
115
|
|
|
93
|
-
console.log(
|
|
116
|
+
console.log('INIT Mantle user data:', userData)
|
|
94
117
|
|
|
95
118
|
// Basic validation
|
|
96
|
-
expect(userData).toBeDefined()
|
|
97
|
-
expect(typeof userData).toBe(
|
|
119
|
+
expect(userData).toBeDefined()
|
|
120
|
+
expect(typeof userData).toBe('object')
|
|
98
121
|
} catch (error) {
|
|
99
|
-
console.log(
|
|
122
|
+
console.log('Error fetching INIT Mantle data:', error)
|
|
100
123
|
}
|
|
101
124
|
},
|
|
102
|
-
{ timeout: 30000 }
|
|
103
|
-
)
|
|
104
|
-
|
|
125
|
+
{ timeout: 30000 },
|
|
126
|
+
)
|
|
105
127
|
|
|
106
128
|
it(
|
|
107
|
-
|
|
129
|
+
'should fetch user data for AAVE V3 on Polygon',
|
|
108
130
|
async () => {
|
|
109
131
|
try {
|
|
110
|
-
const { userData } = await getUserData(Chain.ARBITRUM_ONE, [
|
|
132
|
+
const { userData } = await getUserData(Chain.ARBITRUM_ONE, [
|
|
133
|
+
Lender.AAVE_V3,
|
|
134
|
+
])
|
|
111
135
|
|
|
112
|
-
console.log(
|
|
113
|
-
|
|
136
|
+
console.log(
|
|
137
|
+
'AAVE_V3 Polygon user data:',
|
|
138
|
+
userData[Lender.AAVE_V3][TEST_ADDRESS.toLowerCase()]
|
|
139
|
+
.lendingPositions,
|
|
140
|
+
)
|
|
141
|
+
console.log('AAVE_V3 Polygon user aprData:', userData[Lender.AAVE_V3])
|
|
114
142
|
|
|
115
143
|
// Basic validation
|
|
116
|
-
expect(userData).toBeDefined()
|
|
117
|
-
expect(typeof userData).toBe(
|
|
144
|
+
expect(userData).toBeDefined()
|
|
145
|
+
expect(typeof userData).toBe('object')
|
|
118
146
|
} catch (error) {
|
|
119
|
-
console.log(
|
|
147
|
+
console.log('Error fetching AAVE_V3 Polygon data:', error)
|
|
120
148
|
}
|
|
121
149
|
},
|
|
122
|
-
{ timeout: 30000 }
|
|
123
|
-
)
|
|
124
|
-
|
|
150
|
+
{ timeout: 30000 },
|
|
151
|
+
)
|
|
125
152
|
|
|
126
153
|
it(
|
|
127
|
-
|
|
154
|
+
'should fetch user data for AAVE V3 on Base',
|
|
128
155
|
async () => {
|
|
129
156
|
try {
|
|
130
|
-
const { userData } = await getUserData(Chain.BASE, [Lender.AAVE_V3])
|
|
157
|
+
const { userData } = await getUserData(Chain.BASE, [Lender.AAVE_V3])
|
|
131
158
|
|
|
132
|
-
console.log(
|
|
159
|
+
console.log('AAVE V3 Base user data:', userData)
|
|
133
160
|
|
|
134
161
|
// Basic validation
|
|
135
|
-
expect(userData).toBeDefined()
|
|
136
|
-
expect(typeof userData).toBe(
|
|
162
|
+
expect(userData).toBeDefined()
|
|
163
|
+
expect(typeof userData).toBe('object')
|
|
137
164
|
} catch (error) {
|
|
138
|
-
console.log(
|
|
165
|
+
console.log('Error fetching AAVE V3 Base data:', error)
|
|
139
166
|
}
|
|
140
167
|
},
|
|
141
|
-
{ timeout: 30000 }
|
|
142
|
-
)
|
|
168
|
+
{ timeout: 30000 },
|
|
169
|
+
)
|
|
143
170
|
|
|
144
171
|
it(
|
|
145
|
-
|
|
172
|
+
'should fetch user data for multiple protocols on Arbitrum',
|
|
146
173
|
async () => {
|
|
147
174
|
try {
|
|
148
|
-
const { userData, queries } = await getUserData(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
175
|
+
const { userData, queries } = await getUserData(Chain.ARBITRUM_ONE, [
|
|
176
|
+
Lender.AAVE_V3,
|
|
177
|
+
Lender.COMPOUND_V3_USDC,
|
|
178
|
+
Lender.COMPOUND_V3_USDCE,
|
|
179
|
+
])
|
|
152
180
|
|
|
153
|
-
console.log(
|
|
181
|
+
console.log('Arbitrum multi-protocol user data:', userData)
|
|
154
182
|
|
|
155
|
-
expect(userData).toBeDefined()
|
|
156
|
-
expect(typeof userData).toBe(
|
|
183
|
+
expect(userData).toBeDefined()
|
|
184
|
+
expect(typeof userData).toBe('object')
|
|
157
185
|
|
|
158
186
|
// Check that we get data for each queried protocol
|
|
159
187
|
queries.forEach((query) => {
|
|
160
188
|
if (userData[query.lender]) {
|
|
161
|
-
console.log(`Found data for ${query.lender} on Arbitrum`)
|
|
162
|
-
expect(userData[query.lender]).toBeDefined()
|
|
189
|
+
console.log(`Found data for ${query.lender} on Arbitrum`)
|
|
190
|
+
expect(userData[query.lender]).toBeDefined()
|
|
163
191
|
}
|
|
164
|
-
})
|
|
192
|
+
})
|
|
165
193
|
} catch (error) {
|
|
166
|
-
console.log(
|
|
194
|
+
console.log('Error fetching Arbitrum multi-protocol data:', error)
|
|
167
195
|
}
|
|
168
196
|
},
|
|
169
|
-
{ timeout: 30000 }
|
|
170
|
-
)
|
|
197
|
+
{ timeout: 30000 },
|
|
198
|
+
)
|
|
171
199
|
|
|
172
200
|
it(
|
|
173
|
-
|
|
201
|
+
'should fetch user data across multiple chains',
|
|
174
202
|
async () => {
|
|
175
203
|
const testChains = [
|
|
176
204
|
Chain.ETHEREUM_MAINNET,
|
|
177
205
|
Chain.POLYGON_MAINNET,
|
|
178
206
|
Chain.BASE,
|
|
179
|
-
]
|
|
207
|
+
]
|
|
180
208
|
|
|
181
209
|
try {
|
|
182
210
|
for (const chainId of testChains) {
|
|
183
|
-
const lenders = getLendersForChain(chainId)
|
|
211
|
+
const lenders = getLendersForChain(chainId)
|
|
184
212
|
if (lenders.length === 0) {
|
|
185
|
-
console.log(`No lenders available on ${chainId}`)
|
|
186
|
-
continue
|
|
213
|
+
console.log(`No lenders available on ${chainId}`)
|
|
214
|
+
continue
|
|
187
215
|
}
|
|
188
216
|
|
|
189
217
|
const publicData = await getLenderPublicData(
|
|
@@ -191,19 +219,19 @@ describe(
|
|
|
191
219
|
lenders as any,
|
|
192
220
|
prices as any,
|
|
193
221
|
yields as any,
|
|
194
|
-
multicallRetry
|
|
195
|
-
)
|
|
222
|
+
multicallRetry,
|
|
223
|
+
)
|
|
196
224
|
|
|
197
|
-
const firstLender = lenders[0] as Lender
|
|
225
|
+
const firstLender = lenders[0] as Lender
|
|
198
226
|
const queries: LenderUserQuery[] = [
|
|
199
227
|
{ lender: firstLender, account: TEST_ADDRESS.toLowerCase() }, // test first lender
|
|
200
|
-
]
|
|
228
|
+
]
|
|
201
229
|
|
|
202
230
|
const rawUserData = await getLenderUserDataResult(
|
|
203
231
|
chainId,
|
|
204
232
|
queries,
|
|
205
|
-
getEvmClient
|
|
206
|
-
)
|
|
233
|
+
getEvmClient,
|
|
234
|
+
)
|
|
207
235
|
|
|
208
236
|
const userData = convertLenderUserDataResult(
|
|
209
237
|
chainId,
|
|
@@ -211,51 +239,46 @@ describe(
|
|
|
211
239
|
rawUserData,
|
|
212
240
|
prices as any,
|
|
213
241
|
prices as any,
|
|
214
|
-
publicData
|
|
215
|
-
)
|
|
242
|
+
publicData,
|
|
243
|
+
)
|
|
216
244
|
|
|
217
|
-
console.log(`${chainId} - ${firstLender} user data:`, userData)
|
|
245
|
+
console.log(`${chainId} - ${firstLender} user data:`, userData)
|
|
218
246
|
|
|
219
|
-
expect(userData).toBeDefined()
|
|
220
|
-
expect(typeof userData).toBe(
|
|
247
|
+
expect(userData).toBeDefined()
|
|
248
|
+
expect(typeof userData).toBe('object')
|
|
221
249
|
}
|
|
222
250
|
} catch (error) {
|
|
223
|
-
console.log(
|
|
251
|
+
console.log('Error in multi-chain test:', error)
|
|
224
252
|
}
|
|
225
253
|
},
|
|
226
|
-
{ timeout: 60000 }
|
|
227
|
-
)
|
|
254
|
+
{ timeout: 60000 },
|
|
255
|
+
)
|
|
228
256
|
|
|
229
257
|
it(
|
|
230
|
-
|
|
258
|
+
'should fetch user data for Init protocol on Mantle',
|
|
231
259
|
async () => {
|
|
232
|
-
const chainId = Chain.MANTLE
|
|
260
|
+
const chainId = Chain.MANTLE
|
|
233
261
|
|
|
234
262
|
try {
|
|
235
|
-
const { userData } = await getUserData(
|
|
236
|
-
Chain.MANTLE,
|
|
237
|
-
[Lender.INIT]
|
|
238
|
-
);
|
|
263
|
+
const { userData } = await getUserData(Chain.MANTLE, [Lender.INIT])
|
|
239
264
|
|
|
240
|
-
console.log(
|
|
265
|
+
console.log('Init protocol Mantle user data:', userData)
|
|
241
266
|
|
|
242
|
-
expect(userData).toBeDefined()
|
|
243
|
-
expect(typeof userData).toBe(
|
|
267
|
+
expect(userData).toBeDefined()
|
|
268
|
+
expect(typeof userData).toBe('object')
|
|
244
269
|
} catch (error) {
|
|
245
|
-
console.log(
|
|
270
|
+
console.log('Error fetching Init protocol data:', error)
|
|
246
271
|
}
|
|
247
272
|
},
|
|
248
|
-
{ timeout: 30000 }
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
it("should handle empty queries", async () => {
|
|
252
|
-
const { userData } = await getUserData(Chain.BASE, []);
|
|
253
|
-
|
|
254
|
-
expect(userData).toBeDefined();
|
|
255
|
-
expect(Object.keys(userData)).toHaveLength(0);
|
|
256
|
-
});
|
|
273
|
+
{ timeout: 30000 },
|
|
274
|
+
)
|
|
257
275
|
|
|
276
|
+
it('should handle empty queries', async () => {
|
|
277
|
+
const { userData } = await getUserData(Chain.BASE, [])
|
|
258
278
|
|
|
279
|
+
expect(userData).toBeDefined()
|
|
280
|
+
expect(Object.keys(userData)).toHaveLength(0)
|
|
281
|
+
})
|
|
259
282
|
},
|
|
260
|
-
{ timeout: 90000 }
|
|
261
|
-
)
|
|
283
|
+
{ timeout: 90000 },
|
|
284
|
+
)
|