impermax-sdk 2.1.52 → 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.
@@ -1,6 +1,6 @@
1
- import { Address, Networks } from '../../config/types';
2
- import { OffchainAccountBorrowable } from './lendingPool';
3
- import OffchainAccountVault from './vault';
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.getOffchain(network).getAccount(this.accountAddress);
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
- // TODO FILL WITH FAKE DATA
51
- return [];
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
- return 10;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.52",
3
+ "version": "2.1.53",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",