impermax-sdk 2.1.53 → 2.1.54
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Networks } from "../../config/types";
|
|
2
|
-
import
|
|
2
|
+
import OffchainAccountLendingPool from "./lendingPool";
|
|
3
3
|
import OffchainAccountVault from "./vault";
|
|
4
4
|
import OffchainMultichain from "../offchainMultichain";
|
|
5
5
|
import OffchainAccount from "./offchainAccount";
|
|
@@ -13,6 +13,7 @@ export declare enum SupplyPositionsOrderBy {
|
|
|
13
13
|
TVL = 0
|
|
14
14
|
}
|
|
15
15
|
export interface SupplyPositionsParams {
|
|
16
|
+
networks?: Array<Networks>;
|
|
16
17
|
}
|
|
17
18
|
export declare enum VaultPositionsOrderBy {
|
|
18
19
|
TVL = 0
|
|
@@ -28,7 +29,7 @@ export default class OffchainMultichainAccount {
|
|
|
28
29
|
getAccountAddress: () => string;
|
|
29
30
|
getOffchainAccount(network: Networks): OffchainAccount;
|
|
30
31
|
getLeveragedPositions(params?: LeveragedPositionsParams, orderBy?: LeveragedPositionsOrderBy): Promise<Array<OffchainLeveragedPosition>>;
|
|
31
|
-
getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<
|
|
32
|
+
getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
|
|
32
33
|
getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
|
|
33
34
|
getTotalBalanceUSD(): Promise<number>;
|
|
34
35
|
getVaultsBalanceUSD(): Promise<number>;
|
|
@@ -42,22 +42,43 @@ class OffchainMultichainAccount {
|
|
|
42
42
|
return [];
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
// Easier to return the lending pool object instead of borrowable?
|
|
45
46
|
getSupplyPositions(params = {}, orderBy = SupplyPositionsOrderBy.TVL) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
49
|
+
// Get user supply positions in each network
|
|
50
|
+
const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const offchainAccount = this.getOffchainAccount(network);
|
|
52
|
+
const userData = yield offchainAccount.getUserData();
|
|
53
|
+
if (!userData)
|
|
54
|
+
return [];
|
|
55
|
+
const positions = [];
|
|
56
|
+
// Get network positions in each factory
|
|
57
|
+
const supplyPositions = yield offchainAccount.getSupplyPositions();
|
|
58
|
+
for (const factory in supplyPositions) {
|
|
59
|
+
const poolsOfFactory = supplyPositions[factory];
|
|
60
|
+
for (const poolAddress of poolsOfFactory) {
|
|
61
|
+
positions.push(offchainAccount.getLendingPool(factory, poolAddress));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Promise.all(positions);
|
|
65
|
+
}));
|
|
66
|
+
const results = yield Promise.all(networkPromises);
|
|
67
|
+
return results.flat();
|
|
49
68
|
});
|
|
50
69
|
}
|
|
51
70
|
getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
|
|
52
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
72
|
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
54
73
|
const networksWithVaults = allNetworks.filter((network) => this.offchainMultichain.networkHasVault(network));
|
|
55
|
-
// Get user
|
|
74
|
+
// Get user positions in each network
|
|
56
75
|
const networkPromises = networksWithVaults.map((network) => __awaiter(this, void 0, void 0, function* () {
|
|
57
76
|
const offchainAccount = this.getOffchainAccount(network);
|
|
58
77
|
const vaultsUserData = yield offchainAccount.getVaultsUserData();
|
|
78
|
+
if (!vaultsUserData)
|
|
79
|
+
return [];
|
|
59
80
|
const vaultPromises = [];
|
|
60
|
-
// Get
|
|
81
|
+
// Get network positions in each vault type
|
|
61
82
|
for (const vaultType in vaultsUserData) {
|
|
62
83
|
const vaultsOfType = vaultsUserData[vaultType];
|
|
63
84
|
for (const address in vaultsOfType) {
|
|
@@ -80,7 +101,7 @@ class OffchainMultichainAccount {
|
|
|
80
101
|
getVaultsBalanceUSD() {
|
|
81
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
103
|
const vaultPositions = yield this.getVaultPositions();
|
|
83
|
-
const depositedValue = yield Promise.all(vaultPositions.map(i => i.getValue()));
|
|
104
|
+
const depositedValue = yield Promise.all(vaultPositions.map((i) => i.getValue()));
|
|
84
105
|
return depositedValue.reduce((acc, val) => acc + val, 0);
|
|
85
106
|
});
|
|
86
107
|
}
|
|
@@ -9,7 +9,7 @@ import { LendingPoolVersion } from "./lendingPool/offchainLendingPool";
|
|
|
9
9
|
import OffchainAPRHelper from "./offchainAPRHelper";
|
|
10
10
|
import OffchainPriceHelper from "./offchainPriceHelper";
|
|
11
11
|
import OffchainMultichainAccount from "./account/offchainMultichainAccount";
|
|
12
|
-
import { AddressIndex } from
|
|
12
|
+
import { AddressIndex } from "../config/types";
|
|
13
13
|
export declare enum SortDirection {
|
|
14
14
|
ASC = "asc",
|
|
15
15
|
DESC = "desc"
|