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,462 @@
|
|
|
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 types_1 = require("../config/types");
|
|
14
|
+
const eth_1 = require("../config/eth");
|
|
15
|
+
const imxes_1 = require("../config/contracts/imxes");
|
|
16
|
+
const weths_1 = require("../config/contracts/weths");
|
|
17
|
+
class PoolToken {
|
|
18
|
+
constructor(lendingPool, poolTokenType) {
|
|
19
|
+
this.lendingPool = lendingPool;
|
|
20
|
+
this.poolTokenType = poolTokenType;
|
|
21
|
+
}
|
|
22
|
+
// Subgraph calls
|
|
23
|
+
getPoolTokenData() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const lendingPoolData = yield this.lendingPool.getLendingPoolData();
|
|
26
|
+
return lendingPoolData[this.poolTokenType];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Helpers
|
|
30
|
+
getPoolTokenParam(param) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const poolTokenData = yield this.getPoolTokenData();
|
|
33
|
+
return poolTokenData[param];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getPoolTokenParamFloat(param) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return parseFloat(yield this.getPoolTokenParam(param));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getUnderlyingParam(param) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const poolTokenData = yield this.getPoolTokenData();
|
|
44
|
+
return poolTokenData.underlying[param];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Name
|
|
48
|
+
getName() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (this.poolTokenType == types_1.PoolTokenType.Collateral) {
|
|
51
|
+
const nameA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getName();
|
|
52
|
+
const nameB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getName();
|
|
53
|
+
return nameA + '-' + nameB + ' LP';
|
|
54
|
+
}
|
|
55
|
+
const underlying = yield this.getUnderlyingAddress();
|
|
56
|
+
if (underlying.toLowerCase() === weths_1.WETH[this.lendingPool.subgraph.network].toLowerCase())
|
|
57
|
+
return eth_1.ETH_NAME[this.lendingPool.subgraph.network];
|
|
58
|
+
if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
|
|
59
|
+
return "MIMATIC";
|
|
60
|
+
if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
|
|
61
|
+
return "Maker";
|
|
62
|
+
return this.getUnderlyingParam("name");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Symbol
|
|
66
|
+
getSymbol() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (this.poolTokenType == types_1.PoolTokenType.Collateral) {
|
|
69
|
+
const symbolA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getSymbol();
|
|
70
|
+
const symbolB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getSymbol();
|
|
71
|
+
return symbolA + '-' + symbolB;
|
|
72
|
+
}
|
|
73
|
+
const underlying = yield this.getUnderlyingAddress();
|
|
74
|
+
if (underlying.toLowerCase() === weths_1.WETH[this.lendingPool.subgraph.network].toLowerCase())
|
|
75
|
+
return eth_1.ETH_SYMBOL[this.lendingPool.subgraph.network];
|
|
76
|
+
if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
|
|
77
|
+
return "MAI";
|
|
78
|
+
if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
|
|
79
|
+
return "MKR";
|
|
80
|
+
if (underlying.toLowerCase() === "0xc165d941481e68696f43ee6e99bfb2b23e0e3114")
|
|
81
|
+
return "OXDv1";
|
|
82
|
+
if (underlying.toLowerCase() === "0xc5a9848b9d145965d821aaec8fa32aaee026492d")
|
|
83
|
+
return "OXDv2";
|
|
84
|
+
if (underlying.toLowerCase() === "0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c")
|
|
85
|
+
return "JPYCv1";
|
|
86
|
+
if (underlying.toLowerCase() === "0x431d5dff03120afa4bdf332c61a6e1766ef37bdb")
|
|
87
|
+
return "JPYCv2";
|
|
88
|
+
return this.getUnderlyingParam("symbol");
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Decimals
|
|
92
|
+
getDecimals() {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (this.poolTokenType == types_1.PoolTokenType.Collateral)
|
|
95
|
+
return 18;
|
|
96
|
+
return parseInt(yield this.getUnderlyingParam("decimals"));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// ExchangeRate
|
|
100
|
+
getExchangeRate() {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return this.getPoolTokenParamFloat("exchangeRate");
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Underlying Address
|
|
106
|
+
getUnderlyingAddress() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
if (this.poolTokenType == types_1.PoolTokenType.Collateral)
|
|
109
|
+
return this.lendingPool.pairAddress;
|
|
110
|
+
return this.getUnderlyingParam("id");
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Total balance
|
|
114
|
+
getTotalBalance() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this.getPoolTokenParamFloat("totalBalance");
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
getTotalBalanceUSD() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const totalBalance = yield this.getTotalBalance();
|
|
122
|
+
const tokenPrice = yield this.getTokenPriceFast();
|
|
123
|
+
return totalBalance * tokenPrice;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Reserve Factor
|
|
127
|
+
getReserveFactor() {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return this.getPoolTokenParamFloat("reserveFactor");
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// Kink Borrow Rate
|
|
133
|
+
getKinkBorrowRate() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return this.getPoolTokenParamFloat("kinkBorrowRate");
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Kink Utilization Rate
|
|
139
|
+
getKinkUtilizationRate() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
return this.getPoolTokenParamFloat("kinkUtilizationRate");
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// Borrow Index
|
|
145
|
+
getBorrowIndex() {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
return this.getPoolTokenParamFloat("borrowIndex");
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Accrue Timestamp
|
|
151
|
+
getAccrualTimestamp() {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this.getPoolTokenParamFloat("accrualTimestamp");
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
// Total borrows
|
|
157
|
+
getTotalBorrows() {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
return this.getPoolTokenParamFloat("totalBorrows");
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
getCurrentTotalBorrows() {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const storedAmount = yield this.getTotalBorrows();
|
|
165
|
+
const accrualTimestamp = yield this.getAccrualTimestamp();
|
|
166
|
+
const borrowRate = yield this.getBorrowRate();
|
|
167
|
+
return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
getTotalBorrowsUSD() {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const totalBorrows = yield this.getCurrentTotalBorrows();
|
|
173
|
+
const tokenPrice = yield this.getTokenPriceFast();
|
|
174
|
+
return totalBorrows * tokenPrice;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// Borrow rate
|
|
178
|
+
getBorrowRate() {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
return this.getPoolTokenParamFloat("borrowRate");
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
getBorrowAPR() {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const borrowRate = yield this.getBorrowRate();
|
|
186
|
+
return (0, utils_1.toAPR)(borrowRate);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
getNextBorrowRate(borrowAmount) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const totalBorrows = yield this.getTotalBorrows();
|
|
192
|
+
const supply = yield this.getSupply();
|
|
193
|
+
const UR = (borrowAmount + totalBorrows) / supply;
|
|
194
|
+
const kinkBR = yield this.getKinkBorrowRate();
|
|
195
|
+
const kinkUR = yield this.getKinkUtilizationRate();
|
|
196
|
+
if (UR < kinkUR)
|
|
197
|
+
return UR / kinkUR * kinkBR;
|
|
198
|
+
const kinkMultiplier = this.lendingPool.getKinkMultiplier();
|
|
199
|
+
return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getNextBorrowAPR(borrowAmount) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const borrowRate = yield this.getNextBorrowRate(borrowAmount);
|
|
205
|
+
return (0, utils_1.toAPR)(borrowRate);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// Supply
|
|
209
|
+
getSupply() {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const totalBalance = yield this.getTotalBalance();
|
|
212
|
+
const totalBorrows = yield this.getTotalBorrows();
|
|
213
|
+
return totalBalance + totalBorrows;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getCurrentSupply() {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const storedAmount = yield this.getSupply();
|
|
219
|
+
const accrualTimestamp = yield this.getAccrualTimestamp();
|
|
220
|
+
const supplyRate = yield this.getSupplyRate();
|
|
221
|
+
return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * supplyRate);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
getSupplyUSD() {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const supply = yield this.getCurrentSupply();
|
|
227
|
+
const tokenPrice = yield this.getTokenPriceFast();
|
|
228
|
+
return supply * tokenPrice;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// Utilization Rate
|
|
232
|
+
getUtilizationRate() {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
const supply = yield this.getSupply();
|
|
235
|
+
if (supply == 0)
|
|
236
|
+
return 0;
|
|
237
|
+
const totalBalance = yield this.getTotalBorrows();
|
|
238
|
+
return totalBalance / supply;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Supply Rate
|
|
242
|
+
getSupplyRate() {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const borrowRate = yield this.getBorrowRate();
|
|
245
|
+
const utilizationRate = yield this.getUtilizationRate();
|
|
246
|
+
const reserveFactor = yield this.getReserveFactor();
|
|
247
|
+
return borrowRate * utilizationRate * (1 - reserveFactor);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
getSupplyAPR() {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
const supplyRate = yield this.getSupplyRate();
|
|
253
|
+
return (0, utils_1.toAPR)(supplyRate);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
getNextSupplyRate(supplyAmount) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
const totalBorrows = yield this.getTotalBorrows();
|
|
259
|
+
const supply = yield this.getSupply();
|
|
260
|
+
const UR = totalBorrows / (supply + supplyAmount);
|
|
261
|
+
const kinkBR = yield this.getKinkBorrowRate();
|
|
262
|
+
const kinkUR = yield this.getKinkUtilizationRate();
|
|
263
|
+
const reserveFactor = yield this.getReserveFactor();
|
|
264
|
+
if (UR < kinkUR)
|
|
265
|
+
return UR / kinkUR * kinkBR * UR * (1 - reserveFactor);
|
|
266
|
+
const kinkMultiplier = this.lendingPool.getKinkMultiplier();
|
|
267
|
+
return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR * UR * (1 - reserveFactor);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
getNextSupplyAPR(supplyAmount) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
const supplyRate = yield this.getNextSupplyRate(supplyAmount);
|
|
273
|
+
return (0, utils_1.toAPR)(supplyRate);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
// Reward Speed
|
|
277
|
+
getFarmingRewardsRate() {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
const poolTokenData = yield this.getPoolTokenData();
|
|
280
|
+
const rewards = poolTokenData.rewards;
|
|
281
|
+
if (rewards && rewards.length > 0)
|
|
282
|
+
return rewards;
|
|
283
|
+
const FINISH_DELAY = 3600 * 24;
|
|
284
|
+
const farmingPoolData = poolTokenData.farmingPool;
|
|
285
|
+
if (farmingPoolData === null)
|
|
286
|
+
return [];
|
|
287
|
+
const segmentLength = parseInt(farmingPoolData.segmentLength);
|
|
288
|
+
const epochAmount = parseFloat(farmingPoolData.epochAmount);
|
|
289
|
+
const epochBegin = parseInt(farmingPoolData.epochBegin);
|
|
290
|
+
const epochEnd = epochBegin + segmentLength;
|
|
291
|
+
const timestamp = (new Date()).getTime() / 1000;
|
|
292
|
+
if (timestamp - FINISH_DELAY > epochEnd) {
|
|
293
|
+
// How to manage better this case? Maybe check shares on distributor
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
return [{
|
|
297
|
+
rewardToken: imxes_1.IMX[this.lendingPool.subgraph.network],
|
|
298
|
+
rewardRate: epochAmount / segmentLength
|
|
299
|
+
}];
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
// Farming
|
|
303
|
+
getFarmingRewards() {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
return this.getNextFarmingRewards(0);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
getNextFarmingRewards(borrowAmount) {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
const farmingRewards = yield this.getFarmingRewardsRate();
|
|
311
|
+
const currentBorrowedUSD = yield this.getTotalBorrowsUSD();
|
|
312
|
+
const tokenPrice = yield this.getTokenPriceFast();
|
|
313
|
+
const additionalBorrowsUSD = borrowAmount * tokenPrice;
|
|
314
|
+
const totalBorrowedUSD = currentBorrowedUSD + additionalBorrowsUSD;
|
|
315
|
+
if (totalBorrowedUSD === 0)
|
|
316
|
+
return [];
|
|
317
|
+
const rewards = [];
|
|
318
|
+
for (const reward of farmingRewards) {
|
|
319
|
+
const rewardPrice = yield this.lendingPool.subgraph.priceHelper.getDebankTokenPrice(reward.rewardToken);
|
|
320
|
+
rewards.push({
|
|
321
|
+
APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
|
|
322
|
+
symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
|
|
323
|
+
reward.rewardToken == "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270" ? "WMATIC" :
|
|
324
|
+
"IMX",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return rewards;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
getFarmingAPR() {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
332
|
+
return this.getNextFarmingAPR(0);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
getNextFarmingAPR(borrowAmount) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
const rewards = yield this.getNextFarmingRewards(borrowAmount);
|
|
338
|
+
let APR = 0;
|
|
339
|
+
for (const reward of rewards) {
|
|
340
|
+
APR += reward.APR;
|
|
341
|
+
}
|
|
342
|
+
return APR;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
// Past Data
|
|
346
|
+
getPoolTokenDataPast24h() {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast24h();
|
|
349
|
+
if (!lendingPoolDataPast)
|
|
350
|
+
return undefined;
|
|
351
|
+
return lendingPoolDataPast[this.poolTokenType];
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
getPoolTokenDataPast7d() {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast7d();
|
|
357
|
+
if (!lendingPoolDataPast)
|
|
358
|
+
return undefined;
|
|
359
|
+
return lendingPoolDataPast[this.poolTokenType];
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
// Average Borrow APR
|
|
363
|
+
getAverageBorrowAPR(poolTokenDataPast, fallback) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
if (poolTokenDataPast) {
|
|
366
|
+
const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
|
|
367
|
+
const borrowIndexPast = parseFloat(poolTokenDataPast.borrowIndex);
|
|
368
|
+
const accrualTimestampNow = yield this.getAccrualTimestamp();
|
|
369
|
+
const borrowIndexNow = yield this.getBorrowIndex();
|
|
370
|
+
if (accrualTimestampNow > accrualTimestampPast) {
|
|
371
|
+
const borrowRate = (borrowIndexNow / borrowIndexPast - 1) / (accrualTimestampNow - accrualTimestampPast);
|
|
372
|
+
return borrowRate * 3600 * 24 * 365;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return fallback;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
getAverage24hBorrowAPR() {
|
|
379
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
|
|
381
|
+
return this.getAverageBorrowAPR(poolTokenDataPast, this.getBorrowAPR());
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
getAverage7dBorrowAPR() {
|
|
385
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
+
const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
|
|
387
|
+
return this.getAverageBorrowAPR(poolTokenDataPast, this.getAverage24hBorrowAPR());
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
// Average Supply APR
|
|
391
|
+
getAverageSupplyAPR(poolTokenDataPast, fallback) {
|
|
392
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
+
if (poolTokenDataPast) {
|
|
394
|
+
const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
|
|
395
|
+
const exchangeRatePast = parseFloat(poolTokenDataPast.exchangeRate);
|
|
396
|
+
const accrualTimestampNow = yield this.getAccrualTimestamp();
|
|
397
|
+
const exchangeRateNow = yield this.getExchangeRate();
|
|
398
|
+
if (accrualTimestampNow > accrualTimestampPast) {
|
|
399
|
+
const supplyRate = (exchangeRateNow / exchangeRatePast - 1) / (accrualTimestampNow - accrualTimestampPast);
|
|
400
|
+
return supplyRate * 3600 * 24 * 365;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return fallback;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
getAverage24hSupplyAPR() {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
+
const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
|
|
409
|
+
return this.getAverageSupplyAPR(poolTokenDataPast, this.getSupplyAPR());
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
getAverage7dSupplyAPR() {
|
|
413
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
+
const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
|
|
415
|
+
return this.getAverageSupplyAPR(poolTokenDataPast, this.getAverage24hSupplyAPR());
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
// Calculate collateral price -> returns the price of the collateral, not necessarily of the underlying LP
|
|
419
|
+
calculateCollateralPrice(reserve0, reserve1, totalSupply, price0, price1) {
|
|
420
|
+
if (totalSupply === 0) {
|
|
421
|
+
console.error("Warning: totalSupply is 0");
|
|
422
|
+
return 0;
|
|
423
|
+
}
|
|
424
|
+
const reserve0USD = reserve0 * price0;
|
|
425
|
+
const reserve1USD = reserve1 * price1;
|
|
426
|
+
// adjust reserves taking the latest price passed as parameters
|
|
427
|
+
const adjustedReserveUSD = Math.sqrt(reserve0USD * reserve1USD) * 2;
|
|
428
|
+
return adjustedReserveUSD / totalSupply;
|
|
429
|
+
}
|
|
430
|
+
// Token price getters
|
|
431
|
+
getTokenPriceFast(fallback = true) {
|
|
432
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
433
|
+
let tokenPrice = 0;
|
|
434
|
+
if (this.poolTokenType != types_1.PoolTokenType.Collateral) {
|
|
435
|
+
//const poolTokenData = await this.getPoolTokenData() as BorrowableData;
|
|
436
|
+
//tokenPrice = parseFloat(poolTokenData.underlying.derivedUSD);
|
|
437
|
+
let tokenAddress = yield this.getUnderlyingAddress();
|
|
438
|
+
let tokenPrices = yield this.lendingPool.subgraph.priceHelper.getSubgraphTokenPrice();
|
|
439
|
+
tokenPrice = tokenPrices[tokenAddress];
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
tokenPrice = yield this.lendingPool.getCollateralPrice(false);
|
|
443
|
+
}
|
|
444
|
+
if (tokenPrice > 0)
|
|
445
|
+
return tokenPrice;
|
|
446
|
+
if (fallback) {
|
|
447
|
+
return this.getTokenPriceAccurate();
|
|
448
|
+
}
|
|
449
|
+
return 0;
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
getTokenPriceAccurate() {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
if (this.poolTokenType === types_1.PoolTokenType.Collateral) {
|
|
455
|
+
return this.lendingPool.getCollateralPrice(false);
|
|
456
|
+
}
|
|
457
|
+
let tokenAddress = yield this.getUnderlyingAddress();
|
|
458
|
+
return this.lendingPool.subgraph.priceHelper.getDebankTokenPrice(tokenAddress);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
exports.default = PoolToken;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Subgraph from "./index";
|
|
2
|
+
import { Address } from '../config/types';
|
|
3
|
+
export default class PriceHelper {
|
|
4
|
+
subgraph: Subgraph;
|
|
5
|
+
subgraphTokenPrice: Promise<{
|
|
6
|
+
[key in Address]?: number;
|
|
7
|
+
}>;
|
|
8
|
+
debankTokenPrice: {
|
|
9
|
+
[key in Address]?: Promise<number>;
|
|
10
|
+
};
|
|
11
|
+
constructor(subgraph: Subgraph);
|
|
12
|
+
cleanCache(): void;
|
|
13
|
+
private initializeSubgraphTokenPrice;
|
|
14
|
+
getSubgraphTokenPrice(): Promise<{
|
|
15
|
+
[key in Address]: number;
|
|
16
|
+
}>;
|
|
17
|
+
private getCoingeckoTokenPrice;
|
|
18
|
+
private initializeDebankTokenPrice;
|
|
19
|
+
getDebankTokenPrice(tokenAddress: Address): Promise<number>;
|
|
20
|
+
getImxPrice(): Promise<number>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 debank_ids_1 = require("../config/debank-ids");
|
|
13
|
+
const imxes_1 = require("../config/contracts/imxes");
|
|
14
|
+
// coingecko has priority over debank for initialized tokens
|
|
15
|
+
const coingecko_ids = {
|
|
16
|
+
// Arbitrum
|
|
17
|
+
"0xb348b87b23d5977e2948e6f36ca07e1ec94d7328": "swapfish",
|
|
18
|
+
"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f": "wrapped-bitcoin",
|
|
19
|
+
};
|
|
20
|
+
class PriceHelper {
|
|
21
|
+
constructor(subgraph) {
|
|
22
|
+
this.subgraph = subgraph;
|
|
23
|
+
this.debankTokenPrice = {};
|
|
24
|
+
}
|
|
25
|
+
cleanCache() {
|
|
26
|
+
this.subgraphTokenPrice = null;
|
|
27
|
+
this.debankTokenPrice = {};
|
|
28
|
+
}
|
|
29
|
+
// First source of token price: Subgraph (less accurate, faster)
|
|
30
|
+
initializeSubgraphTokenPrice() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const lendingPoolsData = yield this.subgraph.getLendingPoolsData();
|
|
33
|
+
const subgraphTokenPrice = {};
|
|
34
|
+
for (const factory of Object.keys(lendingPoolsData)) {
|
|
35
|
+
for (const id of Object.keys(lendingPoolsData[factory])) {
|
|
36
|
+
const lendingPool = lendingPoolsData[factory][id];
|
|
37
|
+
subgraphTokenPrice[lendingPool.borrowable0.underlying.id] = parseFloat(lendingPool.borrowable0.underlying.derivedUSD);
|
|
38
|
+
subgraphTokenPrice[lendingPool.borrowable1.underlying.id] = parseFloat(lendingPool.borrowable1.underlying.derivedUSD);
|
|
39
|
+
for (const reward of lendingPool.pair.rewards) {
|
|
40
|
+
subgraphTokenPrice[reward.rewardsToken.id] = parseFloat(reward.rewardsToken.derivedUSD);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//fix for IMX
|
|
45
|
+
subgraphTokenPrice["0x9c67ee39e3c4954396b9142010653f17257dd39c"] = 0;
|
|
46
|
+
subgraphTokenPrice["0x7b35ce522cb72e4077baeb96cb923a5529764a00"] = 0;
|
|
47
|
+
subgraphTokenPrice["0xea6887e4a9cda1b77e70129e5fba830cdb5cddef"] = 0;
|
|
48
|
+
subgraphTokenPrice["0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05"] = 0;
|
|
49
|
+
subgraphTokenPrice["0x900f1ec5819fa087d368877cd03b265bf1802667"] = 0;
|
|
50
|
+
subgraphTokenPrice["0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2"] = 0;
|
|
51
|
+
return subgraphTokenPrice;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
getSubgraphTokenPrice() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (!this.subgraphTokenPrice)
|
|
57
|
+
this.subgraphTokenPrice = this.initializeSubgraphTokenPrice();
|
|
58
|
+
return this.subgraphTokenPrice;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Second source of token price: Debank (more accurate, slower)
|
|
62
|
+
getCoingeckoTokenPrice(tokenAddress) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
const tokenId = coingecko_ids[tokenAddress];
|
|
66
|
+
const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" + tokenId + "&vs_currencies=usd");
|
|
67
|
+
if (response.status != 200)
|
|
68
|
+
return 0;
|
|
69
|
+
const data = yield response.json();
|
|
70
|
+
if (!data)
|
|
71
|
+
return 0;
|
|
72
|
+
return data[tokenId].usd ? data[tokenId].usd : 0;
|
|
73
|
+
}
|
|
74
|
+
catch (_a) {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
initializeDebankTokenPrice(tokenAddress) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (Object.keys(coingecko_ids).includes(tokenAddress.toLowerCase())) {
|
|
82
|
+
const result = this.getCoingeckoTokenPrice(tokenAddress.toLowerCase());
|
|
83
|
+
if (result)
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.subgraph.network] + "&id=" + tokenAddress);
|
|
88
|
+
/*const response = await fetch(
|
|
89
|
+
"https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.subgraph.network] + "&id=" + tokenAddress,
|
|
90
|
+
{headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
|
|
91
|
+
);*/
|
|
92
|
+
if (response.status != 200)
|
|
93
|
+
return 0;
|
|
94
|
+
const data = yield response.json();
|
|
95
|
+
if (!data)
|
|
96
|
+
return 0;
|
|
97
|
+
return data.price ? data.price : 0;
|
|
98
|
+
}
|
|
99
|
+
catch (_a) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
getDebankTokenPrice(tokenAddress) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
if (tokenAddress.toLowerCase() === '0xb348b87b23d5977e2948e6f36ca07e1ec94d7328') { // fix for FISH
|
|
107
|
+
//return 0.07;
|
|
108
|
+
}
|
|
109
|
+
if (tokenAddress.toLowerCase() === '0xf28164a485b0b2c90639e47b0f377b4a438a16b1') { // fix for dQuick
|
|
110
|
+
return (yield this.getDebankTokenPrice('0x831753dd7087cac61ab5644b308642cc1c33dc13')) * 1.68;
|
|
111
|
+
}
|
|
112
|
+
if (tokenAddress.toLowerCase() === '0x63468133ed352e602beb61dd254d6060ad2fe419') { // fix for sTHO
|
|
113
|
+
return (yield this.getDebankTokenPrice('0xae4aa155d2987b454c29450ef4f862cf00907b61')) * 1.1;
|
|
114
|
+
}
|
|
115
|
+
if (tokenAddress.toLowerCase() === '0xfcef8a994209d6916eb2c86cdd2afd60aa6f54b1') { // fix for fBEETS
|
|
116
|
+
return (yield this.getDebankTokenPrice('0xf24bcf4d1e507740041c9cfd2dddb29585adce1e')) * 0.93;
|
|
117
|
+
}
|
|
118
|
+
if (tokenAddress.toLowerCase() === '0x5979d7b546e38e414f7e9822514be443a4800529') { // TEMPORARY fix for WSTETH
|
|
119
|
+
return (yield this.getDebankTokenPrice('0x82af49447d8a07e3bd95bd0d56f35241523fbab1')) / 0.92;
|
|
120
|
+
}
|
|
121
|
+
if (tokenAddress.toLowerCase() === '0x3f56e0c36d275367b8c502090edf38289b3dea0d') { // TEMPORARY fix for MAI
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
if ([
|
|
125
|
+
"0x9c67ee39e3c4954396b9142010653f17257dd39c",
|
|
126
|
+
"0x7b35ce522cb72e4077baeb96cb923a5529764a00",
|
|
127
|
+
"0xea6887e4a9cda1b77e70129e5fba830cdb5cddef",
|
|
128
|
+
"0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05",
|
|
129
|
+
"0x900f1ec5819fa087d368877cd03b265bf1802667",
|
|
130
|
+
"0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2",
|
|
131
|
+
].includes(tokenAddress.toLowerCase())) { // fix for IMX
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
if (tokenAddress.toLowerCase() === '0xda0053f0befcbcac208a3f867bb243716734d809') { // TEMPORARY fix for oxSOLID
|
|
135
|
+
return (yield this.getDebankTokenPrice('0x888ef71766ca594ded1f0fa3ae64ed2941740a20')) * 0.88;
|
|
136
|
+
}
|
|
137
|
+
if (tokenAddress.toLowerCase() === '0x431d5dff03120afa4bdf332c61a6e1766ef37bdb') { // TEMPORARY fix for JPYCv2
|
|
138
|
+
return (yield this.getDebankTokenPrice('0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c'));
|
|
139
|
+
}
|
|
140
|
+
if (!this.debankTokenPrice[tokenAddress])
|
|
141
|
+
this.debankTokenPrice[tokenAddress] = this.initializeDebankTokenPrice(tokenAddress);
|
|
142
|
+
const tokenPrice = yield this.debankTokenPrice[tokenAddress];
|
|
143
|
+
if (tokenPrice === 0) {
|
|
144
|
+
// try fallback on subgraph
|
|
145
|
+
const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
|
|
146
|
+
return subgraphTokenPrice[tokenAddress] ? subgraphTokenPrice[tokenAddress] : 0;
|
|
147
|
+
}
|
|
148
|
+
return tokenPrice;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
getImxPrice() {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const imx = imxes_1.IMX[this.subgraph.network];
|
|
154
|
+
if (!imx)
|
|
155
|
+
return 0;
|
|
156
|
+
const imxPrice = yield this.getDebankTokenPrice(imx);
|
|
157
|
+
if (imxPrice != 0)
|
|
158
|
+
return imxPrice;
|
|
159
|
+
const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
|
|
160
|
+
if (subgraphTokenPrice[imx])
|
|
161
|
+
return subgraphTokenPrice[imx];
|
|
162
|
+
return 0;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.default = PriceHelper;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Subgraph from "./index";
|
|
2
|
+
import { Address } from "../config/types";
|
|
3
|
+
export type SolidexLPDetails = {
|
|
4
|
+
[key in Address]: Array<{
|
|
5
|
+
APR: number;
|
|
6
|
+
symbol: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export default class SolidexHelper {
|
|
10
|
+
subgraph: Subgraph;
|
|
11
|
+
solidexLPDetails: Promise<SolidexLPDetails>;
|
|
12
|
+
constructor(subgraph: Subgraph);
|
|
13
|
+
cleanCache(): void;
|
|
14
|
+
private initializeSolidexLPDetails;
|
|
15
|
+
getSolidexLPDetails(): Promise<SolidexLPDetails>;
|
|
16
|
+
}
|