impermax-sdk 1.2.112 → 2.1.0
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/abis/contracts/IAllowanceTransfer.json +3772 -0
- package/lib/abis/contracts/IERC721.json +3515 -0
- package/lib/abis/contracts/ITokenizedUniswapV2Position.json +4167 -0
- package/lib/abis/contracts/ITokenizedUniswapV3Position.json +5539 -0
- package/lib/abis/contracts/IUniswapV3Pool.json +6606 -0
- package/lib/abis/contracts/ImpermaxV3Borrowable.json +22131 -0
- package/lib/abis/contracts/ImpermaxV3Collateral.json +22988 -0
- package/lib/abis/contracts/ImpermaxV3Factory.json +17645 -0
- package/lib/abis/contracts/ImpermaxV3UniV2Router01.json +32488 -0
- package/lib/abis/contracts/ImpermaxV3UniV3Router01.json +37742 -0
- package/lib/abis/contracts/PoolTokenRouter01.json +9058 -0
- package/lib/config/amms.d.ts +0 -2
- package/lib/config/amms.js +0 -3
- package/lib/config/chainId.d.ts +2 -0
- package/lib/config/chainId.js +26 -0
- package/lib/config/contracts/routers.d.ts +3 -2
- package/lib/config/contracts/routers.js +46 -22
- package/lib/config/factories.js +1 -0
- package/lib/config/farms.d.ts +0 -2
- package/lib/config/farms.js +0 -3
- package/lib/config/types.d.ts +14 -1
- package/lib/config/types.js +15 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.js +11 -4
- package/lib/offchain/account/index.d.ts +4 -2
- package/lib/offchain/account/index.js +7 -3
- package/lib/offchain/account/lendingPool/index.d.ts +2 -1
- package/lib/offchain/account/lendingPool/index.js +3 -1
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.d.ts +0 -3
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +1 -27
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.d.ts +0 -2
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +2 -14
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.d.ts +11 -4
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +16 -15
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.d.ts +25 -0
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +116 -0
- package/lib/offchain/account/offchainAccount.d.ts +6 -6
- package/lib/offchain/account/offchainAccount.js +7 -7
- package/lib/offchain/account/offchainMultichainAccount.d.ts +34 -0
- package/lib/offchain/account/offchainMultichainAccount.js +66 -0
- package/lib/offchain/account/vault/index.d.ts +3 -0
- package/lib/offchain/account/vault/index.js +7 -0
- package/lib/offchain/account/vault/offchainAccountVault.d.ts +16 -0
- package/lib/offchain/account/{offchainAccountLendingVault.js → vault/offchainAccountVault.js} +14 -14
- package/lib/offchain/index.d.ts +3 -2
- package/lib/offchain/index.js +5 -3
- package/lib/offchain/lendingPool/offchainCollateral.d.ts +1 -0
- package/lib/offchain/lendingPool/offchainCollateral.js +6 -0
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +14 -1
- package/lib/offchain/lendingPool/offchainLendingPool.js +47 -0
- package/lib/offchain/offchain.d.ts +8 -15
- package/lib/offchain/offchain.js +16 -19
- package/lib/offchain/offchainAPRHelper.js +0 -1
- package/lib/offchain/offchainInitializer.d.ts +4 -4
- package/lib/offchain/offchainInitializer.js +4 -4
- package/lib/offchain/offchainMultichain.d.ts +50 -0
- package/lib/offchain/offchainMultichain.js +75 -0
- package/lib/offchain/offchainTypes.d.ts +1 -1
- package/lib/offchain/vault/index.d.ts +6 -0
- package/lib/offchain/vault/index.js +14 -0
- package/lib/offchain/vault/offchainHedgedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainHedgedVault.js +57 -0
- package/lib/offchain/vault/offchainLendingVault.d.ts +16 -0
- package/lib/offchain/vault/offchainLendingVault.js +73 -0
- package/lib/offchain/vault/offchainLeveragedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainLeveragedVault.js +57 -0
- package/lib/offchain/{offchainLendingVault.d.ts → vault/offchainVault.d.ts} +16 -7
- package/lib/offchain/{offchainLendingVault.js → vault/offchainVault.js} +33 -17
- package/lib/onchain/account/lendingPool/index.d.ts +8 -1
- package/lib/onchain/account/lendingPool/index.js +38 -1
- package/lib/onchain/account/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.d.ts +7 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.js +12 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +13 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.d.ts +12 -7
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +5 -50
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +55 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +28 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.d.ts +6 -19
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +7 -90
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +25 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +99 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.d.ts +18 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.d.ts +19 -34
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +17 -227
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.d.ts +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +285 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.d.ts +27 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.js +32 -0
- package/lib/onchain/account/onchainAccount.js +1 -2
- package/lib/onchain/account/onchainAccountLendingVault.d.ts +3 -3
- package/lib/onchain/impermaxFactory/index.d.ts +3 -1
- package/lib/onchain/impermaxFactory/index.js +5 -1
- package/lib/onchain/impermaxFactory/lendingPool/index.d.ts +8 -1
- package/lib/onchain/impermaxFactory/lendingPool/index.js +39 -1
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.d.ts +22 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +19 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.d.ts +24 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +90 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +15 -11
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +5 -24
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.d.ts +9 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.d.ts +7 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +23 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.d.ts +5 -16
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +6 -43
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +20 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +58 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.d.ts +13 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +32 -47
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +28 -314
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.d.ts +76 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +338 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.d.ts +42 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.js +39 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.d.ts +19 -9
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.js +16 -26
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +81 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +88 -0
- package/lib/onchain/interactions/lendingPool/index.d.ts +8 -1
- package/lib/onchain/interactions/lendingPool/index.js +38 -1
- package/lib/onchain/interactions/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.d.ts +7 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.js +12 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.d.ts +6 -10
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.js +5 -37
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.d.ts +15 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +63 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.d.ts +9 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.js +14 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.d.ts +3 -15
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.js +5 -37
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.d.ts +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +48 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.d.ts +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.d.ts +16 -31
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.js +12 -94
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.d.ts +42 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +114 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.d.ts +27 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.js +32 -0
- package/lib/onchain/interactions/onchainInteractions.js +3 -4
- package/lib/onchain/interactions/onchainInteractionsLendingVault.d.ts +1 -1
- package/lib/onchain/interactions/onchainInteractionsLendingVault.js +1 -1
- package/lib/onchain/interactions/onchainInteractionsPoolToken.d.ts +13 -13
- package/lib/onchain/interactions/onchainInteractionsPoolToken.js +33 -85
- package/lib/onchain/onchain.d.ts +3 -0
- package/lib/onchain/onchain.js +11 -3
- package/lib/onchain/onchainContractsHelper.d.ts +19 -8
- package/lib/onchain/onchainContractsHelper.js +55 -21
- package/lib/onchain/onchainLendingVault.d.ts +3 -3
- package/lib/onchain/onchainPermitHelper.d.ts +21 -0
- package/lib/onchain/onchainPermitHelper.js +198 -0
- package/lib/onchain/onchainTypes.d.ts +6 -0
- package/package.json +1 -1
- package/lib/offchain/account/offchainAccountLendingVault.d.ts +0 -16
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const types_1 = require("../../../config/types");
|
|
16
|
+
const onchainTypes_1 = require("../../onchainTypes");
|
|
17
|
+
const factories_1 = require("../../../config/factories");
|
|
18
|
+
const lliquidity_math_1 = require("../../../utils/lliquidity-math");
|
|
19
|
+
const utils_1 = require("../../../utils");
|
|
20
|
+
const onchainAccountLendingPool_1 = __importDefault(require("./onchainAccountLendingPool"));
|
|
21
|
+
const onchainAccountBorrowableV2_1 = __importDefault(require("./onchainAccountBorrowableV2"));
|
|
22
|
+
const onchainAccountCollateralV2_1 = __importDefault(require("./onchainAccountCollateralV2"));
|
|
23
|
+
class OnchainAccountLendingPoolV2 extends onchainAccountLendingPool_1.default {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
// Shortcuts
|
|
27
|
+
this.getLendingPool = () => this.lendingPool;
|
|
28
|
+
this.getBorrowable = (borrowable) => this.borrowables[borrowable];
|
|
29
|
+
this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
|
|
30
|
+
this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
|
|
31
|
+
this.getCollateral = () => this.collateral;
|
|
32
|
+
}
|
|
33
|
+
getNewCollateralObject() {
|
|
34
|
+
return new onchainAccountCollateralV2_1.default(this);
|
|
35
|
+
}
|
|
36
|
+
getNewBorrowableObject(borrowable) {
|
|
37
|
+
return new onchainAccountBorrowableV2_1.default(this, borrowable);
|
|
38
|
+
}
|
|
39
|
+
getInteractionsLendingPool() {
|
|
40
|
+
return this.account.getInteractions().getLendingPool(this.getFactory(), this.getId());
|
|
41
|
+
}
|
|
42
|
+
// LP equity number in LPs
|
|
43
|
+
getLPEquity() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const lpEquityUSD = yield this.getLPEquityUSD();
|
|
46
|
+
const tokenPrice = yield this.getCollateral().getTokenPriceAccurate();
|
|
47
|
+
const stakedLPExchangeRate = yield this.lendingPool.getStakedLPExchangeRate();
|
|
48
|
+
return lpEquityUSD / tokenPrice * stakedLPExchangeRate;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Values
|
|
52
|
+
getValuesFromPrice(changes, priceA, priceB) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const valueCollateral = (yield this.getCollateral().getDeposited()) + changes.changeCollateral;
|
|
55
|
+
const amountA = (yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA;
|
|
56
|
+
const amountB = (yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB;
|
|
57
|
+
const valueA = amountA * priceA;
|
|
58
|
+
const valueB = amountB * priceB;
|
|
59
|
+
return {
|
|
60
|
+
valueCollateral: valueCollateral > 0 ? valueCollateral : 0,
|
|
61
|
+
valueA: valueA > 0 ? valueA : 0,
|
|
62
|
+
valueB: valueB > 0 ? valueB : 0,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getValues(changes) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
|
|
69
|
+
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
getMarketValues(changes) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
75
|
+
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Leverage
|
|
79
|
+
getLeverage(changes) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!changes)
|
|
82
|
+
changes = onchainTypes_1.NO_CHANGES;
|
|
83
|
+
const { valueCollateral, valueA, valueB } = yield this.getValues(changes);
|
|
84
|
+
const valueDebt = valueA + valueB;
|
|
85
|
+
if (valueDebt == 0)
|
|
86
|
+
return 1;
|
|
87
|
+
const equity = valueCollateral - valueDebt;
|
|
88
|
+
if (equity <= 0)
|
|
89
|
+
return Infinity;
|
|
90
|
+
return valueDebt / equity + 1;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Liquidation Threshold
|
|
94
|
+
/*public async getLiquidationPriceSwingsGivenValues(values: Values) : Promise<[number, number]> {
|
|
95
|
+
if (!values) return [Infinity, Infinity];
|
|
96
|
+
const { valueCollateral, valueA, valueB } = values;
|
|
97
|
+
if (valueA + valueB == 0) return [Infinity, Infinity];
|
|
98
|
+
const safetyMargin = await this.getSafetyMargin();
|
|
99
|
+
const liquidationPenalty = await this.getLiquidationPenalty();
|
|
100
|
+
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
101
|
+
const rad = Math.sqrt(actualCollateral ** 2 - 4 * valueA * valueB);
|
|
102
|
+
if (!rad) return [0, 0];
|
|
103
|
+
const t = (actualCollateral + rad) / (2 * Math.sqrt(safetyMargin));
|
|
104
|
+
let priceSwingA = (t / valueA) ** 2;
|
|
105
|
+
let priceSwingB = (t / valueB) ** 2;
|
|
106
|
+
return [priceSwingA, priceSwingB];
|
|
107
|
+
}
|
|
108
|
+
public async getLiquidationPricesGivenValues(values: Values) : Promise<[number, number]> {
|
|
109
|
+
const currentPrice = await this.lendingPool.getTWAPPrice();
|
|
110
|
+
const [priceSwingA, priceSwingB] = await this.getLiquidationPriceSwingsGivenValues(values);
|
|
111
|
+
return !this.account.getOnchain().priceInverted ? [currentPrice / priceSwingB, currentPrice * priceSwingA] : [currentPrice / priceSwingA, currentPrice * priceSwingB];
|
|
112
|
+
}
|
|
113
|
+
public async getLiquidationPriceSwings(changes?: Changes) {
|
|
114
|
+
if (!changes) changes = NO_CHANGES;
|
|
115
|
+
const values = await this.getValues(changes);
|
|
116
|
+
return this.getLiquidationPriceSwingsGivenValues(values);
|
|
117
|
+
}
|
|
118
|
+
public async getLiquidationPrices(changes?: Changes) {
|
|
119
|
+
if (!changes) changes = NO_CHANGES;
|
|
120
|
+
const values = await this.getValues(changes);
|
|
121
|
+
return this.getLiquidationPricesGivenValues(values);
|
|
122
|
+
}*/
|
|
123
|
+
getLiquidationPrices(changes) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
if (!changes)
|
|
126
|
+
changes = onchainTypes_1.NO_CHANGES;
|
|
127
|
+
const collateralAmount = Math.max((yield this.getCollateral().getDeposited()) + changes.changeCollateral, 0);
|
|
128
|
+
const debtA = Math.max((yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA, 0);
|
|
129
|
+
const debtB = Math.max((yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB, 0);
|
|
130
|
+
const safetyMargin = yield this.getSafetyMargin();
|
|
131
|
+
const liquidationPenalty = yield this.getLiquidationPenalty();
|
|
132
|
+
const actualCollateral = collateralAmount / liquidationPenalty;
|
|
133
|
+
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getTwapReservesWeights();
|
|
134
|
+
const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
|
|
135
|
+
const collateralA = actualCollateral * reservesWeight0 / priceA;
|
|
136
|
+
const collateralB = actualCollateral * reservesWeight1 / priceB;
|
|
137
|
+
let priceSwingA, priceSwingB;
|
|
138
|
+
if (factories_1.STABLE_FACTORIES.includes(this.lendingPool.getImpermaxFactory().getFactory())) {
|
|
139
|
+
priceSwingA = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
140
|
+
priceSwingB = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
priceSwingA = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
144
|
+
priceSwingB = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
145
|
+
}
|
|
146
|
+
const twapPrice = yield this.lendingPool.getTWAPPrice();
|
|
147
|
+
return !this.account.getOnchain().priceInverted
|
|
148
|
+
? [twapPrice * priceSwingA, twapPrice / priceSwingB]
|
|
149
|
+
: [twapPrice * priceSwingB, twapPrice / priceSwingA];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
// Max Leverage
|
|
153
|
+
/*public async getMaxLeverage() : Promise<number> {
|
|
154
|
+
const availableCashA = await this.getBorrowableA().getPoolToken().getTotalBalance();
|
|
155
|
+
const availableCashB = await this.getBorrowableB().getPoolToken().getTotalBalance();
|
|
156
|
+
const [priceA, priceB] = await this.lendingPool.getMarketPriceDenomLP();
|
|
157
|
+
const [priceATWAP,] = await this.lendingPool.getPriceDenomLP();
|
|
158
|
+
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
159
|
+
const adjustFactor = 1 / diff;
|
|
160
|
+
const availableCashValue1 = availableCashA * priceA;
|
|
161
|
+
const availableCashValue2 = availableCashB * priceB;
|
|
162
|
+
const { valueCollateral, valueA, valueB } = await this.getValues(NO_CHANGES);
|
|
163
|
+
const safetyMargin = (await this.getSafetyMargin()) * this.getUiMargin();
|
|
164
|
+
const liquidationPenalty = await this.getLiquidationPenalty();
|
|
165
|
+
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
166
|
+
const num1 = actualCollateral * Math.sqrt(safetyMargin) - valueA * safetyMargin - valueB;
|
|
167
|
+
const num2 = actualCollateral * Math.sqrt(safetyMargin) - valueB * safetyMargin - valueA;
|
|
168
|
+
const den = safetyMargin + 1 - 2 * Math.sqrt(safetyMargin) / liquidationPenalty;
|
|
169
|
+
const additionalValueBorrowablePerSide = Math.min(num1 / den, num2 / den, availableCashValue1, availableCashValue2) * adjustFactor;
|
|
170
|
+
const valueDebt = valueA + valueB;
|
|
171
|
+
const equity = valueCollateral - valueDebt;
|
|
172
|
+
if (equity == 0) return 1;
|
|
173
|
+
return (valueDebt + additionalValueBorrowablePerSide * 2) / equity + 1;
|
|
174
|
+
}*/
|
|
175
|
+
// binary search how much additional leverage we can get
|
|
176
|
+
getMaxLeverage() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const availableCashA = yield this.getBorrowableA().getPoolToken().getTotalBalance();
|
|
179
|
+
const availableCashB = yield this.getBorrowableB().getPoolToken().getTotalBalance();
|
|
180
|
+
const collateralAmount = yield this.getCollateral().getDeposited();
|
|
181
|
+
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
|
|
182
|
+
//const [priceA, priceB] = await this.lendingPool.getPriceDenomLP();
|
|
183
|
+
//TODO come posso adattare l'aggiustamento alle stable pairs?
|
|
184
|
+
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
185
|
+
const [priceATWAP,] = yield this.lendingPool.getPriceDenomLP();
|
|
186
|
+
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
187
|
+
const collateralA = collateralAmount * reservesWeight0 / priceA;
|
|
188
|
+
const collateralB = collateralAmount * reservesWeight1 / priceB;
|
|
189
|
+
const twapPrice = yield this.lendingPool.getTWAPPrice();
|
|
190
|
+
// start search
|
|
191
|
+
let addLev = 100;
|
|
192
|
+
let addLevPrev = 0;
|
|
193
|
+
let bestChanges = onchainTypes_1.NO_CHANGES;
|
|
194
|
+
for (let i = 0; i < 1000; i++) {
|
|
195
|
+
const jump = Math.abs(addLev - addLevPrev) / 2;
|
|
196
|
+
if (jump < 0.01)
|
|
197
|
+
break;
|
|
198
|
+
addLevPrev = addLev;
|
|
199
|
+
const adjustFactor = Math.pow((0, utils_1.impermanentLoss)(Math.pow(diff, 2)), addLev);
|
|
200
|
+
const actualAddLev = addLev * adjustFactor;
|
|
201
|
+
const changeCollateral = collateralAmount * actualAddLev;
|
|
202
|
+
const changeBorrowedA = collateralA * actualAddLev;
|
|
203
|
+
const changeBorrowedB = collateralB * actualAddLev;
|
|
204
|
+
if (changeBorrowedA > availableCashA || changeBorrowedB > availableCashB) {
|
|
205
|
+
addLev -= jump;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const changes = { changeCollateral, changeBorrowedA, changeBorrowedB };
|
|
209
|
+
const [liqPriceA, liqPriceB] = yield this.getLiquidationPrices(changes);
|
|
210
|
+
if (liqPriceA * this.getUiMargin() > twapPrice || liqPriceB / this.getUiMargin() < twapPrice)
|
|
211
|
+
addLev -= jump;
|
|
212
|
+
else {
|
|
213
|
+
bestChanges = changes;
|
|
214
|
+
addLev += jump;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const maxLeverage = yield this.getLeverage(bestChanges);
|
|
218
|
+
return Math.floor(maxLeverage * 100) / 100;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// Max Deleverage
|
|
222
|
+
getMaxDeleverage(slippage) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const { valueCollateral, valueA, valueB } = yield this.getMarketValues(onchainTypes_1.NO_CHANGES);
|
|
225
|
+
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
|
|
226
|
+
const collateralValueA = valueCollateral * reservesWeight0;
|
|
227
|
+
const collateralValueB = valueCollateral * reservesWeight1;
|
|
228
|
+
if (collateralValueA >= valueA && collateralValueB >= valueB) {
|
|
229
|
+
return (yield this.getCollateral().getDeposited()) * this.account.getOnchain().dust;
|
|
230
|
+
}
|
|
231
|
+
if (valueCollateral < valueA + valueB) {
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
if (valueA / collateralValueA < valueB / collateralValueB) {
|
|
235
|
+
return (valueA + valueA / collateralValueA * collateralValueB);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return (valueB + valueB / collateralValueB * collateralValueA);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
// Available Reward
|
|
243
|
+
getAvailableReward() {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const result = [];
|
|
246
|
+
const farmingAmount = (yield this.getBorrowableA().getAvailableFarmingReward()) + (yield this.getBorrowableB().getAvailableFarmingReward());
|
|
247
|
+
if (farmingAmount > 0) {
|
|
248
|
+
const farmingSymbol = yield this.getBorrowableA().getPoolToken().getFarmingTokenSymbol();
|
|
249
|
+
result.push({
|
|
250
|
+
symbol: farmingSymbol,
|
|
251
|
+
amount: farmingAmount
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const rewarderSymbols = [
|
|
255
|
+
yield this.getBorrowableA().getPoolToken().getRewarderTokenSymbol(),
|
|
256
|
+
yield this.getBorrowableB().getPoolToken().getRewarderTokenSymbol()
|
|
257
|
+
];
|
|
258
|
+
const rewarderAmounts = [
|
|
259
|
+
yield this.getBorrowableA().getAvailableRewarderReward(),
|
|
260
|
+
yield this.getBorrowableB().getAvailableRewarderReward()
|
|
261
|
+
];
|
|
262
|
+
if (rewarderSymbols[0] === rewarderSymbols[1]) {
|
|
263
|
+
const rewarderAmount = rewarderAmounts[0] + rewarderAmounts[1];
|
|
264
|
+
if (rewarderAmount === 0)
|
|
265
|
+
return result;
|
|
266
|
+
result.push({
|
|
267
|
+
symbol: rewarderSymbols[0],
|
|
268
|
+
amount: rewarderAmount
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
for (let i = 0; i < 2; i++) {
|
|
273
|
+
if (rewarderAmounts[i] === 0)
|
|
274
|
+
continue;
|
|
275
|
+
result.push({
|
|
276
|
+
symbol: rewarderSymbols[i],
|
|
277
|
+
amount: rewarderAmounts[i]
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.default = OnchainAccountLendingPoolV2;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Borrowable } from '../../../config/types';
|
|
2
|
+
import { OnchainLendingPoolV3 } from '../../impermaxFactory/lendingPool';
|
|
3
|
+
import OnchainAccountLendingPool from "./onchainAccountLendingPool";
|
|
4
|
+
import OnchainAccountCollateralV3 from "./onchainAccountCollateralV3";
|
|
5
|
+
import OnchainAccountBorrowableV3 from "./onchainAccountBorrowableV3";
|
|
6
|
+
import { OnchainInteractionsLendingPoolV3 } from "../../interactions/lendingPool";
|
|
7
|
+
import OnchainAccountNftlp from "./nftlp";
|
|
8
|
+
import OnchainAccount from "../index";
|
|
9
|
+
export default class OnchainAccountLendingPoolV3 extends OnchainAccountLendingPool {
|
|
10
|
+
protected readonly lendingPool: OnchainLendingPoolV3;
|
|
11
|
+
protected readonly collateral: OnchainAccountCollateralV3;
|
|
12
|
+
protected readonly borrowables: {
|
|
13
|
+
[Borrowable.A]: OnchainAccountBorrowableV3;
|
|
14
|
+
[Borrowable.B]: OnchainAccountBorrowableV3;
|
|
15
|
+
};
|
|
16
|
+
protected readonly nftlp: OnchainAccountNftlp;
|
|
17
|
+
constructor(account: OnchainAccount, lendingPool: OnchainLendingPoolV3);
|
|
18
|
+
protected getNewCollateralObject(): OnchainAccountCollateralV3;
|
|
19
|
+
protected getNewBorrowableObject(borrowable: Borrowable): OnchainAccountBorrowableV3;
|
|
20
|
+
getLendingPool: () => OnchainLendingPoolV3;
|
|
21
|
+
getBorrowable: (borrowable: Borrowable) => OnchainAccountBorrowableV3;
|
|
22
|
+
getBorrowableA: () => OnchainAccountBorrowableV3;
|
|
23
|
+
getBorrowableB: () => OnchainAccountBorrowableV3;
|
|
24
|
+
getCollateral: () => OnchainAccountCollateralV3;
|
|
25
|
+
getNftlp: () => OnchainAccountNftlp;
|
|
26
|
+
getInteractionsLendingPool(): OnchainInteractionsLendingPoolV3;
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const types_1 = require("../../../config/types");
|
|
7
|
+
const onchainAccountLendingPool_1 = __importDefault(require("./onchainAccountLendingPool"));
|
|
8
|
+
const onchainAccountCollateralV3_1 = __importDefault(require("./onchainAccountCollateralV3"));
|
|
9
|
+
const onchainAccountBorrowableV3_1 = __importDefault(require("./onchainAccountBorrowableV3"));
|
|
10
|
+
class OnchainAccountLendingPoolV3 extends onchainAccountLendingPool_1.default {
|
|
11
|
+
constructor(account, lendingPool) {
|
|
12
|
+
super(account, lendingPool);
|
|
13
|
+
// Shortcuts
|
|
14
|
+
this.getLendingPool = () => this.lendingPool;
|
|
15
|
+
this.getBorrowable = (borrowable) => this.borrowables[borrowable];
|
|
16
|
+
this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
|
|
17
|
+
this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
|
|
18
|
+
this.getCollateral = () => this.collateral;
|
|
19
|
+
this.getNftlp = () => this.nftlp;
|
|
20
|
+
this.nftlp = lendingPool.getNftlp().getNewAccountNftlpObject(this);
|
|
21
|
+
}
|
|
22
|
+
getNewCollateralObject() {
|
|
23
|
+
return new onchainAccountCollateralV3_1.default(this);
|
|
24
|
+
}
|
|
25
|
+
getNewBorrowableObject(borrowable) {
|
|
26
|
+
return new onchainAccountBorrowableV3_1.default(this, borrowable);
|
|
27
|
+
}
|
|
28
|
+
getInteractionsLendingPool() {
|
|
29
|
+
return this.account.getInteractions().getLendingPool(this.getFactory(), this.getId());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = OnchainAccountLendingPoolV3;
|
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
16
15
|
const onchainAccountLendingVault_1 = __importDefault(require("./onchainAccountLendingVault"));
|
|
17
16
|
const merkle_distributors_1 = require("../../config/endpoints/merkle-distributors");
|
|
18
17
|
const ethers_1 = require("ethers");
|
|
@@ -43,7 +42,7 @@ class OnchainAccount {
|
|
|
43
42
|
}
|
|
44
43
|
initializeLendingPool(factory, pair) {
|
|
45
44
|
const lendingPool = this.onchain.getImpermaxFactory(factory).getLendingPool(pair);
|
|
46
|
-
return
|
|
45
|
+
return lendingPool.getNewAccountLendingPoolObject(this);
|
|
47
46
|
}
|
|
48
47
|
getLendingPool(factory, pair) {
|
|
49
48
|
if (!this.lendingPools[factory])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import OnchainAccountPoolToken from './onchainAccountPoolToken';
|
|
2
2
|
import OnchainAccount from './onchainAccount';
|
|
3
3
|
import OnchainLendingVault from '../onchainLendingVault';
|
|
4
|
-
import
|
|
4
|
+
import OffchainAccountVault from '../../offchain/account/vault/offchainAccountVault';
|
|
5
5
|
import OnchainInteractionsLendingVault from '../interactions/onchainInteractionsLendingVault';
|
|
6
6
|
export default class OnchainAccountLendingVault extends OnchainAccountPoolToken {
|
|
7
7
|
private account;
|
|
@@ -12,8 +12,8 @@ export default class OnchainAccountLendingVault extends OnchainAccountPoolToken
|
|
|
12
12
|
getAccount: () => OnchainAccount;
|
|
13
13
|
getInteractionsPoolToken(): OnchainInteractionsLendingVault;
|
|
14
14
|
getInteractionsLendingVault: () => OnchainInteractionsLendingVault;
|
|
15
|
-
getOffchainAccountPoolToken(): Promise<
|
|
16
|
-
getOffchainAccountLendingVault: () => Promise<
|
|
15
|
+
getOffchainAccountPoolToken(): Promise<OffchainAccountVault>;
|
|
16
|
+
getOffchainAccountLendingVault: () => Promise<OffchainAccountVault>;
|
|
17
17
|
cleanCache(): void;
|
|
18
18
|
getMaxWithdrawable(): Promise<number>;
|
|
19
19
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as lendingPool from './lendingPool';
|
|
2
2
|
import OnchainLendingPool from "./lendingPool";
|
|
3
3
|
import OnchainImpermaxFactory from './onchainImpermaxFactory';
|
|
4
|
-
|
|
4
|
+
import OnchainImpermaxFactoryV2 from './onchainImpermaxFactoryV2';
|
|
5
|
+
import OnchainImpermaxFactoryV3 from './onchainImpermaxFactoryV3';
|
|
6
|
+
export { lendingPool, OnchainLendingPool, OnchainImpermaxFactoryV2, OnchainImpermaxFactoryV3, };
|
|
5
7
|
export default OnchainImpermaxFactory;
|
|
@@ -26,10 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.OnchainLendingPool = exports.lendingPool = void 0;
|
|
29
|
+
exports.OnchainImpermaxFactoryV3 = exports.OnchainImpermaxFactoryV2 = exports.OnchainLendingPool = exports.lendingPool = void 0;
|
|
30
30
|
const lendingPool = __importStar(require("./lendingPool"));
|
|
31
31
|
exports.lendingPool = lendingPool;
|
|
32
32
|
const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
33
33
|
exports.OnchainLendingPool = lendingPool_1.default;
|
|
34
34
|
const onchainImpermaxFactory_1 = __importDefault(require("./onchainImpermaxFactory"));
|
|
35
|
+
const onchainImpermaxFactoryV2_1 = __importDefault(require("./onchainImpermaxFactoryV2"));
|
|
36
|
+
exports.OnchainImpermaxFactoryV2 = onchainImpermaxFactoryV2_1.default;
|
|
37
|
+
const onchainImpermaxFactoryV3_1 = __importDefault(require("./onchainImpermaxFactoryV3"));
|
|
38
|
+
exports.OnchainImpermaxFactoryV3 = onchainImpermaxFactoryV3_1.default;
|
|
35
39
|
exports.default = onchainImpermaxFactory_1.default;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import * as nftlp from './nftlp';
|
|
1
2
|
import OnchainCollateral from "./onchainCollateral";
|
|
2
3
|
import OnchainBorrowable from "./onchainBorrowable";
|
|
3
4
|
import OnchainLendingPool from './onchainLendingPool';
|
|
4
|
-
|
|
5
|
+
import OnchainLendingPoolV2 from "./onchainLendingPoolV2";
|
|
6
|
+
import OnchainBorrowableV2 from "./onchainBorrowableV2";
|
|
7
|
+
import OnchainCollateralV2 from "./onchainCollateralV2";
|
|
8
|
+
import OnchainLendingPoolV3 from "./onchainLendingPoolV3";
|
|
9
|
+
import OnchainBorrowableV3 from "./onchainBorrowableV3";
|
|
10
|
+
import OnchainCollateralV3 from "./onchainCollateralV3";
|
|
11
|
+
export { nftlp, OnchainBorrowable, OnchainCollateral, OnchainLendingPool, OnchainLendingPoolV2, OnchainBorrowableV2, OnchainCollateralV2, OnchainLendingPoolV3, OnchainBorrowableV3, OnchainCollateralV3, };
|
|
5
12
|
export default OnchainLendingPool;
|
|
@@ -1,12 +1,50 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OnchainCollateral = exports.OnchainBorrowable = void 0;
|
|
29
|
+
exports.OnchainCollateralV3 = exports.OnchainBorrowableV3 = exports.OnchainLendingPoolV3 = exports.OnchainCollateralV2 = exports.OnchainBorrowableV2 = exports.OnchainLendingPoolV2 = exports.OnchainLendingPool = exports.OnchainCollateral = exports.OnchainBorrowable = exports.nftlp = void 0;
|
|
30
|
+
const nftlp = __importStar(require("./nftlp"));
|
|
31
|
+
exports.nftlp = nftlp;
|
|
7
32
|
const onchainCollateral_1 = __importDefault(require("./onchainCollateral"));
|
|
8
33
|
exports.OnchainCollateral = onchainCollateral_1.default;
|
|
9
34
|
const onchainBorrowable_1 = __importDefault(require("./onchainBorrowable"));
|
|
10
35
|
exports.OnchainBorrowable = onchainBorrowable_1.default;
|
|
11
36
|
const onchainLendingPool_1 = __importDefault(require("./onchainLendingPool"));
|
|
37
|
+
exports.OnchainLendingPool = onchainLendingPool_1.default;
|
|
38
|
+
const onchainLendingPoolV2_1 = __importDefault(require("./onchainLendingPoolV2"));
|
|
39
|
+
exports.OnchainLendingPoolV2 = onchainLendingPoolV2_1.default;
|
|
40
|
+
const onchainBorrowableV2_1 = __importDefault(require("./onchainBorrowableV2"));
|
|
41
|
+
exports.OnchainBorrowableV2 = onchainBorrowableV2_1.default;
|
|
42
|
+
const onchainCollateralV2_1 = __importDefault(require("./onchainCollateralV2"));
|
|
43
|
+
exports.OnchainCollateralV2 = onchainCollateralV2_1.default;
|
|
44
|
+
const onchainLendingPoolV3_1 = __importDefault(require("./onchainLendingPoolV3"));
|
|
45
|
+
exports.OnchainLendingPoolV3 = onchainLendingPoolV3_1.default;
|
|
46
|
+
const onchainBorrowableV3_1 = __importDefault(require("./onchainBorrowableV3"));
|
|
47
|
+
exports.OnchainBorrowableV3 = onchainBorrowableV3_1.default;
|
|
48
|
+
const onchainCollateralV3_1 = __importDefault(require("./onchainCollateralV3"));
|
|
49
|
+
exports.OnchainCollateralV3 = onchainCollateralV3_1.default;
|
|
12
50
|
exports.default = onchainLendingPool_1.default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OnchainNftlpUniswapV3 = exports.OnchainNftlp = void 0;
|
|
7
|
+
const onchainNftlp_1 = __importDefault(require("./onchainNftlp"));
|
|
8
|
+
exports.OnchainNftlp = onchainNftlp_1.default;
|
|
9
|
+
const onchainNftlpUniswapV3_1 = __importDefault(require("./onchainNftlpUniswapV3"));
|
|
10
|
+
exports.OnchainNftlpUniswapV3 = onchainNftlpUniswapV3_1.default;
|
|
11
|
+
exports.default = onchainNftlp_1.default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import OnchainLendingPoolV3 from "../onchainLendingPoolV3";
|
|
2
|
+
import { Contract } from "../../../onchainTypes";
|
|
3
|
+
import { OnchainAccountLendingPoolV3 } from "../../../account/lendingPool";
|
|
4
|
+
import OnchainAccountNftlp from "../../../account/lendingPool/nftlp";
|
|
5
|
+
import { OnchainInteractionsLendingPoolV3 } from "../../../interactions/lendingPool";
|
|
6
|
+
import OnchainInteractionsNftlp from "../../../interactions/lendingPool/nftlp";
|
|
7
|
+
export default abstract class OnchainNftlp {
|
|
8
|
+
protected readonly lendingPool: OnchainLendingPoolV3;
|
|
9
|
+
protected cache: {
|
|
10
|
+
nftlp?: Contract;
|
|
11
|
+
};
|
|
12
|
+
abstract getNewAccountNftlpObject(accountLendingPool: OnchainAccountLendingPoolV3): OnchainAccountNftlp;
|
|
13
|
+
abstract getNewInteractionsNftlpObject(accountLendingPool: OnchainInteractionsLendingPoolV3): OnchainInteractionsNftlp;
|
|
14
|
+
constructor(lendingPool: OnchainLendingPoolV3);
|
|
15
|
+
cleanCache(): void;
|
|
16
|
+
protected getContractHelper: () => import("../../..").OnchainContractsHelper;
|
|
17
|
+
getNftlpAddress: () => string;
|
|
18
|
+
protected abstract initializeNftlp(): Contract;
|
|
19
|
+
getNftlp(): any;
|
|
20
|
+
abstract getMarketPrice(): Promise<number>;
|
|
21
|
+
abstract getOraclePrice(): Promise<number>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class OnchainNftlp {
|
|
4
|
+
constructor(lendingPool) {
|
|
5
|
+
this.cache = {};
|
|
6
|
+
this.getContractHelper = () => this.lendingPool.getImpermaxFactory().getOnchain().getContractHelper();
|
|
7
|
+
this.getNftlpAddress = () => this.lendingPool.getId();
|
|
8
|
+
this.lendingPool = lendingPool;
|
|
9
|
+
}
|
|
10
|
+
cleanCache() {
|
|
11
|
+
this.cache = {};
|
|
12
|
+
}
|
|
13
|
+
getNftlp() {
|
|
14
|
+
if (!this.cache.nftlp)
|
|
15
|
+
this.cache.nftlp = this.initializeNftlp();
|
|
16
|
+
return this.cache.nftlp;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = OnchainNftlp;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import OnchainNftlp from "./onchainNftlp";
|
|
2
|
+
import { Contract } from "../../../onchainTypes";
|
|
3
|
+
import { OnchainAccountLendingPoolV3 } from "../../../account/lendingPool";
|
|
4
|
+
import { OnchainAccountNftlpUniswapV3 } from "../../../account/lendingPool/nftlp";
|
|
5
|
+
import { OnchainInteractionsNftlpUniswapV3 } from "../../../interactions/lendingPool/nftlp";
|
|
6
|
+
import { OnchainInteractionsLendingPoolV3 } from "../../../interactions/lendingPool";
|
|
7
|
+
export default class OnchainNftlpUniswapV3 extends OnchainNftlp {
|
|
8
|
+
protected cache: {
|
|
9
|
+
nftlp?: Contract;
|
|
10
|
+
uniswapV3Pools?: {
|
|
11
|
+
[key in number]: Promise<Contract | null>;
|
|
12
|
+
};
|
|
13
|
+
marketPrice?: Promise<number>;
|
|
14
|
+
oraclePrice?: Promise<number>;
|
|
15
|
+
};
|
|
16
|
+
getNewAccountNftlpObject(accountNftlp: OnchainAccountLendingPoolV3): OnchainAccountNftlpUniswapV3;
|
|
17
|
+
getNewInteractionsNftlpObject(interactionsNftlp: OnchainInteractionsLendingPoolV3): OnchainInteractionsNftlpUniswapV3;
|
|
18
|
+
initializeNftlp(): any;
|
|
19
|
+
initializeUniswapV3Pool(fee: number): Promise<Contract | null>;
|
|
20
|
+
getUniswapV3Pool(fee: number): Promise<any>;
|
|
21
|
+
getMarketPrice(): Promise<number>;
|
|
22
|
+
private initializeOraclePrice;
|
|
23
|
+
getOraclePrice(): Promise<number>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const onchainNftlp_1 = __importDefault(require("./onchainNftlp"));
|
|
16
|
+
const nftlp_1 = require("../../../account/lendingPool/nftlp");
|
|
17
|
+
const nftlp_2 = require("../../../interactions/lendingPool/nftlp");
|
|
18
|
+
const FEES = [
|
|
19
|
+
100,
|
|
20
|
+
500,
|
|
21
|
+
3000,
|
|
22
|
+
10000,
|
|
23
|
+
];
|
|
24
|
+
class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.cache = {};
|
|
28
|
+
}
|
|
29
|
+
getNewAccountNftlpObject(accountNftlp) {
|
|
30
|
+
return new nftlp_1.OnchainAccountNftlpUniswapV3(accountNftlp);
|
|
31
|
+
}
|
|
32
|
+
getNewInteractionsNftlpObject(interactionsNftlp) {
|
|
33
|
+
return new nftlp_2.OnchainInteractionsNftlpUniswapV3(interactionsNftlp);
|
|
34
|
+
}
|
|
35
|
+
initializeNftlp() {
|
|
36
|
+
return this.getContractHelper().newNftlpUniV3(this.getNftlpAddress());
|
|
37
|
+
}
|
|
38
|
+
initializeUniswapV3Pool(fee) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const nftlp = this.getNftlp();
|
|
41
|
+
try {
|
|
42
|
+
const poolAddress = yield nftlp.methods.getPool(fee).call();
|
|
43
|
+
return this.getContractHelper().newUniswapV3Pool(poolAddress);
|
|
44
|
+
}
|
|
45
|
+
catch (_a) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getUniswapV3Pool(fee) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!this.cache.uniswapV3Pools)
|
|
53
|
+
this.cache.uniswapV3Pools = {};
|
|
54
|
+
if (!this.cache.uniswapV3Pools[fee])
|
|
55
|
+
this.cache.uniswapV3Pools[fee] = this.initializeUniswapV3Pool(fee);
|
|
56
|
+
return this.cache.uniswapV3Pools[fee];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getMarketPrice() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
let priceCumulative = 0;
|
|
62
|
+
let liquidityCumulative = 0;
|
|
63
|
+
for (const fee of FEES) {
|
|
64
|
+
const pool = yield this.getUniswapV3Pool(fee);
|
|
65
|
+
if (!pool)
|
|
66
|
+
continue;
|
|
67
|
+
const price = Math.pow(((yield pool.methods.slot0().call()).sqrtPriceX96 / Math.pow(2, 96)), 2);
|
|
68
|
+
const liquidity = (yield pool.methods.liquidity().call()) * 1;
|
|
69
|
+
priceCumulative += price * liquidity;
|
|
70
|
+
liquidityCumulative += liquidity;
|
|
71
|
+
}
|
|
72
|
+
return priceCumulative / liquidityCumulative;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
initializeOraclePrice() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const nftlp = yield this.getNftlp();
|
|
79
|
+
return Math.pow((nftlp.methods.oraclePriceSqrtX96().call() / Math.pow(2, 96)), 2);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getOraclePrice() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
if (!this.cache.oraclePrice)
|
|
85
|
+
this.cache.oraclePrice = this.initializeOraclePrice();
|
|
86
|
+
return this.cache.oraclePrice;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.default = OnchainNftlpUniswapV3;
|