@defisaver/positions-sdk 0.0.198 → 0.0.199-dev-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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +69 -69
- package/cjs/config/contracts.d.ts +126 -4
- package/cjs/config/contracts.js +14 -0
- package/cjs/contracts.d.ts +1 -0
- package/cjs/contracts.js +2 -1
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/helpers/liquityV2Helpers/index.d.ts +12 -0
- package/cjs/helpers/liquityV2Helpers/index.js +63 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquityV2/index.d.ts +18 -0
- package/cjs/liquityV2/index.js +184 -0
- package/cjs/markets/aave/marketAssets.js +2 -4
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/liquityV2/index.d.ts +10 -0
- package/cjs/markets/liquityV2/index.js +47 -0
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/types/contracts/generated/LiquityV2CollSurplusPool.d.ts +64 -0
- package/cjs/types/contracts/generated/LiquityV2CollSurplusPool.js +5 -0
- package/cjs/types/contracts/generated/LiquityV2TroveNFT.d.ts +73 -0
- package/cjs/types/contracts/generated/LiquityV2TroveNFT.js +5 -0
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +244 -0
- package/cjs/types/contracts/generated/LiquityV2View.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +3 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquityV2.d.ts +111 -0
- package/cjs/types/liquityV2.js +24 -0
- package/esm/config/contracts.d.ts +126 -4
- package/esm/config/contracts.js +14 -0
- package/esm/contracts.d.ts +1 -0
- package/esm/contracts.js +1 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.d.ts +12 -0
- package/esm/helpers/liquityV2Helpers/index.js +55 -0
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquityV2/index.d.ts +18 -0
- package/esm/liquityV2/index.js +173 -0
- package/esm/markets/aave/marketAssets.js +2 -4
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/liquityV2/index.d.ts +10 -0
- package/esm/markets/liquityV2/index.js +40 -0
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/types/contracts/generated/LiquityV2CollSurplusPool.d.ts +64 -0
- package/esm/types/contracts/generated/LiquityV2CollSurplusPool.js +4 -0
- package/esm/types/contracts/generated/LiquityV2TroveNFT.d.ts +73 -0
- package/esm/types/contracts/generated/LiquityV2TroveNFT.js +4 -0
- package/esm/types/contracts/generated/LiquityV2View.d.ts +244 -0
- package/esm/types/contracts/generated/LiquityV2View.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +3 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquityV2.d.ts +111 -0
- package/esm/types/liquityV2.js +21 -0
- package/package.json +49 -49
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +625 -625
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +220 -220
- package/src/compoundV3/index.ts +291 -291
- package/src/config/contracts.js +1109 -1095
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +133 -132
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +303 -303
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +198 -198
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +246 -246
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +232 -232
- package/src/helpers/index.ts +10 -9
- package/src/helpers/liquityV2Helpers/index.ts +80 -0
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +365 -365
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +50 -48
- package/src/liquity/index.ts +116 -116
- package/src/liquityV2/index.ts +220 -0
- package/src/llamaLend/index.ts +275 -275
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +152 -152
- package/src/markets/aave/marketAssets.ts +44 -46
- package/src/markets/compound/index.ts +213 -213
- package/src/markets/compound/marketsAssets.ts +82 -82
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/index.ts +24 -24
- package/src/markets/liquityV2/index.ts +44 -0
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +631 -631
- package/src/morphoBlue/index.ts +204 -204
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +62 -62
- package/src/services/utils.ts +56 -56
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +461 -461
- package/src/staking/staking.ts +220 -220
- package/src/types/aave.ts +271 -271
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +131 -131
- package/src/types/contracts/generated/LiquityV2CollSurplusPool.ts +130 -0
- package/src/types/contracts/generated/LiquityV2TroveNFT.ts +150 -0
- package/src/types/contracts/generated/LiquityV2View.ts +315 -0
- package/src/types/contracts/generated/index.ts +3 -0
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +171 -171
- package/src/types/index.ts +10 -9
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +119 -0
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +192 -192
- package/src/types/spark.ts +131 -131
|
@@ -0,0 +1,63 @@
|
|
|
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.getLiquityV2AggregatedPositionData = exports.calculateNetApyLiquityV2 = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const moneymarket_1 = require("../../moneymarket");
|
|
9
|
+
const staking_1 = require("../../staking");
|
|
10
|
+
const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) => {
|
|
11
|
+
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
12
|
+
const acc = Object.assign({}, _acc);
|
|
13
|
+
const assetData = assetsData[usedAsset.symbol];
|
|
14
|
+
if (usedAsset.suppliedUsd) {
|
|
15
|
+
const amount = usedAsset.suppliedUsd;
|
|
16
|
+
acc.suppliedUsd = new decimal_js_1.default(acc.suppliedUsd).add(amount).toString();
|
|
17
|
+
if (assetData.incentiveSupplyApy) {
|
|
18
|
+
const incentiveInterest = (0, staking_1.calculateInterestEarned)(amount, assetData.incentiveSupplyApy, 'year', true);
|
|
19
|
+
acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (usedAsset.borrowedUsd) {
|
|
23
|
+
const amount = usedAsset.borrowedUsd;
|
|
24
|
+
acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
|
|
25
|
+
const rate = interestRate;
|
|
26
|
+
const borrowInterest = (0, staking_1.calculateInterestEarned)(amount, rate, 'year', true);
|
|
27
|
+
acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}, {
|
|
31
|
+
borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
|
|
32
|
+
});
|
|
33
|
+
const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
|
|
34
|
+
const totalInterestUsd = new decimal_js_1.default(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
|
|
35
|
+
const balance = new decimal_js_1.default(suppliedUsd).sub(borrowedUsd);
|
|
36
|
+
const netApy = new decimal_js_1.default(totalInterestUsd).div(balance).times(100).toString();
|
|
37
|
+
return { netApy, totalInterestUsd, incentiveUsd };
|
|
38
|
+
};
|
|
39
|
+
exports.calculateNetApyLiquityV2 = calculateNetApyLiquityV2;
|
|
40
|
+
const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, minCollRatio, interestRate, }) => {
|
|
41
|
+
const payload = {};
|
|
42
|
+
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ suppliedUsd }) => suppliedUsd);
|
|
43
|
+
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ borrowedUsd }) => borrowedUsd);
|
|
44
|
+
payload.borrowLimitUsd = new decimal_js_1.default(payload.suppliedUsd).div(minCollRatio).mul(100).toString();
|
|
45
|
+
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
46
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
47
|
+
payload.ratio = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
48
|
+
payload.collRatio = +payload.suppliedUsd ? new decimal_js_1.default(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
49
|
+
const { netApy, incentiveUsd, totalInterestUsd } = (0, exports.calculateNetApyLiquityV2)(usedAssets, assetsData, interestRate);
|
|
50
|
+
payload.netApy = netApy;
|
|
51
|
+
payload.incentiveUsd = incentiveUsd;
|
|
52
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
53
|
+
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
54
|
+
payload.leveragedType = leveragedType;
|
|
55
|
+
payload.leveragedAsset = leveragedAsset;
|
|
56
|
+
payload.liquidationPrice = '';
|
|
57
|
+
if (leveragedType !== '') {
|
|
58
|
+
const assetPrice = assetsData[leveragedAsset].price;
|
|
59
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
60
|
+
}
|
|
61
|
+
return payload;
|
|
62
|
+
};
|
|
63
|
+
exports.getLiquityV2AggregatedPositionData = getLiquityV2AggregatedPositionData;
|
|
@@ -115,73 +115,73 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) =>
|
|
|
115
115
|
});
|
|
116
116
|
exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
|
|
117
117
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
118
|
-
const MARKET_QUERY = `
|
|
119
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
120
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
121
|
-
reallocatableLiquidityAssets
|
|
122
|
-
targetBorrowUtilization
|
|
123
|
-
loanAsset {
|
|
124
|
-
address
|
|
125
|
-
decimals
|
|
126
|
-
priceUsd
|
|
127
|
-
}
|
|
128
|
-
state {
|
|
129
|
-
liquidityAssets
|
|
130
|
-
borrowAssets
|
|
131
|
-
supplyAssets
|
|
132
|
-
}
|
|
133
|
-
publicAllocatorSharedLiquidity {
|
|
134
|
-
assets
|
|
135
|
-
vault {
|
|
136
|
-
address
|
|
137
|
-
name
|
|
138
|
-
}
|
|
139
|
-
allocationMarket {
|
|
140
|
-
uniqueKey
|
|
141
|
-
loanAsset {
|
|
142
|
-
address
|
|
143
|
-
}
|
|
144
|
-
collateralAsset {
|
|
145
|
-
address
|
|
146
|
-
}
|
|
147
|
-
irmAddress
|
|
148
|
-
oracle {
|
|
149
|
-
address
|
|
150
|
-
}
|
|
151
|
-
lltv
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
loanAsset {
|
|
155
|
-
address
|
|
156
|
-
}
|
|
157
|
-
collateralAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
oracle {
|
|
161
|
-
address
|
|
162
|
-
}
|
|
163
|
-
irmAddress
|
|
164
|
-
lltv
|
|
165
|
-
}
|
|
166
|
-
}
|
|
118
|
+
const MARKET_QUERY = `
|
|
119
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
120
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
121
|
+
reallocatableLiquidityAssets
|
|
122
|
+
targetBorrowUtilization
|
|
123
|
+
loanAsset {
|
|
124
|
+
address
|
|
125
|
+
decimals
|
|
126
|
+
priceUsd
|
|
127
|
+
}
|
|
128
|
+
state {
|
|
129
|
+
liquidityAssets
|
|
130
|
+
borrowAssets
|
|
131
|
+
supplyAssets
|
|
132
|
+
}
|
|
133
|
+
publicAllocatorSharedLiquidity {
|
|
134
|
+
assets
|
|
135
|
+
vault {
|
|
136
|
+
address
|
|
137
|
+
name
|
|
138
|
+
}
|
|
139
|
+
allocationMarket {
|
|
140
|
+
uniqueKey
|
|
141
|
+
loanAsset {
|
|
142
|
+
address
|
|
143
|
+
}
|
|
144
|
+
collateralAsset {
|
|
145
|
+
address
|
|
146
|
+
}
|
|
147
|
+
irmAddress
|
|
148
|
+
oracle {
|
|
149
|
+
address
|
|
150
|
+
}
|
|
151
|
+
lltv
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
loanAsset {
|
|
155
|
+
address
|
|
156
|
+
}
|
|
157
|
+
collateralAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
oracle {
|
|
161
|
+
address
|
|
162
|
+
}
|
|
163
|
+
irmAddress
|
|
164
|
+
lltv
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
167
|
`;
|
|
168
|
-
const REWARDS_QUERY = `
|
|
169
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
170
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
171
|
-
uniqueKey
|
|
172
|
-
state {
|
|
173
|
-
rewards {
|
|
174
|
-
amountPerSuppliedToken
|
|
175
|
-
supplyApr
|
|
176
|
-
amountPerBorrowedToken
|
|
177
|
-
borrowApr
|
|
178
|
-
asset {
|
|
179
|
-
address
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
168
|
+
const REWARDS_QUERY = `
|
|
169
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
170
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
171
|
+
uniqueKey
|
|
172
|
+
state {
|
|
173
|
+
rewards {
|
|
174
|
+
amountPerSuppliedToken
|
|
175
|
+
supplyApr
|
|
176
|
+
amountPerBorrowedToken
|
|
177
|
+
borrowApr
|
|
178
|
+
asset {
|
|
179
|
+
address
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
185
|
`;
|
|
186
186
|
/**
|
|
187
187
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
package/cjs/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as compoundV2 from './compoundV2';
|
|
|
8
8
|
import * as spark from './spark';
|
|
9
9
|
import * as curveUsd from './curveUsd';
|
|
10
10
|
import * as liquity from './liquity';
|
|
11
|
+
import * as liquityV2 from './liquityV2';
|
|
11
12
|
import * as maker from './maker';
|
|
12
13
|
import * as staking from './staking';
|
|
13
14
|
import * as multicall from './multicall';
|
|
@@ -20,4 +21,4 @@ import * as morphoBlue from './morphoBlue';
|
|
|
20
21
|
import * as llamaLend from './llamaLend';
|
|
21
22
|
import * as eulerV2 from './eulerV2';
|
|
22
23
|
export * from './types';
|
|
23
|
-
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, };
|
|
24
|
+
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, };
|
package/cjs/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.eulerV2 = exports.llamaLend = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
29
|
+
exports.eulerV2 = exports.llamaLend = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquityV2 = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
30
30
|
require("./setup");
|
|
31
31
|
const aaveV3 = __importStar(require("./aaveV3"));
|
|
32
32
|
exports.aaveV3 = aaveV3;
|
|
@@ -46,6 +46,8 @@ const curveUsd = __importStar(require("./curveUsd"));
|
|
|
46
46
|
exports.curveUsd = curveUsd;
|
|
47
47
|
const liquity = __importStar(require("./liquity"));
|
|
48
48
|
exports.liquity = liquity;
|
|
49
|
+
const liquityV2 = __importStar(require("./liquityV2"));
|
|
50
|
+
exports.liquityV2 = liquityV2;
|
|
49
51
|
const maker = __importStar(require("./maker"));
|
|
50
52
|
exports.maker = maker;
|
|
51
53
|
const staking = __importStar(require("./staking"));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
|
+
export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
|
|
5
|
+
export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
|
|
6
|
+
troves: {
|
|
7
|
+
troveId: string;
|
|
8
|
+
}[];
|
|
9
|
+
nextFreeTroveIndex: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
12
|
+
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
|
|
13
|
+
selectedMarket: LiquityV2MarketInfo;
|
|
14
|
+
assetsData: LiquityV2AssetsData;
|
|
15
|
+
marketData: InnerLiquityV2MarketData;
|
|
16
|
+
troveId: string;
|
|
17
|
+
}) => Promise<LiquityV2TroveData>;
|
|
18
|
+
export declare const getLiquityV2ClaimableCollateral: (collSurplusPoolAddress: EthAddress, account: EthAddress, web3: Web3, network: NetworkNumber) => Promise<string>;
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
exports.getLiquityV2ClaimableCollateral = exports.getLiquityV2TroveData = exports.getDebtInFrontLiquityV2 = exports.getLiquityV2UserTroveIds = exports.getLiquityV2MarketData = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
18
|
+
const contracts_1 = require("../contracts");
|
|
19
|
+
const types_1 = require("../types");
|
|
20
|
+
const staking_1 = require("../staking");
|
|
21
|
+
const liquityV2Helpers_1 = require("../helpers/liquityV2Helpers");
|
|
22
|
+
const utils_1 = require("../services/utils");
|
|
23
|
+
const constants_1 = require("../constants");
|
|
24
|
+
const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
26
|
+
const { marketAddress, debtToken, collateralToken } = selectedMarket;
|
|
27
|
+
const data = yield viewContract.methods.getMarketData(marketAddress).call();
|
|
28
|
+
const hintHelperAddress = data.hintHelpers;
|
|
29
|
+
const troveNFTAddress = data.troveNFT;
|
|
30
|
+
const borrowerOperationsAddress = data.borrowerOperations;
|
|
31
|
+
const troveManagerAddress = data.troveManager;
|
|
32
|
+
const stabilityPoolAddress = data.stabilityPool;
|
|
33
|
+
const collSurplusPoolAddress = data.collSurplusPool;
|
|
34
|
+
const activePoolAddress = data.activePool;
|
|
35
|
+
const minCollRatio = new decimal_js_1.default(data.MCR).div(1e16).toString();
|
|
36
|
+
const criticalCollRatio = new decimal_js_1.default(data.CCR).div(1e18).toString();
|
|
37
|
+
const totalMarketBorrow = (0, tokens_1.assetAmountInEth)(data.entireSystemDebt);
|
|
38
|
+
const totalMarketSupply = (0, tokens_1.assetAmountInEth)(data.entireSystemColl);
|
|
39
|
+
const collPrice = (0, tokens_1.assetAmountInEth)(data.collPrice);
|
|
40
|
+
const totalCollRatio = new decimal_js_1.default(totalMarketSupply).mul(collPrice).div(totalMarketBorrow).toString();
|
|
41
|
+
const leftToBorrowGlobal = new decimal_js_1.default(totalMarketSupply).mul(collPrice).div(criticalCollRatio).sub(totalMarketBorrow)
|
|
42
|
+
.toString();
|
|
43
|
+
const minCollAmountForCurrentBorrow = new decimal_js_1.default(totalMarketBorrow).mul(criticalCollRatio).div(collPrice).toString();
|
|
44
|
+
const leftToWithdrawGlobal = new decimal_js_1.default(totalMarketSupply).sub(minCollAmountForCurrentBorrow).toString();
|
|
45
|
+
const assetsData = {};
|
|
46
|
+
assetsData[debtToken] = {
|
|
47
|
+
symbol: debtToken,
|
|
48
|
+
address: (0, tokens_1.getAssetInfo)(debtToken, network).address,
|
|
49
|
+
price: '1',
|
|
50
|
+
totalSupply: '0',
|
|
51
|
+
totalBorrow: totalMarketBorrow,
|
|
52
|
+
canBeSupplied: false,
|
|
53
|
+
canBeBorrowed: true,
|
|
54
|
+
leftToBorrowGlobal,
|
|
55
|
+
leftToWithdrawGlobal: '0',
|
|
56
|
+
};
|
|
57
|
+
assetsData[collateralToken] = {
|
|
58
|
+
symbol: collateralToken,
|
|
59
|
+
address: (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(collateralToken), network).address,
|
|
60
|
+
price: collPrice,
|
|
61
|
+
totalSupply: totalMarketSupply,
|
|
62
|
+
totalBorrow: '0',
|
|
63
|
+
canBeSupplied: true,
|
|
64
|
+
canBeBorrowed: false,
|
|
65
|
+
leftToBorrowGlobal: '0',
|
|
66
|
+
leftToWithdrawGlobal,
|
|
67
|
+
};
|
|
68
|
+
if (staking_1.STAKING_ASSETS.includes(collateralToken)) {
|
|
69
|
+
assetsData[collateralToken].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralToken, mainnetWeb3);
|
|
70
|
+
assetsData[collateralToken].incentiveSupplyToken = collateralToken;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
assetsData,
|
|
74
|
+
marketData: {
|
|
75
|
+
minCollRatio,
|
|
76
|
+
totalCollRatio: new decimal_js_1.default(totalCollRatio).mul(100).toString(),
|
|
77
|
+
criticalCollRatio: new decimal_js_1.default(criticalCollRatio).mul(100).toString(),
|
|
78
|
+
isUnderCollateralized: new decimal_js_1.default(totalCollRatio).lt(criticalCollRatio),
|
|
79
|
+
hintHelperAddress,
|
|
80
|
+
troveNFTAddress,
|
|
81
|
+
borrowerOperationsAddress,
|
|
82
|
+
troveManagerAddress,
|
|
83
|
+
stabilityPoolAddress,
|
|
84
|
+
collSurplusPoolAddress,
|
|
85
|
+
activePoolAddress,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
exports.getLiquityV2MarketData = getLiquityV2MarketData;
|
|
90
|
+
const _getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getUserTroves(account, marketAddress, startIndex, endIndex).call(); });
|
|
91
|
+
const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100, troves = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
const result = yield _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
|
|
93
|
+
const newStartIndex = endIndex + 1;
|
|
94
|
+
const nextFreeTroveIndex = result.nextFreeTroveIndex;
|
|
95
|
+
const existingTroves = [...troves, ...result.troves];
|
|
96
|
+
if (nextFreeTroveIndex !== '-1')
|
|
97
|
+
return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
|
|
98
|
+
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
99
|
+
});
|
|
100
|
+
const TransferEventSig = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
101
|
+
const getTransferredTroves = (web3, network, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
const nftContract = (0, contracts_1.createContractWrapper)(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
|
|
103
|
+
const currentBlock = yield web3.eth.getBlockNumber();
|
|
104
|
+
const events = yield nftContract.getPastEvents(TransferEventSig, Object.assign({ filter: { to: account } }, (0, utils_1.addToObjectIf)(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 })));
|
|
105
|
+
const userTransferredTroves = events.filter((event) => !(0, utils_1.compareAddresses)(event.returnValues.from, constants_1.ZERO_ADDRESS) && (0, utils_1.compareAddresses)(event.returnValues.to, account));
|
|
106
|
+
// check if the last know transfer address is the user
|
|
107
|
+
userTransferredTroves.forEach((event, index) => {
|
|
108
|
+
const otherTransfers = events.filter((e) => event.blockNumber < e.blockNumber && e.returnValues.tokenId === event.returnValues.tokenId);
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
userTransferredTroves[index].invalid = !!otherTransfers.length;
|
|
111
|
+
});
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.returnValues.tokenId }));
|
|
114
|
+
});
|
|
115
|
+
const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
117
|
+
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
|
|
118
|
+
getUserTroves(viewContract, account, selectedMarket.marketAddress),
|
|
119
|
+
getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
|
|
120
|
+
]);
|
|
121
|
+
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
122
|
+
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
|
|
123
|
+
return { troves: filteredTroves, nextFreeTroveIndex };
|
|
124
|
+
});
|
|
125
|
+
exports.getLiquityV2UserTroveIds = getLiquityV2UserTroveIds;
|
|
126
|
+
const _getDebtInFront = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call(); });
|
|
127
|
+
const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
|
|
129
|
+
if (next === '0')
|
|
130
|
+
return (0, tokens_1.assetAmountInEth)(debt);
|
|
131
|
+
return (0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, next, debt, iterations);
|
|
132
|
+
});
|
|
133
|
+
exports.getDebtInFrontLiquityV2 = getDebtInFrontLiquityV2;
|
|
134
|
+
const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
136
|
+
const { minCollRatio } = marketData;
|
|
137
|
+
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
138
|
+
const [data, debtInFront] = yield Promise.all([
|
|
139
|
+
viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
|
|
140
|
+
(0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, troveId),
|
|
141
|
+
]);
|
|
142
|
+
const usedAssets = {};
|
|
143
|
+
const debtAssetData = assetsData[debtToken];
|
|
144
|
+
const borrowed = (0, tokens_1.assetAmountInEth)(data.debtAmount);
|
|
145
|
+
usedAssets[debtToken] = {
|
|
146
|
+
symbol: debtToken,
|
|
147
|
+
supplied: '0',
|
|
148
|
+
suppliedUsd: '0',
|
|
149
|
+
borrowed,
|
|
150
|
+
borrowedUsd: new decimal_js_1.default(borrowed).mul(debtAssetData.price).toString(),
|
|
151
|
+
isBorrowed: true,
|
|
152
|
+
isSupplied: false,
|
|
153
|
+
};
|
|
154
|
+
const collAssetData = assetsData[collateralToken];
|
|
155
|
+
const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
|
|
156
|
+
usedAssets[collateralToken] = {
|
|
157
|
+
symbol: collateralToken,
|
|
158
|
+
supplied: suppliedColl,
|
|
159
|
+
suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
|
|
160
|
+
borrowed: '0',
|
|
161
|
+
borrowedUsd: '0',
|
|
162
|
+
isBorrowed: false,
|
|
163
|
+
isSupplied: true,
|
|
164
|
+
collateral: true,
|
|
165
|
+
};
|
|
166
|
+
const collRatio = new decimal_js_1.default(data.TCRatio).div(1e16).toString();
|
|
167
|
+
const interestRate = new decimal_js_1.default(data.annualInterestRate).div(1e16).toString();
|
|
168
|
+
const interestBatchManager = data.interestBatchManager;
|
|
169
|
+
const payload = Object.assign(Object.assign({ usedAssets,
|
|
170
|
+
troveId,
|
|
171
|
+
interestRate,
|
|
172
|
+
interestBatchManager,
|
|
173
|
+
debtInFront, troveStatus: types_1.LIQUITY_V2_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
|
|
174
|
+
usedAssets, assetsData, minCollRatio, interestRate,
|
|
175
|
+
})), { collRatio });
|
|
176
|
+
return payload;
|
|
177
|
+
});
|
|
178
|
+
exports.getLiquityV2TroveData = getLiquityV2TroveData;
|
|
179
|
+
const getLiquityV2ClaimableCollateral = (collSurplusPoolAddress, account, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
+
const collSurplusPoolContract = (0, contracts_1.createContractWrapper)(web3, network, 'LiquityV2CollSurplusPool', collSurplusPoolAddress);
|
|
181
|
+
const claimableCollateral = yield collSurplusPoolContract.methods.getCollateral(account).call();
|
|
182
|
+
return claimableCollateral;
|
|
183
|
+
});
|
|
184
|
+
exports.getLiquityV2ClaimableCollateral = getLiquityV2ClaimableCollateral;
|
|
@@ -14,10 +14,8 @@ exports.aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI',
|
|
|
14
14
|
exports.aaveV3AssetsDefaultMarketOpt = [
|
|
15
15
|
'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
|
|
16
16
|
];
|
|
17
|
-
exports.aaveV3AssetsDefaultMarketArb = [
|
|
18
|
-
|
|
19
|
-
];
|
|
20
|
-
exports.aaveV3AssetsDefaultMarketBase = ['ETH', 'cbETH', 'USDbC', 'wstETH', 'USDC', 'weETH', 'cbBTC'];
|
|
17
|
+
exports.aaveV3AssetsDefaultMarketArb = ['DAI', 'LINK', 'USDC.e', 'WBTC', 'ETH', 'USDT', 'AAVE', 'EURS', 'wstETH', 'MAI', 'rETH', 'LUSD', 'USDC', 'FRAX', 'ARB', 'weETH', 'GHO', 'ezETH'];
|
|
18
|
+
exports.aaveV3AssetsDefaultMarketBase = ['ETH', 'cbETH', 'USDbC', 'wstETH', 'USDC', 'weETH', 'cbBTC', 'ezETH'];
|
|
21
19
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
22
20
|
exports.aaveV3AssetsDefaultMarket = {
|
|
23
21
|
[common_1.NetworkNumber.Eth]: exports.aaveV3AssetsDefaultMarketEth,
|
package/cjs/markets/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { SparkMarkets } from './spark';
|
|
|
4
4
|
export { CrvUsdMarkets } from './curveUsd';
|
|
5
5
|
export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
|
|
6
6
|
export { LlamaLendMarkets } from './llamaLend';
|
|
7
|
+
export { LiquityV2Markets } from './liquityV2';
|
|
7
8
|
export { EulerV2Markets } from './euler';
|
package/cjs/markets/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EulerV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.morphoAaveV3AssetEthMarket = exports.morphoAaveV2AssetDefaultMarket = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
|
|
3
|
+
exports.EulerV2Markets = exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.morphoAaveV3AssetEthMarket = exports.morphoAaveV2AssetDefaultMarket = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
|
|
4
4
|
var aave_1 = require("./aave");
|
|
5
5
|
Object.defineProperty(exports, "AaveMarkets", { enumerable: true, get: function () { return aave_1.AaveMarkets; } });
|
|
6
6
|
Object.defineProperty(exports, "aaveV1AssetsDefaultMarket", { enumerable: true, get: function () { return aave_1.aaveV1AssetsDefaultMarket; } });
|
|
@@ -26,5 +26,7 @@ Object.defineProperty(exports, "MorphoBlueMarkets", { enumerable: true, get: fun
|
|
|
26
26
|
Object.defineProperty(exports, "findMorphoBlueMarket", { enumerable: true, get: function () { return morphoBlue_1.findMorphoBlueMarket; } });
|
|
27
27
|
var llamaLend_1 = require("./llamaLend");
|
|
28
28
|
Object.defineProperty(exports, "LlamaLendMarkets", { enumerable: true, get: function () { return llamaLend_1.LlamaLendMarkets; } });
|
|
29
|
+
var liquityV2_1 = require("./liquityV2");
|
|
30
|
+
Object.defineProperty(exports, "LiquityV2Markets", { enumerable: true, get: function () { return liquityV2_1.LiquityV2Markets; } });
|
|
29
31
|
var euler_1 = require("./euler");
|
|
30
32
|
Object.defineProperty(exports, "EulerV2Markets", { enumerable: true, get: function () { return euler_1.EulerV2Markets; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NetworkNumber } from '../../types/common';
|
|
2
|
+
import { LiquityV2MarketInfo } from '../../types/liquityV2';
|
|
3
|
+
export declare const LIQUITY_V2_ETH_MARKET: (networkId?: NetworkNumber) => LiquityV2MarketInfo;
|
|
4
|
+
export declare const LIQUITY_V2_WSTETH_MARKET: (networkId?: NetworkNumber) => LiquityV2MarketInfo;
|
|
5
|
+
export declare const LIQUITY_V2_RETH_MARKET: (networkId?: NetworkNumber) => LiquityV2MarketInfo;
|
|
6
|
+
export declare const LiquityV2Markets: (networkId: NetworkNumber) => {
|
|
7
|
+
readonly liquityv2eth: LiquityV2MarketInfo;
|
|
8
|
+
readonly liquityv2wsteth: LiquityV2MarketInfo;
|
|
9
|
+
readonly liquityv2reth: LiquityV2MarketInfo;
|
|
10
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiquityV2Markets = exports.LIQUITY_V2_RETH_MARKET = exports.LIQUITY_V2_WSTETH_MARKET = exports.LIQUITY_V2_ETH_MARKET = void 0;
|
|
4
|
+
const common_1 = require("../../types/common");
|
|
5
|
+
const liquityV2_1 = require("../../types/liquityV2");
|
|
6
|
+
const LIQUITY_V2_ETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
7
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
8
|
+
label: 'Liquity V2 ETH',
|
|
9
|
+
shortLabel: 'ETH',
|
|
10
|
+
value: liquityV2_1.LiquityV2Versions.LiquityV2Eth,
|
|
11
|
+
url: 'eth',
|
|
12
|
+
debtToken: 'BOLD',
|
|
13
|
+
collateralToken: 'ETH',
|
|
14
|
+
marketAddress: '0xc3fe668b43439525f70fe860f89882f0be312504',
|
|
15
|
+
protocolName: 'liquity-v2',
|
|
16
|
+
});
|
|
17
|
+
exports.LIQUITY_V2_ETH_MARKET = LIQUITY_V2_ETH_MARKET;
|
|
18
|
+
const LIQUITY_V2_WSTETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
19
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
20
|
+
label: 'Liquity V2 wstETH',
|
|
21
|
+
shortLabel: 'wstETH',
|
|
22
|
+
value: liquityV2_1.LiquityV2Versions.LiquityV2WstEth,
|
|
23
|
+
url: 'wsteth',
|
|
24
|
+
debtToken: 'BOLD',
|
|
25
|
+
collateralToken: 'wstETH',
|
|
26
|
+
marketAddress: '0x9b27787ff66aa3cea8dbc47772328459a1fa05ac',
|
|
27
|
+
protocolName: 'liquity-v2',
|
|
28
|
+
});
|
|
29
|
+
exports.LIQUITY_V2_WSTETH_MARKET = LIQUITY_V2_WSTETH_MARKET;
|
|
30
|
+
const LIQUITY_V2_RETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
31
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
32
|
+
label: 'Liquity V2 rETH',
|
|
33
|
+
shortLabel: 'rETH',
|
|
34
|
+
value: liquityV2_1.LiquityV2Versions.LiquityV2REth,
|
|
35
|
+
url: 'reth',
|
|
36
|
+
debtToken: 'BOLD',
|
|
37
|
+
collateralToken: 'rETH',
|
|
38
|
+
marketAddress: '0xde524be191de806011e98c8d36d50d7a88391a3e',
|
|
39
|
+
protocolName: 'liquity-v2',
|
|
40
|
+
});
|
|
41
|
+
exports.LIQUITY_V2_RETH_MARKET = LIQUITY_V2_RETH_MARKET;
|
|
42
|
+
const LiquityV2Markets = (networkId) => ({
|
|
43
|
+
[liquityV2_1.LiquityV2Versions.LiquityV2Eth]: (0, exports.LIQUITY_V2_ETH_MARKET)(networkId),
|
|
44
|
+
[liquityV2_1.LiquityV2Versions.LiquityV2WstEth]: (0, exports.LIQUITY_V2_WSTETH_MARKET)(networkId),
|
|
45
|
+
[liquityV2_1.LiquityV2Versions.LiquityV2REth]: (0, exports.LIQUITY_V2_RETH_MARKET)(networkId),
|
|
46
|
+
});
|
|
47
|
+
exports.LiquityV2Markets = LiquityV2Markets;
|
|
@@ -27,7 +27,7 @@ const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimit
|
|
|
27
27
|
exports.calcLeverageLiqPrice = calcLeverageLiqPrice;
|
|
28
28
|
const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new decimal_js_1.default(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
29
29
|
exports.calculateBorrowingAssetLimit = calculateBorrowingAssetLimit;
|
|
30
|
-
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
|
|
30
|
+
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD', 'BOLD'];
|
|
31
31
|
const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
32
32
|
let borrowUnstable = 0;
|
|
33
33
|
let supplyStable = 0;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type BN from "bn.js";
|
|
3
|
+
import type { ContractOptions } from "web3-eth-contract";
|
|
4
|
+
import type { EventLog } from "web3-core";
|
|
5
|
+
import type { EventEmitter } from "events";
|
|
6
|
+
import type { Callback, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "./types";
|
|
7
|
+
export interface EventOptions {
|
|
8
|
+
filter?: object;
|
|
9
|
+
fromBlock?: BlockType;
|
|
10
|
+
topics?: string[];
|
|
11
|
+
}
|
|
12
|
+
export type BorrowerOperationsAddressChanged = ContractEventLog<{
|
|
13
|
+
_newBorrowerOperationsAddress: string;
|
|
14
|
+
0: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type CollBalanceUpdated = ContractEventLog<{
|
|
17
|
+
_account: string;
|
|
18
|
+
_newBalance: string;
|
|
19
|
+
0: string;
|
|
20
|
+
1: string;
|
|
21
|
+
}>;
|
|
22
|
+
export type CollSent = ContractEventLog<{
|
|
23
|
+
_to: string;
|
|
24
|
+
_amount: string;
|
|
25
|
+
0: string;
|
|
26
|
+
1: string;
|
|
27
|
+
}>;
|
|
28
|
+
export type TroveManagerAddressChanged = ContractEventLog<{
|
|
29
|
+
_newTroveManagerAddress: string;
|
|
30
|
+
0: string;
|
|
31
|
+
}>;
|
|
32
|
+
export interface LiquityV2CollSurplusPool extends BaseContract {
|
|
33
|
+
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): LiquityV2CollSurplusPool;
|
|
34
|
+
clone(): LiquityV2CollSurplusPool;
|
|
35
|
+
methods: {
|
|
36
|
+
NAME(): NonPayableTransactionObject<string>;
|
|
37
|
+
accountSurplus(_account: string, _amount: number | string | BN): NonPayableTransactionObject<void>;
|
|
38
|
+
borrowerOperationsAddress(): NonPayableTransactionObject<string>;
|
|
39
|
+
claimColl(_account: string): NonPayableTransactionObject<void>;
|
|
40
|
+
collToken(): NonPayableTransactionObject<string>;
|
|
41
|
+
getCollBalance(): NonPayableTransactionObject<string>;
|
|
42
|
+
getCollateral(_account: string): NonPayableTransactionObject<string>;
|
|
43
|
+
troveManagerAddress(): NonPayableTransactionObject<string>;
|
|
44
|
+
};
|
|
45
|
+
events: {
|
|
46
|
+
BorrowerOperationsAddressChanged(cb?: Callback<BorrowerOperationsAddressChanged>): EventEmitter;
|
|
47
|
+
BorrowerOperationsAddressChanged(options?: EventOptions, cb?: Callback<BorrowerOperationsAddressChanged>): EventEmitter;
|
|
48
|
+
CollBalanceUpdated(cb?: Callback<CollBalanceUpdated>): EventEmitter;
|
|
49
|
+
CollBalanceUpdated(options?: EventOptions, cb?: Callback<CollBalanceUpdated>): EventEmitter;
|
|
50
|
+
CollSent(cb?: Callback<CollSent>): EventEmitter;
|
|
51
|
+
CollSent(options?: EventOptions, cb?: Callback<CollSent>): EventEmitter;
|
|
52
|
+
TroveManagerAddressChanged(cb?: Callback<TroveManagerAddressChanged>): EventEmitter;
|
|
53
|
+
TroveManagerAddressChanged(options?: EventOptions, cb?: Callback<TroveManagerAddressChanged>): EventEmitter;
|
|
54
|
+
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
55
|
+
};
|
|
56
|
+
once(event: "BorrowerOperationsAddressChanged", cb: Callback<BorrowerOperationsAddressChanged>): void;
|
|
57
|
+
once(event: "BorrowerOperationsAddressChanged", options: EventOptions, cb: Callback<BorrowerOperationsAddressChanged>): void;
|
|
58
|
+
once(event: "CollBalanceUpdated", cb: Callback<CollBalanceUpdated>): void;
|
|
59
|
+
once(event: "CollBalanceUpdated", options: EventOptions, cb: Callback<CollBalanceUpdated>): void;
|
|
60
|
+
once(event: "CollSent", cb: Callback<CollSent>): void;
|
|
61
|
+
once(event: "CollSent", options: EventOptions, cb: Callback<CollSent>): void;
|
|
62
|
+
once(event: "TroveManagerAddressChanged", cb: Callback<TroveManagerAddressChanged>): void;
|
|
63
|
+
once(event: "TroveManagerAddressChanged", options: EventOptions, cb: Callback<TroveManagerAddressChanged>): void;
|
|
64
|
+
}
|