@defisaver/positions-sdk 2.1.49 → 2.1.51-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/aaveV3/index.d.ts +1 -1
- package/cjs/aaveV4/index.d.ts +7 -0
- package/cjs/aaveV4/index.js +167 -0
- package/cjs/config/contracts.d.ts +1277 -0
- package/cjs/config/contracts.js +9 -0
- package/cjs/contracts.d.ts +23120 -0
- package/cjs/contracts.js +2 -1
- package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/cjs/helpers/aaveV4Helpers/index.js +109 -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/aaveV4/index.d.ts +7 -0
- package/cjs/markets/aaveV4/index.js +22 -0
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +19 -2
- package/cjs/portfolio/index.d.ts +1 -1
- package/cjs/portfolio/index.js +26 -17
- package/cjs/services/viem.d.ts +20 -8
- package/cjs/services/viem.js +13 -0
- package/cjs/types/aaveV4.d.ts +129 -0
- package/cjs/types/aaveV4.js +11 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +4 -0
- package/esm/aaveV3/index.d.ts +1 -1
- package/esm/aaveV4/index.d.ts +7 -0
- package/esm/aaveV4/index.js +158 -0
- package/esm/config/contracts.d.ts +1277 -0
- package/esm/config/contracts.js +8 -0
- package/esm/contracts.d.ts +23120 -0
- package/esm/contracts.js +1 -0
- package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/esm/helpers/aaveV4Helpers/index.js +100 -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/aaveV4/index.d.ts +7 -0
- package/esm/markets/aaveV4/index.js +16 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/portfolio/index.d.ts +1 -1
- package/esm/portfolio/index.js +27 -18
- package/esm/services/viem.d.ts +20 -8
- package/esm/services/viem.js +13 -1
- package/esm/types/aaveV4.d.ts +129 -0
- package/esm/types/aaveV4.js +8 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/morphoBlue.d.ts +1 -0
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +4 -0
- package/package.json +1 -1
- package/src/aaveV3/index.ts +1 -1
- package/src/aaveV4/index.ts +169 -0
- package/src/config/contracts.ts +8 -0
- package/src/contracts.ts +3 -1
- package/src/helpers/aaveV4Helpers/index.ts +121 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/markets/aaveV4/index.ts +19 -0
- package/src/markets/index.ts +1 -0
- package/src/markets/morphoBlue/index.ts +17 -0
- package/src/portfolio/index.ts +25 -17
- package/src/services/viem.ts +24 -2
- package/src/types/aaveV4.ts +142 -0
- package/src/types/index.ts +2 -1
- package/src/types/morphoBlue.ts +2 -0
- package/src/types/portfolio.ts +4 -0
package/src/portfolio/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
3
|
import {
|
|
4
4
|
AaveMarkets,
|
|
5
|
+
AaveV4Spokes,
|
|
5
6
|
CompoundMarkets,
|
|
6
7
|
CrvUsdMarkets,
|
|
7
8
|
EulerV2Markets,
|
|
@@ -14,6 +15,7 @@ import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } fr
|
|
|
14
15
|
import {
|
|
15
16
|
AaveV2MarketData,
|
|
16
17
|
AaveV3MarketData,
|
|
18
|
+
AaveV4SpokeData,
|
|
17
19
|
AaveVersions,
|
|
18
20
|
CdpInfo,
|
|
19
21
|
CompoundV2MarketsData,
|
|
@@ -49,8 +51,9 @@ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
|
49
51
|
import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
|
|
50
52
|
import { getKingRewards } from '../claiming/king';
|
|
51
53
|
import { fetchEthenaAirdropRewards } from '../claiming/ethena';
|
|
54
|
+
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
52
55
|
|
|
53
|
-
export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[],
|
|
56
|
+
export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
54
57
|
positions: PortfolioPositionsData;
|
|
55
58
|
stakingPositions: any;
|
|
56
59
|
rewardsData: any;
|
|
@@ -71,21 +74,11 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
71
74
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
72
75
|
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
73
76
|
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
77
|
+
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
74
78
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
batchSize: 2500000,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
const defaultClient = getViemProvider(defaultProvider, network, {
|
|
83
|
-
batch: {
|
|
84
|
-
multicall: {
|
|
85
|
-
batchSize: 2500000,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
});
|
|
79
|
+
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 500_000 : 2_500_000 } } }];
|
|
80
|
+
const client = getViemProvider(provider, ...args);
|
|
81
|
+
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
89
82
|
|
|
90
83
|
const morphoMarketsData: Record<string, MorphoBlueMarketInfo> = {};
|
|
91
84
|
const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
|
|
@@ -98,6 +91,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
98
91
|
const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
|
|
99
92
|
const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
|
|
100
93
|
const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
|
|
94
|
+
const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
|
|
101
95
|
|
|
102
96
|
const markets = {
|
|
103
97
|
morphoMarketsData,
|
|
@@ -110,16 +104,18 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
110
104
|
crvUsdMarketsData,
|
|
111
105
|
llamaLendMarketsData,
|
|
112
106
|
liquityV2MarketsData,
|
|
107
|
+
aaveV4SpokesData,
|
|
113
108
|
};
|
|
114
109
|
|
|
115
110
|
const positions: PortfolioPositionsData = {};
|
|
116
111
|
const stakingPositions: any = {};
|
|
117
112
|
const rewardsData: any = {};
|
|
118
|
-
const allAddresses = [...addresses
|
|
113
|
+
const allAddresses = [...addresses];
|
|
119
114
|
|
|
120
115
|
for (const address of allAddresses) {
|
|
121
116
|
positions[address.toLowerCase() as EthAddress] = {
|
|
122
117
|
aaveV3: {},
|
|
118
|
+
aaveV4: {},
|
|
123
119
|
morphoBlue: {},
|
|
124
120
|
compoundV3: {},
|
|
125
121
|
spark: {},
|
|
@@ -188,6 +184,10 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
188
184
|
const marketData = await _getAaveV3MarketData(client, network, market);
|
|
189
185
|
aaveV3MarketsData[market.value] = marketData;
|
|
190
186
|
}),
|
|
187
|
+
...aaveV4Spokes.map(async (spoke) => {
|
|
188
|
+
const spokeData = await _getAaveV4SpokeData(client, network, spoke);
|
|
189
|
+
aaveV4SpokesData[spoke.value] = spokeData;
|
|
190
|
+
}),
|
|
191
191
|
...aaveV2Markets.map(async (market) => {
|
|
192
192
|
const marketData = await _getAaveV2MarketsData(client, network, market);
|
|
193
193
|
aaveV2MarketsData[market.value] = marketData;
|
|
@@ -430,7 +430,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
430
430
|
})(),
|
|
431
431
|
]);
|
|
432
432
|
|
|
433
|
-
|
|
434
433
|
await Promise.all([
|
|
435
434
|
...aaveV3Markets.map((market) => allAddresses.map(async (address) => {
|
|
436
435
|
try {
|
|
@@ -441,6 +440,15 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
441
440
|
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
442
441
|
}
|
|
443
442
|
})).flat(),
|
|
443
|
+
...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
|
|
444
|
+
try {
|
|
445
|
+
const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
|
|
446
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
447
|
+
} catch (error) {
|
|
448
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
449
|
+
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
450
|
+
}
|
|
451
|
+
})).flat(),
|
|
444
452
|
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
445
453
|
try {
|
|
446
454
|
const [accDataPromise, earnDataPromise] = await Promise.allSettled([
|
package/src/services/viem.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createPublicClient,
|
|
3
|
+
custom,
|
|
4
|
+
encodeFunctionData,
|
|
5
|
+
type Abi,
|
|
6
|
+
} from 'viem';
|
|
2
7
|
import {
|
|
3
8
|
arbitrum, base, mainnet, optimism, linea, plasma,
|
|
4
9
|
} from 'viem/chains';
|
|
@@ -32,4 +37,21 @@ export const getViemProvider = (provider: EthereumProvider, network: NetworkNumb
|
|
|
32
37
|
export const setViemBlockNumber = (block: Blockish) => {
|
|
33
38
|
if (block === 'latest') return {};
|
|
34
39
|
return { blockNumber: BigInt(block) };
|
|
35
|
-
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Utility function to return callData
|
|
44
|
+
* Useful for Tenderly simulation
|
|
45
|
+
*
|
|
46
|
+
* @param contract
|
|
47
|
+
* @param functionName
|
|
48
|
+
* @param args
|
|
49
|
+
*/
|
|
50
|
+
export function encodeCalldata(
|
|
51
|
+
contract: { abi: Abi },
|
|
52
|
+
functionName: string,
|
|
53
|
+
args?: readonly unknown[],
|
|
54
|
+
): `0x${string}` {
|
|
55
|
+
const callDescriptor = { abi: contract.abi, functionName } as const;
|
|
56
|
+
return encodeFunctionData((args ? { ...callDescriptor, args } : callDescriptor) as any);
|
|
57
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
|
+
|
|
3
|
+
export enum AaveV4SpokesType {
|
|
4
|
+
AaveV4CoreSpoke = 'aave_v4_core_spoke',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum AaveV4HubsType {
|
|
8
|
+
AaveV4CoreHub = 'aave_v4_core_hub',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AaveV4SpokeInfo {
|
|
12
|
+
chainIds: NetworkNumber[],
|
|
13
|
+
label: string,
|
|
14
|
+
value: AaveV4SpokesType,
|
|
15
|
+
url: string,
|
|
16
|
+
address: EthAddress,
|
|
17
|
+
hubs: EthAddress[],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AaveV4HubAssetOnChainData {
|
|
21
|
+
assetId: number,
|
|
22
|
+
drawnRate: bigint,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AaveV4HubOnChainData {
|
|
26
|
+
assets: Record<number, AaveV4HubAssetOnChainData>,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AaveV4ReserveAssetOnChain {
|
|
30
|
+
underlying: EthAddress,
|
|
31
|
+
hub: EthAddress,
|
|
32
|
+
assetId: number,
|
|
33
|
+
decimals: number,
|
|
34
|
+
paused: boolean,
|
|
35
|
+
frozen: boolean,
|
|
36
|
+
borrowable: boolean,
|
|
37
|
+
collateralRisk: number,
|
|
38
|
+
collateralFactor: number,
|
|
39
|
+
maxLiquidationBonus: number,
|
|
40
|
+
liquidationFee: number,
|
|
41
|
+
price: bigint,
|
|
42
|
+
totalSupplied: bigint,
|
|
43
|
+
totalDrawn: bigint,
|
|
44
|
+
totalPremium: bigint,
|
|
45
|
+
totalDebt: bigint,
|
|
46
|
+
supplyCap: bigint,
|
|
47
|
+
borrowCap: bigint,
|
|
48
|
+
deficitRay: bigint,
|
|
49
|
+
spokeActive: boolean,
|
|
50
|
+
spokePaused: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AaveV4ReserveAssetData {
|
|
54
|
+
symbol: string,
|
|
55
|
+
underlying: EthAddress,
|
|
56
|
+
hub: EthAddress,
|
|
57
|
+
assetId: number,
|
|
58
|
+
reserveId: number,
|
|
59
|
+
paused: boolean,
|
|
60
|
+
frozen: boolean,
|
|
61
|
+
borrowable: boolean,
|
|
62
|
+
collateralRisk: number,
|
|
63
|
+
collateralFactor: number,
|
|
64
|
+
liquidationFee: number,
|
|
65
|
+
price: string,
|
|
66
|
+
totalSupplied: string,
|
|
67
|
+
totalDrawn: string,
|
|
68
|
+
totalPremium: string,
|
|
69
|
+
totalDebt: string,
|
|
70
|
+
supplyCap: string,
|
|
71
|
+
borrowCap: string,
|
|
72
|
+
spokeActive: boolean,
|
|
73
|
+
spokePaused: boolean,
|
|
74
|
+
drawnRate: string,
|
|
75
|
+
supplyRate: string,
|
|
76
|
+
supplyIncentives: IncentiveData[];
|
|
77
|
+
borrowIncentives: IncentiveData[];
|
|
78
|
+
canBeBorrowed: boolean;
|
|
79
|
+
canBeSupplied: boolean;
|
|
80
|
+
canBeWithdrawn: boolean;
|
|
81
|
+
canBePayBacked: boolean;
|
|
82
|
+
utilization: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
86
|
+
|
|
87
|
+
export interface AaveV4SpokeData {
|
|
88
|
+
assetsData: AaveV4AssetsData,
|
|
89
|
+
oracle: EthAddress,
|
|
90
|
+
oracleDecimals: number,
|
|
91
|
+
address: EthAddress,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface AaveV4UsedReserveAsset {
|
|
95
|
+
symbol: string,
|
|
96
|
+
assetId: number,
|
|
97
|
+
reserveId: number,
|
|
98
|
+
supplied: string,
|
|
99
|
+
suppliedUsd: string,
|
|
100
|
+
drawn: string,
|
|
101
|
+
drawnUsd: string,
|
|
102
|
+
premium: string,
|
|
103
|
+
premiumUsd: string,
|
|
104
|
+
borrowed: string,
|
|
105
|
+
borrowedUsd: string,
|
|
106
|
+
isSupplied: boolean,
|
|
107
|
+
isBorrowed: boolean,
|
|
108
|
+
collateral: boolean,
|
|
109
|
+
collateralFactor: number,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface AaveV4AggregatedPositionData {
|
|
113
|
+
suppliedUsd: string,
|
|
114
|
+
suppliedCollateralUsd: string,
|
|
115
|
+
borrowLimitUsd: string,
|
|
116
|
+
liquidationLimitUsd: string,
|
|
117
|
+
borrowedUsd: string,
|
|
118
|
+
drawnUsd: string,
|
|
119
|
+
premiumUsd: string,
|
|
120
|
+
leftToBorrowUsd: string,
|
|
121
|
+
ratio: string,
|
|
122
|
+
collRatio: string,
|
|
123
|
+
liqRatio: string,
|
|
124
|
+
liqPercent: string,
|
|
125
|
+
leveragedType: string,
|
|
126
|
+
leveragedAsset: string,
|
|
127
|
+
liquidationPrice: string,
|
|
128
|
+
leveragedLsdAssetRatio?: string,
|
|
129
|
+
minCollRatio: string,
|
|
130
|
+
collLiquidationRatio: string,
|
|
131
|
+
minHealthRatio: string,
|
|
132
|
+
netApy: string,
|
|
133
|
+
incentiveUsd: string,
|
|
134
|
+
totalInterestUsd: string,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
|
|
138
|
+
|
|
139
|
+
export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
|
|
140
|
+
usedAssets: AaveV4UsedReserveAssets,
|
|
141
|
+
healthFactor: string,
|
|
142
|
+
}
|
package/src/types/index.ts
CHANGED
package/src/types/morphoBlue.ts
CHANGED
|
@@ -44,6 +44,8 @@ export enum MorphoBlueVersions {
|
|
|
44
44
|
MorphoBlueUSDeDAI_860 = 'morphoblueusdedai_860',
|
|
45
45
|
MorphoBlueUSDeDAI_915 = 'morphoblueusdedai_915',
|
|
46
46
|
|
|
47
|
+
MorphoBlueMORPHOUSDC_625 = 'morphobluemorphousdc_625',
|
|
48
|
+
|
|
47
49
|
// BASE
|
|
48
50
|
MorphoBlueCbEthUSDC_860_Base = 'morphobluecbethusdc_860_base',
|
|
49
51
|
MorphoBlueCbEthUSDC_860_Base_1c21c59d = 'morphobluecbethusdc_860_base_1c21c59d',
|
package/src/types/portfolio.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
2
3
|
import { EthAddress } from './common';
|
|
3
4
|
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
4
5
|
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
@@ -54,6 +55,9 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
54
55
|
[key: string]: FluidVaultData;
|
|
55
56
|
};
|
|
56
57
|
};
|
|
58
|
+
aaveV4: {
|
|
59
|
+
[key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
|
|
60
|
+
};
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export interface PortfolioPositionsData {
|