impermax-sdk 2.1.558 → 2.1.560
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.
- package/lib/offchain/initializer/user/userLendingPool/index.d.ts +2 -0
- package/lib/offchain/initializer/user/userLendingPool/index.js +76 -2
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +1 -0
- package/lib/offchain/lendingPool/offchainLendingPool.js +10 -0
- package/lib/offchain/offchain.d.ts +2 -0
- package/lib/offchain/offchain.js +2 -0
- package/lib/offchain/offchainMultichain.d.ts +4 -0
- package/lib/offchain/offchainMultichain.js +12 -0
- package/lib/offchain/queries/apis/ponder/index.d.ts +2 -0
- package/lib/offchain/queries/apis/ponder/index.js +115 -6
- package/lib/offchain/queries/apis/thegraph/index.d.ts +2 -0
- package/lib/offchain/queries/apis/thegraph/index.js +107 -5
- package/lib/offchain/queries/interfaces/query-builder.d.ts +2 -0
- package/package.json +1 -1
|
@@ -3,4 +3,6 @@ import { RawUserData, UserData } from "../../../offchainTypes";
|
|
|
3
3
|
import Offchain from "../../../offchain";
|
|
4
4
|
export declare function getUserData(this: Offchain, account: Address): Promise<FactoryIndex<UserData> | null>;
|
|
5
5
|
export declare function initializeUserData(this: Offchain, account: Address): Promise<FactoryIndex<UserData> | null>;
|
|
6
|
+
export declare function initializeAllUsersData(this: Offchain): Promise<Record<Address, FactoryIndex<UserData>>>;
|
|
6
7
|
export declare function fetchUserData(this: Offchain, account: Address): Promise<FactoryIndex<RawUserData>>;
|
|
8
|
+
export declare function fetchAllUsersData(this: Offchain): Promise<Record<Address, FactoryIndex<RawUserData>>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchUserData = exports.initializeUserData = exports.getUserData = void 0;
|
|
3
|
+
exports.fetchAllUsersData = exports.fetchUserData = exports.initializeAllUsersData = exports.initializeUserData = exports.getUserData = void 0;
|
|
4
4
|
const subgraphs_1 = require("../../../../config/subgraphs");
|
|
5
5
|
const types_1 = require("../../../../config/types");
|
|
6
6
|
const offchainTypes_1 = require("../../../offchainTypes");
|
|
@@ -22,6 +22,7 @@ exports.getUserData = getUserData;
|
|
|
22
22
|
// For collateralPositions/borrowPositions we separate into:
|
|
23
23
|
// - `initializeV2Positions` for V2
|
|
24
24
|
// - `initializeV3Positions` for V3
|
|
25
|
+
// Initialize single user data
|
|
25
26
|
async function initializeUserData(account) {
|
|
26
27
|
const result = {};
|
|
27
28
|
const userData = await this.fetchUserData(account);
|
|
@@ -72,10 +73,55 @@ async function initializeUserData(account) {
|
|
|
72
73
|
return result;
|
|
73
74
|
}
|
|
74
75
|
exports.initializeUserData = initializeUserData;
|
|
76
|
+
// Initialize all users data
|
|
77
|
+
// NOTE: Only v3 atm as we test
|
|
78
|
+
async function initializeAllUsersData() {
|
|
79
|
+
const allUserData = await this.fetchAllUsersData();
|
|
80
|
+
const result = {};
|
|
81
|
+
for (const userAddress in allUserData) {
|
|
82
|
+
const userData = allUserData[userAddress];
|
|
83
|
+
result[userAddress] = {};
|
|
84
|
+
for (const factory in userData) {
|
|
85
|
+
if (!(0, offchainTypes_1.isV3Factory)(factory))
|
|
86
|
+
continue;
|
|
87
|
+
const userDataOfFactory = userData[factory];
|
|
88
|
+
result[userAddress][factory] = {
|
|
89
|
+
positions: {},
|
|
90
|
+
collateralPositions: {},
|
|
91
|
+
supplyPositions: {},
|
|
92
|
+
borrowPositions: {},
|
|
93
|
+
};
|
|
94
|
+
// Get V3 positions only
|
|
95
|
+
const v3Data = await (0, positionsV3_1.initializeV3Positions)(this, factory, userDataOfFactory);
|
|
96
|
+
result[userAddress][factory].positions = v3Data.positions;
|
|
97
|
+
// Supply positions is same for v2 and v3
|
|
98
|
+
for (const supplyPosition of userDataOfFactory.supplyPositions) {
|
|
99
|
+
const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
|
|
100
|
+
const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
101
|
+
const lendingPool = await this.getLendingPool(factory, lendingPoolId);
|
|
102
|
+
if (!lendingPool) {
|
|
103
|
+
console.error("Can't resolve supplyPosition because lendingPool is null. Lending pool:", lendingPoolId, this.network);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const borrowableA = lendingPool.getBorrowableA();
|
|
107
|
+
const addressA = await borrowableA.getUnderlyingAddress();
|
|
108
|
+
const poolTokenType = underlyingId === addressA
|
|
109
|
+
? types_1.PoolTokenType.BorrowableA
|
|
110
|
+
: types_1.PoolTokenType.BorrowableB;
|
|
111
|
+
if (!(lendingPoolId in result[userAddress][factory].supplyPositions)) {
|
|
112
|
+
result[userAddress][factory].supplyPositions[lendingPoolId] = {};
|
|
113
|
+
}
|
|
114
|
+
result[userAddress][factory].supplyPositions[lendingPoolId][poolTokenType] = supplyPosition;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
exports.initializeAllUsersData = initializeAllUsersData;
|
|
75
121
|
/*--------------------------------------------------------------------------*
|
|
76
122
|
* Fetchers *
|
|
77
123
|
*--------------------------------------------------------------------------*/
|
|
78
|
-
//
|
|
124
|
+
// Fetch single user data
|
|
79
125
|
async function fetchUserData(account) {
|
|
80
126
|
const positions = {};
|
|
81
127
|
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
@@ -95,3 +141,31 @@ async function fetchUserData(account) {
|
|
|
95
141
|
return positions;
|
|
96
142
|
}
|
|
97
143
|
exports.fetchUserData = fetchUserData;
|
|
144
|
+
// Fetch all users data
|
|
145
|
+
// NOTE: Only v3 atm as we test
|
|
146
|
+
async function fetchAllUsersData() {
|
|
147
|
+
const allUserData = {};
|
|
148
|
+
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
149
|
+
if (!(0, offchainTypes_1.isV3Factory)(factory))
|
|
150
|
+
continue;
|
|
151
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
152
|
+
const result = await this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.usersQuery(this.network, factory));
|
|
153
|
+
if (!result || !result.data?.users)
|
|
154
|
+
continue;
|
|
155
|
+
const users = result.data.users;
|
|
156
|
+
// Process each user and group by user address
|
|
157
|
+
for (const user of users) {
|
|
158
|
+
const userAddress = user.id;
|
|
159
|
+
if (!allUserData[userAddress])
|
|
160
|
+
allUserData[userAddress] = {};
|
|
161
|
+
allUserData[userAddress][factory] = {
|
|
162
|
+
positions: user.positions,
|
|
163
|
+
supplyPositions: user.supplyPositions,
|
|
164
|
+
collateralPositions: user.collateralPositions,
|
|
165
|
+
borrowPositions: user.borrowPositions, // Undefined if V3
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return allUserData;
|
|
170
|
+
}
|
|
171
|
+
exports.fetchAllUsersData = fetchAllUsersData;
|
|
@@ -69,6 +69,7 @@ export default abstract class OffchainLendingPool {
|
|
|
69
69
|
isStableFactory(): boolean;
|
|
70
70
|
private normalizeTokenSymbol;
|
|
71
71
|
isStablePair(): Promise<boolean>;
|
|
72
|
+
showInverted(): Promise<boolean>;
|
|
72
73
|
getLendingPoolVersion(): LendingPoolVersion;
|
|
73
74
|
getTotalBorrowsUSD(): Promise<number>;
|
|
74
75
|
private initializeLendingPoolAddresses;
|
|
@@ -179,6 +179,16 @@ class OffchainLendingPool {
|
|
|
179
179
|
return (stables.includes(symbol0) && stables.includes(symbol1)) ||
|
|
180
180
|
(symbol0.slice(-3) === symbol1.slice(-3));
|
|
181
181
|
}
|
|
182
|
+
async showInverted() {
|
|
183
|
+
let [stables, token0, token1] = await Promise.all([
|
|
184
|
+
this.getOffchain().getAPRHelper().getAllStablecoins(),
|
|
185
|
+
this.getBorrowableA().getSymbol(),
|
|
186
|
+
this.getBorrowableB().getSymbol(),
|
|
187
|
+
]);
|
|
188
|
+
const symbol0 = this.normalizeTokenSymbol(token0);
|
|
189
|
+
const symbol1 = this.normalizeTokenSymbol(token1);
|
|
190
|
+
return stables.includes(symbol0) && !stables.includes(symbol1);
|
|
191
|
+
}
|
|
182
192
|
// Versions Specfics
|
|
183
193
|
getLendingPoolVersion() {
|
|
184
194
|
const factoryType = Number(this.factory);
|
|
@@ -105,6 +105,8 @@ export default class Offchain {
|
|
|
105
105
|
protected fetchUserData: typeof initializer.fetchUserData;
|
|
106
106
|
protected initializeUserData: typeof initializer.initializeUserData;
|
|
107
107
|
getUserData: typeof initializer.getUserData;
|
|
108
|
+
fetchAllUsersData: typeof initializer.fetchAllUsersData;
|
|
109
|
+
initializeAllUsersData: typeof initializer.initializeAllUsersData;
|
|
108
110
|
protected initializeXIbexData: typeof initializer.initializeXIbexData;
|
|
109
111
|
getXIbexData: typeof initializer.getXIbexData;
|
|
110
112
|
getXIbexUserData: typeof initializer.getXIbexUserData;
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -86,6 +86,8 @@ class Offchain {
|
|
|
86
86
|
this.fetchUserData = initializer.fetchUserData;
|
|
87
87
|
this.initializeUserData = initializer.initializeUserData;
|
|
88
88
|
this.getUserData = initializer.getUserData;
|
|
89
|
+
this.fetchAllUsersData = initializer.fetchAllUsersData;
|
|
90
|
+
this.initializeAllUsersData = initializer.initializeAllUsersData;
|
|
89
91
|
this.initializeXIbexData = initializer.initializeXIbexData;
|
|
90
92
|
this.getXIbexData = initializer.getXIbexData;
|
|
91
93
|
this.getXIbexUserData = initializer.getXIbexUserData;
|
|
@@ -94,6 +94,10 @@ export default class OffchainMultichain {
|
|
|
94
94
|
private filterVersion;
|
|
95
95
|
getMultichainAccount(accountAddress: Address): OffchainMultichainAccount;
|
|
96
96
|
getMultichainBorrowersList(params?: BorrowersListParams): Promise<OffchainAccount[]>;
|
|
97
|
+
/**
|
|
98
|
+
* TODO: Get all borrowers positions across networks.
|
|
99
|
+
*/
|
|
100
|
+
getAllBorrowerPositions(params?: BorrowersListParams): Promise<any>;
|
|
97
101
|
getActiveAmms(params?: LendingPoolListParams): Promise<Amms[]>;
|
|
98
102
|
/** Gets TVL from defillama */
|
|
99
103
|
getDefillamaTvlData(params?: MultichainTvlParams): Promise<MultichainTvlData>;
|
|
@@ -189,6 +189,18 @@ class OffchainMultichain {
|
|
|
189
189
|
const allBorrowers = await Promise.all(networkPromises);
|
|
190
190
|
return [...new Set(allBorrowers.flat())];
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* TODO: Get all borrowers positions across networks.
|
|
194
|
+
*/
|
|
195
|
+
async getAllBorrowerPositions(params = {}) {
|
|
196
|
+
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
197
|
+
// Fetch all users data for each network in parallel
|
|
198
|
+
const networkPromises = allNetworks.map(async (network) => {
|
|
199
|
+
const offchain = this.getOffchain(network);
|
|
200
|
+
// TODO: Get all users data and return position objects
|
|
201
|
+
//const allUsersData = await offchain.initializeAllUsersData();
|
|
202
|
+
});
|
|
203
|
+
}
|
|
192
204
|
/*--------------------------------------------------------*
|
|
193
205
|
* Whitelisted AMMs list
|
|
194
206
|
*--------------------------------------------------------*/
|
|
@@ -6,8 +6,10 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
|
|
|
6
6
|
getBlockNumber(response: any, network: Networks): number;
|
|
7
7
|
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): DocumentNode;
|
|
8
8
|
userQueryV3(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
9
|
+
usersQueryV3(network: Networks, factory: Factory): DocumentNode;
|
|
9
10
|
lendingPoolsQuery(factory: Factory, addressesFilter: Address[], network: Networks): DocumentNode;
|
|
10
11
|
userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
12
|
+
usersQuery(network: Networks, factory: Factory): DocumentNode;
|
|
11
13
|
tvlQuery(): DocumentNode;
|
|
12
14
|
vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): DocumentNode;
|
|
13
15
|
vaultsUserQuery(account: Address): DocumentNode;
|
|
@@ -89,19 +89,19 @@ class PonderQueryBuilder {
|
|
|
89
89
|
user(id: "${account.toLowerCase()}") {
|
|
90
90
|
id
|
|
91
91
|
positions(limit: 1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}" }) {
|
|
92
|
-
items {
|
|
92
|
+
items {
|
|
93
93
|
id
|
|
94
94
|
tokenId
|
|
95
95
|
lendingPool {
|
|
96
96
|
id
|
|
97
|
-
nftlp {
|
|
97
|
+
nftlp {
|
|
98
98
|
factory
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
borrowPositions {
|
|
102
102
|
items {
|
|
103
103
|
borrowBalance
|
|
104
|
-
borrowIndex
|
|
104
|
+
borrowIndex
|
|
105
105
|
cumulativeBorrows
|
|
106
106
|
borrowable {
|
|
107
107
|
id
|
|
@@ -135,6 +135,60 @@ class PonderQueryBuilder {
|
|
|
135
135
|
}
|
|
136
136
|
}`;
|
|
137
137
|
}
|
|
138
|
+
// Get all users V3 positions from network factory, no address filter
|
|
139
|
+
usersQueryV3(network, factory) {
|
|
140
|
+
return (0, graphql_tag_1.default) `{
|
|
141
|
+
users(limit: 1000, where: {id_not: "0x0000000000000000000000000000000000000000"}) {
|
|
142
|
+
items {
|
|
143
|
+
id
|
|
144
|
+
positions(limit: 1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}" }) {
|
|
145
|
+
items {
|
|
146
|
+
id
|
|
147
|
+
tokenId
|
|
148
|
+
lendingPool {
|
|
149
|
+
id
|
|
150
|
+
nftlp {
|
|
151
|
+
factory
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
borrowPositions {
|
|
155
|
+
items {
|
|
156
|
+
borrowBalance
|
|
157
|
+
borrowIndex
|
|
158
|
+
cumulativeBorrows
|
|
159
|
+
borrowable {
|
|
160
|
+
id
|
|
161
|
+
underlying {
|
|
162
|
+
id
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
supplyPositions(where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}" }) {
|
|
170
|
+
items {
|
|
171
|
+
balance
|
|
172
|
+
cumulativeEarnings
|
|
173
|
+
lastExchangeRate
|
|
174
|
+
borrowable {
|
|
175
|
+
id
|
|
176
|
+
underlying {
|
|
177
|
+
id
|
|
178
|
+
}
|
|
179
|
+
lendingPool {
|
|
180
|
+
id
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
_meta {
|
|
188
|
+
status
|
|
189
|
+
}
|
|
190
|
+
}`;
|
|
191
|
+
}
|
|
138
192
|
/*-----------------------------*
|
|
139
193
|
* 2. Lending pools
|
|
140
194
|
*-----------------------------*/
|
|
@@ -237,7 +291,7 @@ class PonderQueryBuilder {
|
|
|
237
291
|
return (0, graphql_tag_1.default) `{
|
|
238
292
|
user(id: "${account.toLowerCase()}") {
|
|
239
293
|
collateralPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", balance_not: "0"}) {
|
|
240
|
-
items {
|
|
294
|
+
items {
|
|
241
295
|
balance
|
|
242
296
|
collateral {
|
|
243
297
|
lendingPool {
|
|
@@ -247,7 +301,7 @@ class PonderQueryBuilder {
|
|
|
247
301
|
}
|
|
248
302
|
}
|
|
249
303
|
supplyPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", balance_not: "0"}) {
|
|
250
|
-
items {
|
|
304
|
+
items {
|
|
251
305
|
balance
|
|
252
306
|
cumulativeEarnings
|
|
253
307
|
lastExchangeRate
|
|
@@ -262,7 +316,7 @@ class PonderQueryBuilder {
|
|
|
262
316
|
}
|
|
263
317
|
}
|
|
264
318
|
borrowPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", borrowBalance_not: "0"}) {
|
|
265
|
-
items {
|
|
319
|
+
items {
|
|
266
320
|
borrowBalance
|
|
267
321
|
borrowIndex
|
|
268
322
|
borrowable {
|
|
@@ -281,6 +335,60 @@ class PonderQueryBuilder {
|
|
|
281
335
|
}
|
|
282
336
|
}`;
|
|
283
337
|
}
|
|
338
|
+
// Get all users V2 positions from network factory, no address filter
|
|
339
|
+
usersQuery(network, factory) {
|
|
340
|
+
if (factory === types_1.Factory.V3)
|
|
341
|
+
return this.usersQueryV3(network, factory);
|
|
342
|
+
return (0, graphql_tag_1.default) `{
|
|
343
|
+
users(limit: 1000, where: {id_not: "0x0000000000000000000000000000000000000000"}) {
|
|
344
|
+
items {
|
|
345
|
+
id
|
|
346
|
+
collateralPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", balance_not: "0"}) {
|
|
347
|
+
items {
|
|
348
|
+
balance
|
|
349
|
+
collateral {
|
|
350
|
+
lendingPool {
|
|
351
|
+
id
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
supplyPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", balance_not: "0"}) {
|
|
357
|
+
items {
|
|
358
|
+
balance
|
|
359
|
+
cumulativeEarnings
|
|
360
|
+
lastExchangeRate
|
|
361
|
+
borrowable {
|
|
362
|
+
underlying {
|
|
363
|
+
id
|
|
364
|
+
}
|
|
365
|
+
lendingPool {
|
|
366
|
+
id
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
borrowPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", borrowBalance_not: "0"}) {
|
|
372
|
+
items {
|
|
373
|
+
borrowBalance
|
|
374
|
+
borrowIndex
|
|
375
|
+
borrowable {
|
|
376
|
+
underlying {
|
|
377
|
+
id
|
|
378
|
+
}
|
|
379
|
+
lendingPool {
|
|
380
|
+
id
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
_meta {
|
|
388
|
+
status
|
|
389
|
+
}
|
|
390
|
+
}`;
|
|
391
|
+
}
|
|
284
392
|
tvlQuery() {
|
|
285
393
|
return (0, graphql_tag_1.default) `
|
|
286
394
|
{
|
|
@@ -554,6 +662,7 @@ class PonderQueryBuilder {
|
|
|
554
662
|
/*-----------------------------*
|
|
555
663
|
* List of Borrowers V2 & V3
|
|
556
664
|
*-----------------------------*/
|
|
665
|
+
// NOTE: THese are deprecated and should not be used, instead use `usersQuery` and `usersQueryV3`
|
|
557
666
|
borrowersListQuery(factory) {
|
|
558
667
|
if (factory === types_1.Factory.V3)
|
|
559
668
|
return this.borrowersListQueryV3();
|
|
@@ -5,8 +5,10 @@ export declare class TheGraphQueryBuilder implements IQueryBuilder {
|
|
|
5
5
|
getBlockNumber(response: any, network: Networks): number;
|
|
6
6
|
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
7
7
|
userQueryV3(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
8
|
+
usersQueryV3(network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
8
9
|
lendingPoolsQuery(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
9
10
|
userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
11
|
+
usersQuery(network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
10
12
|
tvlQuery(): import("graphql").DocumentNode;
|
|
11
13
|
nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
|
|
12
14
|
nftlpPositionQuery(extension: Extension, positionIds: string[]): import("graphql").DocumentNode;
|
|
@@ -7,8 +7,6 @@ exports.TheGraphQueryBuilder = void 0;
|
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const types_1 = require("../../../../config/types");
|
|
9
9
|
const factories_1 = require("../../../../config/factories");
|
|
10
|
-
// TODO: Might need to separate Vaults query based on vault type, maybe not.
|
|
11
|
-
// TODO: nftlpAeroCLPositions subgraph, nftlpAeroCLPositionsQuery not used atm
|
|
12
10
|
class TheGraphQueryBuilder {
|
|
13
11
|
/*-----------------------------*
|
|
14
12
|
* 1. API Health
|
|
@@ -95,13 +93,65 @@ class TheGraphQueryBuilder {
|
|
|
95
93
|
tokenId
|
|
96
94
|
lendingPool {
|
|
97
95
|
id
|
|
98
|
-
nftlp {
|
|
96
|
+
nftlp {
|
|
99
97
|
factory
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
borrowPositions(first: 1000) {
|
|
103
101
|
borrowBalance
|
|
104
|
-
borrowIndex
|
|
102
|
+
borrowIndex
|
|
103
|
+
cumulativeBorrows
|
|
104
|
+
borrowable {
|
|
105
|
+
id
|
|
106
|
+
underlying {
|
|
107
|
+
id
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
supplyPositions(first: 1000) {
|
|
113
|
+
balance
|
|
114
|
+
cumulativeEarnings
|
|
115
|
+
lastExchangeRate
|
|
116
|
+
borrowable {
|
|
117
|
+
id
|
|
118
|
+
underlying {
|
|
119
|
+
id
|
|
120
|
+
}
|
|
121
|
+
lendingPool {
|
|
122
|
+
id
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_meta {
|
|
128
|
+
block {
|
|
129
|
+
number
|
|
130
|
+
}
|
|
131
|
+
hasIndexingErrors
|
|
132
|
+
}
|
|
133
|
+
}`;
|
|
134
|
+
}
|
|
135
|
+
// Get all users V3 positions from network factory, no address filter
|
|
136
|
+
usersQueryV3(network, factory) {
|
|
137
|
+
// Shh
|
|
138
|
+
network;
|
|
139
|
+
factory;
|
|
140
|
+
return (0, graphql_tag_1.default) `{
|
|
141
|
+
users(first: 1000, where: { borrowPositions_: { borrowBalance_gt: "0", id_not: "0x0000000000000000000000000000000000000000" } }) {
|
|
142
|
+
id
|
|
143
|
+
positions(first: 1000) {
|
|
144
|
+
id
|
|
145
|
+
tokenId
|
|
146
|
+
lendingPool {
|
|
147
|
+
id
|
|
148
|
+
nftlp {
|
|
149
|
+
factory
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
borrowPositions(first: 1000, where: {borrowBalance_gt: "0"}) {
|
|
153
|
+
borrowBalance
|
|
154
|
+
borrowIndex
|
|
105
155
|
cumulativeBorrows
|
|
106
156
|
borrowable {
|
|
107
157
|
id
|
|
@@ -277,6 +327,58 @@ class TheGraphQueryBuilder {
|
|
|
277
327
|
}
|
|
278
328
|
}`;
|
|
279
329
|
}
|
|
330
|
+
// Get all users V2 positions from network factory, no address filter
|
|
331
|
+
usersQuery(network, factory) {
|
|
332
|
+
if (factory === types_1.Factory.V3)
|
|
333
|
+
return this.usersQueryV3(network, factory);
|
|
334
|
+
// Shh
|
|
335
|
+
network;
|
|
336
|
+
factory;
|
|
337
|
+
return (0, graphql_tag_1.default) `{
|
|
338
|
+
users(first: 1000, where: { borrowPositions_: { borrowBalance_gt: "0", id_not: "0x0000000000000000000000000000000000000000" } }) {
|
|
339
|
+
id
|
|
340
|
+
collateralPositions(first: 1000, where: { balance_gt: "0" }) {
|
|
341
|
+
balance
|
|
342
|
+
collateral {
|
|
343
|
+
lendingPool {
|
|
344
|
+
id
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
supplyPositions(first:1000, where: { balance_gt: "0" }) {
|
|
349
|
+
balance
|
|
350
|
+
lastExchangeRate
|
|
351
|
+
cumulativeEarnings
|
|
352
|
+
borrowable {
|
|
353
|
+
underlying {
|
|
354
|
+
id
|
|
355
|
+
}
|
|
356
|
+
lendingPool {
|
|
357
|
+
id
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
borrowPositions(first:1000, where: { borrowBalance_gt: "0" }) {
|
|
362
|
+
borrowBalance
|
|
363
|
+
borrowIndex
|
|
364
|
+
borrowable {
|
|
365
|
+
underlying {
|
|
366
|
+
id
|
|
367
|
+
}
|
|
368
|
+
lendingPool {
|
|
369
|
+
id
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
_meta {
|
|
375
|
+
block {
|
|
376
|
+
number
|
|
377
|
+
}
|
|
378
|
+
hasIndexingErrors
|
|
379
|
+
}
|
|
380
|
+
}`;
|
|
381
|
+
}
|
|
280
382
|
tvlQuery() {
|
|
281
383
|
return (0, graphql_tag_1.default) `{
|
|
282
384
|
impermaxFactories(first: 1) {
|
|
@@ -620,7 +722,7 @@ class TheGraphQueryBuilder {
|
|
|
620
722
|
/*-----------------------------*
|
|
621
723
|
* List of Borrowers V2 & V3
|
|
622
724
|
*-----------------------------*/
|
|
623
|
-
//
|
|
725
|
+
// NOTE: THese are deprecated and should not be used, instead use `usersQuery` and `usersQueryV3`
|
|
624
726
|
borrowersListQuery(factory) {
|
|
625
727
|
if (factory === types_1.Factory.V3)
|
|
626
728
|
return this.borrowersListQueryV3();
|
|
@@ -5,8 +5,10 @@ export interface IQueryBuilder {
|
|
|
5
5
|
getBlockNumber: (response: any, network: Networks) => number;
|
|
6
6
|
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): DocumentNode;
|
|
7
7
|
userQueryV3(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
8
|
+
usersQueryV3(network: Networks, factory: Factory): DocumentNode;
|
|
8
9
|
lendingPoolsQuery(factory: Factory, addressesFilter: Address[] | undefined, network: Networks): DocumentNode;
|
|
9
10
|
userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
11
|
+
usersQuery(network: Networks, factory: Factory): DocumentNode;
|
|
10
12
|
tvlQuery(): DocumentNode;
|
|
11
13
|
nftlpsQuery(extension: Extension, network: Networks): DocumentNode;
|
|
12
14
|
nftlpPositionQuery(extension: Extension, positionIds: string[]): DocumentNode;
|