@defisaver/positions-sdk 2.0.12 → 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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/CLAUDE.md +32 -0
- package/README.md +64 -64
- 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/helpers/morphoBlueHelpers/index.js +66 -66
- 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/helpers/morphoBlueHelpers/index.js +66 -66
- 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 +47 -47
- package/src/aaveV2/index.ts +237 -236
- package/src/aaveV3/index.ts +586 -488
- 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/compoundV2/index.ts +240 -240
- package/src/compoundV3/index.ts +270 -270
- package/src/config/contracts.ts +1208 -1108
- package/src/constants/index.ts +10 -6
- package/src/contracts.ts +121 -108
- package/src/curveUsd/index.ts +250 -250
- package/src/eulerV2/index.ts +314 -314
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1568 -1568
- package/src/helpers/aaveHelpers/index.ts +170 -170
- package/src/helpers/compoundHelpers/index.ts +261 -261
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +259 -259
- package/src/helpers/fluidHelpers/index.ts +324 -324
- package/src/helpers/index.ts +10 -10
- package/src/helpers/liquityV2Helpers/index.ts +80 -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 +47 -45
- package/src/liquity/index.ts +160 -105
- package/src/liquityV2/index.ts +583 -408
- package/src/llamaLend/index.ts +296 -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 +259 -222
- package/src/portfolio/index.ts +533 -285
- package/src/services/priceService.ts +159 -159
- package/src/services/utils.ts +100 -64
- package/src/services/viem.ts +32 -32
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +457 -456
- package/src/staking/staking.ts +194 -193
- package/src/types/aave.ts +194 -194
- package/src/types/claiming.ts +109 -0
- package/src/types/common.ts +88 -88
- package/src/types/compound.ts +136 -136
- package/src/types/curveUsd.ts +121 -121
- package/src/types/euler.ts +174 -174
- package/src/types/fluid.ts +450 -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 +157 -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 +137 -137
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
|
@@ -0,0 +1,104 @@
|
|
|
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 { wethToEth } from '../services/utils';
|
|
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 getMorphoUnderlyingSymbol = (_symbol) => {
|
|
25
|
+
if (_symbol === 'MORPHO Legacy')
|
|
26
|
+
return 'MORPHO';
|
|
27
|
+
return wethToEth(_symbol);
|
|
28
|
+
};
|
|
29
|
+
export const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
if (!address)
|
|
31
|
+
return { claimable: '0' };
|
|
32
|
+
const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
|
|
33
|
+
if (!res.ok)
|
|
34
|
+
throw new Error(yield res.text());
|
|
35
|
+
return res.json();
|
|
36
|
+
});
|
|
37
|
+
export const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
var _a;
|
|
39
|
+
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
40
|
+
const apiDataPromises = walletAddresses.map(address => getMorphoBlueRewardsInfo(address));
|
|
41
|
+
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
42
|
+
// Process API data to get claimable tokens for each wallet
|
|
43
|
+
const allClaimableTokens = [];
|
|
44
|
+
const contractCallsData = [];
|
|
45
|
+
for (let i = 0; i < walletAddresses.length; i++) {
|
|
46
|
+
const walletAddress = walletAddresses[i];
|
|
47
|
+
const data = apiDataArray[i];
|
|
48
|
+
const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
const token = getAssetInfoByAddress(reward.asset.address);
|
|
51
|
+
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)) {
|
|
52
|
+
return acc;
|
|
53
|
+
}
|
|
54
|
+
// Store contract call data for batching
|
|
55
|
+
contractCallsData.push({
|
|
56
|
+
walletAddress,
|
|
57
|
+
tokenAddress: reward.asset.address,
|
|
58
|
+
distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
|
|
59
|
+
});
|
|
60
|
+
return [
|
|
61
|
+
...acc,
|
|
62
|
+
{
|
|
63
|
+
symbol: token.symbol,
|
|
64
|
+
underlyingSymbol: getMorphoUnderlyingSymbol(token.symbol),
|
|
65
|
+
tokenAddress: reward.asset.address,
|
|
66
|
+
amount: assetAmountInEth(reward.claimable, token.symbol),
|
|
67
|
+
walletAddress,
|
|
68
|
+
label: token.symbol,
|
|
69
|
+
claimType: ClaimType.MORPHO,
|
|
70
|
+
additionalClaimFields: {
|
|
71
|
+
originalAmount: reward.claimable,
|
|
72
|
+
distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
|
|
73
|
+
merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
|
|
74
|
+
isLegacy: token.symbol === 'MORPHO Legacy',
|
|
75
|
+
txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
}, [])) || [];
|
|
80
|
+
allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
|
|
81
|
+
}
|
|
82
|
+
// Batch all contract calls using multicall
|
|
83
|
+
const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
|
|
84
|
+
const distributorContract = createViemContractFromConfigFunc('MorphoDistributor', distributor)(provider, network);
|
|
85
|
+
return distributorContract.read.claimed([walletAddress, tokenAddress]);
|
|
86
|
+
});
|
|
87
|
+
const contractResults = yield Promise.all(contractPromises);
|
|
88
|
+
// Process results
|
|
89
|
+
const results = {};
|
|
90
|
+
let contractCallIndex = 0;
|
|
91
|
+
for (const { walletAddress, tokens } of allClaimableTokens) {
|
|
92
|
+
const updatedTokens = [];
|
|
93
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
94
|
+
const claimableToken = tokens[i];
|
|
95
|
+
const claimed = assetAmountInEth(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
|
|
96
|
+
contractCallIndex++;
|
|
97
|
+
const updatedToken = Object.assign({}, claimableToken);
|
|
98
|
+
updatedToken.amount = new Dec(claimableToken.amount).sub(claimed).toString();
|
|
99
|
+
updatedTokens.push(updatedToken);
|
|
100
|
+
}
|
|
101
|
+
results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new Dec(claimableToken.amount).gt(0));
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
});
|
|
@@ -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,179 @@
|
|
|
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 { createViemContractFromConfigFunc, SparkIncentiveDataProviderContractViem, SparkRewardsControllerViem, } from '../contracts';
|
|
13
|
+
import { ClaimType, SparkAirdropType } from '../types/claiming';
|
|
14
|
+
import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
|
|
15
|
+
const IGNITION_REWARDS = '0xCBA0C0a2a0B6Bb11233ec4EA85C5bFfea33e724d';
|
|
16
|
+
const PFL3_REWARDS = '0x7ac96180C4d6b2A328D3a19ac059D0E7Fc3C6d41';
|
|
17
|
+
export const fetchSpkAirdropRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
const res = yield fetch(`https://fe.defisaver.com/api/spark/get-spk-airdrop-rewards/${walletAddress}`, { signal: AbortSignal.timeout(3000) });
|
|
20
|
+
if (!res.ok)
|
|
21
|
+
throw new Error(yield res.text());
|
|
22
|
+
return yield res.json();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
console.error('External API Error: Error fetching SPK airdrop rewards:', err);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const getCumulativeClaimedSpkAirdrop = (provider, network, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const contractIgnition = createViemContractFromConfigFunc('SparkAirdrop', IGNITION_REWARDS)(provider, network);
|
|
31
|
+
const contractPFL = createViemContractFromConfigFunc('SparkAirdrop', PFL3_REWARDS)(provider, network);
|
|
32
|
+
const cumulativeAmounts = yield Promise.all(data.map((airdrop) => {
|
|
33
|
+
const { user, tokenAddress, epoch, type, } = airdrop;
|
|
34
|
+
const contract = type === SparkAirdropType.SPARK_IGNITION ? contractIgnition : contractPFL;
|
|
35
|
+
return contract.read.cumulativeClaimed([user, tokenAddress, BigInt(epoch)]);
|
|
36
|
+
}));
|
|
37
|
+
return cumulativeAmounts.map((amount, i) => assetAmountInEth(amount.toString(), getAssetInfoByAddress(data[i].tokenAddress).symbol).toString());
|
|
38
|
+
});
|
|
39
|
+
export const fetchSparkAirdropRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
41
|
+
const apiDataPromises = walletAddresses.map(address => fetchSpkAirdropRewards(address));
|
|
42
|
+
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
43
|
+
// Process API data and collect contract call data
|
|
44
|
+
const allClaimData = [];
|
|
45
|
+
const contractCallsData = [];
|
|
46
|
+
for (let i = 0; i < walletAddresses.length; i++) {
|
|
47
|
+
const walletAddress = walletAddresses[i];
|
|
48
|
+
const data = apiDataArray[i];
|
|
49
|
+
const falseResponse = !data;
|
|
50
|
+
const emptyResponse = data && data.length === 0;
|
|
51
|
+
const singleResponseWithoutAmount = data && data.length === 1 && !+data[0].amount;
|
|
52
|
+
if (falseResponse || emptyResponse || singleResponseWithoutAmount) {
|
|
53
|
+
allClaimData.push({ walletAddress, data: [] });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// Filter out IGNITION_REWARDS since they are no longer active
|
|
57
|
+
const filteredData = data.filter((rewardInfo) => rewardInfo.type !== SparkAirdropType.SPARK_IGNITION);
|
|
58
|
+
allClaimData.push({ walletAddress, data: filteredData });
|
|
59
|
+
// Collect contract call data
|
|
60
|
+
filteredData.forEach((airdropInfo) => {
|
|
61
|
+
contractCallsData.push({
|
|
62
|
+
user: airdropInfo.wallet_address,
|
|
63
|
+
tokenAddress: airdropInfo.token_address,
|
|
64
|
+
epoch: airdropInfo.epoch,
|
|
65
|
+
type: airdropInfo.type,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Batch all contract calls
|
|
70
|
+
const cumulativeClaimedAmounts = yield getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData);
|
|
71
|
+
// Process results
|
|
72
|
+
const results = {};
|
|
73
|
+
let contractCallIndex = 0;
|
|
74
|
+
for (const { walletAddress, data } of allClaimData) {
|
|
75
|
+
if (data.length === 0) {
|
|
76
|
+
results[walletAddress.toLowerCase()] = [];
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const processedRewards = [];
|
|
80
|
+
for (let i = 0; i < data.length; i++) {
|
|
81
|
+
const rewardInfo = data[i];
|
|
82
|
+
const assetInfo = getAssetInfoByAddress(rewardInfo.token_address);
|
|
83
|
+
const claimedAmount = cumulativeClaimedAmounts[contractCallIndex];
|
|
84
|
+
contractCallIndex++;
|
|
85
|
+
const amount = new Dec(rewardInfo.amount_normalized).minus(claimedAmount).toString();
|
|
86
|
+
if (new Dec(amount).gt('0')) {
|
|
87
|
+
processedRewards.push({
|
|
88
|
+
symbol: assetInfo.symbol,
|
|
89
|
+
underlyingSymbol: assetInfo.symbol,
|
|
90
|
+
amount,
|
|
91
|
+
claimType: ClaimType.SPARK_AIRDROP,
|
|
92
|
+
tokenAddress: rewardInfo.token_address,
|
|
93
|
+
walletAddress: rewardInfo.wallet_address,
|
|
94
|
+
label: 'Spark Airdrop',
|
|
95
|
+
additionalClaimFields: {
|
|
96
|
+
merkleRoot: rewardInfo.root_hash,
|
|
97
|
+
merkleProofs: rewardInfo.proof,
|
|
98
|
+
epoch: rewardInfo.epoch,
|
|
99
|
+
rewardType: rewardInfo.type,
|
|
100
|
+
allRewardsAmount: rewardInfo.amount_normalized,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
results[walletAddress.toLowerCase()] = processedRewards;
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
});
|
|
109
|
+
export const fetchSparkRewards = (provider, network, walletAddress, marketAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
const contract = SparkIncentiveDataProviderContractViem(provider, network);
|
|
111
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
112
|
+
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
113
|
+
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
114
|
+
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
115
|
+
return acc;
|
|
116
|
+
}, []);
|
|
117
|
+
const allATokens = tokensData.reduce((acc, val) => {
|
|
118
|
+
acc.push(val.aTokenIncentivesUserData.tokenAddress);
|
|
119
|
+
acc.push(val.vTokenIncentivesUserData.tokenAddress);
|
|
120
|
+
return acc;
|
|
121
|
+
}, []);
|
|
122
|
+
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => {
|
|
123
|
+
const sparkRewardsContract = SparkRewardsControllerViem(provider, network);
|
|
124
|
+
return sparkRewardsContract.read.getAllUserRewards([[token], walletAddress]);
|
|
125
|
+
}));
|
|
126
|
+
// match amounts to token symbol, parse decimal amounts
|
|
127
|
+
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
128
|
+
const rewardsList = rewardForAAsset[0];
|
|
129
|
+
const amounts = rewardForAAsset[1];
|
|
130
|
+
const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
|
|
131
|
+
const aTokenAddress = allATokens[aaIndex];
|
|
132
|
+
return rewardsList.map((rewardTokenAddress, rewardIndex) => {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
|
|
135
|
+
const amountWei = amounts[rewardIndex];
|
|
136
|
+
const amount = getEthAmountForDecimals(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
|
|
137
|
+
const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
|
|
138
|
+
const underlyingAsset = symbol;
|
|
139
|
+
return ({
|
|
140
|
+
amount,
|
|
141
|
+
symbol,
|
|
142
|
+
underlyingAsset,
|
|
143
|
+
rewardTokenAddress,
|
|
144
|
+
aTokenAddress,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
// sum all unclaimed rewards of all markets per each token
|
|
149
|
+
// (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
|
|
150
|
+
const totalUnclaimedPerRewardToken = {};
|
|
151
|
+
rewardsPerAAssetWithInfo
|
|
152
|
+
.flat()
|
|
153
|
+
.forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
|
|
154
|
+
if (+amount > 0) {
|
|
155
|
+
if (!totalUnclaimedPerRewardToken[symbol]) {
|
|
156
|
+
totalUnclaimedPerRewardToken[symbol] = {
|
|
157
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
totalUnclaimedPerRewardToken[symbol].amount =
|
|
162
|
+
new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
|
|
163
|
+
totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}, []);
|
|
167
|
+
return Object.values(totalUnclaimedPerRewardToken).map((reward) => ({
|
|
168
|
+
symbol: reward.symbol,
|
|
169
|
+
amount: reward.amount,
|
|
170
|
+
claimType: ClaimType.SPARK_REWARDS,
|
|
171
|
+
tokenAddress: reward.rewardTokenAddress,
|
|
172
|
+
underlyingSymbol: reward.underlyingAsset,
|
|
173
|
+
walletAddress,
|
|
174
|
+
label: 'Spark',
|
|
175
|
+
additionalClaimFields: {
|
|
176
|
+
sparkAssetAddresses: reward.aTokenAddresses,
|
|
177
|
+
},
|
|
178
|
+
}));
|
|
179
|
+
});
|