impermax-sdk 2.1.117 → 2.1.118

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.
@@ -11,6 +11,10 @@ export default abstract class OffchainAccountBorrowable extends OffchainAccountP
11
11
  getPoolToken: () => OffchainBorrowable;
12
12
  private getSupplyPosition;
13
13
  getAmount(): Promise<number>;
14
+ getValue(): Promise<number>;
14
15
  getEarnings(): Promise<number>;
15
16
  getEarningsUSD(): Promise<number>;
17
+ private getBorrowPosition;
18
+ getBorrowedAmount(tokenId?: number): Promise<number>;
19
+ getBorrowedValue(tokenId?: number): Promise<number>;
16
20
  }
@@ -22,6 +22,10 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
22
22
  this.borrowable = borrowable;
23
23
  this.poolToken = this.lendingPool.getLendingPool().getBorrowable(borrowable);
24
24
  }
25
+ /*--------------------------------------------------------------------------*
26
+ * Supply Positions *
27
+ *--------------------------------------------------------------------------*/
28
+ // Lending position //
25
29
  getSupplyPosition() {
26
30
  return __awaiter(this, void 0, void 0, function* () {
27
31
  const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
@@ -40,6 +44,14 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
40
44
  return supplyBalance * exchangeRate;
41
45
  });
42
46
  }
47
+ getValue() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const tokenPrice = yield this.poolToken.getTokenPriceAccurate();
50
+ const borrowedAmount = yield this.getAmount();
51
+ return borrowedAmount * tokenPrice;
52
+ });
53
+ }
54
+ // Earnings //
43
55
  // WARN: Not all networks support cumulativeEarnings for now, see the `userQuery` in
44
56
  // queries/apis/thegraph/index.ts. atm only available on Blast
45
57
  getEarnings() {
@@ -64,5 +76,37 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
64
76
  return earnings * tokenPrice;
65
77
  });
66
78
  }
79
+ /*--------------------------------------------------------------------------*
80
+ * Borrow Positions *
81
+ *--------------------------------------------------------------------------*/
82
+ getBorrowPosition(tokenId) {
83
+ var _a, _b, _c, _d;
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
86
+ if (!tokenId)
87
+ return (_a = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.borrowPositions) === null || _a === void 0 ? void 0 : _a[`borrowable${this.borrowable}`];
88
+ // V3
89
+ return (_d = (_c = (_b = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.positions) === null || _b === void 0 ? void 0 : _b[tokenId]) === null || _c === void 0 ? void 0 : _c.borrowPositions) === null || _d === void 0 ? void 0 : _d[this.borrowable];
90
+ });
91
+ }
92
+ // Borrowing position
93
+ getBorrowedAmount(tokenId) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const borrowPosition = yield this.getBorrowPosition(tokenId);
96
+ const borrowIndex = yield this.poolToken.getBorrowIndex();
97
+ if (!borrowPosition)
98
+ return 0;
99
+ const borrowBalance = parseFloat(borrowPosition.borrowBalance);
100
+ const userBorrowIndex = parseFloat(borrowPosition.borrowIndex);
101
+ return borrowBalance * borrowIndex / userBorrowIndex;
102
+ });
103
+ }
104
+ getBorrowedValue(tokenId) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const tokenPrice = yield this.poolToken.getTokenPriceAccurate();
107
+ const borrowedAmount = yield this.getBorrowedAmount(tokenId);
108
+ return borrowedAmount * tokenPrice;
109
+ });
110
+ }
67
111
  }
68
112
  exports.default = OffchainAccountBorrowable;
@@ -1,8 +1,8 @@
1
1
  import OffchainAccount from "../index";
2
- import { Borrowable, PoolTokenType } from "../../../config/types";
2
+ import { Borrowable } from "../../../config/types";
3
3
  import OffchainAccountCollateral from "./offchainAccountCollateral";
4
4
  import OffchainAccountBorrowable from "./offchainAccountBorrowable";
5
- import { SupplyPosition } from "../../offchainTypes";
5
+ import { LendingPoolPosition } from "../../offchainTypes";
6
6
  import OffchainLendingPool from "../../lendingPool";
7
7
  import OffchainLeveragedPosition from "./offchainLeveragedPosition";
8
8
  export default abstract class OffchainAccountLendingPool {
@@ -16,6 +16,7 @@ export default abstract class OffchainAccountLendingPool {
16
16
  protected abstract getNewCollateralObject(): OffchainAccountCollateral;
17
17
  protected abstract getNewBorrowableObject(borrowable: Borrowable): OffchainAccountBorrowable;
18
18
  constructor(account: OffchainAccount, lendingPool: OffchainLendingPool);
19
+ abstract getLendingPoolPosition(): Promise<LendingPoolPosition | undefined>;
19
20
  getAccount: () => OffchainAccount;
20
21
  getLendingPool: () => OffchainLendingPool;
21
22
  getBorrowable: (borrowable: Borrowable) => OffchainAccountBorrowable;
@@ -26,10 +27,6 @@ export default abstract class OffchainAccountLendingPool {
26
27
  protected getId: () => any;
27
28
  getSafetyMargin: () => Promise<number>;
28
29
  getLiquidationPenalty: () => Promise<number>;
29
- getLendingPoolPosition(): Promise<{
30
- [PoolTokenType.BorrowableA]?: SupplyPosition;
31
- [PoolTokenType.BorrowableB]?: SupplyPosition;
32
- } | undefined>;
33
30
  getLeveragedPositions(): Promise<Array<OffchainLeveragedPosition>>;
34
31
  getLeveragedPositionsTotalBalanceUSD(): Promise<number>;
35
32
  getLeveragedPositionsNetAPR(): Promise<number>;
@@ -31,27 +31,6 @@ class OffchainAccountLendingPool {
31
31
  [types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
32
32
  };
33
33
  }
34
- getLendingPoolPosition() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- // TODO rename and refactor
37
- const userData = yield this.account.getUserData();
38
- if (!userData)
39
- return undefined;
40
- const userDataOfFactory = userData[this.lendingPool.getFactory()];
41
- if (!userDataOfFactory)
42
- return undefined;
43
- const pairAddress = this.lendingPool.getPairAddress();
44
- const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
45
- return {
46
- [types_1.PoolTokenType.BorrowableA]: supplyPositions
47
- ? supplyPositions[types_1.PoolTokenType.BorrowableA]
48
- : undefined,
49
- [types_1.PoolTokenType.BorrowableB]: supplyPositions
50
- ? supplyPositions[types_1.PoolTokenType.BorrowableB]
51
- : undefined,
52
- };
53
- });
54
- }
55
34
  getLeveragedPositions() {
56
35
  return __awaiter(this, void 0, void 0, function* () {
57
36
  return [];
@@ -1,5 +1,5 @@
1
1
  import OffchainAccount from "../index";
2
- import { Borrowable, PoolTokenType } from "../../../config/types";
2
+ import { Borrowable } from "../../../config/types";
3
3
  import { SupplyPosition } from "../../offchainTypes";
4
4
  import OffchainLendingPool from "../../lendingPool";
5
5
  import OffchainLeveragedPosition from "./offchainLeveragedPosition";
@@ -29,8 +29,13 @@ export default class OffchainAccountLendingPoolV2 extends OffchainAccountLending
29
29
  getSafetyMargin: () => Promise<number>;
30
30
  getLiquidationPenalty: () => Promise<number>;
31
31
  getLendingPoolPosition(): Promise<{
32
- [PoolTokenType.BorrowableA]?: SupplyPosition;
33
- [PoolTokenType.BorrowableB]?: SupplyPosition;
32
+ borrowable0: SupplyPosition | undefined;
33
+ borrowable1: SupplyPosition | undefined;
34
+ collateralPosition: import("../../offchainTypes").CollateralPosition[] | undefined;
35
+ borrowPositions: {
36
+ borrowable0: import("../../offchainTypes").BorrowPosition | undefined;
37
+ borrowable1: import("../../offchainTypes").BorrowPosition | undefined;
38
+ };
34
39
  } | undefined>;
35
40
  getLeveragedPositions(): Promise<Array<OffchainLeveragedPosition>>;
36
41
  getLeveragedPositionsTotalBalanceUSD(): Promise<number>;
@@ -45,24 +45,27 @@ class OffchainAccountLendingPoolV2 extends offchainAccountLendingPool_1.default
45
45
  [types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
46
46
  };
47
47
  }
48
+ /*--------------------------------------------------------------------------*
49
+ * User Lending Pool Data (PoolToken) *
50
+ *--------------------------------------------------------------------------*/
48
51
  getLendingPoolPosition() {
52
+ var _a, _b;
49
53
  return __awaiter(this, void 0, void 0, function* () {
50
- // TODO rename and refactor
51
54
  const userData = yield this.account.getUserData();
52
- if (!userData)
53
- return undefined;
54
- const userDataOfFactory = userData[this.lendingPool.getFactory()];
55
+ const userDataOfFactory = userData === null || userData === void 0 ? void 0 : userData[this.lendingPool.getFactory()];
55
56
  if (!userDataOfFactory)
56
- return undefined;
57
+ return;
57
58
  const pairAddress = this.lendingPool.getPairAddress();
58
59
  const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
60
+ const borrowPositions = (_a = userDataOfFactory === null || userDataOfFactory === void 0 ? void 0 : userDataOfFactory.borrowPositions) === null || _a === void 0 ? void 0 : _a[pairAddress];
59
61
  return {
60
- [types_1.PoolTokenType.BorrowableA]: supplyPositions
61
- ? supplyPositions[types_1.PoolTokenType.BorrowableA]
62
- : undefined,
63
- [types_1.PoolTokenType.BorrowableB]: supplyPositions
64
- ? supplyPositions[types_1.PoolTokenType.BorrowableB]
65
- : undefined,
62
+ borrowable0: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableA],
63
+ borrowable1: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableB],
64
+ collateralPosition: (_b = userDataOfFactory === null || userDataOfFactory === void 0 ? void 0 : userDataOfFactory.collateralPositions) === null || _b === void 0 ? void 0 : _b[pairAddress],
65
+ borrowPositions: {
66
+ borrowable0: borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions[types_1.PoolTokenType.BorrowableA],
67
+ borrowable1: borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions[types_1.PoolTokenType.BorrowableB]
68
+ },
66
69
  };
67
70
  });
68
71
  }
@@ -1,6 +1,5 @@
1
1
  import OffchainAccount from "../index";
2
- import { Borrowable, PoolTokenType } from "../../../config/types";
3
- import { SupplyPosition } from "../../offchainTypes";
2
+ import { Borrowable } from "../../../config/types";
4
3
  import OffchainLendingPool from "../../lendingPool";
5
4
  import OffchainLeveragedPosition from "./offchainLeveragedPosition";
6
5
  import OffchainAccountLendingPool from "./offchainAccountLendingPool";
@@ -30,11 +29,12 @@ export default class OffchainAccountLendingPoolV3 extends OffchainAccountLending
30
29
  getLiquidationPenalty: () => Promise<number>;
31
30
  getNftlp: () => import("./nftlp/offchainAccountNftlp").default;
32
31
  getLendingPoolPosition(): Promise<{
33
- [PoolTokenType.BorrowableA]?: SupplyPosition;
34
- [PoolTokenType.BorrowableB]?: SupplyPosition;
32
+ borrowable0: import("../../offchainTypes").SupplyPosition | undefined;
33
+ borrowable1: import("../../offchainTypes").SupplyPosition | undefined;
34
+ positions: {} | undefined;
35
35
  } | undefined>;
36
+ getTokenIds(): Promise<(string | undefined)[]>;
36
37
  getLeveragedPositions(): Promise<Array<OffchainLeveragedPosition>>;
37
38
  getLeveragedPositionsTotalBalanceUSD(): Promise<number>;
38
39
  getLeveragedPositionsNetAPR(): Promise<number>;
39
- getTokenIds(): Promise<(string | undefined)[]>;
40
40
  }
@@ -39,30 +39,46 @@ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default
39
39
  this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getLiquidationPenalty(); });
40
40
  this.getNftlp = () => this.collateral.getNftlp();
41
41
  }
42
+ /*--------------------------------------------------------------------------*
43
+ * User Lending Pool Data (NFTLP) *
44
+ *--------------------------------------------------------------------------*/
42
45
  getLendingPoolPosition() {
46
+ var _a;
43
47
  return __awaiter(this, void 0, void 0, function* () {
44
- // TODO rename and refactor
45
48
  const userData = yield this.account.getUserData();
46
- if (!userData)
47
- return undefined;
48
- const userDataOfFactory = userData[this.lendingPool.getFactory()];
49
+ const userDataOfFactory = userData === null || userData === void 0 ? void 0 : userData[this.lendingPool.getFactory()];
49
50
  if (!userDataOfFactory)
50
- return undefined;
51
+ return;
51
52
  const pairAddress = this.lendingPool.getPairAddress();
52
53
  const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
54
+ const positions = (_a = userDataOfFactory === null || userDataOfFactory === void 0 ? void 0 : userDataOfFactory.positions) === null || _a === void 0 ? void 0 : _a[pairAddress];
55
+ const positionsByTokenId = positions === null || positions === void 0 ? void 0 : positions.reduce((acc, position) => {
56
+ acc[position.tokenId] = position;
57
+ return acc;
58
+ }, {});
53
59
  return {
54
- [types_1.PoolTokenType.BorrowableA]: supplyPositions
55
- ? supplyPositions[types_1.PoolTokenType.BorrowableA]
56
- : undefined,
57
- [types_1.PoolTokenType.BorrowableB]: supplyPositions
58
- ? supplyPositions[types_1.PoolTokenType.BorrowableB]
59
- : undefined,
60
+ borrowable0: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableA],
61
+ borrowable1: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableB],
62
+ positions: positionsByTokenId
60
63
  };
61
64
  });
62
65
  }
63
- // Gets the token ids for a user
64
- //public async getTotalBorrowsUSD(): Promise<number> {
65
- //}
66
+ /*--------------------------------------------------------------------------*
67
+ * Getters *
68
+ *--------------------------------------------------------------------------*/
69
+ // Returns all tokenIds for a user in this lending pool
70
+ getTokenIds() {
71
+ var _a, _b;
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const userData = yield this.account.getUserData();
74
+ if (!userData)
75
+ return [];
76
+ const factory = this.getFactory();
77
+ const pairAddress = this.getLendingPool().getPairAddress();
78
+ const positions = ((_b = (_a = userData[factory]) === null || _a === void 0 ? void 0 : _a.positions) === null || _b === void 0 ? void 0 : _b[pairAddress]) || [];
79
+ return positions.map(pos => pos.tokenId);
80
+ });
81
+ }
66
82
  getLeveragedPositions() {
67
83
  return __awaiter(this, void 0, void 0, function* () {
68
84
  return [];
@@ -78,17 +94,5 @@ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default
78
94
  return 1;
79
95
  });
80
96
  }
81
- getTokenIds() {
82
- var _a, _b;
83
- return __awaiter(this, void 0, void 0, function* () {
84
- const userData = yield this.account.getUserData();
85
- if (!userData)
86
- return [];
87
- const factory = this.getLendingPool().getFactory();
88
- const pairAddress = this.getLendingPool().getPairAddress();
89
- const positions = ((_b = (_a = userData[factory]) === null || _a === void 0 ? void 0 : _a.positions) === null || _b === void 0 ? void 0 : _b[pairAddress]) || [];
90
- return positions.map(pos => pos.tokenId);
91
- });
92
- }
93
97
  }
94
98
  exports.default = OffchainAccountLendingPoolV3;
@@ -1,8 +1,8 @@
1
- import Offchain from '../index';
2
- import { Address, AddressIndex, Factory, FactoryIndex } from '../../config/types';
3
- import OffchainAccountLendingPool from './lendingPool';
4
- import OffchainAccountVault from './vault/offchainAccountVault';
5
- import { VaultPosition, UserData } from '../offchainTypes';
1
+ import Offchain from "../index";
2
+ import { Address, AddressIndex, Factory, FactoryIndex } from "../../config/types";
3
+ import OffchainAccountLendingPool from "./lendingPool";
4
+ import OffchainAccountVault from "./vault/offchainAccountVault";
5
+ import { VaultPosition, UserData } from "../offchainTypes";
6
6
  export default class OffchainAccount {
7
7
  private readonly offchain;
8
8
  private readonly accountAddress;
@@ -22,4 +22,5 @@ export default class OffchainAccount {
22
22
  getVaultsSuppliedUSD(): Promise<number>;
23
23
  getVaultsEarningsUSD(): Promise<number>;
24
24
  getVaultsYearlyYieldUSD(): Promise<number>;
25
+ getNftlpPositions(): Promise<FactoryIndex<Address[]>>;
25
26
  }
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const offchainAccountVault_1 = __importDefault(require("./vault/offchainAccountVault"));
16
+ const offchainTypes_1 = require("../offchainTypes");
16
17
  class OffchainAccount {
17
18
  constructor(offchain, account) {
18
19
  this.getOffchain = () => this.offchain;
@@ -131,11 +132,32 @@ class OffchainAccount {
131
132
  const vaultsOfType = vaultsUserData[vaultType];
132
133
  for (const address in vaultsOfType) {
133
134
  const vault = yield this.getVault(address);
134
- yieldUSD += (yield vault.getValue()) * (yield vault.getPoolToken().getSupplyAPR());
135
+ yieldUSD +=
136
+ (yield vault.getValue()) *
137
+ (yield vault.getPoolToken().getSupplyAPR());
135
138
  }
136
139
  }
137
140
  return yieldUSD;
138
141
  });
139
142
  }
143
+ getNftlpPositions() {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const result = {};
146
+ const userData = yield this.getUserData();
147
+ if (userData === null)
148
+ return result;
149
+ for (const factory in userData) {
150
+ // Check for V3 explicitely, not necesary since `positions` doesn't exist in v2
151
+ if (!(0, offchainTypes_1.isV3)(factory))
152
+ continue;
153
+ result[factory] = [];
154
+ const collateralPositions = userData[factory].positions;
155
+ for (const lendingPool in collateralPositions) {
156
+ result[factory].push(lendingPool);
157
+ }
158
+ }
159
+ return result;
160
+ });
161
+ }
140
162
  }
141
163
  exports.default = OffchainAccount;
@@ -23,6 +23,7 @@ export interface SupplyPositionsParams {
23
23
  }
24
24
  export interface BorrowPositionsParams {
25
25
  networks?: Array<Networks>;
26
+ factories?: Array<Factory>;
26
27
  }
27
28
  export interface VaultPositionsParams {
28
29
  networks?: Array<Networks>;
@@ -60,4 +61,5 @@ export default class OffchainMultichainAccount {
60
61
  getVaultsBalanceUSD(): Promise<number>;
61
62
  getSupplyBalanceUSD(): Promise<number>;
62
63
  getNetAPR(): Promise<number>;
64
+ getNftlpPositions(params?: BorrowPositionsParams, orderBy?: BorrowPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
63
65
  }
@@ -80,9 +80,10 @@ class OffchainMultichainAccount {
80
80
  });
81
81
  }
82
82
  getBorrowPositions(params = {}, orderBy = BorrowPositionsOrderBy.TVL) {
83
- var _a;
83
+ var _a, _b;
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
85
  const allNetworks = (_a = params.networks) !== null && _a !== void 0 ? _a : Object.values(types_1.Networks);
86
+ const factories = (_b = params.factories) !== null && _b !== void 0 ? _b : Object.values(types_1.Factory);
86
87
  // Get user supply positions in each network
87
88
  const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
88
89
  const offchainAccount = this.getOffchainAccount(network);
@@ -234,5 +235,29 @@ class OffchainMultichainAccount {
234
235
  return 1;
235
236
  });
236
237
  }
238
+ getNftlpPositions(params = {}, orderBy = BorrowPositionsOrderBy.TVL) {
239
+ var _a;
240
+ return __awaiter(this, void 0, void 0, function* () {
241
+ const allNetworks = (_a = params.networks) !== null && _a !== void 0 ? _a : Object.values(types_1.Networks);
242
+ // Get user supply positions in each network
243
+ const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
244
+ const offchainAccount = this.getOffchainAccount(network);
245
+ const userData = yield offchainAccount.getUserData();
246
+ if (!userData)
247
+ return [];
248
+ const positions = [];
249
+ const borrowPositions = yield offchainAccount.getNftlpPositions();
250
+ for (const factory in borrowPositions) {
251
+ const poolsOfFactory = borrowPositions[factory];
252
+ for (const poolAddress of poolsOfFactory) {
253
+ positions.push(offchainAccount.getLendingPool(factory, poolAddress));
254
+ }
255
+ }
256
+ return Promise.all(positions);
257
+ }));
258
+ const results = yield Promise.all(networkPromises);
259
+ return results.flat();
260
+ });
261
+ }
237
262
  }
238
263
  exports.default = OffchainMultichainAccount;
@@ -1,10 +1,10 @@
1
- import { AddressIndex, Factory, PoolTokenType } from '../../../config/types';
2
- import { Position, CollateralPosition, BorrowPosition } from '../../offchainTypes';
3
- import Offchain from '../../offchain';
4
- export declare function initializeV3Positions(offchain: Offchain, factory: Factory, rawUserData: any): Promise<{
5
- positions: AddressIndex<Position[]>;
1
+ import { AddressIndex, Factory, PoolTokenType } from "../../../config/types";
2
+ import { NftlpPosition, CollateralPosition, BorrowPosition, RawV3UserData, RawV2UserData } from "../../offchainTypes";
3
+ import Offchain from "../../offchain";
4
+ export declare function initializeV3Positions(offchain: Offchain, factory: Factory, rawUserData: RawV3UserData): Promise<{
5
+ positions: AddressIndex<NftlpPosition[]>;
6
6
  }>;
7
- export declare function initializeV2Positions(offchain: Offchain, factory: Factory, rawUserData: any): Promise<{
7
+ export declare function initializeV2Positions(offchain: Offchain, factory: Factory, rawUserData: RawV2UserData): Promise<{
8
8
  collateralPositions: AddressIndex<CollateralPosition[]>;
9
9
  borrowPositions: AddressIndex<{
10
10
  [key in PoolTokenType]?: BorrowPosition;
@@ -22,10 +22,16 @@ function initializeV3Positions(offchain, factory, rawUserData) {
22
22
  return { positions };
23
23
  for (const position of rawUserData.positions) {
24
24
  const lendingPoolId = position.lendingPool.id;
25
- // Initialize and add
26
25
  if (!positions[lendingPoolId])
27
26
  positions[lendingPoolId] = [];
28
- positions[lendingPoolId].push(position);
27
+ // TODO: This is probably over thinking it , but if we're deprecating PoolTokenType, then how can we order Position?
28
+ // From univ3 factory: (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
29
+ // In our case, 1 position -> 2 borrowPositiosn, where the ID of the borrowPosition is the borrowable ID,
30
+ // and it sorts by borrowable Address instead of underlying Address.
31
+ const orderedPosition = Object.assign(Object.assign({}, position), { borrowPositions: position.borrowPositions.sort((a, b) => BigInt(a.borrowable.underlying.id) < BigInt(b.borrowable.underlying.id)
32
+ ? -1
33
+ : 1) });
34
+ positions[lendingPoolId].push(orderedPosition);
29
35
  }
30
36
  return { positions };
31
37
  });
@@ -43,7 +49,7 @@ function initializeV2Positions(offchain, factory, rawUserData) {
43
49
  }
44
50
  collateralPositions[lendingPoolId].push(collateralPosition);
45
51
  }
46
- // Borrow positions
52
+ // Borrow positions
47
53
  for (const borrowPosition of rawUserData.borrowPositions) {
48
54
  const lendingPoolId = borrowPosition.borrowable.lendingPool.id;
49
55
  const underlyingId = borrowPosition.borrowable.underlying.id;
@@ -132,7 +132,7 @@ export interface V2UserData {
132
132
  [key in PoolTokenType]?: BorrowPosition;
133
133
  }>;
134
134
  }
135
- export interface Position {
135
+ export interface NftlpPosition {
136
136
  id: string;
137
137
  tokenId: string;
138
138
  lendingPool: {
@@ -141,18 +141,18 @@ export interface Position {
141
141
  borrowPositions: BorrowPosition[];
142
142
  }
143
143
  export interface RawV3UserData {
144
- positions: Position[];
144
+ positions: NftlpPosition[];
145
145
  supplyPositions: SupplyPosition[];
146
146
  }
147
147
  export interface V3UserData {
148
- positions: AddressIndex<Position[]>;
148
+ positions: AddressIndex<NftlpPosition[]>;
149
149
  supplyPositions: AddressIndex<{
150
150
  [key in PoolTokenType]?: SupplyPosition;
151
151
  }>;
152
152
  }
153
153
  export type RawUserData = RawV2UserData | RawV3UserData;
154
154
  export interface UserData {
155
- positions?: AddressIndex<Position[]>;
155
+ positions?: AddressIndex<NftlpPosition[]>;
156
156
  collateralPositions?: AddressIndex<CollateralPosition[]>;
157
157
  borrowPositions?: AddressIndex<{
158
158
  [key in PoolTokenType]?: BorrowPosition;
@@ -161,6 +161,18 @@ export interface UserData {
161
161
  [key in PoolTokenType]?: SupplyPosition;
162
162
  }>;
163
163
  }
164
+ export interface LendingPoolPosition {
165
+ borrowable0?: SupplyPosition;
166
+ borrowable1?: SupplyPosition;
167
+ collateralPosition?: CollateralPosition[];
168
+ borrowPositions?: {
169
+ borrowable0?: BorrowPosition;
170
+ borrowable1?: BorrowPosition;
171
+ };
172
+ positions?: {
173
+ [tokenId: string]: NftlpPosition;
174
+ };
175
+ }
164
176
  export interface VaultBorrowable {
165
177
  pair: string;
166
178
  address: Address;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.117",
3
+ "version": "2.1.118",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",