@defisaver/positions-sdk 2.1.127-midnight-8-dev → 2.1.127-midnight-9-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.js +26 -10
- package/cjs/aaveV4/merkl.d.ts +2 -1
- package/cjs/aaveV4/merkl.js +42 -35
- package/cjs/config/contracts.d.ts +0 -938
- package/cjs/config/contracts.js +2 -8
- package/cjs/contracts.d.ts +0 -23433
- package/cjs/contracts.js +2 -3
- package/cjs/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/cjs/helpers/aaveV4Helpers/index.js +22 -10
- package/cjs/helpers/index.d.ts +0 -1
- package/cjs/helpers/index.js +1 -2
- package/cjs/index.d.ts +1 -2
- package/cjs/index.js +1 -3
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/markets/morphoBlue/index.d.ts +6 -0
- package/cjs/markets/morphoBlue/index.js +53 -2
- package/cjs/portfolio/discovery.d.ts +1 -1
- package/cjs/portfolio/discovery.js +1 -1
- package/cjs/portfolio/index.js +0 -32
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +3 -1
- package/cjs/staking/staking.js +1 -2
- package/cjs/types/aaveV4.d.ts +5 -0
- package/cjs/types/common.d.ts +4 -0
- package/cjs/types/common.js +6 -1
- package/cjs/types/index.d.ts +0 -1
- package/cjs/types/index.js +0 -1
- package/cjs/types/merkl.d.ts +3 -4
- package/cjs/types/morphoBlue.d.ts +3 -0
- package/cjs/types/morphoBlue.js +3 -0
- package/cjs/types/portfolio.d.ts +0 -4
- package/esm/aaveV4/index.js +27 -11
- package/esm/aaveV4/merkl.d.ts +2 -1
- package/esm/aaveV4/merkl.js +41 -35
- package/esm/config/contracts.d.ts +0 -938
- package/esm/config/contracts.js +0 -6
- package/esm/contracts.d.ts +0 -23433
- package/esm/contracts.js +0 -1
- package/esm/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/esm/helpers/aaveV4Helpers/index.js +21 -10
- package/esm/helpers/index.d.ts +0 -1
- package/esm/helpers/index.js +0 -1
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/markets/morphoBlue/index.d.ts +6 -0
- package/esm/markets/morphoBlue/index.js +48 -0
- package/esm/portfolio/discovery.d.ts +1 -1
- package/esm/portfolio/discovery.js +1 -1
- package/esm/portfolio/index.js +1 -33
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +1 -0
- package/esm/staking/staking.js +1 -2
- package/esm/types/aaveV4.d.ts +5 -0
- package/esm/types/common.d.ts +4 -0
- package/esm/types/common.js +5 -0
- package/esm/types/index.d.ts +0 -1
- package/esm/types/index.js +0 -1
- package/esm/types/merkl.d.ts +3 -4
- package/esm/types/morphoBlue.d.ts +3 -0
- package/esm/types/morphoBlue.js +3 -0
- package/esm/types/portfolio.d.ts +0 -4
- package/package.json +1 -1
- package/src/aaveV4/index.ts +29 -11
- package/src/aaveV4/merkl.ts +41 -32
- package/src/config/contracts.ts +0 -6
- package/src/contracts.ts +0 -1
- package/src/helpers/aaveV4Helpers/index.ts +22 -9
- package/src/helpers/index.ts +0 -1
- package/src/index.ts +0 -2
- package/src/markets/index.ts +0 -1
- package/src/markets/morphoBlue/index.ts +49 -1
- package/src/portfolio/discovery.ts +1 -1
- package/src/portfolio/index.ts +0 -33
- package/src/services/utils.ts +2 -0
- package/src/staking/staking.ts +1 -2
- package/src/types/aaveV4.ts +5 -0
- package/src/types/common.ts +5 -0
- package/src/types/index.ts +0 -1
- package/src/types/merkl.ts +3 -3
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +0 -4
- package/cjs/eulerV2/index.d.ts +0 -47
- package/cjs/eulerV2/index.js +0 -225
- package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
- package/cjs/helpers/eulerHelpers/index.js +0 -231
- package/cjs/markets/euler/index.d.ts +0 -8
- package/cjs/markets/euler/index.js +0 -30
- package/cjs/types/euler.d.ts +0 -153
- package/cjs/types/euler.js +0 -14
- package/esm/eulerV2/index.d.ts +0 -47
- package/esm/eulerV2/index.js +0 -215
- package/esm/helpers/eulerHelpers/index.d.ts +0 -22
- package/esm/helpers/eulerHelpers/index.js +0 -218
- package/esm/markets/euler/index.d.ts +0 -8
- package/esm/markets/euler/index.js +0 -24
- package/esm/types/euler.d.ts +0 -153
- package/esm/types/euler.js +0 -11
- package/src/eulerV2/index.ts +0 -331
- package/src/helpers/eulerHelpers/index.ts +0 -232
- package/src/markets/euler/index.ts +0 -27
- package/src/types/euler.ts +0 -178
package/cjs/types/portfolio.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
|
3
3
|
import { EthAddress } from './common';
|
|
4
4
|
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
5
|
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
-
import { EulerV2PositionData, EulerV2Versions } from './euler';
|
|
7
6
|
import { FluidVaultData } from './fluid';
|
|
8
7
|
import { LiquityTroveInfo } from './liquity';
|
|
9
8
|
import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
@@ -31,9 +30,6 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
31
30
|
spark: {
|
|
32
31
|
[key in SparkVersions]?: PortfolioProtocolData<SparkPositionData>;
|
|
33
32
|
};
|
|
34
|
-
eulerV2: {
|
|
35
|
-
[key in EulerV2Versions]?: Record<EthAddress, PortfolioProtocolData<EulerV2PositionData>>;
|
|
36
|
-
};
|
|
37
33
|
maker: {
|
|
38
34
|
[key: string]: PortfolioProtocolData<CdpData>;
|
|
39
35
|
};
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getViemProvider } from '../services/viem';
|
|
|
13
13
|
import { IncentiveKind, } from '../types';
|
|
14
14
|
import { AaveV4ViewContractViem } from '../contracts';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
|
-
import { isMaxUint, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
16
|
+
import { isMaxUint, shortenAddress, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
17
17
|
import { aaveV4GetAggregatedPositionData, calcUserRiskPremiumBps } from '../helpers/aaveV4Helpers';
|
|
18
18
|
import { findAaveV4SpokeByAddress, getAaveV4HubByAddress } from '../markets/aaveV4';
|
|
19
19
|
import { aprToApy } from '../moneymarket';
|
|
@@ -39,16 +39,16 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
|
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f;
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
43
|
const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
|
|
44
44
|
// `@defisaver/tokens` returns a placeholder ('?', decimals NaN) when the underlying is not in the
|
|
45
45
|
// tokens package. Flag it so consumers can render it read-only instead of feeding NaN into amounts.
|
|
46
46
|
const isUnsupported = assetInfo.symbol === '?';
|
|
47
47
|
const symbol = wethToEth(assetInfo.symbol);
|
|
48
|
+
// The hub registry only provides display metadata — a hub missing from it (newly deployed by
|
|
49
|
+
// Aave, SDK not yet updated) must not prevent the reserve from loading, so fall back to a
|
|
50
|
+
// generated label instead of failing.
|
|
48
51
|
const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
|
|
49
|
-
if (!hubInfo) {
|
|
50
|
-
throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
|
|
51
|
-
}
|
|
52
52
|
const isStakingAsset = STAKING_ASSETS.includes(symbol);
|
|
53
53
|
const supplyIncentives = [];
|
|
54
54
|
const borrowIncentives = [];
|
|
@@ -108,8 +108,8 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
108
108
|
decimals: reserveAsset.decimals,
|
|
109
109
|
isUnsupported,
|
|
110
110
|
underlying: reserveAsset.underlying,
|
|
111
|
-
hub: hubInfo.address,
|
|
112
|
-
hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label
|
|
111
|
+
hub: (_g = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.address) !== null && _g !== void 0 ? _g : reserveAsset.hub,
|
|
112
|
+
hubName: (_h = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label) !== null && _h !== void 0 ? _h : `Hub ${shortenAddress(reserveAsset.hub)}`,
|
|
113
113
|
assetId: reserveAsset.assetId,
|
|
114
114
|
reserveId,
|
|
115
115
|
paused: reserveAsset.paused,
|
|
@@ -147,14 +147,30 @@ export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
|
147
147
|
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
148
148
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
149
149
|
const hubsData = {};
|
|
150
|
+
const loadHubData = (hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress);
|
|
152
|
+
});
|
|
153
|
+
// market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
|
|
154
|
+
// failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
|
|
150
155
|
const [spokeData, merklCampaigns] = yield Promise.all([
|
|
151
156
|
viewContract.read.getSpokeDataFull([market.address]),
|
|
152
157
|
getAaveV4MerkleCampaigns(network),
|
|
153
|
-
...market.hubs.map((hubAddress) =>
|
|
154
|
-
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
155
|
-
})),
|
|
158
|
+
...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
|
|
156
159
|
]);
|
|
157
|
-
|
|
160
|
+
// The on-chain reserves are the source of truth for which hubs the spoke uses — fetch any hub
|
|
161
|
+
// the prefetch didn't cover, so an asset listed from a hub unknown to the SDK can't break the spoke.
|
|
162
|
+
const missingHubs = [...new Set(spokeData[1].map((reserveAsset) => reserveAsset.hub.toLowerCase()))]
|
|
163
|
+
.filter((hubAddress) => !hubsData[hubAddress]);
|
|
164
|
+
yield Promise.all(missingHubs.map(loadHubData));
|
|
165
|
+
const reserveAssetsArray = (yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a;
|
|
167
|
+
const hubAsset = (_a = hubsData[reserveAssetOnChain.hub.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.assets[reserveAssetOnChain.assetId];
|
|
168
|
+
// A reserve whose hub-side asset data can't be resolved is skipped instead of failing the
|
|
169
|
+
// whole spoke (position math degrades for that one asset only).
|
|
170
|
+
if (!hubAsset)
|
|
171
|
+
return null;
|
|
172
|
+
return formatReserveAsset(reserveAssetOnChain, hubAsset, index, +spokeData[0].oracleDecimals.toString(), network);
|
|
173
|
+
})))).filter((asset) => asset !== null);
|
|
158
174
|
const enrichedAssets = reserveAssetsArray.map((asset) => attachAaveV4MerklIncentives(asset, market.address, merklCampaigns));
|
|
159
175
|
return {
|
|
160
176
|
assetsData: enrichedAssets.reduce((acc, reserveAsset) => {
|
package/esm/aaveV4/merkl.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AaveV4MerklRewardMap, AaveV4ReserveAssetData, NetworkNumber } from '../types';
|
|
1
|
+
import { AaveV4MerklRewardMap, AaveV4ReserveAssetData, MerklOpportunity, NetworkNumber } from '../types';
|
|
2
|
+
export declare const buildAaveV4MerklRewardMap: (opportunities: MerklOpportunity[], chainId: NetworkNumber) => AaveV4MerklRewardMap;
|
|
2
3
|
export declare const getAaveV4MerkleCampaigns: (chainId: NetworkNumber) => Promise<AaveV4MerklRewardMap>;
|
|
3
4
|
/**
|
|
4
5
|
* Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
|
package/esm/aaveV4/merkl.js
CHANGED
|
@@ -9,14 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
11
|
import { LONGER_TIMEOUT } from '../services/utils';
|
|
12
|
-
import { IncentiveKind, OpportunityAction, OpportunityStatus, } from '../types';
|
|
12
|
+
import { IncentiveKind, IncentiveSide, OpportunityAction, OpportunityStatus, } from '../types';
|
|
13
13
|
/**
|
|
14
14
|
* Merkl tags Aave V4 reward campaigns by scope via the `type` field:
|
|
15
|
-
* - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per underlying
|
|
15
|
+
* - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per hub contract + underlying)
|
|
16
16
|
* - AAVE_V4_SPOKE_SUPPLY / AAVE_V4_SPOKE_BORROW → reward tied to a spoke (matched per spoke contract + underlying)
|
|
17
|
-
*
|
|
17
|
+
* Campaigns identify the underlying via `tokens[0]` and the scoping contract (the hub or spoke) via
|
|
18
|
+
* `explorerAddress`. The same underlying exists on several hubs (e.g. USDC on Prime and Paxos), so a
|
|
19
|
+
* hub campaign matched by underlying alone would leak onto every hub's reserves — a campaign whose
|
|
20
|
+
* `explorerAddress` isn't a contract any fetched reserve points to simply never matches.
|
|
18
21
|
*/
|
|
19
|
-
const
|
|
22
|
+
const scopeKey = (scopeAddress, underlying) => `${scopeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
|
|
20
23
|
const buildIncentive = (opportunity) => {
|
|
21
24
|
var _a, _b, _c, _d, _e;
|
|
22
25
|
const rewardToken = (_c = (_b = (_a = opportunity.rewardsRecord) === null || _a === void 0 ? void 0 : _a.breakdowns) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.token;
|
|
@@ -28,8 +31,37 @@ const buildIncentive = (opportunity) => {
|
|
|
28
31
|
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
29
32
|
};
|
|
30
33
|
};
|
|
31
|
-
export const
|
|
34
|
+
export const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
|
|
32
35
|
const result = { hub: {}, spoke: {} };
|
|
36
|
+
opportunities
|
|
37
|
+
.filter((o) => o.chainId === chainId)
|
|
38
|
+
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
39
|
+
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
40
|
+
.forEach((o) => {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const underlying = (_c = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
43
|
+
if (!underlying)
|
|
44
|
+
return;
|
|
45
|
+
const scopeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
46
|
+
if (!scopeAddress)
|
|
47
|
+
return;
|
|
48
|
+
const side = o.action === OpportunityAction.BORROW ? IncentiveSide.Borrow : IncentiveSide.Supply;
|
|
49
|
+
const incentive = buildIncentive(o);
|
|
50
|
+
const key = scopeKey(scopeAddress, underlying);
|
|
51
|
+
if (o.type.includes('HUB')) {
|
|
52
|
+
if (!result.hub[key])
|
|
53
|
+
result.hub[key] = {};
|
|
54
|
+
result.hub[key][side] = incentive;
|
|
55
|
+
}
|
|
56
|
+
else if (o.type.includes('SPOKE')) {
|
|
57
|
+
if (!result.spoke[key])
|
|
58
|
+
result.spoke[key] = {};
|
|
59
|
+
result.spoke[key][side] = incentive;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
65
|
try {
|
|
34
66
|
const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave&type=AAVE_V4_HUB_SUPPLY,AAVE_V4_HUB_BORROW,AAVE_V4_SPOKE_SUPPLY,AAVE_V4_SPOKE_BORROW', {
|
|
35
67
|
signal: AbortSignal.timeout(LONGER_TIMEOUT),
|
|
@@ -37,37 +69,11 @@ export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, v
|
|
|
37
69
|
if (!res.ok)
|
|
38
70
|
throw new Error('Failed to fetch Aave V4 Merkle campaigns');
|
|
39
71
|
const opportunities = yield res.json();
|
|
40
|
-
opportunities
|
|
41
|
-
.filter((o) => o.chainId === chainId)
|
|
42
|
-
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
43
|
-
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
44
|
-
.forEach((o) => {
|
|
45
|
-
var _a, _b, _c, _d;
|
|
46
|
-
const underlying = (_c = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
47
|
-
if (!underlying)
|
|
48
|
-
return;
|
|
49
|
-
const side = o.action === OpportunityAction.BORROW ? 'borrow' : 'supply';
|
|
50
|
-
const incentive = buildIncentive(o);
|
|
51
|
-
if (o.type.includes('HUB')) {
|
|
52
|
-
if (!result.hub[underlying])
|
|
53
|
-
result.hub[underlying] = {};
|
|
54
|
-
result.hub[underlying][side] = incentive;
|
|
55
|
-
}
|
|
56
|
-
else if (o.type.includes('SPOKE')) {
|
|
57
|
-
const spokeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
58
|
-
if (!spokeAddress)
|
|
59
|
-
return;
|
|
60
|
-
const key = spokeKey(spokeAddress, underlying);
|
|
61
|
-
if (!result.spoke[key])
|
|
62
|
-
result.spoke[key] = {};
|
|
63
|
-
result.spoke[key][side] = incentive;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return result;
|
|
72
|
+
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
67
73
|
}
|
|
68
74
|
catch (e) {
|
|
69
75
|
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
|
70
|
-
return
|
|
76
|
+
return { hub: {}, spoke: {} };
|
|
71
77
|
}
|
|
72
78
|
});
|
|
73
79
|
/**
|
|
@@ -79,7 +85,7 @@ export const attachAaveV4MerklIncentives = (asset, spokeAddress, campaigns) => {
|
|
|
79
85
|
const underlying = (_a = asset.underlying) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
80
86
|
const baseSupply = asset.supplyIncentives || [];
|
|
81
87
|
const baseBorrow = asset.borrowIncentives || [];
|
|
82
|
-
const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[
|
|
83
|
-
const hubScoped = underlying ? campaigns.hub[underlying] : undefined;
|
|
88
|
+
const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[scopeKey(spokeAddress, underlying)] : undefined;
|
|
89
|
+
const hubScoped = (asset.hub && underlying) ? campaigns.hub[scopeKey(asset.hub, underlying)] : undefined;
|
|
84
90
|
return Object.assign(Object.assign({}, asset), { spokeSupplyIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.supply) ? [...baseSupply, spokeScoped.supply] : baseSupply, spokeBorrowIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.borrow) ? [...baseBorrow, spokeScoped.borrow] : baseBorrow, hubSupplyIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.supply) ? [...baseSupply, hubScoped.supply] : baseSupply, hubBorrowIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.borrow) ? [...baseBorrow, hubScoped.borrow] : baseBorrow });
|
|
85
91
|
};
|