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,44 @@
|
|
|
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 onchainAccountCollateral_1 = __importDefault(require("./onchainAccountCollateral"));
|
|
16
|
+
class OnchainAccountCollateralV3 extends onchainAccountCollateral_1.default {
|
|
17
|
+
constructor(lendingPool) {
|
|
18
|
+
super();
|
|
19
|
+
this.collateralCache = {};
|
|
20
|
+
this.getLendingPool = () => this.lendingPool;
|
|
21
|
+
this.getCollateral = () => this.collateral;
|
|
22
|
+
this.getAccount = () => this.lendingPool.getAccount();
|
|
23
|
+
this.lendingPool = lendingPool;
|
|
24
|
+
this.collateral = lendingPool.getLendingPool().getCollateral();
|
|
25
|
+
}
|
|
26
|
+
getInteractionsCollateral() {
|
|
27
|
+
return this.lendingPool.getInteractionsLendingPool().getCollateral();
|
|
28
|
+
}
|
|
29
|
+
getOffchainAccountCollateral() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const offchainAccountLendingPool = yield this.lendingPool.getOffchainAccountLendingPool();
|
|
32
|
+
return offchainAccountLendingPool.getCollateral();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
cleanCache() {
|
|
36
|
+
this.collateralCache = {};
|
|
37
|
+
}
|
|
38
|
+
getDepositedUSD() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return 0;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = OnchainAccountCollateralV3;
|
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
import OnchainAccount from '../index';
|
|
2
|
-
import {
|
|
2
|
+
import { Borrowable } from '../../../config/types';
|
|
3
3
|
import OnchainAccountCollateral from './onchainAccountCollateral';
|
|
4
4
|
import OnchainAccountBorrowable from './onchainAccountBorrowable';
|
|
5
|
-
import {
|
|
5
|
+
import { PendingRewardUI } from '../../onchainTypes';
|
|
6
6
|
import OnchainLendingPool from '../../impermaxFactory/lendingPool';
|
|
7
|
-
import OnchainAccountPoolToken from '../onchainAccountPoolToken';
|
|
8
7
|
import OnchainInteractionsLendingPool from '../../interactions/lendingPool';
|
|
9
8
|
import OffchainAccountLendingPool from '../../../offchain/account/lendingPool';
|
|
10
|
-
export default class OnchainAccountLendingPool {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export default abstract class OnchainAccountLendingPool {
|
|
10
|
+
protected readonly account: OnchainAccount;
|
|
11
|
+
protected readonly lendingPool: OnchainLendingPool;
|
|
12
|
+
protected readonly collateral: OnchainAccountCollateral;
|
|
13
|
+
protected readonly borrowables: {
|
|
14
|
+
[Borrowable.A]: OnchainAccountBorrowable;
|
|
15
|
+
[Borrowable.B]: OnchainAccountBorrowable;
|
|
16
|
+
};
|
|
17
|
+
protected cache: {};
|
|
18
|
+
protected abstract getNewCollateralObject(): OnchainAccountCollateral;
|
|
19
|
+
protected abstract getNewBorrowableObject(borrowable: Borrowable): OnchainAccountBorrowable;
|
|
15
20
|
constructor(account: OnchainAccount, lendingPool: OnchainLendingPool);
|
|
21
|
+
cleanCache(): void;
|
|
16
22
|
getAccount: () => OnchainAccount;
|
|
17
23
|
getLendingPool: () => OnchainLendingPool;
|
|
18
|
-
|
|
19
|
-
getInteractionsLendingPool(): OnchainInteractionsLendingPool;
|
|
20
|
-
getOffchainAccountLendingPool(): Promise<OffchainAccountLendingPool>;
|
|
21
|
-
cleanCache(): void;
|
|
24
|
+
getBorrowable: (borrowable: Borrowable) => OnchainAccountBorrowable;
|
|
22
25
|
getBorrowableA: () => OnchainAccountBorrowable;
|
|
23
26
|
getBorrowableB: () => OnchainAccountBorrowable;
|
|
24
27
|
getCollateral: () => OnchainAccountCollateral;
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
protected getFactory: () => import("../../../config/types").Factory;
|
|
29
|
+
protected getId: () => string;
|
|
27
30
|
getSafetyMargin: () => Promise<number>;
|
|
28
31
|
getLiquidationPenalty: () => Promise<number>;
|
|
29
32
|
getUiMargin: () => number;
|
|
33
|
+
getInteractionsLendingPool(): OnchainInteractionsLendingPool;
|
|
34
|
+
getOffchainAccountLendingPool(): Promise<OffchainAccountLendingPool>;
|
|
30
35
|
getBalanceUSD(): Promise<number>;
|
|
31
36
|
getSuppliedUSD(): Promise<number>;
|
|
32
37
|
getDebtUSD(): Promise<number>;
|
|
33
38
|
getEquityUSD(): Promise<number>;
|
|
34
39
|
getLPEquityUSD(): Promise<number>;
|
|
35
|
-
getLPEquity(): Promise<number>;
|
|
36
40
|
getAccountAPR(): Promise<number>;
|
|
37
|
-
getValuesFromPrice(changes: Changes, priceA: number, priceB: number): Promise<{
|
|
38
|
-
valueCollateral: number;
|
|
39
|
-
valueA: number;
|
|
40
|
-
valueB: number;
|
|
41
|
-
}>;
|
|
42
|
-
getValues(changes: Changes): Promise<{
|
|
43
|
-
valueCollateral: number;
|
|
44
|
-
valueA: number;
|
|
45
|
-
valueB: number;
|
|
46
|
-
}>;
|
|
47
|
-
getMarketValues(changes: Changes): Promise<{
|
|
48
|
-
valueCollateral: number;
|
|
49
|
-
valueA: number;
|
|
50
|
-
valueB: number;
|
|
51
|
-
}>;
|
|
52
|
-
getLeverage(changes?: Changes): Promise<number>;
|
|
53
|
-
getLiquidationPrices(changes?: Changes): Promise<number[]>;
|
|
54
|
-
getMaxLeverage(): Promise<number>;
|
|
55
|
-
getMaxDeleverage(slippage: number): Promise<number>;
|
|
56
41
|
getAvailableReward(): Promise<PendingRewardUI[]>;
|
|
57
42
|
}
|
|
@@ -8,54 +8,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
const types_1 = require("../../../config/types");
|
|
16
|
-
const onchainAccountCollateral_1 = __importDefault(require("./onchainAccountCollateral"));
|
|
17
|
-
const onchainAccountBorrowable_1 = __importDefault(require("./onchainAccountBorrowable"));
|
|
18
|
-
const onchainTypes_1 = require("../../onchainTypes");
|
|
19
|
-
const factories_1 = require("../../../config/factories");
|
|
20
|
-
const lliquidity_math_1 = require("../../../utils/lliquidity-math");
|
|
21
|
-
const utils_1 = require("../../../utils");
|
|
22
13
|
class OnchainAccountLendingPool {
|
|
23
14
|
constructor(account, lendingPool) {
|
|
24
15
|
this.cache = {};
|
|
16
|
+
// Shortcuts
|
|
25
17
|
this.getAccount = () => this.account;
|
|
26
18
|
this.getLendingPool = () => this.lendingPool;
|
|
27
|
-
|
|
28
|
-
this.getBorrowableA = () => this.
|
|
29
|
-
this.getBorrowableB = () => this.
|
|
30
|
-
this.getCollateral = () => this.
|
|
19
|
+
this.getBorrowable = (borrowable) => this.borrowables[borrowable];
|
|
20
|
+
this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
|
|
21
|
+
this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
|
|
22
|
+
this.getCollateral = () => this.collateral;
|
|
31
23
|
this.getFactory = () => this.lendingPool.getImpermaxFactory().getFactory();
|
|
32
|
-
this.
|
|
24
|
+
this.getId = () => this.lendingPool.getId();
|
|
33
25
|
this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getOffchainLendingPool()).getSafetyMargin(); });
|
|
34
26
|
this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getOffchainLendingPool()).getLiquidationPenalty(); });
|
|
35
27
|
this.getUiMargin = () => this.account.getOnchain().uiMargin;
|
|
36
28
|
this.account = account;
|
|
37
29
|
this.lendingPool = lendingPool;
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
[types_1.
|
|
41
|
-
[types_1.
|
|
30
|
+
this.collateral = this.getNewCollateralObject();
|
|
31
|
+
this.borrowables = {
|
|
32
|
+
[types_1.Borrowable.A]: this.getNewBorrowableObject(types_1.Borrowable.A),
|
|
33
|
+
[types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
|
|
42
34
|
};
|
|
43
35
|
}
|
|
44
|
-
getPoolToken(poolTokenType) {
|
|
45
|
-
return this.poolTokens[poolTokenType];
|
|
46
|
-
}
|
|
47
|
-
getInteractionsLendingPool() {
|
|
48
|
-
return this.account.getInteractions().getLendingPool(this.getFactory(), this.getPairAddress());
|
|
49
|
-
}
|
|
50
|
-
getOffchainAccountLendingPool() {
|
|
51
|
-
return this.account.getOffchainAccount().getLendingPool(this.getFactory(), this.getPairAddress());
|
|
52
|
-
}
|
|
53
36
|
cleanCache() {
|
|
54
37
|
this.cache = {};
|
|
55
38
|
this.getBorrowableA().cleanCache();
|
|
56
39
|
this.getBorrowableB().cleanCache();
|
|
57
40
|
this.getCollateral().cleanCache();
|
|
58
41
|
}
|
|
42
|
+
getInteractionsLendingPool() {
|
|
43
|
+
return this.account.getInteractions().getLendingPool(this.getFactory(), this.getId());
|
|
44
|
+
}
|
|
45
|
+
getOffchainAccountLendingPool() {
|
|
46
|
+
return this.account.getOffchainAccount().getLendingPool(this.getFactory(), this.getId());
|
|
47
|
+
}
|
|
59
48
|
// Balance
|
|
60
49
|
getBalanceUSD() {
|
|
61
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,15 +85,7 @@ class OnchainAccountLendingPool {
|
|
|
96
85
|
return collateralUSD - debtUSD;
|
|
97
86
|
});
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const lpEquityUSD = yield this.getLPEquityUSD();
|
|
102
|
-
const tokenPrice = yield this.getCollateral().getTokenPriceAccurate();
|
|
103
|
-
const stakedLPExchangeRate = yield this.lendingPool.getStakedLPExchangeRate();
|
|
104
|
-
return lpEquityUSD / tokenPrice * stakedLPExchangeRate;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// Debt
|
|
88
|
+
// APR
|
|
108
89
|
getAccountAPR() {
|
|
109
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
91
|
const depositedAUSD = yield this.getBorrowableA().getDepositedUSD();
|
|
@@ -115,197 +96,6 @@ class OnchainAccountLendingPool {
|
|
|
115
96
|
return totalSupplied > 0 ? (depositedAUSD * supplyAPRA + depositedBUSD * supplyAPRB) / totalSupplied : 0;
|
|
116
97
|
});
|
|
117
98
|
}
|
|
118
|
-
// Values
|
|
119
|
-
getValuesFromPrice(changes, priceA, priceB) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const valueCollateral = (yield this.getCollateral().getDeposited()) + changes.changeCollateral;
|
|
122
|
-
const amountA = (yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA;
|
|
123
|
-
const amountB = (yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB;
|
|
124
|
-
const valueA = amountA * priceA;
|
|
125
|
-
const valueB = amountB * priceB;
|
|
126
|
-
return {
|
|
127
|
-
valueCollateral: valueCollateral > 0 ? valueCollateral : 0,
|
|
128
|
-
valueA: valueA > 0 ? valueA : 0,
|
|
129
|
-
valueB: valueB > 0 ? valueB : 0,
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
getValues(changes) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
|
|
136
|
-
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
getMarketValues(changes) {
|
|
140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
142
|
-
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
// Leverage
|
|
146
|
-
getLeverage(changes) {
|
|
147
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
if (!changes)
|
|
149
|
-
changes = onchainTypes_1.NO_CHANGES;
|
|
150
|
-
const { valueCollateral, valueA, valueB } = yield this.getValues(changes);
|
|
151
|
-
const valueDebt = valueA + valueB;
|
|
152
|
-
if (valueDebt == 0)
|
|
153
|
-
return 1;
|
|
154
|
-
const equity = valueCollateral - valueDebt;
|
|
155
|
-
if (equity <= 0)
|
|
156
|
-
return Infinity;
|
|
157
|
-
return valueDebt / equity + 1;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
// Liquidation Threshold
|
|
161
|
-
/*public async getLiquidationPriceSwingsGivenValues(values: Values) : Promise<[number, number]> {
|
|
162
|
-
if (!values) return [Infinity, Infinity];
|
|
163
|
-
const { valueCollateral, valueA, valueB } = values;
|
|
164
|
-
if (valueA + valueB == 0) return [Infinity, Infinity];
|
|
165
|
-
const safetyMargin = await this.getSafetyMargin();
|
|
166
|
-
const liquidationPenalty = await this.getLiquidationPenalty();
|
|
167
|
-
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
168
|
-
const rad = Math.sqrt(actualCollateral ** 2 - 4 * valueA * valueB);
|
|
169
|
-
if (!rad) return [0, 0];
|
|
170
|
-
const t = (actualCollateral + rad) / (2 * Math.sqrt(safetyMargin));
|
|
171
|
-
let priceSwingA = (t / valueA) ** 2;
|
|
172
|
-
let priceSwingB = (t / valueB) ** 2;
|
|
173
|
-
return [priceSwingA, priceSwingB];
|
|
174
|
-
}
|
|
175
|
-
public async getLiquidationPricesGivenValues(values: Values) : Promise<[number, number]> {
|
|
176
|
-
const currentPrice = await this.lendingPool.getTWAPPrice();
|
|
177
|
-
const [priceSwingA, priceSwingB] = await this.getLiquidationPriceSwingsGivenValues(values);
|
|
178
|
-
return !this.account.getOnchain().priceInverted ? [currentPrice / priceSwingB, currentPrice * priceSwingA] : [currentPrice / priceSwingA, currentPrice * priceSwingB];
|
|
179
|
-
}
|
|
180
|
-
public async getLiquidationPriceSwings(changes?: Changes) {
|
|
181
|
-
if (!changes) changes = NO_CHANGES;
|
|
182
|
-
const values = await this.getValues(changes);
|
|
183
|
-
return this.getLiquidationPriceSwingsGivenValues(values);
|
|
184
|
-
}
|
|
185
|
-
public async getLiquidationPrices(changes?: Changes) {
|
|
186
|
-
if (!changes) changes = NO_CHANGES;
|
|
187
|
-
const values = await this.getValues(changes);
|
|
188
|
-
return this.getLiquidationPricesGivenValues(values);
|
|
189
|
-
}*/
|
|
190
|
-
getLiquidationPrices(changes) {
|
|
191
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
if (!changes)
|
|
193
|
-
changes = onchainTypes_1.NO_CHANGES;
|
|
194
|
-
const collateralAmount = Math.max((yield this.getCollateral().getDeposited()) + changes.changeCollateral, 0);
|
|
195
|
-
const debtA = Math.max((yield this.getBorrowableA().getBorrowed()) + changes.changeBorrowedA, 0);
|
|
196
|
-
const debtB = Math.max((yield this.getBorrowableB().getBorrowed()) + changes.changeBorrowedB, 0);
|
|
197
|
-
const safetyMargin = yield this.getSafetyMargin();
|
|
198
|
-
const liquidationPenalty = yield this.getLiquidationPenalty();
|
|
199
|
-
const actualCollateral = collateralAmount / liquidationPenalty;
|
|
200
|
-
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getTwapReservesWeights();
|
|
201
|
-
const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
|
|
202
|
-
const collateralA = actualCollateral * reservesWeight0 / priceA;
|
|
203
|
-
const collateralB = actualCollateral * reservesWeight1 / priceB;
|
|
204
|
-
let priceSwingA, priceSwingB;
|
|
205
|
-
if (factories_1.STABLE_FACTORIES.includes(this.lendingPool.getImpermaxFactory().getFactory())) {
|
|
206
|
-
priceSwingA = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
207
|
-
priceSwingB = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
priceSwingA = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
211
|
-
priceSwingB = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
212
|
-
}
|
|
213
|
-
const twapPrice = yield this.lendingPool.getTWAPPrice();
|
|
214
|
-
return !this.account.getOnchain().priceInverted
|
|
215
|
-
? [twapPrice * priceSwingA, twapPrice / priceSwingB]
|
|
216
|
-
: [twapPrice * priceSwingB, twapPrice / priceSwingA];
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
// Max Leverage
|
|
220
|
-
/*public async getMaxLeverage() : Promise<number> {
|
|
221
|
-
const availableCashA = await this.getBorrowableA().getPoolToken().getTotalBalance();
|
|
222
|
-
const availableCashB = await this.getBorrowableB().getPoolToken().getTotalBalance();
|
|
223
|
-
const [priceA, priceB] = await this.lendingPool.getMarketPriceDenomLP();
|
|
224
|
-
const [priceATWAP,] = await this.lendingPool.getPriceDenomLP();
|
|
225
|
-
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
226
|
-
const adjustFactor = 1 / diff;
|
|
227
|
-
const availableCashValue1 = availableCashA * priceA;
|
|
228
|
-
const availableCashValue2 = availableCashB * priceB;
|
|
229
|
-
const { valueCollateral, valueA, valueB } = await this.getValues(NO_CHANGES);
|
|
230
|
-
const safetyMargin = (await this.getSafetyMargin()) * this.getUiMargin();
|
|
231
|
-
const liquidationPenalty = await this.getLiquidationPenalty();
|
|
232
|
-
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
233
|
-
const num1 = actualCollateral * Math.sqrt(safetyMargin) - valueA * safetyMargin - valueB;
|
|
234
|
-
const num2 = actualCollateral * Math.sqrt(safetyMargin) - valueB * safetyMargin - valueA;
|
|
235
|
-
const den = safetyMargin + 1 - 2 * Math.sqrt(safetyMargin) / liquidationPenalty;
|
|
236
|
-
const additionalValueBorrowablePerSide = Math.min(num1 / den, num2 / den, availableCashValue1, availableCashValue2) * adjustFactor;
|
|
237
|
-
const valueDebt = valueA + valueB;
|
|
238
|
-
const equity = valueCollateral - valueDebt;
|
|
239
|
-
if (equity == 0) return 1;
|
|
240
|
-
return (valueDebt + additionalValueBorrowablePerSide * 2) / equity + 1;
|
|
241
|
-
}*/
|
|
242
|
-
// binary search how much additional leverage we can get
|
|
243
|
-
getMaxLeverage() {
|
|
244
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
const availableCashA = yield this.getBorrowableA().getPoolToken().getTotalBalance();
|
|
246
|
-
const availableCashB = yield this.getBorrowableB().getPoolToken().getTotalBalance();
|
|
247
|
-
const collateralAmount = yield this.getCollateral().getDeposited();
|
|
248
|
-
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
|
|
249
|
-
//const [priceA, priceB] = await this.lendingPool.getPriceDenomLP();
|
|
250
|
-
//TODO come posso adattare l'aggiustamento alle stable pairs?
|
|
251
|
-
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
252
|
-
const [priceATWAP,] = yield this.lendingPool.getPriceDenomLP();
|
|
253
|
-
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
254
|
-
const collateralA = collateralAmount * reservesWeight0 / priceA;
|
|
255
|
-
const collateralB = collateralAmount * reservesWeight1 / priceB;
|
|
256
|
-
const twapPrice = yield this.lendingPool.getTWAPPrice();
|
|
257
|
-
// start search
|
|
258
|
-
let addLev = 100;
|
|
259
|
-
let addLevPrev = 0;
|
|
260
|
-
let bestChanges = onchainTypes_1.NO_CHANGES;
|
|
261
|
-
for (let i = 0; i < 1000; i++) {
|
|
262
|
-
const jump = Math.abs(addLev - addLevPrev) / 2;
|
|
263
|
-
if (jump < 0.01)
|
|
264
|
-
break;
|
|
265
|
-
addLevPrev = addLev;
|
|
266
|
-
const adjustFactor = Math.pow((0, utils_1.impermanentLoss)(Math.pow(diff, 2)), addLev);
|
|
267
|
-
const actualAddLev = addLev * adjustFactor;
|
|
268
|
-
const changeCollateral = collateralAmount * actualAddLev;
|
|
269
|
-
const changeBorrowedA = collateralA * actualAddLev;
|
|
270
|
-
const changeBorrowedB = collateralB * actualAddLev;
|
|
271
|
-
if (changeBorrowedA > availableCashA || changeBorrowedB > availableCashB) {
|
|
272
|
-
addLev -= jump;
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
const changes = { changeCollateral, changeBorrowedA, changeBorrowedB };
|
|
276
|
-
const [liqPriceA, liqPriceB] = yield this.getLiquidationPrices(changes);
|
|
277
|
-
if (liqPriceA * this.getUiMargin() > twapPrice || liqPriceB / this.getUiMargin() < twapPrice)
|
|
278
|
-
addLev -= jump;
|
|
279
|
-
else {
|
|
280
|
-
bestChanges = changes;
|
|
281
|
-
addLev += jump;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const maxLeverage = yield this.getLeverage(bestChanges);
|
|
285
|
-
return Math.floor(maxLeverage * 100) / 100;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
// Max Deleverage
|
|
289
|
-
getMaxDeleverage(slippage) {
|
|
290
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
const { valueCollateral, valueA, valueB } = yield this.getMarketValues(onchainTypes_1.NO_CHANGES);
|
|
292
|
-
const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
|
|
293
|
-
const collateralValueA = valueCollateral * reservesWeight0;
|
|
294
|
-
const collateralValueB = valueCollateral * reservesWeight1;
|
|
295
|
-
if (collateralValueA >= valueA && collateralValueB >= valueB) {
|
|
296
|
-
return (yield this.getCollateral().getDeposited()) * this.account.getOnchain().dust;
|
|
297
|
-
}
|
|
298
|
-
if (valueCollateral < valueA + valueB) {
|
|
299
|
-
return 0;
|
|
300
|
-
}
|
|
301
|
-
if (valueA / collateralValueA < valueB / collateralValueB) {
|
|
302
|
-
return (valueA + valueA / collateralValueA * collateralValueB);
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
return (valueB + valueB / collateralValueB * collateralValueA);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
99
|
// Available Reward
|
|
310
100
|
getAvailableReward() {
|
|
311
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Borrowable } from '../../../config/types';
|
|
2
|
+
import { Changes, PendingRewardUI } from '../../onchainTypes';
|
|
3
|
+
import { OnchainLendingPoolV2 } from '../../impermaxFactory/lendingPool';
|
|
4
|
+
import OnchainAccountLendingPool from "./onchainAccountLendingPool";
|
|
5
|
+
import OnchainAccountBorrowableV2 from "./onchainAccountBorrowableV2";
|
|
6
|
+
import OnchainAccountCollateralV2 from "./onchainAccountCollateralV2";
|
|
7
|
+
import OnchainInteractionsLendingPoolV2 from "../../interactions/lendingPool/onchainInteractionsLendingPoolV2";
|
|
8
|
+
export default class OnchainAccountLendingPoolV2 extends OnchainAccountLendingPool {
|
|
9
|
+
protected readonly lendingPool: OnchainLendingPoolV2;
|
|
10
|
+
protected readonly collateral: OnchainAccountCollateralV2;
|
|
11
|
+
protected readonly borrowables: {
|
|
12
|
+
[Borrowable.A]: OnchainAccountBorrowableV2;
|
|
13
|
+
[Borrowable.B]: OnchainAccountBorrowableV2;
|
|
14
|
+
};
|
|
15
|
+
protected getNewCollateralObject(): OnchainAccountCollateralV2;
|
|
16
|
+
protected getNewBorrowableObject(borrowable: Borrowable): OnchainAccountBorrowableV2;
|
|
17
|
+
getLendingPool: () => OnchainLendingPoolV2;
|
|
18
|
+
getBorrowable: (borrowable: Borrowable) => OnchainAccountBorrowableV2;
|
|
19
|
+
getBorrowableA: () => OnchainAccountBorrowableV2;
|
|
20
|
+
getBorrowableB: () => OnchainAccountBorrowableV2;
|
|
21
|
+
getCollateral: () => OnchainAccountCollateralV2;
|
|
22
|
+
getInteractionsLendingPool(): OnchainInteractionsLendingPoolV2;
|
|
23
|
+
getLPEquity(): Promise<number>;
|
|
24
|
+
getValuesFromPrice(changes: Changes, priceA: number, priceB: number): Promise<{
|
|
25
|
+
valueCollateral: number;
|
|
26
|
+
valueA: number;
|
|
27
|
+
valueB: number;
|
|
28
|
+
}>;
|
|
29
|
+
getValues(changes: Changes): Promise<{
|
|
30
|
+
valueCollateral: number;
|
|
31
|
+
valueA: number;
|
|
32
|
+
valueB: number;
|
|
33
|
+
}>;
|
|
34
|
+
getMarketValues(changes: Changes): Promise<{
|
|
35
|
+
valueCollateral: number;
|
|
36
|
+
valueA: number;
|
|
37
|
+
valueB: number;
|
|
38
|
+
}>;
|
|
39
|
+
getLeverage(changes?: Changes): Promise<number>;
|
|
40
|
+
getLiquidationPrices(changes?: Changes): Promise<number[]>;
|
|
41
|
+
getMaxLeverage(): Promise<number>;
|
|
42
|
+
getMaxDeleverage(slippage: number): Promise<number>;
|
|
43
|
+
getAvailableReward(): Promise<PendingRewardUI[]>;
|
|
44
|
+
}
|