impermax-sdk 1.0.3 → 1.0.5
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/ImpermaxABI.d.ts +2 -0
- package/lib/abis/ImpermaxABI.js +3 -0
- package/lib/abis/contracts/ClaimAggregator.json +2015 -0
- package/lib/abis/contracts/IBorrowable.json +13207 -0
- package/lib/abis/contracts/IClaimable.json +406 -0
- package/lib/abis/contracts/ICollateral.json +8952 -0
- package/lib/abis/contracts/IERC20.json +2376 -0
- package/lib/abis/contracts/IFactory.json +3660 -0
- package/lib/abis/contracts/IFarmingPool.json +3584 -0
- package/lib/abis/contracts/IMerkleDistributor.json +1134 -0
- package/lib/abis/contracts/IRouter02.json +7283 -0
- package/lib/abis/contracts/ISimpleUniswapOracle.json +1469 -0
- package/lib/abis/contracts/IStakedLPToken.json +7309 -0
- package/lib/abis/contracts/IStakingRewards.json +1036 -0
- package/lib/abis/contracts/IUniswapV2Factory.json +1690 -0
- package/lib/abis/contracts/IUniswapV2Pair.json +6761 -0
- package/lib/abis/contracts/ImpermaxChef.json +20945 -0
- package/lib/config/amms.d.ts +44 -0
- package/lib/config/amms.js +216 -0
- package/lib/config/contracts/claim-aggregators.d.ts +2 -0
- package/lib/config/contracts/claim-aggregators.js +18 -0
- package/lib/config/contracts/impermax-chef.d.ts +2 -0
- package/lib/config/contracts/impermax-chef.js +18 -0
- package/lib/config/contracts/imxes.d.ts +2 -0
- package/lib/config/contracts/imxes.js +18 -0
- package/lib/config/contracts/merkle-distributors.d.ts +4 -0
- package/lib/config/contracts/merkle-distributors.js +13 -0
- package/lib/config/contracts/routers.d.ts +2 -0
- package/lib/config/contracts/routers.js +38 -0
- package/lib/config/contracts/simple-uniswap-oracles.d.ts +2 -0
- package/lib/config/contracts/simple-uniswap-oracles.js +35 -0
- package/lib/config/contracts/weths.d.ts +2 -0
- package/lib/config/contracts/weths.js +19 -0
- package/lib/config/debank-ids.d.ts +2 -0
- package/lib/config/debank-ids.js +17 -0
- package/lib/config/endpoints/merkle-distributors.d.ts +4 -0
- package/lib/config/endpoints/merkle-distributors.js +13 -0
- package/lib/config/eth.d.ts +3 -0
- package/lib/config/eth.js +32 -0
- package/lib/config/factories.d.ts +6 -0
- package/lib/config/factories.js +24 -0
- package/lib/config/farms.d.ts +59 -0
- package/lib/config/farms.js +114 -0
- package/lib/config/general.d.ts +5 -0
- package/lib/config/general.js +8 -0
- package/lib/config/subgraphs.d.ts +5 -0
- package/lib/config/subgraphs.js +68 -0
- package/lib/config/types.d.ts +49 -0
- package/lib/config/types.js +34 -0
- package/lib/impermax-router/Account.d.ts +31 -0
- package/lib/impermax-router/Account.js +154 -0
- package/lib/impermax-router/AccountBorrowable.d.ts +22 -0
- package/lib/impermax-router/AccountBorrowable.js +141 -0
- package/lib/impermax-router/AccountCollateral.d.ts +11 -0
- package/lib/impermax-router/AccountCollateral.js +63 -0
- package/lib/impermax-router/AccountLendingPool.d.ts +57 -0
- package/lib/impermax-router/AccountLendingPool.js +266 -0
- package/lib/impermax-router/AccountPoolToken.d.ts +29 -0
- package/lib/impermax-router/AccountPoolToken.js +89 -0
- package/lib/impermax-router/Borrowable.d.ts +27 -0
- package/lib/impermax-router/Borrowable.js +128 -0
- package/lib/impermax-router/Collateral.d.ts +9 -0
- package/lib/impermax-router/Collateral.js +45 -0
- package/lib/impermax-router/ContractsHelper.d.ts +28 -0
- package/lib/impermax-router/ContractsHelper.js +50 -0
- package/lib/impermax-router/ImpermaxFactory.d.ts +15 -0
- package/lib/impermax-router/ImpermaxFactory.js +42 -0
- package/lib/impermax-router/Interactions.d.ts +16 -0
- package/lib/impermax-router/Interactions.js +105 -0
- package/lib/impermax-router/InteractionsLendingPool.d.ts +43 -0
- package/lib/impermax-router/InteractionsLendingPool.js +124 -0
- package/lib/impermax-router/InteractionsPoolToken.d.ts +23 -0
- package/lib/impermax-router/InteractionsPoolToken.js +194 -0
- package/lib/impermax-router/LendingPool.d.ts +69 -0
- package/lib/impermax-router/LendingPool.js +291 -0
- package/lib/impermax-router/PoolToken.d.ts +36 -0
- package/lib/impermax-router/PoolToken.js +140 -0
- package/lib/impermax-router/index.d.ts +20 -0
- package/lib/impermax-router/index.js +34 -0
- package/lib/impermax-router/types.d.ts +45 -0
- package/lib/impermax-router/types.js +14 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.js +114 -0
- package/lib/subgraph/Account.d.ts +18 -0
- package/lib/subgraph/Account.js +111 -0
- package/lib/subgraph/AccountLendingPool.d.ts +19 -0
- package/lib/subgraph/AccountLendingPool.js +71 -0
- package/lib/subgraph/AccountPoolToken.d.ts +14 -0
- package/lib/subgraph/AccountPoolToken.js +75 -0
- package/lib/subgraph/LendingPool.d.ts +39 -0
- package/lib/subgraph/LendingPool.js +204 -0
- package/lib/subgraph/PoolToken.d.ts +64 -0
- package/lib/subgraph/PoolToken.js +462 -0
- package/lib/subgraph/PriceHelper.d.ts +21 -0
- package/lib/subgraph/PriceHelper.js +166 -0
- package/lib/subgraph/SolidexHelper.d.ts +16 -0
- package/lib/subgraph/SolidexHelper.js +58 -0
- package/lib/subgraph/index.d.ts +73 -0
- package/lib/subgraph/index.js +185 -0
- package/lib/subgraph/initializer.d.ts +35 -0
- package/lib/subgraph/initializer.js +517 -0
- package/lib/subgraph/query.d.ts +10 -0
- package/lib/subgraph/query.js +229 -0
- package/lib/subgraph/types.d.ts +145 -0
- package/lib/subgraph/types.js +3 -0
- package/lib/utils/ether-utils.d.ts +5 -0
- package/lib/utils/ether-utils.js +26 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +16 -0
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
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("./types");
|
|
16
|
+
const AccountPoolToken_1 = __importDefault(require("./AccountPoolToken"));
|
|
17
|
+
class AccountCollateral extends AccountPoolToken_1.default {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.collateralCache = {};
|
|
21
|
+
}
|
|
22
|
+
cleanCache() {
|
|
23
|
+
super.cleanCache();
|
|
24
|
+
this.collateralCache = {};
|
|
25
|
+
}
|
|
26
|
+
fixStakedLPExchangeRate(n) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const stakedLPExchangeRate = yield this.poolToken.lendingPool.getStakedLPExchangeRate();
|
|
29
|
+
return (yield n) / stakedLPExchangeRate;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getAvailableBalanceUSD() {
|
|
33
|
+
const _super = Object.create(null, {
|
|
34
|
+
getAvailableBalanceUSD: { get: () => super.getAvailableBalanceUSD }
|
|
35
|
+
});
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return this.fixStakedLPExchangeRate(_super.getAvailableBalanceUSD.call(this));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getDepositedUSD() {
|
|
41
|
+
const _super = Object.create(null, {
|
|
42
|
+
getDepositedUSD: { get: () => super.getDepositedUSD }
|
|
43
|
+
});
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return this.fixStakedLPExchangeRate(_super.getDepositedUSD.call(this));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Max Withdrawable
|
|
49
|
+
getMaxWithdrawable() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const deposited = yield this.getDeposited();
|
|
52
|
+
const availableCash = yield this.poolToken.getTotalBalance();
|
|
53
|
+
const { valueCollateral, valueA, valueB } = yield this.accountLendingPool.getValues(types_1.NO_CHANGES);
|
|
54
|
+
const safetyMargin = (yield this.accountLendingPool.getSafetyMargin()) * this.getUiMargin();
|
|
55
|
+
const liquidationPenalty = yield this.accountLendingPool.getLiquidationPenalty();
|
|
56
|
+
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
57
|
+
const maxWithdrawable1 = (actualCollateral - (valueA + valueB * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty;
|
|
58
|
+
const maxWithdrawable2 = (actualCollateral - (valueB + valueA * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty;
|
|
59
|
+
return Math.max(0, Math.min(deposited, availableCash, maxWithdrawable1, maxWithdrawable2) / this.getDust());
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = AccountCollateral;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Changes, PendingRewardUI, Values } from "./types";
|
|
2
|
+
import Account from "./Account";
|
|
3
|
+
import AccountBorrowable from "./AccountBorrowable";
|
|
4
|
+
import AccountCollateral from "./AccountCollateral";
|
|
5
|
+
import LendingPool from "./LendingPool";
|
|
6
|
+
import { PoolTokenType } from '../config/types';
|
|
7
|
+
export default class AccountLendingPool {
|
|
8
|
+
account: Account;
|
|
9
|
+
lendingPool: LendingPool;
|
|
10
|
+
accountPoolTokens: {
|
|
11
|
+
[PoolTokenType.Collateral]: AccountCollateral;
|
|
12
|
+
[PoolTokenType.BorrowableA]: AccountBorrowable;
|
|
13
|
+
[PoolTokenType.BorrowableB]: AccountBorrowable;
|
|
14
|
+
};
|
|
15
|
+
cache: {
|
|
16
|
+
availableReward?: Promise<PendingRewardUI[]>;
|
|
17
|
+
oldAvailableReward?: Promise<number>;
|
|
18
|
+
};
|
|
19
|
+
constructor(account: Account, lendingPool: LendingPool);
|
|
20
|
+
cleanCache(): void;
|
|
21
|
+
pta: () => AccountBorrowable;
|
|
22
|
+
ptb: () => AccountBorrowable;
|
|
23
|
+
ptc: () => AccountCollateral;
|
|
24
|
+
getSafetyMargin: () => Promise<number>;
|
|
25
|
+
getLiquidationPenalty: () => Promise<number>;
|
|
26
|
+
getUiMargin: () => number;
|
|
27
|
+
getBalanceUSD(): Promise<number>;
|
|
28
|
+
getSuppliedUSD(): Promise<number>;
|
|
29
|
+
getDebtUSD(): Promise<number>;
|
|
30
|
+
getEquityUSD(): Promise<number>;
|
|
31
|
+
getLPEquityUSD(): Promise<number>;
|
|
32
|
+
getLPEquity(): Promise<number>;
|
|
33
|
+
getAccountAPR(): Promise<number>;
|
|
34
|
+
getValuesFromPrice(changes: Changes, priceA: number, priceB: number): Promise<{
|
|
35
|
+
valueCollateral: number;
|
|
36
|
+
valueA: number;
|
|
37
|
+
valueB: number;
|
|
38
|
+
}>;
|
|
39
|
+
getValues(changes: Changes): Promise<{
|
|
40
|
+
valueCollateral: number;
|
|
41
|
+
valueA: number;
|
|
42
|
+
valueB: number;
|
|
43
|
+
}>;
|
|
44
|
+
getMarketValues(changes: Changes): Promise<{
|
|
45
|
+
valueCollateral: number;
|
|
46
|
+
valueA: number;
|
|
47
|
+
valueB: number;
|
|
48
|
+
}>;
|
|
49
|
+
getLeverage(changes?: Changes): Promise<number>;
|
|
50
|
+
getLiquidationPriceSwingsGivenValues(values: Values): Promise<[number, number]>;
|
|
51
|
+
getLiquidationPricesGivenValues(values: Values): Promise<[number, number]>;
|
|
52
|
+
getLiquidationPriceSwings(changes?: Changes): Promise<[number, number]>;
|
|
53
|
+
getLiquidationPrices(changes?: Changes): Promise<[number, number]>;
|
|
54
|
+
getMaxLeverage(): Promise<number>;
|
|
55
|
+
getMaxDeleverage(slippage: number): Promise<number>;
|
|
56
|
+
getAvailableReward(): Promise<PendingRewardUI[]>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
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("./types");
|
|
16
|
+
const AccountBorrowable_1 = __importDefault(require("./AccountBorrowable"));
|
|
17
|
+
const AccountCollateral_1 = __importDefault(require("./AccountCollateral"));
|
|
18
|
+
const types_2 = require("../config/types");
|
|
19
|
+
class AccountLendingPool {
|
|
20
|
+
constructor(account, lendingPool) {
|
|
21
|
+
this.cache = {};
|
|
22
|
+
// Shortcuts
|
|
23
|
+
this.pta = () => this.accountPoolTokens[types_2.PoolTokenType.BorrowableA];
|
|
24
|
+
this.ptb = () => this.accountPoolTokens[types_2.PoolTokenType.BorrowableB];
|
|
25
|
+
this.ptc = () => this.accountPoolTokens[types_2.PoolTokenType.Collateral];
|
|
26
|
+
this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getSubgraphLendingPool()).getSafetyMargin(); });
|
|
27
|
+
this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getSubgraphLendingPool()).getLiquidationPenalty(); });
|
|
28
|
+
this.getUiMargin = () => this.account.router.uiMargin;
|
|
29
|
+
this.account = account;
|
|
30
|
+
this.lendingPool = lendingPool;
|
|
31
|
+
this.accountPoolTokens = {
|
|
32
|
+
[types_2.PoolTokenType.Collateral]: new AccountCollateral_1.default(this, types_2.PoolTokenType.Collateral),
|
|
33
|
+
[types_2.PoolTokenType.BorrowableA]: new AccountBorrowable_1.default(this, types_2.PoolTokenType.BorrowableA),
|
|
34
|
+
[types_2.PoolTokenType.BorrowableB]: new AccountBorrowable_1.default(this, types_2.PoolTokenType.BorrowableB),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
cleanCache() {
|
|
38
|
+
this.cache = {};
|
|
39
|
+
this.pta().cleanCache();
|
|
40
|
+
this.ptb().cleanCache();
|
|
41
|
+
this.ptc().cleanCache();
|
|
42
|
+
}
|
|
43
|
+
// Balance
|
|
44
|
+
getBalanceUSD() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const depositedAUSD = yield this.pta().getDepositedUSD();
|
|
47
|
+
const depositedBUSD = yield this.ptb().getDepositedUSD();
|
|
48
|
+
const depositedCUSD = yield this.ptc().getDepositedUSD();
|
|
49
|
+
return depositedAUSD + depositedBUSD + depositedCUSD;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// Supplied
|
|
53
|
+
getSuppliedUSD() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const depositedAUSD = yield this.pta().getDepositedUSD();
|
|
56
|
+
const depositedBUSD = yield this.ptb().getDepositedUSD();
|
|
57
|
+
return depositedAUSD + depositedBUSD;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Debt
|
|
61
|
+
getDebtUSD() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const borrowedAUSD = yield this.pta().getBorrowedUSD();
|
|
64
|
+
const borrowedBUSD = yield this.ptb().getBorrowedUSD();
|
|
65
|
+
return borrowedAUSD + borrowedBUSD;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Equity
|
|
69
|
+
getEquityUSD() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const balanceUSD = yield this.getBalanceUSD();
|
|
72
|
+
const debtUSD = yield this.getDebtUSD();
|
|
73
|
+
return balanceUSD - debtUSD;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getLPEquityUSD() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const collateralUSD = yield this.ptc().getDepositedUSD();
|
|
79
|
+
const debtUSD = yield this.getDebtUSD();
|
|
80
|
+
return collateralUSD - debtUSD;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getLPEquity() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const lpEquityUSD = yield this.getLPEquityUSD();
|
|
86
|
+
const tokenPrice = yield this.ptc().getTokenPriceAccurate();
|
|
87
|
+
const stakedLPExchangeRate = yield this.lendingPool.getStakedLPExchangeRate();
|
|
88
|
+
return lpEquityUSD / tokenPrice * stakedLPExchangeRate;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Debt
|
|
92
|
+
getAccountAPR() {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const depositedAUSD = yield this.pta().getDepositedUSD();
|
|
95
|
+
const depositedBUSD = yield this.ptb().getDepositedUSD();
|
|
96
|
+
const totalSupplied = depositedAUSD + depositedBUSD;
|
|
97
|
+
const supplyAPRA = yield this.pta().getSupplyAPR();
|
|
98
|
+
const supplyAPRB = yield this.ptb().getSupplyAPR();
|
|
99
|
+
return totalSupplied > 0 ? (depositedAUSD * supplyAPRA + depositedBUSD * supplyAPRB) / totalSupplied : 0;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Values
|
|
103
|
+
getValuesFromPrice(changes, priceA, priceB) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const valueCollateral = (yield this.ptc().getDeposited()) + changes.changeCollateral;
|
|
106
|
+
const amountA = (yield this.pta().getBorrowed()) + changes.changeBorrowedA;
|
|
107
|
+
const amountB = (yield this.ptb().getBorrowed()) + changes.changeBorrowedB;
|
|
108
|
+
const valueA = amountA * priceA;
|
|
109
|
+
const valueB = amountB * priceB;
|
|
110
|
+
return {
|
|
111
|
+
valueCollateral: valueCollateral > 0 ? valueCollateral : 0,
|
|
112
|
+
valueA: valueA > 0 ? valueA : 0,
|
|
113
|
+
valueB: valueB > 0 ? valueB : 0,
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getValues(changes) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
|
|
120
|
+
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
getMarketValues(changes) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
126
|
+
return this.getValuesFromPrice(changes, priceA, priceB);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Leverage
|
|
130
|
+
getLeverage(changes) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (!changes)
|
|
133
|
+
changes = types_1.NO_CHANGES;
|
|
134
|
+
const { valueCollateral, valueA, valueB } = yield this.getValues(changes);
|
|
135
|
+
const valueDebt = valueA + valueB;
|
|
136
|
+
if (valueDebt == 0)
|
|
137
|
+
return 1;
|
|
138
|
+
const equity = valueCollateral - valueDebt;
|
|
139
|
+
if (equity <= 0)
|
|
140
|
+
return Infinity;
|
|
141
|
+
return valueDebt / equity + 1;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// Liquidation Threshold
|
|
145
|
+
getLiquidationPriceSwingsGivenValues(values) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
if (!values)
|
|
148
|
+
return [Infinity, Infinity];
|
|
149
|
+
const { valueCollateral, valueA, valueB } = values;
|
|
150
|
+
if (valueA + valueB == 0)
|
|
151
|
+
return [Infinity, Infinity];
|
|
152
|
+
const safetyMargin = yield this.getSafetyMargin();
|
|
153
|
+
const liquidationPenalty = yield this.getLiquidationPenalty();
|
|
154
|
+
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
155
|
+
const rad = Math.sqrt(Math.pow(actualCollateral, 2) - 4 * valueA * valueB);
|
|
156
|
+
if (!rad)
|
|
157
|
+
return [0, 0];
|
|
158
|
+
const t = (actualCollateral + rad) / (2 * Math.sqrt(safetyMargin));
|
|
159
|
+
let priceSwingA = Math.pow((t / valueA), 2);
|
|
160
|
+
let priceSwingB = Math.pow((t / valueB), 2);
|
|
161
|
+
return [priceSwingA, priceSwingB];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
getLiquidationPricesGivenValues(values) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const currentPrice = yield this.lendingPool.getTWAPPrice();
|
|
167
|
+
const [priceSwingA, priceSwingB] = yield this.getLiquidationPriceSwingsGivenValues(values);
|
|
168
|
+
return !this.account.router.priceInverted ? [currentPrice / priceSwingB, currentPrice * priceSwingA] : [currentPrice / priceSwingA, currentPrice * priceSwingB];
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
getLiquidationPriceSwings(changes) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const values = yield this.getValues(changes);
|
|
174
|
+
return this.getLiquidationPriceSwingsGivenValues(values);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
getLiquidationPrices(changes) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
if (!changes)
|
|
180
|
+
changes = types_1.NO_CHANGES;
|
|
181
|
+
const values = yield this.getValues(changes);
|
|
182
|
+
return this.getLiquidationPricesGivenValues(values);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Max Leverage
|
|
186
|
+
getMaxLeverage() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const availableCashA = yield this.pta().poolToken.getTotalBalance();
|
|
189
|
+
const availableCashB = yield this.ptb().poolToken.getTotalBalance();
|
|
190
|
+
const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
|
|
191
|
+
const [priceATWAP,] = yield this.lendingPool.getPriceDenomLP();
|
|
192
|
+
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
193
|
+
const adjustFactor = 1 / diff;
|
|
194
|
+
const availableCashValue1 = availableCashA * priceA;
|
|
195
|
+
const availableCashValue2 = availableCashB * priceB;
|
|
196
|
+
const { valueCollateral, valueA, valueB } = yield this.getValues(types_1.NO_CHANGES);
|
|
197
|
+
const safetyMargin = (yield this.getSafetyMargin()) * this.getUiMargin();
|
|
198
|
+
const liquidationPenalty = yield this.getLiquidationPenalty();
|
|
199
|
+
const actualCollateral = valueCollateral / liquidationPenalty;
|
|
200
|
+
const num1 = actualCollateral * Math.sqrt(safetyMargin) - valueA * safetyMargin - valueB;
|
|
201
|
+
const num2 = actualCollateral * Math.sqrt(safetyMargin) - valueB * safetyMargin - valueA;
|
|
202
|
+
const den = safetyMargin + 1 - 2 * Math.sqrt(safetyMargin) / liquidationPenalty;
|
|
203
|
+
const additionalValueBorrowablePerSide = Math.min(num1 / den, num2 / den, availableCashValue1, availableCashValue2) * adjustFactor;
|
|
204
|
+
const valueDebt = valueA + valueB;
|
|
205
|
+
const equity = valueCollateral - valueDebt;
|
|
206
|
+
if (equity == 0)
|
|
207
|
+
return 1;
|
|
208
|
+
return (valueDebt + additionalValueBorrowablePerSide * 2) / equity + 1;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// Max Deleverage
|
|
212
|
+
getMaxDeleverage(slippage) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
const { valueCollateral, valueA, valueB } = yield this.getMarketValues(types_1.NO_CHANGES);
|
|
215
|
+
const minRepayPerSide = valueCollateral / 2 / Math.sqrt(slippage);
|
|
216
|
+
if (minRepayPerSide >= valueA && minRepayPerSide >= valueB) {
|
|
217
|
+
return this.ptc().getDeposited();
|
|
218
|
+
}
|
|
219
|
+
if (minRepayPerSide * 2 < valueA + valueB) {
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
return Math.min(valueA, valueB) * 2 * Math.sqrt(slippage);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Available Reward
|
|
226
|
+
getAvailableReward() {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
const result = [];
|
|
229
|
+
const imxAmount = (yield this.pta().getAvailableIMXReward()) + (yield this.ptb().getAvailableIMXReward());
|
|
230
|
+
if (imxAmount > 0)
|
|
231
|
+
result.push({
|
|
232
|
+
symbol: "IMX",
|
|
233
|
+
amount: imxAmount
|
|
234
|
+
});
|
|
235
|
+
const symbols = [
|
|
236
|
+
yield this.pta().poolToken.getRewarderTokenSymbol(),
|
|
237
|
+
yield this.ptb().poolToken.getRewarderTokenSymbol()
|
|
238
|
+
];
|
|
239
|
+
const rewarderAmounts = [
|
|
240
|
+
yield this.pta().getAvailableRewarderReward(),
|
|
241
|
+
yield this.ptb().getAvailableRewarderReward()
|
|
242
|
+
];
|
|
243
|
+
if (symbols[0] === symbols[1]) {
|
|
244
|
+
const rewarderAmount = rewarderAmounts[0] + rewarderAmounts[1];
|
|
245
|
+
if (rewarderAmount === 0)
|
|
246
|
+
return result;
|
|
247
|
+
result.push({
|
|
248
|
+
symbol: symbols[0],
|
|
249
|
+
amount: rewarderAmount
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
for (let i = 0; i < 2; i++) {
|
|
254
|
+
if (rewarderAmounts[i] === 0)
|
|
255
|
+
continue;
|
|
256
|
+
result.push({
|
|
257
|
+
symbol: symbols[i],
|
|
258
|
+
amount: rewarderAmounts[i]
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.default = AccountLendingPool;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import AccountLendingPool from "./AccountLendingPool";
|
|
2
|
+
import PoolToken from "./PoolToken";
|
|
3
|
+
import { PoolTokenType } from '../config/types';
|
|
4
|
+
export default class AccountPoolToken {
|
|
5
|
+
accountLendingPool: AccountLendingPool;
|
|
6
|
+
poolToken: PoolToken;
|
|
7
|
+
cache: {
|
|
8
|
+
availableBalance?: Promise<number>;
|
|
9
|
+
deposited?: Promise<number>;
|
|
10
|
+
};
|
|
11
|
+
constructor(accountLendingPool: AccountLendingPool, poolTokenType: PoolTokenType);
|
|
12
|
+
cleanCache(): void;
|
|
13
|
+
getAccount: () => string;
|
|
14
|
+
getNetwrok: () => import("../config/types").Networks;
|
|
15
|
+
getEth: () => any;
|
|
16
|
+
getDust: () => number;
|
|
17
|
+
getUiMargin: () => number;
|
|
18
|
+
getTokenPriceAccurate: () => Promise<number>;
|
|
19
|
+
getSupplyAPR: () => Promise<number>;
|
|
20
|
+
getBorrowRate: () => Promise<number>;
|
|
21
|
+
getAccrualTimestamp: () => Promise<number>;
|
|
22
|
+
private initializeAvailableBalance;
|
|
23
|
+
getAvailableBalance(): Promise<number>;
|
|
24
|
+
getAvailableBalanceUSD(): Promise<number>;
|
|
25
|
+
private initializeDeposited;
|
|
26
|
+
getDeposited(): Promise<number>;
|
|
27
|
+
getDepositedUSD(): Promise<number>;
|
|
28
|
+
getMaxWithdrawable(): Promise<number>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const weths_1 = require("../config/contracts/weths");
|
|
13
|
+
class AccountPoolToken {
|
|
14
|
+
constructor(accountLendingPool, poolTokenType) {
|
|
15
|
+
this.cache = {};
|
|
16
|
+
// Shortcuts
|
|
17
|
+
this.getAccount = () => this.accountLendingPool.account.account;
|
|
18
|
+
this.getNetwrok = () => this.accountLendingPool.account.router.network;
|
|
19
|
+
this.getEth = () => this.accountLendingPool.account.router.web3.eth;
|
|
20
|
+
this.getDust = () => this.accountLendingPool.account.router.dust;
|
|
21
|
+
this.getUiMargin = () => this.accountLendingPool.account.router.uiMargin;
|
|
22
|
+
this.getTokenPriceAccurate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getTokenPriceAccurate(); });
|
|
23
|
+
this.getSupplyAPR = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getSupplyAPR(); });
|
|
24
|
+
this.getBorrowRate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getBorrowRate(); });
|
|
25
|
+
this.getAccrualTimestamp = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getAccrualTimestamp(); });
|
|
26
|
+
this.accountLendingPool = accountLendingPool;
|
|
27
|
+
this.poolToken = accountLendingPool.lendingPool.poolTokens[poolTokenType];
|
|
28
|
+
}
|
|
29
|
+
cleanCache() {
|
|
30
|
+
this.cache = {};
|
|
31
|
+
}
|
|
32
|
+
// Available Balance
|
|
33
|
+
initializeAvailableBalance() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const token = yield this.poolToken.getToken();
|
|
36
|
+
if (token._address.toLowerCase() == weths_1.WETH[this.getNetwrok()].toLowerCase()) {
|
|
37
|
+
return (yield this.getEth().getBalance(this.getAccount())) / 1e18 / this.getDust();
|
|
38
|
+
}
|
|
39
|
+
const balance = yield token.methods.balanceOf(this.getAccount()).call();
|
|
40
|
+
return (yield this.poolToken.normalize(balance)) / this.getDust();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getAvailableBalance() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!this.cache.availableBalance)
|
|
46
|
+
this.cache.availableBalance = this.initializeAvailableBalance();
|
|
47
|
+
return this.cache.availableBalance;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getAvailableBalanceUSD() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const availableBalance = yield this.getAvailableBalance();
|
|
53
|
+
const tokenPrice = yield this.getTokenPriceAccurate();
|
|
54
|
+
return availableBalance * tokenPrice;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Deposited
|
|
58
|
+
initializeDeposited() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const poolToken = yield this.poolToken.getPoolToken();
|
|
61
|
+
const exchangeRate = yield this.poolToken.getExchangeRate();
|
|
62
|
+
const balance = yield poolToken.methods.balanceOf(this.getAccount()).call();
|
|
63
|
+
return (yield this.poolToken.normalize(balance)) * exchangeRate;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getDeposited() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (!this.cache.deposited)
|
|
69
|
+
this.cache.deposited = this.initializeDeposited();
|
|
70
|
+
return this.cache.deposited;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
getDepositedUSD() {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const deposited = yield this.getDeposited();
|
|
76
|
+
const tokenPrice = yield this.getTokenPriceAccurate();
|
|
77
|
+
return deposited * tokenPrice;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Max Withdrawable
|
|
81
|
+
getMaxWithdrawable() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const deposited = yield this.getDeposited();
|
|
84
|
+
const availableCash = yield this.poolToken.getTotalBalance();
|
|
85
|
+
return Math.min(deposited, availableCash) / this.getDust();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.default = AccountPoolToken;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Contract } from "./types";
|
|
2
|
+
import PoolToken from "./PoolToken";
|
|
3
|
+
import { Address } from '../config/types';
|
|
4
|
+
export default class Borrowable extends PoolToken {
|
|
5
|
+
borrowableCache: {
|
|
6
|
+
borrowTracker?: Promise<Address>;
|
|
7
|
+
rewarder?: Promise<Contract>;
|
|
8
|
+
rewarderTokenSymbol?: Promise<string>;
|
|
9
|
+
rewardSpeed?: Promise<number>;
|
|
10
|
+
};
|
|
11
|
+
cleanCache(): void;
|
|
12
|
+
initializePoolToken(): Promise<Contract>;
|
|
13
|
+
initializeToken(): Promise<Contract>;
|
|
14
|
+
getPriceDenomLP(): Promise<number>;
|
|
15
|
+
getMarketPriceDenomLP(): Promise<number>;
|
|
16
|
+
private initializeBorrowTracker;
|
|
17
|
+
getBorrowTracker(): Promise<string>;
|
|
18
|
+
hasFarming(): Promise<boolean>;
|
|
19
|
+
hasImpermaxChef(): Promise<boolean>;
|
|
20
|
+
getFarmingPool(): Promise<Contract>;
|
|
21
|
+
getImpermaxChef: () => any;
|
|
22
|
+
private initializeRewarder;
|
|
23
|
+
getRewarder(): Promise<any>;
|
|
24
|
+
hasRewarder(): Promise<boolean>;
|
|
25
|
+
private initializeRewarderTokenSymbol;
|
|
26
|
+
getRewarderTokenSymbol(): Promise<string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 PoolToken_1 = __importDefault(require("./PoolToken"));
|
|
16
|
+
const types_1 = require("../config/types");
|
|
17
|
+
class Borrowable extends PoolToken_1.default {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.borrowableCache = {};
|
|
21
|
+
this.getImpermaxChef = () => this.getContractHelper().impermaxChef;
|
|
22
|
+
}
|
|
23
|
+
cleanCache() {
|
|
24
|
+
super.cleanCache();
|
|
25
|
+
this.borrowableCache = {};
|
|
26
|
+
}
|
|
27
|
+
initializePoolToken() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this.getContractHelper().newBorrowable(yield this.getPoolTokenAddressFromLendingPool());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
initializeToken() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const poolToken = yield this.getPoolToken();
|
|
35
|
+
return this.getContractHelper().newERC20(yield poolToken.methods.underlying().call());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Price Denom LP
|
|
39
|
+
getPriceDenomLP() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const prices = yield this.lendingPool.getPriceDenomLP();
|
|
42
|
+
return prices[this.poolTokenType === types_1.PoolTokenType.BorrowableA ? 0 : 1];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getMarketPriceDenomLP() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const prices = yield this.lendingPool.getMarketPriceDenomLP();
|
|
48
|
+
return prices[this.poolTokenType === types_1.PoolTokenType.BorrowableA ? 0 : 1];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Farming Pool
|
|
52
|
+
initializeBorrowTracker() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const borrowable = yield this.getPoolToken();
|
|
55
|
+
return borrowable.methods.borrowTracker().call();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
getBorrowTracker() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!this.borrowableCache.borrowTracker)
|
|
61
|
+
this.borrowableCache.borrowTracker = this.initializeBorrowTracker();
|
|
62
|
+
return this.borrowableCache.borrowTracker;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
hasFarming() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const borrowTracker = yield this.getBorrowTracker();
|
|
68
|
+
return borrowTracker !== '0x0000000000000000000000000000000000000000';
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
hasImpermaxChef() {
|
|
72
|
+
var _a;
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const borrowTracker = yield this.getBorrowTracker();
|
|
75
|
+
return borrowTracker.toLowerCase() === ((_a = this.getImpermaxChef()._address) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getFarmingPool() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (!(yield this.hasFarming()) || (yield this.hasImpermaxChef()))
|
|
81
|
+
return null;
|
|
82
|
+
return this.getContractHelper().newFarmingPool(yield this.getBorrowTracker());
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
initializeRewarder() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const poolTokenAddress = yield this.getPoolTokenAddress();
|
|
88
|
+
try {
|
|
89
|
+
const { rewarder } = yield this.getImpermaxChef().methods.poolInfo(poolTokenAddress).call();
|
|
90
|
+
if (rewarder == "0x0000000000000000000000000000000000000000")
|
|
91
|
+
return null;
|
|
92
|
+
return this.getContractHelper().newImpermaxChef(rewarder);
|
|
93
|
+
}
|
|
94
|
+
catch (_a) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getRewarder() {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
if (!this.borrowableCache.rewarder)
|
|
102
|
+
this.borrowableCache.rewarder = this.initializeRewarder();
|
|
103
|
+
return this.borrowableCache.rewarder;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
hasRewarder() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return (yield this.getRewarder()) !== null;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
initializeRewarderTokenSymbol() {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (!(yield this.hasRewarder()))
|
|
114
|
+
return "";
|
|
115
|
+
const rewarder = yield this.getRewarder();
|
|
116
|
+
const rewardTokenAddress = yield rewarder.methods.rewardToken().call();
|
|
117
|
+
return this.getContractHelper().newERC20(rewardTokenAddress).methods.symbol().call();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
getRewarderTokenSymbol() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (!this.borrowableCache.rewarderTokenSymbol)
|
|
123
|
+
this.borrowableCache.rewarderTokenSymbol = this.initializeRewarderTokenSymbol();
|
|
124
|
+
return this.borrowableCache.rewarderTokenSymbol;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.default = Borrowable;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Contract } from "./types";
|
|
2
|
+
import PoolToken from "./PoolToken";
|
|
3
|
+
export default class Collateral extends PoolToken {
|
|
4
|
+
collateralCache: {};
|
|
5
|
+
cleanCache(): void;
|
|
6
|
+
initializePoolToken(): Promise<Contract>;
|
|
7
|
+
initializeToken(): Promise<Contract>;
|
|
8
|
+
protected initializeExchangeRate(): Promise<number>;
|
|
9
|
+
}
|