impermax-sdk 2.1.288 → 2.1.290

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.
Files changed (31) hide show
  1. package/lib/config/nftlp.d.ts +5 -10
  2. package/lib/config/nftlp.js +5 -15
  3. package/lib/config/types.d.ts +2 -2
  4. package/lib/config/types.js +2 -2
  5. package/lib/offchain/initializer/allPositionsV3.js +1 -1
  6. package/lib/offchain/initializer/index.d.ts +1 -0
  7. package/lib/offchain/initializer/index.js +1 -0
  8. package/lib/offchain/initializer/lendingPools.js +14 -15
  9. package/lib/offchain/initializer/nftlps.d.ts +8 -0
  10. package/lib/offchain/initializer/nftlps.js +69 -0
  11. package/lib/offchain/initializer/user/positionsV3.js +1 -1
  12. package/lib/offchain/lendingPool/nftlp/offchainNftlp.d.ts +2 -0
  13. package/lib/offchain/lendingPool/nftlp/offchainNftlp.js +3 -2
  14. package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +12 -14
  15. package/lib/offchain/lendingPool/offchainLendingPool.d.ts +1 -1
  16. package/lib/offchain/lendingPool/offchainLendingPool.js +0 -9
  17. package/lib/offchain/lendingPool/offchainLendingPoolV2.d.ts +2 -0
  18. package/lib/offchain/lendingPool/offchainLendingPoolV2.js +6 -0
  19. package/lib/offchain/lendingPool/offchainLendingPoolV3.d.ts +2 -0
  20. package/lib/offchain/lendingPool/offchainLendingPoolV3.js +5 -0
  21. package/lib/offchain/offchain.d.ts +6 -1
  22. package/lib/offchain/offchain.js +5 -0
  23. package/lib/offchain/offchainAPRHelper.d.ts +2 -0
  24. package/lib/offchain/offchainAPRHelper.js +4 -2
  25. package/lib/offchain/offchainTypes.d.ts +21 -2
  26. package/lib/offchain/queries/apis/ponder/index.d.ts +2 -1
  27. package/lib/offchain/queries/apis/ponder/index.js +28 -8
  28. package/lib/offchain/queries/apis/thegraph/index.d.ts +3 -2
  29. package/lib/offchain/queries/apis/thegraph/index.js +9 -3
  30. package/lib/offchain/queries/interfaces/query-builder.d.ts +3 -2
  31. package/package.json +1 -1
@@ -1,10 +1,5 @@
1
- import { Networks } from './types';
2
- export declare enum NftlpTypes {
3
- UniswapV3 = "uniswapv3",
4
- AlgebraV3 = "algebrav3"
5
- }
6
- export declare const hrNftlpTypes: Record<NftlpTypes, string>;
7
- export declare const NFTLP_SUBGRAPH_URL: Record<Networks, Partial<Record<NftlpTypes, string[]>>>;
8
- export declare const NFTLP_FACTORY: Record<Networks, Partial<Record<NftlpTypes, string>>>;
9
- export declare function getNftlpSubgraph(network: Networks, dex: NftlpTypes): string[] | undefined;
10
- export declare function getNftlpDex(network: Networks, factoryAddress: string): NftlpTypes | undefined;
1
+ import { Address, Extension, NetworkExtensionIndex, Networks } from './types';
2
+ export declare const NFTLP_SUBGRAPH_URL: NetworkExtensionIndex<string[]>;
3
+ export declare const NFTLP_FACTORY: NetworkExtensionIndex<Address>;
4
+ export declare function getNftlpSubgraph(network: Networks, dex: Extension): string[] | undefined;
5
+ export declare function getNftlpDex(network: Networks, factoryAddress: string): Extension | undefined;
@@ -1,17 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNftlpDex = exports.getNftlpSubgraph = exports.NFTLP_FACTORY = exports.NFTLP_SUBGRAPH_URL = exports.hrNftlpTypes = exports.NftlpTypes = void 0;
3
+ exports.getNftlpDex = exports.getNftlpSubgraph = exports.NFTLP_FACTORY = exports.NFTLP_SUBGRAPH_URL = void 0;
4
4
  const types_1 = require("./types");
5
- // Same as `amms.ts` - Probably remove this and just use NFTLP factory address
6
- var NftlpTypes;
7
- (function (NftlpTypes) {
8
- NftlpTypes["UniswapV3"] = "uniswapv3";
9
- NftlpTypes["AlgebraV3"] = "algebrav3";
10
- })(NftlpTypes = exports.NftlpTypes || (exports.NftlpTypes = {}));
11
- exports.hrNftlpTypes = {
12
- [NftlpTypes.UniswapV3]: "Uniswap V3",
13
- [NftlpTypes.AlgebraV3]: "Algebra V3",
14
- };
15
5
  // Subgraph endpoints for each network/DEX
16
6
  // allow for multiple endpoints for each
17
7
  exports.NFTLP_SUBGRAPH_URL = {
@@ -32,7 +22,7 @@ exports.NFTLP_SUBGRAPH_URL = {
32
22
  [types_1.Networks.Sxnetwork]: {},
33
23
  [types_1.Networks.Blast]: {},
34
24
  [types_1.Networks.Base]: {
35
- [NftlpTypes.UniswapV3]: ["https://base-nftlp-production.up.railway.app/"]
25
+ [types_1.Extension.UniswapV3]: ["https://base-nftlp-production.up.railway.app/"]
36
26
  },
37
27
  [types_1.Networks.Scroll]: {},
38
28
  [types_1.Networks.Optimism]: {},
@@ -59,7 +49,7 @@ exports.NFTLP_FACTORY = {
59
49
  [types_1.Networks.Sxnetwork]: {},
60
50
  [types_1.Networks.Blast]: {},
61
51
  [types_1.Networks.Base]: {
62
- [NftlpTypes.UniswapV3]: "0xe5D6Cf969C01BF8d6c46840eD784D7F209038D7a"
52
+ [types_1.Extension.UniswapV3]: "0xe5D6Cf969C01BF8d6c46840eD784D7F209038D7a"
63
53
  },
64
54
  [types_1.Networks.Scroll]: {},
65
55
  [types_1.Networks.Optimism]: {},
@@ -76,8 +66,8 @@ exports.getNftlpSubgraph = getNftlpSubgraph;
76
66
  function getNftlpDex(network, factoryAddress) {
77
67
  const normalizedAddress = factoryAddress.toLowerCase();
78
68
  const factories = exports.NFTLP_FACTORY[network];
79
- for (const [dex, address] of Object.entries(factories)) {
80
- if (address.toLowerCase() === normalizedAddress) {
69
+ for (const dex of Object.keys(factories)) {
70
+ if (factories[dex]?.toLowerCase() === normalizedAddress) {
81
71
  return dex;
82
72
  }
83
73
  }
@@ -34,8 +34,8 @@ export declare enum Factory {
34
34
  V3 = "8"
35
35
  }
36
36
  export declare enum Extension {
37
- UniswapV2 = 0,
38
- UniswapV3 = 1
37
+ UniswapV2 = "1",
38
+ UniswapV3 = "2"
39
39
  }
40
40
  export declare enum PoolTokenType {
41
41
  Collateral = "collateral",
@@ -40,8 +40,8 @@ var Factory;
40
40
  })(Factory = exports.Factory || (exports.Factory = {}));
41
41
  var Extension;
42
42
  (function (Extension) {
43
- Extension[Extension["UniswapV2"] = 0] = "UniswapV2";
44
- Extension[Extension["UniswapV3"] = 1] = "UniswapV3";
43
+ Extension["UniswapV2"] = "1";
44
+ Extension["UniswapV3"] = "2";
45
45
  //UniswapV4,
46
46
  //Algebra,
47
47
  })(Extension = exports.Extension || (exports.Extension = {}));
@@ -28,7 +28,7 @@ async function initializeAllV3Positions(factory) {
28
28
  if (!positions[lendingPoolId][userAddress])
29
29
  positions[lendingPoolId][userAddress] = [];
30
30
  const dex = (0, nftlp_1.getNftlpDex)(this.network, nftlpFactory);
31
- if (!dex) {
31
+ if (dex === undefined) {
32
32
  console.warn(`Unknown DEX for NFTLP factory ${nftlpFactory} on ${this.network}`);
33
33
  continue;
34
34
  }
@@ -11,3 +11,4 @@ export * from './farming';
11
11
  export * from './tvl';
12
12
  export * from './private-api';
13
13
  export * from './borrowers';
14
+ export * from './nftlps';
@@ -27,3 +27,4 @@ __exportStar(require("./farming"), exports);
27
27
  __exportStar(require("./tvl"), exports);
28
28
  __exportStar(require("./private-api"), exports);
29
29
  __exportStar(require("./borrowers"), exports);
30
+ __exportStar(require("./nftlps"), exports);
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchLendingPools = exports.initializeLendingPoolsData = exports.getLendingPoolData = exports.getLendingPoolsData = void 0;
7
- const amms_1 = require("../../config/amms");
8
7
  const offchainTypes_1 = require("../offchainTypes");
9
8
  const subgraphs_1 = require("../../config/subgraphs");
10
9
  const offchainLendingPoolV2_1 = __importDefault(require("../lendingPool/offchainLendingPoolV2"));
@@ -37,20 +36,20 @@ async function initializeLendingPoolsData() {
37
36
  this.fetchImpermaxChefRewardRates(),
38
37
  ]);
39
38
  // Get Uniswap APR
40
- const lendingPoolsByAmm = {};
41
- for (const factory in lendingPools) {
42
- for (const lendingPool of lendingPools[factory]) {
43
- const amm = (0, amms_1.getAmmByFactory)(this.network,
44
- // WARN: Quick temporary fix, to be removed after
45
- lendingPool?.pair?.uniswapV2Factory ?? lendingPool?.nftlp?.dexFactory);
46
- if (!amm)
47
- continue;
48
- if (!lendingPoolsByAmm[amm])
49
- lendingPoolsByAmm[amm] = [];
50
- const lendingPoolsOfAmm = lendingPoolsByAmm[amm];
51
- lendingPoolsOfAmm.push(lendingPool);
52
- }
53
- }
39
+ //const lendingPoolsByAmm: { [key in Amms]?: LendingPoolData[] } = {};
40
+ //for (const factory in lendingPools) {
41
+ // for (const lendingPool of lendingPools[factory]) {
42
+ // const amm = getAmmByFactory(
43
+ // this.network,
44
+ // // WARN: Quick temporary fix, to be removed after
45
+ // lendingPool?.pair?.uniswapV2Factory ?? lendingPool?.nftlp?.dexFactory,
46
+ // );
47
+ // if (!amm) continue;
48
+ // if (!lendingPoolsByAmm[amm]) lendingPoolsByAmm[amm] = [];
49
+ // const lendingPoolsOfAmm = lendingPoolsByAmm[amm] as LendingPoolData[];
50
+ // lendingPoolsOfAmm.push(lendingPool);
51
+ // }
52
+ //}
54
53
  // const uniswapAPR = await this.fetchUniswapAPR(lendingPoolsByAmm);
55
54
  // Organize lending pools data
56
55
  for (const factory in lendingPools) {
@@ -0,0 +1,8 @@
1
+ import { NftlpData } from "../offchainTypes";
2
+ import { LendingPoolIndex, AddressIndex, Address } from "../../config/types";
3
+ import Offchain from "../offchain";
4
+ import { ExtensionIndex } from "../../config/types";
5
+ export declare function getNftlpsData(this: Offchain): Promise<LendingPoolIndex<NftlpData>>;
6
+ export declare function getNftlpData(this: Offchain, nftlpAddress: Address): Promise<NftlpData>;
7
+ export declare function initializeNftlpsData(this: Offchain): Promise<AddressIndex<NftlpData>>;
8
+ export declare function fetchNftlpsData(this: Offchain): Promise<ExtensionIndex<NftlpData[]>>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchNftlpsData = exports.initializeNftlpsData = exports.getNftlpData = exports.getNftlpsData = void 0;
4
+ const nftlp_1 = require("../../config/nftlp");
5
+ /*--------------------------------------------------------------------------*
6
+ * Getters *
7
+ *--------------------------------------------------------------------------*/
8
+ async function getNftlpsData() {
9
+ if (!this.nftlpsData)
10
+ this.nftlpsData = this.initializeNftlpsData();
11
+ return this.nftlpsData;
12
+ }
13
+ exports.getNftlpsData = getNftlpsData;
14
+ async function getNftlpData(nftlpAddress) {
15
+ return (await this.getNftlpsData())[nftlpAddress];
16
+ }
17
+ exports.getNftlpData = getNftlpData;
18
+ /*--------------------------------------------------------------------------*
19
+ * Initializers *
20
+ *--------------------------------------------------------------------------*/
21
+ // OffchainLendingPool Data
22
+ async function initializeNftlpsData() {
23
+ const nftlpsData = {};
24
+ // Get raw data
25
+ const nftlps = await this.fetchNftlpsData();
26
+ // Organize nftlps data
27
+ // Nftlps id can't be duplicated across different extensions
28
+ for (const extension in nftlps) {
29
+ for (const nftlp of nftlps[extension]) {
30
+ nftlp.dex = extension;
31
+ nftlpsData[nftlp.id] = nftlp;
32
+ }
33
+ }
34
+ return nftlpsData;
35
+ }
36
+ exports.initializeNftlpsData = initializeNftlpsData;
37
+ /*--------------------------------------------------------------------------*
38
+ * Fetchers *
39
+ *--------------------------------------------------------------------------*/
40
+ async function fetchNftlpsData() {
41
+ const calls = [];
42
+ const extensions = [];
43
+ // Only query for pairs in the pairs list
44
+ //const pairs = this.getPairsList(Factory.V3, { whitelisted: true, deprecated: true, blacklisted: true });
45
+ //if (pairs.length === 0) return {};
46
+ let extension;
47
+ for (extension of Object.keys(nftlp_1.NFTLP_SUBGRAPH_URL[this.network])) {
48
+ const subgraphs = nftlp_1.NFTLP_SUBGRAPH_URL[this.network][extension];
49
+ calls.push(this.getEndpointManager().fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.nftlpsQuery(extension, this.network)));
50
+ extensions.push(extension);
51
+ }
52
+ const results = await Promise.all(calls);
53
+ const nftlps = {};
54
+ results.forEach((result, index) => {
55
+ // `offchainEndpointManager` returns null when using filters and cant find subgraph with filter
56
+ if (!result)
57
+ return;
58
+ // Get the factory for this result
59
+ const extension = extensions[index];
60
+ // Get pools data
61
+ const nftlpsForExtension = result.data?.nftlps;
62
+ if (!nftlpsForExtension)
63
+ return;
64
+ // Add all pools for this factory
65
+ nftlps[extension] = nftlpsForExtension;
66
+ });
67
+ return nftlps;
68
+ }
69
+ exports.fetchNftlpsData = fetchNftlpsData;
@@ -37,7 +37,7 @@ async function initializeV3Positions(offchain, factory, rawUserData) {
37
37
  const nftlpFactory = position.lendingPool.nftlp.factory;
38
38
  // 2. Get the subgraph endpoint/s for this NFTLP factory on this chain
39
39
  const dex = (0, nftlp_1.getNftlpDex)(offchain.network, nftlpFactory);
40
- if (!dex) {
40
+ if (dex === undefined) {
41
41
  console.warn(`Unknown DEX for NFTLP factory ${nftlpFactory} on ${offchain.network}`);
42
42
  continue;
43
43
  }
@@ -2,6 +2,7 @@ import OffchainCollateralV3 from "../offchainCollateralV3";
2
2
  import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
3
3
  import OffchainAccountNftlp from "../../account/lendingPool/nftlp/offchainAccountNftlp";
4
4
  import { Extension } from "../../../config/types";
5
+ import { NftlpData } from "../../offchainTypes";
5
6
  export default abstract class OffchainNftlp {
6
7
  protected readonly collateral: OffchainCollateralV3;
7
8
  protected cache: {
@@ -16,6 +17,7 @@ export default abstract class OffchainNftlp {
16
17
  protected abstract initializeMarketPrice(): Promise<number>;
17
18
  abstract getTotalAPR(): Promise<number>;
18
19
  getNftlp(): void;
20
+ getNftlpData(): Promise<NftlpData>;
19
21
  getMarketPrice(): Promise<number>;
20
22
  getOraclePrice(): Promise<number>;
21
23
  cleanCache(): void;
@@ -10,6 +10,9 @@ class OffchainNftlp {
10
10
  getNftlp() {
11
11
  // Something
12
12
  }
13
+ async getNftlpData() {
14
+ return this.getLendingPool().getOffchain().getNftlpData(this.getNftlpAddress());
15
+ }
13
16
  async getMarketPrice() {
14
17
  if (!this.cache.marketPrice)
15
18
  this.cache.marketPrice = this.initializeMarketPrice();
@@ -17,8 +20,6 @@ class OffchainNftlp {
17
20
  }
18
21
  async getOraclePrice() {
19
22
  return this.getMarketPrice();
20
- //if (!this.cache.oraclePrice) this.cache.oraclePrice = this.initializeOraclePrice();
21
- //return this.cache.oraclePrice;
22
23
  }
23
24
  cleanCache() {
24
25
  this.cache = {};
@@ -37,19 +37,12 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
37
37
  ]);
38
38
  return priceA / priceB;
39
39
  }
40
- /*
41
- protected async initializeOraclePrice(): Promise<number> {
42
- const lendingPoolData = await this.getLendingPool().getLendingPoolData() as any;
43
- const priceAdjustment = await this.priceAdjustment();
44
- return formatPriceSqrtX96(lendingPoolData.nftlp.oraclePriceSqrtX96, priceAdjustment);
45
- }
46
- */
47
40
  // get basic UniswapV3Pool info given a fee
48
41
  // used for calculating the apr
49
42
  async initializeUniswapV3Pool(fee) {
50
43
  const feeRaw = fee * 1000000;
51
- const lendingPoolData = await this.getLendingPool().getLendingPoolData();
52
- const pools = lendingPoolData.nftlp.uniswapV3Pools;
44
+ const nftlpUniswapV3Data = await this.getNftlpData();
45
+ const pools = nftlpUniswapV3Data.uniswapV3Pools;
53
46
  console.log("feeRaw", feeRaw);
54
47
  console.log("pools", pools);
55
48
  for (let pool of pools) {
@@ -83,14 +76,19 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
83
76
  const pool = await this.getUniswapV3Pool(fee);
84
77
  if (!pool.address)
85
78
  return { fullRangeRate: 0, tvlUsd: 0 };
86
- // use llama API to get the APR based on last 24hr fees
87
- // their APR is calculated as: total reward / tvl
79
+ // use llama API to get the APR based on last 7 days fees
80
+ // the APR is calculated as: total reward / tvl
88
81
  const offchain = this.getLendingPool().getOffchain();
89
- const { apyBase, tvlUsd, } = await offchain.getAPRHelper().getLlamaYieldsUniswapV3(pool.address, offchain.network);
90
- console.log("apyBase", apyBase);
82
+ const { apyBase, volumeUsd1d, volumeUsd7d, tvlUsd, } = await offchain.getAPRHelper().getLlamaYieldsUniswapV3(pool.address, offchain.network);
83
+ const llamaApyBase = apyBase / 100;
84
+ const apr1dFees = volumeUsd1d * fee * 365 / tvlUsd;
85
+ const apr7dFees = volumeUsd7d * fee / 7 * 365 / tvlUsd;
86
+ console.log("llamaApyBase", llamaApyBase);
87
+ console.log("apr1dFees", apr1dFees);
88
+ console.log("apr7dFees", apr7dFees);
91
89
  console.log("tvlUsd", tvlUsd);
92
90
  // convert llama apy to rate
93
- const avgRate = apyBase / 100 / utils_1.SECONDS_IN_YEAR;
91
+ const avgRate = apr7dFees / utils_1.SECONDS_IN_YEAR;
94
92
  // calculate the usd price of 1 unit of formatted liquidity
95
93
  const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
96
94
  const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
@@ -55,7 +55,7 @@ export default abstract class OffchainLendingPool {
55
55
  getShownLeverage(): Promise<number>;
56
56
  getLendingPoolDataPast24h(): Promise<LendingPoolPastData | undefined>;
57
57
  getLendingPoolDataPast7d(): Promise<LendingPoolPastData | undefined>;
58
- getAmm(): Promise<Amms | null>;
58
+ abstract getAmm(): Promise<Amms | null>;
59
59
  getFarm(): Promise<Farms | null>;
60
60
  getKinkMultiplier(): 2 | 5;
61
61
  abstract getTotalAPR(): Promise<number>;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LendingPoolVersion = void 0;
4
4
  const types_1 = require("../../config/types");
5
5
  const farms_1 = require("../../config/farms");
6
- const amms_1 = require("../../config/amms");
7
6
  const factories_1 = require("../../config/factories");
8
7
  var LendingPoolVersion;
9
8
  (function (LendingPoolVersion) {
@@ -103,14 +102,6 @@ class OffchainLendingPool {
103
102
  async getLendingPoolDataPast7d() {
104
103
  return (await this.getLendingPoolData()).past7d;
105
104
  }
106
- // Amms and farms
107
- async getAmm() {
108
- const lendingPoolData = (await this.getLendingPoolData());
109
- // TODO: this properly
110
- const pairFactory = lendingPoolData.pair?.uniswapV2Factory ??
111
- lendingPoolData.nftlp?.dexFactory;
112
- return (0, amms_1.getAmmByFactory)(this.offchain.network, pairFactory);
113
- }
114
105
  async getFarm() {
115
106
  const lendingPoolData = await this.getLendingPoolData();
116
107
  return (0, farms_1.getFarmByStakedLPFactory)(this.offchain.network, lendingPoolData.pair.factory);
@@ -4,6 +4,7 @@ import OffchainCollateralV2 from "./offchainCollateralV2";
4
4
  import OffchainBorrowableV2 from "./offchainBorrowableV2";
5
5
  import OffchainAccount from "../account";
6
6
  import OffchainAccountLendingPoolV2 from "../account/lendingPool/offchainAccountLendingPoolV2";
7
+ import { Amms } from "../../config/amms";
7
8
  export default class OffchainLendingPoolV2 extends OffchainLendingPool {
8
9
  protected readonly collateral: OffchainCollateralV2;
9
10
  protected readonly borrowables: {
@@ -24,4 +25,5 @@ export default class OffchainLendingPoolV2 extends OffchainLendingPool {
24
25
  getCollateralPrice(fast?: boolean): Promise<number>;
25
26
  getUnderlyingLPPrice(fast?: boolean): Promise<number>;
26
27
  getTotalAPR(): Promise<number>;
28
+ getAmm(): Promise<Amms | null>;
27
29
  }
@@ -10,6 +10,7 @@ const offchainBorrowableV2_1 = __importDefault(require("./offchainBorrowableV2")
10
10
  const offchainAccountLendingPoolV2_1 = __importDefault(require("../account/lendingPool/offchainAccountLendingPoolV2"));
11
11
  const farms_1 = require("../../config/farms");
12
12
  const utils_1 = require("../../utils");
13
+ const amms_1 = require("../../config/amms");
13
14
  class OffchainLendingPoolV2 extends offchainLendingPool_1.default {
14
15
  getNewCollateralObject() {
15
16
  return new offchainCollateralV2_1.default(this);
@@ -122,5 +123,10 @@ class OffchainLendingPoolV2 extends offchainLendingPool_1.default {
122
123
  ]);
123
124
  return uniswapAPR + stakingAPR;
124
125
  }
126
+ async getAmm() {
127
+ const lendingPoolData = (await this.getLendingPoolData());
128
+ const pairFactory = lendingPoolData.pair.uniswapV2Factory;
129
+ return (0, amms_1.getAmmByFactory)(this.offchain.network, pairFactory);
130
+ }
125
131
  }
126
132
  exports.default = OffchainLendingPoolV2;
@@ -4,6 +4,7 @@ import OffchainLendingPool from "./offchainLendingPool";
4
4
  import OffchainBorrowableV3 from "./offchainBorrowableV3";
5
5
  import OffchainAccount from "../account";
6
6
  import OffchainAccountLendingPoolV3 from "../account/lendingPool/offchainAccountLendingPoolV3";
7
+ import { Amms } from "../../config/amms";
7
8
  export default class OffchainLendingPoolV3 extends OffchainLendingPool {
8
9
  protected readonly collateral: OffchainCollateralV3;
9
10
  protected readonly borrowables: {
@@ -19,4 +20,5 @@ export default class OffchainLendingPoolV3 extends OffchainLendingPool {
19
20
  getCollateral: () => OffchainCollateralV3;
20
21
  getNftlp: () => import("./nftlp").OffchainNftlp;
21
22
  getTotalAPR(): Promise<number>;
23
+ getAmm(): Promise<Amms | null>;
22
24
  }
@@ -8,6 +8,7 @@ const offchainCollateralV3_1 = __importDefault(require("./offchainCollateralV3")
8
8
  const offchainLendingPool_1 = __importDefault(require("./offchainLendingPool"));
9
9
  const offchainBorrowableV3_1 = __importDefault(require("./offchainBorrowableV3"));
10
10
  const offchainAccountLendingPoolV3_1 = __importDefault(require("../account/lendingPool/offchainAccountLendingPoolV3"));
11
+ const amms_1 = require("../../config/amms");
11
12
  class OffchainLendingPoolV3 extends offchainLendingPool_1.default {
12
13
  constructor() {
13
14
  super(...arguments);
@@ -30,5 +31,9 @@ class OffchainLendingPoolV3 extends offchainLendingPool_1.default {
30
31
  getTotalAPR() {
31
32
  return this.getNftlp().getTotalAPR();
32
33
  }
34
+ async getAmm() {
35
+ const nftlpData = await this.getNftlp().getNftlpData();
36
+ return (0, amms_1.getAmmByFactory)(this.offchain.network, nftlpData.dexFactory);
37
+ }
33
38
  }
34
39
  exports.default = OffchainLendingPoolV3;
@@ -3,7 +3,7 @@ import OffchainLendingPool from './lendingPool';
3
3
  import OffchainSolidexHelper from './offchainSolidexHelper';
4
4
  import OffchainAccount from './account';
5
5
  import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState, VaultType } from '../config/types';
6
- import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable, NftlpPosition } from './offchainTypes';
6
+ import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable, NftlpPosition, NftlpData } from './offchainTypes';
7
7
  import OffchainVault from './vault/offchainVault';
8
8
  import OffchainConfigManager from './configManager';
9
9
  import { LlamaTvlChart } from './offchainAPRHelper';
@@ -28,6 +28,7 @@ export default class Offchain {
28
28
  protected solidexHelper: OffchainSolidexHelper;
29
29
  protected configManager: OffchainConfigManager;
30
30
  protected lendingPoolsData: Promise<LendingPoolIndex<LendingPoolData>> | null;
31
+ protected nftlpsData: Promise<AddressIndex<NftlpData>> | null;
31
32
  protected usersData: {
32
33
  [key in Address]?: Promise<FactoryIndex<UserData> | null>;
33
34
  };
@@ -97,6 +98,10 @@ export default class Offchain {
97
98
  protected fetchBorrowersList: typeof initializer.fetchBorrowersList;
98
99
  protected initializeBorrowersList: typeof initializer.initializeBorrowersList;
99
100
  getBorrowersList: typeof initializer.getBorrowersList;
101
+ protected fetchNftlpsData: typeof initializer.fetchNftlpsData;
102
+ getNftlpsData: typeof initializer.getNftlpsData;
103
+ getNftlpData: typeof initializer.getNftlpData;
104
+ protected initializeNftlpsData: typeof initializer.initializeNftlpsData;
100
105
  getPairsList(factory: Factory, state: PairState): Address[];
101
106
  getCrossChainTVL(): Promise<number>;
102
107
  getCrossChainTotalValueSupplied(): Promise<number>;
@@ -92,6 +92,11 @@ class Offchain {
92
92
  this.fetchBorrowersList = initializer.fetchBorrowersList;
93
93
  this.initializeBorrowersList = initializer.initializeBorrowersList;
94
94
  this.getBorrowersList = initializer.getBorrowersList;
95
+ // NFTLPS
96
+ this.fetchNftlpsData = initializer.fetchNftlpsData;
97
+ this.getNftlpsData = initializer.getNftlpsData;
98
+ this.getNftlpData = initializer.getNftlpData;
99
+ this.initializeNftlpsData = initializer.initializeNftlpsData;
95
100
  // Config
96
101
  this.offchainMultichain = offchainMultichain;
97
102
  this.network = network;
@@ -43,6 +43,8 @@ export default class OffchainAPRHelper {
43
43
  getLlamaYieldsUniswapV3(pool: Address, chain: Networks): Promise<{
44
44
  apyBase: number;
45
45
  apyBase7d: number;
46
+ volumeUsd1d: number;
47
+ volumeUsd7d: number;
46
48
  tvlUsd: number;
47
49
  }>;
48
50
  getShadowAPR(pool: Address, chain: Networks): Promise<number>;
@@ -203,12 +203,14 @@ class OffchainAPRHelper {
203
203
  return (await this.getLlamaYieldsParams(pool, chain, ['apy']))[0] / 100;
204
204
  }
205
205
  async getLlamaYieldsUniswapV3(pool, chain) {
206
- const [apyBase, apyBase7d, tvlUsd] = await this.getLlamaYieldsParams(pool, chain, [
206
+ const [apyBase, apyBase7d, volumeUsd1d, volumeUsd7d, tvlUsd] = await this.getLlamaYieldsParams(pool, chain, [
207
207
  'apyBase',
208
208
  'apyBase7d',
209
+ 'volumeUsd1d',
210
+ 'volumeUsd7d',
209
211
  'tvlUsd'
210
212
  ]);
211
- return { apyBase, apyBase7d, tvlUsd };
213
+ return { apyBase, apyBase7d, volumeUsd1d, volumeUsd7d, tvlUsd };
212
214
  }
213
215
  // Shadow APRs for Sonic chain only
214
216
  async getShadowAPR(pool, chain) {
@@ -1,4 +1,4 @@
1
- import { Address, AddressIndex, PoolTokenType, ProposalState, WhitelistState, VaultType } from '../config/types';
1
+ import { Address, AddressIndex, PoolTokenType, ProposalState, WhitelistState, VaultType, Extension } from '../config/types';
2
2
  export declare const isV3Factory: (factory: string) => boolean;
3
3
  export interface TokenData {
4
4
  id: Address;
@@ -132,6 +132,25 @@ export interface V2UserData {
132
132
  [key in PoolTokenType]?: BorrowPosition;
133
133
  }>;
134
134
  }
135
+ export interface UniswapV3PoolData {
136
+ liquidity: string;
137
+ fee: string;
138
+ uniswapV3PoolId: Address;
139
+ }
140
+ export interface NftlpUniswapV3Data {
141
+ dex: Extension;
142
+ id: Address;
143
+ factory: Address;
144
+ dexFactory: Address;
145
+ uniswapV3Pools: UniswapV3PoolData[];
146
+ }
147
+ export interface NftlpUniswapV2Data {
148
+ dex: Extension;
149
+ id: Address;
150
+ factory: Address;
151
+ dexFactory: Address;
152
+ }
153
+ export type NftlpData = NftlpUniswapV3Data | NftlpUniswapV2Data;
135
154
  export interface NftlpPosition {
136
155
  id: string;
137
156
  tokenId: string;
@@ -142,7 +161,7 @@ export interface NftlpPosition {
142
161
  };
143
162
  };
144
163
  borrowPositions: BorrowPosition[];
145
- dex: string;
164
+ dex: Extension;
146
165
  nftlp: NftlpPositionData;
147
166
  }
148
167
  export interface NftlpPositionData {
@@ -1,4 +1,4 @@
1
- import { Address, Factory, Networks, VaultType } from "../../../../config/types";
1
+ import { Address, Extension, Factory, Networks, VaultType } from "../../../../config/types";
2
2
  import { IQueryBuilder } from "../../interfaces/query-builder";
3
3
  export declare class PonderQueryBuilder implements IQueryBuilder {
4
4
  blockQuery(): import("graphql").DocumentNode;
@@ -14,6 +14,7 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
14
14
  proposalsMetaQuery(rangeBegin: any, rangeLength: any, descending: any): import("graphql").DocumentNode;
15
15
  proposalQuery(id: number): import("graphql").DocumentNode;
16
16
  ximxQuery(): import("graphql").DocumentNode;
17
+ nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
17
18
  nftlpPositionQuery(lendingPoolId: string, tokenId: string): import("graphql").DocumentNode;
18
19
  borrowersListQueryV2(): import("graphql").DocumentNode;
19
20
  }
@@ -61,14 +61,6 @@ class PonderQueryBuilder {
61
61
  const nftlpStr = `{
62
62
  id
63
63
  factory
64
- dexFactory
65
- uniswapV3Pools {
66
- items {
67
- liquidity
68
- fee
69
- uniswapV3PoolId
70
- }
71
- }
72
64
  }`;
73
65
  const id_in_string = addressesFilter?.length > 0
74
66
  ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]`
@@ -460,6 +452,34 @@ class PonderQueryBuilder {
460
452
  /*-----------------------------*
461
453
  * NFTLP
462
454
  *-----------------------------*/
455
+ nftlpsQuery(extension, network) {
456
+ if (extension === types_1.Extension.UniswapV3) {
457
+ return (0, graphql_tag_1.default) `{
458
+ nftlps {
459
+ items {
460
+ id
461
+ factory
462
+ dexFactory
463
+ uniswapV3Pools {
464
+ items {
465
+ liquidity
466
+ fee
467
+ uniswapV3PoolId
468
+ }
469
+ }
470
+ }
471
+ }
472
+ _meta {
473
+ status
474
+ }
475
+ }`;
476
+ }
477
+ if (extension === types_1.Extension.UniswapV2) {
478
+ // TODO
479
+ }
480
+ console.warn(`nftlpsQuery not implemented for extension: ${extension}`);
481
+ return (0, graphql_tag_1.default) `{}`;
482
+ }
463
483
  nftlpPositionQuery(lendingPoolId, tokenId) {
464
484
  const id = `${lendingPoolId}-${tokenId}`;
465
485
  return (0, graphql_tag_1.default) `{
@@ -1,15 +1,16 @@
1
- import { Address, Factory, Networks, VaultType } from "../../../../config/types";
1
+ import { Address, Extension, Factory, Networks, VaultType } from "../../../../config/types";
2
2
  import { IQueryBuilder } from "../../interfaces/query-builder";
3
3
  export declare class TheGraphQueryBuilder implements IQueryBuilder {
4
4
  blockQuery(timestamp: number): import("graphql").DocumentNode;
5
5
  getBlockNumber(response: any, network: Networks): number;
6
6
  lendingPoolsV3Query(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
7
7
  userQueryV3(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
8
- nftlpPositionQuery(lendingPoolId: string, tokenId: string): import("graphql").DocumentNode;
9
8
  allPositionsV3Query(): import("graphql").DocumentNode;
10
9
  lendingPoolsQuery(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
11
10
  userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
12
11
  tvlQuery(): import("graphql").DocumentNode;
12
+ nftlpsQuery(extension: Extension, network: Networks): import("graphql").DocumentNode;
13
+ nftlpPositionQuery(lendingPoolId: string, tokenId: string): import("graphql").DocumentNode;
13
14
  vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): import("graphql").DocumentNode;
14
15
  vaultsUserQuery(account: Address): import("graphql").DocumentNode;
15
16
  proposalsMetaQuery(rangeBegin: any, rangeLength: any, descending: any): import("graphql").DocumentNode;
@@ -39,9 +39,6 @@ class TheGraphQueryBuilder {
39
39
  userQueryV3(account, network, factory) {
40
40
  return (0, graphql_tag_1.default) `{}`;
41
41
  }
42
- nftlpPositionQuery(lendingPoolId, tokenId) {
43
- return (0, graphql_tag_1.default) `{}`;
44
- }
45
42
  allPositionsV3Query() {
46
43
  return (0, graphql_tag_1.default) `{}`;
47
44
  }
@@ -204,6 +201,15 @@ class TheGraphQueryBuilder {
204
201
  }
205
202
  }`;
206
203
  }
204
+ /*-----------------------------*
205
+ * Nftlps
206
+ *-----------------------------*/
207
+ nftlpsQuery(extension, network) {
208
+ return (0, graphql_tag_1.default) `{}`;
209
+ }
210
+ nftlpPositionQuery(lendingPoolId, tokenId) {
211
+ return (0, graphql_tag_1.default) `{}`;
212
+ }
207
213
  /*-----------------------------*
208
214
  * Lending vaults
209
215
  *-----------------------------*/
@@ -1,15 +1,16 @@
1
1
  import { DocumentNode } from 'graphql';
2
- import { Address, Factory, Networks, VaultType } from '../../../config/types';
2
+ import { Address, Extension, Factory, Networks, VaultType } from '../../../config/types';
3
3
  export interface IQueryBuilder {
4
4
  blockQuery(timestamp: number): DocumentNode;
5
5
  getBlockNumber: (response: any, network: Networks) => number;
6
6
  lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): DocumentNode;
7
7
  userQueryV3(account: Address, network: Networks, factory: Factory): DocumentNode;
8
- nftlpPositionQuery(lendingPoolId: string, tokenId: string): DocumentNode;
9
8
  allPositionsV3Query(): DocumentNode;
10
9
  lendingPoolsQuery(factory: Factory, addressesFilter: Address[] | undefined, network: Networks): DocumentNode;
11
10
  userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
12
11
  tvlQuery(): DocumentNode;
12
+ nftlpsQuery(extension: Extension, network: Networks): DocumentNode;
13
+ nftlpPositionQuery(lendingPoolId: string, tokenId: string): DocumentNode;
13
14
  vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): DocumentNode;
14
15
  vaultsUserQuery(account: Address): DocumentNode;
15
16
  proposalsMetaQuery(rangeBegin: number, rangeLength: number, descending: boolean): DocumentNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.288",
3
+ "version": "2.1.290",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",