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,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 "./types";
|
|
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,45 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import Subgraph from "../subgraph";
|
|
3
|
+
import { Networks } from '../config/types';
|
|
4
|
+
export type Contract = any;
|
|
5
|
+
export declare enum ApprovalType {
|
|
6
|
+
POOL_TOKEN = 0,
|
|
7
|
+
UNDERLYING = 1,
|
|
8
|
+
BORROW = 2
|
|
9
|
+
}
|
|
10
|
+
export interface PermitData {
|
|
11
|
+
permitData: string;
|
|
12
|
+
amount: BigNumber;
|
|
13
|
+
deadline: BigNumber;
|
|
14
|
+
}
|
|
15
|
+
export interface ImpermaxRouterCfg {
|
|
16
|
+
network: Networks;
|
|
17
|
+
subgraph: Subgraph;
|
|
18
|
+
web3: any;
|
|
19
|
+
chainId: number;
|
|
20
|
+
priceInverted: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface Changes {
|
|
23
|
+
changeBorrowedA: number;
|
|
24
|
+
changeBorrowedB: number;
|
|
25
|
+
changeCollateral: number;
|
|
26
|
+
}
|
|
27
|
+
export declare const NO_CHANGES: {
|
|
28
|
+
changeBorrowedA: number;
|
|
29
|
+
changeBorrowedB: number;
|
|
30
|
+
changeCollateral: number;
|
|
31
|
+
};
|
|
32
|
+
export interface Values {
|
|
33
|
+
valueCollateral: number;
|
|
34
|
+
valueA: number;
|
|
35
|
+
valueB: number;
|
|
36
|
+
}
|
|
37
|
+
export interface AirdropData {
|
|
38
|
+
index: number;
|
|
39
|
+
amount: BigNumber;
|
|
40
|
+
proof: Array<string>;
|
|
41
|
+
}
|
|
42
|
+
export interface PendingRewardUI {
|
|
43
|
+
symbol: string;
|
|
44
|
+
amount: number;
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_CHANGES = exports.ApprovalType = void 0;
|
|
4
|
+
var ApprovalType;
|
|
5
|
+
(function (ApprovalType) {
|
|
6
|
+
ApprovalType[ApprovalType["POOL_TOKEN"] = 0] = "POOL_TOKEN";
|
|
7
|
+
ApprovalType[ApprovalType["UNDERLYING"] = 1] = "UNDERLYING";
|
|
8
|
+
ApprovalType[ApprovalType["BORROW"] = 2] = "BORROW";
|
|
9
|
+
})(ApprovalType = exports.ApprovalType || (exports.ApprovalType = {}));
|
|
10
|
+
exports.NO_CHANGES = {
|
|
11
|
+
changeBorrowedA: 0,
|
|
12
|
+
changeBorrowedB: 0,
|
|
13
|
+
changeCollateral: 0,
|
|
14
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Subgraph from './subgraph';
|
|
2
|
+
import ImpermaxRouter from './impermax-router';
|
|
3
|
+
import { CLAIM_AGGREGATOR } from './config/contracts/claim-aggregators';
|
|
4
|
+
import { IMPERMAX_CHEF } from './config/contracts/impermax-chef';
|
|
5
|
+
import { IMX } from './config/contracts/imxes';
|
|
6
|
+
import { MERKLE_DISTRIBUTOR_ETH, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2 } from './config/contracts/merkle-distributors';
|
|
7
|
+
import { MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2 } from './config/endpoints/merkle-distributors';
|
|
8
|
+
import { ROUTER } from './config/contracts/routers';
|
|
9
|
+
import { SIMPLE_UNISWAP_ORACLE } from './config/contracts/simple-uniswap-oracles';
|
|
10
|
+
import { WETH } from './config/contracts/weths';
|
|
11
|
+
import { ADD_LIQUIDITY_URLS, Amms, AMM_FACTORY, AMM_LP_FEE, AMM_SUBGRAPH_URLS, getAmmByFactory, hrAmms } from './config/amms';
|
|
12
|
+
import { DEBANK_IDS } from './config/debank-ids';
|
|
13
|
+
import { ETH_NAME, ETH_SYMBOL } from './config/eth';
|
|
14
|
+
import { BORROW_FEE_FACTORIES, LIQUIDATION_FEE_FACTORIES, OLD_KINK_MULTIPLIER_FACTORIES, SOLIDEX_FACTORIES, V2_FACTORIES } from './config/factories';
|
|
15
|
+
import { FarmIndex, Farms, getFarmByStakedLPFactory, hrFarms, STAKED_LP_FACTORY } from './config/farms';
|
|
16
|
+
import { APPROVE_AMOUNT, DEADLINE, NOT_SYNCED, ZERO } from './config/general';
|
|
17
|
+
import { BLOCKS_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, IMPERMAX_SUBGRAPH_URL, XIMX_SUBGRAPH_URL } from './config/subgraphs';
|
|
18
|
+
import { Address, AddressIndex, AmmIndex, DistributorDetails, Factory, FactoryIndex, LendingPoolIndex, NetworkFactoryIndex, NetworkIndex, Networks, PoolTokenType } from './config/types';
|
|
19
|
+
import SubgraphAccount from './subgraph/Account';
|
|
20
|
+
import SubgraphAccountLendingPool from './subgraph/AccountLendingPool';
|
|
21
|
+
import SubgraphAccountPoolToken from './subgraph/AccountPoolToken';
|
|
22
|
+
import SubgraphLendingPool from './subgraph/LendingPool';
|
|
23
|
+
import SubgraphPoolToken from './subgraph/PoolToken';
|
|
24
|
+
import PriceHelper from './subgraph/PriceHelper';
|
|
25
|
+
import SolidexHelper from './subgraph/SolidexHelper';
|
|
26
|
+
import ImpermaxRouterAccount from './impermax-router/Account';
|
|
27
|
+
import ImpermaxRouterAccountPoolToken from './impermax-router/AccountPoolToken';
|
|
28
|
+
import ImpermaxRouterAccountLendingPool from './impermax-router/AccountLendingPool';
|
|
29
|
+
import AccountBorrowable from './impermax-router/AccountBorrowable';
|
|
30
|
+
import AccountCollateral from './impermax-router/AccountCollateral';
|
|
31
|
+
import Borrowable from './impermax-router/Borrowable';
|
|
32
|
+
import Collateral from './impermax-router/Collateral';
|
|
33
|
+
import ContractsHelper from './impermax-router/ContractsHelper';
|
|
34
|
+
import ImpermaxFactory from './impermax-router/ImpermaxFactory';
|
|
35
|
+
import Interactions from './impermax-router/Interactions';
|
|
36
|
+
import InteractionsLendingPool from './impermax-router/InteractionsLendingPool';
|
|
37
|
+
import InteractionsPoolToken from './impermax-router/InteractionsPoolToken';
|
|
38
|
+
import ImpermaxRouterLendingPool from './impermax-router/LendingPool';
|
|
39
|
+
import ImpermaxRouterPoolToken from './impermax-router/PoolToken';
|
|
40
|
+
import { AirdropData, ApprovalType, Changes, Contract, ImpermaxRouterCfg, NO_CHANGES, PendingRewardUI, PermitData, Values } from './impermax-router/types';
|
|
41
|
+
import { BorrowableData, BorrowablePastData, BorrowPosition, CollateralData, CollateralPosition, FarmingPoolData, LendingPoolData, LendingPoolPastData, PairData, PoolTokenData, RewardData, SupplyPosition, TokenData, TvlData, UserData, XimxData } from './subgraph/types';
|
|
42
|
+
export { CLAIM_AGGREGATOR, IMPERMAX_CHEF, IMX, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2, MERKLE_DISTRIBUTOR_ETH, ROUTER, SIMPLE_UNISWAP_ORACLE, WETH, MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2, hrAmms, AMM_FACTORY, getAmmByFactory, AMM_SUBGRAPH_URLS, ADD_LIQUIDITY_URLS, AMM_LP_FEE, DEBANK_IDS, ETH_SYMBOL, ETH_NAME, SOLIDEX_FACTORIES, BORROW_FEE_FACTORIES, OLD_KINK_MULTIPLIER_FACTORIES, LIQUIDATION_FEE_FACTORIES, V2_FACTORIES, Farms, hrFarms, FarmIndex, STAKED_LP_FACTORY, getFarmByStakedLPFactory, NOT_SYNCED, DEADLINE, ZERO, APPROVE_AMOUNT, IMPERMAX_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, BLOCKS_SUBGRAPH_URL, XIMX_SUBGRAPH_URL, Networks, Factory, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, Subgraph, SubgraphAccount, SubgraphAccountLendingPool, SubgraphAccountPoolToken, SubgraphLendingPool, SubgraphPoolToken, PriceHelper, SolidexHelper, PoolTokenData, BorrowableData, CollateralData, BorrowablePastData, TokenData, RewardData, PairData, FarmingPoolData, LendingPoolPastData, LendingPoolData, CollateralPosition, SupplyPosition, BorrowPosition, UserData, TvlData, XimxData, ImpermaxRouter, ImpermaxRouterAccount, ImpermaxRouterAccountPoolToken, ImpermaxRouterAccountLendingPool, AccountBorrowable, AccountCollateral, Borrowable, Collateral, ContractsHelper, ImpermaxFactory, Interactions, InteractionsLendingPool, InteractionsPoolToken, ImpermaxRouterLendingPool, ImpermaxRouterPoolToken, Contract, ApprovalType, PermitData, ImpermaxRouterCfg, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
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.SolidexHelper = exports.PriceHelper = exports.SubgraphPoolToken = exports.SubgraphLendingPool = exports.SubgraphAccountPoolToken = exports.SubgraphAccountLendingPool = exports.SubgraphAccount = exports.Subgraph = exports.Amms = exports.PoolTokenType = exports.Factory = exports.Networks = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = exports.APPROVE_AMOUNT = exports.ZERO = exports.DEADLINE = exports.NOT_SYNCED = exports.getFarmByStakedLPFactory = exports.STAKED_LP_FACTORY = exports.hrFarms = exports.Farms = exports.V2_FACTORIES = exports.LIQUIDATION_FEE_FACTORIES = exports.OLD_KINK_MULTIPLIER_FACTORIES = exports.BORROW_FEE_FACTORIES = exports.SOLIDEX_FACTORIES = exports.ETH_NAME = exports.ETH_SYMBOL = exports.DEBANK_IDS = exports.AMM_LP_FEE = exports.ADD_LIQUIDITY_URLS = exports.AMM_SUBGRAPH_URLS = exports.getAmmByFactory = exports.AMM_FACTORY = exports.hrAmms = exports.MERKLE_URL_IBEX_2 = exports.MERKLE_URL_IBEX = exports.MERKLE_URL_ETH = exports.WETH = exports.SIMPLE_UNISWAP_ORACLE = exports.ROUTER = exports.MERKLE_DISTRIBUTOR_ETH = exports.MERKLE_DISTRIBUTOR_IBEX_2 = exports.MERKLE_DISTRIBUTOR_IBEX = exports.IMX = exports.IMPERMAX_CHEF = exports.CLAIM_AGGREGATOR = void 0;
|
|
7
|
+
exports.NO_CHANGES = exports.ApprovalType = exports.ImpermaxRouterPoolToken = exports.ImpermaxRouterLendingPool = exports.InteractionsPoolToken = exports.InteractionsLendingPool = exports.Interactions = exports.ImpermaxFactory = exports.ContractsHelper = exports.Collateral = exports.Borrowable = exports.AccountCollateral = exports.AccountBorrowable = exports.ImpermaxRouterAccountLendingPool = exports.ImpermaxRouterAccountPoolToken = exports.ImpermaxRouterAccount = exports.ImpermaxRouter = void 0;
|
|
8
|
+
const subgraph_1 = __importDefault(require("./subgraph"));
|
|
9
|
+
exports.Subgraph = subgraph_1.default;
|
|
10
|
+
const impermax_router_1 = __importDefault(require("./impermax-router"));
|
|
11
|
+
exports.ImpermaxRouter = impermax_router_1.default;
|
|
12
|
+
const claim_aggregators_1 = require("./config/contracts/claim-aggregators");
|
|
13
|
+
Object.defineProperty(exports, "CLAIM_AGGREGATOR", { enumerable: true, get: function () { return claim_aggregators_1.CLAIM_AGGREGATOR; } });
|
|
14
|
+
const impermax_chef_1 = require("./config/contracts/impermax-chef");
|
|
15
|
+
Object.defineProperty(exports, "IMPERMAX_CHEF", { enumerable: true, get: function () { return impermax_chef_1.IMPERMAX_CHEF; } });
|
|
16
|
+
const imxes_1 = require("./config/contracts/imxes");
|
|
17
|
+
Object.defineProperty(exports, "IMX", { enumerable: true, get: function () { return imxes_1.IMX; } });
|
|
18
|
+
const merkle_distributors_1 = require("./config/contracts/merkle-distributors");
|
|
19
|
+
Object.defineProperty(exports, "MERKLE_DISTRIBUTOR_ETH", { enumerable: true, get: function () { return merkle_distributors_1.MERKLE_DISTRIBUTOR_ETH; } });
|
|
20
|
+
Object.defineProperty(exports, "MERKLE_DISTRIBUTOR_IBEX", { enumerable: true, get: function () { return merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX; } });
|
|
21
|
+
Object.defineProperty(exports, "MERKLE_DISTRIBUTOR_IBEX_2", { enumerable: true, get: function () { return merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX_2; } });
|
|
22
|
+
const merkle_distributors_2 = require("./config/endpoints/merkle-distributors");
|
|
23
|
+
Object.defineProperty(exports, "MERKLE_URL_ETH", { enumerable: true, get: function () { return merkle_distributors_2.MERKLE_URL_ETH; } });
|
|
24
|
+
Object.defineProperty(exports, "MERKLE_URL_IBEX", { enumerable: true, get: function () { return merkle_distributors_2.MERKLE_URL_IBEX; } });
|
|
25
|
+
Object.defineProperty(exports, "MERKLE_URL_IBEX_2", { enumerable: true, get: function () { return merkle_distributors_2.MERKLE_URL_IBEX_2; } });
|
|
26
|
+
const routers_1 = require("./config/contracts/routers");
|
|
27
|
+
Object.defineProperty(exports, "ROUTER", { enumerable: true, get: function () { return routers_1.ROUTER; } });
|
|
28
|
+
const simple_uniswap_oracles_1 = require("./config/contracts/simple-uniswap-oracles");
|
|
29
|
+
Object.defineProperty(exports, "SIMPLE_UNISWAP_ORACLE", { enumerable: true, get: function () { return simple_uniswap_oracles_1.SIMPLE_UNISWAP_ORACLE; } });
|
|
30
|
+
const weths_1 = require("./config/contracts/weths");
|
|
31
|
+
Object.defineProperty(exports, "WETH", { enumerable: true, get: function () { return weths_1.WETH; } });
|
|
32
|
+
const amms_1 = require("./config/amms");
|
|
33
|
+
Object.defineProperty(exports, "ADD_LIQUIDITY_URLS", { enumerable: true, get: function () { return amms_1.ADD_LIQUIDITY_URLS; } });
|
|
34
|
+
Object.defineProperty(exports, "Amms", { enumerable: true, get: function () { return amms_1.Amms; } });
|
|
35
|
+
Object.defineProperty(exports, "AMM_FACTORY", { enumerable: true, get: function () { return amms_1.AMM_FACTORY; } });
|
|
36
|
+
Object.defineProperty(exports, "AMM_LP_FEE", { enumerable: true, get: function () { return amms_1.AMM_LP_FEE; } });
|
|
37
|
+
Object.defineProperty(exports, "AMM_SUBGRAPH_URLS", { enumerable: true, get: function () { return amms_1.AMM_SUBGRAPH_URLS; } });
|
|
38
|
+
Object.defineProperty(exports, "getAmmByFactory", { enumerable: true, get: function () { return amms_1.getAmmByFactory; } });
|
|
39
|
+
Object.defineProperty(exports, "hrAmms", { enumerable: true, get: function () { return amms_1.hrAmms; } });
|
|
40
|
+
const debank_ids_1 = require("./config/debank-ids");
|
|
41
|
+
Object.defineProperty(exports, "DEBANK_IDS", { enumerable: true, get: function () { return debank_ids_1.DEBANK_IDS; } });
|
|
42
|
+
const eth_1 = require("./config/eth");
|
|
43
|
+
Object.defineProperty(exports, "ETH_NAME", { enumerable: true, get: function () { return eth_1.ETH_NAME; } });
|
|
44
|
+
Object.defineProperty(exports, "ETH_SYMBOL", { enumerable: true, get: function () { return eth_1.ETH_SYMBOL; } });
|
|
45
|
+
const factories_1 = require("./config/factories");
|
|
46
|
+
Object.defineProperty(exports, "BORROW_FEE_FACTORIES", { enumerable: true, get: function () { return factories_1.BORROW_FEE_FACTORIES; } });
|
|
47
|
+
Object.defineProperty(exports, "LIQUIDATION_FEE_FACTORIES", { enumerable: true, get: function () { return factories_1.LIQUIDATION_FEE_FACTORIES; } });
|
|
48
|
+
Object.defineProperty(exports, "OLD_KINK_MULTIPLIER_FACTORIES", { enumerable: true, get: function () { return factories_1.OLD_KINK_MULTIPLIER_FACTORIES; } });
|
|
49
|
+
Object.defineProperty(exports, "SOLIDEX_FACTORIES", { enumerable: true, get: function () { return factories_1.SOLIDEX_FACTORIES; } });
|
|
50
|
+
Object.defineProperty(exports, "V2_FACTORIES", { enumerable: true, get: function () { return factories_1.V2_FACTORIES; } });
|
|
51
|
+
const farms_1 = require("./config/farms");
|
|
52
|
+
Object.defineProperty(exports, "Farms", { enumerable: true, get: function () { return farms_1.Farms; } });
|
|
53
|
+
Object.defineProperty(exports, "getFarmByStakedLPFactory", { enumerable: true, get: function () { return farms_1.getFarmByStakedLPFactory; } });
|
|
54
|
+
Object.defineProperty(exports, "hrFarms", { enumerable: true, get: function () { return farms_1.hrFarms; } });
|
|
55
|
+
Object.defineProperty(exports, "STAKED_LP_FACTORY", { enumerable: true, get: function () { return farms_1.STAKED_LP_FACTORY; } });
|
|
56
|
+
const general_1 = require("./config/general");
|
|
57
|
+
Object.defineProperty(exports, "APPROVE_AMOUNT", { enumerable: true, get: function () { return general_1.APPROVE_AMOUNT; } });
|
|
58
|
+
Object.defineProperty(exports, "DEADLINE", { enumerable: true, get: function () { return general_1.DEADLINE; } });
|
|
59
|
+
Object.defineProperty(exports, "NOT_SYNCED", { enumerable: true, get: function () { return general_1.NOT_SYNCED; } });
|
|
60
|
+
Object.defineProperty(exports, "ZERO", { enumerable: true, get: function () { return general_1.ZERO; } });
|
|
61
|
+
const subgraphs_1 = require("./config/subgraphs");
|
|
62
|
+
Object.defineProperty(exports, "BLOCKS_SUBGRAPH_URL", { enumerable: true, get: function () { return subgraphs_1.BLOCKS_SUBGRAPH_URL; } });
|
|
63
|
+
Object.defineProperty(exports, "IMPERMAX_CHEF_SUBGRAPH_URL", { enumerable: true, get: function () { return subgraphs_1.IMPERMAX_CHEF_SUBGRAPH_URL; } });
|
|
64
|
+
Object.defineProperty(exports, "IMPERMAX_SUBGRAPH_URL", { enumerable: true, get: function () { return subgraphs_1.IMPERMAX_SUBGRAPH_URL; } });
|
|
65
|
+
Object.defineProperty(exports, "XIMX_SUBGRAPH_URL", { enumerable: true, get: function () { return subgraphs_1.XIMX_SUBGRAPH_URL; } });
|
|
66
|
+
const types_1 = require("./config/types");
|
|
67
|
+
Object.defineProperty(exports, "Factory", { enumerable: true, get: function () { return types_1.Factory; } });
|
|
68
|
+
Object.defineProperty(exports, "Networks", { enumerable: true, get: function () { return types_1.Networks; } });
|
|
69
|
+
Object.defineProperty(exports, "PoolTokenType", { enumerable: true, get: function () { return types_1.PoolTokenType; } });
|
|
70
|
+
const Account_1 = __importDefault(require("./subgraph/Account"));
|
|
71
|
+
exports.SubgraphAccount = Account_1.default;
|
|
72
|
+
const AccountLendingPool_1 = __importDefault(require("./subgraph/AccountLendingPool"));
|
|
73
|
+
exports.SubgraphAccountLendingPool = AccountLendingPool_1.default;
|
|
74
|
+
const AccountPoolToken_1 = __importDefault(require("./subgraph/AccountPoolToken"));
|
|
75
|
+
exports.SubgraphAccountPoolToken = AccountPoolToken_1.default;
|
|
76
|
+
const LendingPool_1 = __importDefault(require("./subgraph/LendingPool"));
|
|
77
|
+
exports.SubgraphLendingPool = LendingPool_1.default;
|
|
78
|
+
const PoolToken_1 = __importDefault(require("./subgraph/PoolToken"));
|
|
79
|
+
exports.SubgraphPoolToken = PoolToken_1.default;
|
|
80
|
+
const PriceHelper_1 = __importDefault(require("./subgraph/PriceHelper"));
|
|
81
|
+
exports.PriceHelper = PriceHelper_1.default;
|
|
82
|
+
const SolidexHelper_1 = __importDefault(require("./subgraph/SolidexHelper"));
|
|
83
|
+
exports.SolidexHelper = SolidexHelper_1.default;
|
|
84
|
+
const Account_2 = __importDefault(require("./impermax-router/Account"));
|
|
85
|
+
exports.ImpermaxRouterAccount = Account_2.default;
|
|
86
|
+
const AccountPoolToken_2 = __importDefault(require("./impermax-router/AccountPoolToken"));
|
|
87
|
+
exports.ImpermaxRouterAccountPoolToken = AccountPoolToken_2.default;
|
|
88
|
+
const AccountLendingPool_2 = __importDefault(require("./impermax-router/AccountLendingPool"));
|
|
89
|
+
exports.ImpermaxRouterAccountLendingPool = AccountLendingPool_2.default;
|
|
90
|
+
const AccountBorrowable_1 = __importDefault(require("./impermax-router/AccountBorrowable"));
|
|
91
|
+
exports.AccountBorrowable = AccountBorrowable_1.default;
|
|
92
|
+
const AccountCollateral_1 = __importDefault(require("./impermax-router/AccountCollateral"));
|
|
93
|
+
exports.AccountCollateral = AccountCollateral_1.default;
|
|
94
|
+
const Borrowable_1 = __importDefault(require("./impermax-router/Borrowable"));
|
|
95
|
+
exports.Borrowable = Borrowable_1.default;
|
|
96
|
+
const Collateral_1 = __importDefault(require("./impermax-router/Collateral"));
|
|
97
|
+
exports.Collateral = Collateral_1.default;
|
|
98
|
+
const ContractsHelper_1 = __importDefault(require("./impermax-router/ContractsHelper"));
|
|
99
|
+
exports.ContractsHelper = ContractsHelper_1.default;
|
|
100
|
+
const ImpermaxFactory_1 = __importDefault(require("./impermax-router/ImpermaxFactory"));
|
|
101
|
+
exports.ImpermaxFactory = ImpermaxFactory_1.default;
|
|
102
|
+
const Interactions_1 = __importDefault(require("./impermax-router/Interactions"));
|
|
103
|
+
exports.Interactions = Interactions_1.default;
|
|
104
|
+
const InteractionsLendingPool_1 = __importDefault(require("./impermax-router/InteractionsLendingPool"));
|
|
105
|
+
exports.InteractionsLendingPool = InteractionsLendingPool_1.default;
|
|
106
|
+
const InteractionsPoolToken_1 = __importDefault(require("./impermax-router/InteractionsPoolToken"));
|
|
107
|
+
exports.InteractionsPoolToken = InteractionsPoolToken_1.default;
|
|
108
|
+
const LendingPool_2 = __importDefault(require("./impermax-router/LendingPool"));
|
|
109
|
+
exports.ImpermaxRouterLendingPool = LendingPool_2.default;
|
|
110
|
+
const PoolToken_2 = __importDefault(require("./impermax-router/PoolToken"));
|
|
111
|
+
exports.ImpermaxRouterPoolToken = PoolToken_2.default;
|
|
112
|
+
const types_2 = require("./impermax-router/types");
|
|
113
|
+
Object.defineProperty(exports, "ApprovalType", { enumerable: true, get: function () { return types_2.ApprovalType; } });
|
|
114
|
+
Object.defineProperty(exports, "NO_CHANGES", { enumerable: true, get: function () { return types_2.NO_CHANGES; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Subgraph from "./index";
|
|
2
|
+
import AccountLendingPool from "./AccountLendingPool";
|
|
3
|
+
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
4
|
+
import { UserData } from './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 Account from "./Account";
|
|
2
|
+
import AccountPoolToken from "./AccountPoolToken";
|
|
3
|
+
import LendingPool from "./LendingPool";
|
|
4
|
+
import { PoolTokenType } from '../config/types';
|
|
5
|
+
import { CollateralPosition, UserData } from './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;
|