@defisaver/positions-sdk 2.1.78-aave-v4-dev → 2.1.79

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.
Files changed (65) hide show
  1. package/cjs/claiming/spark.js +1 -1
  2. package/cjs/config/contracts.d.ts +0 -1551
  3. package/cjs/config/contracts.js +0 -9
  4. package/cjs/contracts.d.ts +0 -32741
  5. package/cjs/contracts.js +1 -2
  6. package/cjs/helpers/index.d.ts +0 -1
  7. package/cjs/helpers/index.js +1 -2
  8. package/cjs/index.d.ts +1 -2
  9. package/cjs/index.js +1 -3
  10. package/cjs/markets/index.d.ts +0 -1
  11. package/cjs/markets/index.js +1 -3
  12. package/cjs/portfolio/index.js +0 -20
  13. package/cjs/types/index.d.ts +0 -1
  14. package/cjs/types/index.js +0 -1
  15. package/cjs/types/portfolio.d.ts +0 -4
  16. package/esm/claiming/spark.js +1 -1
  17. package/esm/config/contracts.d.ts +0 -1551
  18. package/esm/config/contracts.js +0 -8
  19. package/esm/contracts.d.ts +0 -32741
  20. package/esm/contracts.js +0 -1
  21. package/esm/helpers/index.d.ts +0 -1
  22. package/esm/helpers/index.js +0 -1
  23. package/esm/index.d.ts +1 -2
  24. package/esm/index.js +1 -2
  25. package/esm/markets/index.d.ts +0 -1
  26. package/esm/markets/index.js +0 -1
  27. package/esm/portfolio/index.js +1 -21
  28. package/esm/types/index.d.ts +0 -1
  29. package/esm/types/index.js +0 -1
  30. package/esm/types/portfolio.d.ts +0 -4
  31. package/package.json +2 -2
  32. package/src/claiming/spark.ts +1 -1
  33. package/src/config/contracts.ts +0 -8
  34. package/src/contracts.ts +0 -2
  35. package/src/helpers/index.ts +0 -1
  36. package/src/index.ts +0 -2
  37. package/src/markets/index.ts +1 -6
  38. package/src/portfolio/index.ts +0 -20
  39. package/src/types/index.ts +1 -2
  40. package/src/types/portfolio.ts +0 -4
  41. package/cjs/aaveV4/index.d.ts +0 -7
  42. package/cjs/aaveV4/index.js +0 -298
  43. package/cjs/aaveV4/lend.d.ts +0 -45
  44. package/cjs/aaveV4/lend.js +0 -141
  45. package/cjs/helpers/aaveV4Helpers/index.d.ts +0 -12
  46. package/cjs/helpers/aaveV4Helpers/index.js +0 -117
  47. package/cjs/markets/aaveV4/index.d.ts +0 -28
  48. package/cjs/markets/aaveV4/index.js +0 -140
  49. package/cjs/types/aaveV4.d.ts +0 -153
  50. package/cjs/types/aaveV4.js +0 -19
  51. package/esm/aaveV4/index.d.ts +0 -7
  52. package/esm/aaveV4/index.js +0 -255
  53. package/esm/aaveV4/lend.d.ts +0 -45
  54. package/esm/aaveV4/lend.js +0 -134
  55. package/esm/helpers/aaveV4Helpers/index.d.ts +0 -12
  56. package/esm/helpers/aaveV4Helpers/index.js +0 -108
  57. package/esm/markets/aaveV4/index.d.ts +0 -28
  58. package/esm/markets/aaveV4/index.js +0 -122
  59. package/esm/types/aaveV4.d.ts +0 -153
  60. package/esm/types/aaveV4.js +0 -16
  61. package/src/aaveV4/index.ts +0 -291
  62. package/src/aaveV4/lend.ts +0 -180
  63. package/src/helpers/aaveV4Helpers/index.ts +0 -133
  64. package/src/markets/aaveV4/index.ts +0 -149
  65. package/src/types/aaveV4.ts +0 -169
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAaveV4SpokeTypeInfo = exports.AaveV4Spokes = exports.AAVE_V4_MAIN_SPOKE = exports.AAVE_V4_LIDO_SPOKE = exports.AAVE_V4_KELP_SPOKE = exports.AAVE_V4_GOLD_SPOKE = exports.AAVE_V4_ETHERFI_SPOKE = exports.AAVE_V4_ETHENA_SPOKE = exports.AAVE_V4_BLUECHIP_SPOKE = exports.getAaveV4HubByAddress = exports.getAaveV4HubTypeInfo = exports.AaveV4Hubs = exports.AAVE_V4_PRIME_HUB = exports.AAVE_V4_PLUS_HUB = exports.AAVE_V4_CORE_HUB = void 0;
4
- const types_1 = require("../../types");
5
- // HUBS
6
- const AAVE_V4_CORE_HUB = (networkId) => ({
7
- chainIds: [types_1.NetworkNumber.Eth],
8
- label: 'Core Hub',
9
- value: types_1.AaveV4HubsType.AaveV4CoreHub,
10
- address: '0x3Ed2C9829FBCab6015E331a0352F8ae148217D70',
11
- });
12
- exports.AAVE_V4_CORE_HUB = AAVE_V4_CORE_HUB;
13
- const AAVE_V4_PLUS_HUB = (networkId) => ({
14
- chainIds: [types_1.NetworkNumber.Eth],
15
- label: 'Plus Hub',
16
- value: types_1.AaveV4HubsType.AaveV4PlusHub,
17
- address: '0xcb8C80026248f92c6DE735264c23c8e22922C562',
18
- });
19
- exports.AAVE_V4_PLUS_HUB = AAVE_V4_PLUS_HUB;
20
- const AAVE_V4_PRIME_HUB = (networkId) => ({
21
- chainIds: [types_1.NetworkNumber.Eth],
22
- label: 'Prime Hub',
23
- value: types_1.AaveV4HubsType.AaveV4PrimeHub,
24
- address: '0xea40581231Ca775e6A3d7c129cF231D292B85f20',
25
- });
26
- exports.AAVE_V4_PRIME_HUB = AAVE_V4_PRIME_HUB;
27
- const AaveV4Hubs = (networkId) => ({
28
- [types_1.AaveV4HubsType.AaveV4CoreHub]: (0, exports.AAVE_V4_CORE_HUB)(networkId),
29
- [types_1.AaveV4HubsType.AaveV4PlusHub]: (0, exports.AAVE_V4_PLUS_HUB)(networkId),
30
- [types_1.AaveV4HubsType.AaveV4PrimeHub]: (0, exports.AAVE_V4_PRIME_HUB)(networkId),
31
- });
32
- exports.AaveV4Hubs = AaveV4Hubs;
33
- const getAaveV4HubTypeInfo = (type, network) => (Object.assign({}, (0, exports.AaveV4Hubs)(network !== null && network !== void 0 ? network : types_1.NetworkNumber.Eth))[type]);
34
- exports.getAaveV4HubTypeInfo = getAaveV4HubTypeInfo;
35
- const getAaveV4HubByAddress = (networkId, address) => Object.values((0, exports.AaveV4Hubs)(networkId)).find(hub => hub.address.toLowerCase() === address.toLowerCase());
36
- exports.getAaveV4HubByAddress = getAaveV4HubByAddress;
37
- // SPOKES
38
- const AAVE_V4_BLUECHIP_SPOKE = (networkId) => ({
39
- chainIds: [types_1.NetworkNumber.Eth],
40
- label: 'Bluechip Spoke',
41
- value: types_1.AaveV4SpokesType.AaveV4BluechipSpoke,
42
- url: 'bluechip',
43
- address: '0x637F9E189332a2821e5B046E2d7EEFae2405d6c5',
44
- hubs: [
45
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
46
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
47
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
48
- ],
49
- });
50
- exports.AAVE_V4_BLUECHIP_SPOKE = AAVE_V4_BLUECHIP_SPOKE;
51
- const AAVE_V4_ETHENA_SPOKE = (networkId) => ({
52
- chainIds: [types_1.NetworkNumber.Eth],
53
- label: 'Ethena Spoke',
54
- value: types_1.AaveV4SpokesType.AaveV4EthenaSpoke,
55
- url: 'ethena',
56
- address: '0xf3b207c235f6154120F41eB63D5ACCBAfD4086D1',
57
- hubs: [
58
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
59
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
60
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
61
- ],
62
- });
63
- exports.AAVE_V4_ETHENA_SPOKE = AAVE_V4_ETHENA_SPOKE;
64
- const AAVE_V4_ETHERFI_SPOKE = (networkId) => ({
65
- chainIds: [types_1.NetworkNumber.Eth],
66
- label: 'Etherfi Spoke',
67
- value: types_1.AaveV4SpokesType.AaveV4EtherfiSpoke,
68
- url: 'etherfi',
69
- address: '0x4054a9EbfcdB692599a8dF61eb0b3484F2d279D4',
70
- hubs: [
71
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
72
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
73
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
74
- ],
75
- });
76
- exports.AAVE_V4_ETHERFI_SPOKE = AAVE_V4_ETHERFI_SPOKE;
77
- const AAVE_V4_GOLD_SPOKE = (networkId) => ({
78
- chainIds: [types_1.NetworkNumber.Eth],
79
- label: 'Gold Spoke',
80
- value: types_1.AaveV4SpokesType.AaveV4GoldSpoke,
81
- url: 'gold',
82
- address: '0x0DC7ccE912Afab8B49031A0A95DB74531741C2c4',
83
- hubs: [
84
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
85
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
86
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
87
- ],
88
- });
89
- exports.AAVE_V4_GOLD_SPOKE = AAVE_V4_GOLD_SPOKE;
90
- const AAVE_V4_KELP_SPOKE = (networkId) => ({
91
- chainIds: [types_1.NetworkNumber.Eth],
92
- label: 'Kelp Spoke',
93
- value: types_1.AaveV4SpokesType.AaveV4KelpSpoke,
94
- url: 'kelp',
95
- address: '0x8aC76d950a3D03F9E1d857b5AAFFdA3f86C1e9AA',
96
- hubs: [
97
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
98
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
99
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
100
- ],
101
- });
102
- exports.AAVE_V4_KELP_SPOKE = AAVE_V4_KELP_SPOKE;
103
- const AAVE_V4_LIDO_SPOKE = (networkId) => ({
104
- chainIds: [types_1.NetworkNumber.Eth],
105
- label: 'Lido Spoke',
106
- value: types_1.AaveV4SpokesType.AaveV4LidoSpoke,
107
- url: 'lido',
108
- address: '0x4D4a7b3Ce709b4362D7095a4A0105bDFDb5dA2a7',
109
- hubs: [
110
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
111
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
112
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
113
- ],
114
- });
115
- exports.AAVE_V4_LIDO_SPOKE = AAVE_V4_LIDO_SPOKE;
116
- const AAVE_V4_MAIN_SPOKE = (networkId) => ({
117
- chainIds: [types_1.NetworkNumber.Eth],
118
- label: 'Main Spoke',
119
- value: types_1.AaveV4SpokesType.AaveV4MainSpoke,
120
- url: 'main',
121
- address: '0x46539e9123A18c427e6b4DFF114c28CF405Cb023',
122
- hubs: [
123
- (0, exports.AAVE_V4_CORE_HUB)(types_1.NetworkNumber.Eth).address,
124
- (0, exports.AAVE_V4_PLUS_HUB)(types_1.NetworkNumber.Eth).address,
125
- (0, exports.AAVE_V4_PRIME_HUB)(types_1.NetworkNumber.Eth).address,
126
- ],
127
- });
128
- exports.AAVE_V4_MAIN_SPOKE = AAVE_V4_MAIN_SPOKE;
129
- const AaveV4Spokes = (networkId) => ({
130
- [types_1.AaveV4SpokesType.AaveV4BluechipSpoke]: (0, exports.AAVE_V4_BLUECHIP_SPOKE)(networkId),
131
- [types_1.AaveV4SpokesType.AaveV4EthenaSpoke]: (0, exports.AAVE_V4_ETHENA_SPOKE)(networkId),
132
- [types_1.AaveV4SpokesType.AaveV4EtherfiSpoke]: (0, exports.AAVE_V4_ETHERFI_SPOKE)(networkId),
133
- [types_1.AaveV4SpokesType.AaveV4GoldSpoke]: (0, exports.AAVE_V4_GOLD_SPOKE)(networkId),
134
- [types_1.AaveV4SpokesType.AaveV4KelpSpoke]: (0, exports.AAVE_V4_KELP_SPOKE)(networkId),
135
- [types_1.AaveV4SpokesType.AaveV4LidoSpoke]: (0, exports.AAVE_V4_LIDO_SPOKE)(networkId),
136
- [types_1.AaveV4SpokesType.AaveV4MainSpoke]: (0, exports.AAVE_V4_MAIN_SPOKE)(networkId),
137
- });
138
- exports.AaveV4Spokes = AaveV4Spokes;
139
- const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, (0, exports.AaveV4Spokes)(network !== null && network !== void 0 ? network : types_1.NetworkNumber.Eth))[type]);
140
- exports.getAaveV4SpokeTypeInfo = getAaveV4SpokeTypeInfo;
@@ -1,153 +0,0 @@
1
- import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
2
- export declare enum AaveV4HubsType {
3
- AaveV4CoreHub = "aave_v4_core_hub",
4
- AaveV4PlusHub = "aave_v4_plus_hub",
5
- AaveV4PrimeHub = "aave_v4_prime_hub"
6
- }
7
- export declare enum AaveV4SpokesType {
8
- AaveV4BluechipSpoke = "aave_v4_bluechip_spoke",
9
- AaveV4EthenaSpoke = "aave_v4_ethena_spoke",
10
- AaveV4EtherfiSpoke = "aave_v4_etherfi_spoke",
11
- AaveV4GoldSpoke = "aave_v4_gold_spoke",
12
- AaveV4KelpSpoke = "aave_v4_kelp_spoke",
13
- AaveV4LidoSpoke = "aave_v4_lido_spoke",
14
- AaveV4MainSpoke = "aave_v4_main_spoke"
15
- }
16
- export interface AaveV4HubInfo {
17
- chainIds: NetworkNumber[];
18
- label: string;
19
- value: AaveV4HubsType;
20
- address: EthAddress;
21
- }
22
- export interface AaveV4HubAssetOnChainData {
23
- assetId: number;
24
- drawnRate: bigint;
25
- liquidity: bigint;
26
- liquidityFee: number;
27
- swept: bigint;
28
- totalDrawn: bigint;
29
- totalDrawnShares: bigint;
30
- totalPremiumShares: bigint;
31
- }
32
- export interface AaveV4HubOnChainData {
33
- assets: Record<number, AaveV4HubAssetOnChainData>;
34
- }
35
- export interface AaveV4SpokeInfo {
36
- chainIds: NetworkNumber[];
37
- label: string;
38
- value: AaveV4SpokesType;
39
- url: string;
40
- address: EthAddress;
41
- hubs: EthAddress[];
42
- }
43
- export interface AaveV4SpokeData {
44
- assetsData: AaveV4AssetsData;
45
- oracle: EthAddress;
46
- oracleDecimals: number;
47
- address: EthAddress;
48
- }
49
- export interface AaveV4ReserveAssetOnChain {
50
- underlying: EthAddress;
51
- hub: EthAddress;
52
- assetId: number;
53
- decimals: number;
54
- paused: boolean;
55
- frozen: boolean;
56
- borrowable: boolean;
57
- collateralRisk: number;
58
- collateralFactor: number;
59
- maxLiquidationBonus: number;
60
- liquidationFee: number;
61
- price: bigint;
62
- totalSupplied: bigint;
63
- totalDrawn: bigint;
64
- totalPremium: bigint;
65
- totalDebt: bigint;
66
- supplyCap: bigint;
67
- borrowCap: bigint;
68
- deficitRay: bigint;
69
- spokeActive: boolean;
70
- spokeHalted: boolean;
71
- }
72
- export interface AaveV4ReserveAssetData {
73
- symbol: string;
74
- underlying: EthAddress;
75
- hub: EthAddress;
76
- hubName: string;
77
- assetId: number;
78
- reserveId: number;
79
- paused: boolean;
80
- frozen: boolean;
81
- borrowable: boolean;
82
- collateralRisk: number;
83
- collateralFactor: number;
84
- liquidationFee: number;
85
- price: string;
86
- totalSupplied: string;
87
- totalDrawn: string;
88
- totalPremium: string;
89
- totalDebt: string;
90
- supplyCap: string;
91
- borrowCap: string;
92
- spokeActive: boolean;
93
- spokeHalted: boolean;
94
- drawnRate: string;
95
- supplyRate: string;
96
- borrowRate: string;
97
- supplyIncentives: IncentiveData[];
98
- borrowIncentives: IncentiveData[];
99
- canBeBorrowed: boolean;
100
- canBeSupplied: boolean;
101
- canBeWithdrawn: boolean;
102
- canBePayBacked: boolean;
103
- utilization: string;
104
- }
105
- export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
106
- export interface AaveV4UsedReserveAsset {
107
- symbol: string;
108
- hubName: string;
109
- assetId: number;
110
- reserveId: number;
111
- supplied: string;
112
- suppliedUsd: string;
113
- drawn: string;
114
- drawnUsd: string;
115
- premium: string;
116
- premiumUsd: string;
117
- borrowed: string;
118
- borrowedUsd: string;
119
- isSupplied: boolean;
120
- isBorrowed: boolean;
121
- collateral: boolean;
122
- collateralFactor: number;
123
- }
124
- export interface AaveV4AggregatedPositionData {
125
- suppliedUsd: string;
126
- suppliedCollateralUsd: string;
127
- borrowLimitUsd: string;
128
- liquidationLimitUsd: string;
129
- borrowedUsd: string;
130
- drawnUsd: string;
131
- premiumUsd: string;
132
- leftToBorrowUsd: string;
133
- ratio: string;
134
- collRatio: string;
135
- liqRatio: string;
136
- liqPercent: string;
137
- leveragedType: LeverageType;
138
- leveragedAsset: string;
139
- liquidationPrice: string;
140
- minCollRatio: string;
141
- collLiquidationRatio: string;
142
- minHealthRatio: string;
143
- netApy: string;
144
- incentiveUsd: string;
145
- totalInterestUsd: string;
146
- currentVolatilePairRatio?: string;
147
- }
148
- export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
149
- export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
150
- usedAssets: AaveV4UsedReserveAssets;
151
- healthFactor: string;
152
- riskPremiumBps: number;
153
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AaveV4SpokesType = exports.AaveV4HubsType = void 0;
4
- var AaveV4HubsType;
5
- (function (AaveV4HubsType) {
6
- AaveV4HubsType["AaveV4CoreHub"] = "aave_v4_core_hub";
7
- AaveV4HubsType["AaveV4PlusHub"] = "aave_v4_plus_hub";
8
- AaveV4HubsType["AaveV4PrimeHub"] = "aave_v4_prime_hub";
9
- })(AaveV4HubsType || (exports.AaveV4HubsType = AaveV4HubsType = {}));
10
- var AaveV4SpokesType;
11
- (function (AaveV4SpokesType) {
12
- AaveV4SpokesType["AaveV4BluechipSpoke"] = "aave_v4_bluechip_spoke";
13
- AaveV4SpokesType["AaveV4EthenaSpoke"] = "aave_v4_ethena_spoke";
14
- AaveV4SpokesType["AaveV4EtherfiSpoke"] = "aave_v4_etherfi_spoke";
15
- AaveV4SpokesType["AaveV4GoldSpoke"] = "aave_v4_gold_spoke";
16
- AaveV4SpokesType["AaveV4KelpSpoke"] = "aave_v4_kelp_spoke";
17
- AaveV4SpokesType["AaveV4LidoSpoke"] = "aave_v4_lido_spoke";
18
- AaveV4SpokesType["AaveV4MainSpoke"] = "aave_v4_main_spoke";
19
- })(AaveV4SpokesType || (exports.AaveV4SpokesType = AaveV4SpokesType = {}));
@@ -1,7 +0,0 @@
1
- import { Client } from 'viem';
2
- import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
3
- export * as lend from './lend';
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>;
@@ -1,255 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import Dec from 'decimal.js';
11
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
- import { getViemProvider } from '../services/viem';
13
- import { IncentiveKind, } from '../types';
14
- import { AaveV4ViewContractViem } from '../contracts';
15
- import { getStakingApy, STAKING_ASSETS } from '../staking';
16
- import { wethToEth } from '../services/utils';
17
- import { aaveV4GetAggregatedPositionData } from '../helpers/aaveV4Helpers';
18
- import { getAaveV4HubByAddress } from '../markets/aaveV4';
19
- import { aprToApy } from '../moneymarket';
20
- export * as lend from './lend';
21
- const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
22
- const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
23
- return {
24
- assets: hubData.reduce((acc, assetOnChainData) => {
25
- acc[assetOnChainData.assetId] = {
26
- assetId: assetOnChainData.assetId,
27
- drawnRate: assetOnChainData.drawnRate,
28
- liquidity: assetOnChainData.liquidity,
29
- liquidityFee: assetOnChainData.liquidityFee,
30
- swept: assetOnChainData.swept,
31
- totalDrawn: assetOnChainData.totalDrawn,
32
- totalDrawnShares: assetOnChainData.totalDrawnShares,
33
- totalPremiumShares: assetOnChainData.totalPremiumShares,
34
- };
35
- return acc;
36
- }, {}),
37
- };
38
- });
39
- // TODO AaveV4: Will be used for after values, onchain data is available when fetching position data
40
- const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
41
- const collaterals = [];
42
- const debts = [];
43
- Object.entries(usedAssets).forEach(([identifier, asset]) => {
44
- const reserveData = assetsData[identifier];
45
- if (!reserveData)
46
- return;
47
- const borrowedUsdDec = new Dec(asset.borrowedUsd || '0');
48
- if (asset.isBorrowed && borrowedUsdDec.gt(0)) {
49
- debts.push({ valueUsd: borrowedUsdDec });
50
- }
51
- const suppliedUsdDec = new Dec(asset.suppliedUsd || '0');
52
- const isActiveCollateral = asset.collateral
53
- && asset.isSupplied
54
- && asset.collateralFactor > 0
55
- && suppliedUsdDec.gt(0);
56
- if (isActiveCollateral) {
57
- // collateralRisk is stored as a fraction (e.g. 0.25), convert back to bps
58
- const riskBps = new Dec(reserveData.collateralRisk).mul(10000).toNumber();
59
- collaterals.push({
60
- riskBps,
61
- valueUsd: suppliedUsdDec,
62
- });
63
- }
64
- });
65
- const totalDebtUsd = debts.reduce((sum, d) => sum.add(d.valueUsd), new Dec(0));
66
- if (totalDebtUsd.lte(0)) {
67
- return 0;
68
- }
69
- // sort by risk ASC, value DESC
70
- collaterals.sort((a, b) => {
71
- if (a.riskBps !== b.riskBps)
72
- return a.riskBps - b.riskBps;
73
- return b.valueUsd.comparedTo(a.valueUsd);
74
- });
75
- let debtLeftToCover = totalDebtUsd;
76
- let numerator = new Dec(0); // sum(coveredUsd * riskBps)
77
- let coveredDebt = new Dec(0); // sum(coveredUsd)
78
- collaterals.forEach(({ riskBps, valueUsd }) => {
79
- if (debtLeftToCover.lte(0))
80
- return;
81
- const coveredUsd = Dec.min(valueUsd, debtLeftToCover);
82
- numerator = numerator.add(coveredUsd.mul(riskBps));
83
- coveredDebt = coveredDebt.add(coveredUsd);
84
- debtLeftToCover = debtLeftToCover.sub(coveredUsd);
85
- });
86
- if (coveredDebt.lte(0)) {
87
- return 0;
88
- }
89
- const riskPremiumBps = numerator.div(coveredDebt);
90
- return riskPremiumBps.toNumber();
91
- };
92
- const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
93
- var _a, _b, _c, _d, _e, _f;
94
- const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
95
- const symbol = wethToEth(assetInfo.symbol);
96
- const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
97
- if (!hubInfo) {
98
- throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
99
- }
100
- const isStakingAsset = STAKING_ASSETS.includes(symbol);
101
- const supplyIncentives = [];
102
- const borrowIncentives = [];
103
- if (isStakingAsset) {
104
- const yieldApy = yield getStakingApy(symbol, network);
105
- supplyIncentives.push({
106
- apy: yieldApy,
107
- token: symbol,
108
- incentiveKind: IncentiveKind.Staking,
109
- description: `Native ${symbol} yield.`,
110
- });
111
- if (reserveAsset.borrowable) {
112
- // When borrowing assets whose value increases over time
113
- borrowIncentives.push({
114
- apy: new Dec(yieldApy).mul(-1).toString(),
115
- token: symbol,
116
- incentiveKind: IncentiveKind.Reward,
117
- description: `Due to the native yield of ${symbol}, the value of the debt would increase over time.`,
118
- });
119
- }
120
- }
121
- const totalSuppliedRaw = (_a = reserveAsset.totalSupplied) !== null && _a !== void 0 ? _a : 0;
122
- const totalDrawnRaw = (_b = reserveAsset.totalDrawn) !== null && _b !== void 0 ? _b : 0;
123
- const totalPremiumRaw = (_c = reserveAsset.totalPremium) !== null && _c !== void 0 ? _c : 0;
124
- const totalDebtRaw = (_d = reserveAsset.totalDebt) !== null && _d !== void 0 ? _d : 0;
125
- const supplyCapRaw = (_e = reserveAsset.supplyCap) !== null && _e !== void 0 ? _e : 0;
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();
130
- /** @DEV Hub related calculations */
131
- const drawnRate = new Dec(hubAsset.drawnRate.toString()).div(new Dec(10).pow(27));
132
- const borrowApr = drawnRate.mul(100);
133
- const totalDrawn = new Dec(hubAsset.totalDrawn.toString());
134
- const liquidity = new Dec(hubAsset.liquidity.toString());
135
- const swept = new Dec(hubAsset.swept.toString());
136
- const hubUtilizationDenominator = totalDrawn.add(swept).add(liquidity);
137
- const hubUtilization = hubUtilizationDenominator.isZero() ? new Dec(0) : totalDrawn.div(hubUtilizationDenominator);
138
- const liquidityFee = new Dec(hubAsset.liquidityFee.toString()).div(new Dec(10).pow(4));
139
- const totalDrawnShares = new Dec(hubAsset.totalDrawnShares.toString());
140
- const totalPremiumShares = new Dec(hubAsset.totalPremiumShares.toString());
141
- // TODO JK@JK premiumMultiplier should be added to supplyApr calculation (.mul(premiumMultiplier)
142
- // TODO JKJ@JK when we confirm that this is the right way to calculate it
143
- const premiumMultiplier = totalDrawnShares.isZero() ? new Dec(1) : totalDrawnShares.add(totalPremiumShares).div(totalDrawnShares);
144
- const supplyApr = borrowApr.mul(hubUtilization).mul(new Dec(1).minus(liquidityFee));
145
- return ({
146
- symbol,
147
- underlying: reserveAsset.underlying,
148
- hub: hubInfo.address,
149
- hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label,
150
- assetId: reserveAsset.assetId,
151
- reserveId,
152
- paused: reserveAsset.paused,
153
- frozen: reserveAsset.frozen,
154
- borrowable: reserveAsset.borrowable,
155
- collateralRisk: new Dec(reserveAsset.collateralRisk).div(10000).toNumber(),
156
- collateralFactor: new Dec(reserveAsset.collateralFactor).div(10000).toNumber(),
157
- liquidationFee: new Dec(reserveAsset.liquidationFee).div(10000).toNumber(),
158
- price: new Dec(reserveAsset.price).div(new Dec(10).pow(oracleDecimals)).toString(),
159
- totalSupplied: assetAmountInEth(totalSuppliedRaw.toString(), symbol),
160
- totalDrawn: assetAmountInEth(totalDrawnRaw.toString(), symbol),
161
- totalPremium: assetAmountInEth(totalPremiumRaw.toString(), symbol),
162
- totalDebt: assetAmountInEth(totalDebtRaw.toString(), symbol),
163
- supplyCap: assetAmountInEth(supplyCapRaw.toString(), symbol),
164
- borrowCap: assetAmountInEth(borrowCapRaw.toString(), symbol),
165
- spokeActive: reserveAsset.spokeActive,
166
- spokeHalted: reserveAsset.spokeHalted,
167
- drawnRate: drawnRate.toString(),
168
- borrowRate: aprToApy(borrowApr.toString()),
169
- supplyRate: aprToApy(supplyApr.toString()),
170
- supplyIncentives,
171
- borrowIncentives,
172
- canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
173
- canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
174
- canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
175
- canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
176
- utilization,
177
- });
178
- });
179
- export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
180
- return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
181
- const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
182
- const hubsData = {};
183
- const [spokeData] = yield Promise.all([
184
- viewContract.read.getSpokeDataFull([market.address]),
185
- ...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
186
- hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
187
- })),
188
- ]);
189
- 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); })));
190
- return {
191
- assetsData: reserveAssetsArray.reduce((acc, reserveAsset) => {
192
- acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
193
- return acc;
194
- }, {}),
195
- oracle: spokeData[0].oracle,
196
- oracleDecimals: +spokeData[0].oracleDecimals.toString(),
197
- address: market.address,
198
- };
199
- });
200
- }
201
- export function getAaveV4SpokeData(provider_1, network_1, spoke_1) {
202
- return __awaiter(this, arguments, void 0, function* (provider, network, spoke, blockNumber = 'latest') {
203
- return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
204
- });
205
- }
206
- export function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
207
- return __awaiter(this, arguments, void 0, function* (provider, network, spokeData, address, blockNumber = 'latest') {
208
- const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
209
- const loanData = yield viewContract.read.getLoanData([spokeData.address, address]);
210
- const healthFactor = new Dec(loanData.healthFactor).div(1e18).toString();
211
- const usedAssets = loanData.reserves.reduce((acc, usedReserveAsset) => {
212
- const identifier = `${wethToEth(getAssetInfoByAddress(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
213
- const reserveData = spokeData.assetsData[identifier];
214
- const price = reserveData.price;
215
- const supplied = assetAmountInEth(usedReserveAsset.supplied.toString(), reserveData.symbol);
216
- const drawn = assetAmountInEth(usedReserveAsset.drawn.toString(), reserveData.symbol);
217
- const premium = assetAmountInEth(usedReserveAsset.premium.toString(), reserveData.symbol);
218
- const borrowed = assetAmountInEth(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
219
- acc[identifier] = {
220
- symbol: reserveData.symbol,
221
- hubName: reserveData.hubName,
222
- assetId: reserveData.assetId,
223
- reserveId: +usedReserveAsset.reserveId.toString(),
224
- supplied,
225
- suppliedUsd: new Dec(supplied).mul(price).toString(),
226
- drawn,
227
- drawnUsd: new Dec(drawn).mul(price).toString(),
228
- premium,
229
- premiumUsd: new Dec(premium).mul(price).toString(),
230
- borrowed,
231
- borrowedUsd: new Dec(borrowed).mul(price).toString(),
232
- isSupplied: !new Dec(supplied).eq(0),
233
- isBorrowed: usedReserveAsset.isBorrowing,
234
- collateral: usedReserveAsset.isUsingAsCollateral,
235
- collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
236
- };
237
- return acc;
238
- }, {});
239
- const aggregated = aaveV4GetAggregatedPositionData({
240
- usedAssets,
241
- assetsData: spokeData.assetsData,
242
- network,
243
- useUserCollateralFactor: true,
244
- });
245
- const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, spokeData.assetsData);
246
- return Object.assign(Object.assign({}, aggregated), { usedAssets,
247
- healthFactor,
248
- riskPremiumBps });
249
- });
250
- }
251
- export function getAaveV4AccountData(provider_1, network_1, marketData_1, address_1) {
252
- return __awaiter(this, arguments, void 0, function* (provider, network, marketData, address, blockNumber = 'latest') {
253
- return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
254
- });
255
- }
@@ -1,45 +0,0 @@
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[]>;