impermax-sdk 2.1.344 → 2.1.345

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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const offchainAccountNftlp_1 = __importDefault(require("./offchainAccountNftlp"));
7
7
  const uniswapV3General_1 = require("../../../../utils/nftlpMath/uniswapV3General");
8
8
  const uniswapV3_1 = __importDefault(require("../../../../utils/position/uniswapV3"));
9
- const private_api_1 = require("../../../../config/private-api");
10
9
  class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
11
10
  constructor() {
12
11
  super(...arguments);
@@ -79,13 +78,10 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
79
78
  return this.cache.newlyEarnedFees[tokenId];
80
79
  const network = this.getLendingPool().getLendingPool().getOffchain().network;
81
80
  const lendingPoolId = this.getLendingPool().getLendingPool().getPairAddress();
82
- const api = private_api_1.NFTLP_UNIV3_API[network];
83
- if (!api) {
84
- console.log(`Missing newly earned fees API for ${lendingPoolId} on ${network}?`);
85
- return { amountX: 0, amountY: 0 };
86
- }
81
+ const positionId = `${lendingPoolId}-${tokenId}`;
87
82
  try {
88
- const positionFees = await fetch(api.concat(`fees/${lendingPoolId}/${tokenId}`)).then(i => i.json());
83
+ const account = this.getLendingPool().getAccount().getAccountAddress();
84
+ const positionFees = await this.getLendingPool().getLendingPool().getOffchain().getUniswapV3NewlyEarnedFees(account, positionId);
89
85
  this.cache.newlyEarnedFees[tokenId] = { amountX: Number(positionFees.newlyEarnedFees0), amountY: Number(positionFees.newlyEarnedFees1) };
90
86
  return this.cache.newlyEarnedFees[tokenId];
91
87
  }
@@ -1,2 +1,3 @@
1
1
  export * from './vaultsApi';
2
2
  export * from './lendingPoolsApi';
3
+ export * from './userApi';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./vaultsApi"), exports);
18
18
  __exportStar(require("./lendingPoolsApi"), exports);
19
+ __exportStar(require("./userApi"), exports);
@@ -0,0 +1 @@
1
+ export * from './uniswapV3Fees';
@@ -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("./uniswapV3Fees"), exports);
@@ -0,0 +1,5 @@
1
+ import { AddressIndex, Address } from "../../../../../config/types";
2
+ import Offchain from "../../../../../offchain";
3
+ import { NewlyEarnedFees } from "../../../../offchainTypes";
4
+ export declare function fetchUniswapV3NewlyEarnedFees(this: Offchain, account: Address): Promise<AddressIndex<NewlyEarnedFees>>;
5
+ export declare function getUniswapV3NewlyEarnedFees(this: Offchain, account: Address, positionId: string): Promise<NewlyEarnedFees>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ // private-api: uniswapv3 fees
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getUniswapV3NewlyEarnedFees = exports.fetchUniswapV3NewlyEarnedFees = void 0;
5
+ const types_1 = require("../../../../../config/types");
6
+ const private_api_1 = require("../../../../../config/private-api");
7
+ /*--------------------------------------------------------------------------*
8
+ * Fetchers *
9
+ *--------------------------------------------------------------------------*/
10
+ // TODO: Make this better by using getnftlppositions
11
+ // const nftlpPositions = await this.offchainMultichain.getMultichainAccount(account).getNftlpPositions();
12
+ async function fetchUniswapV3NewlyEarnedFees(account) {
13
+ const api = private_api_1.NFTLP_UNIV3_API[this.network];
14
+ if (!api) {
15
+ console.log(`Missing NFTLP uniswapV3 fees api on ${this.network}?`);
16
+ return {};
17
+ }
18
+ const v3Positions = (await this.getUserData(account))?.[8];
19
+ if (!v3Positions?.positions)
20
+ return {};
21
+ // Get only uniswapV3 positions
22
+ const uniswapV3Positions = Object.entries(v3Positions.positions).flatMap(([_, position]) => position.filter(i => i.dex === types_1.Extension.UniswapV3));
23
+ // Get the unqiue position ID ie. lendingPoolId-tokenId
24
+ const positionIds = uniswapV3Positions.map(i => i.id);
25
+ try {
26
+ const response = await fetch(api.concat(`fees/${positionIds.join(",")}`)).then(i => i.json());
27
+ return response;
28
+ }
29
+ catch (err) {
30
+ console.log(`Failed to fetch uniswapV3 user fees data on ${this.network}`);
31
+ return {};
32
+ }
33
+ }
34
+ exports.fetchUniswapV3NewlyEarnedFees = fetchUniswapV3NewlyEarnedFees;
35
+ /*--------------------------------------------------------------------------*
36
+ * Getters *
37
+ *--------------------------------------------------------------------------*/
38
+ async function getUniswapV3NewlyEarnedFees(account, positionId) {
39
+ if (!this.userNewlyEarnedFeesData[types_1.Extension.UniswapV3]) {
40
+ this.userNewlyEarnedFeesData[types_1.Extension.UniswapV3] = this.fetchUniswapV3NewlyEarnedFees(account);
41
+ }
42
+ const feesData = await this.userNewlyEarnedFeesData[types_1.Extension.UniswapV3];
43
+ return feesData[positionId];
44
+ }
45
+ exports.getUniswapV3NewlyEarnedFees = getUniswapV3NewlyEarnedFees;
@@ -0,0 +1 @@
1
+ export * from './fees';
@@ -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("./fees"), exports);
@@ -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, Extension } from '../config/types';
6
- import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable, NftlpData, PoolChart } from './offchainTypes';
6
+ import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData, VaultBorrowable, NftlpData, PoolChart, NewlyEarnedFees } from './offchainTypes';
7
7
  import OffchainVault from './vault/offchainVault';
8
8
  import OffchainConfigManager from './configManager';
9
9
  import { LlamaTvlChart } from './offchainAPRHelper';
@@ -49,6 +49,9 @@ export default class Offchain {
49
49
  protected extensionChartsData: {
50
50
  [key in Extension]?: Promise<AddressIndex<PoolChart[]>>;
51
51
  };
52
+ protected userNewlyEarnedFeesData: {
53
+ [key in Extension]?: Promise<AddressIndex<NewlyEarnedFees>>;
54
+ };
52
55
  constructor(offchainMultichain: OffchainMultichain, network: Networks);
53
56
  cleanCache(): void;
54
57
  getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool | null>;
@@ -99,6 +102,8 @@ export default class Offchain {
99
102
  protected initializeNftlpsData: typeof initializer.initializeNftlpsData;
100
103
  protected fetchUniswapV3Charts: typeof initializer.fetchUniswapV3Charts;
101
104
  getUniswapV3Charts: typeof initializer.getUniswapV3Chart;
105
+ protected fetchUniswapV3NewlyEarnedFees: typeof initializer.fetchUniswapV3NewlyEarnedFees;
106
+ getUniswapV3NewlyEarnedFees: typeof initializer.getUniswapV3NewlyEarnedFees;
102
107
  getPairsList(factory: Factory, state?: PairState): Address[];
103
108
  getCrossChainTVL(): Promise<number>;
104
109
  getCrossChainTotalValueSupplied(): Promise<number>;
@@ -40,8 +40,11 @@ class Offchain {
40
40
  this.deprecatedPairs = {};
41
41
  this.blacklistedPairs = {};
42
42
  this.disabledBorrowsPairs = [];
43
- // 2. NFTLPs
43
+ // ------ Pools API --------
44
44
  this.extensionChartsData = {};
45
+ // ------ User API --------
46
+ // TODO: Proper positionIndex type
47
+ this.userNewlyEarnedFeesData = {};
45
48
  this.getSolidexHelper = () => this.solidexHelper;
46
49
  this.getConfigManager = () => this.configManager;
47
50
  // Multichain, 1 instance
@@ -103,6 +106,8 @@ class Offchain {
103
106
  // Private api initializers
104
107
  this.fetchUniswapV3Charts = initializer.fetchUniswapV3Charts;
105
108
  this.getUniswapV3Charts = initializer.getUniswapV3Chart;
109
+ this.fetchUniswapV3NewlyEarnedFees = initializer.fetchUniswapV3NewlyEarnedFees;
110
+ this.getUniswapV3NewlyEarnedFees = initializer.getUniswapV3NewlyEarnedFees;
106
111
  // Config
107
112
  this.offchainMultichain = offchainMultichain;
108
113
  this.network = network;
@@ -134,6 +139,7 @@ class Offchain {
134
139
  this.getPriceHelper().cleanCache();
135
140
  this.getAPRHelper().cleanCache();
136
141
  this.borrowersList = null;
142
+ this.userNewlyEarnedFeesData = {};
137
143
  }
138
144
  async getLendingPool(factory, pairAddress) {
139
145
  await this.getLendingPoolsData(); // make sure that lending pools are initialized
@@ -287,3 +287,7 @@ export type UniswapV3PoolChart = {
287
287
  timestampUTC: string;
288
288
  };
289
289
  export type PoolChart = UniswapV3PoolChart;
290
+ export type NewlyEarnedFees = {
291
+ newlyEarnedFees0: number;
292
+ newlyEarnedFees1: number;
293
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.344",
3
+ "version": "2.1.345",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",