@defisaver/positions-sdk 2.1.71 → 2.1.72-aave-v4-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 +7 -0
- package/cjs/aaveV4/index.js +174 -0
- package/cjs/config/contracts.d.ts +1551 -0
- package/cjs/config/contracts.js +9 -0
- package/cjs/contracts.d.ts +32741 -0
- package/cjs/contracts.js +2 -1
- package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/cjs/helpers/aaveV4Helpers/index.js +117 -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/aave/marketAssets.js +1 -1
- package/cjs/markets/aaveV4/index.d.ts +28 -0
- package/cjs/markets/aaveV4/index.js +140 -0
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/portfolio/index.js +20 -0
- package/cjs/staking/eligibility.d.ts +6 -0
- package/cjs/staking/eligibility.js +37 -19
- package/cjs/staking/staking.js +4 -2
- package/cjs/types/aaveV4.d.ts +145 -0
- package/cjs/types/aaveV4.js +19 -0
- package/cjs/types/common.d.ts +2 -1
- package/cjs/types/common.js +1 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/portfolio.d.ts +4 -0
- package/esm/aaveV4/index.d.ts +7 -0
- package/esm/aaveV4/index.js +165 -0
- package/esm/config/contracts.d.ts +1551 -0
- package/esm/config/contracts.js +8 -0
- package/esm/contracts.d.ts +32741 -0
- package/esm/contracts.js +1 -0
- package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/esm/helpers/aaveV4Helpers/index.js +108 -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/aave/marketAssets.js +1 -1
- package/esm/markets/aaveV4/index.d.ts +28 -0
- package/esm/markets/aaveV4/index.js +122 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/portfolio/index.js +21 -1
- package/esm/staking/eligibility.d.ts +6 -0
- package/esm/staking/eligibility.js +35 -18
- package/esm/staking/staking.js +4 -2
- package/esm/types/aaveV4.d.ts +145 -0
- package/esm/types/aaveV4.js +16 -0
- package/esm/types/common.d.ts +2 -1
- package/esm/types/common.js +1 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/portfolio.d.ts +4 -0
- package/package.json +2 -2
- package/src/aaveV4/index.ts +176 -0
- package/src/config/contracts.ts +9 -1
- package/src/contracts.ts +3 -1
- package/src/helpers/aaveV4Helpers/index.ts +128 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/markets/aaveV4/index.ts +149 -0
- package/src/markets/index.ts +6 -1
- package/src/portfolio/index.ts +20 -0
- package/src/staking/eligibility.ts +67 -15
- package/src/staking/staking.ts +3 -2
- package/src/types/aaveV4.ts +161 -0
- package/src/types/common.ts +1 -0
- package/src/types/index.ts +2 -1
- package/src/types/portfolio.ts +4 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo } from '../types';
|
|
3
|
+
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
4
|
+
export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
5
|
+
export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
6
|
+
export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
|
|
7
|
+
export declare function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<any>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports._getAaveV4SpokeData = _getAaveV4SpokeData;
|
|
16
|
+
exports.getAaveV4SpokeData = getAaveV4SpokeData;
|
|
17
|
+
exports._getAaveV4AccountData = _getAaveV4AccountData;
|
|
18
|
+
exports.getAaveV4AccountData = getAaveV4AccountData;
|
|
19
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
20
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
21
|
+
const viem_1 = require("../services/viem");
|
|
22
|
+
const common_1 = require("../types/common");
|
|
23
|
+
const contracts_1 = require("../contracts");
|
|
24
|
+
const staking_1 = require("../staking");
|
|
25
|
+
const utils_1 = require("../services/utils");
|
|
26
|
+
const aaveV4Helpers_1 = require("../helpers/aaveV4Helpers");
|
|
27
|
+
const aaveV4_1 = require("../markets/aaveV4");
|
|
28
|
+
const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
30
|
+
return {
|
|
31
|
+
assets: hubData.reduce((acc, assetOnChainData) => {
|
|
32
|
+
acc[assetOnChainData.assetId] = {
|
|
33
|
+
assetId: assetOnChainData.assetId,
|
|
34
|
+
drawnRate: assetOnChainData.drawnRate,
|
|
35
|
+
};
|
|
36
|
+
return acc;
|
|
37
|
+
}, {}),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(reserveAsset.underlying, network);
|
|
42
|
+
const symbol = (0, utils_1.wethToEth)(assetInfo.symbol);
|
|
43
|
+
const hubInfo = (0, aaveV4_1.getAaveV4HubByAddress)(network, reserveAsset.hub);
|
|
44
|
+
if (!hubInfo) {
|
|
45
|
+
throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
|
|
46
|
+
}
|
|
47
|
+
const isStakingAsset = staking_1.STAKING_ASSETS.includes(symbol);
|
|
48
|
+
const supplyIncentives = [];
|
|
49
|
+
const borrowIncentives = [];
|
|
50
|
+
if (isStakingAsset) {
|
|
51
|
+
const yieldApy = yield (0, staking_1.getStakingApy)(symbol, network);
|
|
52
|
+
supplyIncentives.push({
|
|
53
|
+
apy: yieldApy,
|
|
54
|
+
token: symbol,
|
|
55
|
+
incentiveKind: common_1.IncentiveKind.Staking,
|
|
56
|
+
description: `Native ${symbol} yield.`,
|
|
57
|
+
});
|
|
58
|
+
if (reserveAsset.borrowable) {
|
|
59
|
+
// when borrowing assets whose value increases over time
|
|
60
|
+
borrowIncentives.push({
|
|
61
|
+
apy: new decimal_js_1.default(yieldApy).mul(-1).toString(),
|
|
62
|
+
token: symbol,
|
|
63
|
+
incentiveKind: common_1.IncentiveKind.Reward,
|
|
64
|
+
description: `Due to the native yield of ${symbol}, the value of the debt would increase over time.`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return ({
|
|
69
|
+
symbol,
|
|
70
|
+
underlying: reserveAsset.underlying,
|
|
71
|
+
hub: hubInfo.address,
|
|
72
|
+
hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label,
|
|
73
|
+
assetId: reserveAsset.assetId,
|
|
74
|
+
reserveId,
|
|
75
|
+
paused: reserveAsset.paused,
|
|
76
|
+
frozen: reserveAsset.frozen,
|
|
77
|
+
borrowable: reserveAsset.borrowable,
|
|
78
|
+
collateralRisk: new decimal_js_1.default(reserveAsset.collateralRisk).div(10000).toNumber(),
|
|
79
|
+
collateralFactor: new decimal_js_1.default(reserveAsset.collateralFactor).div(10000).toNumber(),
|
|
80
|
+
liquidationFee: new decimal_js_1.default(reserveAsset.liquidationFee).div(10000).toNumber(),
|
|
81
|
+
price: new decimal_js_1.default(reserveAsset.price).div(new decimal_js_1.default(10).pow(oracleDecimals)).toString(),
|
|
82
|
+
totalSupplied: (0, tokens_1.assetAmountInEth)(reserveAsset.totalSupplied.toString(), symbol),
|
|
83
|
+
totalDrawn: (0, tokens_1.assetAmountInEth)(reserveAsset.totalDrawn.toString(), symbol),
|
|
84
|
+
totalPremium: (0, tokens_1.assetAmountInEth)(reserveAsset.totalPremium.toString(), symbol),
|
|
85
|
+
totalDebt: (0, tokens_1.assetAmountInEth)(reserveAsset.totalDebt.toString(), symbol),
|
|
86
|
+
supplyCap: (0, tokens_1.assetAmountInEth)(reserveAsset.supplyCap.toString(), symbol),
|
|
87
|
+
borrowCap: (0, tokens_1.assetAmountInEth)(reserveAsset.borrowCap.toString(), symbol),
|
|
88
|
+
spokeActive: reserveAsset.spokeActive,
|
|
89
|
+
spokeHalted: reserveAsset.spokeHalted,
|
|
90
|
+
drawnRate: new decimal_js_1.default(hubAsset.drawnRate).div(new decimal_js_1.default(10).pow(27)).toString(),
|
|
91
|
+
supplyRate: '0', // To be implemented
|
|
92
|
+
supplyIncentives,
|
|
93
|
+
borrowIncentives,
|
|
94
|
+
canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
95
|
+
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
|
|
96
|
+
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
97
|
+
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
|
|
98
|
+
utilization: new decimal_js_1.default(reserveAsset.totalDrawn.toString()).times(100).div(new decimal_js_1.default(reserveAsset.totalSupplied.toString())).toString(),
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
102
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
103
|
+
const viewContract = (0, contracts_1.AaveV4ViewContractViem)(provider, network, blockNumber);
|
|
104
|
+
const hubsData = {};
|
|
105
|
+
const [spokeData] = yield Promise.all([
|
|
106
|
+
viewContract.read.getSpokeDataFull([market.address]),
|
|
107
|
+
...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
109
|
+
})),
|
|
110
|
+
]);
|
|
111
|
+
const reserveAssetsArray = yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () { return formatReserveAsset(reserveAssetOnChain, hubsData[reserveAssetOnChain.hub].assets[reserveAssetOnChain.assetId], index, +spokeData[0].oracleDecimals.toString(), network); })));
|
|
112
|
+
return {
|
|
113
|
+
assetsData: reserveAssetsArray.reduce((acc, reserveAsset) => {
|
|
114
|
+
acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
|
|
115
|
+
return acc;
|
|
116
|
+
}, {}),
|
|
117
|
+
oracle: spokeData[0].oracle,
|
|
118
|
+
oracleDecimals: +spokeData[0].oracleDecimals.toString(),
|
|
119
|
+
address: market.address,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function getAaveV4SpokeData(provider_1, network_1, spoke_1) {
|
|
124
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, spoke, blockNumber = 'latest') {
|
|
125
|
+
return _getAaveV4SpokeData((0, viem_1.getViemProvider)(provider, network), network, spoke, blockNumber);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
129
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, spokeData, address, blockNumber = 'latest') {
|
|
130
|
+
const viewContract = (0, contracts_1.AaveV4ViewContractViem)(provider, network, blockNumber);
|
|
131
|
+
const loanData = yield viewContract.read.getLoanData([spokeData.address, address]);
|
|
132
|
+
const healthFactor = new decimal_js_1.default(loanData.healthFactor).div(1e18).toString();
|
|
133
|
+
const usedAssets = loanData.reserves.reduce((acc, usedReserveAsset) => {
|
|
134
|
+
const identifier = `${(0, utils_1.wethToEth)((0, tokens_1.getAssetInfoByAddress)(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
|
|
135
|
+
const reserveData = spokeData.assetsData[identifier];
|
|
136
|
+
const price = reserveData.price;
|
|
137
|
+
const supplied = (0, tokens_1.assetAmountInEth)(usedReserveAsset.supplied.toString(), reserveData.symbol);
|
|
138
|
+
const drawn = (0, tokens_1.assetAmountInEth)(usedReserveAsset.drawn.toString(), reserveData.symbol);
|
|
139
|
+
const premium = (0, tokens_1.assetAmountInEth)(usedReserveAsset.premium.toString(), reserveData.symbol);
|
|
140
|
+
const borrowed = (0, tokens_1.assetAmountInEth)(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
|
|
141
|
+
acc[identifier] = {
|
|
142
|
+
symbol: reserveData.symbol,
|
|
143
|
+
hubName: reserveData.hubName,
|
|
144
|
+
assetId: reserveData.assetId,
|
|
145
|
+
reserveId: +usedReserveAsset.reserveId.toString(),
|
|
146
|
+
supplied,
|
|
147
|
+
suppliedUsd: new decimal_js_1.default(supplied).mul(price).toString(),
|
|
148
|
+
drawn,
|
|
149
|
+
drawnUsd: new decimal_js_1.default(drawn).mul(price).toString(),
|
|
150
|
+
premium,
|
|
151
|
+
premiumUsd: new decimal_js_1.default(premium).mul(price).toString(),
|
|
152
|
+
borrowed,
|
|
153
|
+
borrowedUsd: new decimal_js_1.default(borrowed).mul(price).toString(),
|
|
154
|
+
isSupplied: !new decimal_js_1.default(supplied).eq(0),
|
|
155
|
+
isBorrowed: usedReserveAsset.isBorrowing,
|
|
156
|
+
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
157
|
+
collateralFactor: new decimal_js_1.default(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
158
|
+
};
|
|
159
|
+
return acc;
|
|
160
|
+
}, {});
|
|
161
|
+
return Object.assign({ usedAssets,
|
|
162
|
+
healthFactor }, (0, aaveV4Helpers_1.aaveV4GetAggregatedPositionData)({
|
|
163
|
+
usedAssets,
|
|
164
|
+
assetsData: spokeData.assetsData,
|
|
165
|
+
network,
|
|
166
|
+
useUserCollateralFactor: true,
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function getAaveV4AccountData(provider_1, network_1, marketData_1, address_1) {
|
|
171
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, marketData, address, blockNumber = 'latest') {
|
|
172
|
+
return _getAaveV4AccountData((0, viem_1.getViemProvider)(provider, network), network, marketData, address, blockNumber);
|
|
173
|
+
});
|
|
174
|
+
}
|