impermax-sdk 2.1.292 → 2.1.293
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/index.d.ts +3 -2
- package/lib/offchain/account/offchainMultichainAccount.d.ts +9 -1
- package/lib/offchain/account/offchainMultichainAccount.js +34 -9
- package/lib/offchain/initializer/lendingPools.js +1 -5
- package/lib/offchain/initializer/user/lendingPools.js +2 -9
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +3 -3
- package/lib/offchain/lendingPool/offchainLendingPool.js +3 -3
- package/lib/offchain/offchain.d.ts +1 -1
- package/lib/offchain/offchain.js +4 -4
- package/lib/offchain/offchainMultichain.d.ts +5 -1
- package/lib/offchain/offchainMultichain.js +38 -4
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ import OffchainVault, { OffchainLendingVault, OffchainLeveragedVault, OffchainHe
|
|
|
36
36
|
import { SortDirection, VaultListOrderBy, VaultListParams, LendingPoolListParams, LendingPoolListOrderBy } from "./offchain/offchainMultichain";
|
|
37
37
|
import { VaultRisk } from "./offchain/vault/offchainVault";
|
|
38
38
|
import { LendingPoolVersion } from "./offchain/lendingPool/offchainLendingPool";
|
|
39
|
-
import { PositionType, AccountPosition } from "./offchain/account/offchainMultichainAccount";
|
|
39
|
+
import { PositionType, AccountPosition, SupplyPositionsParams, BorrowPositionsParams, TopPositionsParams, VaultPositionsParams, AccountEarningsParams } from "./offchain/account/offchainMultichainAccount";
|
|
40
40
|
import OnchainInteractionsNftlp, { OnchainInteractionsNftlpUniswapV3 } from './onchain/interactions/lendingPool/nftlp';
|
|
41
41
|
import OnchainAccountNftlpUniswapV3 from './onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3';
|
|
42
42
|
import OnchainAccountLendingPoolV3 from './onchain/account/lendingPool/onchainAccountLendingPoolV3';
|
|
@@ -66,4 +66,5 @@ import { OnchainNftlpUniswapV3 } from './onchain/impermaxFactory/lendingPool/nft
|
|
|
66
66
|
import OnchainNftlp from './onchain/impermaxFactory/lendingPool/nftlp';
|
|
67
67
|
import OnchainAccountNftlp from './onchain/account/lendingPool/nftlp';
|
|
68
68
|
import OffchainAccountBorrowableV3 from './offchain/account/lendingPool/offchainAccountBorrowableV3';
|
|
69
|
-
|
|
69
|
+
import { PairState } from "./config/whitelist";
|
|
70
|
+
export { offchain, OffchainMultichain, Offchain, OffchainPoolToken, OffchainLendingPool, OffchainCollateral, OffchainBorrowable, OffchainLendingPoolV2, OffchainCollateralV2, OffchainBorrowableV2, OffchainLendingPoolV3, OffchainCollateralV3, OffchainBorrowableV3, OffchainNftlp, OffchainNftlpUniswapV3, OffchainVault, OffchainLeveragedVault, OffchainLendingVault, OffchainHedgedVault, OffchainConfigManager, OffchainPairConfig, OffchainProposal, OffchainMultichainAccount, OffchainAccount, OffchainAccountPoolToken, OffchainAccountLendingPool, OffchainAccountCollateral, OffchainAccountBorrowable, OffchainAccountLendingPoolV2, OffchainAccountCollateralV2, OffchainAccountBorrowableV2, OffchainAccountLendingPoolV3, OffchainAccountCollateralV3, OffchainAccountBorrowableV3, OffchainAccountNftlp, OffchainAccountNftlpUniswapV3, OffchainLeveragedPosition, OffchainAccountVault, OffchainPriceHelper, OffchainSolidexHelper, PoolTokenData, BorrowableData, CollateralData, BorrowablePastData, TokenData, RewardData, PairData, FarmingPoolData, LendingPoolPastData, LendingPoolData, CollateralPosition, SupplyPosition, BorrowPosition, UserData, TvlData, XimxData, LendingVaultData, VaultPosition, PairConfigData, ProposalData, ProposalMetadata, VaultRisk, VaultType, onchain, Onchain, OnchainImpermaxFactory, OnchainImpermaxFactoryV2, OnchainImpermaxFactoryV3, OnchainPoolToken, OnchainLendingPool, OnchainBorrowable, OnchainCollateral, OnchainLendingPoolV2, OnchainBorrowableV2, OnchainCollateralV2, OnchainLendingPoolV3, OnchainBorrowableV3, OnchainCollateralV3, OnchainNftlp, OnchainNftlpUniswapV3, OnchainLendingVault, OnchainConfigManager, OnchainProposal, OnchainPairConfig, OnchainAccount, OnchainAccountPoolToken, OnchainAccountLendingPool, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingPoolV2, OnchainAccountBorrowableV2, OnchainAccountCollateralV2, OnchainAccountLendingPoolV3, OnchainAccountBorrowableV3, OnchainAccountCollateralV3, OnchainAccountNftlp, OnchainAccountNftlpUniswapV3, OnchainAccountLendingVault, OnchainContractsHelper, OnchainInteractions, OnchainInteractionsPoolToken, OnchainInteractionsLendingPool, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingPoolV2, OnchainInteractionsCollateralV2, OnchainInteractionsBorrowableV2, OnchainInteractionsLendingPoolV3, OnchainInteractionsCollateralV3, OnchainInteractionsBorrowableV3, OnchainInteractionsNftlp, OnchainInteractionsNftlpUniswapV3, OnchainInteractionsLendingVault, OnchainInteractionsConfigManager, Contract, ApprovalType, PermitData, OnchainConfig, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, CollateralConfig, BorrowableV2Config, BorrowableV3Config, PairConfig, CLAIM_AGGREGATOR, IMPERMAX_CHEF, IMX, IMPERMAX_FACTORY, getNetworkFactories, getFactoryByAddress, LENDING_VAULT_WATCHER, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2, MERKLE_DISTRIBUTOR_ETH, ROUTER, SIMPLE_UNISWAP_ORACLE, WETH, MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2, hrAmms, AMM_FACTORY, getAmmByFactory, AMM_SUBGRAPH_URLS, ADD_LIQUIDITY_URLS, AMM_LP_FEE, DEBANK_IDS, ETH_SYMBOL, ETH_NAME, SOLIDEX_FACTORIES, BORROW_FEE_FACTORIES, OLD_KINK_MULTIPLIER_FACTORIES, LIQUIDATION_FEE_FACTORIES, V2_FACTORIES, Farms, hrFarms, FarmIndex, STAKED_LP_FACTORY, getFarmByStakedLPFactory, NOT_SYNCED, DEADLINE, ZERO, APPROVE_AMOUNT, IMPERMAX_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, BLOCKS_SUBGRAPH_URL, XIMX_SUBGRAPH_URL, Networks, Factory, Extension, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable, decimalToBalance, MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice, isV3Factory, UniswapV3Position, UniswapV2Position, Position, BorrowableEntity, PairState, SupplyPositionsParams, BorrowPositionsParams, TopPositionsParams, VaultPositionsParams, AccountEarningsParams };
|
|
@@ -4,6 +4,7 @@ import OffchainAccountVault from "./vault";
|
|
|
4
4
|
import OffchainMultichain from "../offchainMultichain";
|
|
5
5
|
import OffchainAccount from "./offchainAccount";
|
|
6
6
|
import OffchainLeveragedPosition from "./lendingPool/offchainLeveragedPosition";
|
|
7
|
+
import { PairState } from '../../config/whitelist';
|
|
7
8
|
export declare enum LeveragedPositionsOrderBy {
|
|
8
9
|
TVL = 0
|
|
9
10
|
}
|
|
@@ -20,16 +21,18 @@ export declare enum BorrowPositionsOrderBy {
|
|
|
20
21
|
}
|
|
21
22
|
export interface SupplyPositionsParams {
|
|
22
23
|
networks?: Array<Networks>;
|
|
24
|
+
pairState?: PairState;
|
|
23
25
|
}
|
|
24
26
|
export interface BorrowPositionsParams {
|
|
25
27
|
networks?: Array<Networks>;
|
|
26
28
|
factories?: Array<Factory>;
|
|
29
|
+
pairState?: PairState;
|
|
27
30
|
}
|
|
28
31
|
export interface VaultPositionsParams {
|
|
29
32
|
networks?: Array<Networks>;
|
|
30
33
|
}
|
|
31
34
|
export interface TopPositionsParams extends SupplyPositionsParams, VaultPositionsParams {
|
|
32
|
-
|
|
35
|
+
topPositionsLimit?: number;
|
|
33
36
|
}
|
|
34
37
|
export declare enum PositionType {
|
|
35
38
|
MARKET = "Market",
|
|
@@ -47,6 +50,7 @@ export type AccountPosition = {
|
|
|
47
50
|
};
|
|
48
51
|
export type AccountEarningsParams = {
|
|
49
52
|
networks?: Array<Networks>;
|
|
53
|
+
pairState?: PairState;
|
|
50
54
|
};
|
|
51
55
|
export default class OffchainMultichainAccount {
|
|
52
56
|
readonly offchainMultichain: OffchainMultichain;
|
|
@@ -70,4 +74,8 @@ export default class OffchainMultichainAccount {
|
|
|
70
74
|
getTotalEarningsUSD(params?: AccountEarningsParams): Promise<number>;
|
|
71
75
|
getTotalYearlyYieldUSD(params?: AccountEarningsParams): Promise<number>;
|
|
72
76
|
getTotalDailyYieldUSD(params?: AccountEarningsParams): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* 1. Filter by whitelisted/deprecated/blacklisted pairs
|
|
79
|
+
*/
|
|
80
|
+
filterPairState(offchainAccountLendingPools: Array<OffchainAccountLendingPool>, pairState: PairState): OffchainAccountLendingPool[];
|
|
73
81
|
}
|
|
@@ -61,8 +61,11 @@ class OffchainMultichainAccount {
|
|
|
61
61
|
}
|
|
62
62
|
return Promise.all(positions);
|
|
63
63
|
});
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
let results = (await Promise.all(networkPromises)).flat();
|
|
65
|
+
// Apply filters
|
|
66
|
+
if (params.pairState)
|
|
67
|
+
results = this.filterPairState(results, params.pairState);
|
|
68
|
+
return results;
|
|
66
69
|
}
|
|
67
70
|
async getBorrowPositions(params = {}, orderBy = BorrowPositionsOrderBy.TVL) {
|
|
68
71
|
const allNetworks = params.networks ?? Object.values(types_1.Networks);
|
|
@@ -84,8 +87,11 @@ class OffchainMultichainAccount {
|
|
|
84
87
|
}
|
|
85
88
|
return Promise.all(positions);
|
|
86
89
|
});
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
let results = (await Promise.all(networkPromises)).flat();
|
|
91
|
+
// Apply filters
|
|
92
|
+
if (params.pairState)
|
|
93
|
+
results = this.filterPairState(results, params.pairState);
|
|
94
|
+
return results;
|
|
89
95
|
}
|
|
90
96
|
async getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
|
|
91
97
|
const allNetworks = params.networks ?? Object.values(types_1.Networks);
|
|
@@ -111,7 +117,7 @@ class OffchainMultichainAccount {
|
|
|
111
117
|
}
|
|
112
118
|
// Gets the top positions for a user
|
|
113
119
|
async getTopPositions(params = {}) {
|
|
114
|
-
const
|
|
120
|
+
const topPositionsLimit = params.topPositionsLimit ?? 10;
|
|
115
121
|
const [supplyPositions, vaultPositions] = await Promise.all([
|
|
116
122
|
this.getSupplyPositions(params),
|
|
117
123
|
this.getVaultPositions(params),
|
|
@@ -156,15 +162,15 @@ class OffchainMultichainAccount {
|
|
|
156
162
|
}));
|
|
157
163
|
const allPositions = [...supplyValues, ...vaultValues].sort((a, b) => b.value - a.value);
|
|
158
164
|
const totalValue = allPositions.reduce((sum, pos) => sum + pos.value, 0);
|
|
159
|
-
if (allPositions.length <=
|
|
165
|
+
if (allPositions.length <= topPositionsLimit || topPositionsLimit <= 1) {
|
|
160
166
|
return allPositions.map((pos) => ({
|
|
161
167
|
...pos,
|
|
162
168
|
percentage: (pos.value / totalValue) * 100,
|
|
163
169
|
}));
|
|
164
170
|
}
|
|
165
171
|
// Top N-1 positions and calculate "Other"
|
|
166
|
-
const topNMinusOne = allPositions.slice(0,
|
|
167
|
-
const remainingPositions = allPositions.slice(
|
|
172
|
+
const topNMinusOne = allPositions.slice(0, topPositionsLimit - 1);
|
|
173
|
+
const remainingPositions = allPositions.slice(topPositionsLimit - 1);
|
|
168
174
|
const remainingValue = remainingPositions.reduce((sum, pos) => sum + pos.value, 0);
|
|
169
175
|
const result = [
|
|
170
176
|
...topNMinusOne,
|
|
@@ -227,7 +233,10 @@ class OffchainMultichainAccount {
|
|
|
227
233
|
}
|
|
228
234
|
return Promise.all(positions);
|
|
229
235
|
});
|
|
230
|
-
|
|
236
|
+
let results = (await Promise.all(networkPromises)).flat();
|
|
237
|
+
// Apply filters
|
|
238
|
+
if (params.pairState)
|
|
239
|
+
results = this.filterPairState(results, params.pairState);
|
|
231
240
|
return results.flat();
|
|
232
241
|
}
|
|
233
242
|
// -------------------------------
|
|
@@ -273,5 +282,21 @@ class OffchainMultichainAccount {
|
|
|
273
282
|
const yearlyYield = await this.getTotalYearlyYieldUSD(params);
|
|
274
283
|
return yearlyYield / 365;
|
|
275
284
|
}
|
|
285
|
+
// --------------- Filters -----------------
|
|
286
|
+
/**
|
|
287
|
+
* 1. Filter by whitelisted/deprecated/blacklisted pairs
|
|
288
|
+
*/
|
|
289
|
+
filterPairState(offchainAccountLendingPools, pairState) {
|
|
290
|
+
if (!pairState.whitelisted && !pairState.blacklisted && !pairState.deprecated)
|
|
291
|
+
return offchainAccountLendingPools;
|
|
292
|
+
const pools = [];
|
|
293
|
+
if (pairState.whitelisted)
|
|
294
|
+
pools.push(...offchainAccountLendingPools.filter(i => i.getLendingPool().isWhitelisted()));
|
|
295
|
+
if (pairState.blacklisted)
|
|
296
|
+
pools.push(...offchainAccountLendingPools.filter(i => i.getLendingPool().isBlacklisted()));
|
|
297
|
+
if (pairState.deprecated)
|
|
298
|
+
pools.push(...offchainAccountLendingPools.filter(i => i.getLendingPool().isDeprecated()));
|
|
299
|
+
return pools;
|
|
300
|
+
}
|
|
276
301
|
}
|
|
277
302
|
exports.default = OffchainMultichainAccount;
|
|
@@ -113,12 +113,8 @@ async function fetchLendingPools() {
|
|
|
113
113
|
const factories = [];
|
|
114
114
|
let factory;
|
|
115
115
|
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
116
|
-
// Only query for pairs in the pairs list
|
|
117
|
-
const pairs = this.getPairsList(factory, { whitelisted: true, deprecated: true });
|
|
118
|
-
if (pairs.length === 0)
|
|
119
|
-
continue;
|
|
120
116
|
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
121
|
-
calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory,
|
|
117
|
+
calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, [], this.network)));
|
|
122
118
|
factories.push(factory);
|
|
123
119
|
}
|
|
124
120
|
const results = await Promise.all(calls);
|
|
@@ -35,12 +35,6 @@ 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, { whitelisted: true, deprecated: true });
|
|
42
|
-
if (pairs.length === 0)
|
|
43
|
-
continue;
|
|
44
38
|
// Get collateral/borrow positions for V2/V3
|
|
45
39
|
if ((0, offchainTypes_1.isV3Factory)(factory)) {
|
|
46
40
|
// TODO: V3 pair filter (nftlp)
|
|
@@ -49,7 +43,7 @@ async function initializeUserData(account) {
|
|
|
49
43
|
}
|
|
50
44
|
else {
|
|
51
45
|
// Pass filtered pairs
|
|
52
|
-
const v2Data = await (0, positionsV2_1.initializeV2Positions)(this, factory, userDataOfFactory,
|
|
46
|
+
const v2Data = await (0, positionsV2_1.initializeV2Positions)(this, factory, userDataOfFactory, []);
|
|
53
47
|
result[factory].collateralPositions = v2Data.collateralPositions;
|
|
54
48
|
result[factory].borrowPositions = v2Data.borrowPositions;
|
|
55
49
|
}
|
|
@@ -57,8 +51,7 @@ async function initializeUserData(account) {
|
|
|
57
51
|
for (const supplyPosition of userDataOfFactory.supplyPositions) {
|
|
58
52
|
const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
|
|
59
53
|
// Don't include supply positions if lending pool is not in pair list
|
|
60
|
-
if (pairs.length > 0 && !pairs.includes(lendingPoolId))
|
|
61
|
-
continue;
|
|
54
|
+
// if (pairs.length > 0 && !pairs.includes(lendingPoolId)) continue
|
|
62
55
|
const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
63
56
|
const borrowableA = (await this.getLendingPool(factory, lendingPoolId)).getBorrowableA();
|
|
64
57
|
const addressA = await borrowableA.getUnderlyingAddress();
|
|
@@ -60,9 +60,9 @@ export default abstract class OffchainLendingPool {
|
|
|
60
60
|
getKinkMultiplier(): 2 | 5;
|
|
61
61
|
abstract getTotalAPR(): Promise<number>;
|
|
62
62
|
getTVL(): Promise<number>;
|
|
63
|
-
isDeprecated():
|
|
64
|
-
isBlacklisted():
|
|
65
|
-
isWhitelisted():
|
|
63
|
+
isDeprecated(): boolean;
|
|
64
|
+
isBlacklisted(): boolean;
|
|
65
|
+
isWhitelisted(): boolean;
|
|
66
66
|
isLowTVL(): Promise<boolean>;
|
|
67
67
|
isHighTVL(): Promise<boolean>;
|
|
68
68
|
isStable(): Promise<boolean>;
|
|
@@ -121,19 +121,19 @@ class OffchainLendingPool {
|
|
|
121
121
|
return supply0USD + supply1USD + lpUSD;
|
|
122
122
|
}
|
|
123
123
|
// Flags
|
|
124
|
-
|
|
124
|
+
isDeprecated() {
|
|
125
125
|
const deprecatedPairs = this.getOffchain().getPairsList(this.factory, { deprecated: true });
|
|
126
126
|
if (!deprecatedPairs)
|
|
127
127
|
return false;
|
|
128
128
|
return deprecatedPairs.includes(this.pairAddress);
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
isBlacklisted() {
|
|
131
131
|
const blacklistedPairs = this.getOffchain().getPairsList(this.factory, { blacklisted: true });
|
|
132
132
|
if (!blacklistedPairs)
|
|
133
133
|
return false;
|
|
134
134
|
return blacklistedPairs.includes(this.pairAddress);
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
isWhitelisted() {
|
|
137
137
|
const whitelistedPairs = this.getOffchain().getPairsList(this.factory, { whitelisted: true });
|
|
138
138
|
if (!whitelistedPairs)
|
|
139
139
|
return false;
|
|
@@ -102,7 +102,7 @@ export default class Offchain {
|
|
|
102
102
|
getNftlpsData: typeof initializer.getNftlpsData;
|
|
103
103
|
getNftlpData: typeof initializer.getNftlpData;
|
|
104
104
|
protected initializeNftlpsData: typeof initializer.initializeNftlpsData;
|
|
105
|
-
getPairsList(factory: Factory, state
|
|
105
|
+
getPairsList(factory: Factory, state?: PairState): Address[];
|
|
106
106
|
getCrossChainTVL(): Promise<number>;
|
|
107
107
|
getCrossChainTotalValueSupplied(): Promise<number>;
|
|
108
108
|
getCrossChainTotalValueBorrowed(): Promise<number>;
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -152,17 +152,17 @@ class Offchain {
|
|
|
152
152
|
* Pairs to get data, passed in constructor
|
|
153
153
|
* -------------------------------------------------*/
|
|
154
154
|
// Returns pairs list based on pair state.
|
|
155
|
-
//
|
|
155
|
+
// NOTE: Remove this function and access state directly?
|
|
156
156
|
getPairsList(factory, state) {
|
|
157
157
|
const pairs = [];
|
|
158
158
|
const whitelisted = this.whitelistedPairs[factory] ?? [];
|
|
159
159
|
const deprecated = this.deprecatedPairs[factory] ?? [];
|
|
160
160
|
const blacklisted = this.blacklistedPairs[factory] ?? [];
|
|
161
|
-
if (state
|
|
161
|
+
if (state?.whitelisted)
|
|
162
162
|
pairs.push(...whitelisted);
|
|
163
|
-
if (state
|
|
163
|
+
if (state?.deprecated)
|
|
164
164
|
pairs.push(...deprecated);
|
|
165
|
-
if (state
|
|
165
|
+
if (state?.blacklisted)
|
|
166
166
|
pairs.push(...blacklisted);
|
|
167
167
|
return pairs.map(i => i.toLowerCase());
|
|
168
168
|
}
|
|
@@ -49,7 +49,6 @@ export interface LendingPoolListParams {
|
|
|
49
49
|
searchInput?: string;
|
|
50
50
|
amm?: Array<Amms>;
|
|
51
51
|
farm?: Array<Farms>;
|
|
52
|
-
deprecated?: boolean;
|
|
53
52
|
stable?: boolean;
|
|
54
53
|
highTvl?: boolean;
|
|
55
54
|
pairState?: PairState;
|
|
@@ -71,6 +70,11 @@ export default class OffchainMultichain {
|
|
|
71
70
|
getVaultList(params?: VaultListParams): Promise<Array<OffchainVault>>;
|
|
72
71
|
networkHasVault(network: Networks): boolean;
|
|
73
72
|
getLendingPoolList(params?: LendingPoolListParams): Promise<Array<OffchainLendingPool>>;
|
|
73
|
+
filterPairState(offchainLendingPools: Array<OffchainLendingPool>, pairState: PairState): OffchainLendingPool[];
|
|
74
|
+
/**
|
|
75
|
+
* 2. Filter by lending pool version
|
|
76
|
+
*/
|
|
77
|
+
private filterVersion;
|
|
74
78
|
getMultichainAccount(accountAddress: Address): OffchainMultichainAccount;
|
|
75
79
|
getMultichainBorrowersList(params?: BorrowersListParams): Promise<OffchainAccount[]>;
|
|
76
80
|
}
|
|
@@ -98,8 +98,12 @@ class OffchainMultichain {
|
|
|
98
98
|
networkHasVault(network) {
|
|
99
99
|
return Object.keys(subgraphs_1.VAULT_SUBGRAPH_URL[network]).length > 0;
|
|
100
100
|
}
|
|
101
|
+
/*-------------------- Vault Filters ---------------------*
|
|
102
|
+
|
|
103
|
+
// TODO: Vault filters
|
|
104
|
+
|
|
101
105
|
/*--------------------------------------------------------*
|
|
102
|
-
*
|
|
106
|
+
* Lending Pools
|
|
103
107
|
*--------------------------------------------------------*/
|
|
104
108
|
// private async getVaultSortValue( vault: OffchainVault, orderBy: VaultOrderBy,): Promise<number> { }
|
|
105
109
|
async getLendingPoolList(params = {}) {
|
|
@@ -117,12 +121,42 @@ class OffchainMultichain {
|
|
|
117
121
|
const factoryResults = await Promise.all(factoryPromises);
|
|
118
122
|
return factoryResults.flat();
|
|
119
123
|
});
|
|
120
|
-
|
|
124
|
+
let results = (await Promise.all(networkPromises)).flat();
|
|
121
125
|
console.timeEnd("Lending Pools");
|
|
122
|
-
|
|
126
|
+
// Apply filters
|
|
127
|
+
if (params.pairState)
|
|
128
|
+
results = this.filterPairState(results, params.pairState);
|
|
129
|
+
if (params.version)
|
|
130
|
+
results = this.filterVersion(results, params.version);
|
|
131
|
+
// Apply other filters here
|
|
132
|
+
return results;
|
|
133
|
+
}
|
|
134
|
+
/*-------------------- Pool Filters ---------------------*
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 1. Filter by whitelisted/deprecated/blacklisted pairs
|
|
138
|
+
*/
|
|
139
|
+
filterPairState(offchainLendingPools, pairState) {
|
|
140
|
+
if (!pairState.whitelisted && !pairState.blacklisted && !pairState.deprecated)
|
|
141
|
+
return offchainLendingPools;
|
|
142
|
+
const pools = [];
|
|
143
|
+
if (pairState.whitelisted)
|
|
144
|
+
pools.push(...offchainLendingPools.filter(i => i.isWhitelisted()));
|
|
145
|
+
if (pairState.blacklisted)
|
|
146
|
+
pools.push(...offchainLendingPools.filter(i => i.isBlacklisted()));
|
|
147
|
+
if (pairState.deprecated)
|
|
148
|
+
pools.push(...offchainLendingPools.filter(i => i.isDeprecated()));
|
|
149
|
+
return pools;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 2. Filter by lending pool version
|
|
153
|
+
*/
|
|
154
|
+
filterVersion(offchainLendingPools, version) {
|
|
155
|
+
return offchainLendingPools.filter(i => i.getLendingPoolVersion() === version);
|
|
123
156
|
}
|
|
157
|
+
// Add more lending pool filters here
|
|
124
158
|
/*--------------------------------------------------------*
|
|
125
|
-
*
|
|
159
|
+
* 3. Account
|
|
126
160
|
*--------------------------------------------------------*/
|
|
127
161
|
getMultichainAccount(accountAddress) {
|
|
128
162
|
if (!this.multichainAccounts[accountAddress]) {
|