impermax-sdk 2.1.338 → 2.1.339
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/initializer/index.d.ts +1 -1
- package/lib/offchain/initializer/index.js +1 -1
- package/lib/offchain/initializer/privateApi/index.d.ts +2 -0
- package/lib/offchain/initializer/privateApi/index.js +18 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/index.d.ts +1 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/index.js +17 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/index.d.ts +1 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/index.js +17 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/index.d.ts +1 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/index.js +17 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/uniswapV3Charts.d.ts +5 -0
- package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/uniswapV3Charts.js +37 -0
- package/lib/offchain/initializer/privateApi/vaultsApi/index.d.ts +1 -0
- package/lib/offchain/initializer/privateApi/vaultsApi/index.js +17 -0
- package/lib/offchain/initializer/{private-api.d.ts → privateApi/vaultsApi/vaultBorrowables.d.ts} +3 -3
- package/lib/offchain/initializer/{private-api.js → privateApi/vaultsApi/vaultBorrowables.js} +7 -2
- package/lib/offchain/initializer/user/userLendingPool/positionsV3.d.ts +10 -5
- package/lib/offchain/initializer/user/userLendingPool/positionsV3.js +35 -13
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +1 -8
- package/lib/offchain/offchain.d.ts +7 -7
- package/lib/offchain/offchain.js +5 -2
- package/lib/offchain/offchainTypes.d.ts +13 -0
- package/lib/offchain/queries/apis/ponder/index.d.ts +2 -1
- package/lib/offchain/queries/apis/ponder/index.js +8 -3
- package/lib/offchain/queries/apis/thegraph/index.d.ts +1 -1
- package/lib/offchain/queries/apis/thegraph/index.js +1 -1
- package/lib/offchain/queries/interfaces/query-builder.d.ts +1 -1
- package/package.json +1 -1
|
@@ -24,6 +24,6 @@ __exportStar(require("./whitelist"), exports);
|
|
|
24
24
|
__exportStar(require("./staking"), exports);
|
|
25
25
|
__exportStar(require("./farming"), exports);
|
|
26
26
|
__exportStar(require("./tvl"), exports);
|
|
27
|
-
__exportStar(require("./
|
|
27
|
+
__exportStar(require("./privateApi"), exports);
|
|
28
28
|
__exportStar(require("./borrowers"), exports);
|
|
29
29
|
__exportStar(require("./nftlps"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vaultsApi"), exports);
|
|
18
|
+
__exportStar(require("./lendingPoolsApi"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './nftlp';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nftlp"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './uniswapV3';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./uniswapV3"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './uniswapV3Charts';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./uniswapV3Charts"), exports);
|
package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/uniswapV3Charts.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AddressIndex, Address } from "../../../../../../config/types";
|
|
2
|
+
import Offchain from "../../../../../offchain";
|
|
3
|
+
import { PoolChart } from "../../../../../offchainTypes";
|
|
4
|
+
export declare function fetchUniswapV3Charts(this: Offchain): Promise<AddressIndex<PoolChart[]>>;
|
|
5
|
+
export declare function getUniswapV3Chart(this: Offchain, uniswapV3Pool: Address): Promise<PoolChart[]>;
|
package/lib/offchain/initializer/privateApi/lendingPoolsApi/nftlp/uniswapV3/uniswapV3Charts.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// private-api: uniswapv3 charts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getUniswapV3Chart = exports.fetchUniswapV3Charts = void 0;
|
|
5
|
+
const types_1 = require("../../../../../../config/types");
|
|
6
|
+
const private_api_1 = require("../../../../../../config/private-api");
|
|
7
|
+
/*--------------------------------------------------------------------------*
|
|
8
|
+
* Fetchers *
|
|
9
|
+
*--------------------------------------------------------------------------*/
|
|
10
|
+
// Fetches all charts of all lending pools for an NFTLP factory (ie. Dex)
|
|
11
|
+
async function fetchUniswapV3Charts() {
|
|
12
|
+
const api = private_api_1.NFTLP_UNIV3_API[this.network];
|
|
13
|
+
if (!api) {
|
|
14
|
+
console.log(`Missing NFTLP uniswapV3 subgraph on ${this.network}?`);
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(api.concat('pools/charts')).then(i => i.json());
|
|
19
|
+
return response;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.log(`Failed to fetch uniswapV3 Pool data on ${this.network}`);
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.fetchUniswapV3Charts = fetchUniswapV3Charts;
|
|
27
|
+
/*--------------------------------------------------------------------------*
|
|
28
|
+
* Getters *
|
|
29
|
+
*--------------------------------------------------------------------------*/
|
|
30
|
+
async function getUniswapV3Chart(uniswapV3Pool) {
|
|
31
|
+
if (!this.extensionChartsData[types_1.Extension.UniswapV3]) {
|
|
32
|
+
this.extensionChartsData[types_1.Extension.UniswapV3] = this.fetchUniswapV3Charts();
|
|
33
|
+
}
|
|
34
|
+
const poolChartData = await this.extensionChartsData[types_1.Extension.UniswapV3];
|
|
35
|
+
return poolChartData[uniswapV3Pool];
|
|
36
|
+
}
|
|
37
|
+
exports.getUniswapV3Chart = getUniswapV3Chart;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vaultBorrowables';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vaultBorrowables"), exports);
|
package/lib/offchain/initializer/{private-api.d.ts → privateApi/vaultsApi/vaultBorrowables.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AddressIndex, VaultType, Address } from "
|
|
2
|
-
import { VaultBorrowable } from "
|
|
3
|
-
import Offchain from "
|
|
1
|
+
import { AddressIndex, VaultType, Address } from "../../../../config/types";
|
|
2
|
+
import { VaultBorrowable } from "../../../offchainTypes";
|
|
3
|
+
import Offchain from "../../../offchain";
|
|
4
4
|
export declare function fetchVaultBorrowables(this: Offchain, vaultType: VaultType): Promise<AddressIndex<VaultBorrowable[]>>;
|
|
5
5
|
export declare function getVaultBorrowables(this: Offchain, vaultType: VaultType, vaultAddress: Address): Promise<VaultBorrowable[] | null>;
|
package/lib/offchain/initializer/{private-api.js → privateApi/vaultsApi/vaultBorrowables.js}
RENAMED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// private-api: Vault borrowables
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getVaultBorrowables = exports.fetchVaultBorrowables = void 0;
|
|
5
|
-
const private_api_1 = require("
|
|
6
|
-
|
|
5
|
+
const private_api_1 = require("../../../../config/private-api");
|
|
6
|
+
/*--------------------------------------------------------------------------*
|
|
7
|
+
* Fetchers *
|
|
8
|
+
*--------------------------------------------------------------------------*/
|
|
7
9
|
async function fetchVaultBorrowables(vaultType) {
|
|
8
10
|
const api = private_api_1.IMPERMAX_VAULT_API[this.network][vaultType];
|
|
9
11
|
if (!api) {
|
|
@@ -26,6 +28,9 @@ async function fetchVaultBorrowables(vaultType) {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
exports.fetchVaultBorrowables = fetchVaultBorrowables;
|
|
31
|
+
/*--------------------------------------------------------------------------*
|
|
32
|
+
* Getters *
|
|
33
|
+
*--------------------------------------------------------------------------*/
|
|
29
34
|
async function getVaultBorrowables(vaultType, vaultAddress) {
|
|
30
35
|
if (!this.vaultBorrowablesData[vaultType]) {
|
|
31
36
|
this.vaultBorrowablesData[vaultType] = this.fetchVaultBorrowables(vaultType);
|
|
@@ -16,12 +16,17 @@ import Offchain from "../../../offchain";
|
|
|
16
16
|
* borrowPositions: BorrowPosition[];
|
|
17
17
|
* }
|
|
18
18
|
*
|
|
19
|
-
* Now we need to get the detailed NFTLP position data for each position
|
|
20
|
-
*
|
|
19
|
+
* Now we need to get the detailed NFTLP position data for each position from the individual NFTLP Factory Subgraphs to combine it:
|
|
20
|
+
* {
|
|
21
|
+
* ...position,
|
|
22
|
+
* dex: Extension,
|
|
23
|
+
* nftlp: NftlpData -> unique nftlp data from each dex (univ3 nftlp data will be different to univ2 nftlp, etc.)
|
|
24
|
+
* }
|
|
21
25
|
*
|
|
22
|
-
* 1. Get
|
|
23
|
-
* 2.
|
|
24
|
-
* 3.
|
|
26
|
+
* 1. Get all unique NFTLP Factories (ie. Dexes) in the positions
|
|
27
|
+
* 2. Group position IDs by dexes (`poolId-TokenId`) and cache position to combine later
|
|
28
|
+
* 3. Loop through each dex, get subgraph and query all position IDs in 1 call
|
|
29
|
+
* 4. Combine position we got from IMPERMAX_SUBGRAPH_URL with the unique nftlp position data from step 3
|
|
25
30
|
*/
|
|
26
31
|
export declare function initializeV3Positions(offchain: Offchain, factory: Factory, rawUserData: RawV3UserData): Promise<{
|
|
27
32
|
positions: AddressIndex<NftlpPosition[]>;
|
|
@@ -17,25 +17,41 @@ const nftlp_1 = require("../../../../config/nftlp");
|
|
|
17
17
|
* borrowPositions: BorrowPosition[];
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
|
-
* Now we need to get the detailed NFTLP position data for each position
|
|
21
|
-
*
|
|
20
|
+
* Now we need to get the detailed NFTLP position data for each position from the individual NFTLP Factory Subgraphs to combine it:
|
|
21
|
+
* {
|
|
22
|
+
* ...position,
|
|
23
|
+
* dex: Extension,
|
|
24
|
+
* nftlp: NftlpData -> unique nftlp data from each dex (univ3 nftlp data will be different to univ2 nftlp, etc.)
|
|
25
|
+
* }
|
|
22
26
|
*
|
|
23
|
-
* 1. Get
|
|
24
|
-
* 2.
|
|
25
|
-
* 3.
|
|
27
|
+
* 1. Get all unique NFTLP Factories (ie. Dexes) in the positions
|
|
28
|
+
* 2. Group position IDs by dexes (`poolId-TokenId`) and cache position to combine later
|
|
29
|
+
* 3. Loop through each dex, get subgraph and query all position IDs in 1 call
|
|
30
|
+
* 4. Combine position we got from IMPERMAX_SUBGRAPH_URL with the unique nftlp position data from step 3
|
|
26
31
|
*/
|
|
27
32
|
async function initializeV3Positions(offchain, factory, rawUserData) {
|
|
28
33
|
// Shh
|
|
29
34
|
factory;
|
|
30
|
-
// Skip if no positions data (ie V2)
|
|
31
35
|
const positions = {};
|
|
36
|
+
// 1. Get all unique NFTLP factories (ie. Dexes)
|
|
37
|
+
const nftlpFactories = [...new Set(rawUserData.positions.map(position => position.lendingPool.nftlp.factory))];
|
|
38
|
+
const dexPositions = {};
|
|
39
|
+
const positionMap = new Map();
|
|
40
|
+
// 2. Group IDS by dexes and cache each position in a map to combine later
|
|
32
41
|
for (const position of rawUserData.positions) {
|
|
42
|
+
const factoryId = position.lendingPool.nftlp.factory;
|
|
33
43
|
const lendingPoolId = position.lendingPool.id;
|
|
34
44
|
if (!positions[lendingPoolId])
|
|
35
45
|
positions[lendingPoolId] = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
46
|
+
if (!dexPositions[factoryId])
|
|
47
|
+
dexPositions[factoryId] = [];
|
|
48
|
+
// Group position with its factory
|
|
49
|
+
dexPositions[factoryId].push(position.id);
|
|
50
|
+
// Cache position
|
|
51
|
+
positionMap.set(position.id, { position, lendingPoolId });
|
|
52
|
+
}
|
|
53
|
+
// 3. Get unique position data from dex subgraph
|
|
54
|
+
for (const nftlpFactory of nftlpFactories) {
|
|
39
55
|
const dex = (0, nftlp_1.getNftlpDex)(offchain.network, nftlpFactory);
|
|
40
56
|
if (dex === undefined) {
|
|
41
57
|
console.warn(`Unknown DEX for NFTLP factory ${nftlpFactory} on ${offchain.network}`);
|
|
@@ -46,12 +62,18 @@ async function initializeV3Positions(offchain, factory, rawUserData) {
|
|
|
46
62
|
console.warn(`No NFTLP endpoints found for ${dex} on ${offchain.network}`);
|
|
47
63
|
continue;
|
|
48
64
|
}
|
|
49
|
-
//
|
|
50
|
-
const nftlpData = await offchain.getEndpointManager().fetch(endpoints, offchain.network, (queryBuilder) => queryBuilder.nftlpPositionQuery(
|
|
65
|
+
// Fetch NFTLP Positions for this factory in one query
|
|
66
|
+
const nftlpData = await offchain.getEndpointManager().fetch(endpoints, offchain.network, (queryBuilder) => queryBuilder.nftlpPositionQuery(dex, dexPositions[nftlpFactory]));
|
|
51
67
|
if (!nftlpData || !nftlpData.data?.nftlpPositions)
|
|
52
68
|
continue;
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
// 4. Combine position with unique nftlp data
|
|
70
|
+
for (const nftlp of nftlpData.data.nftlpPositions) {
|
|
71
|
+
const positionInfo = positionMap.get(nftlp.id);
|
|
72
|
+
if (positionInfo) {
|
|
73
|
+
const { position, lendingPoolId } = positionInfo;
|
|
74
|
+
positions[lendingPoolId].push({ ...position, dex, nftlp });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
55
77
|
}
|
|
56
78
|
return { positions };
|
|
57
79
|
}
|
|
@@ -9,7 +9,6 @@ const offchainAccountNftlpUniswapV3_1 = __importDefault(require("../../account/l
|
|
|
9
9
|
const uniswapV3General_1 = require("../../../utils/nftlpMath/uniswapV3General");
|
|
10
10
|
const types_1 = require("../../../config/types");
|
|
11
11
|
const utils_1 = require("../../../utils");
|
|
12
|
-
const private_api_1 = require("../../../config/private-api");
|
|
13
12
|
const Q128 = 2 ** 128;
|
|
14
13
|
const Q256 = BigInt(2) ** BigInt(256);
|
|
15
14
|
class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
@@ -120,15 +119,9 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
120
119
|
const { address } = await this.getUniswapV3Pool(fee);
|
|
121
120
|
if (!address)
|
|
122
121
|
return 0;
|
|
123
|
-
const network = this.getLendingPool().getOffchain().network;
|
|
124
|
-
const api = private_api_1.NFTLP_UNIV3_API[network];
|
|
125
|
-
if (!api) {
|
|
126
|
-
console.log(`Missing NFTLP uniswapV3 subgraph on ${network}?`);
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
122
|
let feeGrowthData = [];
|
|
130
123
|
try {
|
|
131
|
-
feeGrowthData = await
|
|
124
|
+
feeGrowthData = await this.getLendingPool().getOffchain().getUniswapV3Charts(address.toLowerCase());
|
|
132
125
|
}
|
|
133
126
|
catch (err) { }
|
|
134
127
|
if (!feeGrowthData || feeGrowthData.length < 2) {
|
|
@@ -2,8 +2,8 @@ import * as initializer from './initializer';
|
|
|
2
2
|
import OffchainLendingPool from './lendingPool';
|
|
3
3
|
import OffchainSolidexHelper from './offchainSolidexHelper';
|
|
4
4
|
import OffchainAccount from './account';
|
|
5
|
-
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState, VaultType } from '../config/types';
|
|
6
|
-
import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable,
|
|
5
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState, VaultType, Extension } from '../config/types';
|
|
6
|
+
import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable, NftlpData, PoolChart } from './offchainTypes';
|
|
7
7
|
import OffchainVault from './vault/offchainVault';
|
|
8
8
|
import OffchainConfigManager from './configManager';
|
|
9
9
|
import { LlamaTvlChart } from './offchainAPRHelper';
|
|
@@ -42,15 +42,13 @@ export default class Offchain {
|
|
|
42
42
|
protected vaultsUsersData: {
|
|
43
43
|
[key in Address]?: Promise<AddressIndex<AddressIndex<VaultPosition>>>;
|
|
44
44
|
};
|
|
45
|
+
protected borrowersList: Promise<OffchainAccount[]> | null;
|
|
45
46
|
protected vaultBorrowablesData: {
|
|
46
47
|
[key in VaultType]?: Promise<AddressIndex<VaultBorrowable[]>>;
|
|
47
48
|
};
|
|
48
|
-
protected
|
|
49
|
-
[key in
|
|
50
|
-
[key: string]: NftlpPosition[];
|
|
51
|
-
}>>;
|
|
49
|
+
protected extensionChartsData: {
|
|
50
|
+
[key in Extension]?: Promise<AddressIndex<PoolChart[]>>;
|
|
52
51
|
};
|
|
53
|
-
protected borrowersList: Promise<OffchainAccount[]> | null;
|
|
54
52
|
constructor(offchainMultichain: OffchainMultichain, network: Networks);
|
|
55
53
|
cleanCache(): void;
|
|
56
54
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool | null>;
|
|
@@ -99,6 +97,8 @@ export default class Offchain {
|
|
|
99
97
|
getNftlpsData: typeof initializer.getNftlpsData;
|
|
100
98
|
getNftlpData: typeof initializer.getNftlpData;
|
|
101
99
|
protected initializeNftlpsData: typeof initializer.initializeNftlpsData;
|
|
100
|
+
protected fetchUniswapV3Charts: typeof initializer.fetchUniswapV3Charts;
|
|
101
|
+
getUniswapV3Charts: typeof initializer.getUniswapV3Chart;
|
|
102
102
|
getPairsList(factory: Factory, state?: PairState): Address[];
|
|
103
103
|
getCrossChainTVL(): Promise<number>;
|
|
104
104
|
getCrossChainTotalValueSupplied(): Promise<number>;
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -40,7 +40,8 @@ class Offchain {
|
|
|
40
40
|
this.deprecatedPairs = {};
|
|
41
41
|
this.blacklistedPairs = {};
|
|
42
42
|
this.disabledBorrowsPairs = [];
|
|
43
|
-
|
|
43
|
+
// 2. NFTLPs
|
|
44
|
+
this.extensionChartsData = {};
|
|
44
45
|
this.getSolidexHelper = () => this.solidexHelper;
|
|
45
46
|
this.getConfigManager = () => this.configManager;
|
|
46
47
|
// Multichain, 1 instance
|
|
@@ -99,6 +100,9 @@ class Offchain {
|
|
|
99
100
|
this.getNftlpsData = initializer.getNftlpsData;
|
|
100
101
|
this.getNftlpData = initializer.getNftlpData;
|
|
101
102
|
this.initializeNftlpsData = initializer.initializeNftlpsData;
|
|
103
|
+
// Private api initializers
|
|
104
|
+
this.fetchUniswapV3Charts = initializer.fetchUniswapV3Charts;
|
|
105
|
+
this.getUniswapV3Charts = initializer.getUniswapV3Chart;
|
|
102
106
|
// Config
|
|
103
107
|
this.offchainMultichain = offchainMultichain;
|
|
104
108
|
this.network = network;
|
|
@@ -129,7 +133,6 @@ class Offchain {
|
|
|
129
133
|
this.configManager.cleanCache();
|
|
130
134
|
this.getPriceHelper().cleanCache();
|
|
131
135
|
this.getAPRHelper().cleanCache();
|
|
132
|
-
this.allV3PositionsData = {};
|
|
133
136
|
this.borrowersList = null;
|
|
134
137
|
}
|
|
135
138
|
async getLendingPool(factory, pairAddress) {
|
|
@@ -274,3 +274,16 @@ export interface WhitelistData {
|
|
|
274
274
|
pair: string;
|
|
275
275
|
state: WhitelistState;
|
|
276
276
|
}
|
|
277
|
+
export type UniswapV3PoolChart = {
|
|
278
|
+
id: string;
|
|
279
|
+
uniswapV3PoolId: Address;
|
|
280
|
+
tick: number;
|
|
281
|
+
liquidity: string;
|
|
282
|
+
sqrtPriceX96: string;
|
|
283
|
+
feeGrowthGlobal0X128: string;
|
|
284
|
+
feeGrowthGlobal1X128: string;
|
|
285
|
+
block: number;
|
|
286
|
+
timestamp: number;
|
|
287
|
+
timestampUTC: string;
|
|
288
|
+
};
|
|
289
|
+
export type PoolChart = UniswapV3PoolChart;
|
|
@@ -14,7 +14,8 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
|
|
|
14
14
|
proposalQuery(id: number): import("graphql").DocumentNode;
|
|
15
15
|
ximxQuery(): import("graphql").DocumentNode;
|
|
16
16
|
nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
|
|
17
|
-
nftlpPositionQuery(
|
|
17
|
+
nftlpPositionQuery(extension: Extension, positionIds: string[]): import("graphql").DocumentNode;
|
|
18
|
+
private nftlpUniswapV3PositionsQuery;
|
|
18
19
|
borrowersListQuery(factory: Factory): import("graphql").DocumentNode;
|
|
19
20
|
borrowersListQueryV2(): import("graphql").DocumentNode;
|
|
20
21
|
borrowersListQueryV3(): import("graphql").DocumentNode;
|
|
@@ -448,10 +448,15 @@ class PonderQueryBuilder {
|
|
|
448
448
|
console.warn(`nftlpsQuery not implemented for extension: ${extension}`);
|
|
449
449
|
return (0, graphql_tag_1.default) `{}`;
|
|
450
450
|
}
|
|
451
|
-
nftlpPositionQuery(
|
|
452
|
-
|
|
451
|
+
nftlpPositionQuery(extension, positionIds) {
|
|
452
|
+
if (extension === types_1.Extension.UniswapV3)
|
|
453
|
+
return this.nftlpUniswapV3PositionsQuery(positionIds);
|
|
454
|
+
return (0, graphql_tag_1.default) `{}`;
|
|
455
|
+
}
|
|
456
|
+
nftlpUniswapV3PositionsQuery(positionIds) {
|
|
457
|
+
const ids = positionIds.map(id => `"${id}"`).join(', ');
|
|
453
458
|
return (0, graphql_tag_1.default) `{
|
|
454
|
-
nftlpPositions(
|
|
459
|
+
nftlpPositions(where: { id_in: [${ids}] }, limit: 1000) {
|
|
455
460
|
items {
|
|
456
461
|
liquidity
|
|
457
462
|
fee
|
|
@@ -9,7 +9,7 @@ export declare class TheGraphQueryBuilder implements IQueryBuilder {
|
|
|
9
9
|
userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
10
10
|
tvlQuery(): import("graphql").DocumentNode;
|
|
11
11
|
nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
|
|
12
|
-
nftlpPositionQuery(
|
|
12
|
+
nftlpPositionQuery(extension: Extension, positionIds: string[]): import("graphql").DocumentNode;
|
|
13
13
|
vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
14
14
|
vaultsUserQuery(account: Address): import("graphql").DocumentNode;
|
|
15
15
|
proposalsMetaQuery(rangeBegin: any, rangeLength: any, descending: any): import("graphql").DocumentNode;
|
|
@@ -204,7 +204,7 @@ class TheGraphQueryBuilder {
|
|
|
204
204
|
nftlpsQuery(extension, network) {
|
|
205
205
|
return (0, graphql_tag_1.default) `{}`;
|
|
206
206
|
}
|
|
207
|
-
nftlpPositionQuery(
|
|
207
|
+
nftlpPositionQuery(extension, positionIds) {
|
|
208
208
|
return (0, graphql_tag_1.default) `{}`;
|
|
209
209
|
}
|
|
210
210
|
/*-----------------------------*
|
|
@@ -9,7 +9,7 @@ export interface IQueryBuilder {
|
|
|
9
9
|
userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
10
10
|
tvlQuery(): DocumentNode;
|
|
11
11
|
nftlpsQuery(extension: Extension, network: Networks): DocumentNode;
|
|
12
|
-
nftlpPositionQuery(
|
|
12
|
+
nftlpPositionQuery(extension: Extension, positionIds: string[]): DocumentNode;
|
|
13
13
|
vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): DocumentNode;
|
|
14
14
|
vaultsUserQuery(account: Address): DocumentNode;
|
|
15
15
|
proposalsMetaQuery(rangeBegin: number, rangeLength: number, descending: boolean): DocumentNode;
|