impermax-sdk 2.1.236 → 2.1.238
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/lendingPools.js +3 -1
- package/lib/offchain/initializer/user/lendingPools.js +9 -2
- package/lib/offchain/initializer/user/positionsV2.d.ts +1 -1
- package/lib/offchain/initializer/user/positionsV2.js +5 -3
- package/lib/offchain/offchain.d.ts +3 -17
- package/lib/offchain/offchain.js +12 -29
- package/lib/offchain/offchainMultichain.d.ts +1 -1
- package/lib/offchain/offchainMultichain.js +2 -2
- package/package.json +1 -1
|
@@ -176,8 +176,10 @@ async function fetchLendingPools() {
|
|
|
176
176
|
const factories = [];
|
|
177
177
|
let factory;
|
|
178
178
|
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
179
|
+
// Only query for pairs in the pairs list
|
|
180
|
+
const pairs = this.getPairsList(factory);
|
|
179
181
|
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
180
|
-
calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory,
|
|
182
|
+
calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, pairs, this.network)));
|
|
181
183
|
factories.push(factory);
|
|
182
184
|
}
|
|
183
185
|
const results = await Promise.all(calls);
|
|
@@ -35,20 +35,27 @@ async function initializeUserData(account) {
|
|
|
35
35
|
supplyPositions: {},
|
|
36
36
|
borrowPositions: {},
|
|
37
37
|
};
|
|
38
|
+
// Get whitelisted + deprecated pairs for this network and factory
|
|
39
|
+
// Unlike lending pools user queries can't be filtered by lending pool id,
|
|
40
|
+
// so we filter manually.
|
|
41
|
+
const pairs = this.getPairsList(factory);
|
|
38
42
|
// Get collateral/borrow positions for V2/V3
|
|
39
43
|
if ((0, offchainTypes_1.isV3Factory)(factory)) {
|
|
44
|
+
// TODO: V3 pair filter (nftlp)
|
|
40
45
|
const v3Data = await (0, positionsV3_1.initializeV3Positions)(this, factory, userDataOfFactory);
|
|
41
46
|
result[factory].positions = v3Data.positions;
|
|
42
47
|
}
|
|
43
48
|
else {
|
|
44
|
-
|
|
49
|
+
// Pass filtered pairs
|
|
50
|
+
const v2Data = await (0, positionsV2_1.initializeV2Positions)(this, factory, userDataOfFactory, pairs);
|
|
45
51
|
result[factory].collateralPositions = v2Data.collateralPositions;
|
|
46
52
|
result[factory].borrowPositions = v2Data.borrowPositions;
|
|
47
53
|
}
|
|
48
54
|
// Supply positions is same for v2 and v3
|
|
49
55
|
for (const supplyPosition of userDataOfFactory.supplyPositions) {
|
|
50
56
|
const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
|
|
51
|
-
if
|
|
57
|
+
// Don't include supply positions if lending pool is not in pair list
|
|
58
|
+
if (pairs.length > 0 && !pairs.includes(lendingPoolId))
|
|
52
59
|
continue;
|
|
53
60
|
const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
54
61
|
const borrowableA = (await this.getLendingPool(factory, lendingPoolId)).getBorrowableA();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressIndex, Factory, PoolTokenType } from "../../../config/types";
|
|
2
2
|
import { CollateralPosition, BorrowPosition, RawV2UserData } from "../../offchainTypes";
|
|
3
3
|
import Offchain from "../../offchain";
|
|
4
|
-
export declare function initializeV2Positions(offchain: Offchain, factory: Factory, rawUserData: RawV2UserData): Promise<{
|
|
4
|
+
export declare function initializeV2Positions(offchain: Offchain, factory: Factory, rawUserData: RawV2UserData, pairs: Array<string>): Promise<{
|
|
5
5
|
collateralPositions: AddressIndex<CollateralPosition[]>;
|
|
6
6
|
borrowPositions: AddressIndex<{
|
|
7
7
|
[key in PoolTokenType]?: BorrowPosition;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initializeV2Positions = void 0;
|
|
4
4
|
const types_1 = require("../../../config/types");
|
|
5
|
-
async function initializeV2Positions(offchain, factory, rawUserData) {
|
|
5
|
+
async function initializeV2Positions(offchain, factory, rawUserData, pairs) {
|
|
6
6
|
const collateralPositions = {};
|
|
7
7
|
const borrowPositions = {};
|
|
8
8
|
// Collateral positions
|
|
9
9
|
for (const collateralPosition of rawUserData.collateralPositions) {
|
|
10
10
|
const lendingPoolId = collateralPosition.collateral.lendingPool.id;
|
|
11
|
-
if
|
|
11
|
+
// Don't include collateral positions if lending pool is not in pair list
|
|
12
|
+
if (pairs.length > 0 && !pairs.includes(lendingPoolId))
|
|
12
13
|
continue;
|
|
13
14
|
if (!collateralPositions[lendingPoolId])
|
|
14
15
|
collateralPositions[lendingPoolId] = [];
|
|
@@ -17,7 +18,8 @@ async function initializeV2Positions(offchain, factory, rawUserData) {
|
|
|
17
18
|
// Borrow positions
|
|
18
19
|
for (const borrowPosition of rawUserData.borrowPositions) {
|
|
19
20
|
const lendingPoolId = borrowPosition.borrowable.lendingPool.id;
|
|
20
|
-
if
|
|
21
|
+
// Don't include borrow positions if lending pool is not in pair list
|
|
22
|
+
if (pairs.length > 0 && !pairs.includes(lendingPoolId))
|
|
21
23
|
continue;
|
|
22
24
|
const underlyingId = borrowPosition.borrowable.underlying.id;
|
|
23
25
|
const borrowableA = (await offchain.getLendingPool(factory, lendingPoolId)).getBorrowableA();
|
|
@@ -18,6 +18,7 @@ export default class Offchain {
|
|
|
18
18
|
readonly network: Networks;
|
|
19
19
|
readonly chainId: number;
|
|
20
20
|
readonly whitelistedPairs: FactoryIndex<Address[]>;
|
|
21
|
+
readonly deprecatedPairs: FactoryIndex<Address[]>;
|
|
21
22
|
protected lendingPools: LendingPoolIndex<OffchainLendingPool>;
|
|
22
23
|
protected vaults: AddressIndex<OffchainVault>;
|
|
23
24
|
protected accounts: AddressIndex<OffchainAccount>;
|
|
@@ -46,7 +47,7 @@ export default class Offchain {
|
|
|
46
47
|
}>>;
|
|
47
48
|
};
|
|
48
49
|
protected borrowersList: Promise<OffchainAccount[]> | null;
|
|
49
|
-
constructor(offchainMultichain: OffchainMultichain, network: Networks, whitelist?: FactoryIndex<Address[]>);
|
|
50
|
+
constructor(offchainMultichain: OffchainMultichain, network: Networks, whitelist?: FactoryIndex<Address[]>, deprecated?: FactoryIndex<Address[]>);
|
|
50
51
|
cleanCache(): void;
|
|
51
52
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
|
|
52
53
|
getVault(vaultAddress: Address): Promise<OffchainVault>;
|
|
@@ -93,22 +94,7 @@ export default class Offchain {
|
|
|
93
94
|
protected fetchBorrowersList: typeof initializer.fetchBorrowersList;
|
|
94
95
|
protected initializeBorrowersList: typeof initializer.initializeBorrowersList;
|
|
95
96
|
getBorrowersList: typeof initializer.getBorrowersList;
|
|
96
|
-
|
|
97
|
-
* DATA GETTERS
|
|
98
|
-
*/
|
|
99
|
-
getPairList(): Promise<{
|
|
100
|
-
pairAddress: string;
|
|
101
|
-
factory: Factory;
|
|
102
|
-
}[]>;
|
|
103
|
-
private getPairData;
|
|
104
|
-
getPairListWithData(pairList: {
|
|
105
|
-
pairAddress: string;
|
|
106
|
-
factory: Factory;
|
|
107
|
-
}[]): Promise<{
|
|
108
|
-
pairAddress: Address;
|
|
109
|
-
factory: Factory;
|
|
110
|
-
totalBorrowsUSD: number;
|
|
111
|
-
}[]>;
|
|
97
|
+
getPairsList(factory: Factory): string[];
|
|
112
98
|
getCrossChainTVL(): Promise<number>;
|
|
113
99
|
getCrossChainTotalValueSupplied(): Promise<number>;
|
|
114
100
|
getCrossChainTotalValueBorrowed(): Promise<number>;
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -33,8 +33,9 @@ const offchainVault_1 = __importDefault(require("./vault/offchainVault"));
|
|
|
33
33
|
const configManager_1 = __importDefault(require("./configManager"));
|
|
34
34
|
const chainId_1 = require("../config/chainId");
|
|
35
35
|
class Offchain {
|
|
36
|
-
constructor(offchainMultichain, network, whitelist) {
|
|
36
|
+
constructor(offchainMultichain, network, whitelist, deprecated) {
|
|
37
37
|
this.whitelistedPairs = {};
|
|
38
|
+
this.deprecatedPairs = {};
|
|
38
39
|
this.allV3PositionsData = {};
|
|
39
40
|
this.getSolidexHelper = () => this.solidexHelper;
|
|
40
41
|
this.getConfigManager = () => this.configManager;
|
|
@@ -90,9 +91,8 @@ class Offchain {
|
|
|
90
91
|
// TODO fix conflicting lines (commented)
|
|
91
92
|
//this.network = cfg.network;
|
|
92
93
|
//this.chainId = cfg.chainId;
|
|
93
|
-
// TODO: refactor way of doing whitelist, messing up with user query since pairs dont get initialized
|
|
94
|
-
// this.whitelistedPairs = whitelist ?? {};
|
|
95
94
|
this.whitelistedPairs = whitelist ?? {};
|
|
95
|
+
this.deprecatedPairs = deprecated ?? {};
|
|
96
96
|
this.offchainMultichain = offchainMultichain;
|
|
97
97
|
this.network = network;
|
|
98
98
|
this.chainId = chainId_1.CHAIN_IDS[network];
|
|
@@ -137,32 +137,15 @@ class Offchain {
|
|
|
137
137
|
this.accounts[accountAddress] = new account_1.default(this, accountAddress);
|
|
138
138
|
return this.accounts[accountAddress];
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for (const pairAddress in lendingPoolData[factory]) {
|
|
150
|
-
result.push({ pairAddress, factory });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
async getPairData(factory, pairAddress) {
|
|
156
|
-
const lendingPool = await this.getLendingPool(factory, pairAddress);
|
|
157
|
-
const totalBorrowsUSD = await lendingPool.getTotalBorrowsUSD();
|
|
158
|
-
return { pairAddress, factory, totalBorrowsUSD };
|
|
159
|
-
}
|
|
160
|
-
async getPairListWithData(pairList) {
|
|
161
|
-
const requests = [];
|
|
162
|
-
for (const pair of pairList) {
|
|
163
|
-
requests.push(this.getPairData(pair.factory, pair.pairAddress));
|
|
164
|
-
}
|
|
165
|
-
return Promise.all(requests);
|
|
140
|
+
/* --------------------------------------------------
|
|
141
|
+
* Pairs to get data, passed in constructor
|
|
142
|
+
* -------------------------------------------------*/
|
|
143
|
+
// Returns the unique whitelisted + deprecated pairs list to show on the frontend.
|
|
144
|
+
getPairsList(factory) {
|
|
145
|
+
const whitelistedPairs = this.whitelistedPairs[factory] ?? [];
|
|
146
|
+
const deprecatedPairs = this.deprecatedPairs[factory] ?? [];
|
|
147
|
+
const pairs = [...whitelistedPairs, ...deprecatedPairs].map(i => i.toLowerCase());
|
|
148
|
+
return pairs;
|
|
166
149
|
}
|
|
167
150
|
/* --------------------------------------------------
|
|
168
151
|
* Cross chain stats
|
|
@@ -62,7 +62,7 @@ export default class OffchainMultichain {
|
|
|
62
62
|
protected multichainAccounts: AddressIndex<OffchainMultichainAccount>;
|
|
63
63
|
private constructor();
|
|
64
64
|
static get instance(): OffchainMultichain;
|
|
65
|
-
getOffchain(network: Networks, whitelist?: FactoryIndex<Address[]>): Offchain;
|
|
65
|
+
getOffchain(network: Networks, whitelist?: FactoryIndex<Address[]>, deprecated?: FactoryIndex<Address[]>): Offchain;
|
|
66
66
|
getAPRHelper(): OffchainAPRHelper;
|
|
67
67
|
getPriceHelper(): OffchainPriceHelper;
|
|
68
68
|
getEndpointManager(): OffchainEndpointManager;
|
|
@@ -61,9 +61,9 @@ class OffchainMultichain {
|
|
|
61
61
|
}
|
|
62
62
|
return __classPrivateFieldGet(OffchainMultichain, _a, "f", _OffchainMultichain_instance);
|
|
63
63
|
}
|
|
64
|
-
getOffchain(network, whitelist) {
|
|
64
|
+
getOffchain(network, whitelist, deprecated) {
|
|
65
65
|
if (!this.offchains[network])
|
|
66
|
-
this.offchains[network] = new offchain_1.default(this, network, whitelist);
|
|
66
|
+
this.offchains[network] = new offchain_1.default(this, network, whitelist, deprecated);
|
|
67
67
|
return this.offchains[network];
|
|
68
68
|
}
|
|
69
69
|
getAPRHelper() {
|