@defisaver/positions-sdk 2.0.13 → 2.0.14-dev-portfolio
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/CLAUDE.md +32 -0
- package/cjs/aaveV2/index.js +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +9 -0
- package/cjs/claiming/aaveV3.js +148 -0
- package/cjs/claiming/compV3.d.ts +15 -0
- package/cjs/claiming/compV3.js +34 -0
- package/cjs/claiming/index.d.ts +6 -0
- package/cjs/claiming/index.js +46 -0
- package/cjs/claiming/king.d.ts +4 -0
- package/cjs/claiming/king.js +72 -0
- package/cjs/claiming/morphoBlue.d.ts +6 -0
- package/cjs/claiming/morphoBlue.js +113 -0
- package/cjs/claiming/spark.d.ts +6 -0
- package/cjs/claiming/spark.js +188 -0
- package/cjs/config/contracts.d.ts +2667 -0
- package/cjs/config/contracts.js +103 -2
- package/cjs/constants/index.d.ts +4 -0
- package/cjs/constants/index.js +6 -2
- package/cjs/contracts.d.ts +2882 -23
- package/cjs/contracts.js +10 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquity/index.d.ts +11 -0
- package/cjs/liquity/index.js +39 -1
- package/cjs/liquityV2/index.d.ts +8 -0
- package/cjs/liquityV2/index.js +161 -0
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/markets/compound/marketsAssets.js +2 -2
- package/cjs/markets/spark/marketAssets.js +1 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +38 -4
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +256 -10
- package/cjs/services/utils.d.ts +5 -0
- package/cjs/services/utils.js +33 -1
- package/cjs/services/viem.d.ts +12 -12
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/staking.js +3 -1
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/umbrella/index.d.ts +5 -0
- package/cjs/umbrella/index.js +50 -0
- package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
- package/cjs/umbrella/umbrellaUtils.js +34 -0
- package/esm/aaveV2/index.js +1 -0
- package/esm/aaveV3/index.d.ts +12 -0
- package/esm/aaveV3/index.js +91 -1
- package/esm/claiming/aaveV3.d.ts +9 -0
- package/esm/claiming/aaveV3.js +139 -0
- package/esm/claiming/compV3.d.ts +15 -0
- package/esm/claiming/compV3.js +30 -0
- package/esm/claiming/index.d.ts +6 -0
- package/esm/claiming/index.js +6 -0
- package/esm/claiming/king.d.ts +4 -0
- package/esm/claiming/king.js +64 -0
- package/esm/claiming/morphoBlue.d.ts +6 -0
- package/esm/claiming/morphoBlue.js +104 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2667 -0
- package/esm/config/contracts.js +102 -1
- package/esm/constants/index.d.ts +4 -0
- package/esm/constants/index.js +5 -1
- package/esm/contracts.d.ts +2882 -23
- package/esm/contracts.js +9 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquity/index.d.ts +11 -0
- package/esm/liquity/index.js +38 -1
- package/esm/liquityV2/index.d.ts +8 -0
- package/esm/liquityV2/index.js +162 -1
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/markets/compound/marketsAssets.js +2 -2
- package/esm/markets/spark/marketAssets.js +1 -1
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +38 -5
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +260 -14
- package/esm/services/utils.d.ts +5 -0
- package/esm/services/utils.js +31 -0
- package/esm/services/viem.d.ts +12 -12
- package/esm/spark/index.js +1 -0
- package/esm/staking/staking.js +3 -1
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/umbrella/index.d.ts +5 -0
- package/esm/umbrella/index.js +46 -0
- package/esm/umbrella/umbrellaUtils.d.ts +22 -0
- package/esm/umbrella/umbrellaUtils.js +28 -0
- package/package.json +2 -2
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +163 -0
- package/src/claiming/compV3.ts +23 -0
- package/src/claiming/index.ts +13 -0
- package/src/claiming/king.ts +66 -0
- package/src/claiming/morphoBlue.ts +119 -0
- package/src/claiming/spark.ts +226 -0
- package/src/config/contracts.ts +105 -5
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +177 -2
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/markets/compound/marketsAssets.ts +2 -2
- package/src/markets/spark/marketAssets.ts +1 -1
- package/src/morphoBlue/index.ts +43 -6
- package/src/portfolio/index.ts +263 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/staking.ts +2 -1
- package/src/types/claiming.ts +109 -0
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { SparkRewardsClaimableToken } from '../types/claiming';
|
|
4
|
+
export declare const fetchSpkAirdropRewards: (walletAddress: EthAddress) => Promise<any>;
|
|
5
|
+
export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;
|
|
6
|
+
export declare const fetchSparkRewards: (provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress) => Promise<SparkRewardsClaimableToken[]>;
|
|
@@ -0,0 +1,188 @@
|
|
|
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.fetchSparkRewards = exports.fetchSparkAirdropRewards = exports.fetchSpkAirdropRewards = void 0;
|
|
16
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
17
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
18
|
+
const contracts_1 = require("../contracts");
|
|
19
|
+
const claiming_1 = require("../types/claiming");
|
|
20
|
+
const utils_1 = require("../services/utils");
|
|
21
|
+
const IGNITION_REWARDS = '0xCBA0C0a2a0B6Bb11233ec4EA85C5bFfea33e724d';
|
|
22
|
+
const PFL3_REWARDS = '0x7ac96180C4d6b2A328D3a19ac059D0E7Fc3C6d41';
|
|
23
|
+
const fetchSpkAirdropRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
const res = yield fetch(`https://fe.defisaver.com/api/spark/get-spk-airdrop-rewards/${walletAddress}`, { signal: AbortSignal.timeout(3000) });
|
|
26
|
+
if (!res.ok)
|
|
27
|
+
throw new Error(yield res.text());
|
|
28
|
+
return yield res.json();
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.error('External API Error: Error fetching SPK airdrop rewards:', err);
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
exports.fetchSpkAirdropRewards = fetchSpkAirdropRewards;
|
|
36
|
+
const getCumulativeClaimedSpkAirdrop = (provider, network, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const contractIgnition = (0, contracts_1.createViemContractFromConfigFunc)('SparkAirdrop', IGNITION_REWARDS)(provider, network);
|
|
38
|
+
const contractPFL = (0, contracts_1.createViemContractFromConfigFunc)('SparkAirdrop', PFL3_REWARDS)(provider, network);
|
|
39
|
+
const cumulativeAmounts = yield Promise.all(data.map((airdrop) => {
|
|
40
|
+
const { user, tokenAddress, epoch, type, } = airdrop;
|
|
41
|
+
const contract = type === claiming_1.SparkAirdropType.SPARK_IGNITION ? contractIgnition : contractPFL;
|
|
42
|
+
return contract.read.cumulativeClaimed([user, tokenAddress, BigInt(epoch)]);
|
|
43
|
+
}));
|
|
44
|
+
return cumulativeAmounts.map((amount, i) => (0, tokens_1.assetAmountInEth)(amount.toString(), (0, tokens_1.getAssetInfoByAddress)(data[i].tokenAddress).symbol).toString());
|
|
45
|
+
});
|
|
46
|
+
const fetchSparkAirdropRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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.fetchSpkAirdropRewards)(address));
|
|
49
|
+
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
50
|
+
// Process API data and collect contract call data
|
|
51
|
+
const allClaimData = [];
|
|
52
|
+
const contractCallsData = [];
|
|
53
|
+
for (let i = 0; i < walletAddresses.length; i++) {
|
|
54
|
+
const walletAddress = walletAddresses[i];
|
|
55
|
+
const data = apiDataArray[i];
|
|
56
|
+
const falseResponse = !data;
|
|
57
|
+
const emptyResponse = data && data.length === 0;
|
|
58
|
+
const singleResponseWithoutAmount = data && data.length === 1 && !+data[0].amount;
|
|
59
|
+
if (falseResponse || emptyResponse || singleResponseWithoutAmount) {
|
|
60
|
+
allClaimData.push({ walletAddress, data: [] });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// Filter out IGNITION_REWARDS since they are no longer active
|
|
64
|
+
const filteredData = data.filter((rewardInfo) => rewardInfo.type !== claiming_1.SparkAirdropType.SPARK_IGNITION);
|
|
65
|
+
allClaimData.push({ walletAddress, data: filteredData });
|
|
66
|
+
// Collect contract call data
|
|
67
|
+
filteredData.forEach((airdropInfo) => {
|
|
68
|
+
contractCallsData.push({
|
|
69
|
+
user: airdropInfo.wallet_address,
|
|
70
|
+
tokenAddress: airdropInfo.token_address,
|
|
71
|
+
epoch: airdropInfo.epoch,
|
|
72
|
+
type: airdropInfo.type,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Batch all contract calls
|
|
77
|
+
const cumulativeClaimedAmounts = yield getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData);
|
|
78
|
+
// Process results
|
|
79
|
+
const results = {};
|
|
80
|
+
let contractCallIndex = 0;
|
|
81
|
+
for (const { walletAddress, data } of allClaimData) {
|
|
82
|
+
if (data.length === 0) {
|
|
83
|
+
results[walletAddress.toLowerCase()] = [];
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const processedRewards = [];
|
|
87
|
+
for (let i = 0; i < data.length; i++) {
|
|
88
|
+
const rewardInfo = data[i];
|
|
89
|
+
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(rewardInfo.token_address);
|
|
90
|
+
const claimedAmount = cumulativeClaimedAmounts[contractCallIndex];
|
|
91
|
+
contractCallIndex++;
|
|
92
|
+
const amount = new decimal_js_1.default(rewardInfo.amount_normalized).minus(claimedAmount).toString();
|
|
93
|
+
if (new decimal_js_1.default(amount).gt('0')) {
|
|
94
|
+
processedRewards.push({
|
|
95
|
+
symbol: assetInfo.symbol,
|
|
96
|
+
underlyingSymbol: assetInfo.symbol,
|
|
97
|
+
amount,
|
|
98
|
+
claimType: claiming_1.ClaimType.SPARK_AIRDROP,
|
|
99
|
+
tokenAddress: rewardInfo.token_address,
|
|
100
|
+
walletAddress: rewardInfo.wallet_address,
|
|
101
|
+
label: 'Spark Airdrop',
|
|
102
|
+
additionalClaimFields: {
|
|
103
|
+
merkleRoot: rewardInfo.root_hash,
|
|
104
|
+
merkleProofs: rewardInfo.proof,
|
|
105
|
+
epoch: rewardInfo.epoch,
|
|
106
|
+
rewardType: rewardInfo.type,
|
|
107
|
+
allRewardsAmount: rewardInfo.amount_normalized,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
results[walletAddress.toLowerCase()] = processedRewards;
|
|
113
|
+
}
|
|
114
|
+
return results;
|
|
115
|
+
});
|
|
116
|
+
exports.fetchSparkAirdropRewards = fetchSparkAirdropRewards;
|
|
117
|
+
const fetchSparkRewards = (provider, network, walletAddress, marketAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const contract = (0, contracts_1.SparkIncentiveDataProviderContractViem)(provider, network);
|
|
119
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
120
|
+
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
121
|
+
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
122
|
+
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
123
|
+
return acc;
|
|
124
|
+
}, []);
|
|
125
|
+
const allATokens = tokensData.reduce((acc, val) => {
|
|
126
|
+
acc.push(val.aTokenIncentivesUserData.tokenAddress);
|
|
127
|
+
acc.push(val.vTokenIncentivesUserData.tokenAddress);
|
|
128
|
+
return acc;
|
|
129
|
+
}, []);
|
|
130
|
+
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => {
|
|
131
|
+
const sparkRewardsContract = (0, contracts_1.SparkRewardsControllerViem)(provider, network);
|
|
132
|
+
return sparkRewardsContract.read.getAllUserRewards([[token], walletAddress]);
|
|
133
|
+
}));
|
|
134
|
+
// match amounts to token symbol, parse decimal amounts
|
|
135
|
+
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
136
|
+
const rewardsList = rewardForAAsset[0];
|
|
137
|
+
const amounts = rewardForAAsset[1];
|
|
138
|
+
const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
|
|
139
|
+
const aTokenAddress = allATokens[aaIndex];
|
|
140
|
+
return rewardsList.map((rewardTokenAddress, rewardIndex) => {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => (0, utils_1.compareAddresses)(arr.rewardTokenAddress, rewardTokenAddress));
|
|
143
|
+
const amountWei = amounts[rewardIndex];
|
|
144
|
+
const amount = (0, utils_1.getEthAmountForDecimals)(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
|
|
145
|
+
const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
|
|
146
|
+
const underlyingAsset = symbol;
|
|
147
|
+
return ({
|
|
148
|
+
amount,
|
|
149
|
+
symbol,
|
|
150
|
+
underlyingAsset,
|
|
151
|
+
rewardTokenAddress,
|
|
152
|
+
aTokenAddress,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
// sum all unclaimed rewards of all markets per each token
|
|
157
|
+
// (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
|
|
158
|
+
const totalUnclaimedPerRewardToken = {};
|
|
159
|
+
rewardsPerAAssetWithInfo
|
|
160
|
+
.flat()
|
|
161
|
+
.forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
|
|
162
|
+
if (+amount > 0) {
|
|
163
|
+
if (!totalUnclaimedPerRewardToken[symbol]) {
|
|
164
|
+
totalUnclaimedPerRewardToken[symbol] = {
|
|
165
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
totalUnclaimedPerRewardToken[symbol].amount =
|
|
170
|
+
new decimal_js_1.default(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
|
|
171
|
+
totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, []);
|
|
175
|
+
return Object.values(totalUnclaimedPerRewardToken).map((reward) => ({
|
|
176
|
+
symbol: reward.symbol,
|
|
177
|
+
amount: reward.amount,
|
|
178
|
+
claimType: claiming_1.ClaimType.SPARK_REWARDS,
|
|
179
|
+
tokenAddress: reward.rewardTokenAddress,
|
|
180
|
+
underlyingSymbol: reward.underlyingAsset,
|
|
181
|
+
walletAddress,
|
|
182
|
+
label: 'Spark',
|
|
183
|
+
additionalClaimFields: {
|
|
184
|
+
sparkAssetAddresses: reward.aTokenAddresses,
|
|
185
|
+
},
|
|
186
|
+
}));
|
|
187
|
+
});
|
|
188
|
+
exports.fetchSparkRewards = fetchSparkRewards;
|