@defisaver/positions-sdk 2.1.75 → 2.1.78-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/merkl.js +1 -1
- package/cjs/aaveV4/index.d.ts +7 -0
- package/cjs/aaveV4/index.js +298 -0
- package/cjs/aaveV4/lend.d.ts +45 -0
- package/cjs/aaveV4/lend.js +141 -0
- package/cjs/claiming/aaveV3.js +1 -1
- 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 +12 -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/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/savings/summerVaults/options.js +8 -8
- package/cjs/types/aaveV4.d.ts +153 -0
- package/cjs/types/aaveV4.js +19 -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/aaveV3/merkl.js +1 -1
- package/esm/aaveV4/index.d.ts +7 -0
- package/esm/aaveV4/index.js +255 -0
- package/esm/aaveV4/lend.d.ts +45 -0
- package/esm/aaveV4/lend.js +134 -0
- package/esm/claiming/aaveV3.js +1 -1
- 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 +12 -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/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/savings/summerVaults/options.js +8 -8
- package/esm/types/aaveV4.d.ts +153 -0
- package/esm/types/aaveV4.js +16 -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/aaveV3/merkl.ts +1 -1
- package/src/aaveV4/index.ts +291 -0
- package/src/aaveV4/lend.ts +180 -0
- package/src/claiming/aaveV3.ts +1 -1
- package/src/config/contracts.ts +8 -0
- package/src/contracts.ts +2 -0
- package/src/helpers/aaveV4Helpers/index.ts +133 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/markets/aaveV4/index.ts +149 -0
- package/src/markets/index.ts +6 -1
- package/src/portfolio/index.ts +20 -0
- package/src/savings/summerVaults/options.ts +8 -8
- package/src/types/aaveV4.ts +169 -0
- package/src/types/index.ts +2 -1
- package/src/types/portfolio.ts +4 -0
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 = {}));
|
package/cjs/types/index.d.ts
CHANGED
package/cjs/types/index.js
CHANGED
package/cjs/types/portfolio.d.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';
|
|
@@ -51,6 +52,9 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
51
52
|
[key: string]: FluidVaultData;
|
|
52
53
|
};
|
|
53
54
|
};
|
|
55
|
+
aaveV4: {
|
|
56
|
+
[key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
|
|
57
|
+
};
|
|
54
58
|
}
|
|
55
59
|
export interface PortfolioPositionsData {
|
|
56
60
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
package/esm/aaveV3/merkl.js
CHANGED
|
@@ -35,7 +35,7 @@ export const formatAaveAsset = (_symbol) => {
|
|
|
35
35
|
};
|
|
36
36
|
export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
37
|
try {
|
|
38
|
-
const res = yield fetch('https://api
|
|
38
|
+
const res = yield fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
|
|
39
39
|
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
40
40
|
});
|
|
41
41
|
if (!res.ok)
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
}
|
|
@@ -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,134 @@
|
|
|
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 { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
11
|
+
import { AaveV4ViewContractViem } from '../contracts';
|
|
12
|
+
import { getViemProvider } from '../services/viem';
|
|
13
|
+
import { wethToEth } from '../services/utils';
|
|
14
|
+
import { NetworkNumber, } from '../types/common';
|
|
15
|
+
export const AAVE_V4_TOKENIZED_SPOKES = {
|
|
16
|
+
AAVE_CORE: '0x08309234884cF7E015b07Bf22569017Aa035cdeF',
|
|
17
|
+
EURC_CORE: '0x73596dED4B2Eb0aC85e477b3c8dB56FC427E6774',
|
|
18
|
+
GHO_CORE: '0xf7E1f1b43922527e5054bD77E7f863Cf182b194D',
|
|
19
|
+
GHO_PRIME: '0xeF1cAd5c6a2C9cb83c952b4B96bbD35b3F61F18f',
|
|
20
|
+
LBTC_CORE: '0x8f4D423590F22833131e3493bf67A27213398f8e',
|
|
21
|
+
LINK_CORE: '0xBE1197750b423e30137E97d9183065d33E903BE6',
|
|
22
|
+
PT_USDe_PLUS: '0x8cA27Ab284F2aA2BcF33D9129e11c101aD2d16de',
|
|
23
|
+
PT_sUSDe_PLUS: '0xb8A464EC56071a98c854f30fE19CfeCc41FA6233',
|
|
24
|
+
PYUSD_CORE: '0x203FB463087005698d50768FcA837047f738632d',
|
|
25
|
+
RLUSD_CORE: '0xa9afdd0c54fb153CaE39cE86E49626B5e9d15513',
|
|
26
|
+
USDC_CORE: '0xa2e476f4cbB06C7bFA8Ad51bCcbF198cd32CfD35',
|
|
27
|
+
USDC_PLUS: '0x320Bec4fB7a25e64c003A007D0AeF7AB3D6C30d7',
|
|
28
|
+
USDC_PRIME: '0x0A0507F7A1129892b5cf74b8B4e911442c466b87',
|
|
29
|
+
USDG_CORE: '0x87c224256f09a014C1BC3e9FbB094C3AdD8fBaCC',
|
|
30
|
+
USDT_CORE: '0x3f12BD5999b9172550893FF52691c980676f9E73',
|
|
31
|
+
USDT_PLUS: '0xa4E74a78bED2d3ab8971e8AB26fb39f26DD8eEd9',
|
|
32
|
+
USDT_PRIME: '0xF565fB55bc96d65561887898bfeb25C1dE7e06d2',
|
|
33
|
+
USDe_PLUS: '0xA0d346ab2699B689AC67aba5174164A84206BB73',
|
|
34
|
+
WBTC_CORE: '0x837Ab872A665e0CF467d41cF56a054031b4A38bc',
|
|
35
|
+
WBTC_PRIME: '0xeae98b8a1798738182B2123DF1eB93d97BD29F34',
|
|
36
|
+
WETH_CORE: '0x3961a75099E986F59a1a31c6f945061641dFD2b2',
|
|
37
|
+
WETH_PRIME: '0xa411826a6ef5d289c0FAa7d5B45FE8aAB52257F6',
|
|
38
|
+
XAUt_CORE: '0x470341bC0e2B833C54D0120642713BdF762A494F',
|
|
39
|
+
cbBTC_CORE: '0xe8D5E595d5b6b5EFf84B7064765fd0e8DfD214C9',
|
|
40
|
+
cbBTC_PRIME: '0x0E986545150DcDDe46Ea9df355D0fD2af33bd75D',
|
|
41
|
+
frxUSD_CORE: '0x00C8A6a42947Cc4E7B6f27963Cab0143ccaaD2B5',
|
|
42
|
+
frxUSD_PLUS: '0xCAB288d37CAb5a9db7b503F086455276Dcde61F1',
|
|
43
|
+
rsETH_CORE: '0x6eEce89caE2163584bA7Ff9743861B9633c245E0',
|
|
44
|
+
sUSDe_PLUS: '0xdf47fc43c88B06edC47753b7d647ff18037D2F3d',
|
|
45
|
+
weETH_CORE: '0xB67F20bFF413C8E5d633B54BD28899c4c9e33ed0',
|
|
46
|
+
wstETH_CORE: '0x474602394d0B02F43AC3D7C8c5cFc0814b03fd40',
|
|
47
|
+
wstETH_PRIME: '0xAcCdAb49ECB9A801CfF62a92fc80D52339b33770',
|
|
48
|
+
};
|
|
49
|
+
export const AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = {
|
|
50
|
+
[NetworkNumber.Eth]: Object.values(AAVE_V4_TOKENIZED_SPOKES),
|
|
51
|
+
};
|
|
52
|
+
export const aaveV4GetTokenizedHubKey = (hubNameOrKey) => {
|
|
53
|
+
if (!hubNameOrKey)
|
|
54
|
+
return null;
|
|
55
|
+
const normalized = hubNameOrKey.trim().toUpperCase();
|
|
56
|
+
// TODO AaveV4 Maybe turn into constants
|
|
57
|
+
if (normalized === 'CORE' || normalized === 'CORE HUB')
|
|
58
|
+
return 'CORE';
|
|
59
|
+
if (normalized === 'PLUS' || normalized === 'PLUS HUB')
|
|
60
|
+
return 'PLUS';
|
|
61
|
+
if (normalized === 'PRIME' || normalized === 'PRIME HUB')
|
|
62
|
+
return 'PRIME';
|
|
63
|
+
if (normalized.includes('CORE'))
|
|
64
|
+
return 'CORE';
|
|
65
|
+
if (normalized.includes('PLUS'))
|
|
66
|
+
return 'PLUS';
|
|
67
|
+
if (normalized.includes('PRIME'))
|
|
68
|
+
return 'PRIME';
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
export const aaveV4GetTokenizedVaultKey = (symbol, hubNameOrKey) => {
|
|
72
|
+
if (!symbol)
|
|
73
|
+
return null;
|
|
74
|
+
const hubKey = aaveV4GetTokenizedHubKey(hubNameOrKey);
|
|
75
|
+
if (!hubKey)
|
|
76
|
+
return null;
|
|
77
|
+
const normalizedSymbol = symbol.trim().replace(/-/g, '_');
|
|
78
|
+
return `${normalizedSymbol}_${hubKey}`;
|
|
79
|
+
};
|
|
80
|
+
export const aaveV4GetTokenizedVaultAddress = (network, symbol, hubNameOrKey) => {
|
|
81
|
+
if (network !== NetworkNumber.Eth)
|
|
82
|
+
return undefined;
|
|
83
|
+
const key = aaveV4GetTokenizedVaultKey(symbol, hubNameOrKey);
|
|
84
|
+
if (!key)
|
|
85
|
+
return undefined;
|
|
86
|
+
return AAVE_V4_TOKENIZED_SPOKES[key];
|
|
87
|
+
};
|
|
88
|
+
const AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY = Object.entries(AAVE_V4_TOKENIZED_SPOKES).reduce((acc, [k, v]) => {
|
|
89
|
+
acc[v.toLowerCase()] = k;
|
|
90
|
+
return acc;
|
|
91
|
+
}, {});
|
|
92
|
+
/**
|
|
93
|
+
* Fetches tokenization vault data for the given user via getTokenizationSpokesData.
|
|
94
|
+
* Returns parsed data including userSuppliedAssets in human-readable form for each vault.
|
|
95
|
+
*/
|
|
96
|
+
export function getAaveV4TokenizationSpokesData(provider, network, userAddress) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a;
|
|
99
|
+
const spokes = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESSES[network]) !== null && _a !== void 0 ? _a : [];
|
|
100
|
+
if (spokes.length === 0)
|
|
101
|
+
return [];
|
|
102
|
+
const client = getViemProvider(provider, network);
|
|
103
|
+
const viewContract = AaveV4ViewContractViem(client, network);
|
|
104
|
+
const raw = yield viewContract.read.getTokenizationSpokesData([spokes, userAddress]);
|
|
105
|
+
return raw.map((r, i) => {
|
|
106
|
+
var _a, _b, _c, _d, _e;
|
|
107
|
+
const vaultAddress = spokes[i];
|
|
108
|
+
const key = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY[vaultAddress.toLowerCase()]) !== null && _a !== void 0 ? _a : null;
|
|
109
|
+
const symbol = wethToEth(getAssetInfoByAddress(r.underlyingAsset, network).symbol);
|
|
110
|
+
if (symbol === '?') { // unsupported asset
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const hubKey = key ? (_b = key.split('_').pop()) !== null && _b !== void 0 ? _b : '' : '';
|
|
114
|
+
const decimals = Number((_c = r.decimals) !== null && _c !== void 0 ? _c : 18);
|
|
115
|
+
const userSuppliedAssetsRaw = (_d = r.userSuppliedAssets) !== null && _d !== void 0 ? _d : 0;
|
|
116
|
+
const userSuppliedSharesRaw = (_e = r.userSuppliedShares) !== null && _e !== void 0 ? _e : 0;
|
|
117
|
+
const userSuppliedAssetsEth = assetAmountInEth(userSuppliedAssetsRaw.toString(), symbol);
|
|
118
|
+
const userSuppliedSharesEth = assetAmountInEth(userSuppliedSharesRaw.toString(), symbol);
|
|
119
|
+
return {
|
|
120
|
+
vaultAddress,
|
|
121
|
+
key,
|
|
122
|
+
symbol,
|
|
123
|
+
hubKey,
|
|
124
|
+
userSuppliedAssetsEth,
|
|
125
|
+
userSuppliedSharesEth,
|
|
126
|
+
userSuppliedAssets: userSuppliedAssetsRaw.toString(),
|
|
127
|
+
userSuppliedShares: userSuppliedSharesRaw.toString(),
|
|
128
|
+
underlyingAsset: r.underlyingAsset,
|
|
129
|
+
spoke: r.spoke,
|
|
130
|
+
decimals,
|
|
131
|
+
};
|
|
132
|
+
}).filter(item => item != null);
|
|
133
|
+
});
|
|
134
|
+
}
|
package/esm/claiming/aaveV3.js
CHANGED
|
@@ -92,7 +92,7 @@ export function getMeritUnclaimedRewards(account_1, network_1) {
|
|
|
92
92
|
return __awaiter(this, arguments, void 0, function* (account, network, acceptMorpho = true) {
|
|
93
93
|
let data;
|
|
94
94
|
try {
|
|
95
|
-
const res = yield fetch(`https://api
|
|
95
|
+
const res = yield fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
|
|
96
96
|
data = yield res.json();
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|