impermax-sdk 2.1.62 → 2.1.63

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.
@@ -12,15 +12,18 @@ export interface LeveragedPositionsParams {
12
12
  export declare enum SupplyPositionsOrderBy {
13
13
  TVL = 0
14
14
  }
15
- export interface SupplyPositionsParams {
16
- networks?: Array<Networks>;
17
- }
18
15
  export declare enum VaultPositionsOrderBy {
19
16
  TVL = 0
20
17
  }
18
+ export interface SupplyPositionsParams {
19
+ networks?: Array<Networks>;
20
+ }
21
21
  export interface VaultPositionsParams {
22
22
  networks?: Array<Networks>;
23
23
  }
24
+ export interface TopPositionsParams extends SupplyPositionsParams, VaultPositionsParams {
25
+ limit?: number;
26
+ }
24
27
  export declare enum PositionType {
25
28
  MARKET = "Market",
26
29
  VAULT = "Vault",
@@ -45,9 +48,9 @@ export default class OffchainMultichainAccount {
45
48
  getLeveragedPositions(params?: LeveragedPositionsParams, orderBy?: LeveragedPositionsOrderBy): Promise<Array<OffchainLeveragedPosition>>;
46
49
  getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
47
50
  getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
51
+ getTopPositions(params?: TopPositionsParams): Promise<Array<AccountPosition>>;
48
52
  getTotalBalanceUSD(): Promise<number>;
49
53
  getVaultsBalanceUSD(): Promise<number>;
50
54
  getSupplyBalanceUSD(): Promise<number>;
51
- getTopPositions(limit?: number): Promise<Array<AccountPosition>>;
52
55
  getNetAPR(): Promise<number>;
53
56
  }
@@ -51,8 +51,9 @@ class OffchainMultichainAccount {
51
51
  }
52
52
  // Easier to return the lending pool object instead of borrowable?
53
53
  getSupplyPositions(params = {}, orderBy = SupplyPositionsOrderBy.TVL) {
54
+ var _a;
54
55
  return __awaiter(this, void 0, void 0, function* () {
55
- const allNetworks = params.networks || Object.values(types_1.Networks);
56
+ const allNetworks = (_a = params.networks) !== null && _a !== void 0 ? _a : Object.values(types_1.Networks);
56
57
  // Get user supply positions in each network
57
58
  const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
58
59
  const offchainAccount = this.getOffchainAccount(network);
@@ -75,8 +76,9 @@ class OffchainMultichainAccount {
75
76
  });
76
77
  }
77
78
  getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
79
+ var _a;
78
80
  return __awaiter(this, void 0, void 0, function* () {
79
- const allNetworks = params.networks || Object.values(types_1.Networks);
81
+ const allNetworks = (_a = params.networks) !== null && _a !== void 0 ? _a : Object.values(types_1.Networks);
80
82
  const networksWithVaults = allNetworks.filter((network) => this.offchainMultichain.networkHasVault(network));
81
83
  // Get user positions in each network
82
84
  const networkPromises = networksWithVaults.map((network) => __awaiter(this, void 0, void 0, function* () {
@@ -98,42 +100,14 @@ class OffchainMultichainAccount {
98
100
  return results.flat();
99
101
  });
100
102
  }
101
- // Account stats
102
- getTotalBalanceUSD() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const [vaultBalanceUSD, supplyBalanceUSD] = yield Promise.all([
105
- this.getVaultsBalanceUSD(),
106
- this.getSupplyBalanceUSD(),
107
- ]);
108
- return vaultBalanceUSD + supplyBalanceUSD;
109
- });
110
- }
111
- getVaultsBalanceUSD() {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const vaultPositions = yield this.getVaultPositions();
114
- const depositedValue = yield Promise.all(vaultPositions.map((i) => i.getValue()));
115
- return depositedValue.reduce((acc, val) => acc + val, 0);
116
- });
117
- }
118
- getSupplyBalanceUSD() {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- const supplyPositions = yield this.getSupplyPositions();
121
- const suppliedValue = yield Promise.all(supplyPositions.map((pool) => __awaiter(this, void 0, void 0, function* () {
122
- const [valueA, valueB] = yield Promise.all([
123
- pool.getBorrowableA().getValue(),
124
- pool.getBorrowableB().getValue(),
125
- ]);
126
- return valueA + valueB;
127
- })));
128
- return suppliedValue.reduce((acc, val) => acc + val, 0);
129
- });
130
- }
131
103
  // Gets the top positions for a user
132
- getTopPositions(limit = 10) {
104
+ getTopPositions(params = {}) {
105
+ var _a;
133
106
  return __awaiter(this, void 0, void 0, function* () {
107
+ const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : 10;
134
108
  const [supplyPositions, vaultPositions] = yield Promise.all([
135
- this.getSupplyPositions(),
136
- this.getVaultPositions(),
109
+ this.getSupplyPositions(params),
110
+ this.getVaultPositions(params),
137
111
  ]);
138
112
  // Lending Market positions
139
113
  const supplyValues = yield Promise.all(supplyPositions.map((pool) => __awaiter(this, void 0, void 0, function* () {
@@ -144,7 +118,7 @@ class OffchainMultichainAccount {
144
118
  pool.getBorrowableB().getPoolToken().getSymbol(),
145
119
  pool.getLendingPool().getOffchain().network,
146
120
  pool.getLendingPool().getLendingPoolData(),
147
- pool.getLendingPool().getFactory()
121
+ pool.getLendingPool().getFactory(),
148
122
  ]);
149
123
  const totalValue = valueA + valueB;
150
124
  return {
@@ -153,7 +127,7 @@ class OffchainMultichainAccount {
153
127
  type: PositionType.MARKET,
154
128
  network: network,
155
129
  id: data.id,
156
- factory: factory
130
+ factory: factory,
157
131
  };
158
132
  })));
159
133
  // Vault positions
@@ -162,7 +136,7 @@ class OffchainMultichainAccount {
162
136
  vault.getValue(),
163
137
  vault.getPoolToken().getSymbol(),
164
138
  vault.getPoolToken().getOffchain().network,
165
- vault.getPoolToken().getPoolTokenData()
139
+ vault.getPoolToken().getPoolTokenData(),
166
140
  ]);
167
141
  return {
168
142
  name: symbol,
@@ -170,7 +144,7 @@ class OffchainMultichainAccount {
170
144
  type: PositionType.VAULT,
171
145
  network: network,
172
146
  id: data.id,
173
- factory: undefined
147
+ factory: undefined,
174
148
  };
175
149
  })));
176
150
  const allPositions = [...supplyValues, ...vaultValues].sort((a, b) => b.value - a.value);
@@ -178,7 +152,7 @@ class OffchainMultichainAccount {
178
152
  if (allPositions.length <= limit || limit <= 1) {
179
153
  return allPositions.map((pos) => (Object.assign(Object.assign({}, pos), { percentage: (pos.value / totalValue) * 100 })));
180
154
  }
181
- // Top N-1 positions and calculate "Other"
155
+ // Top N-1 positions and calculate "Other"
182
156
  const topNMinusOne = allPositions.slice(0, limit - 1);
183
157
  const remainingPositions = allPositions.slice(limit - 1);
184
158
  const remainingValue = remainingPositions.reduce((sum, pos) => sum + pos.value, 0);
@@ -190,12 +164,42 @@ class OffchainMultichainAccount {
190
164
  type: PositionType.OTHER,
191
165
  network: types_1.Networks.Mainnet,
192
166
  id: "",
193
- factory: undefined
167
+ factory: undefined,
194
168
  },
195
169
  ].map((pos) => (Object.assign(Object.assign({}, pos), { percentage: (pos.value / totalValue) * 100 })));
196
170
  return result;
197
171
  });
198
172
  }
173
+ // Account stats
174
+ getTotalBalanceUSD() {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ const [vaultBalanceUSD, supplyBalanceUSD] = yield Promise.all([
177
+ this.getVaultsBalanceUSD(),
178
+ this.getSupplyBalanceUSD(),
179
+ ]);
180
+ return vaultBalanceUSD + supplyBalanceUSD;
181
+ });
182
+ }
183
+ getVaultsBalanceUSD() {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ const vaultPositions = yield this.getVaultPositions();
186
+ const depositedValue = yield Promise.all(vaultPositions.map((i) => i.getValue()));
187
+ return depositedValue.reduce((acc, val) => acc + val, 0);
188
+ });
189
+ }
190
+ getSupplyBalanceUSD() {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const supplyPositions = yield this.getSupplyPositions();
193
+ const suppliedValue = yield Promise.all(supplyPositions.map((pool) => __awaiter(this, void 0, void 0, function* () {
194
+ const [valueA, valueB] = yield Promise.all([
195
+ pool.getBorrowableA().getValue(),
196
+ pool.getBorrowableB().getValue(),
197
+ ]);
198
+ return valueA + valueB;
199
+ })));
200
+ return suppliedValue.reduce((acc, val) => acc + val, 0);
201
+ });
202
+ }
199
203
  getNetAPR() {
200
204
  return __awaiter(this, void 0, void 0, function* () {
201
205
  return 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.62",
3
+ "version": "2.1.63",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",