impermax-sdk 1.0.1 → 1.0.2
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/esm/abis/ImpermaxABI.d.ts +2 -0
- package/lib/esm/abis/ImpermaxABI.js +3 -0
- package/lib/esm/abis/contracts/ClaimAggregator.json +2015 -0
- package/lib/esm/abis/contracts/IBorrowable.json +13207 -0
- package/lib/esm/abis/contracts/IClaimable.json +406 -0
- package/lib/esm/abis/contracts/ICollateral.json +8952 -0
- package/lib/esm/abis/contracts/IERC20.json +2376 -0
- package/lib/esm/abis/contracts/IFactory.json +3660 -0
- package/lib/esm/abis/contracts/IFarmingPool.json +3584 -0
- package/lib/esm/abis/contracts/IMerkleDistributor.json +1134 -0
- package/lib/esm/abis/contracts/IRouter02.json +7283 -0
- package/lib/esm/abis/contracts/ISimpleUniswapOracle.json +1469 -0
- package/lib/esm/abis/contracts/IStakedLPToken.json +7309 -0
- package/lib/esm/abis/contracts/IStakingRewards.json +1036 -0
- package/lib/esm/abis/contracts/IUniswapV2Factory.json +1690 -0
- package/lib/esm/abis/contracts/IUniswapV2Pair.json +6761 -0
- package/lib/esm/abis/contracts/ImpermaxChef.json +20945 -0
- package/lib/esm/config/amms.d.ts +25 -0
- package/lib/esm/config/amms.js +196 -0
- package/lib/esm/config/contracts/claim-aggregators.d.ts +2 -0
- package/lib/esm/config/contracts/claim-aggregators.js +18 -0
- package/lib/esm/config/contracts/impermax-chef.d.ts +2 -0
- package/lib/esm/config/contracts/impermax-chef.js +18 -0
- package/lib/esm/config/contracts/imxes.d.ts +2 -0
- package/lib/esm/config/contracts/imxes.js +18 -0
- package/lib/esm/config/contracts/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/contracts/merkle-distributors.js +13 -0
- package/lib/esm/config/contracts/routers.d.ts +2 -0
- package/lib/esm/config/contracts/routers.js +38 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.d.ts +2 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.js +35 -0
- package/lib/esm/config/contracts/weths.d.ts +2 -0
- package/lib/esm/config/contracts/weths.js +19 -0
- package/lib/esm/config/debank-ids.d.ts +2 -0
- package/lib/esm/config/debank-ids.js +17 -0
- package/lib/esm/config/endpoints/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/endpoints/merkle-distributors.js +13 -0
- package/lib/esm/config/eth.d.ts +3 -0
- package/lib/esm/config/eth.js +32 -0
- package/lib/esm/config/factories.d.ts +6 -0
- package/lib/esm/config/factories.js +24 -0
- package/lib/esm/config/farms.d.ts +59 -0
- package/lib/esm/config/farms.js +114 -0
- package/lib/esm/config/general.d.ts +3 -0
- package/lib/esm/config/general.js +8 -0
- package/lib/esm/config/subgraphs.d.ts +5 -0
- package/lib/esm/config/subgraphs.js +68 -0
- package/lib/esm/config/types.d.ts +67 -0
- package/lib/esm/config/types.js +54 -0
- package/lib/esm/impermax-router/Account.d.ts +31 -0
- package/lib/esm/impermax-router/Account.js +154 -0
- package/lib/esm/impermax-router/AccountBorrowable.d.ts +22 -0
- package/lib/esm/impermax-router/AccountBorrowable.js +141 -0
- package/lib/esm/impermax-router/AccountCollateral.d.ts +11 -0
- package/lib/esm/impermax-router/AccountCollateral.js +63 -0
- package/lib/esm/impermax-router/AccountLendingPool.d.ts +57 -0
- package/lib/esm/impermax-router/AccountLendingPool.js +266 -0
- package/lib/esm/impermax-router/AccountPoolToken.d.ts +29 -0
- package/lib/esm/impermax-router/AccountPoolToken.js +89 -0
- package/lib/esm/impermax-router/Borrowable.d.ts +27 -0
- package/lib/esm/impermax-router/Borrowable.js +128 -0
- package/lib/esm/impermax-router/Collateral.d.ts +9 -0
- package/lib/esm/impermax-router/Collateral.js +45 -0
- package/lib/esm/impermax-router/ContractsHelper.d.ts +28 -0
- package/lib/esm/impermax-router/ContractsHelper.js +50 -0
- package/lib/esm/impermax-router/ImpermaxFactory.d.ts +15 -0
- package/lib/esm/impermax-router/ImpermaxFactory.js +42 -0
- package/lib/esm/impermax-router/Interactions.d.ts +16 -0
- package/lib/esm/impermax-router/Interactions.js +105 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.d.ts +43 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.js +124 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.d.ts +23 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.js +194 -0
- package/lib/esm/impermax-router/LendingPool.d.ts +69 -0
- package/lib/esm/impermax-router/LendingPool.js +291 -0
- package/lib/esm/impermax-router/PoolToken.d.ts +36 -0
- package/lib/esm/impermax-router/PoolToken.js +140 -0
- package/lib/esm/impermax-router/index.d.ts +20 -0
- package/lib/esm/impermax-router/index.js +34 -0
- package/lib/esm/impermax-router/interfaces.d.ts +218 -0
- package/lib/esm/impermax-router/interfaces.js +15 -0
- package/{index.ts → lib/esm/index.d.ts} +1 -3
- package/lib/esm/index.js +10 -0
- package/lib/esm/subgraph/Account.d.ts +18 -0
- package/lib/esm/subgraph/Account.js +111 -0
- package/lib/esm/subgraph/AccountLendingPool.d.ts +19 -0
- package/lib/esm/subgraph/AccountLendingPool.js +71 -0
- package/lib/esm/subgraph/AccountPoolToken.d.ts +14 -0
- package/lib/esm/subgraph/AccountPoolToken.js +75 -0
- package/lib/esm/subgraph/LendingPool.d.ts +38 -0
- package/lib/esm/subgraph/LendingPool.js +204 -0
- package/lib/esm/subgraph/PoolToken.d.ts +64 -0
- package/lib/esm/subgraph/PoolToken.js +462 -0
- package/lib/esm/subgraph/PriceHelper.d.ts +21 -0
- package/lib/esm/subgraph/PriceHelper.js +166 -0
- package/lib/esm/subgraph/SolidexHelper.d.ts +16 -0
- package/lib/esm/subgraph/SolidexHelper.js +58 -0
- package/lib/esm/subgraph/index.d.ts +73 -0
- package/lib/esm/subgraph/index.js +185 -0
- package/lib/esm/subgraph/initializer.d.ts +34 -0
- package/lib/esm/subgraph/initializer.js +517 -0
- package/lib/esm/subgraph/query.d.ts +10 -0
- package/lib/esm/subgraph/query.js +229 -0
- package/lib/esm/utils/ether-utils.d.ts +5 -0
- package/lib/esm/utils/ether-utils.js +26 -0
- package/lib/esm/utils/index.d.ts +3 -0
- package/lib/esm/utils/index.js +16 -0
- package/package.json +9 -3
- package/.idea/impermax-sdk.iml +0 -12
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/workspace.xml +0 -642
- package/abis/ImpermaxABI.ts +0 -3
- package/abis/contracts/BAllowance.json +0 -4735
- package/abis/contracts/BDeployer.json +0 -1195
- package/abis/contracts/BInterestRateModel.json +0 -10796
- package/abis/contracts/BSetter.json +0 -6219
- package/abis/contracts/BStorage.json +0 -2613
- package/abis/contracts/Borrowable.json +0 -19937
- package/abis/contracts/CDeployer.json +0 -1104
- package/abis/contracts/CSetter.json +0 -5094
- package/abis/contracts/CStorage.json +0 -516
- package/abis/contracts/ClaimAggregator.json +0 -2015
- package/abis/contracts/Collateral.json +0 -21615
- package/abis/contracts/ERC20.json +0 -819
- package/abis/contracts/Factory.json +0 -21986
- package/abis/contracts/FarmingPool.json +0 -8601
- package/abis/contracts/IBDeployer.json +0 -351
- package/abis/contracts/IBorrowTracker.json +0 -346
- package/abis/contracts/IBorrowable.json +0 -13207
- package/abis/contracts/ICDeployer.json +0 -294
- package/abis/contracts/IClaimable.json +0 -406
- package/abis/contracts/ICollateral.json +0 -8952
- package/abis/contracts/IERC20.json +0 -2376
- package/abis/contracts/IFactory.json +0 -3660
- package/abis/contracts/IFarmingPool.json +0 -3584
- package/abis/contracts/IImpermaxCallee.json +0 -679
- package/abis/contracts/IMerkleDistributor.json +0 -1134
- package/abis/contracts/IPoolToken.json +0 -5343
- package/abis/contracts/IRouter01.json +0 -6891
- package/abis/contracts/IRouter02.json +0 -7283
- package/abis/contracts/ISimpleUniswapOracle.json +0 -1469
- package/abis/contracts/IStakedLPToken.json +0 -7309
- package/abis/contracts/IStakingRewards.json +0 -1036
- package/abis/contracts/IUniswapV2Callee.json +0 -403
- package/abis/contracts/IUniswapV2ERC20.json +0 -3155
- package/abis/contracts/IUniswapV2Factory.json +0 -1690
- package/abis/contracts/IUniswapV2Pair.json +0 -6761
- package/abis/contracts/IWETH.json +0 -561
- package/abis/contracts/ImpermaxChef.json +0 -20945
- package/abis/contracts/ImpermaxERC20.json +0 -12095
- package/abis/contracts/Math.json +0 -1966
- package/abis/contracts/MockERC20.json +0 -8884
- package/abis/contracts/PoolToken.json +0 -10784
- package/abis/contracts/Router01.json +0 -43963
- package/abis/contracts/SafeMath.json +0 -6828
- package/abis/contracts/SimpleUniswapOracle.json +0 -9640
- package/abis/contracts/TransferHelper.json +0 -4875
- package/abis/contracts/UQ112x112.json +0 -1201
- package/abis/contracts/UniswapV2ERC20.json +0 -10969
- package/abis/contracts/UniswapV2Factory.json +0 -5521
- package/abis/contracts/UniswapV2Library.json +0 -13789
- package/abis/contracts/UniswapV2Pair.json +0 -30782
- package/abis/contracts/WETH9.json +0 -6613
- package/config/amms.ts +0 -199
- package/config/contracts/claim-aggregators.ts +0 -16
- package/config/contracts/impermax-chef.ts +0 -16
- package/config/contracts/imxes.ts +0 -16
- package/config/contracts/merkle-distributors.ts +0 -13
- package/config/contracts/routers.ts +0 -36
- package/config/contracts/simple-uniswap-oracles.ts +0 -33
- package/config/contracts/weths.ts +0 -18
- package/config/debank-ids.ts +0 -15
- package/config/endpoints/merkle-distributors.ts +0 -13
- package/config/eth.ts +0 -32
- package/config/factories.ts +0 -26
- package/config/farms.ts +0 -119
- package/config/general.ts +0 -8
- package/config/subgraphs.ts +0 -69
- package/config/types.ts +0 -81
- package/impermax-router/Account.ts +0 -123
- package/impermax-router/AccountBorrowable.ts +0 -110
- package/impermax-router/AccountCollateral.ts +0 -40
- package/impermax-router/AccountLendingPool.ts +0 -231
- package/impermax-router/AccountPoolToken.ts +0 -76
- package/impermax-router/Borrowable.ts +0 -86
- package/impermax-router/Collateral.ts +0 -26
- package/impermax-router/ContractsHelper.ts +0 -64
- package/impermax-router/ImpermaxFactory.ts +0 -47
- package/impermax-router/Interactions.ts +0 -94
- package/impermax-router/InteractionsLendingPool.ts +0 -129
- package/impermax-router/InteractionsPoolToken.ts +0 -187
- package/impermax-router/LendingPool.ts +0 -256
- package/impermax-router/PoolToken.ts +0 -112
- package/impermax-router/index.ts +0 -49
- package/impermax-router/interfaces.ts +0 -233
- package/subgraph/Account.ts +0 -93
- package/subgraph/AccountLendingPool.ts +0 -60
- package/subgraph/AccountPoolToken.ts +0 -60
- package/subgraph/LendingPool.ts +0 -179
- package/subgraph/PoolToken.ts +0 -381
- package/subgraph/PriceHelper.ts +0 -150
- package/subgraph/SolidexHelper.ts +0 -54
- package/subgraph/index.ts +0 -166
- package/subgraph/initializer.ts +0 -509
- package/subgraph/query.ts +0 -224
- package/tsconfig.json +0 -16
- package/utils/ether-utils.ts +0 -22
- package/utils/index.ts +0 -12
|
@@ -0,0 +1,140 @@
|
|
|
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 utils_1 = require("../utils");
|
|
13
|
+
const ether_utils_1 = require("../utils/ether-utils");
|
|
14
|
+
class PoolToken {
|
|
15
|
+
constructor(lendingPool, poolTokenType) {
|
|
16
|
+
this.cache = {};
|
|
17
|
+
this.getContractHelper = () => this.lendingPool.factory.router.contractsHelper;
|
|
18
|
+
this.lendingPool = lendingPool;
|
|
19
|
+
this.poolTokenType = poolTokenType;
|
|
20
|
+
}
|
|
21
|
+
cleanCache() {
|
|
22
|
+
this.cache = {};
|
|
23
|
+
}
|
|
24
|
+
getSubgraphPoolToken() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const lendingPool = yield this.lendingPool.getSubgraphLendingPool();
|
|
27
|
+
return lendingPool.poolTokens[this.poolTokenType];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getPoolTokenAddressFromLendingPool() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return (yield this.lendingPool.getPoolTokenAddresses())[this.poolTokenType];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getPoolToken() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!this.cache.poolToken)
|
|
38
|
+
this.cache.poolToken = this.initializePoolToken();
|
|
39
|
+
return this.cache.poolToken;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getPoolTokenAddress() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return (yield this.getPoolToken())._address;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getToken() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!this.cache.token)
|
|
50
|
+
this.cache.token = this.initializeToken();
|
|
51
|
+
return this.cache.token;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
getTokenAddress() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return (yield this.getToken())._address;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getDecimals() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const subgraph = yield this.getSubgraphPoolToken();
|
|
62
|
+
return yield subgraph.getDecimals();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Utilities
|
|
66
|
+
normalize(amount) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return amount / Math.pow(10, yield this.getDecimals());
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
toBigNumber(amount) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (!(0, utils_1.isValidNumber)(amount))
|
|
74
|
+
return null;
|
|
75
|
+
return (0, ether_utils_1.decimalToBalance)(amount, yield this.getDecimals());
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
toNumber(amount) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (!amount)
|
|
81
|
+
return null;
|
|
82
|
+
return parseFloat(amount.toString()) / Math.pow(10, yield this.getDecimals());
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
toTokens(amount) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if (!(0, utils_1.isValidNumber)(amount))
|
|
88
|
+
return null;
|
|
89
|
+
const exchangeRate = yield this.getExchangeRate();
|
|
90
|
+
return (0, ether_utils_1.decimalToBalance)(amount / exchangeRate, yield this.getDecimals());
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
fromTokens(amount) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
if (!amount)
|
|
96
|
+
return null;
|
|
97
|
+
const exchangeRate = yield this.getExchangeRate();
|
|
98
|
+
return parseFloat(amount.toString()) * exchangeRate / Math.pow(10, yield this.getDecimals());
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Total balance
|
|
102
|
+
initializeTotalBalance() {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const poolToken = yield this.getPoolToken();
|
|
105
|
+
const amount = yield poolToken.methods.totalBalance().call();
|
|
106
|
+
return this.normalize(amount);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getTotalBalance() {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
if (!this.cache.totalBalance)
|
|
112
|
+
this.cache.totalBalance = this.initializeTotalBalance();
|
|
113
|
+
return this.cache.totalBalance;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getTotalBalanceUSD() {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const totalBalance = yield this.getTotalBalance();
|
|
119
|
+
const subgraph = yield this.getSubgraphPoolToken();
|
|
120
|
+
const tokenPrice = yield subgraph.getTokenPriceFast();
|
|
121
|
+
return totalBalance * tokenPrice;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Exchange rate
|
|
125
|
+
initializeExchangeRate() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const poolToken = yield this.getPoolToken();
|
|
128
|
+
let exchangeRate = (yield poolToken.methods.exchangeRate().call()) / 1e18;
|
|
129
|
+
return exchangeRate;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
getExchangeRate() {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (!this.cache.exchangeRate)
|
|
135
|
+
this.cache.exchangeRate = this.initializeExchangeRate();
|
|
136
|
+
return this.cache.exchangeRate;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.default = PoolToken;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ImpermaxRouterCfg } from "./interfaces";
|
|
2
|
+
import Subgraph from "../subgraph";
|
|
3
|
+
import ContractsHelper from "./ContractsHelper";
|
|
4
|
+
import ImpermaxFactory from "./ImpermaxFactory";
|
|
5
|
+
import { Factory, FactoryIndex, Networks } from '../config/types';
|
|
6
|
+
export default class ImpermaxRouter {
|
|
7
|
+
network: Networks;
|
|
8
|
+
subgraph: Subgraph;
|
|
9
|
+
web3: any;
|
|
10
|
+
chainId: number;
|
|
11
|
+
contractsHelper: ContractsHelper;
|
|
12
|
+
factories: FactoryIndex<ImpermaxFactory>;
|
|
13
|
+
uiMargin: number;
|
|
14
|
+
dust: number;
|
|
15
|
+
priceInverted: boolean;
|
|
16
|
+
constructor(cfg: ImpermaxRouterCfg);
|
|
17
|
+
cleanCache(): void;
|
|
18
|
+
setPriceInverted(priceInverted: boolean): void;
|
|
19
|
+
getFactory(factory: Factory): ImpermaxFactory;
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 ContractsHelper_1 = __importDefault(require("./ContractsHelper"));
|
|
7
|
+
const ImpermaxFactory_1 = __importDefault(require("./ImpermaxFactory"));
|
|
8
|
+
class ImpermaxRouter {
|
|
9
|
+
constructor(cfg) {
|
|
10
|
+
this.network = cfg.network;
|
|
11
|
+
this.subgraph = cfg.subgraph;
|
|
12
|
+
this.web3 = cfg.web3;
|
|
13
|
+
this.chainId = cfg.chainId;
|
|
14
|
+
this.uiMargin = 1.1;
|
|
15
|
+
this.dust = 1.000001;
|
|
16
|
+
this.priceInverted = cfg.priceInverted;
|
|
17
|
+
this.contractsHelper = new ContractsHelper_1.default(this);
|
|
18
|
+
this.factories = {};
|
|
19
|
+
}
|
|
20
|
+
cleanCache() {
|
|
21
|
+
for (const factory of Object.keys(this.factories)) {
|
|
22
|
+
this.factories[factory].cleanCache();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
setPriceInverted(priceInverted) {
|
|
26
|
+
this.priceInverted = priceInverted;
|
|
27
|
+
}
|
|
28
|
+
getFactory(factory) {
|
|
29
|
+
if (!this.factories[factory])
|
|
30
|
+
this.factories[factory] = new ImpermaxFactory_1.default(this, factory);
|
|
31
|
+
return this.factories[factory];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = ImpermaxRouter;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import Subgraph from "../subgraph";
|
|
3
|
+
import { Address, Networks, PoolTokenType } from '../config/types';
|
|
4
|
+
export type Contract = any;
|
|
5
|
+
export type RouterContract = Contract;
|
|
6
|
+
export type FactoryContract = Contract;
|
|
7
|
+
export type SimpleUniswapOracleContract = Contract;
|
|
8
|
+
export type ERC20Contract = Contract;
|
|
9
|
+
export type UniswapV2PairContract = Contract;
|
|
10
|
+
export type UniswapV2FactoryContract = Contract;
|
|
11
|
+
export type BorrowableContract = Contract;
|
|
12
|
+
export type CollateralContract = Contract;
|
|
13
|
+
export type MerkleDistributorContract = Contract;
|
|
14
|
+
export type FarmingPoolContract = Contract;
|
|
15
|
+
export type ClaimAggregatorContract = Contract;
|
|
16
|
+
export type ClaimableContract = Contract;
|
|
17
|
+
export type StakedLPTokenContract = Contract;
|
|
18
|
+
export type ImpermaxChefContract = Contract;
|
|
19
|
+
export type LendingPool = {
|
|
20
|
+
uniswapV2Pair: UniswapV2PairContract;
|
|
21
|
+
tokenA: ERC20Contract;
|
|
22
|
+
tokenB: ERC20Contract;
|
|
23
|
+
collateral: CollateralContract;
|
|
24
|
+
borrowableA: BorrowableContract;
|
|
25
|
+
borrowableB: BorrowableContract;
|
|
26
|
+
farmingPoolA: FarmingPoolContract;
|
|
27
|
+
farmingPoolB: FarmingPoolContract;
|
|
28
|
+
stakedLPToken: StakedLPTokenContract;
|
|
29
|
+
};
|
|
30
|
+
export declare enum ApprovalType {
|
|
31
|
+
POOL_TOKEN = 0,
|
|
32
|
+
UNDERLYING = 1,
|
|
33
|
+
BORROW = 2
|
|
34
|
+
}
|
|
35
|
+
export interface PermitData {
|
|
36
|
+
permitData: string;
|
|
37
|
+
amount: BigNumber;
|
|
38
|
+
deadline: BigNumber;
|
|
39
|
+
}
|
|
40
|
+
export interface Changes {
|
|
41
|
+
changeBorrowedA: number;
|
|
42
|
+
changeBorrowedB: number;
|
|
43
|
+
changeCollateral: number;
|
|
44
|
+
}
|
|
45
|
+
export declare const NO_CHANGES: {
|
|
46
|
+
changeBorrowedA: number;
|
|
47
|
+
changeBorrowedB: number;
|
|
48
|
+
changeCollateral: number;
|
|
49
|
+
};
|
|
50
|
+
export interface Values {
|
|
51
|
+
valueCollateral: number;
|
|
52
|
+
valueA: number;
|
|
53
|
+
valueB: number;
|
|
54
|
+
}
|
|
55
|
+
export interface ImpermaxRouterCfg {
|
|
56
|
+
network: Networks;
|
|
57
|
+
subgraph: Subgraph;
|
|
58
|
+
web3: any;
|
|
59
|
+
chainId: number;
|
|
60
|
+
priceInverted: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface PoolTokenData {
|
|
63
|
+
id: Address;
|
|
64
|
+
totalBalance: string;
|
|
65
|
+
exchangeRate: string;
|
|
66
|
+
totalBalanceUSD: string;
|
|
67
|
+
}
|
|
68
|
+
export interface BorrowableData extends PoolTokenData {
|
|
69
|
+
underlying: TokenData;
|
|
70
|
+
totalBorrows: string;
|
|
71
|
+
borrowRate: string;
|
|
72
|
+
reserveFactor: string;
|
|
73
|
+
kinkBorrowRate: string;
|
|
74
|
+
kinkUtilizationRate: string;
|
|
75
|
+
borrowIndex: string;
|
|
76
|
+
accrualTimestamp: string;
|
|
77
|
+
farmingPool: FarmingPoolData;
|
|
78
|
+
rewards?: Array<{
|
|
79
|
+
rewardToken: Address;
|
|
80
|
+
rewardRate: number;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
export interface CollateralData extends PoolTokenData {
|
|
84
|
+
safetyMargin: string;
|
|
85
|
+
liquidationIncentive: string;
|
|
86
|
+
liquidationFee: string;
|
|
87
|
+
}
|
|
88
|
+
export interface BorrowablePastData {
|
|
89
|
+
borrowIndex: string;
|
|
90
|
+
accrualTimestamp: string;
|
|
91
|
+
exchangeRate: string;
|
|
92
|
+
}
|
|
93
|
+
export interface TokenData {
|
|
94
|
+
id: Address;
|
|
95
|
+
symbol: string;
|
|
96
|
+
name: string;
|
|
97
|
+
decimals: string;
|
|
98
|
+
derivedUSD: string;
|
|
99
|
+
}
|
|
100
|
+
export interface RewardData {
|
|
101
|
+
id: Address;
|
|
102
|
+
rewardRate: string;
|
|
103
|
+
rewardsToken: TokenData;
|
|
104
|
+
periodFinish: string;
|
|
105
|
+
}
|
|
106
|
+
export interface PairData {
|
|
107
|
+
id: Address;
|
|
108
|
+
factory: string;
|
|
109
|
+
reserve0: string;
|
|
110
|
+
reserve1: string;
|
|
111
|
+
totalSupply: string;
|
|
112
|
+
reserveUSD: string;
|
|
113
|
+
token0Price: string;
|
|
114
|
+
token1Price: string;
|
|
115
|
+
derivedUSD: string;
|
|
116
|
+
uniswapV2PairAddress: string;
|
|
117
|
+
uniswapV2Factory: string;
|
|
118
|
+
isStakedLPToken: boolean;
|
|
119
|
+
exchangeRate: string;
|
|
120
|
+
stakingRewards: string;
|
|
121
|
+
masterChef: string;
|
|
122
|
+
pid: string;
|
|
123
|
+
stakedTotalSupply: string;
|
|
124
|
+
rewards: Array<RewardData>;
|
|
125
|
+
uniswapAPR: number;
|
|
126
|
+
}
|
|
127
|
+
export interface FarmingPoolData {
|
|
128
|
+
epochAmount: string;
|
|
129
|
+
epochBegin: string;
|
|
130
|
+
segmentLength: string;
|
|
131
|
+
vestingBegin: string;
|
|
132
|
+
sharePercentage: string;
|
|
133
|
+
}
|
|
134
|
+
export interface LendingPoolPastData {
|
|
135
|
+
[PoolTokenType.Collateral]: undefined;
|
|
136
|
+
[PoolTokenType.BorrowableA]: BorrowablePastData;
|
|
137
|
+
[PoolTokenType.BorrowableB]: BorrowablePastData;
|
|
138
|
+
}
|
|
139
|
+
export interface LendingPoolData {
|
|
140
|
+
id: Address;
|
|
141
|
+
[PoolTokenType.Collateral]: CollateralData;
|
|
142
|
+
[PoolTokenType.BorrowableA]: BorrowableData;
|
|
143
|
+
[PoolTokenType.BorrowableB]: BorrowableData;
|
|
144
|
+
pair: PairData;
|
|
145
|
+
past24h?: LendingPoolPastData;
|
|
146
|
+
past7d?: LendingPoolPastData;
|
|
147
|
+
}
|
|
148
|
+
export interface CollateralPosition {
|
|
149
|
+
balance: string;
|
|
150
|
+
collateral: {
|
|
151
|
+
lendingPool: {
|
|
152
|
+
id: Address;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export interface SupplyPosition {
|
|
157
|
+
balance: string;
|
|
158
|
+
borrowable: {
|
|
159
|
+
underlying: {
|
|
160
|
+
id: Address;
|
|
161
|
+
};
|
|
162
|
+
lendingPool: {
|
|
163
|
+
id: Address;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export interface BorrowPosition {
|
|
168
|
+
borrowBalance: string;
|
|
169
|
+
borrowIndex: string;
|
|
170
|
+
borrowable: {
|
|
171
|
+
underlying: {
|
|
172
|
+
id: Address;
|
|
173
|
+
};
|
|
174
|
+
lendingPool: {
|
|
175
|
+
id: Address;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export interface UserData {
|
|
180
|
+
collateralPositions: {
|
|
181
|
+
[key in Address]: CollateralPosition;
|
|
182
|
+
};
|
|
183
|
+
supplyPositions: {
|
|
184
|
+
[key in Address]: {
|
|
185
|
+
[key in PoolTokenType]?: SupplyPosition;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
borrowPositions: {
|
|
189
|
+
[key in Address]: {
|
|
190
|
+
[key in PoolTokenType]?: BorrowPosition;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export interface TvlData {
|
|
195
|
+
crossChainTVLUSD: number;
|
|
196
|
+
totalBalanceUSD: number;
|
|
197
|
+
totalBorrowsUSD: number;
|
|
198
|
+
totalSupplyUSD: number;
|
|
199
|
+
}
|
|
200
|
+
export interface AirdropData {
|
|
201
|
+
index: number;
|
|
202
|
+
amount: BigNumber;
|
|
203
|
+
proof: Array<string>;
|
|
204
|
+
}
|
|
205
|
+
export interface ClaimEvent {
|
|
206
|
+
amount: number;
|
|
207
|
+
transactionHash: string;
|
|
208
|
+
}
|
|
209
|
+
export interface XimxData {
|
|
210
|
+
totalSupply: string;
|
|
211
|
+
totalBalance: string;
|
|
212
|
+
exchangeRate: string;
|
|
213
|
+
dailyAPR: string;
|
|
214
|
+
}
|
|
215
|
+
export interface PendingRewardUI {
|
|
216
|
+
symbol: string;
|
|
217
|
+
amount: number;
|
|
218
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_CHANGES = exports.ApprovalType = void 0;
|
|
4
|
+
const types_1 = require("../config/types");
|
|
5
|
+
var ApprovalType;
|
|
6
|
+
(function (ApprovalType) {
|
|
7
|
+
ApprovalType[ApprovalType["POOL_TOKEN"] = 0] = "POOL_TOKEN";
|
|
8
|
+
ApprovalType[ApprovalType["UNDERLYING"] = 1] = "UNDERLYING";
|
|
9
|
+
ApprovalType[ApprovalType["BORROW"] = 2] = "BORROW";
|
|
10
|
+
})(ApprovalType = exports.ApprovalType || (exports.ApprovalType = {}));
|
|
11
|
+
exports.NO_CHANGES = {
|
|
12
|
+
changeBorrowedA: 0,
|
|
13
|
+
changeBorrowedB: 0,
|
|
14
|
+
changeCollateral: 0,
|
|
15
|
+
};
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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.ImpermaxRouter = exports.Subgraph = void 0;
|
|
7
|
+
const subgraph_1 = __importDefault(require("./subgraph"));
|
|
8
|
+
exports.Subgraph = subgraph_1.default;
|
|
9
|
+
const impermax_router_1 = __importDefault(require("./impermax-router"));
|
|
10
|
+
exports.ImpermaxRouter = impermax_router_1.default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UserData } from "../impermax-router/interfaces";
|
|
2
|
+
import Subgraph from "./index";
|
|
3
|
+
import AccountLendingPool from "./AccountLendingPool";
|
|
4
|
+
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
5
|
+
export default class Account {
|
|
6
|
+
subgraph: Subgraph;
|
|
7
|
+
account: Address;
|
|
8
|
+
accountLLPs: LendingPoolIndex<Promise<AccountLendingPool>>;
|
|
9
|
+
constructor(subgraph: Subgraph, account: Address);
|
|
10
|
+
private initializeAccountLendingPool;
|
|
11
|
+
getAccountLendingPool(factory: Factory, pair: Address): Promise<AccountLendingPool>;
|
|
12
|
+
getUserData(): Promise<FactoryIndex<UserData>>;
|
|
13
|
+
getBorrowPositions(): Promise<FactoryIndex<Address[]>>;
|
|
14
|
+
getSupplyPositions(): Promise<FactoryIndex<Address[]>>;
|
|
15
|
+
getAccountTotalValueLocked(): Promise<number>;
|
|
16
|
+
getAccountTotalValueSupplied(): Promise<number>;
|
|
17
|
+
getAccountTotalValueBorrowed(): Promise<number>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 AccountLendingPool_1 = __importDefault(require("./AccountLendingPool"));
|
|
16
|
+
const types_1 = require("../config/types");
|
|
17
|
+
class Account {
|
|
18
|
+
constructor(subgraph, account) {
|
|
19
|
+
this.subgraph = subgraph;
|
|
20
|
+
this.account = account;
|
|
21
|
+
this.accountLLPs = {};
|
|
22
|
+
}
|
|
23
|
+
initializeAccountLendingPool(factory, pair) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const lendingPool = yield this.subgraph.getLendingPool(factory, pair);
|
|
26
|
+
return new AccountLendingPool_1.default(this, lendingPool);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
getAccountLendingPool(factory, pair) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (!this.accountLLPs[factory])
|
|
32
|
+
this.accountLLPs[factory] = {};
|
|
33
|
+
if (!this.accountLLPs[factory][pair])
|
|
34
|
+
this.accountLLPs[factory][pair] = this.initializeAccountLendingPool(factory, pair);
|
|
35
|
+
return this.accountLLPs[factory][pair];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getUserData() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return this.subgraph.getUserData(this.account);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getBorrowPositions() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const result = {};
|
|
46
|
+
const userData = yield this.getUserData();
|
|
47
|
+
for (const factory of Object.keys(userData)) {
|
|
48
|
+
result[factory] = Object.keys(userData[factory].collateralPositions);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
getSupplyPositions() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const result = {};
|
|
56
|
+
const userData = yield this.getUserData();
|
|
57
|
+
for (const factory of Object.keys(userData)) {
|
|
58
|
+
result[factory] = Object.keys(userData[factory].supplyPositions);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getAccountTotalValueLocked() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const borrowPositions = yield this.getBorrowPositions();
|
|
66
|
+
const supplyPositions = yield this.getSupplyPositions();
|
|
67
|
+
let tvl = 0;
|
|
68
|
+
for (const factory of Object.keys(borrowPositions)) {
|
|
69
|
+
for (const uniswapV2PairAddress of borrowPositions[factory]) {
|
|
70
|
+
const accountLendingPool = yield this.getAccountLendingPool(factory, uniswapV2PairAddress);
|
|
71
|
+
tvl += yield accountLendingPool.getBorrowerEquityValue();
|
|
72
|
+
}
|
|
73
|
+
for (const uniswapV2PairAddress of supplyPositions[factory]) {
|
|
74
|
+
const accountLendingPool = yield this.getAccountLendingPool(factory, uniswapV2PairAddress);
|
|
75
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableA].getSuppliedValue();
|
|
76
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableB].getSuppliedValue();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return tvl;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getAccountTotalValueSupplied() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const supplyPositions = yield this.getSupplyPositions();
|
|
85
|
+
let tvl = 0;
|
|
86
|
+
for (const factory of Object.keys(supplyPositions)) {
|
|
87
|
+
for (const uniswapV2PairAddress of supplyPositions[factory]) {
|
|
88
|
+
const accountLendingPool = yield this.getAccountLendingPool(factory, uniswapV2PairAddress);
|
|
89
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableA].getSuppliedValue();
|
|
90
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableB].getSuppliedValue();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return tvl;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getAccountTotalValueBorrowed() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const borrowPositions = yield this.getBorrowPositions();
|
|
99
|
+
let tvl = 0;
|
|
100
|
+
for (const factory of Object.keys(borrowPositions)) {
|
|
101
|
+
for (const uniswapV2PairAddress of borrowPositions[factory]) {
|
|
102
|
+
const accountLendingPool = yield this.getAccountLendingPool(factory, uniswapV2PairAddress);
|
|
103
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableA].getBorrowedValue();
|
|
104
|
+
tvl += yield accountLendingPool.accountPoolTokens[types_1.PoolTokenType.BorrowableB].getBorrowedValue();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return tvl;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.default = Account;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CollateralPosition, UserData } from "../impermax-router/interfaces";
|
|
2
|
+
import Account from "./Account";
|
|
3
|
+
import AccountPoolToken from "./AccountPoolToken";
|
|
4
|
+
import LendingPool from "./LendingPool";
|
|
5
|
+
import { PoolTokenType } from '../config/types';
|
|
6
|
+
export default class AccountLendingPool {
|
|
7
|
+
account: Account;
|
|
8
|
+
lendingPool: LendingPool;
|
|
9
|
+
accountPoolTokens: {
|
|
10
|
+
[key in PoolTokenType]?: AccountPoolToken;
|
|
11
|
+
};
|
|
12
|
+
constructor(account: Account, lendingPool: LendingPool);
|
|
13
|
+
getAccountPoolToken(poolTokenType: PoolTokenType): AccountPoolToken;
|
|
14
|
+
getUserData(): Promise<UserData>;
|
|
15
|
+
getCollateralPosition(): Promise<CollateralPosition>;
|
|
16
|
+
getCollateralAmount(): Promise<number>;
|
|
17
|
+
getCollateralValue(): Promise<number>;
|
|
18
|
+
getBorrowerEquityValue(): Promise<number>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 AccountPoolToken_1 = __importDefault(require("./AccountPoolToken"));
|
|
16
|
+
const types_1 = require("../config/types");
|
|
17
|
+
class AccountLendingPool {
|
|
18
|
+
constructor(account, lendingPool) {
|
|
19
|
+
this.account = account;
|
|
20
|
+
this.lendingPool = lendingPool;
|
|
21
|
+
this.accountPoolTokens = {};
|
|
22
|
+
this.accountPoolTokens[types_1.PoolTokenType.Collateral] = new AccountPoolToken_1.default(this, types_1.PoolTokenType.Collateral);
|
|
23
|
+
this.accountPoolTokens[types_1.PoolTokenType.BorrowableA] = new AccountPoolToken_1.default(this, types_1.PoolTokenType.BorrowableA);
|
|
24
|
+
this.accountPoolTokens[types_1.PoolTokenType.BorrowableB] = new AccountPoolToken_1.default(this, types_1.PoolTokenType.BorrowableB);
|
|
25
|
+
}
|
|
26
|
+
getAccountPoolToken(poolTokenType) {
|
|
27
|
+
return this.accountPoolTokens[poolTokenType];
|
|
28
|
+
}
|
|
29
|
+
getUserData() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const userData = yield this.account.getUserData();
|
|
32
|
+
if (!userData)
|
|
33
|
+
return null;
|
|
34
|
+
return userData[this.lendingPool.factory];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getCollateralPosition() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const userData = yield this.getUserData();
|
|
40
|
+
if (!userData)
|
|
41
|
+
return null;
|
|
42
|
+
return userData.collateralPositions[this.lendingPool.pairAddress];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getCollateralAmount() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const collateralPosition = yield this.getCollateralPosition();
|
|
48
|
+
if (!collateralPosition)
|
|
49
|
+
return 0;
|
|
50
|
+
const exchangeRate = yield this.lendingPool.poolTokens[types_1.PoolTokenType.Collateral].getExchangeRate();
|
|
51
|
+
const collateralBalance = parseFloat(collateralPosition.balance);
|
|
52
|
+
return collateralBalance * exchangeRate;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getCollateralValue() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const tokenPrice = yield this.lendingPool.poolTokens[types_1.PoolTokenType.Collateral].getTokenPriceAccurate();
|
|
58
|
+
const collateralAmount = yield this.getCollateralAmount();
|
|
59
|
+
return collateralAmount * tokenPrice;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getBorrowerEquityValue() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const collateralValue = yield this.getCollateralValue();
|
|
65
|
+
const borrowedValueA = yield this.accountPoolTokens[types_1.PoolTokenType.BorrowableA].getBorrowedValue();
|
|
66
|
+
const borrowedValueB = yield this.accountPoolTokens[types_1.PoolTokenType.BorrowableB].getBorrowedValue();
|
|
67
|
+
return collateralValue - borrowedValueA - borrowedValueB;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = AccountLendingPool;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
constructor(accountLendingPool: AccountLendingPool, poolTokenType: PoolTokenType);
|
|
8
|
+
private getBorrowPosition;
|
|
9
|
+
private getSupplyPosition;
|
|
10
|
+
getBorrowedAmount(): Promise<number>;
|
|
11
|
+
getBorrowedValue(): Promise<number>;
|
|
12
|
+
getSuppliedAmount(): Promise<number>;
|
|
13
|
+
getSuppliedValue(): Promise<number>;
|
|
14
|
+
}
|