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,27 @@
|
|
|
1
|
+
import { Contract } from "./interfaces";
|
|
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 "./interfaces";
|
|
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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
class Collateral extends PoolToken_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.collateralCache = {};
|
|
20
|
+
}
|
|
21
|
+
cleanCache() {
|
|
22
|
+
super.cleanCache();
|
|
23
|
+
this.collateralCache = {};
|
|
24
|
+
}
|
|
25
|
+
initializePoolToken() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.lendingPool.factory.router.contractsHelper.newCollateral(yield this.getPoolTokenAddressFromLendingPool());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
initializeToken() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return this.lendingPool.getUniswapV2Pair();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
initializeExchangeRate() {
|
|
36
|
+
const _super = Object.create(null, {
|
|
37
|
+
initializeExchangeRate: { get: () => super.initializeExchangeRate }
|
|
38
|
+
});
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let exchangeRate = yield _super.initializeExchangeRate.call(this);
|
|
41
|
+
return exchangeRate * (yield this.lendingPool.getStakedLPExchangeRate());
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = Collateral;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Contract } from "./interfaces";
|
|
2
|
+
import ImpermaxRouter from "./index";
|
|
3
|
+
import { Address } from '../config/types';
|
|
4
|
+
export default class ContractsHelper {
|
|
5
|
+
router: ImpermaxRouter;
|
|
6
|
+
impermaxChef: Contract;
|
|
7
|
+
merkleDistributorIbex: Contract;
|
|
8
|
+
merkleDistributorIbex2: Contract;
|
|
9
|
+
merkleDistributorEth: Contract;
|
|
10
|
+
claimAggregator: Contract;
|
|
11
|
+
constructor(router: ImpermaxRouter);
|
|
12
|
+
newContract: (abi: any, address: Address) => any;
|
|
13
|
+
newRouter: (address: Address) => any;
|
|
14
|
+
newFactory: (address: Address) => any;
|
|
15
|
+
newSimpleUniswapOracle: (address: Address) => any;
|
|
16
|
+
newUniswapV2Pair: (address: Address) => any;
|
|
17
|
+
newUniswapV2Factory: (address: Address) => any;
|
|
18
|
+
newERC20: (address: Address) => any;
|
|
19
|
+
newCollateral: (address: Address) => any;
|
|
20
|
+
newBorrowable: (address: Address) => any;
|
|
21
|
+
newStakedLPToken: (address: Address) => any;
|
|
22
|
+
newMerkleDistributor: (address: Address) => any;
|
|
23
|
+
newFarmingPool: (address: Address) => any;
|
|
24
|
+
newClaimAggregator: (address: Address) => any;
|
|
25
|
+
newClaimable: (address: Address) => any;
|
|
26
|
+
newStakingRewards: (address: Address) => any;
|
|
27
|
+
newImpermaxChef: (address: Address) => any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 IERC20_json_1 = __importDefault(require("../abis/contracts/IERC20.json"));
|
|
7
|
+
const IUniswapV2Pair_json_1 = __importDefault(require("../abis/contracts/IUniswapV2Pair.json"));
|
|
8
|
+
const IUniswapV2Factory_json_1 = __importDefault(require("../abis/contracts/IUniswapV2Factory.json"));
|
|
9
|
+
const IRouter02_json_1 = __importDefault(require("../abis/contracts/IRouter02.json"));
|
|
10
|
+
const IBorrowable_json_1 = __importDefault(require("../abis/contracts/IBorrowable.json"));
|
|
11
|
+
const ICollateral_json_1 = __importDefault(require("../abis/contracts/ICollateral.json"));
|
|
12
|
+
const IStakedLPToken_json_1 = __importDefault(require("../abis/contracts/IStakedLPToken.json"));
|
|
13
|
+
const IFactory_json_1 = __importDefault(require("../abis/contracts/IFactory.json"));
|
|
14
|
+
const ISimpleUniswapOracle_json_1 = __importDefault(require("../abis/contracts/ISimpleUniswapOracle.json"));
|
|
15
|
+
const IMerkleDistributor_json_1 = __importDefault(require("../abis/contracts/IMerkleDistributor.json"));
|
|
16
|
+
const IFarmingPool_json_1 = __importDefault(require("../abis/contracts/IFarmingPool.json"));
|
|
17
|
+
const ClaimAggregator_json_1 = __importDefault(require("../abis/contracts/ClaimAggregator.json"));
|
|
18
|
+
const IClaimable_json_1 = __importDefault(require("../abis/contracts/IClaimable.json"));
|
|
19
|
+
const IStakingRewards_json_1 = __importDefault(require("../abis/contracts/IStakingRewards.json"));
|
|
20
|
+
const ImpermaxChef_json_1 = __importDefault(require("../abis/contracts/ImpermaxChef.json"));
|
|
21
|
+
const impermax_chef_1 = require("../config/contracts/impermax-chef");
|
|
22
|
+
const claim_aggregators_1 = require("../config/contracts/claim-aggregators");
|
|
23
|
+
const merkle_distributors_1 = require("../config/contracts/merkle-distributors");
|
|
24
|
+
class ContractsHelper {
|
|
25
|
+
constructor(router) {
|
|
26
|
+
this.newContract = (abi, address) => new this.router.web3.eth.Contract(abi, address);
|
|
27
|
+
this.newRouter = (address) => this.newContract(IRouter02_json_1.default.abi, address);
|
|
28
|
+
this.newFactory = (address) => this.newContract(IFactory_json_1.default.abi, address);
|
|
29
|
+
this.newSimpleUniswapOracle = (address) => this.newContract(ISimpleUniswapOracle_json_1.default.abi, address);
|
|
30
|
+
this.newUniswapV2Pair = (address) => this.newContract(IUniswapV2Pair_json_1.default.abi, address);
|
|
31
|
+
this.newUniswapV2Factory = (address) => this.newContract(IUniswapV2Factory_json_1.default.abi, address);
|
|
32
|
+
this.newERC20 = (address) => this.newContract(IERC20_json_1.default.abi, address);
|
|
33
|
+
this.newCollateral = (address) => this.newContract(ICollateral_json_1.default.abi, address);
|
|
34
|
+
this.newBorrowable = (address) => this.newContract(IBorrowable_json_1.default.abi, address);
|
|
35
|
+
this.newStakedLPToken = (address) => this.newContract(IStakedLPToken_json_1.default.abi, address);
|
|
36
|
+
this.newMerkleDistributor = (address) => this.newContract(IMerkleDistributor_json_1.default.abi, address);
|
|
37
|
+
this.newFarmingPool = (address) => this.newContract(IFarmingPool_json_1.default.abi, address);
|
|
38
|
+
this.newClaimAggregator = (address) => this.newContract(ClaimAggregator_json_1.default.abi, address);
|
|
39
|
+
this.newClaimable = (address) => this.newContract(IClaimable_json_1.default.abi, address);
|
|
40
|
+
this.newStakingRewards = (address) => this.newContract(IStakingRewards_json_1.default.abi, address);
|
|
41
|
+
this.newImpermaxChef = (address) => this.newContract(ImpermaxChef_json_1.default.abi, address);
|
|
42
|
+
this.router = router;
|
|
43
|
+
this.impermaxChef = this.newImpermaxChef(impermax_chef_1.IMPERMAX_CHEF[this.router.network]);
|
|
44
|
+
this.merkleDistributorIbex = this.newMerkleDistributor(merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX[this.router.network]);
|
|
45
|
+
this.merkleDistributorIbex2 = this.newMerkleDistributor(merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX_2[this.router.network]);
|
|
46
|
+
this.merkleDistributorEth = this.newMerkleDistributor(merkle_distributors_1.MERKLE_DISTRIBUTOR_ETH[this.router.network]);
|
|
47
|
+
this.claimAggregator = this.newClaimAggregator(claim_aggregators_1.CLAIM_AGGREGATOR[this.router.network]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = ContractsHelper;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ImpermaxRouter from "./index";
|
|
2
|
+
import LendingPool from "./LendingPool";
|
|
3
|
+
import { Address, Factory } from '../config/types';
|
|
4
|
+
export default class ImpermaxFactory {
|
|
5
|
+
router: ImpermaxRouter;
|
|
6
|
+
factory: Factory;
|
|
7
|
+
lendingPools: {
|
|
8
|
+
[key in Address]: LendingPool;
|
|
9
|
+
};
|
|
10
|
+
constructor(router: ImpermaxRouter, factory: Factory);
|
|
11
|
+
cleanCache(): void;
|
|
12
|
+
getSimpleUniswapOracle(): any;
|
|
13
|
+
getRouter(): any;
|
|
14
|
+
getLendingPool(uniswapV2PairAddress: Address): LendingPool;
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 LendingPool_1 = __importDefault(require("./LendingPool"));
|
|
7
|
+
const simple_uniswap_oracles_1 = require("../config/contracts/simple-uniswap-oracles");
|
|
8
|
+
const routers_1 = require("../config/contracts/routers");
|
|
9
|
+
class ImpermaxFactory {
|
|
10
|
+
constructor(router, factory) {
|
|
11
|
+
this.router = router;
|
|
12
|
+
this.factory = factory;
|
|
13
|
+
this.lendingPools = {};
|
|
14
|
+
}
|
|
15
|
+
cleanCache() {
|
|
16
|
+
for (const pairAddress of Object.keys(this.lendingPools)) {
|
|
17
|
+
this.lendingPools[pairAddress].cleanCache();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getSimpleUniswapOracle() {
|
|
21
|
+
const address = simple_uniswap_oracles_1.SIMPLE_UNISWAP_ORACLE[this.router.network][this.factory];
|
|
22
|
+
if (!address) {
|
|
23
|
+
console.error("SimpleUniswapOracle address not found");
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return this.router.contractsHelper.newSimpleUniswapOracle(address);
|
|
27
|
+
}
|
|
28
|
+
getRouter() {
|
|
29
|
+
const address = routers_1.ROUTER[this.router.network][this.factory];
|
|
30
|
+
if (!address) {
|
|
31
|
+
console.error("Router address not found");
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return this.router.contractsHelper.newRouter(address);
|
|
35
|
+
}
|
|
36
|
+
getLendingPool(uniswapV2PairAddress) {
|
|
37
|
+
if (!this.lendingPools[uniswapV2PairAddress])
|
|
38
|
+
this.lendingPools[uniswapV2PairAddress] = new LendingPool_1.default(this, uniswapV2PairAddress);
|
|
39
|
+
return this.lendingPools[uniswapV2PairAddress];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = ImpermaxFactory;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import Account from "./Account";
|
|
3
|
+
import InteractionsLendingPool from "./InteractionsLendingPool";
|
|
4
|
+
import { AirdropData, Contract } from "./interfaces";
|
|
5
|
+
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
6
|
+
export default class Interactions {
|
|
7
|
+
account: Account;
|
|
8
|
+
interactionsLLPs: LendingPoolIndex<Promise<InteractionsLendingPool>>;
|
|
9
|
+
constructor(account: Account);
|
|
10
|
+
private initializeInteractionsLendingPool;
|
|
11
|
+
getInteractionsLendingPool(factory: Factory, pair: Address): Promise<InteractionsLendingPool>;
|
|
12
|
+
send(method: any, onTransactionHash: Function, value?: BigNumber): Promise<any>;
|
|
13
|
+
claimAirdrop(airdropData: AirdropData, merkleDistributor: Contract, onTransactionHash: Function): Promise<any>;
|
|
14
|
+
claims(pairAddresses: FactoryIndex<Address[]>, onTransactionHash: Function): Promise<any>;
|
|
15
|
+
claimDistributor(claimableAddress: Address, onTransactionHash: Function): Promise<any>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 ethers_1 = require("ethers");
|
|
16
|
+
const InteractionsLendingPool_1 = __importDefault(require("./InteractionsLendingPool"));
|
|
17
|
+
const types_1 = require("../config/types");
|
|
18
|
+
const ZERO = ethers_1.BigNumber.from(0);
|
|
19
|
+
class Interactions {
|
|
20
|
+
constructor(account) {
|
|
21
|
+
this.account = account;
|
|
22
|
+
this.interactionsLLPs = {};
|
|
23
|
+
}
|
|
24
|
+
initializeInteractionsLendingPool(factory, pair) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const lendingPool = yield this.account.getAccountLendingPool(factory, pair);
|
|
27
|
+
return new InteractionsLendingPool_1.default(this, lendingPool);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getInteractionsLendingPool(factory, pair) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (!this.interactionsLLPs[factory])
|
|
33
|
+
this.interactionsLLPs[factory] = {};
|
|
34
|
+
if (!this.interactionsLLPs[factory][pair])
|
|
35
|
+
this.interactionsLLPs[factory][pair] = this.initializeInteractionsLendingPool(factory, pair);
|
|
36
|
+
return this.interactionsLLPs[factory][pair];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
send(method, onTransactionHash, value = ZERO) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
try {
|
|
42
|
+
yield method.call({ from: this.account.account, value });
|
|
43
|
+
return method.send({ from: this.account.account, value }).on('transactionHash', onTransactionHash);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
claimAirdrop(airdropData, merkleDistributor, onTransactionHash) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return this.send(merkleDistributor.methods.claim(airdropData.index, this.account.account, airdropData.amount, airdropData.proof), onTransactionHash);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
claims(pairAddresses, onTransactionHash) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const requests = [];
|
|
58
|
+
for (const factory of Object.keys(pairAddresses)) {
|
|
59
|
+
for (const pairAddress of pairAddresses[factory]) {
|
|
60
|
+
for (const poolToken of [types_1.PoolTokenType.BorrowableA, types_1.PoolTokenType.BorrowableB]) {
|
|
61
|
+
requests.push((() => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const accountBorrowable = (yield this.account.getAccountLendingPool(factory, pairAddress)).accountPoolTokens[poolToken];
|
|
63
|
+
const borrowable = accountBorrowable.poolToken;
|
|
64
|
+
const pendingReward = (yield accountBorrowable.getAvailableIMXReward()) + (yield accountBorrowable.getAvailableRewarderReward());
|
|
65
|
+
return {
|
|
66
|
+
hasPendingReward: pendingReward > 0,
|
|
67
|
+
hasImpermaxChef: yield borrowable.hasImpermaxChef(),
|
|
68
|
+
farmingPool: yield borrowable.getFarmingPool(),
|
|
69
|
+
borrowableAddress: yield borrowable.getPoolTokenAddress(),
|
|
70
|
+
};
|
|
71
|
+
}))());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const data = yield Promise.all(requests);
|
|
76
|
+
const toClaimThroughChef = [];
|
|
77
|
+
const toClaimThroughAggregator = [];
|
|
78
|
+
for (const borrowable of data) {
|
|
79
|
+
if (!borrowable.hasPendingReward)
|
|
80
|
+
continue;
|
|
81
|
+
if (borrowable.hasImpermaxChef) {
|
|
82
|
+
toClaimThroughChef.push(borrowable.borrowableAddress);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
toClaimThroughAggregator.push(borrowable.farmingPool._address);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (toClaimThroughAggregator.length > 0) {
|
|
89
|
+
const claimAggregator = this.account.router.contractsHelper.claimAggregator;
|
|
90
|
+
return this.send(claimAggregator.methods.claims(this.account.account, toClaimThroughAggregator), onTransactionHash);
|
|
91
|
+
}
|
|
92
|
+
else if (toClaimThroughChef.length > 0) {
|
|
93
|
+
const impermaxChef = this.account.router.contractsHelper.impermaxChef;
|
|
94
|
+
return this.send(impermaxChef.methods.massHarvest(toClaimThroughChef, this.account.account), onTransactionHash);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
claimDistributor(claimableAddress, onTransactionHash) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const claimable = this.account.router.contractsHelper.newClaimable(claimableAddress);
|
|
101
|
+
return this.send(claimable.methods.claim(), onTransactionHash);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.default = Interactions;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Interactions from "./Interactions";
|
|
2
|
+
import AccountLendingPool from "./AccountLendingPool";
|
|
3
|
+
import InteractionsPoolToken from "./InteractionsPoolToken";
|
|
4
|
+
import { BigNumber } from "ethers";
|
|
5
|
+
import { PoolTokenType } from '../config/types';
|
|
6
|
+
import { PermitData } from './interfaces';
|
|
7
|
+
export default class InteractionsLendingPool {
|
|
8
|
+
interactions: Interactions;
|
|
9
|
+
accountLendingPool: AccountLendingPool;
|
|
10
|
+
interactionsPoolToken: {
|
|
11
|
+
[PoolTokenType.Collateral]: InteractionsPoolToken;
|
|
12
|
+
[PoolTokenType.BorrowableA]: InteractionsPoolToken;
|
|
13
|
+
[PoolTokenType.BorrowableB]: InteractionsPoolToken;
|
|
14
|
+
};
|
|
15
|
+
constructor(interactions: Interactions, accountLendingPool: AccountLendingPool);
|
|
16
|
+
getRouterLendingPool: () => import("./LendingPool").default;
|
|
17
|
+
getRouterContract: () => any;
|
|
18
|
+
getAccount: () => string;
|
|
19
|
+
send: (method: any, onTransactionHash: Function) => Promise<any>;
|
|
20
|
+
getOwnerSpender(): {
|
|
21
|
+
owner: string;
|
|
22
|
+
spender: any;
|
|
23
|
+
};
|
|
24
|
+
getLeverageAmounts(leverage: number, slippage: number): Promise<{
|
|
25
|
+
bAmountA: number;
|
|
26
|
+
bAmountB: number;
|
|
27
|
+
cAmount: number;
|
|
28
|
+
bAmountAMin: number;
|
|
29
|
+
bAmountBMin: number;
|
|
30
|
+
cAmountMin: number;
|
|
31
|
+
}>;
|
|
32
|
+
leverage(amountA: BigNumber, amountB: BigNumber, amountAMin: BigNumber, amountBMin: BigNumber, permitDataA: PermitData, permitDataB: PermitData, onTransactionHash: Function): Promise<any>;
|
|
33
|
+
getDeleverageAmounts(changeCollateralAmount: number, slippage: number): Promise<{
|
|
34
|
+
bAmountA: number;
|
|
35
|
+
bAmountB: number;
|
|
36
|
+
cAmount: number;
|
|
37
|
+
bAmountAMin: number;
|
|
38
|
+
bAmountBMin: number;
|
|
39
|
+
}>;
|
|
40
|
+
deleverage(tokens: BigNumber, amountAMin: BigNumber, amountBMin: BigNumber, permitData: PermitData, onTransactionHash: Function): Promise<any>;
|
|
41
|
+
trackBorrows(onTransactionHash: Function): Promise<any>;
|
|
42
|
+
reinvest(onTransactionHash: Function): Promise<any>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 InteractionsPoolToken_1 = __importDefault(require("./InteractionsPoolToken"));
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const types_1 = require("../config/types");
|
|
18
|
+
const general_1 = require("../config/general");
|
|
19
|
+
class InteractionsLendingPool {
|
|
20
|
+
constructor(interactions, accountLendingPool) {
|
|
21
|
+
this.getRouterLendingPool = () => this.accountLendingPool.lendingPool;
|
|
22
|
+
this.getRouterContract = () => this.accountLendingPool.lendingPool.factory.getRouter();
|
|
23
|
+
this.getAccount = () => this.accountLendingPool.account.account;
|
|
24
|
+
this.send = (method, onTransactionHash) => this.interactions.send(method, onTransactionHash);
|
|
25
|
+
this.interactions = interactions;
|
|
26
|
+
this.accountLendingPool = accountLendingPool;
|
|
27
|
+
this.interactionsPoolToken = {
|
|
28
|
+
[types_1.PoolTokenType.Collateral]: new InteractionsPoolToken_1.default(this, types_1.PoolTokenType.Collateral),
|
|
29
|
+
[types_1.PoolTokenType.BorrowableA]: new InteractionsPoolToken_1.default(this, types_1.PoolTokenType.BorrowableA),
|
|
30
|
+
[types_1.PoolTokenType.BorrowableB]: new InteractionsPoolToken_1.default(this, types_1.PoolTokenType.BorrowableB),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
getOwnerSpender() {
|
|
34
|
+
const router = this.accountLendingPool.lendingPool.factory.getRouter();
|
|
35
|
+
return {
|
|
36
|
+
owner: this.accountLendingPool.account.account,
|
|
37
|
+
spender: router._address,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
getLeverageAmounts(leverage, slippage) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const [priceA, priceB] = yield this.accountLendingPool.lendingPool.getMarketPriceDenomLP();
|
|
43
|
+
// This function must use the market price, but the account leverage is calculated with the TWAP, so we need an adjustFactor
|
|
44
|
+
const [priceATWAP, priceBTWAP] = yield this.accountLendingPool.lendingPool.getPriceDenomLP();
|
|
45
|
+
const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
|
|
46
|
+
const adjustFactor = Math.pow((0, utils_1.impermanentLoss)(Math.pow(diff, 2)), leverage);
|
|
47
|
+
const currentLeverage = yield this.accountLendingPool.getLeverage();
|
|
48
|
+
const collateralValue = yield this.accountLendingPool.ptc().getDeposited();
|
|
49
|
+
const changeCollateralValue = (collateralValue * leverage / currentLeverage - collateralValue) * adjustFactor;
|
|
50
|
+
const valueForEach = changeCollateralValue / 2;
|
|
51
|
+
const bAmountA = priceA > 0 ? valueForEach / priceA : 0;
|
|
52
|
+
const bAmountB = priceB > 0 ? valueForEach / priceB : 0;
|
|
53
|
+
const cAmount = changeCollateralValue ? changeCollateralValue : 0;
|
|
54
|
+
return {
|
|
55
|
+
bAmountA: bAmountA,
|
|
56
|
+
bAmountB: bAmountB,
|
|
57
|
+
cAmount: cAmount,
|
|
58
|
+
bAmountAMin: bAmountA / slippage,
|
|
59
|
+
bAmountBMin: bAmountB / slippage,
|
|
60
|
+
cAmountMin: cAmount / Math.sqrt(slippage),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
leverage(amountA, amountB, amountAMin, amountBMin, permitDataA, permitDataB, onTransactionHash) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const router = this.getRouterContract();
|
|
67
|
+
const dataA = permitDataA ? permitDataA.permitData : '0x';
|
|
68
|
+
const dataB = permitDataB ? permitDataB.permitData : '0x';
|
|
69
|
+
if (permitDataA && permitDataB && !permitDataA.deadline.eq(permitDataB.deadline))
|
|
70
|
+
return console.error("Permits deadline are not equal");
|
|
71
|
+
const deadline = permitDataA ? permitDataA.deadline : permitDataB ? permitDataB.deadline : general_1.DEADLINE;
|
|
72
|
+
const pairAddress = this.getRouterLendingPool().pairAddress;
|
|
73
|
+
const account = this.accountLendingPool.account.account;
|
|
74
|
+
return this.send(router.methods.leverage(pairAddress, amountA, amountB, amountAMin, amountBMin, account, deadline, dataA, dataB), onTransactionHash);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
getDeleverageAmounts(changeCollateralAmount, slippage) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
changeCollateralAmount = changeCollateralAmount !== null && changeCollateralAmount !== void 0 ? changeCollateralAmount : 0;
|
|
80
|
+
const [priceA, priceB] = yield this.accountLendingPool.lendingPool.getMarketPriceDenomLP();
|
|
81
|
+
const valueForEach = changeCollateralAmount / 2;
|
|
82
|
+
const bAmountA = priceA > 0 ? valueForEach / priceA : 0;
|
|
83
|
+
const bAmountB = priceB > 0 ? valueForEach / priceB : 0;
|
|
84
|
+
return {
|
|
85
|
+
bAmountA: bAmountA,
|
|
86
|
+
bAmountB: bAmountB,
|
|
87
|
+
cAmount: changeCollateralAmount,
|
|
88
|
+
bAmountAMin: bAmountA / Math.sqrt(slippage),
|
|
89
|
+
bAmountBMin: bAmountB / Math.sqrt(slippage),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
deleverage(tokens, amountAMin, amountBMin, permitData, onTransactionHash) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const router = this.getRouterContract();
|
|
96
|
+
const data = permitData ? permitData.permitData : '0x';
|
|
97
|
+
const deadline = permitData ? permitData.deadline : general_1.DEADLINE;
|
|
98
|
+
const pairAddress = this.getRouterLendingPool().pairAddress;
|
|
99
|
+
return this.send(router.methods.deleverage(pairAddress, tokens, amountAMin, amountBMin, deadline, data), onTransactionHash);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
trackBorrows(onTransactionHash) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const account = this.accountLendingPool.account.account;
|
|
105
|
+
const claimAggregator = this.interactions.account.router.contractsHelper.claimAggregator;
|
|
106
|
+
const toTrack = [];
|
|
107
|
+
for (const borrowable of [types_1.PoolTokenType.BorrowableA, types_1.PoolTokenType.BorrowableB]) {
|
|
108
|
+
const b = this.accountLendingPool.accountPoolTokens[borrowable];
|
|
109
|
+
if ((yield b.getBorrowed()) === 0 || (yield b.getFarmingShares()) > 0)
|
|
110
|
+
continue;
|
|
111
|
+
toTrack.push(yield this.getRouterLendingPool().poolTokens[borrowable].getPoolTokenAddress());
|
|
112
|
+
}
|
|
113
|
+
return this.send(claimAggregator.methods.trackBorrows(account, toTrack), onTransactionHash);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
reinvest(onTransactionHash) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const account = this.accountLendingPool.account.account;
|
|
119
|
+
const stakedLPToken = yield this.getRouterLendingPool().getStakedLPToken();
|
|
120
|
+
return this.send(stakedLPToken.methods.reinvest(), onTransactionHash);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.default = InteractionsLendingPool;
|