@defisaver/positions-sdk 2.1.72-aave-v4-dev → 2.1.72-aave-v4-3-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.d.ts +2 -2
- package/cjs/aaveV4/index.js +133 -14
- package/cjs/aaveV4/lend.d.ts +45 -0
- package/cjs/aaveV4/lend.js +141 -0
- package/cjs/helpers/aaveV4Helpers/index.d.ts +1 -2
- package/cjs/helpers/aaveV4Helpers/index.js +7 -7
- package/cjs/types/aaveV4.d.ts +8 -0
- package/esm/aaveV4/index.d.ts +2 -2
- package/esm/aaveV4/index.js +97 -12
- package/esm/aaveV4/lend.d.ts +45 -0
- package/esm/aaveV4/lend.js +134 -0
- package/esm/helpers/aaveV4Helpers/index.d.ts +1 -2
- package/esm/helpers/aaveV4Helpers/index.js +1 -1
- package/esm/types/aaveV4.d.ts +8 -0
- package/package.json +1 -1
- package/src/aaveV4/index.ts +128 -18
- package/src/aaveV4/lend.ts +180 -0
- package/src/helpers/aaveV4Helpers/index.ts +7 -2
- package/src/types/aaveV4.ts +8 -0
package/cjs/aaveV4/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo } from '../types';
|
|
3
|
-
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
|
|
3
|
+
export * as lend from './lend';
|
|
4
4
|
export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
5
5
|
export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
6
6
|
export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
|
package/cjs/aaveV4/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,6 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
46
|
};
|
|
14
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.lend = void 0;
|
|
15
49
|
exports._getAaveV4SpokeData = _getAaveV4SpokeData;
|
|
16
50
|
exports.getAaveV4SpokeData = getAaveV4SpokeData;
|
|
17
51
|
exports._getAaveV4AccountData = _getAaveV4AccountData;
|
|
@@ -19,12 +53,14 @@ exports.getAaveV4AccountData = getAaveV4AccountData;
|
|
|
19
53
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
20
54
|
const tokens_1 = require("@defisaver/tokens");
|
|
21
55
|
const viem_1 = require("../services/viem");
|
|
22
|
-
const
|
|
56
|
+
const types_1 = require("../types");
|
|
23
57
|
const contracts_1 = require("../contracts");
|
|
24
58
|
const staking_1 = require("../staking");
|
|
25
59
|
const utils_1 = require("../services/utils");
|
|
26
60
|
const aaveV4Helpers_1 = require("../helpers/aaveV4Helpers");
|
|
27
61
|
const aaveV4_1 = require("../markets/aaveV4");
|
|
62
|
+
const moneymarket_1 = require("../moneymarket");
|
|
63
|
+
exports.lend = __importStar(require("./lend"));
|
|
28
64
|
const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
65
|
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
30
66
|
return {
|
|
@@ -32,12 +68,71 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
|
|
|
32
68
|
acc[assetOnChainData.assetId] = {
|
|
33
69
|
assetId: assetOnChainData.assetId,
|
|
34
70
|
drawnRate: assetOnChainData.drawnRate,
|
|
71
|
+
liquidity: assetOnChainData.liquidity,
|
|
72
|
+
liquidityFee: assetOnChainData.liquidityFee,
|
|
73
|
+
swept: assetOnChainData.swept,
|
|
74
|
+
totalDrawn: assetOnChainData.totalDrawn,
|
|
75
|
+
totalDrawnShares: assetOnChainData.totalDrawnShares,
|
|
76
|
+
totalPremiumShares: assetOnChainData.totalPremiumShares,
|
|
35
77
|
};
|
|
36
78
|
return acc;
|
|
37
79
|
}, {}),
|
|
38
80
|
};
|
|
39
81
|
});
|
|
82
|
+
const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
|
|
83
|
+
const collaterals = [];
|
|
84
|
+
const debts = [];
|
|
85
|
+
Object.entries(usedAssets).forEach(([identifier, asset]) => {
|
|
86
|
+
const reserveData = assetsData[identifier];
|
|
87
|
+
if (!reserveData)
|
|
88
|
+
return;
|
|
89
|
+
const borrowedUsdDec = new decimal_js_1.default(asset.borrowedUsd || '0');
|
|
90
|
+
if (asset.isBorrowed && borrowedUsdDec.gt(0)) {
|
|
91
|
+
debts.push({ valueUsd: borrowedUsdDec });
|
|
92
|
+
}
|
|
93
|
+
const suppliedUsdDec = new decimal_js_1.default(asset.suppliedUsd || '0');
|
|
94
|
+
const isActiveCollateral = asset.collateral
|
|
95
|
+
&& asset.isSupplied
|
|
96
|
+
&& asset.collateralFactor > 0
|
|
97
|
+
&& suppliedUsdDec.gt(0);
|
|
98
|
+
if (isActiveCollateral) {
|
|
99
|
+
// collateralRisk is stored as a fraction (e.g. 0.25), convert back to bps
|
|
100
|
+
const riskBps = new decimal_js_1.default(reserveData.collateralRisk).mul(10000).toNumber();
|
|
101
|
+
collaterals.push({
|
|
102
|
+
riskBps,
|
|
103
|
+
valueUsd: suppliedUsdDec,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const totalDebtUsd = debts.reduce((sum, d) => sum.add(d.valueUsd), new decimal_js_1.default(0));
|
|
108
|
+
if (totalDebtUsd.lte(0)) {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
// sort by risk ASC, value DESC
|
|
112
|
+
collaterals.sort((a, b) => {
|
|
113
|
+
if (a.riskBps !== b.riskBps)
|
|
114
|
+
return a.riskBps - b.riskBps;
|
|
115
|
+
return b.valueUsd.comparedTo(a.valueUsd);
|
|
116
|
+
});
|
|
117
|
+
let debtLeftToCover = totalDebtUsd;
|
|
118
|
+
let numerator = new decimal_js_1.default(0); // sum(coveredUsd * riskBps)
|
|
119
|
+
let coveredDebt = new decimal_js_1.default(0); // sum(coveredUsd)
|
|
120
|
+
collaterals.forEach(({ riskBps, valueUsd }) => {
|
|
121
|
+
if (debtLeftToCover.lte(0))
|
|
122
|
+
return;
|
|
123
|
+
const coveredUsd = decimal_js_1.default.min(valueUsd, debtLeftToCover);
|
|
124
|
+
numerator = numerator.add(coveredUsd.mul(riskBps));
|
|
125
|
+
coveredDebt = coveredDebt.add(coveredUsd);
|
|
126
|
+
debtLeftToCover = debtLeftToCover.sub(coveredUsd);
|
|
127
|
+
});
|
|
128
|
+
if (coveredDebt.lte(0)) {
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
const riskPremiumBps = numerator.div(coveredDebt);
|
|
132
|
+
return riskPremiumBps.toNumber();
|
|
133
|
+
};
|
|
40
134
|
const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
var _a, _b, _c, _d, _e, _f;
|
|
41
136
|
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(reserveAsset.underlying, network);
|
|
42
137
|
const symbol = (0, utils_1.wethToEth)(assetInfo.symbol);
|
|
43
138
|
const hubInfo = (0, aaveV4_1.getAaveV4HubByAddress)(network, reserveAsset.hub);
|
|
@@ -52,7 +147,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
52
147
|
supplyIncentives.push({
|
|
53
148
|
apy: yieldApy,
|
|
54
149
|
token: symbol,
|
|
55
|
-
incentiveKind:
|
|
150
|
+
incentiveKind: types_1.IncentiveKind.Staking,
|
|
56
151
|
description: `Native ${symbol} yield.`,
|
|
57
152
|
});
|
|
58
153
|
if (reserveAsset.borrowable) {
|
|
@@ -60,11 +155,31 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
60
155
|
borrowIncentives.push({
|
|
61
156
|
apy: new decimal_js_1.default(yieldApy).mul(-1).toString(),
|
|
62
157
|
token: symbol,
|
|
63
|
-
incentiveKind:
|
|
158
|
+
incentiveKind: types_1.IncentiveKind.Reward,
|
|
64
159
|
description: `Due to the native yield of ${symbol}, the value of the debt would increase over time.`,
|
|
65
160
|
});
|
|
66
161
|
}
|
|
67
162
|
}
|
|
163
|
+
const totalSuppliedRaw = (_a = reserveAsset.totalSupplied) !== null && _a !== void 0 ? _a : 0;
|
|
164
|
+
const totalDrawnRaw = (_b = reserveAsset.totalDrawn) !== null && _b !== void 0 ? _b : 0;
|
|
165
|
+
const totalPremiumRaw = (_c = reserveAsset.totalPremium) !== null && _c !== void 0 ? _c : 0;
|
|
166
|
+
const totalDebtRaw = (_d = reserveAsset.totalDebt) !== null && _d !== void 0 ? _d : 0;
|
|
167
|
+
const supplyCapRaw = (_e = reserveAsset.supplyCap) !== null && _e !== void 0 ? _e : 0;
|
|
168
|
+
const borrowCapRaw = (_f = reserveAsset.borrowCap) !== null && _f !== void 0 ? _f : 0;
|
|
169
|
+
/** @DEV Hub related calculations */
|
|
170
|
+
const drawnRate = new decimal_js_1.default(hubAsset.drawnRate.toString()).div(new decimal_js_1.default(10).pow(27));
|
|
171
|
+
const borrowApr = drawnRate.mul(100);
|
|
172
|
+
const totalDrawn = new decimal_js_1.default(hubAsset.totalDrawn.toString());
|
|
173
|
+
const liquidity = new decimal_js_1.default(hubAsset.liquidity.toString());
|
|
174
|
+
const swept = new decimal_js_1.default(hubAsset.swept.toString());
|
|
175
|
+
const hubUtilization = totalDrawn.div(totalDrawn.add(swept).add(liquidity));
|
|
176
|
+
const liquidityFee = new decimal_js_1.default(hubAsset.liquidityFee.toString()).div(new decimal_js_1.default(10).pow(4));
|
|
177
|
+
const totalDrawnShares = new decimal_js_1.default(hubAsset.totalDrawnShares.toString());
|
|
178
|
+
const totalPremiumShares = new decimal_js_1.default(hubAsset.totalPremiumShares.toString());
|
|
179
|
+
// TODO JK@JK premiumMultiplier should be added to supplyApr calculation (.mul(premiumMultiplier)
|
|
180
|
+
// TODO JKJ@JK when we confirm that this is the right way to calculate it
|
|
181
|
+
const premiumMultiplier = totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
|
|
182
|
+
const supplyApr = borrowApr.mul(hubUtilization).mul(new decimal_js_1.default(1).minus(liquidityFee));
|
|
68
183
|
return ({
|
|
69
184
|
symbol,
|
|
70
185
|
underlying: reserveAsset.underlying,
|
|
@@ -79,16 +194,17 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
79
194
|
collateralFactor: new decimal_js_1.default(reserveAsset.collateralFactor).div(10000).toNumber(),
|
|
80
195
|
liquidationFee: new decimal_js_1.default(reserveAsset.liquidationFee).div(10000).toNumber(),
|
|
81
196
|
price: new decimal_js_1.default(reserveAsset.price).div(new decimal_js_1.default(10).pow(oracleDecimals)).toString(),
|
|
82
|
-
totalSupplied: (0, tokens_1.assetAmountInEth)(
|
|
83
|
-
totalDrawn: (0, tokens_1.assetAmountInEth)(
|
|
84
|
-
totalPremium: (0, tokens_1.assetAmountInEth)(
|
|
85
|
-
totalDebt: (0, tokens_1.assetAmountInEth)(
|
|
86
|
-
supplyCap: (0, tokens_1.assetAmountInEth)(
|
|
87
|
-
borrowCap: (0, tokens_1.assetAmountInEth)(
|
|
197
|
+
totalSupplied: (0, tokens_1.assetAmountInEth)(totalSuppliedRaw.toString(), symbol),
|
|
198
|
+
totalDrawn: (0, tokens_1.assetAmountInEth)(totalDrawnRaw.toString(), symbol),
|
|
199
|
+
totalPremium: (0, tokens_1.assetAmountInEth)(totalPremiumRaw.toString(), symbol),
|
|
200
|
+
totalDebt: (0, tokens_1.assetAmountInEth)(totalDebtRaw.toString(), symbol),
|
|
201
|
+
supplyCap: (0, tokens_1.assetAmountInEth)(supplyCapRaw.toString(), symbol),
|
|
202
|
+
borrowCap: (0, tokens_1.assetAmountInEth)(borrowCapRaw.toString(), symbol),
|
|
88
203
|
spokeActive: reserveAsset.spokeActive,
|
|
89
204
|
spokeHalted: reserveAsset.spokeHalted,
|
|
90
|
-
drawnRate:
|
|
91
|
-
|
|
205
|
+
drawnRate: drawnRate.toString(),
|
|
206
|
+
borrowRate: (0, moneymarket_1.aprToApy)(borrowApr.toString()),
|
|
207
|
+
supplyRate: (0, moneymarket_1.aprToApy)(supplyApr.toString()),
|
|
92
208
|
supplyIncentives,
|
|
93
209
|
borrowIncentives,
|
|
94
210
|
canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
@@ -158,13 +274,16 @@ function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
|
158
274
|
};
|
|
159
275
|
return acc;
|
|
160
276
|
}, {});
|
|
161
|
-
|
|
162
|
-
healthFactor }, (0, aaveV4Helpers_1.aaveV4GetAggregatedPositionData)({
|
|
277
|
+
const aggregated = (0, aaveV4Helpers_1.aaveV4GetAggregatedPositionData)({
|
|
163
278
|
usedAssets,
|
|
164
279
|
assetsData: spokeData.assetsData,
|
|
165
280
|
network,
|
|
166
281
|
useUserCollateralFactor: true,
|
|
167
|
-
})
|
|
282
|
+
});
|
|
283
|
+
const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, spokeData.assetsData);
|
|
284
|
+
return Object.assign(Object.assign({}, aggregated), { usedAssets,
|
|
285
|
+
healthFactor,
|
|
286
|
+
riskPremiumBps });
|
|
168
287
|
});
|
|
169
288
|
}
|
|
170
289
|
function getAaveV4AccountData(provider_1, network_1, marketData_1, address_1) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
+
export interface AaveV4TokenizationSpokeData {
|
|
3
|
+
underlyingAsset: EthAddress;
|
|
4
|
+
assetId: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
spoke: EthAddress;
|
|
7
|
+
spokeActive: boolean;
|
|
8
|
+
spokeHalted: boolean;
|
|
9
|
+
spokeDepositCap: string;
|
|
10
|
+
spokeTotalAssets: string;
|
|
11
|
+
spokeTotalShares: string;
|
|
12
|
+
hub: EthAddress;
|
|
13
|
+
hubLiquidity: string;
|
|
14
|
+
hubDrawnRate: string;
|
|
15
|
+
convertToShares: string;
|
|
16
|
+
convertToAssets: string;
|
|
17
|
+
user: EthAddress;
|
|
18
|
+
userSuppliedAssets: string;
|
|
19
|
+
userSuppliedShares: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const AAVE_V4_TOKENIZED_SPOKES: Record<string, EthAddress>;
|
|
22
|
+
export declare const AAVE_V4_TOKENIZED_SPOKE_ADDRESSES: Partial<Record<NetworkNumber, EthAddress[]>>;
|
|
23
|
+
export type AaveV4TokenizedHubKey = 'CORE' | 'PLUS' | 'PRIME';
|
|
24
|
+
export declare const aaveV4GetTokenizedHubKey: (hubNameOrKey?: string | null) => AaveV4TokenizedHubKey | null;
|
|
25
|
+
export declare const aaveV4GetTokenizedVaultKey: (symbol: string, hubNameOrKey?: string | null) => string | null;
|
|
26
|
+
export declare const aaveV4GetTokenizedVaultAddress: (network: NetworkNumber, symbol: string, hubNameOrKey?: string | null) => EthAddress | undefined;
|
|
27
|
+
/** Parsed tokenization spoke data with human-readable supplied amounts for display */
|
|
28
|
+
export interface AaveV4TokenizationSpokeDataParsed {
|
|
29
|
+
vaultAddress: EthAddress;
|
|
30
|
+
key: string | null;
|
|
31
|
+
symbol: string;
|
|
32
|
+
hubKey: string;
|
|
33
|
+
userSuppliedAssetsEth: string;
|
|
34
|
+
userSuppliedSharesEth: string;
|
|
35
|
+
userSuppliedAssets: string;
|
|
36
|
+
userSuppliedShares: string;
|
|
37
|
+
underlyingAsset: EthAddress;
|
|
38
|
+
spoke: EthAddress;
|
|
39
|
+
decimals: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetches tokenization vault data for the given user via getTokenizationSpokesData.
|
|
43
|
+
* Returns parsed data including userSuppliedAssets in human-readable form for each vault.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getAaveV4TokenizationSpokesData(provider: EthereumProvider, network: NetworkNumber, userAddress: EthAddress): Promise<AaveV4TokenizationSpokeDataParsed[]>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.aaveV4GetTokenizedVaultAddress = exports.aaveV4GetTokenizedVaultKey = exports.aaveV4GetTokenizedHubKey = exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = exports.AAVE_V4_TOKENIZED_SPOKES = void 0;
|
|
13
|
+
exports.getAaveV4TokenizationSpokesData = getAaveV4TokenizationSpokesData;
|
|
14
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
15
|
+
const contracts_1 = require("../contracts");
|
|
16
|
+
const viem_1 = require("../services/viem");
|
|
17
|
+
const utils_1 = require("../services/utils");
|
|
18
|
+
const common_1 = require("../types/common");
|
|
19
|
+
exports.AAVE_V4_TOKENIZED_SPOKES = {
|
|
20
|
+
AAVE_CORE: '0x08309234884cF7E015b07Bf22569017Aa035cdeF',
|
|
21
|
+
EURC_CORE: '0x73596dED4B2Eb0aC85e477b3c8dB56FC427E6774',
|
|
22
|
+
GHO_CORE: '0xf7E1f1b43922527e5054bD77E7f863Cf182b194D',
|
|
23
|
+
GHO_PRIME: '0xeF1cAd5c6a2C9cb83c952b4B96bbD35b3F61F18f',
|
|
24
|
+
LBTC_CORE: '0x8f4D423590F22833131e3493bf67A27213398f8e',
|
|
25
|
+
LINK_CORE: '0xBE1197750b423e30137E97d9183065d33E903BE6',
|
|
26
|
+
PT_USDe_PLUS: '0x8cA27Ab284F2aA2BcF33D9129e11c101aD2d16de',
|
|
27
|
+
PT_sUSDe_PLUS: '0xb8A464EC56071a98c854f30fE19CfeCc41FA6233',
|
|
28
|
+
PYUSD_CORE: '0x203FB463087005698d50768FcA837047f738632d',
|
|
29
|
+
RLUSD_CORE: '0xa9afdd0c54fb153CaE39cE86E49626B5e9d15513',
|
|
30
|
+
USDC_CORE: '0xa2e476f4cbB06C7bFA8Ad51bCcbF198cd32CfD35',
|
|
31
|
+
USDC_PLUS: '0x320Bec4fB7a25e64c003A007D0AeF7AB3D6C30d7',
|
|
32
|
+
USDC_PRIME: '0x0A0507F7A1129892b5cf74b8B4e911442c466b87',
|
|
33
|
+
USDG_CORE: '0x87c224256f09a014C1BC3e9FbB094C3AdD8fBaCC',
|
|
34
|
+
USDT_CORE: '0x3f12BD5999b9172550893FF52691c980676f9E73',
|
|
35
|
+
USDT_PLUS: '0xa4E74a78bED2d3ab8971e8AB26fb39f26DD8eEd9',
|
|
36
|
+
USDT_PRIME: '0xF565fB55bc96d65561887898bfeb25C1dE7e06d2',
|
|
37
|
+
USDe_PLUS: '0xA0d346ab2699B689AC67aba5174164A84206BB73',
|
|
38
|
+
WBTC_CORE: '0x837Ab872A665e0CF467d41cF56a054031b4A38bc',
|
|
39
|
+
WBTC_PRIME: '0xeae98b8a1798738182B2123DF1eB93d97BD29F34',
|
|
40
|
+
WETH_CORE: '0x3961a75099E986F59a1a31c6f945061641dFD2b2',
|
|
41
|
+
WETH_PRIME: '0xa411826a6ef5d289c0FAa7d5B45FE8aAB52257F6',
|
|
42
|
+
XAUt_CORE: '0x470341bC0e2B833C54D0120642713BdF762A494F',
|
|
43
|
+
cbBTC_CORE: '0xe8D5E595d5b6b5EFf84B7064765fd0e8DfD214C9',
|
|
44
|
+
cbBTC_PRIME: '0x0E986545150DcDDe46Ea9df355D0fD2af33bd75D',
|
|
45
|
+
frxUSD_CORE: '0x00C8A6a42947Cc4E7B6f27963Cab0143ccaaD2B5',
|
|
46
|
+
frxUSD_PLUS: '0xCAB288d37CAb5a9db7b503F086455276Dcde61F1',
|
|
47
|
+
rsETH_CORE: '0x6eEce89caE2163584bA7Ff9743861B9633c245E0',
|
|
48
|
+
sUSDe_PLUS: '0xdf47fc43c88B06edC47753b7d647ff18037D2F3d',
|
|
49
|
+
weETH_CORE: '0xB67F20bFF413C8E5d633B54BD28899c4c9e33ed0',
|
|
50
|
+
wstETH_CORE: '0x474602394d0B02F43AC3D7C8c5cFc0814b03fd40',
|
|
51
|
+
wstETH_PRIME: '0xAcCdAb49ECB9A801CfF62a92fc80D52339b33770',
|
|
52
|
+
};
|
|
53
|
+
exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = {
|
|
54
|
+
[common_1.NetworkNumber.Eth]: Object.values(exports.AAVE_V4_TOKENIZED_SPOKES),
|
|
55
|
+
};
|
|
56
|
+
const aaveV4GetTokenizedHubKey = (hubNameOrKey) => {
|
|
57
|
+
if (!hubNameOrKey)
|
|
58
|
+
return null;
|
|
59
|
+
const normalized = hubNameOrKey.trim().toUpperCase();
|
|
60
|
+
// TODO AaveV4 Maybe turn into constants
|
|
61
|
+
if (normalized === 'CORE' || normalized === 'CORE HUB')
|
|
62
|
+
return 'CORE';
|
|
63
|
+
if (normalized === 'PLUS' || normalized === 'PLUS HUB')
|
|
64
|
+
return 'PLUS';
|
|
65
|
+
if (normalized === 'PRIME' || normalized === 'PRIME HUB')
|
|
66
|
+
return 'PRIME';
|
|
67
|
+
if (normalized.includes('CORE'))
|
|
68
|
+
return 'CORE';
|
|
69
|
+
if (normalized.includes('PLUS'))
|
|
70
|
+
return 'PLUS';
|
|
71
|
+
if (normalized.includes('PRIME'))
|
|
72
|
+
return 'PRIME';
|
|
73
|
+
return null;
|
|
74
|
+
};
|
|
75
|
+
exports.aaveV4GetTokenizedHubKey = aaveV4GetTokenizedHubKey;
|
|
76
|
+
const aaveV4GetTokenizedVaultKey = (symbol, hubNameOrKey) => {
|
|
77
|
+
if (!symbol)
|
|
78
|
+
return null;
|
|
79
|
+
const hubKey = (0, exports.aaveV4GetTokenizedHubKey)(hubNameOrKey);
|
|
80
|
+
if (!hubKey)
|
|
81
|
+
return null;
|
|
82
|
+
const normalizedSymbol = symbol.trim().replace(/-/g, '_');
|
|
83
|
+
return `${normalizedSymbol}_${hubKey}`;
|
|
84
|
+
};
|
|
85
|
+
exports.aaveV4GetTokenizedVaultKey = aaveV4GetTokenizedVaultKey;
|
|
86
|
+
const aaveV4GetTokenizedVaultAddress = (network, symbol, hubNameOrKey) => {
|
|
87
|
+
if (network !== common_1.NetworkNumber.Eth)
|
|
88
|
+
return undefined;
|
|
89
|
+
const key = (0, exports.aaveV4GetTokenizedVaultKey)(symbol, hubNameOrKey);
|
|
90
|
+
if (!key)
|
|
91
|
+
return undefined;
|
|
92
|
+
return exports.AAVE_V4_TOKENIZED_SPOKES[key];
|
|
93
|
+
};
|
|
94
|
+
exports.aaveV4GetTokenizedVaultAddress = aaveV4GetTokenizedVaultAddress;
|
|
95
|
+
const AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY = Object.entries(exports.AAVE_V4_TOKENIZED_SPOKES).reduce((acc, [k, v]) => {
|
|
96
|
+
acc[v.toLowerCase()] = k;
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
/**
|
|
100
|
+
* Fetches tokenization vault data for the given user via getTokenizationSpokesData.
|
|
101
|
+
* Returns parsed data including userSuppliedAssets in human-readable form for each vault.
|
|
102
|
+
*/
|
|
103
|
+
function getAaveV4TokenizationSpokesData(provider, network, userAddress) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
var _a;
|
|
106
|
+
const spokes = (_a = exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES[network]) !== null && _a !== void 0 ? _a : [];
|
|
107
|
+
if (spokes.length === 0)
|
|
108
|
+
return [];
|
|
109
|
+
const client = (0, viem_1.getViemProvider)(provider, network);
|
|
110
|
+
const viewContract = (0, contracts_1.AaveV4ViewContractViem)(client, network);
|
|
111
|
+
const raw = yield viewContract.read.getTokenizationSpokesData([spokes, userAddress]);
|
|
112
|
+
return raw.map((r, i) => {
|
|
113
|
+
var _a, _b, _c, _d, _e;
|
|
114
|
+
const vaultAddress = spokes[i];
|
|
115
|
+
const key = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY[vaultAddress.toLowerCase()]) !== null && _a !== void 0 ? _a : null;
|
|
116
|
+
const symbol = (0, utils_1.wethToEth)((0, tokens_1.getAssetInfoByAddress)(r.underlyingAsset, network).symbol);
|
|
117
|
+
if (symbol === '?') { // unsupported asset
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const hubKey = key ? (_b = key.split('_').pop()) !== null && _b !== void 0 ? _b : '' : '';
|
|
121
|
+
const decimals = Number((_c = r.decimals) !== null && _c !== void 0 ? _c : 18);
|
|
122
|
+
const userSuppliedAssetsRaw = (_d = r.userSuppliedAssets) !== null && _d !== void 0 ? _d : 0;
|
|
123
|
+
const userSuppliedSharesRaw = (_e = r.userSuppliedShares) !== null && _e !== void 0 ? _e : 0;
|
|
124
|
+
const userSuppliedAssetsEth = (0, tokens_1.assetAmountInEth)(userSuppliedAssetsRaw.toString(), symbol);
|
|
125
|
+
const userSuppliedSharesEth = (0, tokens_1.assetAmountInEth)(userSuppliedSharesRaw.toString(), symbol);
|
|
126
|
+
return {
|
|
127
|
+
vaultAddress,
|
|
128
|
+
key,
|
|
129
|
+
symbol,
|
|
130
|
+
hubKey,
|
|
131
|
+
userSuppliedAssetsEth,
|
|
132
|
+
userSuppliedSharesEth,
|
|
133
|
+
userSuppliedAssets: userSuppliedAssetsRaw.toString(),
|
|
134
|
+
userSuppliedShares: userSuppliedSharesRaw.toString(),
|
|
135
|
+
underlyingAsset: r.underlyingAsset,
|
|
136
|
+
spoke: r.spoke,
|
|
137
|
+
decimals,
|
|
138
|
+
};
|
|
139
|
+
}).filter(item => item != null);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
|
|
2
|
-
import { LeverageType, NetworkNumber } from '../../types/common';
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, LeverageType, NetworkNumber } from '../../types';
|
|
3
2
|
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
4
3
|
export declare const isLeveragedPosAaveV4: (usedAssets: AaveV4UsedReserveAssets, dustLimit?: number) => {
|
|
5
4
|
leveragedType: LeverageType;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.aaveV4GetAggregatedPositionData = exports.isLeveragedPosAaveV4 = exports.aaveV4GetCollateralFactor = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const moneymarket_1 = require("../../moneymarket");
|
|
9
|
-
const
|
|
9
|
+
const types_1 = require("../../types");
|
|
10
10
|
const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
11
11
|
exports.aaveV4GetCollateralFactor = aaveV4GetCollateralFactor;
|
|
12
12
|
const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
@@ -38,24 +38,24 @@ const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
|
38
38
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
39
39
|
if (isLong) {
|
|
40
40
|
return {
|
|
41
|
-
leveragedType:
|
|
41
|
+
leveragedType: types_1.LeverageType.Long,
|
|
42
42
|
leveragedAsset: longAsset,
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
if (isShort) {
|
|
46
46
|
return {
|
|
47
|
-
leveragedType:
|
|
47
|
+
leveragedType: types_1.LeverageType.Short,
|
|
48
48
|
leveragedAsset: shortAsset,
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
if (isVolatilePair) {
|
|
52
52
|
return {
|
|
53
|
-
leveragedType:
|
|
53
|
+
leveragedType: types_1.LeverageType.VolatilePair,
|
|
54
54
|
leveragedAsset: longAsset,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
return {
|
|
58
|
-
leveragedType:
|
|
58
|
+
leveragedType: types_1.LeverageType.None,
|
|
59
59
|
leveragedAsset: '',
|
|
60
60
|
};
|
|
61
61
|
};
|
|
@@ -82,13 +82,13 @@ const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useU
|
|
|
82
82
|
if (leveragedType !== '') {
|
|
83
83
|
const leveragedAssetData = assetsData[leveragedAsset];
|
|
84
84
|
let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
|
|
85
|
-
if (leveragedType ===
|
|
85
|
+
if (leveragedType === types_1.LeverageType.VolatilePair) {
|
|
86
86
|
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
87
87
|
const borrowedAssetPrice = assetsData[`${borrowedAsset.symbol}-${borrowedAsset.reserveId}`].price;
|
|
88
88
|
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
89
89
|
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
90
90
|
if (isReverse) {
|
|
91
|
-
payload.leveragedType =
|
|
91
|
+
payload.leveragedType = types_1.LeverageType.VolatilePairReverse;
|
|
92
92
|
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
93
93
|
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
94
94
|
}
|
package/cjs/types/aaveV4.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface AaveV4HubInfo {
|
|
|
22
22
|
export interface AaveV4HubAssetOnChainData {
|
|
23
23
|
assetId: number;
|
|
24
24
|
drawnRate: bigint;
|
|
25
|
+
liquidity: bigint;
|
|
26
|
+
liquidityFee: number;
|
|
27
|
+
swept: bigint;
|
|
28
|
+
totalDrawn: bigint;
|
|
29
|
+
totalDrawnShares: bigint;
|
|
30
|
+
totalPremiumShares: bigint;
|
|
25
31
|
}
|
|
26
32
|
export interface AaveV4HubOnChainData {
|
|
27
33
|
assets: Record<number, AaveV4HubAssetOnChainData>;
|
|
@@ -87,6 +93,7 @@ export interface AaveV4ReserveAssetData {
|
|
|
87
93
|
spokeHalted: boolean;
|
|
88
94
|
drawnRate: string;
|
|
89
95
|
supplyRate: string;
|
|
96
|
+
borrowRate: string;
|
|
90
97
|
supplyIncentives: IncentiveData[];
|
|
91
98
|
borrowIncentives: IncentiveData[];
|
|
92
99
|
canBeBorrowed: boolean;
|
|
@@ -142,4 +149,5 @@ export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
|
|
|
142
149
|
export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
|
|
143
150
|
usedAssets: AaveV4UsedReserveAssets;
|
|
144
151
|
healthFactor: string;
|
|
152
|
+
riskPremiumBps: number;
|
|
145
153
|
}
|
package/esm/aaveV4/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo } from '../types';
|
|
3
|
-
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
|
|
3
|
+
export * as lend from './lend';
|
|
4
4
|
export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
5
5
|
export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
6
6
|
export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
|