@defisaver/positions-sdk 2.1.114 → 2.1.115

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.
@@ -1,5 +1,4 @@
1
- import { MerkleRewardMap } from '../types';
2
- import { NetworkNumber } from '../types/common';
1
+ import { MerkleRewardMap, NetworkNumber } from '../types';
3
2
  export declare const getAaveUnderlyingSymbol: (_symbol?: string) => string;
4
3
  /**
5
4
  * aEthLidoUSDC -> aUSDC
@@ -40,8 +40,8 @@ const formatAaveAsset = (_symbol) => {
40
40
  exports.formatAaveAsset = formatAaveAsset;
41
41
  const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
42
42
  try {
43
- const res = yield fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
44
- signal: AbortSignal.timeout(utils_1.DEFAULT_TIMEOUT),
43
+ const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
44
+ signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
45
45
  });
46
46
  if (!res.ok)
47
47
  throw new Error('Failed to fetch Merkle campaigns');
@@ -1,5 +1,4 @@
1
- import { AaveV4MerklRewardMap, AaveV4ReserveAssetData } from '../types';
2
- import { NetworkNumber } from '../types/common';
1
+ import { AaveV4MerklRewardMap, AaveV4ReserveAssetData, NetworkNumber } from '../types';
3
2
  export declare const getAaveV4MerkleCampaigns: (chainId: NetworkNumber) => Promise<AaveV4MerklRewardMap>;
4
3
  /**
5
4
  * Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
@@ -34,8 +34,8 @@ const buildIncentive = (opportunity) => {
34
34
  const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
35
35
  const result = { hub: {}, spoke: {} };
36
36
  try {
37
- const res = yield fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
38
- signal: AbortSignal.timeout(utils_1.DEFAULT_TIMEOUT),
37
+ const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
38
+ signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
39
39
  });
40
40
  if (!res.ok)
41
41
  throw new Error('Failed to fetch Aave V4 Merkle campaigns');
@@ -1,5 +1,5 @@
1
1
  import { Client } from 'viem';
2
- import { EthAddress, NetworkNumber } from '../types/common';
2
+ import { EthAddress, NetworkNumber } from '../types';
3
3
  import { ClaimableToken } from '../types/claiming';
4
4
  export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
5
5
  export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]>;
@@ -99,7 +99,7 @@ function getMeritUnclaimedRewards(account, network) {
99
99
  return __awaiter(this, void 0, void 0, function* () {
100
100
  let data;
101
101
  try {
102
- const res = yield fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
102
+ const res = yield fetch(`https://fe.defisaver.com/api/merkl/get-user-rewards/${account}?chainId=${network}`, { signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT) });
103
103
  data = yield res.json();
104
104
  }
105
105
  catch (error) {
@@ -107,6 +107,10 @@ function getMeritUnclaimedRewards(account, network) {
107
107
  data = [];
108
108
  }
109
109
  const claimableTokens = [];
110
+ // Merkl (or our proxy, on a non-2xx) can return a non-array error body; `fetch` doesn't throw on
111
+ // HTTP errors, so guard before iterating. Mirrors the app-side getMeritUnclaimedRewards.
112
+ if (!Array.isArray(data))
113
+ return claimableTokens;
110
114
  data.forEach((item) => {
111
115
  item.rewards.forEach(reward => {
112
116
  const { token, amount, claimed, proofs, } = reward;
@@ -1,5 +1,4 @@
1
- import { MerkleRewardMap } from '../types';
2
- import { NetworkNumber } from '../types/common';
1
+ import { MerkleRewardMap, NetworkNumber } from '../types';
3
2
  export declare const getAaveUnderlyingSymbol: (_symbol?: string) => string;
4
3
  /**
5
4
  * aEthLidoUSDC -> aUSDC
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { aprToApy } from '../moneymarket';
11
- import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
11
+ import { LONGER_TIMEOUT, wethToEth } from '../services/utils';
12
12
  import { OpportunityAction, OpportunityStatus, } from '../types';
13
13
  export const getAaveUnderlyingSymbol = (_symbol = '') => {
14
14
  let symbol = _symbol
@@ -35,8 +35,8 @@ 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-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
39
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
38
+ const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
39
+ signal: AbortSignal.timeout(LONGER_TIMEOUT),
40
40
  });
41
41
  if (!res.ok)
42
42
  throw new Error('Failed to fetch Merkle campaigns');
@@ -1,5 +1,4 @@
1
- import { AaveV4MerklRewardMap, AaveV4ReserveAssetData } from '../types';
2
- import { NetworkNumber } from '../types/common';
1
+ import { AaveV4MerklRewardMap, AaveV4ReserveAssetData, NetworkNumber } from '../types';
3
2
  export declare const getAaveV4MerkleCampaigns: (chainId: NetworkNumber) => Promise<AaveV4MerklRewardMap>;
4
3
  /**
5
4
  * Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { aprToApy } from '../moneymarket';
11
- import { DEFAULT_TIMEOUT } from '../services/utils';
11
+ import { LONGER_TIMEOUT } from '../services/utils';
12
12
  import { IncentiveKind, OpportunityAction, OpportunityStatus, } from '../types';
13
13
  /**
14
14
  * Merkl tags Aave V4 reward campaigns by scope via the `type` field:
@@ -31,8 +31,8 @@ const buildIncentive = (opportunity) => {
31
31
  export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
32
32
  const result = { hub: {}, spoke: {} };
33
33
  try {
34
- const res = yield fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
35
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
34
+ const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
35
+ signal: AbortSignal.timeout(LONGER_TIMEOUT),
36
36
  });
37
37
  if (!res.ok)
38
38
  throw new Error('Failed to fetch Aave V4 Merkle campaigns');
@@ -1,5 +1,5 @@
1
1
  import { Client } from 'viem';
2
- import { EthAddress, NetworkNumber } from '../types/common';
2
+ import { EthAddress, NetworkNumber } from '../types';
3
3
  import { ClaimableToken } from '../types/claiming';
4
4
  export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
5
5
  export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]>;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import Dec from 'decimal.js';
11
11
  import { ClaimType } from '../types/claiming';
12
12
  import { AaveIncentiveDataProviderV3ContractViem, AaveRewardsControllerViem, } from '../contracts';
13
- import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
13
+ import { compareAddresses, getEthAmountForDecimals, LONGER_TIMEOUT } from '../services/utils';
14
14
  import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
15
15
  const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
16
16
  symbol: reward.symbol,
@@ -92,7 +92,7 @@ export function getMeritUnclaimedRewards(account, network) {
92
92
  return __awaiter(this, void 0, void 0, function* () {
93
93
  let data;
94
94
  try {
95
- const res = yield fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
95
+ const res = yield fetch(`https://fe.defisaver.com/api/merkl/get-user-rewards/${account}?chainId=${network}`, { signal: AbortSignal.timeout(LONGER_TIMEOUT) });
96
96
  data = yield res.json();
97
97
  }
98
98
  catch (error) {
@@ -100,6 +100,10 @@ export function getMeritUnclaimedRewards(account, network) {
100
100
  data = [];
101
101
  }
102
102
  const claimableTokens = [];
103
+ // Merkl (or our proxy, on a non-2xx) can return a non-array error body; `fetch` doesn't throw on
104
+ // HTTP errors, so guard before iterating. Mirrors the app-side getMeritUnclaimedRewards.
105
+ if (!Array.isArray(data))
106
+ return claimableTokens;
103
107
  data.forEach((item) => {
104
108
  item.rewards.forEach(reward => {
105
109
  const { token, amount, claimed, proofs, } = reward;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.114",
3
+ "version": "2.1.115",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,9 +1,9 @@
1
1
  import { aprToApy } from '../moneymarket';
2
- import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
2
+ import { LONGER_TIMEOUT, wethToEth } from '../services/utils';
3
3
  import {
4
4
  MerkleRewardMap, MerklOpportunity, OpportunityAction, OpportunityStatus,
5
+ EthAddress, NetworkNumber,
5
6
  } from '../types';
6
- import { EthAddress, NetworkNumber } from '../types/common';
7
7
 
8
8
  export const getAaveUnderlyingSymbol = (_symbol = '') => {
9
9
  let symbol = _symbol
@@ -31,8 +31,8 @@ export const formatAaveAsset = (_symbol: string) => {
31
31
 
32
32
  export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<MerkleRewardMap> => {
33
33
  try {
34
- const res = await fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
35
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
34
+ const res = await fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
35
+ signal: AbortSignal.timeout(LONGER_TIMEOUT),
36
36
  });
37
37
  if (!res.ok) throw new Error('Failed to fetch Merkle campaigns');
38
38
  const opportunities = await res.json() as MerklOpportunity[];
@@ -1,5 +1,5 @@
1
1
  import { aprToApy } from '../moneymarket';
2
- import { DEFAULT_TIMEOUT } from '../services/utils';
2
+ import { LONGER_TIMEOUT } from '../services/utils';
3
3
  import {
4
4
  AaveV4MerklRewardMap,
5
5
  AaveV4ReserveAssetData,
@@ -8,8 +8,8 @@ import {
8
8
  MerklOpportunity,
9
9
  OpportunityAction,
10
10
  OpportunityStatus,
11
+ NetworkNumber,
11
12
  } from '../types';
12
- import { NetworkNumber } from '../types/common';
13
13
 
14
14
  /**
15
15
  * Merkl tags Aave V4 reward campaigns by scope via the `type` field:
@@ -34,8 +34,8 @@ const buildIncentive = (opportunity: MerklOpportunity): IncentiveData => {
34
34
  export const getAaveV4MerkleCampaigns = async (chainId: NetworkNumber): Promise<AaveV4MerklRewardMap> => {
35
35
  const result: AaveV4MerklRewardMap = { hub: {}, spoke: {} };
36
36
  try {
37
- const res = await fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
38
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
37
+ const res = await fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave', {
38
+ signal: AbortSignal.timeout(LONGER_TIMEOUT),
39
39
  });
40
40
  if (!res.ok) throw new Error('Failed to fetch Aave V4 Merkle campaigns');
41
41
  const opportunities = await res.json() as MerklOpportunity[];
@@ -1,12 +1,12 @@
1
1
  import { Client } from 'viem';
2
2
  import Dec from 'decimal.js';
3
- import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { EthAddress, NetworkNumber } from '../types';
4
4
  import { ClaimableToken, ClaimType } from '../types/claiming';
5
5
  import {
6
6
  AaveIncentiveDataProviderV3ContractViem,
7
7
  AaveRewardsControllerViem,
8
8
  } from '../contracts';
9
- import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
9
+ import { compareAddresses, getEthAmountForDecimals, LONGER_TIMEOUT } from '../services/utils';
10
10
  import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
11
11
 
12
12
  type AaveReward = {
@@ -106,8 +106,8 @@ export async function getUnclaimedRewardsForAllMarkets(
106
106
  export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]> {
107
107
  let data;
108
108
  try {
109
- const res = await fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`,
110
- { signal: AbortSignal.timeout(3000) });
109
+ const res = await fetch(`https://fe.defisaver.com/api/merkl/get-user-rewards/${account}?chainId=${network}`,
110
+ { signal: AbortSignal.timeout(LONGER_TIMEOUT) });
111
111
  data = await res.json();
112
112
  } catch (error) {
113
113
  console.error('External API Failure: Aave Merit', error);
@@ -116,6 +116,10 @@ export async function getMeritUnclaimedRewards(account: EthAddress, network: Net
116
116
 
117
117
  const claimableTokens: ClaimableToken[] = [];
118
118
 
119
+ // Merkl (or our proxy, on a non-2xx) can return a non-array error body; `fetch` doesn't throw on
120
+ // HTTP errors, so guard before iterating. Mirrors the app-side getMeritUnclaimedRewards.
121
+ if (!Array.isArray(data)) return claimableTokens;
122
+
119
123
  data.forEach((item: { rewards: any[]; }) => {
120
124
  item.rewards.forEach(reward => {
121
125
  const {