impermax-sdk 2.1.144 → 2.1.145

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.
@@ -37,7 +37,7 @@ exports.IMPERMAX_VAULT_API = {
37
37
  [types_1.Networks.Ropsten]: {},
38
38
  [types_1.Networks.Mainnet]: {},
39
39
  [types_1.Networks.Polygon]: {
40
- [types_1.VaultType.LENDING]: "https://polygon-lendingvaults-production.up.railway.app/vaults/"
40
+ [types_1.VaultType.LENDING]: "https://polygon-lendingvaults-production.up.railway.app/"
41
41
  },
42
42
  [types_1.Networks.Arbitrum]: {},
43
43
  [types_1.Networks.Avalanche]: {},
@@ -51,17 +51,17 @@ exports.IMPERMAX_VAULT_API = {
51
51
  [types_1.Networks.Canto]: {},
52
52
  [types_1.Networks.ZksyncEra]: {},
53
53
  [types_1.Networks.Base]: {
54
- [types_1.VaultType.LENDING]: "https://base-lendingvaults-production.up.railway.app/vaults/"
54
+ [types_1.VaultType.LENDING]: "https://base-lendingvaults-production.up.railway.app/"
55
55
  },
56
56
  [types_1.Networks.Mantle]: {},
57
57
  [types_1.Networks.Scroll]: {},
58
58
  [types_1.Networks.Optimism]: {},
59
59
  [types_1.Networks.Real]: {},
60
60
  [types_1.Networks.Blast]: {
61
- [types_1.VaultType.LENDING]: "https://blast-lendingvaults-production.up.railway.app/vaults/"
61
+ [types_1.VaultType.LENDING]: "https://blast-lendingvaults-production.up.railway.app/"
62
62
  },
63
63
  [types_1.Networks.Sonic]: {
64
- [types_1.VaultType.LENDING]: "https://sonic-lendingvaults-production.up.railway.app/vaults/"
64
+ [types_1.VaultType.LENDING]: "https://sonic-lendingvaults-production.up.railway.app/"
65
65
  },
66
66
  [types_1.Networks.Linea]: {},
67
67
  };
@@ -8,3 +8,4 @@ export * from './whitelist';
8
8
  export * from './staking';
9
9
  export * from './farming';
10
10
  export * from './tvl';
11
+ export * from './private-api';
@@ -24,3 +24,4 @@ __exportStar(require("./whitelist"), exports);
24
24
  __exportStar(require("./staking"), exports);
25
25
  __exportStar(require("./farming"), exports);
26
26
  __exportStar(require("./tvl"), exports);
27
+ __exportStar(require("./private-api"), exports);
@@ -0,0 +1,5 @@
1
+ import { AddressIndex, VaultType, Address } from "../../config/types";
2
+ import { VaultBorrowable } from "../offchainTypes";
3
+ import Offchain from "../offchain";
4
+ export declare function fetchVaultBorrowables(this: Offchain, vaultType: VaultType): Promise<AddressIndex<VaultBorrowable[]>>;
5
+ export declare function getVaultBorrowables(this: Offchain, vaultType: VaultType, vaultAddress: Address): Promise<VaultBorrowable[] | null>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // private-api: Vault borrowables
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getVaultBorrowables = exports.fetchVaultBorrowables = void 0;
5
+ const private_api_1 = require("../../config/private-api");
6
+ // NOTE: Refactor private-api calls into their own module?
7
+ async function fetchVaultBorrowables(vaultType) {
8
+ const api = private_api_1.IMPERMAX_VAULT_API[this.network][vaultType];
9
+ if (!api) {
10
+ console.log(`Missing API for ${vaultType} on ${this.network}?`);
11
+ return {};
12
+ }
13
+ try {
14
+ const response = await fetch(api.concat('borrowables')).then(i => i.json());
15
+ return response.reduce((acc, borrowable) => {
16
+ const vaultId = borrowable.lendingVaultId.toLowerCase();
17
+ if (!acc[vaultId])
18
+ acc[vaultId] = [];
19
+ acc[vaultId].push(borrowable);
20
+ return acc;
21
+ }, {});
22
+ }
23
+ catch (err) {
24
+ console.log(`Failed to fetch vault borrowables for ${vaultType} on ${this.network}`);
25
+ return {};
26
+ }
27
+ }
28
+ exports.fetchVaultBorrowables = fetchVaultBorrowables;
29
+ async function getVaultBorrowables(vaultType, vaultAddress) {
30
+ if (!this.vaultBorrowablesData[vaultType]) {
31
+ this.vaultBorrowablesData[vaultType] = this.fetchVaultBorrowables(vaultType);
32
+ }
33
+ const borrowablesMap = await this.vaultBorrowablesData[vaultType];
34
+ return borrowablesMap?.[vaultAddress.toLowerCase()] || null;
35
+ }
36
+ exports.getVaultBorrowables = getVaultBorrowables;
@@ -1,12 +1,9 @@
1
1
  import * as initializer from './initializer';
2
2
  import OffchainLendingPool from './lendingPool';
3
- import OffchainPriceHelper from './offchainPriceHelper';
4
- import OffchainAPRHelper from './offchainAPRHelper';
5
3
  import OffchainSolidexHelper from './offchainSolidexHelper';
6
4
  import OffchainAccount from './account';
7
- import OffchainEndpointManager from './offchainEndpointManager';
8
- import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState } from '../config/types';
9
- import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData } from './offchainTypes';
5
+ import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState, VaultType } from '../config/types';
6
+ import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable } from './offchainTypes';
10
7
  import OffchainVault from './vault/offchainVault';
11
8
  import OffchainConfigManager from './configManager';
12
9
  import { LlamaTvlChart } from './offchainAPRHelper';
@@ -40,6 +37,9 @@ export default class Offchain {
40
37
  protected vaultsUsersData: {
41
38
  [key in Address]?: Promise<AddressIndex<AddressIndex<VaultPosition>>>;
42
39
  };
40
+ protected vaultBorrowablesData: {
41
+ [key in VaultType]?: Promise<AddressIndex<VaultBorrowable[]>>;
42
+ };
43
43
  constructor(offchainMultichain: OffchainMultichain, network: Networks, whitelist?: FactoryIndex<Address[]>);
44
44
  cleanCache(): void;
45
45
  getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
@@ -47,9 +47,9 @@ export default class Offchain {
47
47
  getAccount(accountAddress: Address): OffchainAccount;
48
48
  getSolidexHelper: () => OffchainSolidexHelper;
49
49
  getConfigManager: () => OffchainConfigManager;
50
- getPriceHelper: () => OffchainPriceHelper;
51
- getAPRHelper: () => OffchainAPRHelper;
52
- getEndpointManager: () => OffchainEndpointManager;
50
+ getPriceHelper: () => import("./offchainPriceHelper").default;
51
+ getAPRHelper: () => import("./offchainAPRHelper").default;
52
+ getEndpointManager: () => import("./offchainEndpointManager").default;
53
53
  apolloFetcher: typeof initializer.apolloFetcher;
54
54
  protected fetchLendingPools: typeof initializer.fetchLendingPools;
55
55
  protected fetchLendingPoolsPast: typeof initializer.fetchLendingPoolsPast;
@@ -79,6 +79,8 @@ export default class Offchain {
79
79
  getVaultData: typeof initializer.getVaultData;
80
80
  protected fetchVaultsUserData: typeof initializer.fetchVaultsUserData;
81
81
  protected initializeVaultsUserData: typeof initializer.initializeVaultsUserData;
82
+ protected fetchVaultBorrowables: typeof initializer.fetchVaultBorrowables;
83
+ getVaultBorrowables: typeof initializer.getVaultBorrowables;
82
84
  /**
83
85
  * DATA GETTERS
84
86
  */
@@ -78,6 +78,8 @@ class Offchain {
78
78
  this.getVaultData = initializer.getVaultData;
79
79
  this.fetchVaultsUserData = initializer.fetchVaultsUserData;
80
80
  this.initializeVaultsUserData = initializer.initializeVaultsUserData;
81
+ this.fetchVaultBorrowables = initializer.fetchVaultBorrowables;
82
+ this.getVaultBorrowables = initializer.getVaultBorrowables;
81
83
  // TODO fix conflicting lines (commented)
82
84
  //this.network = cfg.network;
83
85
  //this.chainId = cfg.chainId;
@@ -92,6 +94,7 @@ class Offchain {
92
94
  this.accounts = {};
93
95
  this.usersData = {};
94
96
  this.vaultsUsersData = {};
97
+ this.vaultBorrowablesData = {};
95
98
  }
96
99
  cleanCache() {
97
100
  this.lendingPoolsData = null;
@@ -93,7 +93,7 @@ class OffchainAPRHelper {
93
93
  }
94
94
  async initializeShadowPools() {
95
95
  try {
96
- const response = await fetch("https://sdk-api-production.up.railway.app/api/apr/sonic/shadow").then((i) => i.json());
96
+ const response = await fetch("https://api.shadow.so/mixed-pairs").then((i) => i.json());
97
97
  this.shadowAllPools = response.pairs.reduce((acc, pool) => {
98
98
  acc[pool.id.toLowerCase()] = pool;
99
99
  return acc;
@@ -7,7 +7,6 @@ exports.RiskLevel = void 0;
7
7
  const types_1 = require("../../config/types");
8
8
  const offchainVault_1 = __importDefault(require("./offchainVault"));
9
9
  const amms_1 = require("../../config/amms");
10
- const private_api_1 = require("../../config/private-api");
11
10
  var RiskLevel;
12
11
  (function (RiskLevel) {
13
12
  RiskLevel[RiskLevel["LOW"] = 0] = "LOW";
@@ -60,20 +59,7 @@ class OffchainLendingVault extends offchainVault_1.default {
60
59
  async getLendingVaultBorrowables() {
61
60
  if (this.vaultBorrowables)
62
61
  return this.vaultBorrowables;
63
- const network = this.getOffchain().network;
64
- const vaultAddress = this.getVaultAddress();
65
- const api = private_api_1.IMPERMAX_VAULT_API[network][this.vaultType];
66
- if (!api) {
67
- console.log(`Missing API for ${vaultAddress} on ${network}?`);
68
- return null;
69
- }
70
- try {
71
- this.vaultBorrowables = await fetch(api.concat(vaultAddress, '/borrowables')).then((i) => i.json());
72
- }
73
- catch (err) {
74
- console.log(`No vault data found for ${vaultAddress} on ${network}`);
75
- this.vaultBorrowables = []; // Leave empty to prevent refeteching
76
- }
62
+ this.vaultBorrowables = await this.getOffchain().getVaultBorrowables(this.vaultType, this.getVaultAddress());
77
63
  return this.vaultBorrowables;
78
64
  }
79
65
  }
@@ -132,7 +132,7 @@ class OffchainVault extends offchainPoolToken_1.default {
132
132
  return null;
133
133
  }
134
134
  try {
135
- this.vaultDayData = await fetch(api.concat(vaultAddress)).then((i) => i.json());
135
+ this.vaultDayData = await fetch(api.concat('vaults/', vaultAddress)).then((i) => i.json());
136
136
  }
137
137
  catch (err) {
138
138
  console.log(`No vault data found for ${vaultAddress} on ${network}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.144",
3
+ "version": "2.1.145",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",