impermax-sdk 2.1.51 → 2.1.53
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/offchainMultichainAccount.d.ts +5 -3
- package/lib/offchain/account/offchainMultichainAccount.js +31 -4
- package/lib/offchain/offchainMultichain.d.ts +4 -1
- package/lib/offchain/offchainMultichain.js +11 -1
- package/lib/offchain/vault/offchainLendingVault.d.ts +4 -3
- package/lib/offchain/vault/offchainLendingVault.js +27 -10
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Address, Networks } from
|
|
2
|
-
import { OffchainAccountBorrowable } from
|
|
3
|
-
import OffchainAccountVault from
|
|
1
|
+
import { Address, Networks } from "../../config/types";
|
|
2
|
+
import { OffchainAccountBorrowable } from "./lendingPool";
|
|
3
|
+
import OffchainAccountVault from "./vault";
|
|
4
4
|
import OffchainMultichain from "../offchainMultichain";
|
|
5
5
|
import OffchainAccount from "./offchainAccount";
|
|
6
6
|
import OffchainLeveragedPosition from "./lendingPool/offchainLeveragedPosition";
|
|
@@ -18,6 +18,7 @@ export declare enum VaultPositionsOrderBy {
|
|
|
18
18
|
TVL = 0
|
|
19
19
|
}
|
|
20
20
|
export interface VaultPositionsParams {
|
|
21
|
+
networks?: Array<Networks>;
|
|
21
22
|
}
|
|
22
23
|
export default class OffchainMultichainAccount {
|
|
23
24
|
readonly offchainMultichain: OffchainMultichain;
|
|
@@ -30,5 +31,6 @@ export default class OffchainMultichainAccount {
|
|
|
30
31
|
getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountBorrowable>>;
|
|
31
32
|
getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
|
|
32
33
|
getTotalBalanceUSD(): Promise<number>;
|
|
34
|
+
getVaultsBalanceUSD(): Promise<number>;
|
|
33
35
|
getNetAPR(): Promise<number>;
|
|
34
36
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.VaultPositionsOrderBy = exports.SupplyPositionsOrderBy = exports.LeveragedPositionsOrderBy = void 0;
|
|
13
|
+
const types_1 = require("../../config/types");
|
|
13
14
|
var LeveragedPositionsOrderBy;
|
|
14
15
|
(function (LeveragedPositionsOrderBy) {
|
|
15
16
|
LeveragedPositionsOrderBy[LeveragedPositionsOrderBy["TVL"] = 0] = "TVL";
|
|
@@ -30,7 +31,9 @@ class OffchainMultichainAccount {
|
|
|
30
31
|
this.accountAddress = account;
|
|
31
32
|
}
|
|
32
33
|
getOffchainAccount(network) {
|
|
33
|
-
return this.offchainMultichain
|
|
34
|
+
return this.offchainMultichain
|
|
35
|
+
.getOffchain(network)
|
|
36
|
+
.getAccount(this.accountAddress);
|
|
34
37
|
}
|
|
35
38
|
// Positions
|
|
36
39
|
getLeveragedPositions(params = {}, orderBy = LeveragedPositionsOrderBy.TVL) {
|
|
@@ -47,14 +50,38 @@ class OffchainMultichainAccount {
|
|
|
47
50
|
}
|
|
48
51
|
getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
|
|
49
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
54
|
+
const networksWithVaults = allNetworks.filter((network) => this.offchainMultichain.networkHasVault(network));
|
|
55
|
+
// Get user vaults in a network
|
|
56
|
+
const networkPromises = networksWithVaults.map((network) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const offchainAccount = this.getOffchainAccount(network);
|
|
58
|
+
const vaultsUserData = yield offchainAccount.getVaultsUserData();
|
|
59
|
+
const vaultPromises = [];
|
|
60
|
+
// Get user positions in each vault type
|
|
61
|
+
for (const vaultType in vaultsUserData) {
|
|
62
|
+
const vaultsOfType = vaultsUserData[vaultType];
|
|
63
|
+
for (const address in vaultsOfType) {
|
|
64
|
+
vaultPromises.push(offchainAccount.getVault(address));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Promise.all(vaultPromises);
|
|
68
|
+
}));
|
|
69
|
+
const results = yield Promise.all(networkPromises);
|
|
70
|
+
return results.flat();
|
|
52
71
|
});
|
|
53
72
|
}
|
|
54
73
|
// Account stats
|
|
55
74
|
getTotalBalanceUSD() {
|
|
56
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
|
|
76
|
+
// TODO: Markets
|
|
77
|
+
return this.getVaultsBalanceUSD();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getVaultsBalanceUSD() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const vaultPositions = yield this.getVaultPositions();
|
|
83
|
+
const depositedValue = yield Promise.all(vaultPositions.map(i => i.getValue()));
|
|
84
|
+
return depositedValue.reduce((acc, val) => acc + val, 0);
|
|
58
85
|
});
|
|
59
86
|
}
|
|
60
87
|
getNetAPR() {
|
|
@@ -8,6 +8,8 @@ import OffchainLendingPool from "./lendingPool";
|
|
|
8
8
|
import { LendingPoolVersion } from "./lendingPool/offchainLendingPool";
|
|
9
9
|
import OffchainAPRHelper from "./offchainAPRHelper";
|
|
10
10
|
import OffchainPriceHelper from "./offchainPriceHelper";
|
|
11
|
+
import OffchainMultichainAccount from "./account/offchainMultichainAccount";
|
|
12
|
+
import { AddressIndex } from '../config/types';
|
|
11
13
|
export declare enum SortDirection {
|
|
12
14
|
ASC = "asc",
|
|
13
15
|
DESC = "desc"
|
|
@@ -50,8 +52,8 @@ export default class OffchainMultichain {
|
|
|
50
52
|
protected offchains: NetworkIndex<Offchain>;
|
|
51
53
|
protected aprHelper: OffchainAPRHelper;
|
|
52
54
|
protected priceHelper: OffchainPriceHelper;
|
|
53
|
-
private lendingPoolsInitialized;
|
|
54
55
|
protected lendingPools: OffchainLendingPool[];
|
|
56
|
+
protected multichainAccounts: AddressIndex<OffchainMultichainAccount>;
|
|
55
57
|
private constructor();
|
|
56
58
|
static get instance(): OffchainMultichain;
|
|
57
59
|
getOffchain(network: Networks, whitelist?: FactoryIndex<Address[]>): Offchain;
|
|
@@ -60,4 +62,5 @@ export default class OffchainMultichain {
|
|
|
60
62
|
getVaultList(params?: VaultListParams): Promise<Array<OffchainVault>>;
|
|
61
63
|
networkHasVault(network: Networks): boolean;
|
|
62
64
|
getLendingPoolList(params?: LendingPoolListParams): Promise<Array<OffchainLendingPool>>;
|
|
65
|
+
getMultichainAccount(accountAddress: Address): OffchainMultichainAccount;
|
|
63
66
|
}
|
|
@@ -30,6 +30,7 @@ const offchain_1 = __importDefault(require("./offchain"));
|
|
|
30
30
|
const subgraphs_1 = require("../config/subgraphs");
|
|
31
31
|
const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
|
|
32
32
|
const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
|
|
33
|
+
const offchainMultichainAccount_1 = __importDefault(require("./account/offchainMultichainAccount"));
|
|
33
34
|
// For vaults and pools
|
|
34
35
|
var SortDirection;
|
|
35
36
|
(function (SortDirection) {
|
|
@@ -54,8 +55,8 @@ var LendingPoolListOrderBy;
|
|
|
54
55
|
// singleton class
|
|
55
56
|
class OffchainMultichain {
|
|
56
57
|
constructor() {
|
|
57
|
-
this.lendingPoolsInitialized = null;
|
|
58
58
|
this.lendingPools = [];
|
|
59
|
+
this.multichainAccounts = {};
|
|
59
60
|
// Initialize empty
|
|
60
61
|
this.offchains = {};
|
|
61
62
|
this.aprHelper = new offchainAPRHelper_1.default(this);
|
|
@@ -128,6 +129,15 @@ class OffchainMultichain {
|
|
|
128
129
|
return results.flat();
|
|
129
130
|
});
|
|
130
131
|
}
|
|
132
|
+
/*--------------------------------------------------------*
|
|
133
|
+
* Account
|
|
134
|
+
*--------------------------------------------------------*/
|
|
135
|
+
getMultichainAccount(accountAddress) {
|
|
136
|
+
if (!this.multichainAccounts[accountAddress]) {
|
|
137
|
+
this.multichainAccounts[accountAddress] = new offchainMultichainAccount_1.default(this, accountAddress);
|
|
138
|
+
}
|
|
139
|
+
return this.multichainAccounts[accountAddress];
|
|
140
|
+
}
|
|
131
141
|
}
|
|
132
142
|
exports.default = OffchainMultichain;
|
|
133
143
|
_a = OffchainMultichain;
|
|
@@ -9,13 +9,14 @@ export declare enum RiskLevel {
|
|
|
9
9
|
HIGH = 2
|
|
10
10
|
}
|
|
11
11
|
export default class OffchainLendingVault extends OffchainVault {
|
|
12
|
+
protected vaultBorrowables: Array<VaultBorrowable> | null;
|
|
12
13
|
constructor(offchain: Offchain, vaultAddress: Address);
|
|
13
14
|
getRiskLevel(): Promise<RiskLevel>;
|
|
14
15
|
getAvailableLiquidity(): Promise<number>;
|
|
15
16
|
getAvailableLiquidityUSD(): Promise<number>;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
getLendingVaultBorrowableAmm(borrowable: VaultBorrowable): Promise<Amms | null>;
|
|
18
|
+
getLendingVaultBorrowablesWithAmm(): Promise<Array<VaultBorrowable & {
|
|
18
19
|
amm: Amms | null;
|
|
19
20
|
}>>;
|
|
20
|
-
|
|
21
|
+
getLendingVaultBorrowables(): Promise<Array<VaultBorrowable> | null>;
|
|
21
22
|
}
|
|
@@ -16,6 +16,7 @@ exports.RiskLevel = void 0;
|
|
|
16
16
|
const types_1 = require("../../config/types");
|
|
17
17
|
const offchainVault_1 = __importDefault(require("./offchainVault"));
|
|
18
18
|
const amms_1 = require("../../config/amms");
|
|
19
|
+
const private_api_1 = require("../../config/private-api");
|
|
19
20
|
var RiskLevel;
|
|
20
21
|
(function (RiskLevel) {
|
|
21
22
|
RiskLevel[RiskLevel["LOW"] = 0] = "LOW";
|
|
@@ -25,6 +26,7 @@ var RiskLevel;
|
|
|
25
26
|
class OffchainLendingVault extends offchainVault_1.default {
|
|
26
27
|
constructor(offchain, vaultAddress) {
|
|
27
28
|
super(offchain, vaultAddress);
|
|
29
|
+
this.vaultBorrowables = null;
|
|
28
30
|
this.vaultType = types_1.VaultType.LENDING;
|
|
29
31
|
}
|
|
30
32
|
getRiskLevel() {
|
|
@@ -45,7 +47,7 @@ class OffchainLendingVault extends offchainVault_1.default {
|
|
|
45
47
|
return availableLiquidity * tokenPrice;
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
getLendingVaultBorrowableAmm(borrowable) {
|
|
49
51
|
var _a, _b;
|
|
50
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
53
|
const lendingPoolsData = yield this.getOffchain().getLendingPoolsData();
|
|
@@ -62,22 +64,37 @@ class OffchainLendingVault extends offchainVault_1.default {
|
|
|
62
64
|
return null;
|
|
63
65
|
});
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
getLendingVaultBorrowablesWithAmm() {
|
|
66
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const borrowables = yield this.
|
|
69
|
+
const borrowables = yield this.getLendingVaultBorrowables();
|
|
70
|
+
if (!borrowables)
|
|
71
|
+
return [];
|
|
68
72
|
const borrowablesWithAmm = yield Promise.all(borrowables.map((borrowable) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return (Object.assign(Object.assign({}, borrowable), { amm: yield this.
|
|
73
|
+
return (Object.assign(Object.assign({}, borrowable), { amm: yield this.getLendingVaultBorrowableAmm(borrowable) }));
|
|
70
74
|
})));
|
|
71
75
|
return borrowablesWithAmm;
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
|
-
//
|
|
75
|
-
|
|
78
|
+
// Avoid doing this through initializer and do it as-needed
|
|
79
|
+
getLendingVaultBorrowables() {
|
|
76
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
if (this.vaultBorrowables)
|
|
82
|
+
return this.vaultBorrowables;
|
|
83
|
+
const network = this.getOffchain().network;
|
|
84
|
+
const vaultAddress = this.getVaultAddress();
|
|
85
|
+
const api = private_api_1.IMPERMAX_VAULT_API[network][this.vaultType];
|
|
86
|
+
if (!api) {
|
|
87
|
+
console.log(`Missing API for ${vaultAddress} on ${network}?`);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
this.vaultBorrowables = yield fetch(api.concat(vaultAddress, '/borrowables')).then((i) => i.json());
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.log(`No vault data found for ${vaultAddress} on ${network}`);
|
|
95
|
+
this.vaultBorrowables = []; // Leave empty to prevent refeteching
|
|
96
|
+
}
|
|
97
|
+
return this.vaultBorrowables;
|
|
81
98
|
});
|
|
82
99
|
}
|
|
83
100
|
}
|