@defisaver/positions-sdk 2.0.14 → 2.0.15-dev-2
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/aaveV2/index.js +9 -5
- package/cjs/aaveV3/index.js +63 -46
- package/cjs/aaveV3/merit.d.ts +17 -0
- package/cjs/aaveV3/merit.js +95 -0
- package/cjs/aaveV3/merkl.d.ts +19 -0
- package/cjs/aaveV3/merkl.js +98 -0
- package/cjs/compoundV2/index.js +13 -7
- package/cjs/compoundV3/index.js +7 -2
- package/cjs/config/contracts.d.ts +6510 -1851
- package/cjs/config/contracts.js +33 -12
- package/cjs/contracts.d.ts +178 -0
- package/cjs/eulerV2/index.js +11 -2
- package/cjs/fluid/index.js +105 -34
- package/cjs/helpers/aaveHelpers/index.js +0 -1
- package/cjs/helpers/compoundHelpers/index.d.ts +3 -5
- package/cjs/helpers/compoundHelpers/index.js +15 -11
- package/cjs/helpers/eulerHelpers/index.d.ts +0 -5
- package/cjs/helpers/eulerHelpers/index.js +2 -31
- package/cjs/helpers/fluidHelpers/index.js +2 -0
- package/cjs/helpers/liquityV2Helpers/index.js +3 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/liquityV2/index.js +10 -2
- package/cjs/llamaLend/index.js +10 -2
- package/cjs/morphoBlue/index.js +20 -6
- package/cjs/spark/index.js +20 -30
- package/cjs/staking/eligibility.d.ts +11 -0
- package/cjs/staking/eligibility.js +43 -0
- package/cjs/staking/index.d.ts +1 -0
- package/cjs/staking/index.js +1 -0
- package/cjs/staking/staking.d.ts +1 -7
- package/cjs/staking/staking.js +29 -55
- package/cjs/types/aave.d.ts +3 -8
- package/cjs/types/common.d.ts +16 -4
- package/cjs/types/common.js +10 -1
- package/cjs/types/euler.d.ts +3 -3
- package/cjs/types/fluid.d.ts +3 -5
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +3 -1
- package/cjs/types/morphoBlue.d.ts +3 -5
- package/cjs/types/spark.d.ts +0 -3
- package/esm/aaveV2/index.js +9 -5
- package/esm/aaveV3/index.js +64 -47
- package/esm/aaveV3/merit.d.ts +17 -0
- package/esm/aaveV3/merit.js +90 -0
- package/esm/aaveV3/merkl.d.ts +19 -0
- package/esm/aaveV3/merkl.js +92 -0
- package/esm/compoundV2/index.js +13 -7
- package/esm/compoundV3/index.js +7 -2
- package/esm/config/contracts.d.ts +6510 -1851
- package/esm/config/contracts.js +33 -12
- package/esm/contracts.d.ts +178 -0
- package/esm/eulerV2/index.js +11 -2
- package/esm/fluid/index.js +106 -35
- package/esm/helpers/aaveHelpers/index.js +0 -1
- package/esm/helpers/compoundHelpers/index.d.ts +3 -5
- package/esm/helpers/compoundHelpers/index.js +16 -12
- package/esm/helpers/eulerHelpers/index.d.ts +0 -5
- package/esm/helpers/eulerHelpers/index.js +2 -30
- package/esm/helpers/fluidHelpers/index.js +2 -0
- package/esm/helpers/liquityV2Helpers/index.js +3 -2
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/liquityV2/index.js +11 -3
- package/esm/llamaLend/index.js +11 -3
- package/esm/morphoBlue/index.js +21 -7
- package/esm/spark/index.js +21 -31
- package/esm/staking/eligibility.d.ts +11 -0
- package/esm/staking/eligibility.js +36 -0
- package/esm/staking/index.d.ts +1 -0
- package/esm/staking/index.js +1 -0
- package/esm/staking/staking.d.ts +1 -7
- package/esm/staking/staking.js +28 -53
- package/esm/types/aave.d.ts +3 -8
- package/esm/types/common.d.ts +16 -4
- package/esm/types/common.js +9 -0
- package/esm/types/euler.d.ts +3 -3
- package/esm/types/fluid.d.ts +3 -5
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +3 -1
- package/esm/types/morphoBlue.d.ts +3 -5
- package/esm/types/spark.d.ts +0 -3
- package/package.json +47 -47
- package/src/aaveV2/index.ts +239 -236
- package/src/aaveV3/index.ts +511 -488
- package/src/aaveV3/merit.ts +98 -0
- package/src/aaveV3/merkl.ts +141 -0
- package/src/compoundV2/index.ts +244 -240
- package/src/compoundV3/index.ts +274 -270
- package/src/config/contracts.ts +1129 -1108
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +107 -107
- package/src/curveUsd/index.ts +250 -250
- package/src/eulerV2/index.ts +324 -314
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1636 -1568
- package/src/helpers/aaveHelpers/index.ts +169 -170
- package/src/helpers/compoundHelpers/index.ts +267 -261
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -259
- package/src/helpers/fluidHelpers/index.ts +326 -324
- package/src/helpers/index.ts +10 -10
- package/src/helpers/liquityV2Helpers/index.ts +82 -80
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +390 -390
- package/src/helpers/sparkHelpers/index.ts +155 -155
- package/src/index.ts +45 -45
- package/src/liquity/index.ts +104 -104
- package/src/liquityV2/index.ts +418 -408
- package/src/llamaLend/index.ts +305 -296
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +116 -116
- package/src/markets/aave/marketAssets.ts +49 -49
- package/src/markets/compound/index.ts +227 -227
- package/src/markets/compound/marketsAssets.ts +90 -90
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2456 -2456
- package/src/markets/index.ts +25 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +11 -11
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoBlue/index.ts +236 -222
- package/src/portfolio/index.ts +285 -285
- package/src/services/priceService.ts +159 -159
- package/src/services/utils.ts +63 -63
- package/src/services/viem.ts +32 -32
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +444 -456
- package/src/staking/eligibility.ts +37 -0
- package/src/staking/index.ts +2 -1
- package/src/staking/staking.ts +169 -194
- package/src/types/aave.ts +189 -194
- package/src/types/common.ts +103 -88
- package/src/types/compound.ts +136 -136
- package/src/types/curveUsd.ts +121 -121
- package/src/types/euler.ts +175 -174
- package/src/types/fluid.ts +448 -450
- package/src/types/index.ts +11 -11
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +159 -157
- package/src/types/maker.ts +63 -63
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/portfolio.ts +60 -60
- package/src/types/spark.ts +135 -137
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
3
|
+
import { NetworkNumber } from '../types/common';
|
|
4
|
+
import { aprToApy } from '../moneymarket';
|
|
5
|
+
import { AaveVersions } from '../types';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type RewardInfo = { apy: string; rewardTokenSymbol: string, description: string };
|
|
9
|
+
type MeritTokenRewardMap = { supply: Record<string, RewardInfo>; borrow: Record<string, RewardInfo> };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
|
|
13
|
+
* Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
|
|
14
|
+
* Active campaigns found here: https://apps.aavechan.com/merit
|
|
15
|
+
*/
|
|
16
|
+
const MERIT_DATA_MAP:
|
|
17
|
+
Record<
|
|
18
|
+
NetworkNumber,
|
|
19
|
+
Partial<Record<
|
|
20
|
+
AaveVersions,
|
|
21
|
+
Record<string, {
|
|
22
|
+
rewardTokenSymbol: string;
|
|
23
|
+
action: 'supply' | 'borrow' | 'stake';
|
|
24
|
+
message?: string;
|
|
25
|
+
supplyTokens?: string[],
|
|
26
|
+
borrowTokens?: string[],
|
|
27
|
+
}>
|
|
28
|
+
>>
|
|
29
|
+
> = {
|
|
30
|
+
[NetworkNumber.Eth]: {
|
|
31
|
+
[AaveVersions.AaveV3]: {
|
|
32
|
+
'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
|
|
33
|
+
'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
|
|
34
|
+
// Campaign disabled here as it's present on Merkl API:
|
|
35
|
+
// 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
|
|
36
|
+
},
|
|
37
|
+
[AaveVersions.AaveV3Lido]: {},
|
|
38
|
+
[AaveVersions.AaveV3Etherfi]: {},
|
|
39
|
+
},
|
|
40
|
+
[NetworkNumber.Arb]: {
|
|
41
|
+
[AaveVersions.AaveV3]: {},
|
|
42
|
+
},
|
|
43
|
+
[NetworkNumber.Opt]: {
|
|
44
|
+
[AaveVersions.AaveV3]: {},
|
|
45
|
+
},
|
|
46
|
+
[NetworkNumber.Base]: {
|
|
47
|
+
[AaveVersions.AaveV3]: {
|
|
48
|
+
'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
|
|
49
|
+
'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
|
|
50
|
+
'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
[NetworkNumber.Linea]: {
|
|
54
|
+
[AaveVersions.AaveV3]: {},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Fetches merit rewards data from Aave API
|
|
60
|
+
*/
|
|
61
|
+
export const fetchMeritRewardsData = async (): Promise<Record<string, number | null>> => {
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch('https://apps.aavechan.com/api/merit/aprs', {
|
|
64
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
65
|
+
});
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
return data.currentAPR.actionsAPR as Record<string, number | null>;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Failed to fetch merit rewards data:', error);
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const getMeritCampaigns = async (chainId: NetworkNumber, market: AaveVersions): Promise<MeritTokenRewardMap> => {
|
|
75
|
+
const meritData = await fetchMeritRewardsData();
|
|
76
|
+
const relevantCampaigns = {
|
|
77
|
+
supply: {},
|
|
78
|
+
borrow: {},
|
|
79
|
+
} as MeritTokenRewardMap;
|
|
80
|
+
Object.entries(MERIT_DATA_MAP[chainId]?.[market] || {})
|
|
81
|
+
.filter(([key, rewardData]) => !!meritData[key])
|
|
82
|
+
.forEach(([key, rewardData]) => {
|
|
83
|
+
const apr = meritData[key]!;
|
|
84
|
+
if (!apr) return;
|
|
85
|
+
const reward = {
|
|
86
|
+
rewardTokenSymbol: rewardData.rewardTokenSymbol,
|
|
87
|
+
apy: aprToApy(apr).toString(),
|
|
88
|
+
description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
|
|
89
|
+
};
|
|
90
|
+
rewardData.supplyTokens?.forEach(token => {
|
|
91
|
+
relevantCampaigns.supply[token] = reward;
|
|
92
|
+
});
|
|
93
|
+
rewardData.borrowTokens?.forEach(token => {
|
|
94
|
+
relevantCampaigns.borrow[token] = reward;
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return relevantCampaigns;
|
|
98
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { aprToApy } from '../moneymarket';
|
|
2
|
+
import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
|
|
3
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
+
|
|
5
|
+
enum OpportunityAction {
|
|
6
|
+
LEND = 'LEND',
|
|
7
|
+
BORROW = 'BORROW',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
enum OpportunityStatus {
|
|
11
|
+
LIVE = 'LIVE',
|
|
12
|
+
PAST = 'PAST',
|
|
13
|
+
UPCOMING = 'UPCOMING',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type MerklOpportunity = {
|
|
17
|
+
chainId: number;
|
|
18
|
+
type: string;
|
|
19
|
+
identifier: EthAddress;
|
|
20
|
+
name: string;
|
|
21
|
+
status: OpportunityStatus;
|
|
22
|
+
action: OpportunityAction;
|
|
23
|
+
tvl: number;
|
|
24
|
+
apr: number;
|
|
25
|
+
dailyRewards: number;
|
|
26
|
+
tags: [];
|
|
27
|
+
id: string;
|
|
28
|
+
explorerAddress?: EthAddress;
|
|
29
|
+
description?: string;
|
|
30
|
+
tokens: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
chainId: number;
|
|
34
|
+
address: EthAddress;
|
|
35
|
+
decimals: number;
|
|
36
|
+
icon: string;
|
|
37
|
+
verified: boolean;
|
|
38
|
+
isTest: boolean;
|
|
39
|
+
price: number;
|
|
40
|
+
symbol: string;
|
|
41
|
+
}[];
|
|
42
|
+
rewardsRecord: {
|
|
43
|
+
id: string;
|
|
44
|
+
total: number;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
breakdowns: {
|
|
47
|
+
token: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
chainId: number;
|
|
51
|
+
address: EthAddress;
|
|
52
|
+
decimals: number;
|
|
53
|
+
symbol: string;
|
|
54
|
+
displaySymbol: string;
|
|
55
|
+
icon: string;
|
|
56
|
+
verified: boolean;
|
|
57
|
+
isTest: boolean;
|
|
58
|
+
type: string;
|
|
59
|
+
isNative: boolean;
|
|
60
|
+
price: number;
|
|
61
|
+
};
|
|
62
|
+
amount: string;
|
|
63
|
+
value: number;
|
|
64
|
+
distributionType: string;
|
|
65
|
+
id: string;
|
|
66
|
+
campaignId: string;
|
|
67
|
+
dailyRewardsRecordId: string;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type RewardInfo = { apy: string; rewardTokenSymbol: string, description: string, identifier: string };
|
|
73
|
+
type MerkleRewardMap = Record<EthAddress, { supply?: RewardInfo; borrow?: RewardInfo }>;
|
|
74
|
+
|
|
75
|
+
export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
76
|
+
let symbol = _symbol
|
|
77
|
+
.replace(/^aEthLido/, '')
|
|
78
|
+
.replace(/^aEthEtherFi/, '')
|
|
79
|
+
.replace(/^aEth/, '')
|
|
80
|
+
.replace(/^aArb/, '')
|
|
81
|
+
.replace(/^aOpt/, '')
|
|
82
|
+
.replace(/^aBas/, '')
|
|
83
|
+
.replace(/^aLin/, '');
|
|
84
|
+
if (symbol.startsWith('a')) symbol = symbol.slice(1);
|
|
85
|
+
return wethToEth(symbol);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* aEthLidoUSDC -> aUSDC
|
|
90
|
+
* USDC -> USDC
|
|
91
|
+
*/
|
|
92
|
+
export const formatAaveAsset = (_symbol: string) => {
|
|
93
|
+
if (_symbol.startsWith('a')) {
|
|
94
|
+
return `a${getAaveUnderlyingSymbol(_symbol)}`;
|
|
95
|
+
}
|
|
96
|
+
return _symbol;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<MerkleRewardMap> => {
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
|
|
102
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
103
|
+
});
|
|
104
|
+
if (!res.ok) throw new Error('Failed to fetch Merkle campaigns');
|
|
105
|
+
const opportunities = await res.json() as MerklOpportunity[];
|
|
106
|
+
const relevantOpportunities = opportunities
|
|
107
|
+
.filter((o: MerklOpportunity) => o.chainId === chainId)
|
|
108
|
+
.filter((o: MerklOpportunity) => o.status === OpportunityStatus.LIVE);
|
|
109
|
+
return relevantOpportunities.reduce((acc, opportunity) => {
|
|
110
|
+
const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
|
|
111
|
+
const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
|
|
112
|
+
if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
|
|
113
|
+
const supplyAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
|
|
114
|
+
if (!acc[supplyAToken]) acc[supplyAToken] = {};
|
|
115
|
+
acc[supplyAToken].supply = {
|
|
116
|
+
apy: aprToApy(opportunity.apr),
|
|
117
|
+
// rewardToken: rewardToken.address,
|
|
118
|
+
rewardTokenSymbol: rewardToken.symbol,
|
|
119
|
+
description,
|
|
120
|
+
identifier: opportunity.identifier,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
|
|
124
|
+
const borrowAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
|
|
125
|
+
if (!acc[borrowAToken]) acc[borrowAToken] = {};
|
|
126
|
+
acc[borrowAToken].borrow = {
|
|
127
|
+
apy: aprToApy(opportunity.apr),
|
|
128
|
+
// rewardToken: rewardToken.address,
|
|
129
|
+
rewardTokenSymbol: rewardToken.symbol,
|
|
130
|
+
description,
|
|
131
|
+
identifier: opportunity.identifier,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return acc;
|
|
135
|
+
}, {} as MerkleRewardMap);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.error('Failed to fetch Merkle campaigns', e);
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|