@defisaver/positions-sdk 0.0.165 → 0.0.166-dev2
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/cjs/config/contracts.d.ts +72 -0
- package/cjs/config/contracts.js +6 -0
- package/cjs/contracts.d.ts +1 -0
- package/cjs/contracts.js +2 -1
- package/cjs/eulerV2/index.d.ts +40 -0
- package/cjs/eulerV2/index.js +207 -0
- package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
- package/cjs/helpers/eulerHelpers/index.js +232 -0
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/markets/euler/index.d.ts +10 -0
- package/cjs/markets/euler/index.js +41 -0
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/services/utils.d.ts +2 -0
- package/cjs/services/utils.js +4 -1
- package/cjs/staking/staking.d.ts +1 -0
- package/cjs/staking/staking.js +10 -2
- package/cjs/types/contracts/generated/EulerV2View.d.ts +333 -0
- package/cjs/types/contracts/generated/EulerV2View.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +1 -0
- package/cjs/types/euler.d.ts +148 -0
- package/cjs/types/euler.js +15 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/esm/config/contracts.d.ts +72 -0
- package/esm/config/contracts.js +6 -0
- package/esm/contracts.d.ts +1 -0
- package/esm/contracts.js +1 -0
- package/esm/eulerV2/index.d.ts +40 -0
- package/esm/eulerV2/index.js +199 -0
- package/esm/helpers/eulerHelpers/index.d.ts +27 -0
- package/esm/helpers/eulerHelpers/index.js +219 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/markets/euler/index.d.ts +10 -0
- package/esm/markets/euler/index.js +34 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/services/utils.d.ts +2 -0
- package/esm/services/utils.js +2 -0
- package/esm/staking/staking.d.ts +1 -0
- package/esm/staking/staking.js +8 -1
- package/esm/types/contracts/generated/EulerV2View.d.ts +333 -0
- package/esm/types/contracts/generated/EulerV2View.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +1 -0
- package/esm/types/euler.d.ts +148 -0
- package/esm/types/euler.js +12 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/package.json +2 -1
- package/src/config/contracts.js +6 -0
- package/src/contracts.ts +2 -0
- package/src/eulerV2/index.ts +286 -0
- package/src/helpers/eulerHelpers/index.ts +231 -0
- package/src/helpers/index.ts +2 -1
- package/src/index.ts +2 -0
- package/src/markets/euler/index.ts +38 -0
- package/src/markets/index.ts +3 -1
- package/src/services/utils.ts +3 -0
- package/src/staking/staking.ts +8 -1
- package/src/types/contracts/generated/EulerV2View.ts +434 -0
- package/src/types/contracts/generated/index.ts +1 -0
- package/src/types/euler.ts +171 -0
- package/src/types/index.ts +2 -1
|
@@ -0,0 +1,232 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getApyAfterValuesEstimationEulerV2 = exports.getEulerV2SupplyRate = exports.getUtilizationRate = exports.getEulerV2BorrowRate = exports.getEulerV2AggregatedData = exports.calculateNetApy = exports.isLeveragedPos = void 0;
|
|
27
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
28
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
29
|
+
const moneymarket_1 = require("../../moneymarket");
|
|
30
|
+
const staking_1 = require("../../staking");
|
|
31
|
+
const contracts_1 = require("../../contracts");
|
|
32
|
+
const constants_1 = require("../../constants");
|
|
33
|
+
const multicall_1 = require("../../multicall");
|
|
34
|
+
const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
35
|
+
let borrowUnstable = 0;
|
|
36
|
+
let supplyStable = 0;
|
|
37
|
+
let borrowStable = 0;
|
|
38
|
+
let supplyUnstable = 0;
|
|
39
|
+
let longAsset = '';
|
|
40
|
+
let shortAsset = '';
|
|
41
|
+
let leverageAssetVault = '';
|
|
42
|
+
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, vaultAddress, }) => {
|
|
43
|
+
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
44
|
+
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
45
|
+
if (isSupplied && moneymarket_1.STABLE_ASSETS.includes(symbol) && collateral)
|
|
46
|
+
supplyStable += 1;
|
|
47
|
+
if (isBorrowed && moneymarket_1.STABLE_ASSETS.includes(symbol))
|
|
48
|
+
borrowStable += 1;
|
|
49
|
+
if (isBorrowed && !moneymarket_1.STABLE_ASSETS.includes(symbol)) {
|
|
50
|
+
borrowUnstable += 1;
|
|
51
|
+
shortAsset = symbol;
|
|
52
|
+
leverageAssetVault = vaultAddress;
|
|
53
|
+
}
|
|
54
|
+
if (isSupplied && !moneymarket_1.STABLE_ASSETS.includes(symbol) && collateral) {
|
|
55
|
+
supplyUnstable += 1;
|
|
56
|
+
longAsset = symbol;
|
|
57
|
+
leverageAssetVault = vaultAddress;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
61
|
+
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
62
|
+
// lsd -> liquid staking derivative
|
|
63
|
+
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
64
|
+
if (isLong) {
|
|
65
|
+
return {
|
|
66
|
+
leveragedType: 'long',
|
|
67
|
+
leveragedAsset: longAsset,
|
|
68
|
+
leveragedVault: leverageAssetVault,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (isShort) {
|
|
72
|
+
return {
|
|
73
|
+
leveragedType: 'short',
|
|
74
|
+
leveragedAsset: shortAsset,
|
|
75
|
+
leveragedVault: leverageAssetVault,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (isLsdLeveraged) {
|
|
79
|
+
return {
|
|
80
|
+
leveragedType: 'lsd-leverage',
|
|
81
|
+
leveragedAsset: longAsset,
|
|
82
|
+
leveragedVault: leverageAssetVault,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
leveragedType: '',
|
|
87
|
+
leveragedAsset: '',
|
|
88
|
+
leveragedVault: '',
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.isLeveragedPos = isLeveragedPos;
|
|
92
|
+
const calculateNetApy = (usedAssets, assetsData) => {
|
|
93
|
+
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
94
|
+
const acc = Object.assign({}, _acc);
|
|
95
|
+
const assetData = assetsData[usedAsset.vaultAddress.toLowerCase()];
|
|
96
|
+
if (usedAsset.isSupplied) {
|
|
97
|
+
const amount = usedAsset.suppliedUsd;
|
|
98
|
+
acc.suppliedUsd = new decimal_js_1.default(acc.suppliedUsd).add(amount).toString();
|
|
99
|
+
const rate = assetData.supplyRate;
|
|
100
|
+
const supplyInterest = (0, staking_1.calculateInterestEarned)(amount, rate, 'year', true);
|
|
101
|
+
acc.supplyInterest = new decimal_js_1.default(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
102
|
+
}
|
|
103
|
+
if (usedAsset.isBorrowed) {
|
|
104
|
+
const amount = usedAsset.borrowedUsd;
|
|
105
|
+
acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
|
|
106
|
+
const rate = assetData.borrowRate;
|
|
107
|
+
const borrowInterest = (0, staking_1.calculateInterestEarned)(amount, rate, 'year', true);
|
|
108
|
+
acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
109
|
+
}
|
|
110
|
+
return acc;
|
|
111
|
+
}, {
|
|
112
|
+
borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
|
|
113
|
+
});
|
|
114
|
+
const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
|
|
115
|
+
const totalInterestUsd = new decimal_js_1.default(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
|
|
116
|
+
const balance = new decimal_js_1.default(suppliedUsd).sub(borrowedUsd);
|
|
117
|
+
const netApy = new decimal_js_1.default(totalInterestUsd).div(balance).times(100).toString();
|
|
118
|
+
return { netApy, totalInterestUsd, incentiveUsd };
|
|
119
|
+
};
|
|
120
|
+
exports.calculateNetApy = calculateNetApy;
|
|
121
|
+
const getEulerV2AggregatedData = (_a) => {
|
|
122
|
+
var { usedAssets, assetsData, network } = _a, rest = __rest(_a, ["usedAssets", "assetsData", "network"]);
|
|
123
|
+
const payload = {};
|
|
124
|
+
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
125
|
+
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
126
|
+
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
127
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new decimal_js_1.default(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].collateralFactor));
|
|
128
|
+
payload.liquidationLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new decimal_js_1.default(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].liquidationRatio));
|
|
129
|
+
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
130
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
131
|
+
payload.ratio = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
132
|
+
payload.collRatio = +payload.suppliedUsd ? new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
133
|
+
const { netApy, incentiveUsd, totalInterestUsd } = (0, exports.calculateNetApy)(usedAssets, assetsData);
|
|
134
|
+
payload.netApy = netApy;
|
|
135
|
+
payload.incentiveUsd = incentiveUsd;
|
|
136
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
137
|
+
payload.minRatio = '100';
|
|
138
|
+
payload.liqRatio = new decimal_js_1.default(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
139
|
+
payload.liqPercent = new decimal_js_1.default(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
140
|
+
const { leveragedType, leveragedAsset, leveragedVault } = (0, exports.isLeveragedPos)(usedAssets);
|
|
141
|
+
payload.leveragedType = leveragedType;
|
|
142
|
+
if (leveragedType !== '') {
|
|
143
|
+
payload.leveragedAsset = leveragedAsset;
|
|
144
|
+
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
145
|
+
if (leveragedType === 'lsd-leverage') {
|
|
146
|
+
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
147
|
+
if (ethAsset) {
|
|
148
|
+
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
|
|
149
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(ethAsset.price).toString();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
153
|
+
}
|
|
154
|
+
return payload;
|
|
155
|
+
};
|
|
156
|
+
exports.getEulerV2AggregatedData = getEulerV2AggregatedData;
|
|
157
|
+
const getEulerV2BorrowRate = (interestRate) => {
|
|
158
|
+
const _interestRate = new decimal_js_1.default(interestRate).div(1e27).toString();
|
|
159
|
+
const secondsPerYear = 31556953;
|
|
160
|
+
const a = new decimal_js_1.default(1).plus(_interestRate).pow(secondsPerYear - 1).toString();
|
|
161
|
+
return new decimal_js_1.default(new decimal_js_1.default(a).minus(1)).mul(100).toString();
|
|
162
|
+
};
|
|
163
|
+
exports.getEulerV2BorrowRate = getEulerV2BorrowRate;
|
|
164
|
+
const getUtilizationRate = (totalBorrows, totalAssets) => new decimal_js_1.default(totalBorrows).div(totalAssets).toString();
|
|
165
|
+
exports.getUtilizationRate = getUtilizationRate;
|
|
166
|
+
const getEulerV2SupplyRate = (borrowRate, utilizationRate, _interestFee) => {
|
|
167
|
+
const interestFee = new decimal_js_1.default(_interestFee).div(10000);
|
|
168
|
+
const fee = new decimal_js_1.default(1).minus(interestFee);
|
|
169
|
+
return new decimal_js_1.default(borrowRate).mul(utilizationRate).mul(fee).toString();
|
|
170
|
+
};
|
|
171
|
+
exports.getEulerV2SupplyRate = getEulerV2SupplyRate;
|
|
172
|
+
const getLiquidityChanges = (action, amount, isBorrowOperation) => {
|
|
173
|
+
let liquidityAdded;
|
|
174
|
+
let liquidityRemoved;
|
|
175
|
+
if (isBorrowOperation) {
|
|
176
|
+
liquidityAdded = action === 'payback' ? amount : '0';
|
|
177
|
+
liquidityRemoved = action === 'borrow' ? amount : '0';
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
liquidityAdded = action === 'collateral' ? amount : '0';
|
|
181
|
+
liquidityRemoved = action === 'withdraw' ? amount : '0';
|
|
182
|
+
}
|
|
183
|
+
return { liquidityAdded, liquidityRemoved };
|
|
184
|
+
};
|
|
185
|
+
const getApyAfterValuesEstimationEulerV2 = (actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
|
+
const eulerV2ViewContract = (0, contracts_1.EulerV2ViewContract)(web3, network);
|
|
187
|
+
const multicallData = [];
|
|
188
|
+
const apyAfterValuesEstimationParams = [];
|
|
189
|
+
actions.forEach(({ action, amount, asset, vaultAddress, }) => {
|
|
190
|
+
const amountInWei = (0, tokens_1.assetAmountInWei)(amount, asset);
|
|
191
|
+
const isBorrowOperation = constants_1.borrowOperations.includes(action);
|
|
192
|
+
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amountInWei, isBorrowOperation);
|
|
193
|
+
apyAfterValuesEstimationParams.push([
|
|
194
|
+
vaultAddress,
|
|
195
|
+
constants_1.borrowOperations.includes(action),
|
|
196
|
+
liquidityAdded,
|
|
197
|
+
liquidityRemoved,
|
|
198
|
+
]);
|
|
199
|
+
multicallData.push({
|
|
200
|
+
target: eulerV2ViewContract.options.address,
|
|
201
|
+
abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getVaultInfoFull'),
|
|
202
|
+
params: [vaultAddress],
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
multicallData.push({
|
|
206
|
+
target: eulerV2ViewContract.options.address,
|
|
207
|
+
abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getApyAfterValuesEstimation'),
|
|
208
|
+
params: [apyAfterValuesEstimationParams],
|
|
209
|
+
});
|
|
210
|
+
const multicallRes = yield (0, multicall_1.multicall)(multicallData, web3, network);
|
|
211
|
+
const numOfActions = actions.length;
|
|
212
|
+
const data = {};
|
|
213
|
+
for (let i = 0; i < numOfActions; i += 1) {
|
|
214
|
+
const _interestRate = multicallRes[numOfActions].estimatedBorrowRates[i];
|
|
215
|
+
const vaultInfo = multicallRes[i][0];
|
|
216
|
+
const decimals = vaultInfo.decimals;
|
|
217
|
+
const borrowRate = (0, exports.getEulerV2BorrowRate)(_interestRate);
|
|
218
|
+
const amount = new decimal_js_1.default(actions[i].amount).mul(Math.pow(10, decimals)).toString();
|
|
219
|
+
const action = actions[i].action;
|
|
220
|
+
const isBorrowOperation = constants_1.borrowOperations.includes(action);
|
|
221
|
+
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amount, isBorrowOperation);
|
|
222
|
+
const totalBorrows = new decimal_js_1.default(vaultInfo.totalBorrows).add(isBorrowOperation ? liquidityRemoved : '0').sub(isBorrowOperation ? liquidityAdded : '0').toString();
|
|
223
|
+
const totalAssets = new decimal_js_1.default(vaultInfo.totalAssets).add(isBorrowOperation ? '0' : liquidityAdded).sub(isBorrowOperation ? '0' : liquidityRemoved).toString();
|
|
224
|
+
const utilizationRate = (0, exports.getUtilizationRate)(totalBorrows, totalAssets);
|
|
225
|
+
data[vaultInfo.vaultAddr.toLowerCase()] = {
|
|
226
|
+
borrowRate,
|
|
227
|
+
supplyRate: (0, exports.getEulerV2SupplyRate)(borrowRate, utilizationRate, vaultInfo.interestFee),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return data;
|
|
231
|
+
});
|
|
232
|
+
exports.getApyAfterValuesEstimationEulerV2 = getApyAfterValuesEstimationEulerV2;
|
package/cjs/helpers/index.d.ts
CHANGED
|
@@ -6,3 +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 eulerV2Helpers from './eulerHelpers';
|
package/cjs/helpers/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
26
|
+
exports.eulerV2Helpers = exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
27
27
|
exports.aaveHelpers = __importStar(require("./aaveHelpers"));
|
|
28
28
|
exports.compoundHelpers = __importStar(require("./compoundHelpers"));
|
|
29
29
|
exports.sparkHelpers = __importStar(require("./sparkHelpers"));
|
|
@@ -32,3 +32,4 @@ exports.makerHelpers = __importStar(require("./makerHelpers"));
|
|
|
32
32
|
exports.chickenBondsHelpers = __importStar(require("./chickenBondsHelpers"));
|
|
33
33
|
exports.morphoBlueHelpers = __importStar(require("./morphoBlueHelpers"));
|
|
34
34
|
exports.llamaLendHelpers = __importStar(require("./llamaLendHelpers"));
|
|
35
|
+
exports.eulerV2Helpers = __importStar(require("./eulerHelpers"));
|
package/cjs/index.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ import * as chickenBonds from './chickenBonds';
|
|
|
18
18
|
import * as exchange from './exchange';
|
|
19
19
|
import * as morphoBlue from './morphoBlue';
|
|
20
20
|
import * as llamaLend from './llamaLend';
|
|
21
|
+
import * as eulerV2 from './eulerV2';
|
|
21
22
|
export * from './types';
|
|
22
|
-
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, };
|
|
23
|
+
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, 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.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.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;
|
|
@@ -66,4 +66,6 @@ const morphoBlue = __importStar(require("./morphoBlue"));
|
|
|
66
66
|
exports.morphoBlue = morphoBlue;
|
|
67
67
|
const llamaLend = __importStar(require("./llamaLend"));
|
|
68
68
|
exports.llamaLend = llamaLend;
|
|
69
|
+
const eulerV2 = __importStar(require("./eulerV2"));
|
|
70
|
+
exports.eulerV2 = eulerV2;
|
|
69
71
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NetworkNumber } from '../../types/common';
|
|
2
|
+
import { EulerV2Market } from '../../types';
|
|
3
|
+
export declare const eUSDC2: (networkId: NetworkNumber) => EulerV2Market;
|
|
4
|
+
export declare const eUSDC8: (networkId: NetworkNumber) => EulerV2Market;
|
|
5
|
+
export declare const eWETH2: (networkId: NetworkNumber) => EulerV2Market;
|
|
6
|
+
export declare const EulerV2Markets: (networkId: NetworkNumber) => {
|
|
7
|
+
readonly "eUSDC-2": EulerV2Market;
|
|
8
|
+
readonly "eUSDC-8": EulerV2Market;
|
|
9
|
+
readonly "eWETH-2": EulerV2Market;
|
|
10
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EulerV2Markets = exports.eWETH2 = exports.eUSDC8 = exports.eUSDC2 = void 0;
|
|
4
|
+
const common_1 = require("../../types/common");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const eUSDC2 = (networkId) => ({
|
|
7
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
8
|
+
label: 'Euler Prime USDC',
|
|
9
|
+
shortLabel: 'eUSDC-2',
|
|
10
|
+
value: types_1.EulerV2Versions.eUSDC2,
|
|
11
|
+
asset: 'USDC',
|
|
12
|
+
secondLabel: 'Market',
|
|
13
|
+
marketAddress: '0x797DD80692c3b2dAdabCe8e30C07fDE5307D48a9',
|
|
14
|
+
});
|
|
15
|
+
exports.eUSDC2 = eUSDC2;
|
|
16
|
+
const eUSDC8 = (networkId) => ({
|
|
17
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
18
|
+
label: 'Stablecoin Maxi USDC',
|
|
19
|
+
shortLabel: 'eUSDC-8',
|
|
20
|
+
value: types_1.EulerV2Versions.eUSDC8,
|
|
21
|
+
asset: 'USDC',
|
|
22
|
+
secondLabel: 'Market',
|
|
23
|
+
marketAddress: '0xce45EF0414dE3516cAF1BCf937bF7F2Cf67873De',
|
|
24
|
+
});
|
|
25
|
+
exports.eUSDC8 = eUSDC8;
|
|
26
|
+
const eWETH2 = (networkId) => ({
|
|
27
|
+
chainIds: [common_1.NetworkNumber.Eth],
|
|
28
|
+
label: 'Euler Prime WETH',
|
|
29
|
+
shortLabel: 'eWETH-2',
|
|
30
|
+
value: types_1.EulerV2Versions.eWETH2,
|
|
31
|
+
asset: 'WETH',
|
|
32
|
+
secondLabel: 'Market',
|
|
33
|
+
marketAddress: '0xD8b27CF359b7D15710a5BE299AF6e7Bf904984C2',
|
|
34
|
+
});
|
|
35
|
+
exports.eWETH2 = eWETH2;
|
|
36
|
+
const EulerV2Markets = (networkId) => ({
|
|
37
|
+
[types_1.EulerV2Versions.eUSDC2]: (0, exports.eUSDC2)(networkId),
|
|
38
|
+
[types_1.EulerV2Versions.eUSDC8]: (0, exports.eUSDC8)(networkId),
|
|
39
|
+
[types_1.EulerV2Versions.eWETH2]: (0, exports.eWETH2)(networkId),
|
|
40
|
+
});
|
|
41
|
+
exports.EulerV2Markets = EulerV2Markets;
|
package/cjs/markets/index.d.ts
CHANGED
package/cjs/markets/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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,3 +26,5 @@ 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 euler_1 = require("./euler");
|
|
30
|
+
Object.defineProperty(exports, "EulerV2Markets", { enumerable: true, get: function () { return euler_1.EulerV2Markets; } });
|
package/cjs/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/cjs/services/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isEnabledOnBitmap = exports.mapRange = exports.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.getWeiAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
6
|
+
exports.isMaxuint = exports.MAXUINT = exports.isEnabledOnBitmap = exports.mapRange = exports.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.getWeiAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const tokens_1 = require("@defisaver/tokens");
|
|
9
9
|
const common_1 = require("../types/common");
|
|
@@ -56,3 +56,6 @@ exports.mapRange = mapRange;
|
|
|
56
56
|
// eslint-disable-next-line no-bitwise
|
|
57
57
|
const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
58
58
|
exports.isEnabledOnBitmap = isEnabledOnBitmap;
|
|
59
|
+
exports.MAXUINT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
60
|
+
const isMaxuint = (amount) => (0, exports.compareAddresses)(exports.MAXUINT, amount);
|
|
61
|
+
exports.isMaxuint = isMaxuint;
|
package/cjs/staking/staking.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const getStETHApr: (web3: Web3, fromBlock?: number, blockNumber?:
|
|
|
4
4
|
export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
5
5
|
export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
6
|
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
7
|
+
export declare const getSsrApy: () => Promise<string>;
|
|
7
8
|
export declare const STAKING_ASSETS: string[];
|
|
8
9
|
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | "0" | undefined;
|
|
9
10
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
package/cjs/staking/staking.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getDsrApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
|
|
15
|
+
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getSsrApy = exports.getDsrApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const contracts_1 = require("../contracts");
|
|
18
18
|
const common_1 = require("../types/common");
|
|
@@ -86,6 +86,12 @@ const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, vo
|
|
|
86
86
|
.toString();
|
|
87
87
|
});
|
|
88
88
|
exports.getDsrApy = getDsrApy;
|
|
89
|
+
const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const res = yield fetch('https://app.defisaver.com/api/sky/data');
|
|
91
|
+
const data = yield res.json();
|
|
92
|
+
return new decimal_js_1.default(data.data.skyData[0].sky_savings_rate_apy).mul(100).toString();
|
|
93
|
+
});
|
|
94
|
+
exports.getSsrApy = getSsrApy;
|
|
89
95
|
const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
96
|
console.log('getSuperOETHApy');
|
|
91
97
|
const res = yield fetch('https://origin.squids.live/origin-squid/graphql', {
|
|
@@ -109,7 +115,7 @@ const getApyFromDfsApi = (asset) => __awaiter(void 0, void 0, void 0, function*
|
|
|
109
115
|
const data = yield res.json();
|
|
110
116
|
return data.apy;
|
|
111
117
|
});
|
|
112
|
-
exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb'];
|
|
118
|
+
exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS'];
|
|
113
119
|
const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
114
120
|
console.log('getStakingApy', asset, blockNumber, fromBlock);
|
|
115
121
|
try {
|
|
@@ -137,6 +143,8 @@ const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefine
|
|
|
137
143
|
return getApyFromDfsApi('pufETH');
|
|
138
144
|
if (asset === 'wsuperOETHb')
|
|
139
145
|
return getSuperOETHApy();
|
|
146
|
+
if (asset === 'sUSDS')
|
|
147
|
+
return (0, exports.getSsrApy)();
|
|
140
148
|
}
|
|
141
149
|
catch (e) {
|
|
142
150
|
console.error(`Failed to fetch APY for ${asset}`);
|