@defisaver/positions-sdk 2.1.169-custom-fetching-dev → 2.1.169-custom-fetching-3-dev
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/aaveV2/index.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +4 -3
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/king.d.ts +2 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +3 -3
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -22
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/liquity/index.d.ts +4 -4
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +10 -10
- package/cjs/liquityV2/index.js +59 -59
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.js +45 -40
- package/cjs/services/merkl.d.ts +36 -2
- package/cjs/services/merkl.js +142 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/portfolio.d.ts +2 -0
- package/cjs/umbrella/index.d.ts +2 -2
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +4 -3
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +5 -4
- package/esm/claiming/king.d.ts +2 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +3 -3
- package/esm/claiming/spark.js +8 -7
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -22
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/liquity/index.d.ts +4 -4
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +10 -10
- package/esm/liquityV2/index.js +60 -60
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.js +47 -42
- package/esm/services/merkl.d.ts +36 -2
- package/esm/services/merkl.js +136 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/portfolio.d.ts +2 -0
- package/esm/umbrella/index.d.ts +2 -2
- package/esm/umbrella/index.js +5 -4
- package/package.json +1 -1
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +15 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +5 -3
- package/src/claiming/king.ts +6 -3
- package/src/claiming/spark.ts +9 -6
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +88 -70
- package/src/fluid/merkl.ts +12 -7
- package/src/liquity/index.ts +23 -23
- package/src/liquityV2/index.ts +64 -56
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +48 -41
- package/src/services/merkl.ts +152 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/types/merkl.ts +20 -0
- package/src/types/portfolio.ts +2 -0
- package/src/umbrella/index.ts +6 -5
package/cjs/services/merkl.js
CHANGED
|
@@ -9,31 +9,154 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.fetchAllMerklOpportunities = void 0;
|
|
12
|
+
exports.fetchMerklOpportunities = exports.fetchMerklOpportunitiesAt = exports.fetchMerklOpportunityAprAt = exports.fetchMerklOpportunitiesByIds = exports.fetchAllMerklCampaigns = exports.fetchAllMerklOpportunities = void 0;
|
|
13
|
+
const types_1 = require("../types");
|
|
13
14
|
const utils_1 = require("./utils");
|
|
14
|
-
const
|
|
15
|
+
const MERKL_API_URL = 'https://fe.defisaver.com/api/merkl';
|
|
16
|
+
const MERKL_OPPORTUNITIES_URL = `${MERKL_API_URL}/opportunities`;
|
|
17
|
+
const MERKL_CAMPAIGNS_URL = `${MERKL_API_URL}/campaigns`;
|
|
18
|
+
// Merkl caps list pages at 100 items; opportunity ids are batched below that so a single page
|
|
19
|
+
// covers every id in the batch.
|
|
20
|
+
const MERKL_MAX_PAGE_ITEMS = 100;
|
|
21
|
+
const OPPORTUNITY_ID_BATCH_SIZE = 50;
|
|
22
|
+
// APR history is fetched per opportunity, so historical lookups are throttled to keep a block with
|
|
23
|
+
// many live campaigns from firing every request at once.
|
|
24
|
+
const APR_RECORDS_CONCURRENCY = 10;
|
|
25
|
+
const SECONDS_PER_DAY = 24 * 60 * 60;
|
|
26
|
+
const merklGet = (url, query, label) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const res = yield fetch(`${url}?${new URLSearchParams(query)}`, { signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT) });
|
|
28
|
+
if (!res.ok)
|
|
29
|
+
throw new Error(`Failed to fetch Merkl ${label}`);
|
|
30
|
+
return res.json();
|
|
31
|
+
});
|
|
15
32
|
/**
|
|
16
|
-
* Fetches every page matching the query
|
|
17
|
-
* `items`
|
|
33
|
+
* Fetches every page matching the query, advancing `page` until an empty page comes back. When
|
|
34
|
+
* `items` is omitted, Merkl's default page size applies and no client-side maximum is imposed.
|
|
18
35
|
*/
|
|
19
|
-
const
|
|
20
|
-
const
|
|
36
|
+
const fetchAllMerklPages = (url, query, label, items) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const results = [];
|
|
21
38
|
let page = 0;
|
|
22
|
-
let
|
|
39
|
+
let pageResults;
|
|
23
40
|
do {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
|
|
27
|
-
});
|
|
28
|
-
if (!res.ok)
|
|
29
|
-
throw new Error(`Failed to fetch Merkl opportunities page ${page}`);
|
|
30
|
-
const data = yield res.json(); // eslint-disable-line no-await-in-loop
|
|
41
|
+
const pageQuery = Object.assign(Object.assign(Object.assign({}, query), { page: page.toString() }), (items ? { items: items.toString() } : {}));
|
|
42
|
+
const data = yield merklGet(url, pageQuery, `${label} page ${page}`); // eslint-disable-line no-await-in-loop
|
|
31
43
|
if (!Array.isArray(data))
|
|
32
|
-
throw new Error(`Invalid Merkl
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
throw new Error(`Invalid Merkl ${label} response on page ${page}`);
|
|
45
|
+
pageResults = data;
|
|
46
|
+
results.push(...pageResults);
|
|
35
47
|
page += 1;
|
|
36
|
-
} while (
|
|
37
|
-
return
|
|
48
|
+
} while (pageResults.length > 0);
|
|
49
|
+
return results;
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Fetches every opportunity matching the query. Merkl returns 20 opportunities by default, so omitting
|
|
53
|
+
* `items` and advancing `page` avoids imposing a client-side maximum on the result set.
|
|
54
|
+
*/
|
|
55
|
+
const fetchAllMerklOpportunities = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
return (fetchAllMerklPages(MERKL_OPPORTUNITIES_URL, query, 'opportunities'));
|
|
38
57
|
});
|
|
39
58
|
exports.fetchAllMerklOpportunities = fetchAllMerklOpportunities;
|
|
59
|
+
/** Fetches every campaign matching the query, e.g. `{ mainProtocolId: 'aave', status: 'LIVE,PAST' }`. */
|
|
60
|
+
const fetchAllMerklCampaigns = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
return (fetchAllMerklPages(MERKL_CAMPAIGNS_URL, query, 'campaigns', MERKL_MAX_PAGE_ITEMS));
|
|
62
|
+
});
|
|
63
|
+
exports.fetchAllMerklCampaigns = fetchAllMerklCampaigns;
|
|
64
|
+
/**
|
|
65
|
+
* Fetches the opportunities with the given Merkl-internal ids, regardless of their current status.
|
|
66
|
+
* Ids Merkl no longer serves (hidden or test campaigns) are simply absent from the result.
|
|
67
|
+
*/
|
|
68
|
+
const fetchMerklOpportunitiesByIds = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const batches = [];
|
|
70
|
+
for (let i = 0; i < ids.length; i += OPPORTUNITY_ID_BATCH_SIZE)
|
|
71
|
+
batches.push(ids.slice(i, i + OPPORTUNITY_ID_BATCH_SIZE));
|
|
72
|
+
const results = yield Promise.all(batches.map((batch) => merklGet(MERKL_OPPORTUNITIES_URL, { id: batch.join(','), items: MERKL_MAX_PAGE_ITEMS.toString() }, 'opportunities by id')));
|
|
73
|
+
return results.flatMap((data) => {
|
|
74
|
+
if (!Array.isArray(data))
|
|
75
|
+
throw new Error('Invalid Merkl opportunities by id response');
|
|
76
|
+
return data;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
exports.fetchMerklOpportunitiesByIds = fetchMerklOpportunitiesByIds;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the reward APR Merkl recorded for the opportunity at the given unix timestamp (seconds),
|
|
82
|
+
* or `undefined` when no campaign was computing for it then. Records are hourly buckets keyed by
|
|
83
|
+
* their start, newest first, so the first bucket at or before the timestamp carries the value in
|
|
84
|
+
* force at that moment; the window is a day wide to tolerate computation gaps.
|
|
85
|
+
*/
|
|
86
|
+
const fetchMerklOpportunityAprAt = (opportunityId, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
var _a;
|
|
88
|
+
const records = yield merklGet(`${MERKL_OPPORTUNITIES_URL}/${opportunityId}/apr-records`, {
|
|
89
|
+
grain: 'HOUR',
|
|
90
|
+
from: (timestamp - SECONDS_PER_DAY).toString(),
|
|
91
|
+
to: timestamp.toString(),
|
|
92
|
+
items: '1',
|
|
93
|
+
}, `APR records for opportunity ${opportunityId}`);
|
|
94
|
+
if (!Array.isArray(records))
|
|
95
|
+
throw new Error(`Invalid Merkl APR records response for opportunity ${opportunityId}`);
|
|
96
|
+
return (_a = records[0]) === null || _a === void 0 ? void 0 : _a.apr;
|
|
97
|
+
});
|
|
98
|
+
exports.fetchMerklOpportunityAprAt = fetchMerklOpportunityAprAt;
|
|
99
|
+
const mapWithConcurrency = (items, concurrency, fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const results = [];
|
|
101
|
+
for (let i = 0; i < items.length; i += concurrency) {
|
|
102
|
+
results.push(...yield Promise.all(items.slice(i, i + concurrency).map(fn))); // eslint-disable-line no-await-in-loop
|
|
103
|
+
}
|
|
104
|
+
return results;
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Reconstructs the opportunities that were live at `timestamp` (unix seconds), shaped like the
|
|
108
|
+
* live listing so the per-protocol reward mappers can consume either without knowing which they got:
|
|
109
|
+
* 1. campaigns for the protocol (and chain, when the query names one) whose [start, end] covers
|
|
110
|
+
* the timestamp identify the opportunities that were rewarded then — the live listing can't,
|
|
111
|
+
* since campaigns live then are mostly PAST now and ones live now didn't exist then;
|
|
112
|
+
* 2. those opportunities are loaded by id (works for PAST ones too) and narrowed to `query.type`;
|
|
113
|
+
* 3. each one's `apr` is replaced with the value Merkl recorded at the timestamp, and ones with no
|
|
114
|
+
* record then are dropped, since nothing was being computed for them.
|
|
115
|
+
* `status` is forced to LIVE so status filters downstream keep working, `campaigns` carries the
|
|
116
|
+
* covering campaigns, and a reward token breakdown is synthesized from the campaign's reward token
|
|
117
|
+
* when Merkl no longer serves one for the opportunity (it drops them once an opportunity is PAST).
|
|
118
|
+
* `query.status` is ignored: it describes the present, not the requested moment.
|
|
119
|
+
*/
|
|
120
|
+
const fetchMerklOpportunitiesAt = (query, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
var _a;
|
|
122
|
+
const campaignQuery = { status: 'LIVE,PAST', endTimestamp: timestamp.toString() };
|
|
123
|
+
if (query.mainProtocolId)
|
|
124
|
+
campaignQuery.mainProtocolId = query.mainProtocolId;
|
|
125
|
+
if (query.chainId)
|
|
126
|
+
campaignQuery.chainId = query.chainId;
|
|
127
|
+
// `endTimestamp` only narrows the listing upstream — the exact window check happens here
|
|
128
|
+
const campaigns = (yield (0, exports.fetchAllMerklCampaigns)(campaignQuery))
|
|
129
|
+
.filter((c) => { var _a, _b; return c.opportunityId && +((_a = c.startTimestamp) !== null && _a !== void 0 ? _a : 0) <= timestamp && timestamp <= +((_b = c.endTimestamp) !== null && _b !== void 0 ? _b : 0); });
|
|
130
|
+
const campaignsByOpportunity = {};
|
|
131
|
+
campaigns.forEach((c) => {
|
|
132
|
+
if (!campaignsByOpportunity[c.opportunityId])
|
|
133
|
+
campaignsByOpportunity[c.opportunityId] = [];
|
|
134
|
+
campaignsByOpportunity[c.opportunityId].push(c);
|
|
135
|
+
});
|
|
136
|
+
const opportunityIds = Object.keys(campaignsByOpportunity);
|
|
137
|
+
if (!opportunityIds.length)
|
|
138
|
+
return [];
|
|
139
|
+
const types = (_a = query.type) === null || _a === void 0 ? void 0 : _a.split(',').filter(Boolean);
|
|
140
|
+
const opportunities = (yield (0, exports.fetchMerklOpportunitiesByIds)(opportunityIds))
|
|
141
|
+
.filter((o) => !(types === null || types === void 0 ? void 0 : types.length) || types.includes(o.type));
|
|
142
|
+
const aprs = yield mapWithConcurrency(opportunities, APR_RECORDS_CONCURRENCY, (o) => (0, exports.fetchMerklOpportunityAprAt)(o.id, timestamp));
|
|
143
|
+
return opportunities.flatMap((o, i) => {
|
|
144
|
+
var _a, _b, _c;
|
|
145
|
+
const apr = aprs[i];
|
|
146
|
+
if (apr === undefined)
|
|
147
|
+
return [];
|
|
148
|
+
const coveringCampaigns = campaignsByOpportunity[o.id];
|
|
149
|
+
const rewardToken = (_a = coveringCampaigns.find((c) => c.rewardToken)) === null || _a === void 0 ? void 0 : _a.rewardToken;
|
|
150
|
+
const hasBreakdown = !!((_c = (_b = o.rewardsRecord) === null || _b === void 0 ? void 0 : _b.breakdowns) === null || _c === void 0 ? void 0 : _c.length);
|
|
151
|
+
return [Object.assign(Object.assign({}, o), { status: types_1.OpportunityStatus.LIVE, apr, campaigns: coveringCampaigns, rewardsRecord: hasBreakdown || !rewardToken ? o.rewardsRecord : Object.assign(Object.assign({}, o.rewardsRecord), { breakdowns: [{ token: rewardToken, campaignId: coveringCampaigns[0].campaignId }] }) })];
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
exports.fetchMerklOpportunitiesAt = fetchMerklOpportunitiesAt;
|
|
155
|
+
/**
|
|
156
|
+
* Live opportunities when no timestamp is given, otherwise the opportunities as they were at that
|
|
157
|
+
* unix timestamp (seconds) — see `fetchMerklOpportunitiesAt`.
|
|
158
|
+
*/
|
|
159
|
+
const fetchMerklOpportunities = (query, asOfTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
return (asOfTimestamp === undefined ? (0, exports.fetchAllMerklOpportunities)(query) : (0, exports.fetchMerklOpportunitiesAt)(query, asOfTimestamp));
|
|
161
|
+
});
|
|
162
|
+
exports.fetchMerklOpportunities = fetchMerklOpportunities;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { Client, PublicClient } from 'viem';
|
|
3
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
-
export declare const getEthPrice: (client: Client) => Promise<string>;
|
|
5
|
-
export declare const getUSDCPrice: (client: Client) => Promise<string>;
|
|
6
|
-
export declare const getCompPrice: (client: Client) => Promise<string>;
|
|
7
|
-
export declare const getWstETHPrice: (client: Client, network?: NetworkNumber) => Promise<string>;
|
|
8
|
-
export declare const getWeETHPrice: (client: Client, network?: NetworkNumber) => Promise<string>;
|
|
9
|
-
export declare const getWsrETHPrice: (client: Client, network?: NetworkNumber) => Promise<string>;
|
|
10
|
-
export declare const getSyrupUSDTPrice: (client: Client, network?: NetworkNumber) => Promise<string>;
|
|
11
|
-
export declare const getWstUSRPrice: (client: Client, network?: NetworkNumber) => Promise<string>;
|
|
3
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
+
export declare const getEthPrice: (client: Client, block?: Blockish) => Promise<string>;
|
|
5
|
+
export declare const getUSDCPrice: (client: Client, block?: Blockish) => Promise<string>;
|
|
6
|
+
export declare const getCompPrice: (client: Client, block?: Blockish) => Promise<string>;
|
|
7
|
+
export declare const getWstETHPrice: (client: Client, network?: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
8
|
+
export declare const getWeETHPrice: (client: Client, network?: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
9
|
+
export declare const getWsrETHPrice: (client: Client, network?: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
10
|
+
export declare const getSyrupUSDTPrice: (client: Client, network?: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
11
|
+
export declare const getWstUSRPrice: (client: Client, network?: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
12
12
|
export declare const getWstETHChainLinkPriceCalls: (client: PublicClient, network: NetworkNumber) => ({
|
|
13
13
|
address: `0x${string}`;
|
|
14
14
|
abi: readonly [{
|
|
@@ -1821,7 +1821,7 @@ export declare const parseWeETHPriceCalls: (_ethPrice: string, weETHrateAnswer:
|
|
|
1821
1821
|
ethPrice: Dec;
|
|
1822
1822
|
weETHRate: string;
|
|
1823
1823
|
};
|
|
1824
|
-
export declare const getWstETHPriceFluid: (client: PublicClient, network: NetworkNumber) => Promise<string>;
|
|
1825
|
-
export declare const getBTCPriceForFluid: (client: PublicClient, network: NetworkNumber) => Promise<string>;
|
|
1826
|
-
export declare const getEthPriceForFluid: (client: PublicClient, network: NetworkNumber) => Promise<string>;
|
|
1824
|
+
export declare const getWstETHPriceFluid: (client: PublicClient, network: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
1825
|
+
export declare const getBTCPriceForFluid: (client: PublicClient, network: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
1826
|
+
export declare const getEthPriceForFluid: (client: PublicClient, network: NetworkNumber, block?: Blockish) => Promise<string>;
|
|
1827
1827
|
export declare const getChainlinkAssetAddress: (symbol: string, network: NetworkNumber) => EthAddress;
|
|
@@ -18,78 +18,79 @@ const tokens_1 = require("@defisaver/tokens");
|
|
|
18
18
|
const contracts_1 = require("../contracts");
|
|
19
19
|
const common_1 = require("../types/common");
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
|
+
const viem_1 = require("./viem");
|
|
21
22
|
const constants_1 = require("../constants");
|
|
22
|
-
const getEthPrice = (
|
|
23
|
+
const getEthPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, block = 'latest') {
|
|
23
24
|
const contract = (0, contracts_1.ETHPriceFeedContractViem)(client, common_1.NetworkNumber.Eth);
|
|
24
|
-
const price = yield contract.read.latestAnswer();
|
|
25
|
+
const price = yield contract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block));
|
|
25
26
|
return new decimal_js_1.default(price.toString()).div(1e8).toString();
|
|
26
27
|
});
|
|
27
28
|
exports.getEthPrice = getEthPrice;
|
|
28
|
-
const getUSDCPrice = (
|
|
29
|
+
const getUSDCPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, block = 'latest') {
|
|
29
30
|
const contract = (0, contracts_1.USDCPriceFeedContractViem)(client, common_1.NetworkNumber.Eth);
|
|
30
|
-
const price = yield contract.read.latestAnswer();
|
|
31
|
+
const price = yield contract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block));
|
|
31
32
|
return new decimal_js_1.default(price.toString()).div(1e8).toString();
|
|
32
33
|
});
|
|
33
34
|
exports.getUSDCPrice = getUSDCPrice;
|
|
34
|
-
const getCompPrice = (
|
|
35
|
+
const getCompPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, block = 'latest') {
|
|
35
36
|
const contract = (0, contracts_1.COMPPriceFeedContractViem)(client, common_1.NetworkNumber.Eth);
|
|
36
|
-
const price = yield contract.read.latestAnswer();
|
|
37
|
+
const price = yield contract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block));
|
|
37
38
|
return new decimal_js_1.default(price.toString()).div(1e8).toString();
|
|
38
39
|
});
|
|
39
40
|
exports.getCompPrice = getCompPrice;
|
|
40
|
-
const getWstETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
|
|
41
|
+
const getWstETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth, block = 'latest') {
|
|
41
42
|
const wstETHFeedContract = (0, contracts_1.WstETHPriceFeedContractViem)(client, network);
|
|
42
43
|
const ethFeedContract = (0, contracts_1.ETHPriceFeedContractViem)(client, network);
|
|
43
44
|
const [ethPriceWei, wstETHRateWei, decimals] = yield Promise.all([
|
|
44
|
-
ethFeedContract.read.latestAnswer(),
|
|
45
|
-
wstETHFeedContract.read.latestRoundData(),
|
|
46
|
-
wstETHFeedContract.read.decimals(),
|
|
45
|
+
ethFeedContract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block)),
|
|
46
|
+
wstETHFeedContract.read.latestRoundData((0, viem_1.setViemBlockNumber)(block)),
|
|
47
|
+
wstETHFeedContract.read.decimals((0, viem_1.setViemBlockNumber)(block)),
|
|
47
48
|
]);
|
|
48
49
|
const ethPrice = new decimal_js_1.default(ethPriceWei.toString()).div(1e8);
|
|
49
50
|
const wstETHRate = (0, utils_1.getEthAmountForDecimals)(wstETHRateWei[1].toString(), decimals);
|
|
50
51
|
return new decimal_js_1.default(ethPrice).mul(wstETHRate).toString();
|
|
51
52
|
});
|
|
52
53
|
exports.getWstETHPrice = getWstETHPrice;
|
|
53
|
-
const getWeETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
|
|
54
|
+
const getWeETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth, block = 'latest') {
|
|
54
55
|
const weETHFeedContract = (0, contracts_1.WeETHPriceFeedContractViem)(client, network);
|
|
55
56
|
const ethFeedContract = (0, contracts_1.ETHPriceFeedContractViem)(client, network);
|
|
56
57
|
const [ethPriceWei, weETHRateWei, decimals] = yield Promise.all([
|
|
57
|
-
ethFeedContract.read.latestAnswer(),
|
|
58
|
-
weETHFeedContract.read.latestRoundData(),
|
|
59
|
-
weETHFeedContract.read.decimals(),
|
|
58
|
+
ethFeedContract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block)),
|
|
59
|
+
weETHFeedContract.read.latestRoundData((0, viem_1.setViemBlockNumber)(block)),
|
|
60
|
+
weETHFeedContract.read.decimals((0, viem_1.setViemBlockNumber)(block)),
|
|
60
61
|
]);
|
|
61
62
|
const ethPrice = new decimal_js_1.default(ethPriceWei.toString()).div(1e8);
|
|
62
63
|
const weETHRate = (0, utils_1.getEthAmountForDecimals)(weETHRateWei[1].toString(), decimals);
|
|
63
64
|
return new decimal_js_1.default(ethPrice).mul(weETHRate).toString();
|
|
64
65
|
});
|
|
65
66
|
exports.getWeETHPrice = getWeETHPrice;
|
|
66
|
-
const getWsrETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
|
|
67
|
+
const getWsrETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth, block = 'latest') {
|
|
67
68
|
const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
|
|
68
69
|
const [ethPriceWei, wrsETHRateWei] = yield Promise.all([
|
|
69
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('WETH', network).address, constants_1.USD_QUOTE]),
|
|
70
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wrsETH', network).address, (0, tokens_1.getAssetInfo)('WETH', network).address]),
|
|
70
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('WETH', network).address, constants_1.USD_QUOTE], (0, viem_1.setViemBlockNumber)(block)),
|
|
71
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wrsETH', network).address, (0, tokens_1.getAssetInfo)('WETH', network).address], (0, viem_1.setViemBlockNumber)(block)),
|
|
71
72
|
]);
|
|
72
73
|
const ethPrice = new decimal_js_1.default(ethPriceWei[1].toString()).div(1e8);
|
|
73
74
|
const wrsETHRate = (0, utils_1.getEthAmountForDecimals)(wrsETHRateWei[1].toString(), 18);
|
|
74
75
|
return new decimal_js_1.default(ethPrice).mul(wrsETHRate).toString();
|
|
75
76
|
});
|
|
76
77
|
exports.getWsrETHPrice = getWsrETHPrice;
|
|
77
|
-
const getSyrupUSDTPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
|
|
78
|
+
const getSyrupUSDTPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth, block = 'latest') {
|
|
78
79
|
const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
|
|
79
80
|
const [usdtPriceWei, syrupUSDTRateWei] = yield Promise.all([
|
|
80
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USDT', network).address, constants_1.USD_QUOTE]),
|
|
81
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('syrupUSDT', network).address, (0, tokens_1.getAssetInfo)('USDT', network).address]),
|
|
81
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USDT', network).address, constants_1.USD_QUOTE], (0, viem_1.setViemBlockNumber)(block)),
|
|
82
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('syrupUSDT', network).address, (0, tokens_1.getAssetInfo)('USDT', network).address], (0, viem_1.setViemBlockNumber)(block)),
|
|
82
83
|
]);
|
|
83
84
|
const usdtPrice = new decimal_js_1.default(usdtPriceWei[1].toString()).div(1e8);
|
|
84
85
|
const syrupUSDTPrice = (0, utils_1.getEthAmountForDecimals)(syrupUSDTRateWei[1].toString(), 18);
|
|
85
86
|
return new decimal_js_1.default(usdtPrice).mul(syrupUSDTPrice).toString();
|
|
86
87
|
});
|
|
87
88
|
exports.getSyrupUSDTPrice = getSyrupUSDTPrice;
|
|
88
|
-
const getWstUSRPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
|
|
89
|
+
const getWstUSRPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth, block = 'latest') {
|
|
89
90
|
const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
|
|
90
91
|
const [usrPriceWei, wstUSRRateWei] = yield Promise.all([
|
|
91
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USR', network).address, constants_1.USD_QUOTE]),
|
|
92
|
-
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wstUSR', network).address, (0, tokens_1.getAssetInfo)('USR', network).address]),
|
|
92
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USR', network).address, constants_1.USD_QUOTE], (0, viem_1.setViemBlockNumber)(block)),
|
|
93
|
+
feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wstUSR', network).address, (0, tokens_1.getAssetInfo)('USR', network).address], (0, viem_1.setViemBlockNumber)(block)),
|
|
93
94
|
]);
|
|
94
95
|
const usrPrice = new decimal_js_1.default(usrPriceWei[1].toString()).div(1e8);
|
|
95
96
|
const wstUSRPrice = (0, utils_1.getEthAmountForDecimals)(wstUSRRateWei[1].toString(), 18);
|
|
@@ -236,23 +237,23 @@ const parseWeETHPriceCalls = (_ethPrice, weETHrateAnswer, decimals) => {
|
|
|
236
237
|
};
|
|
237
238
|
exports.parseWeETHPriceCalls = parseWeETHPriceCalls;
|
|
238
239
|
// this is a fixed version, the original version is above but requires to refactor comp v3 function, so it's easier to just copy the function for now
|
|
239
|
-
const getWstETHPriceFluid = (
|
|
240
|
+
const getWstETHPriceFluid = (client_1, network_1, ...args_1) => __awaiter(void 0, [client_1, network_1, ...args_1], void 0, function* (client, network, block = 'latest') {
|
|
240
241
|
const calls = (0, exports.getWstETHChainLinkPriceCalls)(client, network);
|
|
241
|
-
const results = yield client.multicall({ contracts: calls });
|
|
242
|
+
const results = yield client.multicall(Object.assign({ contracts: calls }, (0, viem_1.setViemBlockNumber)(block)));
|
|
242
243
|
// @ts-ignore
|
|
243
244
|
const { ethPrice, wstETHRate } = (0, exports.parseWstETHPriceCalls)(results[0].result.toString(), results[1].result[1].toString(), results[2].result.toString());
|
|
244
245
|
return new decimal_js_1.default(ethPrice).mul(wstETHRate).toString();
|
|
245
246
|
});
|
|
246
247
|
exports.getWstETHPriceFluid = getWstETHPriceFluid;
|
|
247
|
-
const getBTCPriceForFluid = (
|
|
248
|
+
const getBTCPriceForFluid = (client_1, network_1, ...args_1) => __awaiter(void 0, [client_1, network_1, ...args_1], void 0, function* (client, network, block = 'latest') {
|
|
248
249
|
const contract = (0, contracts_1.BTCPriceFeedContractViem)(client, network);
|
|
249
|
-
const price = yield contract.read.latestAnswer();
|
|
250
|
+
const price = yield contract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block));
|
|
250
251
|
return new decimal_js_1.default(price).div(1e8).toString();
|
|
251
252
|
});
|
|
252
253
|
exports.getBTCPriceForFluid = getBTCPriceForFluid;
|
|
253
|
-
const getEthPriceForFluid = (
|
|
254
|
+
const getEthPriceForFluid = (client_1, network_1, ...args_1) => __awaiter(void 0, [client_1, network_1, ...args_1], void 0, function* (client, network, block = 'latest') {
|
|
254
255
|
const contract = (0, contracts_1.ETHPriceFeedContractViem)(client, network);
|
|
255
|
-
const price = yield contract.read.latestAnswer();
|
|
256
|
+
const price = yield contract.read.latestAnswer((0, viem_1.setViemBlockNumber)(block));
|
|
256
257
|
return new decimal_js_1.default(price).div(1e8).toString();
|
|
257
258
|
});
|
|
258
259
|
exports.getEthPriceForFluid = getEthPriceForFluid;
|
package/cjs/services/viem.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Abi } from 'viem';
|
|
1
|
+
import { type Abi, type Client } from 'viem';
|
|
2
2
|
import { Blockish, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
3
|
export declare const getViemChain: (network: NetworkNumber) => {
|
|
4
4
|
blockExplorers: {
|
|
@@ -4401,8 +4401,16 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
4401
4401
|
transport?: undefined;
|
|
4402
4402
|
type?: undefined;
|
|
4403
4403
|
uid?: undefined;
|
|
4404
|
-
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<import("viem").Transport, undefined, undefined>, "getBlockNumber" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client:
|
|
4404
|
+
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<import("viem").Transport, undefined, undefined>, "getBlockNumber" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: Client<import("viem").Transport, undefined, undefined, import("viem").PublicRpcSchema, import("viem").PublicActions<import("viem").Transport, undefined>>) => client) => Client<import("viem").Transport, undefined, undefined, import("viem").PublicRpcSchema, { [K in keyof client]: client[K]; } & import("viem").PublicActions<import("viem").Transport, undefined>>;
|
|
4405
4405
|
};
|
|
4406
|
+
/**
|
|
4407
|
+
* Unix timestamp (seconds) of the block, for data sources keyed by time rather than block (Merkl
|
|
4408
|
+
* reward history). `'latest'` resolves to `undefined` without an RPC call, since live sources need
|
|
4409
|
+
* no timestamp. A numeric block costs one `eth_getBlockByNumber` unless the caller already knows
|
|
4410
|
+
* its timestamp and passes it — flows that fetch many markets at one block resolve it once and
|
|
4411
|
+
* hand it down.
|
|
4412
|
+
*/
|
|
4413
|
+
export declare const getBlockTimestamp: (client: Client, block: Blockish, blockTimestamp?: number) => Promise<number | undefined>;
|
|
4406
4414
|
export declare const setViemBlockNumber: (block: Blockish) => {
|
|
4407
4415
|
blockNumber?: undefined;
|
|
4408
4416
|
} | {
|
package/cjs/services/viem.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setViemBlockNumber = exports.getViemProvider = exports.getViemChain = void 0;
|
|
12
|
+
exports.setViemBlockNumber = exports.getBlockTimestamp = exports.getViemProvider = exports.getViemChain = void 0;
|
|
4
13
|
exports.encodeCalldata = encodeCalldata;
|
|
5
14
|
const viem_1 = require("viem");
|
|
15
|
+
const actions_1 = require("viem/actions");
|
|
6
16
|
const chains_1 = require("viem/chains");
|
|
7
17
|
const common_1 = require("../types/common");
|
|
8
18
|
const getViemChain = (network) => {
|
|
@@ -26,6 +36,22 @@ const getViemChain = (network) => {
|
|
|
26
36
|
exports.getViemChain = getViemChain;
|
|
27
37
|
const getViemProvider = (provider, network, options) => (0, viem_1.createPublicClient)(Object.assign({ transport: (0, viem_1.custom)(provider), chain: (0, exports.getViemChain)(network) }, options));
|
|
28
38
|
exports.getViemProvider = getViemProvider;
|
|
39
|
+
/**
|
|
40
|
+
* Unix timestamp (seconds) of the block, for data sources keyed by time rather than block (Merkl
|
|
41
|
+
* reward history). `'latest'` resolves to `undefined` without an RPC call, since live sources need
|
|
42
|
+
* no timestamp. A numeric block costs one `eth_getBlockByNumber` unless the caller already knows
|
|
43
|
+
* its timestamp and passes it — flows that fetch many markets at one block resolve it once and
|
|
44
|
+
* hand it down.
|
|
45
|
+
*/
|
|
46
|
+
const getBlockTimestamp = (client, block, blockTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
if (block === 'latest')
|
|
48
|
+
return undefined;
|
|
49
|
+
if (blockTimestamp !== undefined)
|
|
50
|
+
return blockTimestamp;
|
|
51
|
+
const { timestamp } = yield (0, actions_1.getBlock)(client, { blockNumber: BigInt(block) });
|
|
52
|
+
return Number(timestamp);
|
|
53
|
+
});
|
|
54
|
+
exports.getBlockTimestamp = getBlockTimestamp;
|
|
29
55
|
const setViemBlockNumber = (block) => {
|
|
30
56
|
if (block === 'latest')
|
|
31
57
|
return {};
|
package/cjs/spark/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare const sparkEmodeCategoriesMapping: (extractedState: {
|
|
|
6
6
|
}, usedAssets: SparkUsedAssets) => {
|
|
7
7
|
[key: number]: SparkEModeCategoryDataMapping;
|
|
8
8
|
};
|
|
9
|
-
export declare const _getSparkMarketsData: (provider: Client, network: NetworkNumber, selectedMarket: SparkMarketData) => Promise<SparkMarketsData>;
|
|
10
|
-
export declare const getSparkMarketsData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: SparkMarketData) => Promise<SparkMarketsData>;
|
|
9
|
+
export declare const _getSparkMarketsData: (provider: Client, network: NetworkNumber, selectedMarket: SparkMarketData, blockNumber?: Blockish) => Promise<SparkMarketsData>;
|
|
10
|
+
export declare const getSparkMarketsData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: SparkMarketData, blockNumber?: Blockish) => Promise<SparkMarketsData>;
|
|
11
11
|
export declare const EMPTY_SPARK_DATA: {
|
|
12
12
|
usedAssets: {};
|
|
13
13
|
suppliedUsd: string;
|
|
@@ -34,10 +34,10 @@ export declare const _getSparkAccountData: (provider: Client, network: NetworkNu
|
|
|
34
34
|
selectedMarket: SparkMarketData;
|
|
35
35
|
assetsData: SparkAssetsData;
|
|
36
36
|
eModeCategoriesData: EModeCategoriesData;
|
|
37
|
-
}) => Promise<SparkPositionData>;
|
|
37
|
+
}, blockNumber?: Blockish) => Promise<SparkPositionData>;
|
|
38
38
|
export declare const getSparkAccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: {
|
|
39
39
|
selectedMarket: SparkMarketData;
|
|
40
40
|
assetsData: SparkAssetsData;
|
|
41
41
|
eModeCategoriesData: EModeCategoriesData;
|
|
42
|
-
}) => Promise<SparkPositionData>;
|
|
42
|
+
}, blockNumber?: Blockish) => Promise<SparkPositionData>;
|
|
43
43
|
export declare const getSparkFullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: SparkMarketData) => Promise<SparkPositionData>;
|
package/cjs/spark/index.js
CHANGED
|
@@ -50,14 +50,14 @@ const sparkEmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
50
50
|
return categoriesMapping;
|
|
51
51
|
};
|
|
52
52
|
exports.sparkEmodeCategoriesMapping = sparkEmodeCategoriesMapping;
|
|
53
|
-
const _getSparkMarketsData = (
|
|
53
|
+
const _getSparkMarketsData = (provider_1, network_1, selectedMarket_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, selectedMarket_1, ...args_1], void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
54
54
|
const marketAddress = selectedMarket.providerAddress;
|
|
55
55
|
const loanInfoContract = (0, contracts_1.SparkViewContractViem)(provider, network);
|
|
56
56
|
const sparkIncentivesContract = (0, contracts_1.SparkIncentiveDataProviderContractViem)(provider, network);
|
|
57
57
|
// eslint-disable-next-line prefer-const
|
|
58
58
|
let [loanInfo, rewardInfo] = yield Promise.all([
|
|
59
|
-
loanInfoContract.read.getFullTokensInfo([marketAddress, selectedMarket.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address)]),
|
|
60
|
-
sparkIncentivesContract.read.getReservesIncentivesData([marketAddress]),
|
|
59
|
+
loanInfoContract.read.getFullTokensInfo([marketAddress, selectedMarket.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address)], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
60
|
+
sparkIncentivesContract.read.getReservesIncentivesData([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
61
61
|
]);
|
|
62
62
|
rewardInfo = rewardInfo.reduce((all, market) => {
|
|
63
63
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -215,7 +215,7 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
|
|
|
215
215
|
return { assetsData: filteredAssetsData, eModeCategoriesData };
|
|
216
216
|
});
|
|
217
217
|
exports._getSparkMarketsData = _getSparkMarketsData;
|
|
218
|
-
const getSparkMarketsData = (
|
|
218
|
+
const getSparkMarketsData = (provider_1, network_1, selectedMarket_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, selectedMarket_1, ...args_1], void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') { return (0, exports._getSparkMarketsData)((0, viem_1.getViemProvider)(provider, network), network, selectedMarket, blockNumber); });
|
|
219
219
|
exports.getSparkMarketsData = getSparkMarketsData;
|
|
220
220
|
exports.EMPTY_SPARK_DATA = {
|
|
221
221
|
usedAssets: {},
|
|
@@ -244,7 +244,7 @@ const _getSparkAccountBalances = (provider, network, block, addressMapping, addr
|
|
|
244
244
|
exports._getSparkAccountBalances = _getSparkAccountBalances;
|
|
245
245
|
const getSparkAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getSparkAccountBalances)((0, viem_1.getViemProvider)(provider, network, { batch: { multicall: true } }), network, block, addressMapping, address); });
|
|
246
246
|
exports.getSparkAccountBalances = getSparkAccountBalances;
|
|
247
|
-
const _getSparkAccountData = (
|
|
247
|
+
const _getSparkAccountData = (provider_1, network_1, address_1, extractedState_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, extractedState_1, ...args_1], void 0, function* (provider, network, address, extractedState, blockNumber = 'latest') {
|
|
248
248
|
const { selectedMarket: market, assetsData, } = extractedState;
|
|
249
249
|
let payload = Object.assign(Object.assign({}, exports.EMPTY_SPARK_DATA), { lastUpdated: Date.now() });
|
|
250
250
|
if (!address) {
|
|
@@ -260,9 +260,9 @@ const _getSparkAccountData = (provider, network, address, extractedState) => __a
|
|
|
260
260
|
const _addresses = market.assets.map((a) => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address);
|
|
261
261
|
const middleAddressIndex = Math.floor(_addresses.length / 2); // split addresses in half to avoid gas limit by multicall
|
|
262
262
|
const [userEMode, tokenBalances1, tokenBalances2] = yield Promise.all([
|
|
263
|
-
lendingPoolContract.read.getUserEMode([address]),
|
|
264
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex)]),
|
|
265
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length)]),
|
|
263
|
+
lendingPoolContract.read.getUserEMode([address], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
264
|
+
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex)], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
265
|
+
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length)], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
266
266
|
]);
|
|
267
267
|
const loanInfo = [...tokenBalances1, ...tokenBalances2];
|
|
268
268
|
const usedAssets = {};
|
|
@@ -321,7 +321,7 @@ const _getSparkAccountData = (provider, network, address, extractedState) => __a
|
|
|
321
321
|
return payload;
|
|
322
322
|
});
|
|
323
323
|
exports._getSparkAccountData = _getSparkAccountData;
|
|
324
|
-
const getSparkAccountData = (
|
|
324
|
+
const getSparkAccountData = (provider_1, network_1, address_1, extractedState_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, extractedState_1, ...args_1], void 0, function* (provider, network, address, extractedState, blockNumber = 'latest') { return (0, exports._getSparkAccountData)((0, viem_1.getViemProvider)(provider, network), network, address, extractedState, blockNumber); });
|
|
325
325
|
exports.getSparkAccountData = getSparkAccountData;
|
|
326
326
|
const getSparkFullPositionData = (provider, network, address, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
327
327
|
const marketData = yield (0, exports.getSparkMarketsData)(provider, network, market);
|
package/cjs/types/merkl.d.ts
CHANGED
|
@@ -126,6 +126,24 @@ export type MerklOpportunity = {
|
|
|
126
126
|
}[];
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
+
/** One entry of Merkl's campaign listing: a campaign plus the opportunity it rewards. */
|
|
130
|
+
export type MerklCampaignListItem = MerklCampaign & {
|
|
131
|
+
opportunityId: string;
|
|
132
|
+
type: string;
|
|
133
|
+
rewardToken?: MerklOpportunity['rewardsRecord']['breakdowns'][number]['token'];
|
|
134
|
+
};
|
|
135
|
+
/** One bucket of an opportunity's APR history (`apr` is the last value recorded in the bucket). */
|
|
136
|
+
export type MerklAprRecord = {
|
|
137
|
+
timestamp: string;
|
|
138
|
+
date: string;
|
|
139
|
+
apr: number;
|
|
140
|
+
open: number;
|
|
141
|
+
min: number;
|
|
142
|
+
max: number;
|
|
143
|
+
avg: number;
|
|
144
|
+
samples: number;
|
|
145
|
+
hasUntrustedContribution: boolean;
|
|
146
|
+
};
|
|
129
147
|
export type MerkleRewardInfo = {
|
|
130
148
|
apy: string;
|
|
131
149
|
rewardTokenSymbol: string;
|
package/cjs/types/portfolio.d.ts
CHANGED
|
@@ -87,6 +87,8 @@ export interface CustomDeFiDataOptions {
|
|
|
87
87
|
isSim?: boolean;
|
|
88
88
|
/** viem multicall calldata cap in bytes; defaults to 250k (2k when isSim). */
|
|
89
89
|
batchSize?: number;
|
|
90
|
+
/** Every read is made at this block; defaults to latest. */
|
|
91
|
+
blockNumber?: number;
|
|
90
92
|
}
|
|
91
93
|
export interface CustomDeFiData {
|
|
92
94
|
positions: PortfolioPositionsData;
|
package/cjs/umbrella/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
-
export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<{
|
|
4
4
|
[k: string]: any;
|
|
5
5
|
}>;
|
package/cjs/umbrella/index.js
CHANGED
|
@@ -12,16 +12,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getUmbrellaData = void 0;
|
|
13
13
|
const contracts_1 = require("../contracts");
|
|
14
14
|
const utils_1 = require("../services/utils");
|
|
15
|
+
const viem_1 = require("../services/viem");
|
|
15
16
|
const umbrellaUtils_1 = require("./umbrellaUtils");
|
|
16
17
|
const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
|
|
17
18
|
const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
|
|
18
|
-
const getUmbrellaData = (
|
|
19
|
+
const getUmbrellaData = (provider_1, network_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, ...args_1], void 0, function* (provider, network, address, blockNumber = 'latest') {
|
|
19
20
|
const umbrellaView = (0, contracts_1.AaveUmbrellaViewViem)(provider, network);
|
|
20
21
|
const aaveV3View = (0, contracts_1.AaveV3ViewContractViem)(provider, network);
|
|
21
22
|
const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = yield Promise.all([
|
|
22
|
-
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
|
|
23
|
-
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
|
|
24
|
-
umbrellaView.read.getUserAggregatedData([umbrella, address]),
|
|
23
|
+
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
24
|
+
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
25
|
+
umbrellaView.read.getUserAggregatedData([umbrella, address], (0, viem_1.setViemBlockNumber)(blockNumber)),
|
|
25
26
|
]);
|
|
26
27
|
return Object.fromEntries(umbrellaUtils_1.tokenEntries.map(([symbol, tokenAddr]) => {
|
|
27
28
|
// @ts-ignore
|
package/esm/aaveV2/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
3
|
import { AaveMarketInfo, AaveV2AssetsData, AaveV2PositionData } from '../types';
|
|
4
|
-
export declare const _getAaveV2MarketsData: (provider: Client, network: NetworkNumber, selectedMarket: AaveMarketInfo) => Promise<{
|
|
4
|
+
export declare const _getAaveV2MarketsData: (provider: Client, network: NetworkNumber, selectedMarket: AaveMarketInfo, blockNumber?: Blockish) => Promise<{
|
|
5
5
|
assetsData: AaveV2AssetsData;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const getAaveV2MarketsData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: AaveMarketInfo) => Promise<{
|
|
7
|
+
export declare const getAaveV2MarketsData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: AaveMarketInfo, blockNumber?: Blockish) => Promise<{
|
|
8
8
|
assetsData: AaveV2AssetsData;
|
|
9
9
|
}>;
|
|
10
10
|
export declare const _getAaveV2AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
11
11
|
export declare const getAaveV2AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
12
|
-
export declare const _getAaveV2AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo) => Promise<AaveV2PositionData>;
|
|
13
|
-
export declare const getAaveV2AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo) => Promise<AaveV2PositionData>;
|
|
12
|
+
export declare const _getAaveV2AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo, blockNumber?: Blockish) => Promise<AaveV2PositionData>;
|
|
13
|
+
export declare const getAaveV2AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo, blockNumber?: Blockish) => Promise<AaveV2PositionData>;
|
|
14
14
|
export declare const getAaveV2FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV2PositionData>;
|