@defisaver/positions-sdk 2.1.137 → 2.1.139

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 (94) hide show
  1. package/cjs/aaveV4/index.js +26 -10
  2. package/cjs/aaveV4/merkl.d.ts +2 -1
  3. package/cjs/aaveV4/merkl.js +42 -35
  4. package/cjs/config/contracts.d.ts +0 -938
  5. package/cjs/config/contracts.js +1 -8
  6. package/cjs/contracts.d.ts +0 -23433
  7. package/cjs/contracts.js +2 -3
  8. package/cjs/helpers/aaveV4Helpers/index.d.ts +7 -1
  9. package/cjs/helpers/aaveV4Helpers/index.js +22 -10
  10. package/cjs/helpers/index.d.ts +0 -1
  11. package/cjs/helpers/index.js +1 -2
  12. package/cjs/index.d.ts +1 -2
  13. package/cjs/index.js +1 -3
  14. package/cjs/markets/index.d.ts +0 -1
  15. package/cjs/markets/index.js +1 -3
  16. package/cjs/portfolio/discovery.d.ts +1 -1
  17. package/cjs/portfolio/discovery.js +1 -1
  18. package/cjs/portfolio/index.js +0 -32
  19. package/cjs/services/utils.d.ts +1 -0
  20. package/cjs/services/utils.js +3 -1
  21. package/cjs/staking/staking.js +1 -2
  22. package/cjs/types/aaveV4.d.ts +5 -0
  23. package/cjs/types/common.d.ts +4 -0
  24. package/cjs/types/common.js +6 -1
  25. package/cjs/types/index.d.ts +0 -1
  26. package/cjs/types/index.js +0 -1
  27. package/cjs/types/merkl.d.ts +3 -4
  28. package/cjs/types/portfolio.d.ts +0 -4
  29. package/esm/aaveV4/index.js +27 -11
  30. package/esm/aaveV4/merkl.d.ts +2 -1
  31. package/esm/aaveV4/merkl.js +41 -35
  32. package/esm/config/contracts.d.ts +0 -938
  33. package/esm/config/contracts.js +0 -6
  34. package/esm/contracts.d.ts +0 -23433
  35. package/esm/contracts.js +0 -1
  36. package/esm/helpers/aaveV4Helpers/index.d.ts +7 -1
  37. package/esm/helpers/aaveV4Helpers/index.js +21 -10
  38. package/esm/helpers/index.d.ts +0 -1
  39. package/esm/helpers/index.js +0 -1
  40. package/esm/index.d.ts +1 -2
  41. package/esm/index.js +1 -2
  42. package/esm/markets/index.d.ts +0 -1
  43. package/esm/markets/index.js +0 -1
  44. package/esm/portfolio/discovery.d.ts +1 -1
  45. package/esm/portfolio/discovery.js +1 -1
  46. package/esm/portfolio/index.js +1 -33
  47. package/esm/services/utils.d.ts +1 -0
  48. package/esm/services/utils.js +1 -0
  49. package/esm/staking/staking.js +1 -2
  50. package/esm/types/aaveV4.d.ts +5 -0
  51. package/esm/types/common.d.ts +4 -0
  52. package/esm/types/common.js +5 -0
  53. package/esm/types/index.d.ts +0 -1
  54. package/esm/types/index.js +0 -1
  55. package/esm/types/merkl.d.ts +3 -4
  56. package/esm/types/portfolio.d.ts +0 -4
  57. package/package.json +1 -1
  58. package/src/aaveV4/index.ts +29 -11
  59. package/src/aaveV4/merkl.ts +41 -32
  60. package/src/config/contracts.ts +0 -6
  61. package/src/contracts.ts +0 -1
  62. package/src/helpers/aaveV4Helpers/index.ts +22 -9
  63. package/src/helpers/index.ts +0 -1
  64. package/src/index.ts +0 -2
  65. package/src/markets/index.ts +0 -1
  66. package/src/portfolio/discovery.ts +1 -1
  67. package/src/portfolio/index.ts +0 -33
  68. package/src/services/utils.ts +2 -0
  69. package/src/staking/staking.ts +1 -2
  70. package/src/types/aaveV4.ts +5 -0
  71. package/src/types/common.ts +5 -0
  72. package/src/types/index.ts +0 -1
  73. package/src/types/merkl.ts +3 -3
  74. package/src/types/portfolio.ts +0 -4
  75. package/cjs/eulerV2/index.d.ts +0 -47
  76. package/cjs/eulerV2/index.js +0 -225
  77. package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
  78. package/cjs/helpers/eulerHelpers/index.js +0 -231
  79. package/cjs/markets/euler/index.d.ts +0 -8
  80. package/cjs/markets/euler/index.js +0 -30
  81. package/cjs/types/euler.d.ts +0 -153
  82. package/cjs/types/euler.js +0 -14
  83. package/esm/eulerV2/index.d.ts +0 -47
  84. package/esm/eulerV2/index.js +0 -215
  85. package/esm/helpers/eulerHelpers/index.d.ts +0 -22
  86. package/esm/helpers/eulerHelpers/index.js +0 -218
  87. package/esm/markets/euler/index.d.ts +0 -8
  88. package/esm/markets/euler/index.js +0 -24
  89. package/esm/types/euler.d.ts +0 -153
  90. package/esm/types/euler.js +0 -11
  91. package/src/eulerV2/index.ts +0 -331
  92. package/src/helpers/eulerHelpers/index.ts +0 -232
  93. package/src/markets/euler/index.ts +0 -27
  94. package/src/types/euler.ts +0 -178
@@ -84,16 +84,16 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
84
84
  };
85
85
  });
86
86
  const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
87
- var _a, _b, _c, _d, _e, _f;
87
+ var _a, _b, _c, _d, _e, _f, _g, _h;
88
88
  const assetInfo = (0, tokens_1.getAssetInfoByAddress)(reserveAsset.underlying, network);
89
89
  // `@defisaver/tokens` returns a placeholder ('?', decimals NaN) when the underlying is not in the
90
90
  // tokens package. Flag it so consumers can render it read-only instead of feeding NaN into amounts.
91
91
  const isUnsupported = assetInfo.symbol === '?';
92
92
  const symbol = (0, utils_1.wethToEth)(assetInfo.symbol);
93
+ // The hub registry only provides display metadata — a hub missing from it (newly deployed by
94
+ // Aave, SDK not yet updated) must not prevent the reserve from loading, so fall back to a
95
+ // generated label instead of failing.
93
96
  const hubInfo = (0, aaveV4_1.getAaveV4HubByAddress)(network, reserveAsset.hub);
94
- if (!hubInfo) {
95
- throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
96
- }
97
97
  const isStakingAsset = staking_1.STAKING_ASSETS.includes(symbol);
98
98
  const supplyIncentives = [];
99
99
  const borrowIncentives = [];
@@ -153,8 +153,8 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
153
153
  decimals: reserveAsset.decimals,
154
154
  isUnsupported,
155
155
  underlying: reserveAsset.underlying,
156
- hub: hubInfo.address,
157
- hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label,
156
+ hub: (_g = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.address) !== null && _g !== void 0 ? _g : reserveAsset.hub,
157
+ hubName: (_h = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label) !== null && _h !== void 0 ? _h : `Hub ${(0, utils_1.shortenAddress)(reserveAsset.hub)}`,
158
158
  assetId: reserveAsset.assetId,
159
159
  reserveId,
160
160
  paused: reserveAsset.paused,
@@ -192,14 +192,30 @@ function _getAaveV4SpokeData(provider_1, network_1, market_1) {
192
192
  return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
193
193
  const viewContract = (0, contracts_1.AaveV4ViewContractViem)(provider, network, blockNumber);
194
194
  const hubsData = {};
195
+ const loadHubData = (hubAddress) => __awaiter(this, void 0, void 0, function* () {
196
+ hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress);
197
+ });
198
+ // market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
199
+ // failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
195
200
  const [spokeData, merklCampaigns] = yield Promise.all([
196
201
  viewContract.read.getSpokeDataFull([market.address]),
197
202
  (0, merkl_1.getAaveV4MerkleCampaigns)(network),
198
- ...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
199
- hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
200
- })),
203
+ ...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
201
204
  ]);
202
- 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); })));
205
+ // The on-chain reserves are the source of truth for which hubs the spoke uses fetch any hub
206
+ // the prefetch didn't cover, so an asset listed from a hub unknown to the SDK can't break the spoke.
207
+ const missingHubs = [...new Set(spokeData[1].map((reserveAsset) => reserveAsset.hub.toLowerCase()))]
208
+ .filter((hubAddress) => !hubsData[hubAddress]);
209
+ yield Promise.all(missingHubs.map(loadHubData));
210
+ const reserveAssetsArray = (yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () {
211
+ var _a;
212
+ const hubAsset = (_a = hubsData[reserveAssetOnChain.hub.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.assets[reserveAssetOnChain.assetId];
213
+ // A reserve whose hub-side asset data can't be resolved is skipped instead of failing the
214
+ // whole spoke (position math degrades for that one asset only).
215
+ if (!hubAsset)
216
+ return null;
217
+ return formatReserveAsset(reserveAssetOnChain, hubAsset, index, +spokeData[0].oracleDecimals.toString(), network);
218
+ })))).filter((asset) => asset !== null);
203
219
  const enrichedAssets = reserveAssetsArray.map((asset) => (0, merkl_1.attachAaveV4MerklIncentives)(asset, market.address, merklCampaigns));
204
220
  return {
205
221
  assetsData: enrichedAssets.reduce((acc, reserveAsset) => {
@@ -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
@@ -9,17 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.attachAaveV4MerklIncentives = exports.getAaveV4MerkleCampaigns = void 0;
12
+ exports.attachAaveV4MerklIncentives = exports.getAaveV4MerkleCampaigns = exports.buildAaveV4MerklRewardMap = void 0;
13
13
  const moneymarket_1 = require("../moneymarket");
14
14
  const utils_1 = require("../services/utils");
15
15
  const types_1 = require("../types");
16
16
  /**
17
17
  * Merkl tags Aave V4 reward campaigns by scope via the `type` field:
18
- * - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per underlying token)
18
+ * - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per hub contract + underlying)
19
19
  * - AAVE_V4_SPOKE_SUPPLY / AAVE_V4_SPOKE_BORROW → reward tied to a spoke (matched per spoke contract + underlying)
20
- * Hub campaigns identify the underlying via `tokens[0]`; spoke campaigns identify the spoke via `explorerAddress`.
20
+ * Campaigns identify the underlying via `tokens[0]` and the scoping contract (the hub or spoke) via
21
+ * `explorerAddress`. The same underlying exists on several hubs (e.g. USDC on Prime and Paxos), so a
22
+ * hub campaign matched by underlying alone would leak onto every hub's reserves — a campaign whose
23
+ * `explorerAddress` isn't a contract any fetched reserve points to simply never matches.
21
24
  */
22
- const spokeKey = (spokeAddress, underlying) => `${spokeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
25
+ const scopeKey = (scopeAddress, underlying) => `${scopeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
23
26
  const buildIncentive = (opportunity) => {
24
27
  var _a, _b, _c, _d, _e;
25
28
  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;
@@ -31,8 +34,38 @@ const buildIncentive = (opportunity) => {
31
34
  description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
32
35
  };
33
36
  };
34
- const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
35
38
  const result = { hub: {}, spoke: {} };
39
+ opportunities
40
+ .filter((o) => o.chainId === chainId)
41
+ .filter((o) => o.status === types_1.OpportunityStatus.LIVE)
42
+ .filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
43
+ .forEach((o) => {
44
+ var _a, _b, _c, _d;
45
+ 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();
46
+ if (!underlying)
47
+ return;
48
+ const scopeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
49
+ if (!scopeAddress)
50
+ return;
51
+ const side = o.action === types_1.OpportunityAction.BORROW ? types_1.IncentiveSide.Borrow : types_1.IncentiveSide.Supply;
52
+ const incentive = buildIncentive(o);
53
+ const key = scopeKey(scopeAddress, underlying);
54
+ if (o.type.includes('HUB')) {
55
+ if (!result.hub[key])
56
+ result.hub[key] = {};
57
+ result.hub[key][side] = incentive;
58
+ }
59
+ else if (o.type.includes('SPOKE')) {
60
+ if (!result.spoke[key])
61
+ result.spoke[key] = {};
62
+ result.spoke[key][side] = incentive;
63
+ }
64
+ });
65
+ return result;
66
+ };
67
+ exports.buildAaveV4MerklRewardMap = buildAaveV4MerklRewardMap;
68
+ const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
36
69
  try {
37
70
  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', {
38
71
  signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
@@ -40,37 +73,11 @@ const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0,
40
73
  if (!res.ok)
41
74
  throw new Error('Failed to fetch Aave V4 Merkle campaigns');
42
75
  const opportunities = yield res.json();
43
- opportunities
44
- .filter((o) => o.chainId === chainId)
45
- .filter((o) => o.status === types_1.OpportunityStatus.LIVE)
46
- .filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
47
- .forEach((o) => {
48
- var _a, _b, _c, _d;
49
- 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();
50
- if (!underlying)
51
- return;
52
- const side = o.action === types_1.OpportunityAction.BORROW ? 'borrow' : 'supply';
53
- const incentive = buildIncentive(o);
54
- if (o.type.includes('HUB')) {
55
- if (!result.hub[underlying])
56
- result.hub[underlying] = {};
57
- result.hub[underlying][side] = incentive;
58
- }
59
- else if (o.type.includes('SPOKE')) {
60
- const spokeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
61
- if (!spokeAddress)
62
- return;
63
- const key = spokeKey(spokeAddress, underlying);
64
- if (!result.spoke[key])
65
- result.spoke[key] = {};
66
- result.spoke[key][side] = incentive;
67
- }
68
- });
69
- return result;
76
+ return (0, exports.buildAaveV4MerklRewardMap)(opportunities, chainId);
70
77
  }
71
78
  catch (e) {
72
79
  console.error('Failed to fetch Aave V4 Merkle campaigns', e);
73
- return result;
80
+ return { hub: {}, spoke: {} };
74
81
  }
75
82
  });
76
83
  exports.getAaveV4MerkleCampaigns = getAaveV4MerkleCampaigns;
@@ -83,8 +90,8 @@ const attachAaveV4MerklIncentives = (asset, spokeAddress, campaigns) => {
83
90
  const underlying = (_a = asset.underlying) === null || _a === void 0 ? void 0 : _a.toLowerCase();
84
91
  const baseSupply = asset.supplyIncentives || [];
85
92
  const baseBorrow = asset.borrowIncentives || [];
86
- const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[spokeKey(spokeAddress, underlying)] : undefined;
87
- const hubScoped = underlying ? campaigns.hub[underlying] : undefined;
93
+ const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[scopeKey(spokeAddress, underlying)] : undefined;
94
+ const hubScoped = (asset.hub && underlying) ? campaigns.hub[scopeKey(asset.hub, underlying)] : undefined;
88
95
  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 });
89
96
  };
90
97
  exports.attachAaveV4MerklIncentives = attachAaveV4MerklIncentives;