impermax-sdk 2.1.52 → 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,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 OffchainAccountLendingPool 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";
@@ -13,11 +13,13 @@ 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
19
20
  }
20
21
  export interface VaultPositionsParams {
22
+ networks?: Array<Networks>;
21
23
  }
22
24
  export default class OffchainMultichainAccount {
23
25
  readonly offchainMultichain: OffchainMultichain;
@@ -27,8 +29,9 @@ export default class OffchainMultichainAccount {
27
29
  getAccountAddress: () => string;
28
30
  getOffchainAccount(network: Networks): OffchainAccount;
29
31
  getLeveragedPositions(params?: LeveragedPositionsParams, orderBy?: LeveragedPositionsOrderBy): Promise<Array<OffchainLeveragedPosition>>;
30
- getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountBorrowable>>;
32
+ getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
31
33
  getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
32
34
  getTotalBalanceUSD(): Promise<number>;
35
+ getVaultsBalanceUSD(): Promise<number>;
33
36
  getNetAPR(): Promise<number>;
34
37
  }
@@ -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) {
@@ -39,22 +42,67 @@ class OffchainMultichainAccount {
39
42
  return [];
40
43
  });
41
44
  }
45
+ // Easier to return the lending pool object instead of borrowable?
42
46
  getSupplyPositions(params = {}, orderBy = SupplyPositionsOrderBy.TVL) {
43
47
  return __awaiter(this, void 0, void 0, function* () {
44
- // TODO FILL WITH FAKE DATA
45
- return [];
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();
46
68
  });
47
69
  }
48
70
  getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
49
71
  return __awaiter(this, void 0, void 0, function* () {
50
- // TODO FILL WITH FAKE DATA
51
- return [];
72
+ const allNetworks = params.networks || Object.values(types_1.Networks);
73
+ const networksWithVaults = allNetworks.filter((network) => this.offchainMultichain.networkHasVault(network));
74
+ // Get user positions in each network
75
+ const networkPromises = networksWithVaults.map((network) => __awaiter(this, void 0, void 0, function* () {
76
+ const offchainAccount = this.getOffchainAccount(network);
77
+ const vaultsUserData = yield offchainAccount.getVaultsUserData();
78
+ if (!vaultsUserData)
79
+ return [];
80
+ const vaultPromises = [];
81
+ // Get network positions in each vault type
82
+ for (const vaultType in vaultsUserData) {
83
+ const vaultsOfType = vaultsUserData[vaultType];
84
+ for (const address in vaultsOfType) {
85
+ vaultPromises.push(offchainAccount.getVault(address));
86
+ }
87
+ }
88
+ return Promise.all(vaultPromises);
89
+ }));
90
+ const results = yield Promise.all(networkPromises);
91
+ return results.flat();
52
92
  });
53
93
  }
54
94
  // Account stats
55
95
  getTotalBalanceUSD() {
56
96
  return __awaiter(this, void 0, void 0, function* () {
57
- return 10;
97
+ // TODO: Markets
98
+ return this.getVaultsBalanceUSD();
99
+ });
100
+ }
101
+ getVaultsBalanceUSD() {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const vaultPositions = yield this.getVaultPositions();
104
+ const depositedValue = yield Promise.all(vaultPositions.map((i) => i.getValue()));
105
+ return depositedValue.reduce((acc, val) => acc + val, 0);
58
106
  });
59
107
  }
60
108
  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.54",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",