impermax-sdk 2.1.138 → 2.1.139
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/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.d.ts +16 -5
- package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.js +16 -0
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +8 -4
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.d.ts +0 -1
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +10 -30
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import OffchainAccountNftlp from "./offchainAccountNftlp";
|
|
2
2
|
import { NftlpPosition } from "../../../offchainTypes";
|
|
3
|
-
|
|
3
|
+
import UniswapV3Position from "../../../../utils/nftlpMath/uniswapV3Position";
|
|
4
|
+
interface PositionData {
|
|
4
5
|
fee: number;
|
|
5
6
|
tickLower: number;
|
|
6
7
|
tickUpper: number;
|
|
@@ -10,18 +11,28 @@ interface UniswapV3NftlpData {
|
|
|
10
11
|
unclaimedFees0: number;
|
|
11
12
|
unclaimedFees1: number;
|
|
12
13
|
}
|
|
13
|
-
export type
|
|
14
|
-
nftlp:
|
|
14
|
+
export type UniswapV3PositionData = NftlpPosition & {
|
|
15
|
+
nftlp: PositionData;
|
|
15
16
|
};
|
|
16
17
|
export default class OffchainAccountNftlpUniswapV3 extends OffchainAccountNftlp {
|
|
18
|
+
protected cache: {
|
|
19
|
+
positionsData?: {
|
|
20
|
+
[keys in number]: Promise<PositionData>;
|
|
21
|
+
};
|
|
22
|
+
positionsObject?: {
|
|
23
|
+
[keys in number]: Promise<UniswapV3Position>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
17
26
|
getNftlp: () => any;
|
|
18
|
-
getTokenPositions(): Promise<Record<string,
|
|
19
|
-
getPositionData(tokenId: number): Promise<
|
|
27
|
+
getTokenPositions(): Promise<Record<string, UniswapV3PositionData>>;
|
|
28
|
+
getPositionData(tokenId: number): Promise<PositionData>;
|
|
20
29
|
getFee(tokenId: number): Promise<number>;
|
|
21
30
|
getTickLower(tokenId: number): Promise<number>;
|
|
22
31
|
getTickUpper(tokenId: number): Promise<number>;
|
|
23
32
|
getPriceA(tokenId: number): Promise<number>;
|
|
24
33
|
getPriceB(tokenId: number): Promise<number>;
|
|
25
34
|
getLiquidity(tokenId: number): Promise<number>;
|
|
35
|
+
createPositionObject(tokenId: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
|
|
36
|
+
getPositionObject(tokenId: number): Promise<UniswapV3Position>;
|
|
26
37
|
}
|
|
27
38
|
export {};
|
|
@@ -14,9 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const offchainAccountNftlp_1 = __importDefault(require("./offchainAccountNftlp"));
|
|
16
16
|
const uniswapV3General_1 = require("../../../../utils/nftlpMath/uniswapV3General");
|
|
17
|
+
const uniswapV3Position_1 = __importDefault(require("../../../../utils/nftlpMath/uniswapV3Position"));
|
|
17
18
|
class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
18
19
|
constructor() {
|
|
19
20
|
super(...arguments);
|
|
21
|
+
this.cache = {};
|
|
20
22
|
// Return as NFTLP Dex class
|
|
21
23
|
this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
|
|
22
24
|
}
|
|
@@ -69,5 +71,19 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
|
69
71
|
return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
|
|
70
72
|
});
|
|
71
73
|
}
|
|
74
|
+
createPositionObject(tokenId, lockStateChange = true) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return new uniswapV3Position_1.default(yield this.getLiquidity(tokenId), yield this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), yield this.getLendingPool().getBorrowableB().getBorrowedAmount(tokenId), yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), yield this.getPriceA(tokenId), yield this.getPriceB(tokenId), yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getPositionObject(tokenId) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!this.cache.positionsObject)
|
|
82
|
+
this.cache.positionsObject = {};
|
|
83
|
+
if (!this.cache.positionsObject[tokenId])
|
|
84
|
+
this.cache.positionsObject[tokenId] = this.createPositionObject(tokenId);
|
|
85
|
+
return this.cache.positionsObject[tokenId];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
72
88
|
}
|
|
73
89
|
exports.default = OffchainAccountNftlpUniswapV3;
|
|
@@ -80,13 +80,17 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
|
|
|
80
80
|
* Borrow Positions *
|
|
81
81
|
*--------------------------------------------------------------------------*/
|
|
82
82
|
getBorrowPosition(tokenId) {
|
|
83
|
-
var _a, _b, _c
|
|
83
|
+
var _a, _b, _c;
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
85
|
const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
|
|
86
|
-
|
|
86
|
+
// For V2 borrow positions
|
|
87
|
+
if (tokenId === undefined)
|
|
87
88
|
return (_a = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.borrowPositions) === null || _a === void 0 ? void 0 : _a[`borrowable${this.borrowable}`];
|
|
88
|
-
// V3
|
|
89
|
-
|
|
89
|
+
// For V3 borrow positions with tokenId
|
|
90
|
+
// Find the corresponding borrow position for this borrowable using underlying address
|
|
91
|
+
const borrowPositions = (_c = (_b = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.positions) === null || _b === void 0 ? void 0 : _b[tokenId]) === null || _c === void 0 ? void 0 : _c.borrowPositions;
|
|
92
|
+
const borrowableId = yield this.getPoolToken().getUnderlyingAddress();
|
|
93
|
+
return borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions.find(i => i.borrowable.underlying.id === borrowableId);
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
// Borrowing position
|
|
@@ -14,7 +14,6 @@ export default class OffchainNftlpUniswapV3 extends OffchainNftlp {
|
|
|
14
14
|
price: number;
|
|
15
15
|
liquidity: number;
|
|
16
16
|
} | null>;
|
|
17
|
-
getUniswapV3Pool(fee: number): Promise<void>;
|
|
18
17
|
protected initializeMarketPrice(): Promise<number>;
|
|
19
18
|
protected initializeOraclePrice(): Promise<number>;
|
|
20
19
|
private priceAdjustment;
|
|
@@ -27,47 +27,27 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
27
27
|
}
|
|
28
28
|
initializeUniswapV3Pool(fee) {
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const res = {
|
|
31
|
-
price: 0,
|
|
32
|
-
liquidity: 0
|
|
33
|
-
};
|
|
30
|
+
const res = { price: 0, liquidity: 0 };
|
|
34
31
|
const lendingPool = this.collateral.getLendingPool();
|
|
35
32
|
const lendingPoolData = yield lendingPool.getLendingPoolData();
|
|
36
33
|
return res;
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
getUniswapV3Pool(fee) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
//if (!this.cache.uniswapV3Pools) this.cache.uniswapV3Pools = {};
|
|
42
|
-
//if (!this.cache.uniswapV3Pools[fee]) {
|
|
43
|
-
// this.cache.uniswapV3Pools[fee] = this.initializeUniswapV3Pool(fee);
|
|
44
|
-
//}
|
|
45
|
-
//return this.cache.uniswapV3Pools[fee];
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
36
|
initializeMarketPrice() {
|
|
49
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// priceCumulative += price * liquidity;
|
|
57
|
-
// liquidityCumulative += liquidity;
|
|
58
|
-
//}
|
|
59
|
-
//return liquidityCumulative > 0 ? priceCumulative / liquidityCumulative : 0;
|
|
60
|
-
return 1;
|
|
38
|
+
const lendingPool = this.getLendingPool();
|
|
39
|
+
const [priceA, priceB] = yield Promise.all([
|
|
40
|
+
lendingPool.getBorrowableA().getTokenPriceAccurate(),
|
|
41
|
+
lendingPool.getBorrowableB().getTokenPriceAccurate()
|
|
42
|
+
]);
|
|
43
|
+
return priceA / priceB;
|
|
61
44
|
});
|
|
62
45
|
}
|
|
63
46
|
initializeOraclePrice() {
|
|
64
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//// This would come from offchain data
|
|
69
|
-
//return lendingPoolData.nftlp?.oraclePrice || 0;
|
|
70
|
-
return 1;
|
|
48
|
+
const lendingPoolData = yield this.getLendingPool().getLendingPoolData();
|
|
49
|
+
const priceAdjustment = yield this.priceAdjustment();
|
|
50
|
+
return (0, uniswapV3General_1.formatPriceSqrtX96)(lendingPoolData.nftlp.oraclePriceSqrtX96, priceAdjustment);
|
|
71
51
|
});
|
|
72
52
|
}
|
|
73
53
|
priceAdjustment() {
|