impermax-sdk 2.1.337 → 2.1.338
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/offchainAccount.js +0 -1
- package/lib/offchain/initializer/user/index.d.ts +2 -2
- package/lib/offchain/initializer/user/index.js +2 -2
- package/lib/offchain/initializer/user/userLendingPool/index.js +97 -0
- package/package.json +1 -1
- package/lib/offchain/initializer/user/lendingPools/index.js +0 -96
- /package/lib/offchain/initializer/user/{lendingPools → userLendingPool}/index.d.ts +0 -0
- /package/lib/offchain/initializer/user/{lendingPools → userLendingPool}/positionsV2.d.ts +0 -0
- /package/lib/offchain/initializer/user/{lendingPools → userLendingPool}/positionsV2.js +0 -0
- /package/lib/offchain/initializer/user/{lendingPools → userLendingPool}/positionsV3.d.ts +0 -0
- /package/lib/offchain/initializer/user/{lendingPools → userLendingPool}/positionsV3.js +0 -0
- /package/lib/offchain/initializer/user/{vaults → userVault}/index.d.ts +0 -0
- /package/lib/offchain/initializer/user/{vaults → userVault}/index.js +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './userVault';
|
|
2
|
+
export * from './userLendingPool';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./userVault"), exports);
|
|
18
|
+
__exportStar(require("./userLendingPool"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchUserData = exports.initializeUserData = exports.getUserData = void 0;
|
|
4
|
+
const subgraphs_1 = require("../../../../config/subgraphs");
|
|
5
|
+
const types_1 = require("../../../../config/types");
|
|
6
|
+
const offchainTypes_1 = require("../../../offchainTypes");
|
|
7
|
+
const positionsV2_1 = require("./positionsV2");
|
|
8
|
+
const positionsV3_1 = require("./positionsV3");
|
|
9
|
+
/*--------------------------------------------------------------------------*
|
|
10
|
+
* Getters *
|
|
11
|
+
*--------------------------------------------------------------------------*/
|
|
12
|
+
async function getUserData(account) {
|
|
13
|
+
if (!(account in this.usersData))
|
|
14
|
+
this.usersData[account] = this.initializeUserData(account);
|
|
15
|
+
return this.usersData[account];
|
|
16
|
+
}
|
|
17
|
+
exports.getUserData = getUserData;
|
|
18
|
+
/*--------------------------------------------------------------------------*
|
|
19
|
+
* Initializers *
|
|
20
|
+
*--------------------------------------------------------------------------*/
|
|
21
|
+
// For supply positions v2/v3 remains unchanged.
|
|
22
|
+
// For collateralPositions/borrowPositions we separate into:
|
|
23
|
+
// - `initializeV2Positions` for V2
|
|
24
|
+
// - `initializeV3Positions` for V3
|
|
25
|
+
async function initializeUserData(account) {
|
|
26
|
+
const result = {};
|
|
27
|
+
const userData = await this.fetchUserData(account);
|
|
28
|
+
if (!userData)
|
|
29
|
+
return null;
|
|
30
|
+
for (const factory in userData) {
|
|
31
|
+
const userDataOfFactory = userData[factory];
|
|
32
|
+
result[factory] = {
|
|
33
|
+
positions: {},
|
|
34
|
+
collateralPositions: {},
|
|
35
|
+
supplyPositions: {},
|
|
36
|
+
borrowPositions: {},
|
|
37
|
+
};
|
|
38
|
+
// Get collateral/borrow positions for V2/V3
|
|
39
|
+
if ((0, offchainTypes_1.isV3Factory)(factory)) {
|
|
40
|
+
// TODO: V3 pair filter (nftlp)
|
|
41
|
+
const v3Data = await (0, positionsV3_1.initializeV3Positions)(this, factory, userDataOfFactory);
|
|
42
|
+
result[factory].positions = v3Data.positions;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Pass filtered pairs
|
|
46
|
+
const v2Data = await (0, positionsV2_1.initializeV2Positions)(this, factory, userDataOfFactory, []);
|
|
47
|
+
result[factory].collateralPositions = v2Data.collateralPositions;
|
|
48
|
+
result[factory].borrowPositions = v2Data.borrowPositions;
|
|
49
|
+
}
|
|
50
|
+
// Supply positions is same for v2 and v3
|
|
51
|
+
for (const supplyPosition of userDataOfFactory.supplyPositions) {
|
|
52
|
+
const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
|
|
53
|
+
// Don't include supply positions if lending pool is not in pair list
|
|
54
|
+
// if (pairs.length > 0 && !pairs.includes(lendingPoolId)) continue
|
|
55
|
+
const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
56
|
+
const lendingPool = await this.getLendingPool(factory, lendingPoolId);
|
|
57
|
+
if (!lendingPool) {
|
|
58
|
+
console.error("Can't resolve supplyPosition because lendingPool is null. Lending pool:", lendingPoolId, this.network);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const borrowableA = lendingPool.getBorrowableA();
|
|
62
|
+
const addressA = await borrowableA.getUnderlyingAddress();
|
|
63
|
+
const poolTokenType = underlyingId === addressA
|
|
64
|
+
? types_1.PoolTokenType.BorrowableA
|
|
65
|
+
: types_1.PoolTokenType.BorrowableB;
|
|
66
|
+
if (!(lendingPoolId in result[factory].supplyPositions)) {
|
|
67
|
+
result[factory].supplyPositions[lendingPoolId] = {};
|
|
68
|
+
}
|
|
69
|
+
result[factory].supplyPositions[lendingPoolId][poolTokenType] = supplyPosition;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
exports.initializeUserData = initializeUserData;
|
|
75
|
+
/*--------------------------------------------------------------------------*
|
|
76
|
+
* Fetchers *
|
|
77
|
+
*--------------------------------------------------------------------------*/
|
|
78
|
+
// User Data
|
|
79
|
+
async function fetchUserData(account) {
|
|
80
|
+
const positions = {};
|
|
81
|
+
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
82
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
83
|
+
// Decides for v3 query internally
|
|
84
|
+
const result = await this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.userQuery(account, this.network, factory));
|
|
85
|
+
if (!result || !result.data?.user)
|
|
86
|
+
continue;
|
|
87
|
+
const user = result.data.user;
|
|
88
|
+
positions[factory] = {
|
|
89
|
+
positions: user.positions,
|
|
90
|
+
supplyPositions: user.supplyPositions,
|
|
91
|
+
collateralPositions: user.collateralPositions,
|
|
92
|
+
borrowPositions: user.borrowPositions, // Undefined if V3
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return positions;
|
|
96
|
+
}
|
|
97
|
+
exports.fetchUserData = fetchUserData;
|
package/package.json
CHANGED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchUserData = exports.initializeUserData = exports.getUserData = void 0;
|
|
4
|
-
// import { initializeV2Positions } from "./positionsV2";
|
|
5
|
-
// import { initializeV3Positions } from "./positionsV3";
|
|
6
|
-
/*--------------------------------------------------------------------------*
|
|
7
|
-
* Getters *
|
|
8
|
-
*--------------------------------------------------------------------------*/
|
|
9
|
-
async function getUserData(account) {
|
|
10
|
-
console.log("Account: ", account);
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
exports.getUserData = getUserData;
|
|
14
|
-
/*--------------------------------------------------------------------------*
|
|
15
|
-
* Initializers *
|
|
16
|
-
*--------------------------------------------------------------------------*/
|
|
17
|
-
// For supply positions v2/v3 remains unchanged.
|
|
18
|
-
// For collateralPositions/borrowPositions we separate into:
|
|
19
|
-
// - `initializeV2Positions` for V2
|
|
20
|
-
// - `initializeV3Positions` for V3
|
|
21
|
-
async function initializeUserData(account) {
|
|
22
|
-
return null;
|
|
23
|
-
// const result: FactoryIndex<UserData> = {};
|
|
24
|
-
// const userData = await this.fetchUserData(account);
|
|
25
|
-
// if (!userData) return null;
|
|
26
|
-
// for (const factory in userData) {
|
|
27
|
-
// const userDataOfFactory = userData[factory];
|
|
28
|
-
// result[factory] = {
|
|
29
|
-
// positions: {},
|
|
30
|
-
// collateralPositions: {},
|
|
31
|
-
// supplyPositions: {},
|
|
32
|
-
// borrowPositions: {},
|
|
33
|
-
// };
|
|
34
|
-
// // Get collateral/borrow positions for V2/V3
|
|
35
|
-
// if (isV3Factory(factory)) {
|
|
36
|
-
// // TODO: V3 pair filter (nftlp)
|
|
37
|
-
// const v3Data = await initializeV3Positions(this, factory as Factory, userDataOfFactory);
|
|
38
|
-
// result[factory].positions = v3Data.positions;
|
|
39
|
-
// } else {
|
|
40
|
-
// // Pass filtered pairs
|
|
41
|
-
// const v2Data = await initializeV2Positions(this, factory as Factory, userDataOfFactory, []);
|
|
42
|
-
// result[factory].collateralPositions = v2Data.collateralPositions;
|
|
43
|
-
// result[factory].borrowPositions = v2Data.borrowPositions;
|
|
44
|
-
// }
|
|
45
|
-
// // Supply positions is same for v2 and v3
|
|
46
|
-
// for (const supplyPosition of userDataOfFactory.supplyPositions) {
|
|
47
|
-
// const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
|
|
48
|
-
// // Don't include supply positions if lending pool is not in pair list
|
|
49
|
-
// // if (pairs.length > 0 && !pairs.includes(lendingPoolId)) continue
|
|
50
|
-
// const underlyingId = supplyPosition.borrowable.underlying.id;
|
|
51
|
-
// const lendingPool = await this.getLendingPool(factory as Factory, lendingPoolId);
|
|
52
|
-
// if (!lendingPool) {
|
|
53
|
-
// console.error("Can't resolve supplyPosition because lendingPool is null. Lending pool:", lendingPoolId, this.network);
|
|
54
|
-
// continue;
|
|
55
|
-
// }
|
|
56
|
-
// const borrowableA = lendingPool.getBorrowableA();
|
|
57
|
-
// const addressA = await borrowableA.getUnderlyingAddress();
|
|
58
|
-
// const poolTokenType = underlyingId === addressA
|
|
59
|
-
// ? PoolTokenType.BorrowableA
|
|
60
|
-
// : PoolTokenType.BorrowableB;
|
|
61
|
-
// if (!(lendingPoolId in result[factory].supplyPositions)) {
|
|
62
|
-
// result[factory].supplyPositions[lendingPoolId] = {};
|
|
63
|
-
// }
|
|
64
|
-
// result[factory].supplyPositions[lendingPoolId][poolTokenType] = supplyPosition;
|
|
65
|
-
// }
|
|
66
|
-
// }
|
|
67
|
-
// return result;
|
|
68
|
-
}
|
|
69
|
-
exports.initializeUserData = initializeUserData;
|
|
70
|
-
/*--------------------------------------------------------------------------*
|
|
71
|
-
* Fetchers *
|
|
72
|
-
*--------------------------------------------------------------------------*/
|
|
73
|
-
// User Data
|
|
74
|
-
async function fetchUserData(account) {
|
|
75
|
-
return 0;
|
|
76
|
-
// const positions: FactoryIndex<RawUserData> = {};
|
|
77
|
-
// for (const factory in IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
78
|
-
// const subgraphs = IMPERMAX_SUBGRAPH_URL[this.network][factory] as string[];
|
|
79
|
-
// // Decides for v3 query internally
|
|
80
|
-
// const result = await this.getEndpointManager().fetch(
|
|
81
|
-
// subgraphs,
|
|
82
|
-
// this.network,
|
|
83
|
-
// (queryBuilder) => queryBuilder.userQuery(account, this.network, factory as Factory),
|
|
84
|
-
// );
|
|
85
|
-
// if (!result || !result.data?.user) continue;
|
|
86
|
-
// const user = result.data.user;
|
|
87
|
-
// positions[factory as Factory] = {
|
|
88
|
-
// positions: user.positions, // Undefined if v2
|
|
89
|
-
// supplyPositions: user.supplyPositions,
|
|
90
|
-
// collateralPositions: user.collateralPositions, // Undefined if V3
|
|
91
|
-
// borrowPositions: user.borrowPositions, // Undefined if V3
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
// return positions;
|
|
95
|
-
}
|
|
96
|
-
exports.fetchUserData = fetchUserData;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|