impermax-sdk 2.1.198 → 2.1.200

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.
@@ -28,6 +28,18 @@ export default class OnchainAccountNftlpUniswapV3 extends OnchainAccountNftlp {
28
28
  getPriceA(tokenId: number): Promise<number>;
29
29
  getPriceB(tokenId: number): Promise<number>;
30
30
  getLiquidity(tokenId: number): Promise<number>;
31
+ getCurrentFeeGrowthInsideX128(tokenId: number): Promise<{
32
+ currentFeeGrowthInside0X128: number;
33
+ currentFeeGrowthInside1X128: number;
34
+ }>;
35
+ getCurrentUnclaimedFeesRaw(tokenId: number): Promise<{
36
+ unclaimedFees0: number;
37
+ unclaimedFees1: number;
38
+ }>;
39
+ getCurrentUnclaimedFees(tokenId: number): Promise<{
40
+ unclaimedFees0: number;
41
+ unclaimedFees1: number;
42
+ }>;
31
43
  createPositionObject(tokenId: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
32
44
  createNewPositionObject(fee: number, priceA: number, priceB: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
33
45
  getPositionObject(tokenId: number): Promise<UniswapV3Position>;
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const onchainAccountNftlp_1 = __importDefault(require("./onchainAccountNftlp"));
7
7
  const uniswapV3_1 = __importDefault(require("../../../../utils/position/uniswapV3"));
8
8
  const uniswapV3General_1 = require("../../../../utils/nftlpMath/uniswapV3General");
9
+ const REINVESTOR = '0x000000000000000000000000000000000000dead';
10
+ const Q128 = 2 * 128;
9
11
  class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
10
12
  constructor() {
11
13
  super(...arguments);
@@ -44,9 +46,39 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
44
46
  const liquidity = (await this.getPositionData(tokenId)).liquidity;
45
47
  return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
46
48
  }
49
+ async getCurrentFeeGrowthInsideX128(tokenId) {
50
+ const multicall = this.getLendingPool().getAccount().getOnchain().multicall;
51
+ const nftlp = this.getNftlp().getNftlp();
52
+ const [_, position] = await multicall.aggregate([
53
+ nftlp.methods.reinvest(tokenId, REINVESTOR),
54
+ nftlp.methods.positions(tokenId)
55
+ ]);
56
+ return {
57
+ currentFeeGrowthInside0X128: position[4],
58
+ currentFeeGrowthInside1X128: position[5],
59
+ };
60
+ }
61
+ async getCurrentUnclaimedFeesRaw(tokenId) {
62
+ const { currentFeeGrowthInside0X128, currentFeeGrowthInside1X128 } = await this.getCurrentFeeGrowthInsideX128(tokenId);
63
+ const positionData = await this.getPositionData(tokenId);
64
+ const delta0 = currentFeeGrowthInside0X128 - positionData.feeGrowthInside0LastX128;
65
+ const delta1 = currentFeeGrowthInside1X128 - positionData.feeGrowthInside1LastX128;
66
+ return {
67
+ unclaimedFees0: positionData.unclaimedFees0 + delta0 * positionData.liquidity / Q128,
68
+ unclaimedFees1: positionData.unclaimedFees1 + delta1 * positionData.liquidity / Q128,
69
+ };
70
+ }
71
+ async getCurrentUnclaimedFees(tokenId) {
72
+ const raw = await this.getCurrentUnclaimedFeesRaw(tokenId);
73
+ return {
74
+ unclaimedFees0: this.getNftlp().getLendingPool().getBorrowableA().normalize(raw.unclaimedFees0),
75
+ unclaimedFees1: this.getNftlp().getLendingPool().getBorrowableB().normalize(raw.unclaimedFees1),
76
+ };
77
+ }
47
78
  async createPositionObject(tokenId, lockStateChange = true) {
48
- return new uniswapV3_1.default(await this.getLiquidity(tokenId), 0, // TODO uncollectedFees
49
- 0, await this.getLendingPool().getBorrowableA().getBorrowed(tokenId), await this.getLendingPool().getBorrowableB().getBorrowed(tokenId), await this.getNftlp().getMarketPrice(), await this.getNftlp().getOraclePrice(), await this.getPriceA(tokenId), await this.getPriceB(tokenId), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
79
+ const unclaimedFees = await this.getCurrentUnclaimedFees(tokenId);
80
+ console.log("unclaimedFees", unclaimedFees);
81
+ return new uniswapV3_1.default(await this.getLiquidity(tokenId), unclaimedFees.unclaimedFees0, unclaimedFees.unclaimedFees1, await this.getLendingPool().getBorrowableA().getBorrowed(tokenId), await this.getLendingPool().getBorrowableB().getBorrowed(tokenId), await this.getNftlp().getMarketPrice(), await this.getNftlp().getOraclePrice(), await this.getPriceA(tokenId), await this.getPriceB(tokenId), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
50
82
  }
51
83
  async createNewPositionObject(fee, priceA, priceB, lockStateChange = false) {
52
84
  priceA = await this.getNftlp().nearestUsableTickPrice(priceA, fee);
@@ -25,7 +25,7 @@ export default class Onchain {
25
25
  protected lendingVaults: AddressIndex<OnchainLendingVault>;
26
26
  protected accounts: AddressIndex<OnchainAccount>;
27
27
  protected interactions: AddressIndex<OnchainInteractions>;
28
- protected multicall: Multicall;
28
+ multicall: Multicall;
29
29
  constructor(cfg: OnchainConfig);
30
30
  cleanCache(): void;
31
31
  setPriceInverted(priceInverted: boolean): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.198",
3
+ "version": "2.1.200",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",