impermax-sdk 2.1.177 → 2.1.178
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/config/private-api.d.ts +3 -2
- package/lib/config/private-api.js +28 -1
- package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.d.ts +14 -0
- package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.js +34 -2
- package/lib/offchain/queries/apis/ponder/index.js +2 -0
- package/package.json +1 -1
|
@@ -4,5 +4,6 @@ import { Address, NetworkVaultTypeIndex, NetworkFactoryIndex } from "./types";
|
|
|
4
4
|
* things (ie. charts, leaderboards, etc.). The app must function well
|
|
5
5
|
* without any of these endpoints, so just nice to haves.
|
|
6
6
|
*/
|
|
7
|
-
export declare const IMPERMAX_POOLS_API: NetworkFactoryIndex<
|
|
8
|
-
export declare const IMPERMAX_VAULT_API: NetworkVaultTypeIndex<
|
|
7
|
+
export declare const IMPERMAX_POOLS_API: NetworkFactoryIndex<string>;
|
|
8
|
+
export declare const IMPERMAX_VAULT_API: NetworkVaultTypeIndex<string>;
|
|
9
|
+
export declare const NFTLP_FEE_API: NetworkFactoryIndex<Address>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IMPERMAX_VAULT_API = exports.IMPERMAX_POOLS_API = void 0;
|
|
3
|
+
exports.NFTLP_FEE_API = exports.IMPERMAX_VAULT_API = exports.IMPERMAX_POOLS_API = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
/**
|
|
6
6
|
* Private API Endpoints which we might need to use in future for non-core
|
|
@@ -65,4 +65,31 @@ exports.IMPERMAX_VAULT_API = {
|
|
|
65
65
|
},
|
|
66
66
|
[types_1.Networks.Linea]: {},
|
|
67
67
|
};
|
|
68
|
+
// :lendingPoolId/:tokenId
|
|
69
|
+
exports.NFTLP_FEE_API = {
|
|
70
|
+
[types_1.Networks.Ropsten]: {},
|
|
71
|
+
[types_1.Networks.Mainnet]: {},
|
|
72
|
+
[types_1.Networks.Polygon]: {},
|
|
73
|
+
[types_1.Networks.Arbitrum]: {},
|
|
74
|
+
[types_1.Networks.Avalanche]: {},
|
|
75
|
+
[types_1.Networks.Moonriver]: {},
|
|
76
|
+
[types_1.Networks.Aurora]: {},
|
|
77
|
+
[types_1.Networks.Cronos]: {},
|
|
78
|
+
[types_1.Networks.Fantom]: {},
|
|
79
|
+
[types_1.Networks.Harmony]: {},
|
|
80
|
+
[types_1.Networks.Moonbeam]: {},
|
|
81
|
+
[types_1.Networks.Sxnetwork]: {},
|
|
82
|
+
[types_1.Networks.Canto]: {},
|
|
83
|
+
[types_1.Networks.ZksyncEra]: {},
|
|
84
|
+
[types_1.Networks.Base]: {
|
|
85
|
+
[types_1.Factory.V3]: "https://base-nftlp-production.up.railway.app/8453/"
|
|
86
|
+
},
|
|
87
|
+
[types_1.Networks.Mantle]: {},
|
|
88
|
+
[types_1.Networks.Scroll]: {},
|
|
89
|
+
[types_1.Networks.Optimism]: {},
|
|
90
|
+
[types_1.Networks.Real]: {},
|
|
91
|
+
[types_1.Networks.Blast]: {},
|
|
92
|
+
[types_1.Networks.Sonic]: {},
|
|
93
|
+
[types_1.Networks.Linea]: {},
|
|
94
|
+
};
|
|
68
95
|
// Add more here
|
|
@@ -10,10 +10,16 @@ interface PositionData {
|
|
|
10
10
|
feeGrowthInside1LastX128: number;
|
|
11
11
|
unclaimedFees0: number;
|
|
12
12
|
unclaimedFees1: number;
|
|
13
|
+
totalFeesEarned0: number;
|
|
14
|
+
totalFeesEarned1: number;
|
|
13
15
|
}
|
|
14
16
|
export type UniswapV3PositionData = NftlpPosition & {
|
|
15
17
|
nftlp: PositionData;
|
|
16
18
|
};
|
|
19
|
+
interface PositionFees {
|
|
20
|
+
uncollectedFees0: number;
|
|
21
|
+
uncollectedFees1: number;
|
|
22
|
+
}
|
|
17
23
|
export default class OffchainAccountNftlpUniswapV3 extends OffchainAccountNftlp {
|
|
18
24
|
protected cache: {
|
|
19
25
|
positionsData?: {
|
|
@@ -22,6 +28,9 @@ export default class OffchainAccountNftlpUniswapV3 extends OffchainAccountNftlp
|
|
|
22
28
|
positionsObject?: {
|
|
23
29
|
[keys in number]: Promise<UniswapV3Position>;
|
|
24
30
|
};
|
|
31
|
+
pendingFees?: {
|
|
32
|
+
[keys in number]: PositionFees;
|
|
33
|
+
};
|
|
25
34
|
};
|
|
26
35
|
getNftlp: () => any;
|
|
27
36
|
getTokenPositions(): Promise<Record<string, UniswapV3PositionData>>;
|
|
@@ -35,5 +44,10 @@ export default class OffchainAccountNftlpUniswapV3 extends OffchainAccountNftlp
|
|
|
35
44
|
createPositionObject(tokenId: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
|
|
36
45
|
createNewPositionObject(fee: number, priceA: number, priceB: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
|
|
37
46
|
getPositionObject(tokenId: number): Promise<UniswapV3Position>;
|
|
47
|
+
getUncollectedFees(tokenId: number): Promise<PositionFees>;
|
|
48
|
+
getTotalAccruedFees(tokenId: number): Promise<{
|
|
49
|
+
accruedFees0: number;
|
|
50
|
+
accruedFees1: number;
|
|
51
|
+
}>;
|
|
38
52
|
}
|
|
39
53
|
export {};
|
|
@@ -6,6 +6,7 @@ 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");
|
|
9
10
|
class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
10
11
|
constructor() {
|
|
11
12
|
super(...arguments);
|
|
@@ -46,8 +47,8 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
|
46
47
|
return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
|
|
47
48
|
}
|
|
48
49
|
async createPositionObject(tokenId, lockStateChange = true) {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const { uncollectedFees0, uncollectedFees1 } = await this.getUncollectedFees(tokenId);
|
|
51
|
+
return new uniswapV3_1.default(await this.getLiquidity(tokenId), uncollectedFees0, uncollectedFees1, await this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), await this.getLendingPool().getBorrowableB().getBorrowedAmount(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);
|
|
51
52
|
}
|
|
52
53
|
async createNewPositionObject(fee, priceA, priceB, lockStateChange = false) {
|
|
53
54
|
// TODO check for priceA/priceB sanity
|
|
@@ -60,5 +61,36 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
|
60
61
|
this.cache.positionsObject[tokenId] = this.createPositionObject(tokenId);
|
|
61
62
|
return this.cache.positionsObject[tokenId];
|
|
62
63
|
}
|
|
64
|
+
async getUncollectedFees(tokenId) {
|
|
65
|
+
if (!this.cache.pendingFees)
|
|
66
|
+
this.cache.pendingFees = {};
|
|
67
|
+
if (tokenId in this.cache.pendingFees)
|
|
68
|
+
return this.cache.pendingFees[tokenId];
|
|
69
|
+
const network = this.getLendingPool().getLendingPool().getOffchain().network;
|
|
70
|
+
const factory = this.getLendingPool().getLendingPool().getFactory();
|
|
71
|
+
const lendingPoolId = this.getLendingPool().getLendingPool().getPairAddress();
|
|
72
|
+
const api = private_api_1.NFTLP_FEE_API[network][factory];
|
|
73
|
+
if (!api) {
|
|
74
|
+
console.log(`Missing Fees API for ${lendingPoolId} on ${network}?`);
|
|
75
|
+
return { uncollectedFees0: 0, uncollectedFees1: 0 };
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const positionFees = await fetch(api.concat(`collect/${lendingPoolId}/${tokenId}`)).then(i => i.json());
|
|
79
|
+
this.cache.pendingFees[tokenId] = { uncollectedFees0: Number(positionFees.feesEarned0), uncollectedFees1: Number(positionFees.feesEarned1) };
|
|
80
|
+
return this.cache.pendingFees[tokenId];
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
console.log(`No pending fees data for ${lendingPoolId} on ${network}`);
|
|
84
|
+
return { uncollectedFees0: 0, uncollectedFees1: 0 };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async getTotalAccruedFees(tokenId) {
|
|
88
|
+
const { totalFeesEarned0, totalFeesEarned1 } = (await this.getPositionData(tokenId));
|
|
89
|
+
const { uncollectedFees0, uncollectedFees1 } = await this.getUncollectedFees(tokenId);
|
|
90
|
+
return {
|
|
91
|
+
accruedFees0: Number(totalFeesEarned0) + uncollectedFees0,
|
|
92
|
+
accruedFees1: Number(totalFeesEarned1) + uncollectedFees1,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
63
95
|
}
|
|
64
96
|
exports.default = OffchainAccountNftlpUniswapV3;
|