impermax-sdk 2.1.511 → 2.1.513
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/offchain.d.ts +2 -1
- package/lib/offchain/offchain.js +62 -0
- package/lib/offchain/offchainMultichain.d.ts +2 -2
- package/lib/offchain/offchainMultichain.js +13 -15
- package/lib/offchain/offchainTypes.d.ts +9 -1
- package/lib/offchain/queries/apis/ponder/index.js +0 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import OffchainLendingPool from './lendingPool';
|
|
|
3
3
|
import OffchainSolidexHelper from './offchainSolidexHelper';
|
|
4
4
|
import OffchainAccount from './account';
|
|
5
5
|
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState, Extension } from '../config/types';
|
|
6
|
-
import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XIbexData, NftlpData, PoolChart, NewlyEarnedFees, NftlpStats, XIbexUserData, NewlyEarnedReward } from './offchainTypes';
|
|
6
|
+
import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XIbexData, NftlpData, PoolChart, NewlyEarnedFees, NftlpStats, XIbexUserData, NewlyEarnedReward, NetworkTokenData } from './offchainTypes';
|
|
7
7
|
import OffchainVault from './vault/offchainVault';
|
|
8
8
|
import OffchainConfigManager from './configManager';
|
|
9
9
|
import { PairState } from '../config/whitelist';
|
|
@@ -121,4 +121,5 @@ export default class Offchain {
|
|
|
121
121
|
protected fetchNftlpsData: typeof initializer.fetchNftlpsData;
|
|
122
122
|
protected initializeNftlpsData: typeof initializer.initializeNftlpsData;
|
|
123
123
|
getPairsList(factory: Factory, state?: PairState): Address[];
|
|
124
|
+
getNetworkTokens(): Promise<NetworkTokenData[]>;
|
|
124
125
|
}
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -205,5 +205,67 @@ class Offchain {
|
|
|
205
205
|
pairs.push(...blacklisted);
|
|
206
206
|
return pairs.map(i => i.toLowerCase());
|
|
207
207
|
}
|
|
208
|
+
async getNetworkTokens() {
|
|
209
|
+
const tokenMap = new Map();
|
|
210
|
+
try {
|
|
211
|
+
const lendingPoolsData = await this.getLendingPoolsData();
|
|
212
|
+
// 1. Go through each factory
|
|
213
|
+
const factoryPromises = Object.entries(lendingPoolsData).map(async ([factory, pools]) => {
|
|
214
|
+
// 2. Go through each pool in the factory
|
|
215
|
+
const poolPromises = Object.keys(pools).map(async (poolId) => {
|
|
216
|
+
try {
|
|
217
|
+
const lendingPool = await this.getLendingPool(factory, poolId);
|
|
218
|
+
if (!lendingPool)
|
|
219
|
+
return [];
|
|
220
|
+
// 3. Get both borrowables borrowables from this pool
|
|
221
|
+
const [borrowableA, borrowableB] = await Promise.all([lendingPool.getBorrowableA(), lendingPool.getBorrowableB()]);
|
|
222
|
+
// 4. Get underlying tokens from both borrowables
|
|
223
|
+
const tokenPromises = [borrowableA, borrowableB].map(async (borrowable) => {
|
|
224
|
+
try {
|
|
225
|
+
const [address, symbol, name, decimals] = await Promise.all([
|
|
226
|
+
borrowable.getUnderlyingAddress(),
|
|
227
|
+
borrowable.getSymbol(),
|
|
228
|
+
borrowable.getName(),
|
|
229
|
+
borrowable.getDecimals(),
|
|
230
|
+
]);
|
|
231
|
+
if (!address)
|
|
232
|
+
return null;
|
|
233
|
+
return {
|
|
234
|
+
token: `${this.network}:${address}`,
|
|
235
|
+
id: address,
|
|
236
|
+
symbol,
|
|
237
|
+
name,
|
|
238
|
+
decimals,
|
|
239
|
+
chainId: this.chainId,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
console.error(`Error getting token details for borrowable in pool ${poolId}:`, error);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
// The token's data like symbol etc.
|
|
248
|
+
const tokens = await Promise.all(tokenPromises);
|
|
249
|
+
return tokens.filter((token) => token !== null);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
console.error(`Error processing pool ${poolId} in factory ${factory} on ${this.network}:`, error);
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const poolResults = await Promise.all(poolPromises);
|
|
257
|
+
return poolResults.flat();
|
|
258
|
+
});
|
|
259
|
+
const factoryResults = await Promise.all(factoryPromises);
|
|
260
|
+
const networkTokens = factoryResults.flat();
|
|
261
|
+
// Need to put then in a set to return unique tokens
|
|
262
|
+
networkTokens.forEach(tokenData => tokenMap.set(tokenData.token, tokenData));
|
|
263
|
+
return Array.from(tokenMap.values());
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
console.error(`Error processing network ${this.network}:`, error);
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
208
270
|
}
|
|
209
271
|
exports.default = Offchain;
|
|
@@ -14,7 +14,7 @@ import { AddressIndex } from "../config/types";
|
|
|
14
14
|
import OffchainAccount from "./account/offchainAccount";
|
|
15
15
|
import { PairState } from '../config/whitelist';
|
|
16
16
|
import { LlamaTvlChart } from './offchainAPRHelper';
|
|
17
|
-
import {
|
|
17
|
+
import { NetworkTokenData } from "./offchainTypes";
|
|
18
18
|
export declare enum SortDirection {
|
|
19
19
|
ASC = "asc",
|
|
20
20
|
DESC = "desc"
|
|
@@ -105,6 +105,6 @@ export default class OffchainMultichain {
|
|
|
105
105
|
*/
|
|
106
106
|
getTvlData(params?: MultichainTvlParams): Promise<MultichainTvlData>;
|
|
107
107
|
getImpermaxTvlChart(network?: Networks): Promise<LlamaTvlChart>;
|
|
108
|
-
getNetworkTokens(networks?: Networks[]): Promise<
|
|
108
|
+
getNetworkTokens(networks?: Networks[]): Promise<NetworkTokenData[]>;
|
|
109
109
|
}
|
|
110
110
|
export {};
|
|
@@ -296,21 +296,19 @@ class OffchainMultichain {
|
|
|
296
296
|
// ERC20 TOKENS
|
|
297
297
|
//
|
|
298
298
|
async getNetworkTokens(networks) {
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}));
|
|
313
|
-
return Array.from(tokenSet);
|
|
299
|
+
const allNetworks = networks || Object.values(types_1.Networks);
|
|
300
|
+
const networkPromises = allNetworks.map(async (network) => {
|
|
301
|
+
try {
|
|
302
|
+
const offchain = this.getOffchain(network);
|
|
303
|
+
return await offchain.getNetworkTokens();
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error(`Error processing network ${network}:`, error);
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
const results = await Promise.all(networkPromises);
|
|
311
|
+
return results.flat();
|
|
314
312
|
}
|
|
315
313
|
}
|
|
316
314
|
exports.default = OffchainMultichain;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, AddressIndex, PoolTokenType, ProposalState, WhitelistState, VaultType, Extension, Factory, Borrowable } from '../config/types';
|
|
1
|
+
import { Address, AddressIndex, PoolTokenType, ProposalState, WhitelistState, VaultType, Extension, Factory, Borrowable, Networks } from '../config/types';
|
|
2
2
|
import { Amms } from '../config/amms';
|
|
3
3
|
export declare const isV3Factory: (factory: string) => boolean;
|
|
4
4
|
export interface TokenData {
|
|
@@ -14,6 +14,14 @@ export interface PoolTokenData {
|
|
|
14
14
|
exchangeRate: string;
|
|
15
15
|
totalBalanceUSD: string;
|
|
16
16
|
}
|
|
17
|
+
export type NetworkTokenData = {
|
|
18
|
+
token: `${Networks}:${Address}`;
|
|
19
|
+
id: Address;
|
|
20
|
+
symbol: string;
|
|
21
|
+
name: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
chainId: number;
|
|
24
|
+
};
|
|
17
25
|
export interface BorrowableData extends PoolTokenData {
|
|
18
26
|
underlying: TokenData;
|
|
19
27
|
totalBorrows: string;
|