@defisaver/positions-sdk 0.0.166-dev6-liquity-v2 → 0.0.166-dev6
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 +32 -3
- package/cjs/config/contracts.js +3 -3
- package/cjs/contracts.d.ts +1 -1
- package/cjs/contracts.js +2 -2
- package/cjs/eulerV2/index.d.ts +41 -0
- package/cjs/eulerV2/index.js +218 -0
- package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
- package/cjs/helpers/eulerHelpers/index.js +234 -0
- package/cjs/helpers/index.d.ts +1 -1
- package/cjs/helpers/index.js +2 -2
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +3 -3
- package/cjs/markets/euler/index.d.ts +8 -0
- package/cjs/markets/euler/index.js +30 -0
- package/cjs/markets/index.d.ts +1 -1
- package/cjs/markets/index.js +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/services/utils.d.ts +2 -0
- package/cjs/services/utils.js +4 -1
- package/cjs/staking/staking.js +0 -2
- package/cjs/types/contracts/generated/EulerV2View.d.ts +345 -0
- package/cjs/types/contracts/generated/index.d.ts +1 -1
- package/cjs/types/euler.d.ts +149 -0
- package/cjs/types/euler.js +14 -0
- package/cjs/types/index.d.ts +1 -1
- package/cjs/types/index.js +1 -1
- package/esm/config/contracts.d.ts +32 -3
- package/esm/config/contracts.js +3 -3
- package/esm/contracts.d.ts +1 -1
- package/esm/contracts.js +1 -1
- package/esm/eulerV2/index.d.ts +41 -0
- package/esm/eulerV2/index.js +210 -0
- package/esm/helpers/eulerHelpers/index.d.ts +27 -0
- package/esm/helpers/eulerHelpers/index.js +221 -0
- package/esm/helpers/index.d.ts +1 -1
- package/esm/helpers/index.js +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/markets/euler/index.d.ts +8 -0
- package/esm/markets/euler/index.js +24 -0
- package/esm/markets/index.d.ts +1 -1
- package/esm/markets/index.js +1 -1
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/services/utils.d.ts +2 -0
- package/esm/services/utils.js +2 -0
- package/esm/staking/staking.js +0 -2
- package/esm/types/contracts/generated/EulerV2View.d.ts +345 -0
- package/esm/types/contracts/generated/index.d.ts +1 -1
- package/esm/types/euler.d.ts +149 -0
- package/esm/types/euler.js +11 -0
- package/esm/types/index.d.ts +1 -1
- package/esm/types/index.js +1 -1
- package/package.json +49 -49
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +590 -590
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +281 -281
- package/src/config/contracts.js +1040 -1040
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +130 -130
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +302 -0
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +194 -194
- 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 +233 -0
- package/src/helpers/index.ts +9 -9
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +115 -115
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +48 -48
- package/src/liquity/index.ts +116 -116
- 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 +46 -46
- package/src/markets/compound/index.ts +173 -173
- package/src/markets/compound/marketsAssets.ts +64 -64
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +27 -0
- package/src/markets/index.ts +24 -23
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +728 -728
- 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 +630 -630
- package/src/morphoBlue/index.ts +171 -171
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +57 -54
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +424 -424
- package/src/staking/staking.ts +216 -218
- package/src/types/aave.ts +262 -262
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +129 -129
- package/src/types/contracts/generated/EulerV2View.ts +446 -0
- package/src/types/contracts/generated/index.ts +1 -1
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +172 -0
- package/src/types/index.ts +10 -10
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +146 -146
- package/src/types/spark.ts +127 -127
- package/cjs/helpers/liquityV2Helpers/index.d.ts +0 -12
- package/cjs/helpers/liquityV2Helpers/index.js +0 -62
- package/cjs/liquityV2/index.d.ts +0 -11
- package/cjs/liquityV2/index.js +0 -108
- package/cjs/markets/liquityV2/index.d.ts +0 -8
- package/cjs/markets/liquityV2/index.js +0 -34
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +0 -222
- package/cjs/types/liquityV2.d.ts +0 -84
- package/cjs/types/liquityV2.js +0 -8
- package/esm/helpers/liquityV2Helpers/index.d.ts +0 -12
- package/esm/helpers/liquityV2Helpers/index.js +0 -54
- package/esm/liquityV2/index.d.ts +0 -11
- package/esm/liquityV2/index.js +0 -99
- package/esm/markets/liquityV2/index.d.ts +0 -8
- package/esm/markets/liquityV2/index.js +0 -28
- package/esm/types/contracts/generated/LiquityV2View.d.ts +0 -222
- package/esm/types/liquityV2.d.ts +0 -84
- package/esm/types/liquityV2.js +0 -5
- package/src/helpers/liquityV2Helpers/index.ts +0 -79
- package/src/liquityV2/index.ts +0 -126
- package/src/markets/liquityV2/index.ts +0 -31
- package/src/types/contracts/generated/LiquityV2View.ts +0 -280
- package/src/types/liquityV2.ts +0 -90
- /package/cjs/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
- /package/esm/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import Dec from 'decimal.js';
|
|
22
|
+
import { assetAmountInWei } from '@defisaver/tokens';
|
|
23
|
+
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
|
|
24
|
+
import { calculateInterestEarned } from '../../staking';
|
|
25
|
+
import { EulerV2ViewContract } from '../../contracts';
|
|
26
|
+
import { borrowOperations } from '../../constants';
|
|
27
|
+
import { multicall } from '../../multicall';
|
|
28
|
+
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
29
|
+
let borrowUnstable = 0;
|
|
30
|
+
let supplyStable = 0;
|
|
31
|
+
let borrowStable = 0;
|
|
32
|
+
let supplyUnstable = 0;
|
|
33
|
+
let longAsset = '';
|
|
34
|
+
let shortAsset = '';
|
|
35
|
+
let leverageAssetVault = '';
|
|
36
|
+
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, vaultAddress, }) => {
|
|
37
|
+
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
38
|
+
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
39
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
40
|
+
supplyStable += 1;
|
|
41
|
+
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
42
|
+
borrowStable += 1;
|
|
43
|
+
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
44
|
+
borrowUnstable += 1;
|
|
45
|
+
shortAsset = symbol;
|
|
46
|
+
leverageAssetVault = vaultAddress;
|
|
47
|
+
}
|
|
48
|
+
if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
|
|
49
|
+
supplyUnstable += 1;
|
|
50
|
+
longAsset = symbol;
|
|
51
|
+
leverageAssetVault = vaultAddress;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
55
|
+
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
56
|
+
// lsd -> liquid staking derivative
|
|
57
|
+
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
58
|
+
if (isLong) {
|
|
59
|
+
return {
|
|
60
|
+
leveragedType: 'long',
|
|
61
|
+
leveragedAsset: longAsset,
|
|
62
|
+
leveragedVault: leverageAssetVault,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (isShort) {
|
|
66
|
+
return {
|
|
67
|
+
leveragedType: 'short',
|
|
68
|
+
leveragedAsset: shortAsset,
|
|
69
|
+
leveragedVault: leverageAssetVault,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (isLsdLeveraged) {
|
|
73
|
+
return {
|
|
74
|
+
leveragedType: 'lsd-leverage',
|
|
75
|
+
leveragedAsset: longAsset,
|
|
76
|
+
leveragedVault: leverageAssetVault,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
leveragedType: '',
|
|
81
|
+
leveragedAsset: '',
|
|
82
|
+
leveragedVault: '',
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export const calculateNetApy = (usedAssets, assetsData) => {
|
|
86
|
+
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
87
|
+
const acc = Object.assign({}, _acc);
|
|
88
|
+
const assetData = assetsData[usedAsset.vaultAddress.toLowerCase()];
|
|
89
|
+
if (usedAsset.isSupplied) {
|
|
90
|
+
const amount = usedAsset.suppliedUsd;
|
|
91
|
+
acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
|
|
92
|
+
const rate = assetData.supplyRate;
|
|
93
|
+
const supplyInterest = calculateInterestEarned(amount, rate, 'year', true);
|
|
94
|
+
acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
95
|
+
}
|
|
96
|
+
if (usedAsset.isBorrowed) {
|
|
97
|
+
const amount = usedAsset.borrowedUsd;
|
|
98
|
+
acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
|
|
99
|
+
const rate = assetData.borrowRate;
|
|
100
|
+
const borrowInterest = calculateInterestEarned(amount, rate, 'year', true);
|
|
101
|
+
acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
102
|
+
}
|
|
103
|
+
return acc;
|
|
104
|
+
}, {
|
|
105
|
+
borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
|
|
106
|
+
});
|
|
107
|
+
const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
|
|
108
|
+
const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
|
|
109
|
+
const balance = new Dec(suppliedUsd).sub(borrowedUsd);
|
|
110
|
+
const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
|
|
111
|
+
return { netApy, totalInterestUsd, incentiveUsd };
|
|
112
|
+
};
|
|
113
|
+
export const getEulerV2AggregatedData = (_a) => {
|
|
114
|
+
var { usedAssets, assetsData, network } = _a, rest = __rest(_a, ["usedAssets", "assetsData", "network"]);
|
|
115
|
+
const payload = {};
|
|
116
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
117
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
118
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
119
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new Dec(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].collateralFactor));
|
|
120
|
+
payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new Dec(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].liquidationRatio));
|
|
121
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
122
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
123
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
124
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
125
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
|
|
126
|
+
payload.netApy = netApy;
|
|
127
|
+
payload.incentiveUsd = incentiveUsd;
|
|
128
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
129
|
+
payload.minRatio = '100';
|
|
130
|
+
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
131
|
+
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
132
|
+
const { leveragedType, leveragedAsset, leveragedVault } = isLeveragedPos(usedAssets);
|
|
133
|
+
payload.leveragedType = leveragedType;
|
|
134
|
+
if (leveragedType !== '') {
|
|
135
|
+
payload.leveragedAsset = leveragedAsset;
|
|
136
|
+
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
137
|
+
if (leveragedType === 'lsd-leverage') {
|
|
138
|
+
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
139
|
+
if (ethAsset) {
|
|
140
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
|
|
141
|
+
assetPrice = new Dec(assetPrice).div(ethAsset.price).toString();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
145
|
+
}
|
|
146
|
+
return payload;
|
|
147
|
+
};
|
|
148
|
+
export const getEulerV2BorrowRate = (interestRate) => {
|
|
149
|
+
const _interestRate = new Dec(interestRate).div(1e27).toString();
|
|
150
|
+
const secondsPerYear = 31556953;
|
|
151
|
+
const a = new Dec(1).plus(_interestRate).pow(secondsPerYear - 1).toString();
|
|
152
|
+
return new Dec(new Dec(a).minus(1)).mul(100).toString();
|
|
153
|
+
};
|
|
154
|
+
export const getUtilizationRate = (totalBorrows, totalAssets) => new Dec(totalBorrows).div(totalAssets).toString();
|
|
155
|
+
export const getEulerV2SupplyRate = (borrowRate, utilizationRate, _interestFee) => {
|
|
156
|
+
const interestFee = new Dec(_interestFee).div(10000);
|
|
157
|
+
const fee = new Dec(1).minus(interestFee);
|
|
158
|
+
return new Dec(borrowRate).mul(utilizationRate).mul(fee).toString();
|
|
159
|
+
};
|
|
160
|
+
const getLiquidityChanges = (action, amount, isBorrowOperation) => {
|
|
161
|
+
let liquidityAdded;
|
|
162
|
+
let liquidityRemoved;
|
|
163
|
+
if (isBorrowOperation) {
|
|
164
|
+
liquidityAdded = action === 'payback' ? amount : '0';
|
|
165
|
+
liquidityRemoved = action === 'borrow' ? amount : '0';
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
liquidityAdded = action === 'collateral' ? amount : '0';
|
|
169
|
+
liquidityRemoved = action === 'withdraw' ? amount : '0';
|
|
170
|
+
}
|
|
171
|
+
return { liquidityAdded, liquidityRemoved };
|
|
172
|
+
};
|
|
173
|
+
export const getApyAfterValuesEstimationEulerV2 = (actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
const eulerV2ViewContract = EulerV2ViewContract(web3, network);
|
|
175
|
+
const multicallData = [];
|
|
176
|
+
const apyAfterValuesEstimationParams = [];
|
|
177
|
+
actions.forEach(({ action, amount, asset, vaultAddress, }) => {
|
|
178
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
179
|
+
const isBorrowOperation = borrowOperations.includes(action);
|
|
180
|
+
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amountInWei, isBorrowOperation);
|
|
181
|
+
apyAfterValuesEstimationParams.push([
|
|
182
|
+
vaultAddress,
|
|
183
|
+
borrowOperations.includes(action),
|
|
184
|
+
liquidityAdded,
|
|
185
|
+
liquidityRemoved,
|
|
186
|
+
]);
|
|
187
|
+
multicallData.push({
|
|
188
|
+
target: eulerV2ViewContract.options.address,
|
|
189
|
+
abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getVaultInfoFull'),
|
|
190
|
+
params: [vaultAddress],
|
|
191
|
+
// @DEV gas usage is HUGE if vault has a lot of collaterals, so be careful, this can break if they add more collaterals
|
|
192
|
+
gasLimit: 10000000,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
multicallData.push({
|
|
196
|
+
target: eulerV2ViewContract.options.address,
|
|
197
|
+
abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getApyAfterValuesEstimation'),
|
|
198
|
+
params: [apyAfterValuesEstimationParams],
|
|
199
|
+
});
|
|
200
|
+
const multicallRes = yield multicall(multicallData, web3, network);
|
|
201
|
+
const numOfActions = actions.length;
|
|
202
|
+
const data = {};
|
|
203
|
+
for (let i = 0; i < numOfActions; i += 1) {
|
|
204
|
+
const _interestRate = multicallRes[numOfActions].estimatedBorrowRates[i];
|
|
205
|
+
const vaultInfo = multicallRes[i][0];
|
|
206
|
+
const decimals = vaultInfo.decimals;
|
|
207
|
+
const borrowRate = getEulerV2BorrowRate(_interestRate);
|
|
208
|
+
const amount = new Dec(actions[i].amount).mul(Math.pow(10, decimals)).toString();
|
|
209
|
+
const action = actions[i].action;
|
|
210
|
+
const isBorrowOperation = borrowOperations.includes(action);
|
|
211
|
+
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amount, isBorrowOperation);
|
|
212
|
+
const totalBorrows = new Dec(vaultInfo.totalBorrows).add(isBorrowOperation ? liquidityRemoved : '0').sub(isBorrowOperation ? liquidityAdded : '0').toString();
|
|
213
|
+
const totalAssets = new Dec(vaultInfo.totalAssets).add(isBorrowOperation ? '0' : liquidityAdded).sub(isBorrowOperation ? '0' : liquidityRemoved).toString();
|
|
214
|
+
const utilizationRate = getUtilizationRate(totalBorrows, totalAssets);
|
|
215
|
+
data[vaultInfo.vaultAddr.toLowerCase()] = {
|
|
216
|
+
borrowRate,
|
|
217
|
+
supplyRate: getEulerV2SupplyRate(borrowRate, utilizationRate, vaultInfo.interestFee),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return data;
|
|
221
|
+
});
|
package/esm/helpers/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export * as makerHelpers from './makerHelpers';
|
|
|
6
6
|
export * as chickenBondsHelpers from './chickenBondsHelpers';
|
|
7
7
|
export * as morphoBlueHelpers from './morphoBlueHelpers';
|
|
8
8
|
export * as llamaLendHelpers from './llamaLendHelpers';
|
|
9
|
-
export * as
|
|
9
|
+
export * as eulerV2Helpers from './eulerHelpers';
|
package/esm/helpers/index.js
CHANGED
|
@@ -6,4 +6,4 @@ export * as makerHelpers from './makerHelpers';
|
|
|
6
6
|
export * as chickenBondsHelpers from './chickenBondsHelpers';
|
|
7
7
|
export * as morphoBlueHelpers from './morphoBlueHelpers';
|
|
8
8
|
export * as llamaLendHelpers from './llamaLendHelpers';
|
|
9
|
-
export * as
|
|
9
|
+
export * as eulerV2Helpers from './eulerHelpers';
|
package/esm/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ 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';
|
|
12
11
|
import * as maker from './maker';
|
|
13
12
|
import * as staking from './staking';
|
|
14
13
|
import * as multicall from './multicall';
|
|
@@ -19,5 +18,6 @@ import * as chickenBonds from './chickenBonds';
|
|
|
19
18
|
import * as exchange from './exchange';
|
|
20
19
|
import * as morphoBlue from './morphoBlue';
|
|
21
20
|
import * as llamaLend from './llamaLend';
|
|
21
|
+
import * as eulerV2 from './eulerV2';
|
|
22
22
|
export * from './types';
|
|
23
|
-
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity,
|
|
23
|
+
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, };
|
package/esm/index.js
CHANGED
|
@@ -8,7 +8,6 @@ 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';
|
|
12
11
|
import * as maker from './maker';
|
|
13
12
|
import * as staking from './staking';
|
|
14
13
|
import * as multicall from './multicall';
|
|
@@ -19,5 +18,6 @@ import * as chickenBonds from './chickenBonds';
|
|
|
19
18
|
import * as exchange from './exchange';
|
|
20
19
|
import * as morphoBlue from './morphoBlue';
|
|
21
20
|
import * as llamaLend from './llamaLend';
|
|
21
|
+
import * as eulerV2 from './eulerV2';
|
|
22
22
|
export * from './types';
|
|
23
|
-
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity,
|
|
23
|
+
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NetworkNumber } from '../../types/common';
|
|
2
|
+
import { EulerV2Market } from '../../types';
|
|
3
|
+
export declare const eUSDC2: (networkId: NetworkNumber) => EulerV2Market;
|
|
4
|
+
export declare const eWETH2: (networkId: NetworkNumber) => EulerV2Market;
|
|
5
|
+
export declare const EulerV2Markets: (networkId: NetworkNumber) => {
|
|
6
|
+
readonly "eUSDC-2": EulerV2Market;
|
|
7
|
+
readonly "eWETH-2": EulerV2Market;
|
|
8
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NetworkNumber } from '../../types/common';
|
|
2
|
+
import { EulerV2Versions } from '../../types';
|
|
3
|
+
export const eUSDC2 = (networkId) => ({
|
|
4
|
+
chainIds: [NetworkNumber.Eth],
|
|
5
|
+
label: 'Euler Prime USDC',
|
|
6
|
+
shortLabel: 'eUSDC-2',
|
|
7
|
+
value: EulerV2Versions.eUSDC2,
|
|
8
|
+
asset: 'USDC',
|
|
9
|
+
secondLabel: 'Market',
|
|
10
|
+
marketAddress: '0x797DD80692c3b2dAdabCe8e30C07fDE5307D48a9',
|
|
11
|
+
});
|
|
12
|
+
export const eWETH2 = (networkId) => ({
|
|
13
|
+
chainIds: [NetworkNumber.Eth],
|
|
14
|
+
label: 'Euler Prime WETH',
|
|
15
|
+
shortLabel: 'eWETH-2',
|
|
16
|
+
value: EulerV2Versions.eWETH2,
|
|
17
|
+
asset: 'WETH',
|
|
18
|
+
secondLabel: 'Market',
|
|
19
|
+
marketAddress: '0xD8b27CF359b7D15710a5BE299AF6e7Bf904984C2',
|
|
20
|
+
});
|
|
21
|
+
export const EulerV2Markets = (networkId) => ({
|
|
22
|
+
[EulerV2Versions.eUSDC2]: eUSDC2(networkId),
|
|
23
|
+
[EulerV2Versions.eWETH2]: eWETH2(networkId),
|
|
24
|
+
});
|
package/esm/markets/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ 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 {
|
|
7
|
+
export { EulerV2Markets } from './euler';
|
package/esm/markets/index.js
CHANGED
|
@@ -4,4 +4,4 @@ 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 {
|
|
7
|
+
export { EulerV2Markets } from './euler';
|
|
@@ -16,7 +16,7 @@ export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borr
|
|
|
16
16
|
return '0';
|
|
17
17
|
};
|
|
18
18
|
export const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new Dec(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
19
|
-
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'
|
|
19
|
+
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
|
|
20
20
|
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
21
21
|
let borrowUnstable = 0;
|
|
22
22
|
let supplyStable = 0;
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -20,3 +20,5 @@ export declare const bytesToString: (hex: string) => string;
|
|
|
20
20
|
*/
|
|
21
21
|
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
|
22
22
|
export declare const isEnabledOnBitmap: (bitmap: number, assetId: number) => bigint;
|
|
23
|
+
export declare const MAXUINT: string;
|
|
24
|
+
export declare const isMaxuint: (amount: string) => boolean;
|
package/esm/services/utils.js
CHANGED
|
@@ -33,3 +33,5 @@ export const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
|
|
|
33
33
|
};
|
|
34
34
|
// eslint-disable-next-line no-bitwise
|
|
35
35
|
export const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
36
|
+
export const MAXUINT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
37
|
+
export const isMaxuint = (amount) => compareAddresses(MAXUINT, amount);
|
package/esm/staking/staking.js
CHANGED
|
@@ -82,7 +82,6 @@ export const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
82
82
|
return new Dec(data.data.skyData[0].sky_savings_rate_apy).mul(100).toString();
|
|
83
83
|
});
|
|
84
84
|
const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
console.log('getSuperOETHApy');
|
|
86
85
|
const res = yield fetch('https://origin.squids.live/origin-squid/graphql', {
|
|
87
86
|
method: 'POST',
|
|
88
87
|
headers: {
|
|
@@ -106,7 +105,6 @@ const getApyFromDfsApi = (asset) => __awaiter(void 0, void 0, void 0, function*
|
|
|
106
105
|
});
|
|
107
106
|
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS'];
|
|
108
107
|
export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
109
|
-
console.log('getStakingApy', asset, blockNumber, fromBlock);
|
|
110
108
|
try {
|
|
111
109
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
112
110
|
return getStETHApr(web3, fromBlock, blockNumber);
|