impermax-sdk 2.1.331 → 2.1.332
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/account/offchainAccount.d.ts +1 -1
- package/lib/offchain/account/offchainAccount.js +20 -1
- package/lib/offchain/account/offchainMultichainAccount.js +6 -3
- package/lib/offchain/configManager/offchainPairConfig.d.ts +1 -1
- package/lib/offchain/initializer/user/lendingPools.js +6 -1
- package/lib/offchain/initializer/user/positionsV2.js +6 -1
- package/lib/offchain/offchain.d.ts +1 -1
- package/lib/offchain/offchainMultichain.js +7 -2
- package/lib/offchain/vault/offchainLendingVault.js +2 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +2 -1
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +5 -2
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +2 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +2 -1
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +4 -1
- package/package.json +1 -1
|
@@ -28,7 +28,7 @@ export default class OffchainAccount {
|
|
|
28
28
|
getOffchain: () => Offchain;
|
|
29
29
|
getAccountAddress: () => string;
|
|
30
30
|
private initializeLendingPool;
|
|
31
|
-
getLendingPool(factory: Factory, pair: Address): Promise<OffchainAccountLendingPool>;
|
|
31
|
+
getLendingPool(factory: Factory, pair: Address): Promise<OffchainAccountLendingPool | null>;
|
|
32
32
|
private initializeVault;
|
|
33
33
|
getVault(vaultAddress: Address): Promise<OffchainAccountVault>;
|
|
34
34
|
getUserData(): Promise<FactoryIndex<UserData> | null>;
|
|
@@ -17,7 +17,11 @@ class OffchainAccount {
|
|
|
17
17
|
}
|
|
18
18
|
async initializeLendingPool(factory, pair) {
|
|
19
19
|
const lendingPool = await this.offchain.getLendingPool(factory, pair);
|
|
20
|
-
|
|
20
|
+
if (!lendingPool) {
|
|
21
|
+
console.error("AccountLendingPool is null:", pair, factory, this.offchain.network);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return lendingPool?.getNewAccountLendingPoolObject(this);
|
|
21
25
|
}
|
|
22
26
|
async getLendingPool(factory, pair) {
|
|
23
27
|
if (!this.lendingPools[factory])
|
|
@@ -151,6 +155,8 @@ class OffchainAccount {
|
|
|
151
155
|
// Get pools of this factory
|
|
152
156
|
for (const poolAddress of poolsOfFactory) {
|
|
153
157
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
158
|
+
if (!pool)
|
|
159
|
+
return 0;
|
|
154
160
|
// Don't take into account earnings with blacklisted pools
|
|
155
161
|
if (pool.getLendingPool().isBlacklisted())
|
|
156
162
|
continue;
|
|
@@ -176,6 +182,8 @@ class OffchainAccount {
|
|
|
176
182
|
// Get pools of this factory
|
|
177
183
|
for (const poolAddress of poolsOfFactory) {
|
|
178
184
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
185
|
+
if (!pool)
|
|
186
|
+
continue;
|
|
179
187
|
lendingPools.push(pool);
|
|
180
188
|
}
|
|
181
189
|
}
|
|
@@ -209,6 +217,8 @@ class OffchainAccount {
|
|
|
209
217
|
// Get pools of this factory
|
|
210
218
|
for (const poolAddress of poolsOfFactory) {
|
|
211
219
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
220
|
+
if (!pool)
|
|
221
|
+
continue;
|
|
212
222
|
lendingPools.push(pool);
|
|
213
223
|
}
|
|
214
224
|
}
|
|
@@ -237,6 +247,8 @@ class OffchainAccount {
|
|
|
237
247
|
// Get pools of this factory
|
|
238
248
|
for (const poolAddress of poolsOfFactory) {
|
|
239
249
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
250
|
+
if (!pool)
|
|
251
|
+
continue;
|
|
240
252
|
lendingPools.push(pool);
|
|
241
253
|
}
|
|
242
254
|
}
|
|
@@ -260,6 +272,11 @@ class OffchainAccount {
|
|
|
260
272
|
async getAccountMarketData(factory, poolAddress) {
|
|
261
273
|
// Get market
|
|
262
274
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
275
|
+
if (!pool)
|
|
276
|
+
return {
|
|
277
|
+
lending: { totalBalanceUSD: 0, totalAPR: 0 },
|
|
278
|
+
borrowing: { totalBalanceUSD: 0, totalAPR: 0 },
|
|
279
|
+
};
|
|
263
280
|
// 1. Lending
|
|
264
281
|
const [valueA, valueB, aprA, aprB] = await Promise.all([
|
|
265
282
|
pool.getBorrowableA().getValue(),
|
|
@@ -314,6 +331,8 @@ class OffchainAccount {
|
|
|
314
331
|
async getMarketDailyProfitUSD(factory, poolAddress) {
|
|
315
332
|
// Get market
|
|
316
333
|
const pool = await this.getLendingPool(factory, poolAddress);
|
|
334
|
+
if (!pool)
|
|
335
|
+
return 0;
|
|
317
336
|
// Escape if blacklisted pool
|
|
318
337
|
if (!pool.getLendingPool().isBlacklisted())
|
|
319
338
|
return 0;
|
|
@@ -59,7 +59,8 @@ class OffchainMultichainAccount {
|
|
|
59
59
|
}
|
|
60
60
|
return Promise.all(positions);
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
const accountLendingPools = (await Promise.all(networkPromises)).flat();
|
|
63
|
+
let results = accountLendingPools.filter(x => x);
|
|
63
64
|
// Apply filters
|
|
64
65
|
if (params.pairState)
|
|
65
66
|
results = this.filterPairState(results, params.pairState);
|
|
@@ -87,7 +88,8 @@ class OffchainMultichainAccount {
|
|
|
87
88
|
}
|
|
88
89
|
return Promise.all(positions);
|
|
89
90
|
});
|
|
90
|
-
|
|
91
|
+
const accountLendingPools = (await Promise.all(networkPromises)).flat();
|
|
92
|
+
let results = accountLendingPools.filter(x => x);
|
|
91
93
|
// Apply filters
|
|
92
94
|
if (params.pairState)
|
|
93
95
|
results = this.filterPairState(results, params.pairState);
|
|
@@ -114,7 +116,8 @@ class OffchainMultichainAccount {
|
|
|
114
116
|
}
|
|
115
117
|
return Promise.all(positions);
|
|
116
118
|
});
|
|
117
|
-
|
|
119
|
+
const accountLendingPools = (await Promise.all(networkPromises)).flat();
|
|
120
|
+
let results = accountLendingPools.filter(x => x);
|
|
118
121
|
// Apply filters
|
|
119
122
|
if (params.pairState)
|
|
120
123
|
results = this.filterPairState(results, params.pairState);
|
|
@@ -14,7 +14,7 @@ export default class OffchainPairConfig {
|
|
|
14
14
|
protected getProposalParamFloat(param: string): number;
|
|
15
15
|
getFactory(): Promise<Factory>;
|
|
16
16
|
getPairAddress(): Promise<string>;
|
|
17
|
-
getLendingPool(): Promise<OffchainLendingPool>;
|
|
17
|
+
getLendingPool(): Promise<OffchainLendingPool | null>;
|
|
18
18
|
getSafetyMargin(): Promise<number>;
|
|
19
19
|
getLiquidationIncentive(): Promise<number>;
|
|
20
20
|
getLiquidationFee(): Promise<number>;
|
|
@@ -53,7 +53,12 @@ async function initializeUserData(account) {
|
|
|
53
53
|
// Don't include supply positions if lending pool is not in pair list
|
|
54
54
|
// if (pairs.length > 0 && !pairs.includes(lendingPoolId)) continue
|
|
55
55
|
const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
56
|
-
const
|
|
56
|
+
const lendingPool = await this.getLendingPool(factory, lendingPoolId);
|
|
57
|
+
if (!lendingPool) {
|
|
58
|
+
console.error("Can't resolve supplyPosition because lendingPool is null. Lending pool:", lendingPoolId, this.network);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const borrowableA = lendingPool.getBorrowableA();
|
|
57
62
|
const addressA = await borrowableA.getUnderlyingAddress();
|
|
58
63
|
const poolTokenType = underlyingId === addressA
|
|
59
64
|
? types_1.PoolTokenType.BorrowableA
|
|
@@ -22,7 +22,12 @@ async function initializeV2Positions(offchain, factory, rawUserData, pairs) {
|
|
|
22
22
|
if (pairs.length > 0 && !pairs.includes(lendingPoolId))
|
|
23
23
|
continue;
|
|
24
24
|
const underlyingId = borrowPosition.borrowable.underlying.id;
|
|
25
|
-
const
|
|
25
|
+
const lendingPool = await offchain.getLendingPool(factory, lendingPoolId);
|
|
26
|
+
if (!lendingPool) {
|
|
27
|
+
console.error("Can't resolve v2 position because lendingPool is null. Lending pool:", lendingPoolId, offchain.network);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const borrowableA = lendingPool.getBorrowableA();
|
|
26
31
|
const addressA = await borrowableA.getUnderlyingAddress();
|
|
27
32
|
const poolTokenType = underlyingId === addressA
|
|
28
33
|
? types_1.PoolTokenType.BorrowableA
|
|
@@ -53,7 +53,7 @@ export default class Offchain {
|
|
|
53
53
|
protected borrowersList: Promise<OffchainAccount[]> | null;
|
|
54
54
|
constructor(offchainMultichain: OffchainMultichain, network: Networks);
|
|
55
55
|
cleanCache(): void;
|
|
56
|
-
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
|
|
56
|
+
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool | null>;
|
|
57
57
|
getVault(vaultAddress: Address): Promise<OffchainVault>;
|
|
58
58
|
getAccount(accountAddress: Address): OffchainAccount;
|
|
59
59
|
getSolidexHelper: () => OffchainSolidexHelper;
|
|
@@ -115,8 +115,13 @@ class OffchainMultichain {
|
|
|
115
115
|
const lendingPoolsData = await offchain.getLendingPoolsData();
|
|
116
116
|
// Factories
|
|
117
117
|
const factoryPromises = Object.entries(lendingPoolsData).map(async ([factory, pools]) => {
|
|
118
|
-
const poolPromises = Object.keys(pools).map((poolId) =>
|
|
119
|
-
|
|
118
|
+
const poolPromises = Object.keys(pools).map(async (poolId) => {
|
|
119
|
+
const lendingPool = await offchain.getLendingPool(factory, poolId);
|
|
120
|
+
if (!lendingPool)
|
|
121
|
+
console.error("Can't include", poolId, factory, network, "in pools list");
|
|
122
|
+
return lendingPool;
|
|
123
|
+
});
|
|
124
|
+
return (await Promise.all(poolPromises)).filter(x => x);
|
|
120
125
|
});
|
|
121
126
|
const factoryResults = await Promise.all(factoryPromises);
|
|
122
127
|
return factoryResults.flat();
|
|
@@ -49,6 +49,8 @@ class OffchainLendingVault extends offchainVault_1.default {
|
|
|
49
49
|
if (pair) {
|
|
50
50
|
const account = this.getOffchain().getAccount(this.getVaultAddress());
|
|
51
51
|
const lendingPool = await account.getLendingPool(factory, borrowable.pairAddress);
|
|
52
|
+
if (!lendingPool)
|
|
53
|
+
continue;
|
|
52
54
|
const underlyingAddress = await this.getUnderlyingAddress();
|
|
53
55
|
const underlyingAddressA = await lendingPool.getLendingPool().getBorrowableA().getUnderlyingAddress();
|
|
54
56
|
if (underlyingAddress.toLowerCase() === underlyingAddressA.toLowerCase())
|
|
@@ -38,6 +38,7 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
|
|
|
38
38
|
//if (await this.getLendingPool().getLendingPool().isStable()) {
|
|
39
39
|
// TODO return stablePosition
|
|
40
40
|
//} else {
|
|
41
|
+
const offchainLendingPool = await this.getLendingPool().getLendingPool().getOffchainLendingPool();
|
|
41
42
|
return new position_1.UniswapV2Position({
|
|
42
43
|
liquidity: await this.getLiquidity(),
|
|
43
44
|
debtX: await this.getLendingPool().getBorrowableA().getBorrowed(),
|
|
@@ -48,7 +49,7 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
|
|
|
48
49
|
liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
|
|
49
50
|
borrowableX: await this.getLendingPool().getLendingPool().getBorrowableA().createBorrowableObject(lockStateChange),
|
|
50
51
|
borrowableY: await this.getLendingPool().getLendingPool().getBorrowableB().createBorrowableObject(lockStateChange),
|
|
51
|
-
baseRate:
|
|
52
|
+
baseRate: offchainLendingPool ? (await offchainLendingPool.getTotalAPR()) / utils_1.SECONDS_IN_YEAR : 0,
|
|
52
53
|
lockStateChange,
|
|
53
54
|
});
|
|
54
55
|
//}
|
|
@@ -33,8 +33,11 @@ class OnchainAccountLendingPool {
|
|
|
33
33
|
getInteractionsLendingPool() {
|
|
34
34
|
return this.account.getInteractions().getLendingPool(this.getFactory(), this.getId());
|
|
35
35
|
}
|
|
36
|
-
getOffchainAccountLendingPool() {
|
|
37
|
-
|
|
36
|
+
async getOffchainAccountLendingPool() {
|
|
37
|
+
const accountLendingPool = await this.account.getOffchainAccount().getLendingPool(this.getFactory(), this.getId());
|
|
38
|
+
if (!accountLendingPool)
|
|
39
|
+
throw new Error("getOffchainAccountLendingPool");
|
|
40
|
+
return accountLendingPool;
|
|
38
41
|
}
|
|
39
42
|
// Supplied
|
|
40
43
|
async getSuppliedUSD() {
|
|
@@ -25,6 +25,8 @@ class OnchainBorrowable extends onchainPoolToken_1.default {
|
|
|
25
25
|
}
|
|
26
26
|
async getOffchainPoolToken() {
|
|
27
27
|
const lendingPool = await this.lendingPool.getOffchainLendingPool();
|
|
28
|
+
if (!lendingPool)
|
|
29
|
+
throw new Error("getOffchainPoolToken");
|
|
28
30
|
return lendingPool.getBorrowable(this.borrowable);
|
|
29
31
|
}
|
|
30
32
|
async initializeToken() {
|
|
@@ -5,6 +5,7 @@ import OnchainBorrowable from './onchainBorrowable';
|
|
|
5
5
|
import OnchainAccountLendingPool from "../../account/lendingPool";
|
|
6
6
|
import OnchainInteractions, { OnchainInteractionsLendingPool } from "../../interactions";
|
|
7
7
|
import OnchainAccount from "../../account";
|
|
8
|
+
import { OffchainLendingPool } from "../../../offchain";
|
|
8
9
|
export default abstract class OnchainLendingPool {
|
|
9
10
|
protected readonly id: Address;
|
|
10
11
|
protected readonly impermaxFactory: OnchainImpermaxFactory;
|
|
@@ -34,7 +35,7 @@ export default abstract class OnchainLendingPool {
|
|
|
34
35
|
getCollateral: () => OnchainCollateral;
|
|
35
36
|
protected getContractHelper: () => import("../..").OnchainContractsHelper;
|
|
36
37
|
cleanCache(): void;
|
|
37
|
-
getOffchainLendingPool(): Promise<
|
|
38
|
+
getOffchainLendingPool(): Promise<OffchainLendingPool>;
|
|
38
39
|
private initializeLendingPoolAddresses;
|
|
39
40
|
private getLendingPoolAddresses;
|
|
40
41
|
getCollateralAddress(): Promise<string>;
|
|
@@ -27,7 +27,10 @@ class OnchainLendingPool {
|
|
|
27
27
|
this.getCollateral().cleanCache();
|
|
28
28
|
}
|
|
29
29
|
async getOffchainLendingPool() {
|
|
30
|
-
|
|
30
|
+
const lendingPool = await this.impermaxFactory.getOnchain().getOffchain().getLendingPool(this.impermaxFactory.getFactory(), this.id);
|
|
31
|
+
if (!lendingPool)
|
|
32
|
+
throw new Error("getOffchainLendingPool");
|
|
33
|
+
return lendingPool;
|
|
31
34
|
}
|
|
32
35
|
async initializeLendingPoolAddresses() {
|
|
33
36
|
const lPool = await (await this.impermaxFactory.getFactoryContract()).methods.getLendingPool(this.id).call();
|