impermax-sdk 2.1.333 → 2.1.334

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.
Files changed (27) hide show
  1. package/lib/offchain/initializer/borrowers/allPositionsV2.d.ts +0 -0
  2. package/lib/offchain/initializer/borrowers/allPositionsV2.js +71 -0
  3. package/lib/offchain/initializer/borrowers/allPositionsV3.d.ts +0 -0
  4. package/lib/offchain/initializer/borrowers/allPositionsV3.js +107 -0
  5. package/lib/offchain/initializer/borrowers/index.js +2 -4
  6. package/lib/offchain/initializer/index.d.ts +0 -1
  7. package/lib/offchain/initializer/index.js +0 -1
  8. package/lib/offchain/initializer/user/{lendingPools.d.ts → lendingPools/index.d.ts} +3 -3
  9. package/lib/offchain/initializer/user/{lendingPools.js → lendingPools/index.js} +3 -3
  10. package/lib/offchain/initializer/user/{positionsV2.d.ts → lendingPools/positionsV2.d.ts} +3 -3
  11. package/lib/offchain/initializer/user/{positionsV2.js → lendingPools/positionsV2.js} +1 -1
  12. package/lib/offchain/initializer/user/{positionsV3.d.ts → lendingPools/positionsV3.d.ts} +3 -3
  13. package/lib/offchain/initializer/user/{positionsV3.js → lendingPools/positionsV3.js} +1 -1
  14. package/lib/offchain/initializer/user/{vaults.d.ts → vaults/index.d.ts} +3 -3
  15. package/lib/offchain/initializer/user/{vaults.js → vaults/index.js} +1 -1
  16. package/lib/offchain/offchain.d.ts +0 -3
  17. package/lib/offchain/offchain.js +5 -3
  18. package/lib/offchain/offchainMultichain.d.ts +1 -0
  19. package/lib/offchain/offchainMultichain.js +19 -0
  20. package/lib/offchain/queries/apis/ponder/index.d.ts +2 -1
  21. package/lib/offchain/queries/apis/ponder/index.js +38 -31
  22. package/lib/offchain/queries/apis/thegraph/index.d.ts +2 -1
  23. package/lib/offchain/queries/apis/thegraph/index.js +9 -3
  24. package/lib/offchain/queries/interfaces/query-builder.d.ts +1 -2
  25. package/package.json +1 -1
  26. package/lib/offchain/initializer/allPositionsV3.d.ts +0 -23
  27. package/lib/offchain/initializer/allPositionsV3.js +0 -63
@@ -0,0 +1,71 @@
1
+ // NOTE: `fetchBorrowersList` will fetch v2 and v3 positions.
2
+ // Hidden atm in case in the future we add functionality get only v2 positions.
3
+ // import { Address, Factory, FactoryIndex } from '../../../config/types';
4
+ // import { IMPERMAX_SUBGRAPH_URL } from '../../../config/subgraphs';
5
+ // import Offchain from '../../offchain';
6
+ // import OffchainAccount from '../../account';
7
+ // import { ApolloQueryResult } from "apollo-client";
8
+ //
9
+ // /*--------------------------------------------------------------------------*
10
+ // * Getters *
11
+ // *--------------------------------------------------------------------------*/
12
+ //
13
+ // export async function getBorrowersList(
14
+ // this: Offchain
15
+ // ): Promise<OffchainAccount[]> {
16
+ // if (!this.borrowersList) this.borrowersList = this.initializeBorrowersList();
17
+ // return this.borrowersList;
18
+ // }
19
+ //
20
+ // /*--------------------------------------------------------------------------*
21
+ // * Initializers *
22
+ // *--------------------------------------------------------------------------*/
23
+ //
24
+ // export async function initializeBorrowersList(
25
+ // this: Offchain
26
+ // ): Promise<OffchainAccount[]> {
27
+ // const borrowersData = await this.fetchBorrowersList();
28
+ // const uniqueBorrowers = new Set<Address>();
29
+ //
30
+ // // Make borrowers unique across all lending pools
31
+ // for (const factory in borrowersData) {
32
+ // borrowersData[factory].forEach((b: any) => uniqueBorrowers.add(b.toLowerCase()));
33
+ // }
34
+ //
35
+ // return Array.from(uniqueBorrowers).map(address => this.getAccount(address))
36
+ // }
37
+ //
38
+ // /*--------------------------------------------------------------------------*
39
+ // * Fetchers *
40
+ // *--------------------------------------------------------------------------*/
41
+ //
42
+ // export async function fetchBorrowersList(
43
+ // this: Offchain
44
+ // ): Promise<FactoryIndex<Address[]>> {
45
+ // const calls: Promise<ApolloQueryResult<any>>[] = [];
46
+ // const factories: Factory[] = [];
47
+ //
48
+ // let factory: Factory;
49
+ // for (factory in IMPERMAX_SUBGRAPH_URL[this.network]) {
50
+ // const subgraphs = IMPERMAX_SUBGRAPH_URL[this.network][factory] as string[];
51
+ // calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.borrowersListQuery(factory)));
52
+ // factories.push(factory);
53
+ // }
54
+ //
55
+ // const results = await Promise.all(calls);
56
+ // const borrowers: FactoryIndex<Address[]> = {};
57
+ //
58
+ // results.forEach((result, index) => {
59
+ // if (!result) return;
60
+ // // Get the factory for this result
61
+ // const factory = factories[index];
62
+ //
63
+ // const borrowPositions = result.data?.borrowPositions;
64
+ // if (!borrowPositions) return;
65
+ //
66
+ // // Borrower addresses for this factory
67
+ // borrowers[factory] = borrowPositions.map((i: any) => i.user.id);
68
+ // });
69
+ //
70
+ // return borrowers;
71
+ // }
@@ -0,0 +1,107 @@
1
+ // NOTE: `fetchBorrowersList` will fetch v2 and v3 positions.
2
+ // Hidden atm in case in the future we add functionality get only v3 positions.
3
+ // import { AddressIndex, Factory } from "../../config/types";
4
+ // import { NftlpPosition, BorrowPosition } from "../offchainTypes";
5
+ // import Offchain from "../../offchain";
6
+ // import { getNftlpDex, getNftlpSubgraph } from "../../config/nftlp";
7
+ // import { IMPERMAX_SUBGRAPH_URL, } from '../../config/subgraphs';
8
+ //
9
+ // type PositionV3 = {
10
+ // id: string;
11
+ // userId: string;
12
+ // tokenId: string;
13
+ // lendingPool: {
14
+ // id: string;
15
+ // nftlp: {
16
+ // factory: string;
17
+ // }
18
+ // };
19
+ // borrowPositions: BorrowPosition[];
20
+ // }
21
+ //
22
+ // /*--------------------------------------------------------------------------*
23
+ // * Getters *
24
+ // *--------------------------------------------------------------------------*/
25
+ //
26
+ // export async function getAllV3PositionsData(
27
+ // this: Offchain,
28
+ // factory: Factory
29
+ // ): Promise<AddressIndex<{[key: string]: NftlpPosition[]}>> {
30
+ // if (!this.allV3PositionsData[factory]) this.allV3PositionsData[factory] = this.initializeAllV3Positions(factory);
31
+ // return this.allV3PositionsData[factory]!;
32
+ // }
33
+ //
34
+ // /*--------------------------------------------------------------------------*
35
+ // * Initializers *
36
+ // *--------------------------------------------------------------------------*/
37
+ //
38
+ // export async function initializeAllV3Positions(
39
+ // this: Offchain,
40
+ // factory: Factory,
41
+ // ): Promise<AddressIndex<{[key: string]: NftlpPosition[]}>> {
42
+ // const globalPositions = await this.fetchAllV3Positions(factory);
43
+ //
44
+ // const positions: AddressIndex<{[key: string]: NftlpPosition[]}> = {};
45
+ //
46
+ // for (const position of globalPositions) {
47
+ // const lendingPoolId = position.lendingPool.id;
48
+ // const userAddress = position.userId;
49
+ // const nftlpFactory = position.lendingPool.nftlp.factory;
50
+ //
51
+ // // Initialize empty if need
52
+ // if (!positions[lendingPoolId]) positions[lendingPoolId] = {};
53
+ // if (!positions[lendingPoolId][userAddress]) positions[lendingPoolId][userAddress] = [];
54
+ //
55
+ // const dex = getNftlpDex(this.network, nftlpFactory);
56
+ // if (dex === undefined) {
57
+ // console.warn(`Unknown DEX for NFTLP factory ${nftlpFactory} on ${this.network}`);
58
+ // continue;
59
+ // }
60
+ //
61
+ // // Might not be needed for all positions??
62
+ // const endpoints = getNftlpSubgraph(this.network, dex);
63
+ // if (!endpoints?.length) {
64
+ // console.warn(`No NFTLP endpoints found for ${dex} on ${this.network}`);
65
+ // continue;
66
+ // }
67
+ //
68
+ // const nftlpData = await this.getEndpointManager().fetch(
69
+ // endpoints,
70
+ // this.network,
71
+ // (queryBuilder) => queryBuilder.nftlpPositionQuery(lendingPoolId, position.tokenId)
72
+ // );
73
+ //
74
+ // // Create final position object
75
+ // const nftlpPosition = { ...position, dex, nftlp: nftlpData.data.nftlpPositions?.[0] };
76
+ //
77
+ // // Add to results
78
+ // positions[lendingPoolId][userAddress].push(nftlpPosition);
79
+ // }
80
+ //
81
+ // return positions;
82
+ // }
83
+ //
84
+ // /*--------------------------------------------------------------------------*
85
+ // * Fetchers *
86
+ // *--------------------------------------------------------------------------*/
87
+ //
88
+ // // Same as user/positionsV3
89
+ // export async function fetchAllV3Positions(
90
+ // this: Offchain,
91
+ // factory: Factory
92
+ // ): Promise<PositionV3[]> {
93
+ // const subgraphs = IMPERMAX_SUBGRAPH_URL[this.network][factory];
94
+ // if (!subgraphs?.length) {
95
+ // console.warn(`No subgraphs found for factory ${factory} on ${this.network}`);
96
+ // return [];
97
+ // }
98
+ //
99
+ // const allPositionsData = await this.getEndpointManager().fetch(
100
+ // subgraphs,
101
+ // this.network,
102
+ // (queryBuilder) => queryBuilder.allPositionsV3Query()
103
+ // );
104
+ //
105
+ // return allPositionsData?.data?.positions || [];
106
+ // }
107
+ //
@@ -33,10 +33,8 @@ async function fetchBorrowersList() {
33
33
  const factories = [];
34
34
  let factory;
35
35
  for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
36
- if (factory === types_1.Factory.V3)
37
- continue;
38
36
  const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
39
- calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.borrowersListQueryV2()));
37
+ calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.borrowersListQuery(factory)));
40
38
  factories.push(factory);
41
39
  }
42
40
  const results = await Promise.all(calls);
@@ -46,7 +44,7 @@ async function fetchBorrowersList() {
46
44
  return;
47
45
  // Get the factory for this result
48
46
  const factory = factories[index];
49
- const borrowPositions = result.data?.borrowPositions;
47
+ const borrowPositions = factory === types_1.Factory.V3 ? result.data?.positions : result.data?.borrowPositions;
50
48
  if (!borrowPositions)
51
49
  return;
52
50
  // Borrower addresses for this factory
@@ -3,7 +3,6 @@ export * from './blocks';
3
3
  export * from './lendingPools';
4
4
  export * from './lendingPoolsPast';
5
5
  export * from './vaults';
6
- export * from './allPositionsV3';
7
6
  export * from './user';
8
7
  export * from './whitelist';
9
8
  export * from './staking';
@@ -19,7 +19,6 @@ __exportStar(require("./blocks"), exports);
19
19
  __exportStar(require("./lendingPools"), exports);
20
20
  __exportStar(require("./lendingPoolsPast"), exports);
21
21
  __exportStar(require("./vaults"), exports);
22
- __exportStar(require("./allPositionsV3"), exports);
23
22
  __exportStar(require("./user"), exports);
24
23
  __exportStar(require("./whitelist"), exports);
25
24
  __exportStar(require("./staking"), exports);
@@ -1,6 +1,6 @@
1
- import { Address, FactoryIndex } from "../../../config/types";
2
- import { RawUserData, UserData } from "../../offchainTypes";
3
- import Offchain from "../../offchain";
1
+ import { Address, FactoryIndex } from "../../../../config/types";
2
+ import { RawUserData, UserData } from "../../../offchainTypes";
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
6
  export declare function fetchUserData(this: Offchain, account: Address): Promise<FactoryIndex<RawUserData>>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchUserData = exports.initializeUserData = exports.getUserData = void 0;
4
- const subgraphs_1 = require("../../../config/subgraphs");
5
- const types_1 = require("../../../config/types");
6
- const offchainTypes_1 = require("../../offchainTypes");
4
+ const subgraphs_1 = require("../../../../config/subgraphs");
5
+ const types_1 = require("../../../../config/types");
6
+ const offchainTypes_1 = require("../../../offchainTypes");
7
7
  const positionsV2_1 = require("./positionsV2");
8
8
  const positionsV3_1 = require("./positionsV3");
9
9
  /*--------------------------------------------------------------------------*
@@ -1,6 +1,6 @@
1
- import { AddressIndex, Factory, PoolTokenType } from "../../../config/types";
2
- import { CollateralPosition, BorrowPosition, RawV2UserData } from "../../offchainTypes";
3
- import Offchain from "../../offchain";
1
+ import { AddressIndex, Factory, PoolTokenType } from "../../../../config/types";
2
+ import { CollateralPosition, BorrowPosition, RawV2UserData } from "../../../offchainTypes";
3
+ import Offchain from "../../../offchain";
4
4
  export declare function initializeV2Positions(offchain: Offchain, factory: Factory, rawUserData: RawV2UserData, pairs: Array<string>): Promise<{
5
5
  collateralPositions: AddressIndex<CollateralPosition[]>;
6
6
  borrowPositions: AddressIndex<{
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initializeV2Positions = void 0;
4
- const types_1 = require("../../../config/types");
4
+ const types_1 = require("../../../../config/types");
5
5
  async function initializeV2Positions(offchain, factory, rawUserData, pairs) {
6
6
  const collateralPositions = {};
7
7
  const borrowPositions = {};
@@ -1,6 +1,6 @@
1
- import { AddressIndex, Factory } from "../../../config/types";
2
- import { NftlpPosition, RawV3UserData } from "../../offchainTypes";
3
- import Offchain from "../../offchain";
1
+ import { AddressIndex, Factory } from "../../../../config/types";
2
+ import { NftlpPosition, RawV3UserData } from "../../../offchainTypes";
3
+ import Offchain from "../../../offchain";
4
4
  /**
5
5
  * At this point we have all Collateral Positions (V3 NFTLP positions) of a user
6
6
  * on a chain across many different NFTLPs (we got this from `IMPERMAX_SUBGRAPH_URL`):
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initializeV3Positions = void 0;
4
- const nftlp_1 = require("../../../config/nftlp");
4
+ const nftlp_1 = require("../../../../config/nftlp");
5
5
  /**
6
6
  * At this point we have all Collateral Positions (V3 NFTLP positions) of a user
7
7
  * on a chain across many different NFTLPs (we got this from `IMPERMAX_SUBGRAPH_URL`):
@@ -1,6 +1,6 @@
1
- import { Address, AddressIndex } from "../../../config/types";
2
- import { VaultPosition } from "../../offchainTypes";
3
- import Offchain from "../../offchain";
1
+ import { Address, AddressIndex } from "../../../../config/types";
2
+ import { VaultPosition } from "../../../offchainTypes";
3
+ import Offchain from "../../../offchain";
4
4
  export declare function getVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<AddressIndex<VaultPosition>>>;
5
5
  export declare function initializeVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<AddressIndex<VaultPosition>>>;
6
6
  export declare function fetchVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<VaultPosition[]>>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchVaultsUserData = exports.initializeVaultsUserData = exports.getVaultsUserData = void 0;
4
- const subgraphs_1 = require("../../../config/subgraphs");
4
+ const subgraphs_1 = require("../../../../config/subgraphs");
5
5
  /*--------------------------------------------------------------------------*
6
6
  * Getters *
7
7
  *--------------------------------------------------------------------------*/
@@ -92,9 +92,6 @@ export default class Offchain {
92
92
  protected initializeVaultsUserData: typeof initializer.initializeVaultsUserData;
93
93
  protected fetchVaultBorrowables: typeof initializer.fetchVaultBorrowables;
94
94
  getVaultBorrowables: typeof initializer.getVaultBorrowables;
95
- protected fetchAllV3Positions: typeof initializer.fetchAllV3Positions;
96
- protected initializeAllV3Positions: typeof initializer.initializeAllV3Positions;
97
- getAllV3PositionsData: typeof initializer.getAllV3PositionsData;
98
95
  protected fetchBorrowersList: typeof initializer.fetchBorrowersList;
99
96
  protected initializeBorrowersList: typeof initializer.initializeBorrowersList;
100
97
  getBorrowersList: typeof initializer.getBorrowersList;
@@ -86,9 +86,11 @@ class Offchain {
86
86
  this.initializeVaultsUserData = initializer.initializeVaultsUserData;
87
87
  this.fetchVaultBorrowables = initializer.fetchVaultBorrowables;
88
88
  this.getVaultBorrowables = initializer.getVaultBorrowables;
89
- this.fetchAllV3Positions = initializer.fetchAllV3Positions;
90
- this.initializeAllV3Positions = initializer.initializeAllV3Positions;
91
- this.getAllV3PositionsData = initializer.getAllV3PositionsData;
89
+ // NOTE: This isn't needed as `fetchBorrowersList` below will fetch v2 and v3 positions.
90
+ // Hidden atm in case we decide to add functions for v3 only.
91
+ // protected fetchAllV3Positions = initializer.fetchAllV3Positions;
92
+ // protected initializeAllV3Positions = initializer.initializeAllV3Positions;
93
+ // public getAllV3PositionsData = initializer.getAllV3PositionsData;
92
94
  this.fetchBorrowersList = initializer.fetchBorrowersList;
93
95
  this.initializeBorrowersList = initializer.initializeBorrowersList;
94
96
  this.getBorrowersList = initializer.getBorrowersList;
@@ -77,4 +77,5 @@ export default class OffchainMultichain {
77
77
  private filterVersion;
78
78
  getMultichainAccount(accountAddress: Address): OffchainMultichainAccount;
79
79
  getMultichainBorrowersList(params?: BorrowersListParams): Promise<OffchainAccount[]>;
80
+ getActiveAmms(params?: LendingPoolListParams): Promise<Amms[]>;
80
81
  }
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.SortDirection = void 0;
19
19
  const types_1 = require("../config/types");
20
20
  const offchain_1 = __importDefault(require("./offchain"));
21
+ const amms_1 = require("../config/amms");
21
22
  const subgraphs_1 = require("../config/subgraphs");
22
23
  const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
23
24
  const offchainPriceHelperV2_1 = __importDefault(require("./offchainPriceHelperV2"));
@@ -183,6 +184,24 @@ class OffchainMultichain {
183
184
  const allBorrowers = await Promise.all(networkPromises);
184
185
  return [...new Set(allBorrowers.flat())];
185
186
  }
187
+ /*--------------------------------------------------------*
188
+ * Whitelisted AMMs list
189
+ *--------------------------------------------------------*/
190
+ async getActiveAmms(params = {}) {
191
+ // Get lending pools
192
+ const lendingPools = await this.getLendingPoolList(params);
193
+ // Go through each lending pool and get amm.
194
+ // Check if pool is whitelisted, if so add amm to set.
195
+ const activeAmms = new Set();
196
+ const results = lendingPools.map(async (pool) => {
197
+ const amm = await pool.getAmm();
198
+ if (amm && pool.isWhitelisted())
199
+ activeAmms.add(amms_1.hrAmms[amm]);
200
+ });
201
+ await Promise.all(results);
202
+ // Unique AMMs
203
+ return Array.from(activeAmms);
204
+ }
186
205
  }
187
206
  exports.default = OffchainMultichain;
188
207
  _a = OffchainMultichain;
@@ -5,7 +5,6 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
5
5
  getBlockNumber(response: any, network: Networks): number;
6
6
  lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): import("graphql").DocumentNode;
7
7
  userQueryV3(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
8
- allPositionsV3Query(): import("graphql").DocumentNode;
9
8
  lendingPoolsQuery(factory: Factory, addressesFilter: Address[], network: Networks): import("graphql").DocumentNode;
10
9
  userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
11
10
  tvlQuery(): import("graphql").DocumentNode;
@@ -16,5 +15,7 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
16
15
  ximxQuery(): import("graphql").DocumentNode;
17
16
  nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
18
17
  nftlpPositionQuery(lendingPoolId: string, tokenId: string): import("graphql").DocumentNode;
18
+ borrowersListQuery(factory: Factory): import("graphql").DocumentNode;
19
19
  borrowersListQueryV2(): import("graphql").DocumentNode;
20
+ borrowersListQueryV3(): import("graphql").DocumentNode;
20
21
  }
@@ -132,37 +132,6 @@ class PonderQueryBuilder {
132
132
  }
133
133
  }`;
134
134
  }
135
- allPositionsV3Query() {
136
- return (0, graphql_tag_1.default) `{
137
- positions(limit: 1000) {
138
- items {
139
- id
140
- userId
141
- tokenId
142
- lendingPool {
143
- id
144
- nftlp {
145
- factory
146
- }
147
- }
148
- borrowPositions {
149
- items {
150
- id
151
- borrowBalance
152
- borrowable {
153
- underlying {
154
- id
155
- }
156
- }
157
- }
158
- }
159
- }
160
- }
161
- _meta {
162
- status
163
- }
164
- }`;
165
- }
166
135
  /*-----------------------------*
167
136
  * 2. Lending pools
168
137
  *-----------------------------*/
@@ -512,6 +481,11 @@ class PonderQueryBuilder {
512
481
  /*-----------------------------*
513
482
  * List of Borrowers V2 & V3
514
483
  *-----------------------------*/
484
+ borrowersListQuery(factory) {
485
+ if (factory === types_1.Factory.V3)
486
+ return this.borrowersListQueryV3();
487
+ return this.borrowersListQueryV2();
488
+ }
515
489
  borrowersListQueryV2() {
516
490
  return (0, graphql_tag_1.default) `{
517
491
  borrowPositions(limit: 1000, where: {borrowBalance_not: "0"}) {
@@ -532,5 +506,38 @@ class PonderQueryBuilder {
532
506
  }
533
507
  }`;
534
508
  }
509
+ borrowersListQueryV3() {
510
+ return (0, graphql_tag_1.default) `{
511
+ positions(limit: 1000) {
512
+ items {
513
+ id
514
+ tokenId
515
+ user {
516
+ id
517
+ }
518
+ lendingPool {
519
+ id
520
+ nftlp {
521
+ factory
522
+ }
523
+ }
524
+ borrowPositions {
525
+ items {
526
+ id
527
+ borrowBalance
528
+ borrowable {
529
+ underlying {
530
+ id
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
+ }
537
+ _meta {
538
+ status
539
+ }
540
+ }`;
541
+ }
535
542
  }
536
543
  exports.PonderQueryBuilder = PonderQueryBuilder;
@@ -5,7 +5,6 @@ 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
- allPositionsV3Query(): import("graphql").DocumentNode;
9
8
  lendingPoolsQuery(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
10
9
  userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
11
10
  tvlQuery(): import("graphql").DocumentNode;
@@ -21,5 +20,7 @@ export declare class TheGraphQueryBuilder implements IQueryBuilder {
21
20
  pastVolumeQuery(blockNumber: number, addressesFilter: Address[]): import("graphql").DocumentNode;
22
21
  currentVolumeAndReservesQuery(addressesFilter: Address[]): import("graphql").DocumentNode;
23
22
  whitelistQuery(): import("graphql").DocumentNode;
23
+ borrowersListQuery(factory: Factory): import("graphql").DocumentNode;
24
24
  borrowersListQueryV2(): import("graphql").DocumentNode;
25
+ borrowersListQueryV3(): import("graphql").DocumentNode;
25
26
  }
@@ -39,9 +39,6 @@ class TheGraphQueryBuilder {
39
39
  userQueryV3(account, network, factory) {
40
40
  return (0, graphql_tag_1.default) `{}`;
41
41
  }
42
- allPositionsV3Query() {
43
- return (0, graphql_tag_1.default) `{}`;
44
- }
45
42
  /*-----------------------------*
46
43
  * 2. Lending pools
47
44
  *-----------------------------*/
@@ -384,11 +381,20 @@ class TheGraphQueryBuilder {
384
381
  /*-----------------------------*
385
382
  * List of Borrowers V2 & V3
386
383
  *-----------------------------*/
384
+ // TODO: thegraph borrowersListQueryV3
385
+ borrowersListQuery(factory) {
386
+ if (factory === types_1.Factory.V3)
387
+ return this.borrowersListQueryV3();
388
+ return this.borrowersListQueryV2();
389
+ }
387
390
  borrowersListQueryV2() {
388
391
  return (0, graphql_tag_1.default) `{
389
392
  borrowPositions(where: {borrowBalance_gt: "0"}) { user { id } }
390
393
  _meta { block { number } }
391
394
  }`;
392
395
  }
396
+ borrowersListQueryV3() {
397
+ return (0, graphql_tag_1.default) `{}`;
398
+ }
393
399
  }
394
400
  exports.TheGraphQueryBuilder = TheGraphQueryBuilder;
@@ -5,7 +5,6 @@ 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
- allPositionsV3Query(): DocumentNode;
9
8
  lendingPoolsQuery(factory: Factory, addressesFilter: Address[] | undefined, network: Networks): DocumentNode;
10
9
  userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
11
10
  tvlQuery(): DocumentNode;
@@ -21,5 +20,5 @@ export interface IQueryBuilder {
21
20
  whitelistQuery?(): DocumentNode;
22
21
  currentVolumeAndReservesQuery?(addressesFilter: Address[]): DocumentNode;
23
22
  pastVolumeQuery?(blockNumber: number, addressesFilter: Address[]): DocumentNode;
24
- borrowersListQueryV2(): DocumentNode;
23
+ borrowersListQuery(factory: Factory): DocumentNode;
25
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.333",
3
+ "version": "2.1.334",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -1,23 +0,0 @@
1
- import { AddressIndex, Factory } from "../../config/types";
2
- import { NftlpPosition, BorrowPosition } from "../offchainTypes";
3
- import Offchain from "../../offchain";
4
- type PositionV3 = {
5
- id: string;
6
- userId: string;
7
- tokenId: string;
8
- lendingPool: {
9
- id: string;
10
- nftlp: {
11
- factory: string;
12
- };
13
- };
14
- borrowPositions: BorrowPosition[];
15
- };
16
- export declare function getAllV3PositionsData(this: Offchain, factory: Factory): Promise<AddressIndex<{
17
- [key: string]: NftlpPosition[];
18
- }>>;
19
- export declare function initializeAllV3Positions(this: Offchain, factory: Factory): Promise<AddressIndex<{
20
- [key: string]: NftlpPosition[];
21
- }>>;
22
- export declare function fetchAllV3Positions(this: Offchain, factory: Factory): Promise<PositionV3[]>;
23
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchAllV3Positions = exports.initializeAllV3Positions = exports.getAllV3PositionsData = void 0;
4
- const nftlp_1 = require("../../config/nftlp");
5
- const subgraphs_1 = require("../../config/subgraphs");
6
- /*--------------------------------------------------------------------------*
7
- * Getters *
8
- *--------------------------------------------------------------------------*/
9
- async function getAllV3PositionsData(factory) {
10
- if (!this.allV3PositionsData[factory])
11
- this.allV3PositionsData[factory] = this.initializeAllV3Positions(factory);
12
- return this.allV3PositionsData[factory];
13
- }
14
- exports.getAllV3PositionsData = getAllV3PositionsData;
15
- /*--------------------------------------------------------------------------*
16
- * Initializers *
17
- *--------------------------------------------------------------------------*/
18
- async function initializeAllV3Positions(factory) {
19
- const globalPositions = await this.fetchAllV3Positions(factory);
20
- const positions = {};
21
- for (const position of globalPositions) {
22
- const lendingPoolId = position.lendingPool.id;
23
- const userAddress = position.userId;
24
- const nftlpFactory = position.lendingPool.nftlp.factory;
25
- // Initialize empty if need
26
- if (!positions[lendingPoolId])
27
- positions[lendingPoolId] = {};
28
- if (!positions[lendingPoolId][userAddress])
29
- positions[lendingPoolId][userAddress] = [];
30
- const dex = (0, nftlp_1.getNftlpDex)(this.network, nftlpFactory);
31
- if (dex === undefined) {
32
- console.warn(`Unknown DEX for NFTLP factory ${nftlpFactory} on ${this.network}`);
33
- continue;
34
- }
35
- // Might not be needed for all positions??
36
- const endpoints = (0, nftlp_1.getNftlpSubgraph)(this.network, dex);
37
- if (!endpoints?.length) {
38
- console.warn(`No NFTLP endpoints found for ${dex} on ${this.network}`);
39
- continue;
40
- }
41
- const nftlpData = await this.getEndpointManager().fetch(endpoints, this.network, (queryBuilder) => queryBuilder.nftlpPositionQuery(lendingPoolId, position.tokenId));
42
- // Create final position object
43
- const nftlpPosition = { ...position, dex, nftlp: nftlpData.data.nftlpPositions?.[0] };
44
- // Add to results
45
- positions[lendingPoolId][userAddress].push(nftlpPosition);
46
- }
47
- return positions;
48
- }
49
- exports.initializeAllV3Positions = initializeAllV3Positions;
50
- /*--------------------------------------------------------------------------*
51
- * Fetchers *
52
- *--------------------------------------------------------------------------*/
53
- // Same as user/positionsV3
54
- async function fetchAllV3Positions(factory) {
55
- const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
56
- if (!subgraphs?.length) {
57
- console.warn(`No subgraphs found for factory ${factory} on ${this.network}`);
58
- return [];
59
- }
60
- const allPositionsData = await this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.allPositionsV3Query());
61
- return allPositionsData?.data?.positions || [];
62
- }
63
- exports.fetchAllV3Positions = fetchAllV3Positions;