@metamask/social-controllers 2.8.0 → 3.0.0
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/CHANGELOG.md +24 -1
- package/dist/{SocialController-method-action-types.d.mts → SocialController-method-action-types.d.ts} +2 -2
- package/dist/SocialController-method-action-types.d.ts.map +1 -0
- package/dist/{SocialController-method-action-types.mjs → SocialController-method-action-types.js} +1 -1
- package/dist/SocialController-method-action-types.js.map +1 -0
- package/dist/{SocialController.d.mts → SocialController.d.ts} +8 -8
- package/dist/SocialController.d.ts.map +1 -0
- package/dist/{SocialController.mjs → SocialController.js} +3 -3
- package/dist/SocialController.js.map +1 -0
- package/dist/{SocialService-method-action-types.d.cts → SocialService-method-action-types.d.ts} +2 -2
- package/dist/SocialService-method-action-types.d.ts.map +1 -0
- package/dist/{SocialService-method-action-types.mjs → SocialService-method-action-types.js} +1 -1
- package/dist/SocialService-method-action-types.js.map +1 -0
- package/dist/{SocialService.d.cts → SocialService.d.ts} +9 -9
- package/dist/SocialService.d.ts.map +1 -0
- package/dist/{SocialService.mjs → SocialService.js} +128 -131
- package/dist/SocialService.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +10 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/social-constants.d.ts +28 -0
- package/dist/social-constants.d.ts.map +1 -0
- package/dist/{social-constants.mjs → social-constants.js} +1 -1
- package/dist/social-constants.js.map +1 -0
- package/dist/{social-types.d.mts → social-types.d.ts} +14 -14
- package/dist/social-types.d.ts.map +1 -0
- package/dist/{social-types.mjs → social-types.js} +2 -2
- package/dist/social-types.js.map +1 -0
- package/package.json +17 -21
- package/dist/SocialController-method-action-types.cjs +0 -7
- package/dist/SocialController-method-action-types.cjs.map +0 -1
- package/dist/SocialController-method-action-types.d.cts +0 -71
- package/dist/SocialController-method-action-types.d.cts.map +0 -1
- package/dist/SocialController-method-action-types.d.mts.map +0 -1
- package/dist/SocialController-method-action-types.mjs.map +0 -1
- package/dist/SocialController.cjs +0 -160
- package/dist/SocialController.cjs.map +0 -1
- package/dist/SocialController.d.cts +0 -80
- package/dist/SocialController.d.cts.map +0 -1
- package/dist/SocialController.d.mts.map +0 -1
- package/dist/SocialController.mjs.map +0 -1
- package/dist/SocialService-method-action-types.cjs +0 -7
- package/dist/SocialService-method-action-types.cjs.map +0 -1
- package/dist/SocialService-method-action-types.d.cts.map +0 -1
- package/dist/SocialService-method-action-types.d.mts +0 -194
- package/dist/SocialService-method-action-types.d.mts.map +0 -1
- package/dist/SocialService-method-action-types.mjs.map +0 -1
- package/dist/SocialService.cjs +0 -635
- package/dist/SocialService.cjs.map +0 -1
- package/dist/SocialService.d.cts.map +0 -1
- package/dist/SocialService.d.mts +0 -171
- package/dist/SocialService.d.mts.map +0 -1
- package/dist/SocialService.mjs.map +0 -1
- package/dist/index.cjs +0 -14
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -10
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -5
- package/dist/index.mjs.map +0 -1
- package/dist/social-constants.cjs +0 -31
- package/dist/social-constants.cjs.map +0 -1
- package/dist/social-constants.d.cts +0 -28
- package/dist/social-constants.d.cts.map +0 -1
- package/dist/social-constants.d.mts +0 -28
- package/dist/social-constants.d.mts.map +0 -1
- package/dist/social-constants.mjs.map +0 -1
- package/dist/social-types.cjs +0 -27
- package/dist/social-types.cjs.map +0 -1
- package/dist/social-types.d.cts +0 -343
- package/dist/social-types.d.cts.map +0 -1
- package/dist/social-types.d.mts.map +0 -1
- package/dist/social-types.mjs.map +0 -1
package/dist/SocialService.cjs
DELETED
|
@@ -1,635 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var _SocialService_instances, _a, _SocialService_baseUrl, _SocialService_v1Url_get, _SocialService_v2Url_get, _SocialService_throwIfNotOk, _SocialService_getAuthHeaders, _SocialService_fetchPositions;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SocialService = void 0;
|
|
16
|
-
const base_data_service_1 = require("@metamask/base-data-service");
|
|
17
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
19
|
-
const social_constants_js_1 = require("./social-constants.cjs");
|
|
20
|
-
const social_types_js_1 = require("./social-types.cjs");
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Superstruct validation schemas
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
const SocialHandlesStruct = (0, superstruct_1.type)({
|
|
25
|
-
twitter: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
26
|
-
farcaster: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
27
|
-
ens: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
28
|
-
lens: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
29
|
-
});
|
|
30
|
-
const ProfileSummaryStruct = (0, superstruct_1.type)({
|
|
31
|
-
profileId: (0, superstruct_1.string)(),
|
|
32
|
-
address: (0, superstruct_1.string)(),
|
|
33
|
-
name: (0, superstruct_1.string)(),
|
|
34
|
-
imageUrl: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
35
|
-
});
|
|
36
|
-
const PositionStruct = (0, superstruct_1.type)({
|
|
37
|
-
positionId: (0, superstruct_1.string)(),
|
|
38
|
-
tokenSymbol: (0, superstruct_1.string)(),
|
|
39
|
-
tokenName: (0, superstruct_1.string)(),
|
|
40
|
-
tokenAddress: (0, superstruct_1.string)(),
|
|
41
|
-
chain: (0, superstruct_1.string)(),
|
|
42
|
-
positionAmount: (0, superstruct_1.number)(),
|
|
43
|
-
isOpen: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
44
|
-
boughtUsd: (0, superstruct_1.number)(),
|
|
45
|
-
soldUsd: (0, superstruct_1.number)(),
|
|
46
|
-
realizedPnl: (0, superstruct_1.number)(),
|
|
47
|
-
costBasis: (0, superstruct_1.number)(),
|
|
48
|
-
trades: (0, superstruct_1.array)(social_types_js_1.TradeStruct),
|
|
49
|
-
lastTradeAt: (0, superstruct_1.number)(),
|
|
50
|
-
tokenImageUrl: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
51
|
-
currentValueUSD: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
52
|
-
pnlValueUsd: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
53
|
-
pnlPercent: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
54
|
-
perpPositionType: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.enums)(['long', 'short']))),
|
|
55
|
-
perpLeverage: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
56
|
-
positionAmountWithLeverage: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
57
|
-
});
|
|
58
|
-
const PaginationStruct = (0, superstruct_1.type)({
|
|
59
|
-
hasMore: (0, superstruct_1.boolean)(),
|
|
60
|
-
nextPage: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
61
|
-
});
|
|
62
|
-
const LeaderboardEntryStruct = (0, superstruct_1.type)({
|
|
63
|
-
rank: (0, superstruct_1.number)(),
|
|
64
|
-
addresses: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
65
|
-
profileId: (0, superstruct_1.string)(),
|
|
66
|
-
name: (0, superstruct_1.string)(),
|
|
67
|
-
imageUrl: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
68
|
-
pnl30d: (0, superstruct_1.number)(),
|
|
69
|
-
winRate30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
70
|
-
roiPercent30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
71
|
-
tradeCount30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
72
|
-
pnl7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
73
|
-
winRate7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
74
|
-
roiPercent7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
75
|
-
tradeCount7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
76
|
-
pnlPerChain: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.number)()),
|
|
77
|
-
followerCount: (0, superstruct_1.number)(),
|
|
78
|
-
socialHandles: SocialHandlesStruct,
|
|
79
|
-
});
|
|
80
|
-
const LeaderboardResponseStruct = (0, superstruct_1.type)({
|
|
81
|
-
traders: (0, superstruct_1.array)(LeaderboardEntryStruct),
|
|
82
|
-
});
|
|
83
|
-
const TraderProfileStruct = (0, superstruct_1.type)({
|
|
84
|
-
profileId: (0, superstruct_1.string)(),
|
|
85
|
-
address: (0, superstruct_1.string)(),
|
|
86
|
-
allAddresses: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
87
|
-
name: (0, superstruct_1.string)(),
|
|
88
|
-
imageUrl: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
89
|
-
});
|
|
90
|
-
const TraderStatsStruct = (0, superstruct_1.type)({
|
|
91
|
-
pnl30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
92
|
-
winRate30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
93
|
-
roiPercent30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
94
|
-
tradeCount30d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
95
|
-
pnl7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
96
|
-
winRate7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
97
|
-
roiPercent7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
98
|
-
tradeCount7d: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
99
|
-
medianHoldMinutes: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
100
|
-
});
|
|
101
|
-
const PerChainBreakdownStruct = (0, superstruct_1.type)({
|
|
102
|
-
perChainPnl: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.number)()),
|
|
103
|
-
perChainRoi: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.nullable)((0, superstruct_1.number)())),
|
|
104
|
-
perChainVolume: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.number)()),
|
|
105
|
-
perChainPnl7d: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.number)())),
|
|
106
|
-
perChainRoi7d: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.nullable)((0, superstruct_1.number)()))),
|
|
107
|
-
perChainVolume7d: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.number)())),
|
|
108
|
-
});
|
|
109
|
-
const TraderProfileResponseStruct = (0, superstruct_1.type)({
|
|
110
|
-
profile: TraderProfileStruct,
|
|
111
|
-
stats: TraderStatsStruct,
|
|
112
|
-
perChainBreakdown: PerChainBreakdownStruct,
|
|
113
|
-
socialHandles: SocialHandlesStruct,
|
|
114
|
-
followerCount: (0, superstruct_1.number)(),
|
|
115
|
-
followingCount: (0, superstruct_1.number)(),
|
|
116
|
-
});
|
|
117
|
-
const PositionsResponseStruct = (0, superstruct_1.type)({
|
|
118
|
-
positions: (0, superstruct_1.array)(PositionStruct),
|
|
119
|
-
pagination: PaginationStruct,
|
|
120
|
-
computedAt: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
121
|
-
});
|
|
122
|
-
// A feed item is a position plus the trader who made the trade (`actor`) and
|
|
123
|
-
// the item's creation timestamp. Reuses PositionStruct so the trade/position
|
|
124
|
-
// fields stay in lockstep with the positions endpoints.
|
|
125
|
-
const FeedItemStruct = (0, superstruct_1.assign)(PositionStruct, (0, superstruct_1.type)({
|
|
126
|
-
actor: ProfileSummaryStruct,
|
|
127
|
-
timestamp: (0, superstruct_1.number)(),
|
|
128
|
-
}));
|
|
129
|
-
const FeedPaginationStruct = (0, superstruct_1.type)({
|
|
130
|
-
olderCursor: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
|
|
131
|
-
newerCursor: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
|
|
132
|
-
});
|
|
133
|
-
const FeedResponseStruct = (0, superstruct_1.type)({
|
|
134
|
-
items: (0, superstruct_1.array)(FeedItemStruct),
|
|
135
|
-
pagination: FeedPaginationStruct,
|
|
136
|
-
});
|
|
137
|
-
const FollowersResponseStruct = (0, superstruct_1.type)({
|
|
138
|
-
followers: (0, superstruct_1.array)(ProfileSummaryStruct),
|
|
139
|
-
count: (0, superstruct_1.number)(),
|
|
140
|
-
});
|
|
141
|
-
const FollowingResponseStruct = (0, superstruct_1.type)({
|
|
142
|
-
following: (0, superstruct_1.array)(ProfileSummaryStruct),
|
|
143
|
-
count: (0, superstruct_1.number)(),
|
|
144
|
-
});
|
|
145
|
-
const FollowResponseStruct = (0, superstruct_1.type)({
|
|
146
|
-
followed: (0, superstruct_1.array)(ProfileSummaryStruct),
|
|
147
|
-
});
|
|
148
|
-
const UnfollowResponseStruct = (0, superstruct_1.type)({
|
|
149
|
-
unfollowed: (0, superstruct_1.array)(ProfileSummaryStruct),
|
|
150
|
-
});
|
|
151
|
-
// ---------------------------------------------------------------------------
|
|
152
|
-
// Messenger types
|
|
153
|
-
// ---------------------------------------------------------------------------
|
|
154
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
155
|
-
'fetchLeaderboard',
|
|
156
|
-
'fetchTraderProfile',
|
|
157
|
-
'fetchOpenPositions',
|
|
158
|
-
'fetchClosedPositions',
|
|
159
|
-
'fetchFollowers',
|
|
160
|
-
'fetchFollowing',
|
|
161
|
-
'fetchPositionById',
|
|
162
|
-
'fetchFeed',
|
|
163
|
-
'follow',
|
|
164
|
-
'unfollow',
|
|
165
|
-
'optOutOfLeaderboard',
|
|
166
|
-
'optInToLeaderboard',
|
|
167
|
-
'refreshNotificationPreferencesCache',
|
|
168
|
-
];
|
|
169
|
-
// ---------------------------------------------------------------------------
|
|
170
|
-
// Service
|
|
171
|
-
// ---------------------------------------------------------------------------
|
|
172
|
-
/**
|
|
173
|
-
* Data service wrapping social-api endpoints.
|
|
174
|
-
*/
|
|
175
|
-
class SocialService extends base_data_service_1.BaseDataService {
|
|
176
|
-
constructor({ messenger, baseUrl, policyOptions, }) {
|
|
177
|
-
super({ name: social_constants_js_1.serviceName, messenger, policyOptions });
|
|
178
|
-
_SocialService_instances.add(this);
|
|
179
|
-
_SocialService_baseUrl.set(this, void 0);
|
|
180
|
-
__classPrivateFieldSet(this, _SocialService_baseUrl, baseUrl, "f");
|
|
181
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Fetches the leaderboard of top traders.
|
|
185
|
-
*
|
|
186
|
-
* Calls `GET ${baseUrl}/leaderboard`.
|
|
187
|
-
*
|
|
188
|
-
* @param options - Optional query parameters for sorting, chain filtering, and limit.
|
|
189
|
-
* @returns The leaderboard response with ranked traders.
|
|
190
|
-
*/
|
|
191
|
-
async fetchLeaderboard(options) {
|
|
192
|
-
const leaderboardResponse = await this.fetchQuery({
|
|
193
|
-
queryKey: [`${this.name}:fetchLeaderboard`, options ?? null],
|
|
194
|
-
queryFn: async () => {
|
|
195
|
-
const { sort, chains, limit } = options ?? {};
|
|
196
|
-
const url = new URL(`${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/leaderboard`);
|
|
197
|
-
if (sort) {
|
|
198
|
-
url.searchParams.append('sort', sort);
|
|
199
|
-
}
|
|
200
|
-
if (chains) {
|
|
201
|
-
for (const chain of chains) {
|
|
202
|
-
url.searchParams.append('chains', chain);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (limit !== undefined) {
|
|
206
|
-
url.searchParams.append('limit', String(limit));
|
|
207
|
-
}
|
|
208
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
209
|
-
const response = await fetch(url.toString(), {
|
|
210
|
-
headers: authHeaders,
|
|
211
|
-
});
|
|
212
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED);
|
|
213
|
-
const leaderboardData = await response.json();
|
|
214
|
-
if (!(0, superstruct_1.is)(leaderboardData, LeaderboardResponseStruct)) {
|
|
215
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_LEADERBOARD_INVALID_RESPONSE);
|
|
216
|
-
}
|
|
217
|
-
return leaderboardData;
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
return leaderboardResponse;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Fetches a trader's profile by address or profile ID.
|
|
224
|
-
*
|
|
225
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.
|
|
226
|
-
*
|
|
227
|
-
* @param options - Options bag.
|
|
228
|
-
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
229
|
-
* @returns The trader profile response.
|
|
230
|
-
*/
|
|
231
|
-
async fetchTraderProfile(options) {
|
|
232
|
-
const { addressOrId } = options;
|
|
233
|
-
const traderProfileResponse = await this.fetchQuery({
|
|
234
|
-
queryKey: [`${this.name}:fetchTraderProfile`, addressOrId],
|
|
235
|
-
queryFn: async () => {
|
|
236
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/traders/${encodeURIComponent(addressOrId)}/profile`;
|
|
237
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
238
|
-
const response = await fetch(url, { headers: authHeaders });
|
|
239
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED);
|
|
240
|
-
const traderProfileData = await response.json();
|
|
241
|
-
if (!(0, superstruct_1.is)(traderProfileData, TraderProfileResponseStruct)) {
|
|
242
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_TRADER_PROFILE_INVALID_RESPONSE);
|
|
243
|
-
}
|
|
244
|
-
return traderProfileData;
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
return traderProfileResponse;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Fetches a trader's open positions.
|
|
251
|
-
*
|
|
252
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.
|
|
253
|
-
*
|
|
254
|
-
* @param options - Options bag.
|
|
255
|
-
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
256
|
-
* @param options.chain - Filter by chain.
|
|
257
|
-
* @param options.sort - Sort by 'value' or 'latest'.
|
|
258
|
-
* @param options.limit - Number of results per page.
|
|
259
|
-
* @param options.page - Page number (1-based).
|
|
260
|
-
* @returns The positions response.
|
|
261
|
-
*/
|
|
262
|
-
async fetchOpenPositions(options) {
|
|
263
|
-
return __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_fetchPositions).call(this, 'open', options);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Fetches a trader's closed positions.
|
|
267
|
-
*
|
|
268
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.
|
|
269
|
-
*
|
|
270
|
-
* @param options - Options bag.
|
|
271
|
-
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
272
|
-
* @param options.chain - Filter by chain.
|
|
273
|
-
* @param options.sort - Sort by 'value' or 'latest'.
|
|
274
|
-
* @param options.limit - Number of results per page.
|
|
275
|
-
* @param options.page - Page number (1-based).
|
|
276
|
-
* @returns The positions response.
|
|
277
|
-
*/
|
|
278
|
-
async fetchClosedPositions(options) {
|
|
279
|
-
return __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_fetchPositions).call(this, 'closed', options);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Fetches a trader's MetaMask followers.
|
|
283
|
-
*
|
|
284
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.
|
|
285
|
-
*
|
|
286
|
-
* @param options - Options bag.
|
|
287
|
-
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
288
|
-
* @returns The followers response.
|
|
289
|
-
*/
|
|
290
|
-
async fetchFollowers(options) {
|
|
291
|
-
const { addressOrId } = options;
|
|
292
|
-
const followersResponse = await this.fetchQuery({
|
|
293
|
-
queryKey: [`${this.name}:fetchFollowers`, addressOrId],
|
|
294
|
-
queryFn: async () => {
|
|
295
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/traders/${encodeURIComponent(addressOrId)}/followers`;
|
|
296
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
297
|
-
const response = await fetch(url, { headers: authHeaders });
|
|
298
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED);
|
|
299
|
-
const followersData = await response.json();
|
|
300
|
-
if (!(0, superstruct_1.is)(followersData, FollowersResponseStruct)) {
|
|
301
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_FOLLOWERS_INVALID_RESPONSE);
|
|
302
|
-
}
|
|
303
|
-
return followersData;
|
|
304
|
-
},
|
|
305
|
-
});
|
|
306
|
-
return followersResponse;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Fetches a single position by its unique ID.
|
|
310
|
-
*
|
|
311
|
-
* Calls `GET ${baseUrl}/traders/position/${positionId}`.
|
|
312
|
-
*
|
|
313
|
-
* @param options - Options bag.
|
|
314
|
-
* @param options.positionId - Unique position ID (UUID).
|
|
315
|
-
* @returns The position.
|
|
316
|
-
*/
|
|
317
|
-
async fetchPositionById(options) {
|
|
318
|
-
const { positionId } = options;
|
|
319
|
-
const positionResponse = await this.fetchQuery({
|
|
320
|
-
queryKey: [`${this.name}:fetchPositionById`, positionId],
|
|
321
|
-
queryFn: async () => {
|
|
322
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/traders/position/${encodeURIComponent(positionId)}`;
|
|
323
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
324
|
-
const response = await fetch(url, { headers: authHeaders });
|
|
325
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_POSITION_BY_ID_FAILED);
|
|
326
|
-
const positionData = await response.json();
|
|
327
|
-
if (!(0, superstruct_1.is)(positionData, PositionStruct)) {
|
|
328
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_POSITION_BY_ID_INVALID_RESPONSE);
|
|
329
|
-
}
|
|
330
|
-
return positionData;
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
return positionResponse;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Fetches a page of the trader-activity feed.
|
|
337
|
-
*
|
|
338
|
-
* Calls `GET ${baseUrl}/feed`. For the `following` scope the current user is
|
|
339
|
-
* identified server-side from the JWT sub claim carried in the Authorization
|
|
340
|
-
* header; the `leaderboard` scope is generic and shared by all users.
|
|
341
|
-
*
|
|
342
|
-
* Cursor pagination supports infinite scroll: pass `pagination.olderCursor`
|
|
343
|
-
* from a prior response back as `olderThan` to load older items, and
|
|
344
|
-
* `pagination.newerCursor` as `newerThan` to fetch newer items.
|
|
345
|
-
*
|
|
346
|
-
* @param options - Options bag.
|
|
347
|
-
* @param options.scope - `following` (default) or `leaderboard`.
|
|
348
|
-
* @param options.chains - Filter by one or more chains.
|
|
349
|
-
* @param options.limit - Number of results per page.
|
|
350
|
-
* @param options.olderThan - Cursor for older items (scroll down).
|
|
351
|
-
* @param options.newerThan - Cursor for newer items (refresh).
|
|
352
|
-
* @returns The feed response with items and pagination cursors.
|
|
353
|
-
*/
|
|
354
|
-
async fetchFeed(options) {
|
|
355
|
-
const feedResponse = await this.fetchQuery({
|
|
356
|
-
queryKey: [`${this.name}:fetchFeed`, options ?? null],
|
|
357
|
-
staleTime: 0,
|
|
358
|
-
queryFn: async () => {
|
|
359
|
-
const { scope, chains, limit, olderThan, newerThan } = options ?? {};
|
|
360
|
-
const url = new URL(`${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/feed`);
|
|
361
|
-
if (scope) {
|
|
362
|
-
url.searchParams.append('scope', scope);
|
|
363
|
-
}
|
|
364
|
-
if (chains) {
|
|
365
|
-
for (const chain of chains) {
|
|
366
|
-
url.searchParams.append('chains', chain);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (limit !== undefined) {
|
|
370
|
-
url.searchParams.append('limit', String(limit));
|
|
371
|
-
}
|
|
372
|
-
if (olderThan) {
|
|
373
|
-
url.searchParams.append('olderThan', olderThan);
|
|
374
|
-
}
|
|
375
|
-
if (newerThan) {
|
|
376
|
-
url.searchParams.append('newerThan', newerThan);
|
|
377
|
-
}
|
|
378
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
379
|
-
const response = await fetch(url.toString(), {
|
|
380
|
-
headers: authHeaders,
|
|
381
|
-
});
|
|
382
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_FEED_FAILED);
|
|
383
|
-
const feedData = await response.json();
|
|
384
|
-
if (!(0, superstruct_1.is)(feedData, FeedResponseStruct)) {
|
|
385
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_FEED_INVALID_RESPONSE);
|
|
386
|
-
}
|
|
387
|
-
return feedData;
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
return feedResponse;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Fetches the list of traders the current user is following.
|
|
394
|
-
*
|
|
395
|
-
* Calls `GET ${baseUrl}/users/me/following`. The caller is identified
|
|
396
|
-
* server-side from the JWT sub claim carried in the Authorization header.
|
|
397
|
-
*
|
|
398
|
-
* @returns The following response.
|
|
399
|
-
*/
|
|
400
|
-
async fetchFollowing() {
|
|
401
|
-
const followingResponse = await this.fetchQuery({
|
|
402
|
-
queryKey: [`${this.name}:fetchFollowing`],
|
|
403
|
-
staleTime: 0,
|
|
404
|
-
queryFn: async () => {
|
|
405
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/users/me/following`;
|
|
406
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
407
|
-
const response = await fetch(url, { headers: authHeaders });
|
|
408
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED);
|
|
409
|
-
const followingData = await response.json();
|
|
410
|
-
if (!(0, superstruct_1.is)(followingData, FollowingResponseStruct)) {
|
|
411
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FETCH_FOLLOWING_INVALID_RESPONSE);
|
|
412
|
-
}
|
|
413
|
-
return followingData;
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
return followingResponse;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Follows one or more traders on behalf of the current user.
|
|
420
|
-
*
|
|
421
|
-
* Calls `PUT ${baseUrl}/users/me/follows`. The caller is identified
|
|
422
|
-
* server-side from the JWT sub claim carried in the Authorization header.
|
|
423
|
-
*
|
|
424
|
-
* @param options - Options bag.
|
|
425
|
-
* @param options.targets - Array of wallet addresses or profile IDs to follow.
|
|
426
|
-
* @returns The follow response with confirmed follows.
|
|
427
|
-
*/
|
|
428
|
-
async follow(options) {
|
|
429
|
-
const { targets } = options;
|
|
430
|
-
const followResponse = await this.fetchQuery({
|
|
431
|
-
queryKey: [`${this.name}:follow`, targets],
|
|
432
|
-
staleTime: 0,
|
|
433
|
-
queryFn: async () => {
|
|
434
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/users/me/follows`;
|
|
435
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
436
|
-
const response = await fetch(url, {
|
|
437
|
-
method: 'PUT',
|
|
438
|
-
headers: { ...authHeaders, 'Content-Type': 'application/json' },
|
|
439
|
-
body: JSON.stringify({ targets }),
|
|
440
|
-
});
|
|
441
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.FOLLOW_FAILED);
|
|
442
|
-
const followData = await response.json();
|
|
443
|
-
if (!(0, superstruct_1.is)(followData, FollowResponseStruct)) {
|
|
444
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.FOLLOW_INVALID_RESPONSE);
|
|
445
|
-
}
|
|
446
|
-
return followData;
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
return followResponse;
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Unfollows one or more traders on behalf of the current user.
|
|
453
|
-
*
|
|
454
|
-
* Calls `DELETE ${baseUrl}/users/me/follows?targets=...`. Targets are sent
|
|
455
|
-
* as query params because Fastify does not parse request bodies on DELETE
|
|
456
|
-
* requests per RFC 9110. The caller is identified server-side from the JWT
|
|
457
|
-
* sub claim carried in the Authorization header.
|
|
458
|
-
*
|
|
459
|
-
* @param options - Options bag.
|
|
460
|
-
* @param options.targets - Array of wallet addresses or profile IDs to unfollow.
|
|
461
|
-
* @returns The unfollow response with confirmed unfollows.
|
|
462
|
-
*/
|
|
463
|
-
async unfollow(options) {
|
|
464
|
-
const { targets } = options;
|
|
465
|
-
const unfollowResponse = await this.fetchQuery({
|
|
466
|
-
queryKey: [`${this.name}:unfollow`, targets],
|
|
467
|
-
staleTime: 0,
|
|
468
|
-
queryFn: async () => {
|
|
469
|
-
const url = new URL(`${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/users/me/follows`);
|
|
470
|
-
for (const target of targets) {
|
|
471
|
-
url.searchParams.append('targets', target);
|
|
472
|
-
}
|
|
473
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
474
|
-
const response = await fetch(url.toString(), {
|
|
475
|
-
method: 'DELETE',
|
|
476
|
-
headers: authHeaders,
|
|
477
|
-
});
|
|
478
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.UNFOLLOW_FAILED);
|
|
479
|
-
const unfollowData = await response.json();
|
|
480
|
-
if (!(0, superstruct_1.is)(unfollowData, UnfollowResponseStruct)) {
|
|
481
|
-
throw new Error(social_constants_js_1.SocialServiceErrorMessage.UNFOLLOW_INVALID_RESPONSE);
|
|
482
|
-
}
|
|
483
|
-
return unfollowData;
|
|
484
|
-
},
|
|
485
|
-
});
|
|
486
|
-
return unfollowResponse;
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Opts the current user out of the PnL leaderboard.
|
|
490
|
-
*/
|
|
491
|
-
async optOutOfLeaderboard() {
|
|
492
|
-
await this.fetchQuery({
|
|
493
|
-
queryKey: [`${this.name}:optOutOfLeaderboard`],
|
|
494
|
-
staleTime: 0,
|
|
495
|
-
queryFn: async () => {
|
|
496
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/leaderboard/opt-out`;
|
|
497
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
498
|
-
const response = await fetch(url, {
|
|
499
|
-
method: 'POST',
|
|
500
|
-
headers: authHeaders,
|
|
501
|
-
});
|
|
502
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.LEADERBOARD_OPT_OUT_FAILED);
|
|
503
|
-
return null;
|
|
504
|
-
},
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Opts the current user back into the PnL leaderboard.
|
|
509
|
-
*/
|
|
510
|
-
async optInToLeaderboard() {
|
|
511
|
-
await this.fetchQuery({
|
|
512
|
-
queryKey: [`${this.name}:optInToLeaderboard`],
|
|
513
|
-
staleTime: 0,
|
|
514
|
-
queryFn: async () => {
|
|
515
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/leaderboard/opt-in`;
|
|
516
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
517
|
-
const response = await fetch(url, {
|
|
518
|
-
method: 'POST',
|
|
519
|
-
headers: authHeaders,
|
|
520
|
-
});
|
|
521
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.LEADERBOARD_OPT_IN_FAILED);
|
|
522
|
-
return null;
|
|
523
|
-
},
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Asks the social-api to refresh its cached copy of the current user's
|
|
528
|
-
* notification preferences.
|
|
529
|
-
*
|
|
530
|
-
* Calls `POST ${baseUrl}/notifications/preferences/cache-refresh`. The caller
|
|
531
|
-
* is identified server-side from the JWT sub claim carried in the
|
|
532
|
-
* Authorization header, so it can only ever refresh its own entry.
|
|
533
|
-
*
|
|
534
|
-
* The client calls this immediately after writing a preference change to
|
|
535
|
-
* Authenticated User Storage (AUS), which is the source of truth. The social
|
|
536
|
-
* api re-reads from AUS and repopulates its cache so the change is honoured
|
|
537
|
-
* near-instantly rather than after the cache TTL lapses. It is a pure
|
|
538
|
-
* optimisation on top of that bounded TTL: the write has already succeeded by
|
|
539
|
-
* the time this runs, so callers should treat it as best-effort and must not
|
|
540
|
-
* roll back the AUS write if it fails.
|
|
541
|
-
*/
|
|
542
|
-
async refreshNotificationPreferencesCache() {
|
|
543
|
-
await this.fetchQuery({
|
|
544
|
-
queryKey: [`${this.name}:refreshNotificationPreferencesCache`],
|
|
545
|
-
staleTime: 0,
|
|
546
|
-
queryFn: async () => {
|
|
547
|
-
const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/notifications/preferences/cache-refresh`;
|
|
548
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
549
|
-
const response = await fetch(url, {
|
|
550
|
-
method: 'POST',
|
|
551
|
-
headers: authHeaders,
|
|
552
|
-
});
|
|
553
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, social_constants_js_1.SocialServiceErrorMessage.NOTIFICATION_PREFERENCES_CACHE_REFRESH_FAILED);
|
|
554
|
-
return null;
|
|
555
|
-
},
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
exports.SocialService = SocialService;
|
|
560
|
-
_a = SocialService, _SocialService_baseUrl = new WeakMap(), _SocialService_instances = new WeakSet(), _SocialService_v1Url_get = function _SocialService_v1Url_get() {
|
|
561
|
-
return `${__classPrivateFieldGet(this, _SocialService_baseUrl, "f")}/api/v1`;
|
|
562
|
-
}, _SocialService_v2Url_get = function _SocialService_v2Url_get() {
|
|
563
|
-
return `${__classPrivateFieldGet(this, _SocialService_baseUrl, "f")}/api/v2`;
|
|
564
|
-
}, _SocialService_throwIfNotOk = function _SocialService_throwIfNotOk(response, message) {
|
|
565
|
-
if (!response.ok) {
|
|
566
|
-
throw new controller_utils_1.HttpError(response.status, `${message}: ${response.status}`);
|
|
567
|
-
}
|
|
568
|
-
}, _SocialService_getAuthHeaders =
|
|
569
|
-
/**
|
|
570
|
-
* Returns an Authorization header with a JWT bearer token obtained from the
|
|
571
|
-
* AuthenticationController.
|
|
572
|
-
*
|
|
573
|
-
* @returns A headers object containing the Authorization header.
|
|
574
|
-
*/
|
|
575
|
-
async function _SocialService_getAuthHeaders() {
|
|
576
|
-
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
577
|
-
return { Authorization: `Bearer ${token}` };
|
|
578
|
-
}, _SocialService_fetchPositions =
|
|
579
|
-
/**
|
|
580
|
-
* Shared helper for fetching open/closed positions.
|
|
581
|
-
*
|
|
582
|
-
* @param status - "open" or "closed".
|
|
583
|
-
* @param options - Options bag including addressOrId and query parameters.
|
|
584
|
-
* @returns The positions response.
|
|
585
|
-
*/
|
|
586
|
-
async function _SocialService_fetchPositions(status, options) {
|
|
587
|
-
const { addressOrId, chain, sort, limit, page } = options;
|
|
588
|
-
const failedMessage = status === 'open'
|
|
589
|
-
? social_constants_js_1.SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_FAILED
|
|
590
|
-
: social_constants_js_1.SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_FAILED;
|
|
591
|
-
const invalidMessage = status === 'open'
|
|
592
|
-
? social_constants_js_1.SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_INVALID_RESPONSE
|
|
593
|
-
: social_constants_js_1.SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_INVALID_RESPONSE;
|
|
594
|
-
const positionsResponse = await this.fetchQuery({
|
|
595
|
-
queryKey: [
|
|
596
|
-
`${this.name}:fetch${status === 'open' ? 'Open' : 'Closed'}Positions`,
|
|
597
|
-
addressOrId,
|
|
598
|
-
chain ?? null,
|
|
599
|
-
// sort is not used for open positions (v2 endpoint dropped it),
|
|
600
|
-
// so exclude it from the key to avoid redundant cache entries
|
|
601
|
-
status === 'closed' ? (sort ?? null) : null,
|
|
602
|
-
limit ?? null,
|
|
603
|
-
page ?? null,
|
|
604
|
-
],
|
|
605
|
-
queryFn: async () => {
|
|
606
|
-
const baseUrl = status === 'open' ? __classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v2Url_get) : __classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get);
|
|
607
|
-
const url = new URL(`${baseUrl}/traders/${encodeURIComponent(addressOrId)}/positions/${status}`);
|
|
608
|
-
if (chain) {
|
|
609
|
-
url.searchParams.append('chain', chain);
|
|
610
|
-
}
|
|
611
|
-
// sort is not supported on the v2 open-positions endpoint
|
|
612
|
-
if (sort && status === 'closed') {
|
|
613
|
-
url.searchParams.append('sort', sort);
|
|
614
|
-
}
|
|
615
|
-
if (limit !== undefined) {
|
|
616
|
-
url.searchParams.append('limit', String(limit));
|
|
617
|
-
}
|
|
618
|
-
if (page !== undefined) {
|
|
619
|
-
url.searchParams.append('page', String(page));
|
|
620
|
-
}
|
|
621
|
-
const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
|
|
622
|
-
const response = await fetch(url.toString(), {
|
|
623
|
-
headers: authHeaders,
|
|
624
|
-
});
|
|
625
|
-
__classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, failedMessage);
|
|
626
|
-
const positionsData = await response.json();
|
|
627
|
-
if (!(0, superstruct_1.is)(positionsData, PositionsResponseStruct)) {
|
|
628
|
-
throw new Error(invalidMessage);
|
|
629
|
-
}
|
|
630
|
-
return positionsData;
|
|
631
|
-
},
|
|
632
|
-
});
|
|
633
|
-
return positionsResponse;
|
|
634
|
-
};
|
|
635
|
-
//# sourceMappingURL=SocialService.cjs.map
|