@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
@@ -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 token)
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
- * Hub campaigns identify the underlying via `tokens[0]`; spoke campaigns identify the spoke via `explorerAddress`.
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 spokeKey = (spokeAddress, underlying) => `${spokeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
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 getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
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 result;
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[spokeKey(spokeAddress, underlying)] : undefined;
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
  };