@defisaver/positions-sdk 2.1.137 → 2.1.139
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/cjs/aaveV4/index.js +26 -10
- package/cjs/aaveV4/merkl.d.ts +2 -1
- package/cjs/aaveV4/merkl.js +42 -35
- package/cjs/config/contracts.d.ts +0 -938
- package/cjs/config/contracts.js +1 -8
- package/cjs/contracts.d.ts +0 -23433
- package/cjs/contracts.js +2 -3
- package/cjs/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/cjs/helpers/aaveV4Helpers/index.js +22 -10
- package/cjs/helpers/index.d.ts +0 -1
- package/cjs/helpers/index.js +1 -2
- package/cjs/index.d.ts +1 -2
- package/cjs/index.js +1 -3
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/portfolio/discovery.d.ts +1 -1
- package/cjs/portfolio/discovery.js +1 -1
- package/cjs/portfolio/index.js +0 -32
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +3 -1
- package/cjs/staking/staking.js +1 -2
- package/cjs/types/aaveV4.d.ts +5 -0
- package/cjs/types/common.d.ts +4 -0
- package/cjs/types/common.js +6 -1
- package/cjs/types/index.d.ts +0 -1
- package/cjs/types/index.js +0 -1
- package/cjs/types/merkl.d.ts +3 -4
- package/cjs/types/portfolio.d.ts +0 -4
- package/esm/aaveV4/index.js +27 -11
- package/esm/aaveV4/merkl.d.ts +2 -1
- package/esm/aaveV4/merkl.js +41 -35
- package/esm/config/contracts.d.ts +0 -938
- package/esm/config/contracts.js +0 -6
- package/esm/contracts.d.ts +0 -23433
- package/esm/contracts.js +0 -1
- package/esm/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/esm/helpers/aaveV4Helpers/index.js +21 -10
- package/esm/helpers/index.d.ts +0 -1
- package/esm/helpers/index.js +0 -1
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/portfolio/discovery.d.ts +1 -1
- package/esm/portfolio/discovery.js +1 -1
- package/esm/portfolio/index.js +1 -33
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +1 -0
- package/esm/staking/staking.js +1 -2
- package/esm/types/aaveV4.d.ts +5 -0
- package/esm/types/common.d.ts +4 -0
- package/esm/types/common.js +5 -0
- package/esm/types/index.d.ts +0 -1
- package/esm/types/index.js +0 -1
- package/esm/types/merkl.d.ts +3 -4
- package/esm/types/portfolio.d.ts +0 -4
- package/package.json +1 -1
- package/src/aaveV4/index.ts +29 -11
- package/src/aaveV4/merkl.ts +41 -32
- package/src/config/contracts.ts +0 -6
- package/src/contracts.ts +0 -1
- package/src/helpers/aaveV4Helpers/index.ts +22 -9
- package/src/helpers/index.ts +0 -1
- package/src/index.ts +0 -2
- package/src/markets/index.ts +0 -1
- package/src/portfolio/discovery.ts +1 -1
- package/src/portfolio/index.ts +0 -33
- package/src/services/utils.ts +2 -0
- package/src/staking/staking.ts +1 -2
- package/src/types/aaveV4.ts +5 -0
- package/src/types/common.ts +5 -0
- package/src/types/index.ts +0 -1
- package/src/types/merkl.ts +3 -3
- package/src/types/portfolio.ts +0 -4
- package/cjs/eulerV2/index.d.ts +0 -47
- package/cjs/eulerV2/index.js +0 -225
- package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
- package/cjs/helpers/eulerHelpers/index.js +0 -231
- package/cjs/markets/euler/index.d.ts +0 -8
- package/cjs/markets/euler/index.js +0 -30
- package/cjs/types/euler.d.ts +0 -153
- package/cjs/types/euler.js +0 -14
- package/esm/eulerV2/index.d.ts +0 -47
- package/esm/eulerV2/index.js +0 -215
- package/esm/helpers/eulerHelpers/index.d.ts +0 -22
- package/esm/helpers/eulerHelpers/index.js +0 -218
- package/esm/markets/euler/index.d.ts +0 -8
- package/esm/markets/euler/index.js +0 -24
- package/esm/types/euler.d.ts +0 -153
- package/esm/types/euler.js +0 -11
- package/src/eulerV2/index.ts +0 -331
- package/src/helpers/eulerHelpers/index.ts +0 -232
- package/src/markets/euler/index.ts +0 -27
- package/src/types/euler.ts +0 -178
package/esm/aaveV4/merkl.js
CHANGED
|
@@ -9,14 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
11
|
import { LONGER_TIMEOUT } from '../services/utils';
|
|
12
|
-
import { IncentiveKind, OpportunityAction, OpportunityStatus, } from '../types';
|
|
12
|
+
import { IncentiveKind, IncentiveSide, OpportunityAction, OpportunityStatus, } from '../types';
|
|
13
13
|
/**
|
|
14
14
|
* Merkl tags Aave V4 reward campaigns by scope via the `type` field:
|
|
15
|
-
* - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per underlying
|
|
15
|
+
* - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per hub contract + underlying)
|
|
16
16
|
* - AAVE_V4_SPOKE_SUPPLY / AAVE_V4_SPOKE_BORROW → reward tied to a spoke (matched per spoke contract + underlying)
|
|
17
|
-
*
|
|
17
|
+
* Campaigns identify the underlying via `tokens[0]` and the scoping contract (the hub or spoke) via
|
|
18
|
+
* `explorerAddress`. The same underlying exists on several hubs (e.g. USDC on Prime and Paxos), so a
|
|
19
|
+
* hub campaign matched by underlying alone would leak onto every hub's reserves — a campaign whose
|
|
20
|
+
* `explorerAddress` isn't a contract any fetched reserve points to simply never matches.
|
|
18
21
|
*/
|
|
19
|
-
const
|
|
22
|
+
const scopeKey = (scopeAddress, underlying) => `${scopeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
|
|
20
23
|
const buildIncentive = (opportunity) => {
|
|
21
24
|
var _a, _b, _c, _d, _e;
|
|
22
25
|
const rewardToken = (_c = (_b = (_a = opportunity.rewardsRecord) === null || _a === void 0 ? void 0 : _a.breakdowns) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.token;
|
|
@@ -28,8 +31,37 @@ const buildIncentive = (opportunity) => {
|
|
|
28
31
|
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
29
32
|
};
|
|
30
33
|
};
|
|
31
|
-
export const
|
|
34
|
+
export const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
|
|
32
35
|
const result = { hub: {}, spoke: {} };
|
|
36
|
+
opportunities
|
|
37
|
+
.filter((o) => o.chainId === chainId)
|
|
38
|
+
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
39
|
+
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
40
|
+
.forEach((o) => {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const underlying = (_c = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
43
|
+
if (!underlying)
|
|
44
|
+
return;
|
|
45
|
+
const scopeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
46
|
+
if (!scopeAddress)
|
|
47
|
+
return;
|
|
48
|
+
const side = o.action === OpportunityAction.BORROW ? IncentiveSide.Borrow : IncentiveSide.Supply;
|
|
49
|
+
const incentive = buildIncentive(o);
|
|
50
|
+
const key = scopeKey(scopeAddress, underlying);
|
|
51
|
+
if (o.type.includes('HUB')) {
|
|
52
|
+
if (!result.hub[key])
|
|
53
|
+
result.hub[key] = {};
|
|
54
|
+
result.hub[key][side] = incentive;
|
|
55
|
+
}
|
|
56
|
+
else if (o.type.includes('SPOKE')) {
|
|
57
|
+
if (!result.spoke[key])
|
|
58
|
+
result.spoke[key] = {};
|
|
59
|
+
result.spoke[key][side] = incentive;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
65
|
try {
|
|
34
66
|
const res = yield fetch('https://fe.defisaver.com/api/merkl/opportunities?mainProtocolId=aave&type=AAVE_V4_HUB_SUPPLY,AAVE_V4_HUB_BORROW,AAVE_V4_SPOKE_SUPPLY,AAVE_V4_SPOKE_BORROW', {
|
|
35
67
|
signal: AbortSignal.timeout(LONGER_TIMEOUT),
|
|
@@ -37,37 +69,11 @@ export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, v
|
|
|
37
69
|
if (!res.ok)
|
|
38
70
|
throw new Error('Failed to fetch Aave V4 Merkle campaigns');
|
|
39
71
|
const opportunities = yield res.json();
|
|
40
|
-
opportunities
|
|
41
|
-
.filter((o) => o.chainId === chainId)
|
|
42
|
-
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
43
|
-
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
44
|
-
.forEach((o) => {
|
|
45
|
-
var _a, _b, _c, _d;
|
|
46
|
-
const underlying = (_c = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
47
|
-
if (!underlying)
|
|
48
|
-
return;
|
|
49
|
-
const side = o.action === OpportunityAction.BORROW ? 'borrow' : 'supply';
|
|
50
|
-
const incentive = buildIncentive(o);
|
|
51
|
-
if (o.type.includes('HUB')) {
|
|
52
|
-
if (!result.hub[underlying])
|
|
53
|
-
result.hub[underlying] = {};
|
|
54
|
-
result.hub[underlying][side] = incentive;
|
|
55
|
-
}
|
|
56
|
-
else if (o.type.includes('SPOKE')) {
|
|
57
|
-
const spokeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
58
|
-
if (!spokeAddress)
|
|
59
|
-
return;
|
|
60
|
-
const key = spokeKey(spokeAddress, underlying);
|
|
61
|
-
if (!result.spoke[key])
|
|
62
|
-
result.spoke[key] = {};
|
|
63
|
-
result.spoke[key][side] = incentive;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return result;
|
|
72
|
+
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
67
73
|
}
|
|
68
74
|
catch (e) {
|
|
69
75
|
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
|
70
|
-
return
|
|
76
|
+
return { hub: {}, spoke: {} };
|
|
71
77
|
}
|
|
72
78
|
});
|
|
73
79
|
/**
|
|
@@ -79,7 +85,7 @@ export const attachAaveV4MerklIncentives = (asset, spokeAddress, campaigns) => {
|
|
|
79
85
|
const underlying = (_a = asset.underlying) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
80
86
|
const baseSupply = asset.supplyIncentives || [];
|
|
81
87
|
const baseBorrow = asset.borrowIncentives || [];
|
|
82
|
-
const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[
|
|
83
|
-
const hubScoped = underlying ? campaigns.hub[underlying] : undefined;
|
|
88
|
+
const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[scopeKey(spokeAddress, underlying)] : undefined;
|
|
89
|
+
const hubScoped = (asset.hub && underlying) ? campaigns.hub[scopeKey(asset.hub, underlying)] : undefined;
|
|
84
90
|
return Object.assign(Object.assign({}, asset), { spokeSupplyIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.supply) ? [...baseSupply, spokeScoped.supply] : baseSupply, spokeBorrowIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.borrow) ? [...baseBorrow, spokeScoped.borrow] : baseBorrow, hubSupplyIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.supply) ? [...baseSupply, hubScoped.supply] : baseSupply, hubBorrowIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.borrow) ? [...baseBorrow, hubScoped.borrow] : baseBorrow });
|
|
85
91
|
};
|