@defisaver/positions-sdk 2.1.72-aave-v4-4-dev → 2.1.72-aave-v4-5-dev
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/aaveV4/index.js +9 -4
- package/esm/aaveV4/index.js +9 -4
- package/package.json +2 -2
- package/src/aaveV4/index.ts +9 -4
package/cjs/aaveV4/index.js
CHANGED
|
@@ -79,6 +79,7 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
|
|
|
79
79
|
}, {}),
|
|
80
80
|
};
|
|
81
81
|
});
|
|
82
|
+
// TODO AaveV4: Will be used for after values, onchain data is available when fetching position data
|
|
82
83
|
const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
|
|
83
84
|
const collaterals = [];
|
|
84
85
|
const debts = [];
|
|
@@ -151,7 +152,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
151
152
|
description: `Native ${symbol} yield.`,
|
|
152
153
|
});
|
|
153
154
|
if (reserveAsset.borrowable) {
|
|
154
|
-
//
|
|
155
|
+
// When borrowing assets whose value increases over time
|
|
155
156
|
borrowIncentives.push({
|
|
156
157
|
apy: new decimal_js_1.default(yieldApy).mul(-1).toString(),
|
|
157
158
|
token: symbol,
|
|
@@ -166,19 +167,23 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
166
167
|
const totalDebtRaw = (_d = reserveAsset.totalDebt) !== null && _d !== void 0 ? _d : 0;
|
|
167
168
|
const supplyCapRaw = (_e = reserveAsset.supplyCap) !== null && _e !== void 0 ? _e : 0;
|
|
168
169
|
const borrowCapRaw = (_f = reserveAsset.borrowCap) !== null && _f !== void 0 ? _f : 0;
|
|
170
|
+
const totalSuppliedDec = new decimal_js_1.default(totalSuppliedRaw.toString());
|
|
171
|
+
const totalDrawnDec = new decimal_js_1.default(totalDrawnRaw.toString());
|
|
172
|
+
const utilization = totalSuppliedDec.isZero() ? '0' : totalDrawnDec.times(100).div(totalSuppliedDec).toString();
|
|
169
173
|
/** @DEV Hub related calculations */
|
|
170
174
|
const drawnRate = new decimal_js_1.default(hubAsset.drawnRate.toString()).div(new decimal_js_1.default(10).pow(27));
|
|
171
175
|
const borrowApr = drawnRate.mul(100);
|
|
172
176
|
const totalDrawn = new decimal_js_1.default(hubAsset.totalDrawn.toString());
|
|
173
177
|
const liquidity = new decimal_js_1.default(hubAsset.liquidity.toString());
|
|
174
178
|
const swept = new decimal_js_1.default(hubAsset.swept.toString());
|
|
175
|
-
const
|
|
179
|
+
const hubUtilizationDenominator = totalDrawn.add(swept).add(liquidity);
|
|
180
|
+
const hubUtilization = hubUtilizationDenominator.isZero() ? new decimal_js_1.default(0) : totalDrawn.div(hubUtilizationDenominator);
|
|
176
181
|
const liquidityFee = new decimal_js_1.default(hubAsset.liquidityFee.toString()).div(new decimal_js_1.default(10).pow(4));
|
|
177
182
|
const totalDrawnShares = new decimal_js_1.default(hubAsset.totalDrawnShares.toString());
|
|
178
183
|
const totalPremiumShares = new decimal_js_1.default(hubAsset.totalPremiumShares.toString());
|
|
179
184
|
// TODO JK@JK premiumMultiplier should be added to supplyApr calculation (.mul(premiumMultiplier)
|
|
180
185
|
// TODO JKJ@JK when we confirm that this is the right way to calculate it
|
|
181
|
-
const premiumMultiplier = totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
186
|
+
const premiumMultiplier = totalDrawnShares.isZero() ? new decimal_js_1.default(1) : totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
182
187
|
const supplyApr = borrowApr.mul(hubUtilization).mul(new decimal_js_1.default(1).minus(liquidityFee));
|
|
183
188
|
return ({
|
|
184
189
|
symbol,
|
|
@@ -211,7 +216,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
211
216
|
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
212
217
|
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
213
218
|
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
214
|
-
utilization
|
|
219
|
+
utilization,
|
|
215
220
|
});
|
|
216
221
|
});
|
|
217
222
|
function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -36,6 +36,7 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
|
|
|
36
36
|
}, {}),
|
|
37
37
|
};
|
|
38
38
|
});
|
|
39
|
+
// TODO AaveV4: Will be used for after values, onchain data is available when fetching position data
|
|
39
40
|
const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
|
|
40
41
|
const collaterals = [];
|
|
41
42
|
const debts = [];
|
|
@@ -108,7 +109,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
108
109
|
description: `Native ${symbol} yield.`,
|
|
109
110
|
});
|
|
110
111
|
if (reserveAsset.borrowable) {
|
|
111
|
-
//
|
|
112
|
+
// When borrowing assets whose value increases over time
|
|
112
113
|
borrowIncentives.push({
|
|
113
114
|
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
114
115
|
token: symbol,
|
|
@@ -123,19 +124,23 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
123
124
|
const totalDebtRaw = (_d = reserveAsset.totalDebt) !== null && _d !== void 0 ? _d : 0;
|
|
124
125
|
const supplyCapRaw = (_e = reserveAsset.supplyCap) !== null && _e !== void 0 ? _e : 0;
|
|
125
126
|
const borrowCapRaw = (_f = reserveAsset.borrowCap) !== null && _f !== void 0 ? _f : 0;
|
|
127
|
+
const totalSuppliedDec = new Dec(totalSuppliedRaw.toString());
|
|
128
|
+
const totalDrawnDec = new Dec(totalDrawnRaw.toString());
|
|
129
|
+
const utilization = totalSuppliedDec.isZero() ? '0' : totalDrawnDec.times(100).div(totalSuppliedDec).toString();
|
|
126
130
|
/** @DEV Hub related calculations */
|
|
127
131
|
const drawnRate = new Dec(hubAsset.drawnRate.toString()).div(new Dec(10).pow(27));
|
|
128
132
|
const borrowApr = drawnRate.mul(100);
|
|
129
133
|
const totalDrawn = new Dec(hubAsset.totalDrawn.toString());
|
|
130
134
|
const liquidity = new Dec(hubAsset.liquidity.toString());
|
|
131
135
|
const swept = new Dec(hubAsset.swept.toString());
|
|
132
|
-
const
|
|
136
|
+
const hubUtilizationDenominator = totalDrawn.add(swept).add(liquidity);
|
|
137
|
+
const hubUtilization = hubUtilizationDenominator.isZero() ? new Dec(0) : totalDrawn.div(hubUtilizationDenominator);
|
|
133
138
|
const liquidityFee = new Dec(hubAsset.liquidityFee.toString()).div(new Dec(10).pow(4));
|
|
134
139
|
const totalDrawnShares = new Dec(hubAsset.totalDrawnShares.toString());
|
|
135
140
|
const totalPremiumShares = new Dec(hubAsset.totalPremiumShares.toString());
|
|
136
141
|
// TODO JK@JK premiumMultiplier should be added to supplyApr calculation (.mul(premiumMultiplier)
|
|
137
142
|
// TODO JKJ@JK when we confirm that this is the right way to calculate it
|
|
138
|
-
const premiumMultiplier = totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
143
|
+
const premiumMultiplier = totalDrawnShares.isZero() ? new Dec(1) : totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
139
144
|
const supplyApr = borrowApr.mul(hubUtilization).mul(new Dec(1).minus(liquidityFee));
|
|
140
145
|
return ({
|
|
141
146
|
symbol,
|
|
@@ -168,7 +173,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
168
173
|
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
169
174
|
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
170
175
|
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
171
|
-
utilization
|
|
176
|
+
utilization,
|
|
172
177
|
});
|
|
173
178
|
});
|
|
174
179
|
export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "2.1.72-aave-v4-
|
|
3
|
+
"version": "2.1.72-aave-v4-5-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@defisaver/tokens": "
|
|
24
|
+
"@defisaver/tokens": "1.7.26-aave-v4-dev",
|
|
25
25
|
"@types/lodash": "^4.17.15",
|
|
26
26
|
"@types/memoizee": "^0.4.12",
|
|
27
27
|
"decimal.js": "^10.6.0",
|
package/src/aaveV4/index.ts
CHANGED
|
@@ -46,6 +46,7 @@ const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractVi
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
// TODO AaveV4: Will be used for after values, onchain data is available when fetching position data
|
|
49
50
|
const calcUserRiskPremiumBps = (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData): number => {
|
|
50
51
|
type CollateralInfo = { riskBps: number; valueUsd: Dec };
|
|
51
52
|
type DebtInfo = { valueUsd: Dec };
|
|
@@ -134,7 +135,7 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
|
|
|
134
135
|
description: `Native ${symbol} yield.`,
|
|
135
136
|
});
|
|
136
137
|
if (reserveAsset.borrowable) {
|
|
137
|
-
//
|
|
138
|
+
// When borrowing assets whose value increases over time
|
|
138
139
|
borrowIncentives.push({
|
|
139
140
|
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
140
141
|
token: symbol,
|
|
@@ -150,6 +151,9 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
|
|
|
150
151
|
const totalDebtRaw = reserveAsset.totalDebt ?? 0;
|
|
151
152
|
const supplyCapRaw = reserveAsset.supplyCap ?? 0;
|
|
152
153
|
const borrowCapRaw = reserveAsset.borrowCap ?? 0;
|
|
154
|
+
const totalSuppliedDec = new Dec(totalSuppliedRaw.toString());
|
|
155
|
+
const totalDrawnDec = new Dec(totalDrawnRaw.toString());
|
|
156
|
+
const utilization = totalSuppliedDec.isZero() ? '0' : totalDrawnDec.times(100).div(totalSuppliedDec).toString();
|
|
153
157
|
|
|
154
158
|
/** @DEV Hub related calculations */
|
|
155
159
|
const drawnRate = new Dec(hubAsset.drawnRate.toString()).div(new Dec(10).pow(27));
|
|
@@ -157,13 +161,14 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
|
|
|
157
161
|
const totalDrawn = new Dec(hubAsset.totalDrawn.toString());
|
|
158
162
|
const liquidity = new Dec(hubAsset.liquidity.toString());
|
|
159
163
|
const swept = new Dec(hubAsset.swept.toString());
|
|
160
|
-
const
|
|
164
|
+
const hubUtilizationDenominator = totalDrawn.add(swept).add(liquidity);
|
|
165
|
+
const hubUtilization = hubUtilizationDenominator.isZero() ? new Dec(0) : totalDrawn.div(hubUtilizationDenominator);
|
|
161
166
|
const liquidityFee = new Dec(hubAsset.liquidityFee.toString()).div(new Dec(10).pow(4));
|
|
162
167
|
const totalDrawnShares = new Dec(hubAsset.totalDrawnShares.toString());
|
|
163
168
|
const totalPremiumShares = new Dec(hubAsset.totalPremiumShares.toString());
|
|
164
169
|
// TODO JK@JK premiumMultiplier should be added to supplyApr calculation (.mul(premiumMultiplier)
|
|
165
170
|
// TODO JKJ@JK when we confirm that this is the right way to calculate it
|
|
166
|
-
const premiumMultiplier = totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
171
|
+
const premiumMultiplier = totalDrawnShares.isZero() ? new Dec(1) : totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
167
172
|
const supplyApr = borrowApr.mul(hubUtilization).mul(new Dec(1).minus(liquidityFee));
|
|
168
173
|
|
|
169
174
|
return ({
|
|
@@ -197,7 +202,7 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
|
|
|
197
202
|
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
198
203
|
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
199
204
|
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
200
|
-
utilization
|
|
205
|
+
utilization,
|
|
201
206
|
});
|
|
202
207
|
};
|
|
203
208
|
|