@defisaver/positions-sdk 2.1.104 → 2.1.105

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 (37) hide show
  1. package/cjs/claiming/aaveV3.d.ts +1 -1
  2. package/cjs/claiming/aaveV3.js +3 -4
  3. package/cjs/claiming/index.d.ts +1 -2
  4. package/cjs/claiming/index.js +1 -3
  5. package/cjs/config/contracts.d.ts +0 -214
  6. package/cjs/config/contracts.js +1 -6
  7. package/cjs/helpers/morphoBlueHelpers/index.d.ts +0 -1
  8. package/cjs/helpers/morphoBlueHelpers/index.js +27 -32
  9. package/cjs/portfolio/index.js +0 -27
  10. package/cjs/types/claiming.d.ts +1 -13
  11. package/cjs/types/claiming.js +0 -2
  12. package/cjs/types/morphoBlue.d.ts +2 -3
  13. package/esm/claiming/aaveV3.d.ts +1 -1
  14. package/esm/claiming/aaveV3.js +3 -4
  15. package/esm/claiming/index.d.ts +1 -2
  16. package/esm/claiming/index.js +1 -2
  17. package/esm/config/contracts.d.ts +0 -214
  18. package/esm/config/contracts.js +0 -4
  19. package/esm/helpers/morphoBlueHelpers/index.d.ts +0 -1
  20. package/esm/helpers/morphoBlueHelpers/index.js +27 -31
  21. package/esm/portfolio/index.js +0 -27
  22. package/esm/types/claiming.d.ts +1 -13
  23. package/esm/types/claiming.js +0 -2
  24. package/esm/types/morphoBlue.d.ts +2 -3
  25. package/package.json +1 -1
  26. package/src/claiming/aaveV3.ts +2 -3
  27. package/src/claiming/index.ts +0 -2
  28. package/src/config/contracts.ts +0 -4
  29. package/src/helpers/morphoBlueHelpers/index.ts +29 -32
  30. package/src/portfolio/index.ts +0 -25
  31. package/src/types/claiming.ts +0 -15
  32. package/src/types/morphoBlue.ts +2 -3
  33. package/cjs/claiming/morphoBlue.d.ts +0 -5
  34. package/cjs/claiming/morphoBlue.js +0 -113
  35. package/esm/claiming/morphoBlue.d.ts +0 -5
  36. package/esm/claiming/morphoBlue.js +0 -105
  37. package/src/claiming/morphoBlue.ts +0 -119
@@ -1264,10 +1264,6 @@ export const SparkRewardsController = {
1264
1264
  }
1265
1265
  }
1266
1266
  } as const;
1267
- export const MorphoDistributor = {
1268
- "abi": [{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"uint256","name":"initialTimelock","type":"uint256"},{"internalType":"bytes32","name":"initialRoot","type":"bytes32"},{"internalType":"bytes32","name":"initialIpfsHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"acceptRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"reward","type":"address"},{"internalType":"uint256","name":"claimable","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"claim","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"reward","type":"address"}],"name":"claimed","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ipfsHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isUpdater","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingRoot","outputs":[{"internalType":"bytes32","name":"root","type":"bytes32"},{"internalType":"bytes32","name":"ipfsHash","type":"bytes32"},{"internalType":"uint256","name":"validAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revokePendingRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newRoot","type":"bytes32"},{"internalType":"bytes32","name":"newIpfsHash","type":"bytes32"}],"name":"setRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"updater","type":"address"},{"internalType":"bool","name":"active","type":"bool"}],"name":"setRootUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newTimelock","type":"uint256"}],"name":"setTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newRoot","type":"bytes32"},{"internalType":"bytes32","name":"newIpfsHash","type":"bytes32"}],"name":"submitRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timelock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
1269
- "networks": {}
1270
- } as const;
1271
1267
  export const AaveRewardsController = {
1272
1268
  "abi": [{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"address","name":"user","type":"address"}],"name":"getAllUserRewards","outputs":[{"internalType":"address[]","name":"rewardsList","type":"address[]"},{"internalType":"uint256[]","name":"unclaimedAmounts","type":"uint256[]"}],"stateMutability":"view","type":"function"}],
1273
1269
  "networks": {
@@ -146,12 +146,14 @@ export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMark
146
146
  return { borrowRate, supplyRate };
147
147
  };
148
148
 
149
- const API_URL = 'https://blue-api.morpho.org/graphql';
149
+ const API_URL = 'https://api.morpho.org/graphql';
150
+ // Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
151
+ const ACRM_TARGET_UTILIZATION = '900000000000000000';
152
+
150
153
  const MARKET_QUERY = `
151
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
152
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
154
+ query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
155
+ marketById(marketId: $marketId, chainId: $chainId) {
153
156
  reallocatableLiquidityAssets
154
- targetBorrowUtilization
155
157
  loanAsset {
156
158
  address
157
159
  decimals
@@ -168,8 +170,8 @@ const MARKET_QUERY = `
168
170
  address
169
171
  name
170
172
  }
171
- allocationMarket {
172
- uniqueKey
173
+ withdrawMarket {
174
+ marketId
173
175
  loanAsset {
174
176
  address
175
177
  }
@@ -193,15 +195,15 @@ const MARKET_QUERY = `
193
195
  address
194
196
  }
195
197
  irmAddress
196
- lltv
198
+ lltv
197
199
  }
198
200
  }
199
201
  `;
200
202
 
201
203
  const REWARDS_QUERY = `
202
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
203
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
204
- uniqueKey
204
+ query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
205
+ marketById(marketId: $marketId, chainId: $chainId) {
206
+ marketId
205
207
  state {
206
208
  rewards {
207
209
  amountPerSuppliedToken
@@ -230,19 +232,19 @@ export const getReallocatableLiquidity = async (marketId: string, network: Netwo
230
232
  headers: { 'Content-Type': 'application/json' },
231
233
  body: JSON.stringify({
232
234
  query: MARKET_QUERY,
233
- variables: { uniqueKey: marketId, chainId: network },
235
+ variables: { marketId, chainId: network },
234
236
  }),
235
237
  signal: AbortSignal.timeout(LONGER_TIMEOUT),
236
238
  });
237
239
 
238
- const data: { data: { marketByUniqueKey: MorphoBlueRealloactionMarketData } } = await response.json();
239
- const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketByUniqueKey;
240
+ const data: { data: { marketById: MorphoBlueRealloactionMarketData } } = await response.json();
241
+ const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketById;
240
242
 
241
243
  if (!marketData) throw new Error('Market data not found');
242
244
 
243
245
  return {
244
246
  reallocatableLiquidity: marketData.reallocatableLiquidityAssets,
245
- targetBorrowUtilization: marketData.targetBorrowUtilization,
247
+ targetBorrowUtilization: ACRM_TARGET_UTILIZATION,
246
248
  };
247
249
  } catch (error) {
248
250
  console.error('External API Failure: Morpho blue reallocatable liquidity', error);
@@ -295,13 +297,13 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
295
297
  headers: { 'Content-Type': 'application/json' },
296
298
  body: JSON.stringify({
297
299
  query: MARKET_QUERY,
298
- variables: { uniqueKey: marketId, chainId: network },
300
+ variables: { marketId, chainId: network },
299
301
  }),
300
302
  signal: AbortSignal.timeout(LONGER_TIMEOUT),
301
303
  });
302
304
 
303
- const data: { data: { marketByUniqueKey: MorphoBlueRealloactionMarketData } } = await response.json();
304
- const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketByUniqueKey;
305
+ const data: { data: { marketById: MorphoBlueRealloactionMarketData } } = await response.json();
306
+ const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketById;
305
307
 
306
308
  if (!marketData) throw new Error('Market data not found');
307
309
 
@@ -315,9 +317,9 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
315
317
  const newUtil = new Dec(newTotalBorrowAssets).div(totalSupplyWei).toString();
316
318
  const newUtilScaled = new Dec(newUtil).mul(1e18).toString();
317
319
 
318
- if (new Dec(newUtilScaled).lt(marketData.targetBorrowUtilization)) return { vaults: [], withdrawals: [] };
320
+ if (new Dec(newUtilScaled).lt(ACRM_TARGET_UTILIZATION)) return { vaults: [], withdrawals: [] };
319
321
 
320
- const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, totalBorrowWei, totalSupplyWei, marketData.targetBorrowUtilization, marketData.reallocatableLiquidityAssets);
322
+ const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, totalBorrowWei, totalSupplyWei, ACRM_TARGET_UTILIZATION, marketData.reallocatableLiquidityAssets);
321
323
 
322
324
  const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce(
323
325
  (acc: Record<string, string>, item: MorphoBluePublicAllocatorItem) => {
@@ -348,14 +350,14 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
348
350
  totalReallocated = new Dec(totalReallocated).add(amountToTake).toString();
349
351
  const withdrawal: [string[], string, string] = [
350
352
  [
351
- item.allocationMarket.loanAsset.address,
352
- item.allocationMarket.collateralAsset?.address,
353
- item.allocationMarket.oracle?.address,
354
- item.allocationMarket.irmAddress,
355
- item.allocationMarket.lltv,
353
+ item.withdrawMarket.loanAsset.address,
354
+ item.withdrawMarket.collateralAsset?.address,
355
+ item.withdrawMarket.oracle?.address,
356
+ item.withdrawMarket.irmAddress,
357
+ item.withdrawMarket.lltv,
356
358
  ],
357
359
  amountToTake.toString(),
358
- item.allocationMarket.uniqueKey,
360
+ item.withdrawMarket.marketId,
359
361
  ];
360
362
  if (!withdrawalsPerVault[vaultAddress]) {
361
363
  withdrawalsPerVault[vaultAddress] = [];
@@ -386,12 +388,12 @@ export const getRewardsForMarket = async (marketId: string, network: NetworkNumb
386
388
  headers: { 'Content-Type': 'application/json' },
387
389
  body: JSON.stringify({
388
390
  query: REWARDS_QUERY,
389
- variables: { uniqueKey: marketId, chainId: network },
391
+ variables: { marketId, chainId: network },
390
392
  }),
391
393
  });
392
394
 
393
395
  const data = await response.json();
394
- const marketData = data?.data?.marketByUniqueKey;
396
+ const marketData = data?.data?.marketById;
395
397
  if (!marketData) throw new Error('Market data not found');
396
398
  const morphoAssetInfo = getAssetInfo('MORPHO');
397
399
  const { supplyApr, borrowApr } = marketData.state.rewards.find((reward: any) => compareAddresses(reward.asset.address, morphoAssetInfo.addresses[network])) || { supplyApr: '0', borrowApr: '0' };
@@ -399,8 +401,3 @@ export const getRewardsForMarket = async (marketId: string, network: NetworkNumb
399
401
  const borrowAprPercent = new Dec(borrowApr).mul(100).toString();
400
402
  return { supplyApy: aprToApy(supplyAprPercent), borrowApy: aprToApy(borrowAprPercent) };
401
403
  };
402
-
403
- export const getMorphoUnderlyingSymbol = (_symbol: string) => {
404
- if (_symbol === 'MORPHO Legacy') return 'MORPHO';
405
- return wethToEth(_symbol);
406
- };
@@ -48,7 +48,6 @@ import { getUmbrellaData } from '../umbrella';
48
48
  import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
49
49
  import { getCompoundV3Rewards } from '../claiming/compV3';
50
50
  import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
51
- import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
52
51
  import { getKingRewards } from '../claiming/king';
53
52
  import { fetchEthenaAirdropRewards } from '../claiming/ethena';
54
53
  import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
@@ -61,7 +60,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
61
60
  }> {
62
61
  const isMainnet = network === NetworkNumber.Eth;
63
62
  const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
64
- const isMorphoRewardsSupported = [NetworkNumber.Eth, NetworkNumber.Base].includes(network);
65
63
 
66
64
  const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
67
65
  const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
@@ -157,7 +155,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
157
155
  spark: {},
158
156
  spk: {},
159
157
  king: {},
160
- morpho: {},
161
158
  ethena: {},
162
159
  };
163
160
  }
@@ -354,28 +351,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
354
351
  rewardsData[address.toLowerCase() as EthAddress].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
355
352
  }
356
353
  })).flat(),
357
- // Batch Morpho Blue rewards
358
- (async () => {
359
- if (!isMorphoRewardsSupported) return;
360
- try {
361
- const morphoRewards = await fetchMorphoBlueRewards(client, network, addresses);
362
- for (const address of addresses) {
363
- const lowerAddress = address.toLowerCase() as EthAddress;
364
- rewardsData[lowerAddress].morpho = {
365
- error: '',
366
- data: morphoRewards[lowerAddress] || [],
367
- };
368
- }
369
- } catch (error) {
370
- console.error('Error fetching Morpho Blue rewards data in batch:', error);
371
- for (const address of addresses) {
372
- rewardsData[address.toLowerCase() as EthAddress].morpho = {
373
- error: 'Error fetching Morpho Blue rewards data in batch',
374
- data: null,
375
- };
376
- }
377
- }
378
- })(),
379
354
  // Batch Spark Airdrop rewards
380
355
  (async () => {
381
356
  try {
@@ -9,8 +9,6 @@ export enum ClaimType {
9
9
  COMPOUND_V3_COMP = 'COMPOUND_V3_COMP',
10
10
  /** Rewards from Spark (wstETH only for now) */
11
11
  SPARK_REWARDS = 'SPARK_REWARDS',
12
- /** Rewards from Morpho */
13
- MORPHO = 'MORPHO',
14
12
  /** Rewards from King (prev LTR^2 - received for weETH holding) */
15
13
  KING_REWARDS = 'KING_REWARDS',
16
14
  /** Spark Airdrop */
@@ -63,18 +61,6 @@ export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
63
61
  };
64
62
  };
65
63
 
66
- export type MorphoClaimableToken = _ClaimableTokenPartial & {
67
- claimType: ClaimType.MORPHO,
68
- additionalClaimFields: {
69
- originalAmount: string,
70
- merkleProofs: string[];
71
- distributor: EthAddress;
72
- isLegacy: boolean;
73
- txData: string;
74
- }
75
- };
76
-
77
-
78
64
  export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
79
65
  claimType: ClaimType.COMPOUND_V3_COMP,
80
66
  additionalClaimFields: {
@@ -106,7 +92,6 @@ export type ClaimableToken =
106
92
  AaveRewardsClaimableToken
107
93
  | AaveMeritRewardsClaimableToken
108
94
  | CompoundV3CompClaimableToken
109
- | MorphoClaimableToken
110
95
  | SparkRewardsClaimableToken
111
96
  | KingRewardsClaimableToken
112
97
  | SparkAirdropClaimableToken
@@ -206,13 +206,13 @@ export interface MorphoBlueAllocationMarket {
206
206
  oracle: { address: string },
207
207
  irmAddress: string,
208
208
  lltv: string,
209
- uniqueKey: string,
209
+ marketId: string,
210
210
  }
211
211
 
212
212
  export interface MorphoBluePublicAllocatorItem {
213
213
  vault: MorphoBlueVault,
214
214
  assets: string,
215
- allocationMarket: MorphoBlueAllocationMarket,
215
+ withdrawMarket: MorphoBlueAllocationMarket,
216
216
  }
217
217
 
218
218
  export interface MorphoBlueAllocatorMarketState {
@@ -222,7 +222,6 @@ export interface MorphoBlueAllocatorMarketState {
222
222
 
223
223
  export interface MorphoBlueRealloactionMarketData {
224
224
  reallocatableLiquidityAssets: string,
225
- targetBorrowUtilization: string,
226
225
  publicAllocatorSharedLiquidity: MorphoBluePublicAllocatorItem[],
227
226
  state: MorphoBlueAllocatorMarketState,
228
227
  }
@@ -1,5 +0,0 @@
1
- import { Client } from 'viem';
2
- import { ClaimableToken } from '../types/claiming';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
5
- export declare const fetchMorphoBlueRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, ClaimableToken[]>>;
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.fetchMorphoBlueRewards = exports.getMorphoBlueRewardsInfo = void 0;
16
- const tokens_1 = require("@defisaver/tokens");
17
- const decimal_js_1 = __importDefault(require("decimal.js"));
18
- const claiming_1 = require("../types/claiming");
19
- const contracts_1 = require("../contracts");
20
- const morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
21
- const MORPHO_ALLOWED_CONTRACTS = [
22
- '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
23
- '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
24
- '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
25
- ];
26
- const MORPHO_ALLOWED_TOKENS = [
27
- 'MORPHO',
28
- 'MORPHO Legacy',
29
- ];
30
- const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
31
- if (!address)
32
- return { claimable: '0' };
33
- try {
34
- const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
35
- if (!res.ok)
36
- throw new Error(yield res.text());
37
- return yield res.json();
38
- }
39
- catch (error) {
40
- console.error('External API Failure: Morpho Merit', error);
41
- return { claimable: '0' };
42
- }
43
- });
44
- exports.getMorphoBlueRewardsInfo = getMorphoBlueRewardsInfo;
45
- const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
46
- var _a;
47
- // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
48
- const apiDataPromises = walletAddresses.map(address => (0, exports.getMorphoBlueRewardsInfo)(address));
49
- const apiDataArray = yield Promise.all(apiDataPromises);
50
- // Process API data to get claimable tokens for each wallet
51
- const allClaimableTokens = [];
52
- const contractCallsData = [];
53
- for (let i = 0; i < walletAddresses.length; i++) {
54
- const walletAddress = walletAddresses[i];
55
- const data = apiDataArray[i];
56
- const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
57
- var _a, _b, _c;
58
- const token = (0, tokens_1.getAssetInfoByAddress)(reward.asset.address);
59
- if (!MORPHO_ALLOWED_CONTRACTS.includes((_a = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _a === void 0 ? void 0 : _a.address) || !MORPHO_ALLOWED_TOKENS.includes(token.symbol)) {
60
- return acc;
61
- }
62
- // Store contract call data for batching
63
- contractCallsData.push({
64
- walletAddress,
65
- tokenAddress: reward.asset.address,
66
- distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
67
- });
68
- return [
69
- ...acc,
70
- {
71
- symbol: token.symbol,
72
- underlyingSymbol: (0, morphoBlueHelpers_1.getMorphoUnderlyingSymbol)(token.symbol),
73
- tokenAddress: reward.asset.address,
74
- amount: (0, tokens_1.assetAmountInEth)(reward.claimable, token.symbol),
75
- walletAddress,
76
- label: token.symbol,
77
- claimType: claiming_1.ClaimType.MORPHO,
78
- additionalClaimFields: {
79
- originalAmount: reward.claimable,
80
- distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
81
- merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
82
- isLegacy: token.symbol === 'MORPHO Legacy',
83
- txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
84
- },
85
- }
86
- ];
87
- }, [])) || [];
88
- allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
89
- }
90
- // Batch all contract calls using multicall
91
- const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
92
- const distributorContract = (0, contracts_1.createViemContractFromConfigFunc)('MorphoDistributor', distributor)(provider, network);
93
- return distributorContract.read.claimed([walletAddress, tokenAddress]);
94
- });
95
- const contractResults = yield Promise.all(contractPromises);
96
- // Process results
97
- const results = {};
98
- let contractCallIndex = 0;
99
- for (const { walletAddress, tokens } of allClaimableTokens) {
100
- const updatedTokens = [];
101
- for (let i = 0; i < tokens.length; i++) {
102
- const claimableToken = tokens[i];
103
- const claimed = (0, tokens_1.assetAmountInEth)(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
104
- contractCallIndex++;
105
- const updatedToken = Object.assign({}, claimableToken);
106
- updatedToken.amount = new decimal_js_1.default(claimableToken.amount).sub(claimed).toString();
107
- updatedTokens.push(updatedToken);
108
- }
109
- results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new decimal_js_1.default(claimableToken.amount).gt(0));
110
- }
111
- return results;
112
- });
113
- exports.fetchMorphoBlueRewards = fetchMorphoBlueRewards;
@@ -1,5 +0,0 @@
1
- import { Client } from 'viem';
2
- import { ClaimableToken } from '../types/claiming';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
5
- export declare const fetchMorphoBlueRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, ClaimableToken[]>>;
@@ -1,105 +0,0 @@
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 Dec from 'decimal.js';
12
- import { ClaimType } from '../types/claiming';
13
- import { createViemContractFromConfigFunc } from '../contracts';
14
- import { getMorphoUnderlyingSymbol } from '../helpers/morphoBlueHelpers';
15
- const MORPHO_ALLOWED_CONTRACTS = [
16
- '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
17
- '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
18
- '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
19
- ];
20
- const MORPHO_ALLOWED_TOKENS = [
21
- 'MORPHO',
22
- 'MORPHO Legacy',
23
- ];
24
- export const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
25
- if (!address)
26
- return { claimable: '0' };
27
- try {
28
- const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
29
- if (!res.ok)
30
- throw new Error(yield res.text());
31
- return yield res.json();
32
- }
33
- catch (error) {
34
- console.error('External API Failure: Morpho Merit', error);
35
- return { claimable: '0' };
36
- }
37
- });
38
- export const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
39
- var _a;
40
- // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
41
- const apiDataPromises = walletAddresses.map(address => getMorphoBlueRewardsInfo(address));
42
- const apiDataArray = yield Promise.all(apiDataPromises);
43
- // Process API data to get claimable tokens for each wallet
44
- const allClaimableTokens = [];
45
- const contractCallsData = [];
46
- for (let i = 0; i < walletAddresses.length; i++) {
47
- const walletAddress = walletAddresses[i];
48
- const data = apiDataArray[i];
49
- const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
50
- var _a, _b, _c;
51
- const token = getAssetInfoByAddress(reward.asset.address);
52
- if (!MORPHO_ALLOWED_CONTRACTS.includes((_a = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _a === void 0 ? void 0 : _a.address) || !MORPHO_ALLOWED_TOKENS.includes(token.symbol)) {
53
- return acc;
54
- }
55
- // Store contract call data for batching
56
- contractCallsData.push({
57
- walletAddress,
58
- tokenAddress: reward.asset.address,
59
- distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
60
- });
61
- return [
62
- ...acc,
63
- {
64
- symbol: token.symbol,
65
- underlyingSymbol: getMorphoUnderlyingSymbol(token.symbol),
66
- tokenAddress: reward.asset.address,
67
- amount: assetAmountInEth(reward.claimable, token.symbol),
68
- walletAddress,
69
- label: token.symbol,
70
- claimType: ClaimType.MORPHO,
71
- additionalClaimFields: {
72
- originalAmount: reward.claimable,
73
- distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
74
- merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
75
- isLegacy: token.symbol === 'MORPHO Legacy',
76
- txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
77
- },
78
- }
79
- ];
80
- }, [])) || [];
81
- allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
82
- }
83
- // Batch all contract calls using multicall
84
- const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
85
- const distributorContract = createViemContractFromConfigFunc('MorphoDistributor', distributor)(provider, network);
86
- return distributorContract.read.claimed([walletAddress, tokenAddress]);
87
- });
88
- const contractResults = yield Promise.all(contractPromises);
89
- // Process results
90
- const results = {};
91
- let contractCallIndex = 0;
92
- for (const { walletAddress, tokens } of allClaimableTokens) {
93
- const updatedTokens = [];
94
- for (let i = 0; i < tokens.length; i++) {
95
- const claimableToken = tokens[i];
96
- const claimed = assetAmountInEth(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
97
- contractCallIndex++;
98
- const updatedToken = Object.assign({}, claimableToken);
99
- updatedToken.amount = new Dec(claimableToken.amount).sub(claimed).toString();
100
- updatedTokens.push(updatedToken);
101
- }
102
- results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new Dec(claimableToken.amount).gt(0));
103
- }
104
- return results;
105
- });
@@ -1,119 +0,0 @@
1
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
2
- import { Client } from 'viem';
3
- import Dec from 'decimal.js';
4
- import { ClaimableToken, ClaimType } from '../types/claiming';
5
- import { EthAddress, NetworkNumber } from '../types/common';
6
- import { createViemContractFromConfigFunc } from '../contracts';
7
- import { getMorphoUnderlyingSymbol } from '../helpers/morphoBlueHelpers';
8
-
9
- const MORPHO_ALLOWED_CONTRACTS = [
10
- '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
11
- '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
12
- '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
13
- ];
14
-
15
- const MORPHO_ALLOWED_TOKENS = [
16
- 'MORPHO',
17
- 'MORPHO Legacy',
18
- ];
19
-
20
-
21
- export const getMorphoBlueRewardsInfo = async (address: EthAddress) => {
22
- if (!address) return { claimable: '0' };
23
-
24
- try {
25
- const res = await fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`,
26
- { signal: AbortSignal.timeout(3000) });
27
-
28
- if (!res.ok) throw new Error(await res.text());
29
- return await res.json();
30
- } catch (error) {
31
- console.error('External API Failure: Morpho Merit', error);
32
- return { claimable: '0' };
33
- }
34
- };
35
-
36
- export const fetchMorphoBlueRewards = async (
37
- provider: Client,
38
- network: NetworkNumber,
39
- walletAddresses: EthAddress[],
40
- ): Promise<Record<string, ClaimableToken[]>> => {
41
- // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
42
- const apiDataPromises = walletAddresses.map(address => getMorphoBlueRewardsInfo(address));
43
- const apiDataArray = await Promise.all(apiDataPromises);
44
-
45
- // Process API data to get claimable tokens for each wallet
46
- const allClaimableTokens: Array<{ walletAddress: EthAddress; tokens: ClaimableToken[] }> = [];
47
- const contractCallsData: Array<{ walletAddress: EthAddress; tokenAddress: EthAddress; distributor: EthAddress }> = [];
48
-
49
- for (let i = 0; i < walletAddresses.length; i++) {
50
- const walletAddress = walletAddresses[i];
51
- const data = apiDataArray[i];
52
-
53
- const claimableTokens = data?.data?.reduce((acc: ClaimableToken[], reward: any) => {
54
- const token = getAssetInfoByAddress(reward.asset.address);
55
- if (!MORPHO_ALLOWED_CONTRACTS.includes(reward?.distributor?.address) || !MORPHO_ALLOWED_TOKENS.includes(token.symbol)) {
56
- return acc;
57
- }
58
-
59
- // Store contract call data for batching
60
- contractCallsData.push({
61
- walletAddress,
62
- tokenAddress: reward.asset.address,
63
- distributor: reward?.distributor?.address,
64
- });
65
-
66
- return [
67
- ...acc,
68
- {
69
- symbol: token.symbol,
70
- underlyingSymbol: getMorphoUnderlyingSymbol(token.symbol),
71
- tokenAddress: reward.asset.address,
72
- amount: assetAmountInEth(reward.claimable, token.symbol),
73
- walletAddress,
74
- label: token.symbol,
75
- claimType: ClaimType.MORPHO,
76
- additionalClaimFields: {
77
- originalAmount: reward.claimable,
78
- distributor: reward?.distributor?.address,
79
- merkleProofs: reward?.proof,
80
- isLegacy: token.symbol === 'MORPHO Legacy',
81
- txData: reward?.tx_data,
82
- },
83
- }];
84
- }, []) || [];
85
-
86
- allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
87
- }
88
-
89
- // Batch all contract calls using multicall
90
- const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
91
- const distributorContract = createViemContractFromConfigFunc('MorphoDistributor', distributor)(provider, network);
92
- return distributorContract.read.claimed([walletAddress, tokenAddress]);
93
- });
94
- const contractResults = await Promise.all(contractPromises);
95
-
96
- // Process results
97
- const results: Record<string, ClaimableToken[]> = {};
98
- let contractCallIndex = 0;
99
-
100
- for (const { walletAddress, tokens } of allClaimableTokens) {
101
- const updatedTokens: ClaimableToken[] = [];
102
-
103
- for (let i = 0; i < tokens.length; i++) {
104
- const claimableToken = tokens[i];
105
- const claimed = assetAmountInEth(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
106
- contractCallIndex++;
107
-
108
- const updatedToken = { ...claimableToken };
109
- updatedToken.amount = new Dec(claimableToken.amount).sub(claimed).toString();
110
- updatedTokens.push(updatedToken);
111
- }
112
-
113
- results[walletAddress.toLowerCase() as EthAddress] = updatedTokens.filter(
114
- (claimableToken) => new Dec(claimableToken.amount).gt(0),
115
- );
116
- }
117
-
118
- return results;
119
- };