@metamask/social-controllers 0.1.0 → 1.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.
@@ -2,12 +2,15 @@ import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent
2
2
  import { BaseDataService } from "@metamask/base-data-service";
3
3
  import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
4
4
  import type { Messenger } from "@metamask/messenger";
5
+ import type { AuthenticationController } from "@metamask/profile-sync-controller";
5
6
  import { serviceName } from "./social-constants.cjs";
6
7
  import type { FetchFollowersOptions, FetchFollowingOptions, FetchLeaderboardOptions, FetchPositionsOptions, FetchTraderProfileOptions, FollowersResponse, FollowingResponse, FollowOptions, FollowResponse, LeaderboardResponse, PositionsResponse, TraderProfileResponse, UnfollowOptions, UnfollowResponse } from "./social-types.cjs";
7
8
  import type { SocialServiceMethodActions } from "./SocialService-method-action-types.cjs";
8
9
  export type SocialServiceActions = SocialServiceMethodActions | DataServiceInvalidateQueriesAction<typeof serviceName>;
9
10
  export type SocialServiceEvents = DataServiceCacheUpdatedEvent<typeof serviceName> | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
10
- export type SocialServiceMessenger = Messenger<typeof serviceName, SocialServiceActions, SocialServiceEvents>;
11
+ type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerTokenAction;
12
+ type AllowedEvents = never;
13
+ export type SocialServiceMessenger = Messenger<typeof serviceName, SocialServiceActions | AllowedActions, SocialServiceEvents | AllowedEvents>;
11
14
  /**
12
15
  * Data service wrapping social-api endpoints.
13
16
  */
@@ -110,4 +113,5 @@ export declare class SocialService extends BaseDataService<typeof serviceName, S
110
113
  */
111
114
  unfollow(options: UnfollowOptions): Promise<UnfollowResponse>;
112
115
  }
116
+ export {};
113
117
  //# sourceMappingURL=SocialService.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SocialService.d.cts","sourceRoot":"","sources":["../src/SocialService.ts"],"names":[],"mapp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,CAAC,iBAAiB,CAAC;IA2B7B;;;;;;;;;OASG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA6B7D;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoGpE"}
@@ -2,12 +2,15 @@ import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent
2
2
  import { BaseDataService } from "@metamask/base-data-service";
3
3
  import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
4
4
  import type { Messenger } from "@metamask/messenger";
5
+ import type { AuthenticationController } from "@metamask/profile-sync-controller";
5
6
  import { serviceName } from "./social-constants.mjs";
6
7
  import type { FetchFollowersOptions, FetchFollowingOptions, FetchLeaderboardOptions, FetchPositionsOptions, FetchTraderProfileOptions, FollowersResponse, FollowingResponse, FollowOptions, FollowResponse, LeaderboardResponse, PositionsResponse, TraderProfileResponse, UnfollowOptions, UnfollowResponse } from "./social-types.mjs";
7
8
  import type { SocialServiceMethodActions } from "./SocialService-method-action-types.mjs";
8
9
  export type SocialServiceActions = SocialServiceMethodActions | DataServiceInvalidateQueriesAction<typeof serviceName>;
9
10
  export type SocialServiceEvents = DataServiceCacheUpdatedEvent<typeof serviceName> | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
10
- export type SocialServiceMessenger = Messenger<typeof serviceName, SocialServiceActions, SocialServiceEvents>;
11
+ type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerTokenAction;
12
+ type AllowedEvents = never;
13
+ export type SocialServiceMessenger = Messenger<typeof serviceName, SocialServiceActions | AllowedActions, SocialServiceEvents | AllowedEvents>;
11
14
  /**
12
15
  * Data service wrapping social-api endpoints.
13
16
  */
@@ -110,4 +113,5 @@ export declare class SocialService extends BaseDataService<typeof serviceName, S
110
113
  */
111
114
  unfollow(options: UnfollowOptions): Promise<UnfollowResponse>;
112
115
  }
116
+ export {};
113
117
  //# sourceMappingURL=SocialService.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SocialService.d.mts","sourceRoot":"","sources":["../src/SocialService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAarD,OAAO,EAAE,WAAW,EAA6B,+BAA2B;AAC5E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EACjB,2BAAuB;AACxB,OAAO,KAAK,EAAE,0BAA0B,EAAE,gDAA4C;AAkJtF,MAAM,MAAM,oBAAoB,GAC5B,0BAA0B,GAC1B,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE3D,MAAM,MAAM,mBAAmB,GAC3B,4BAA4B,CAAC,OAAO,WAAW,CAAC,GAChD,oCAAoC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7D,MAAM,MAAM,sBAAsB,GAAG,SAAS,CAC5C,OAAO,WAAW,EAClB,oBAAoB,EACpB,mBAAmB,CACpB,CAAC;AAMF;;GAEG;AACH,qBAAa,aAAc,SAAQ,eAAe,CAChD,OAAO,WAAW,EAClB,sBAAsB,CACvB;;gBAWa,EACV,SAAS,EACT,OAAO,EACP,aAAa,GACd,EAAE;QACD,SAAS,EAAE,sBAAsB,CAAC;QAClC,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAsBD;;;;;;;OAOG;IACG,gBAAgB,CACpB,OAAO,CAAC,EAAE,uBAAu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7B,OAAO,CAAC,iBAAiB,CAAC;IA0B7B;;;;;;;;OAQG;IACG,cAAc,CAClB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IA2B7B;;;;;;;;;OASG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA6B7D;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoGpE"}
@@ -9,11 +9,12 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  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");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _SocialService_instances, _a, _SocialService_baseUrl, _SocialService_v1Url_get, _SocialService_v2Url_get, _SocialService_throwIfNotOk, _SocialService_fetchPositions;
12
+ var _SocialService_instances, _a, _SocialService_baseUrl, _SocialService_v1Url_get, _SocialService_v2Url_get, _SocialService_throwIfNotOk, _SocialService_getAuthHeaders, _SocialService_fetchPositions;
13
13
  import { BaseDataService } from "@metamask/base-data-service";
14
14
  import { HttpError } from "@metamask/controller-utils";
15
15
  import { array, boolean, is, nullable, number, optional, record, string, type as structType } from "@metamask/superstruct";
16
16
  import { serviceName, SocialServiceErrorMessage } from "./social-constants.mjs";
17
+ import { TradeStruct } from "./social-types.mjs";
17
18
  // ---------------------------------------------------------------------------
18
19
  // Superstruct validation schemas
19
20
  // ---------------------------------------------------------------------------
@@ -29,13 +30,6 @@ const ProfileSummaryStruct = structType({
29
30
  name: string(),
30
31
  imageUrl: optional(nullable(string())),
31
32
  });
32
- const TradeStruct = structType({
33
- direction: string(),
34
- tokenAmount: number(),
35
- usdCost: number(),
36
- timestamp: number(),
37
- transactionHash: string(),
38
- });
39
33
  const PositionStruct = structType({
40
34
  tokenSymbol: string(),
41
35
  tokenName: string(),
@@ -48,6 +42,7 @@ const PositionStruct = structType({
48
42
  costBasis: number(),
49
43
  trades: array(TradeStruct),
50
44
  lastTradeAt: number(),
45
+ tokenImageUrl: optional(nullable(string())),
51
46
  currentValueUSD: optional(nullable(number())),
52
47
  pnlValueUsd: optional(nullable(number())),
53
48
  pnlPercent: optional(nullable(number())),
@@ -93,6 +88,7 @@ const TraderStatsStruct = structType({
93
88
  winRate7d: optional(nullable(number())),
94
89
  roiPercent7d: optional(nullable(number())),
95
90
  tradeCount7d: optional(nullable(number())),
91
+ medianHoldMinutes: optional(nullable(number())),
96
92
  });
97
93
  const PerChainBreakdownStruct = structType({
98
94
  perChainPnl: record(string(), number()),
@@ -178,7 +174,10 @@ export class SocialService extends BaseDataService {
178
174
  if (limit !== undefined) {
179
175
  url.searchParams.append('limit', String(limit));
180
176
  }
181
- const response = await fetch(url.toString());
177
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
178
+ const response = await fetch(url.toString(), {
179
+ headers: authHeaders,
180
+ });
182
181
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED);
183
182
  const leaderboardData = await response.json();
184
183
  if (!is(leaderboardData, LeaderboardResponseStruct)) {
@@ -204,7 +203,8 @@ export class SocialService extends BaseDataService {
204
203
  queryKey: [`${this.name}:fetchTraderProfile`, addressOrId],
205
204
  queryFn: async () => {
206
205
  const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/traders/${encodeURIComponent(addressOrId)}/profile`;
207
- const response = await fetch(url);
206
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
207
+ const response = await fetch(url, { headers: authHeaders });
208
208
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED);
209
209
  const traderProfileData = await response.json();
210
210
  if (!is(traderProfileData, TraderProfileResponseStruct)) {
@@ -262,7 +262,8 @@ export class SocialService extends BaseDataService {
262
262
  queryKey: [`${this.name}:fetchFollowers`, addressOrId],
263
263
  queryFn: async () => {
264
264
  const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/traders/${encodeURIComponent(addressOrId)}/followers`;
265
- const response = await fetch(url);
265
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
266
+ const response = await fetch(url, { headers: authHeaders });
266
267
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED);
267
268
  const followersData = await response.json();
268
269
  if (!is(followersData, FollowersResponseStruct)) {
@@ -289,7 +290,8 @@ export class SocialService extends BaseDataService {
289
290
  staleTime: 0,
290
291
  queryFn: async () => {
291
292
  const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/users/${encodeURIComponent(addressOrUid)}/following`;
292
- const response = await fetch(url);
293
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
294
+ const response = await fetch(url, { headers: authHeaders });
293
295
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED);
294
296
  const followingData = await response.json();
295
297
  if (!is(followingData, FollowingResponseStruct)) {
@@ -317,9 +319,10 @@ export class SocialService extends BaseDataService {
317
319
  staleTime: 0,
318
320
  queryFn: async () => {
319
321
  const url = `${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get)}/users/${encodeURIComponent(addressOrUid)}/follows`;
322
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
320
323
  const response = await fetch(url, {
321
324
  method: 'PUT',
322
- headers: { 'Content-Type': 'application/json' },
325
+ headers: { ...authHeaders, 'Content-Type': 'application/json' },
323
326
  body: JSON.stringify({ targets }),
324
327
  });
325
328
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.FOLLOW_FAILED);
@@ -354,7 +357,11 @@ export class SocialService extends BaseDataService {
354
357
  for (const target of targets) {
355
358
  url.searchParams.append('targets', target);
356
359
  }
357
- const response = await fetch(url.toString(), { method: 'DELETE' });
360
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
361
+ const response = await fetch(url.toString(), {
362
+ method: 'DELETE',
363
+ headers: authHeaders,
364
+ });
358
365
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, SocialServiceErrorMessage.UNFOLLOW_FAILED);
359
366
  const unfollowData = await response.json();
360
367
  if (!is(unfollowData, UnfollowResponseStruct)) {
@@ -374,6 +381,16 @@ _a = SocialService, _SocialService_baseUrl = new WeakMap(), _SocialService_insta
374
381
  if (!response.ok) {
375
382
  throw new HttpError(response.status, `${message}: ${response.status}`);
376
383
  }
384
+ }, _SocialService_getAuthHeaders =
385
+ /**
386
+ * Returns an Authorization header with a JWT bearer token obtained from the
387
+ * AuthenticationController.
388
+ *
389
+ * @returns A headers object containing the Authorization header.
390
+ */
391
+ async function _SocialService_getAuthHeaders() {
392
+ const token = await this.messenger.call('AuthenticationController:getBearerToken');
393
+ return { Authorization: `Bearer ${token}` };
377
394
  }, _SocialService_fetchPositions =
378
395
  /**
379
396
  * Shared helper for fetching open/closed positions.
@@ -402,7 +419,8 @@ async function _SocialService_fetchPositions(status, options) {
402
419
  page ?? null,
403
420
  ],
404
421
  queryFn: async () => {
405
- const url = new URL(`${__classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v2Url_get)}/traders/${encodeURIComponent(addressOrId)}/positions/${status}`);
422
+ const baseUrl = status === 'open' ? __classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v2Url_get) : __classPrivateFieldGet(this, _SocialService_instances, "a", _SocialService_v1Url_get);
423
+ const url = new URL(`${baseUrl}/traders/${encodeURIComponent(addressOrId)}/positions/${status}`);
406
424
  if (chain) {
407
425
  url.searchParams.append('chain', chain);
408
426
  }
@@ -416,7 +434,10 @@ async function _SocialService_fetchPositions(status, options) {
416
434
  if (page !== undefined) {
417
435
  url.searchParams.append('page', String(page));
418
436
  }
419
- const response = await fetch(url.toString());
437
+ const authHeaders = await __classPrivateFieldGet(this, _SocialService_instances, "m", _SocialService_getAuthHeaders).call(this);
438
+ const response = await fetch(url.toString(), {
439
+ headers: authHeaders,
440
+ });
420
441
  __classPrivateFieldGet(_a, _a, "m", _SocialService_throwIfNotOk).call(_a, response, failedMessage);
421
442
  const positionsData = await response.json();
422
443
  if (!is(positionsData, PositionsResponseStruct)) {
@@ -1 +1 @@
1
- {"version":3,"file":"SocialService.mjs","sourceRoot":"","sources":["../src/SocialService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAE9D,OAAO,EAAE,SAAS,EAAE,mCAAmC;AAEvD,OAAO,EACL,KAAK,EACL,OAAO,EACP,EAAE,EACF,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,IAAI,UAAU,EACnB,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,+BAA2B;AAmB5E,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,UAAU,CAAC;IACrC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACjC,IAAI,EAAE,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Event,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n is,\n nullable,\n number,\n optional,\n record,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { serviceName, SocialServiceErrorMessage } from './social-constants';\nimport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardResponse,\n PositionsResponse,\n TraderProfileResponse,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\nimport type { SocialServiceMethodActions } from './SocialService-method-action-types';\n\n// ---------------------------------------------------------------------------\n// Superstruct validation schemas\n// ---------------------------------------------------------------------------\n\nconst SocialHandlesStruct = structType({\n twitter: optional(nullable(string())),\n farcaster: optional(nullable(string())),\n ens: optional(nullable(string())),\n lens: optional(nullable(string())),\n});\n\nconst ProfileSummaryStruct = structType({\n profileId: string(),\n address: string(),\n name: string(),\n imageUrl: optional(nullable(string())),\n});\n\nconst TradeStruct = structType({\n direction: string(),\n tokenAmount: number(),\n usdCost: number(),\n timestamp: number(),\n transactionHash: string(),\n});\n\nconst PositionStruct = structType({\n tokenSymbol: string(),\n tokenName: string(),\n tokenAddress: string(),\n chain: string(),\n positionAmount: number(),\n boughtUsd: number(),\n soldUsd: number(),\n realizedPnl: number(),\n costBasis: number(),\n trades: array(TradeStruct),\n lastTradeAt: number(),\n currentValueUSD: optional(nullable(number())),\n pnlValueUsd: optional(nullable(number())),\n pnlPercent: optional(nullable(number())),\n});\n\nconst PaginationStruct = structType({\n hasMore: boolean(),\n nextPage: optional(number()),\n});\n\nconst LeaderboardEntryStruct = structType({\n rank: number(),\n addresses: array(string()),\n profileId: string(),\n name: string(),\n imageUrl: optional(nullable(string())),\n pnl30d: number(),\n winRate30d: optional(nullable(number())),\n roiPercent30d: optional(nullable(number())),\n tradeCount30d: optional(nullable(number())),\n pnl7d: optional(nullable(number())),\n winRate7d: optional(nullable(number())),\n roiPercent7d: optional(nullable(number())),\n tradeCount7d: optional(nullable(number())),\n pnlPerChain: record(string(), number()),\n followerCount: number(),\n socialHandles: SocialHandlesStruct,\n});\n\nconst LeaderboardResponseStruct = structType({\n traders: array(LeaderboardEntryStruct),\n});\n\nconst TraderProfileStruct = structType({\n profileId: string(),\n address: string(),\n allAddresses: array(string()),\n name: string(),\n imageUrl: optional(nullable(string())),\n});\n\nconst TraderStatsStruct = structType({\n pnl30d: optional(nullable(number())),\n winRate30d: optional(nullable(number())),\n roiPercent30d: optional(nullable(number())),\n tradeCount30d: optional(nullable(number())),\n pnl7d: optional(nullable(number())),\n winRate7d: optional(nullable(number())),\n roiPercent7d: optional(nullable(number())),\n tradeCount7d: optional(nullable(number())),\n});\n\nconst PerChainBreakdownStruct = structType({\n perChainPnl: record(string(), number()),\n perChainRoi: record(string(), nullable(number())),\n perChainVolume: record(string(), number()),\n});\n\nconst TraderProfileResponseStruct = structType({\n profile: TraderProfileStruct,\n stats: TraderStatsStruct,\n perChainBreakdown: PerChainBreakdownStruct,\n socialHandles: SocialHandlesStruct,\n followerCount: number(),\n followingCount: number(),\n});\n\nconst PositionsResponseStruct = structType({\n positions: array(PositionStruct),\n pagination: PaginationStruct,\n computedAt: optional(nullable(string())),\n});\n\nconst FollowersResponseStruct = structType({\n followers: array(ProfileSummaryStruct),\n count: number(),\n});\n\nconst FollowingResponseStruct = structType({\n following: array(ProfileSummaryStruct),\n count: number(),\n});\n\nconst FollowResponseStruct = structType({\n followed: array(ProfileSummaryStruct),\n});\n\nconst UnfollowResponseStruct = structType({\n unfollowed: array(ProfileSummaryStruct),\n});\n\n// ---------------------------------------------------------------------------\n// Messenger types\n// ---------------------------------------------------------------------------\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchLeaderboard',\n 'fetchTraderProfile',\n 'fetchOpenPositions',\n 'fetchClosedPositions',\n 'fetchFollowers',\n 'fetchFollowing',\n 'follow',\n 'unfollow',\n] as const;\n\nexport type SocialServiceActions =\n | SocialServiceMethodActions\n | DataServiceInvalidateQueriesAction<typeof serviceName>;\n\nexport type SocialServiceEvents =\n | DataServiceCacheUpdatedEvent<typeof serviceName>\n | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\nexport type SocialServiceMessenger = Messenger<\n typeof serviceName,\n SocialServiceActions,\n SocialServiceEvents\n>;\n\n// ---------------------------------------------------------------------------\n// Service\n// ---------------------------------------------------------------------------\n\n/**\n * Data service wrapping social-api endpoints.\n */\nexport class SocialService extends BaseDataService<\n typeof serviceName,\n SocialServiceMessenger\n> {\n readonly #baseUrl: string;\n\n get #v1Url(): string {\n return `${this.#baseUrl}/api/v1`;\n }\n\n get #v2Url(): string {\n return `${this.#baseUrl}/api/v2`;\n }\n\n constructor({\n messenger,\n baseUrl,\n policyOptions,\n }: {\n messenger: SocialServiceMessenger;\n baseUrl: string;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Throws an HttpError if the response is not ok.\n *\n * @param response - The fetch response to check.\n * @param message - The error message prefix from SocialServiceErrorMessage.\n */\n static #throwIfNotOk(response: Response, message: string): void {\n if (!response.ok) {\n throw new HttpError(response.status, `${message}: ${response.status}`);\n }\n }\n\n /**\n * Fetches the leaderboard of top traders.\n *\n * Calls `GET ${baseUrl}/leaderboard`.\n *\n * @param options - Optional query parameters for sorting, chain filtering, and limit.\n * @returns The leaderboard response with ranked traders.\n */\n async fetchLeaderboard(\n options?: FetchLeaderboardOptions,\n ): Promise<LeaderboardResponse> {\n const leaderboardResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchLeaderboard`, options ?? null],\n queryFn: async () => {\n const { sort, chains, limit } = options ?? {};\n const url = new URL(`${this.#v1Url}/leaderboard`);\n if (sort) {\n url.searchParams.append('sort', sort);\n }\n if (chains) {\n for (const chain of chains) {\n url.searchParams.append('chains', chain);\n }\n }\n if (limit !== undefined) {\n url.searchParams.append('limit', String(limit));\n }\n\n const response = await fetch(url.toString());\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED,\n );\n const leaderboardData = await response.json();\n if (!is(leaderboardData, LeaderboardResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_LEADERBOARD_INVALID_RESPONSE,\n );\n }\n return leaderboardData as LeaderboardResponse;\n },\n });\n\n return leaderboardResponse;\n }\n\n /**\n * Fetches a trader's profile by address or profile ID.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The trader profile response.\n */\n async fetchTraderProfile(\n options: FetchTraderProfileOptions,\n ): Promise<TraderProfileResponse> {\n const { addressOrId } = options;\n\n const traderProfileResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchTraderProfile`, addressOrId],\n queryFn: async () => {\n const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/profile`;\n const response = await fetch(url);\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED,\n );\n const traderProfileData = await response.json();\n if (!is(traderProfileData, TraderProfileResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_TRADER_PROFILE_INVALID_RESPONSE,\n );\n }\n return traderProfileData as TraderProfileResponse;\n },\n });\n\n return traderProfileResponse;\n }\n\n /**\n * Fetches a trader's open positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\n async fetchOpenPositions(\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n return this.#fetchPositions('open', options);\n }\n\n /**\n * Fetches a trader's closed positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\n async fetchClosedPositions(\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n return this.#fetchPositions('closed', options);\n }\n\n /**\n * Fetches a trader's MetaMask followers.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The followers response.\n */\n async fetchFollowers(\n options: FetchFollowersOptions,\n ): Promise<FollowersResponse> {\n const { addressOrId } = options;\n\n const followersResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchFollowers`, addressOrId],\n queryFn: async () => {\n const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/followers`;\n const response = await fetch(url);\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED,\n );\n const followersData = await response.json();\n if (!is(followersData, FollowersResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_FOLLOWERS_INVALID_RESPONSE,\n );\n }\n return followersData as FollowersResponse;\n },\n });\n\n return followersResponse;\n }\n\n /**\n * Fetches the list of traders a user is following.\n *\n * Calls `GET ${baseUrl}/users/${addressOrUid}/following`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID.\n * @returns The following response.\n */\n async fetchFollowing(\n options: FetchFollowingOptions,\n ): Promise<FollowingResponse> {\n const { addressOrUid } = options;\n\n const followingResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchFollowing`, addressOrUid],\n staleTime: 0,\n queryFn: async () => {\n const url = `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/following`;\n const response = await fetch(url);\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED,\n );\n const followingData = await response.json();\n if (!is(followingData, FollowingResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_FOLLOWING_INVALID_RESPONSE,\n );\n }\n return followingData as FollowingResponse;\n },\n });\n\n return followingResponse;\n }\n\n /**\n * Follows one or more traders.\n *\n * Calls `PUT ${baseUrl}/users/${addressOrUid}/follows`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\n * @param options.targets - Array of wallet addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\n async follow(options: FollowOptions): Promise<FollowResponse> {\n const { addressOrUid, targets } = options;\n\n const followResponse = await this.fetchQuery({\n queryKey: [`${this.name}:follow`, addressOrUid, targets],\n staleTime: 0,\n queryFn: async () => {\n const url = `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/follows`;\n const response = await fetch(url, {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ targets }),\n });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FOLLOW_FAILED,\n );\n const followData = await response.json();\n if (!is(followData, FollowResponseStruct)) {\n throw new Error(SocialServiceErrorMessage.FOLLOW_INVALID_RESPONSE);\n }\n return followData as FollowResponse;\n },\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders.\n *\n * Calls `DELETE ${baseUrl}/users/${addressOrUid}/follows?targets=...`.\n * Targets are sent as query params because Fastify does not parse\n * request bodies on DELETE requests per RFC 9110.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\n * @param options.targets - Array of wallet addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\n async unfollow(options: UnfollowOptions): Promise<UnfollowResponse> {\n const { addressOrUid, targets } = options;\n\n const unfollowResponse = await this.fetchQuery({\n queryKey: [`${this.name}:unfollow`, addressOrUid, targets],\n staleTime: 0,\n queryFn: async () => {\n const url = new URL(\n `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/follows`,\n );\n for (const target of targets) {\n url.searchParams.append('targets', target);\n }\n const response = await fetch(url.toString(), { method: 'DELETE' });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.UNFOLLOW_FAILED,\n );\n const unfollowData = await response.json();\n if (!is(unfollowData, UnfollowResponseStruct)) {\n throw new Error(SocialServiceErrorMessage.UNFOLLOW_INVALID_RESPONSE);\n }\n return unfollowData as UnfollowResponse;\n },\n });\n\n return unfollowResponse;\n }\n\n /**\n * Shared helper for fetching open/closed positions.\n *\n * @param status - \"open\" or \"closed\".\n * @param options - Options bag including addressOrId and query parameters.\n * @returns The positions response.\n */\n async #fetchPositions(\n status: 'open' | 'closed',\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n const { addressOrId, chain, sort, limit, page } = options;\n\n const failedMessage =\n status === 'open'\n ? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_FAILED\n : SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_FAILED;\n const invalidMessage =\n status === 'open'\n ? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_INVALID_RESPONSE\n : SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_INVALID_RESPONSE;\n\n const positionsResponse = await this.fetchQuery({\n queryKey: [\n `${this.name}:fetch${status === 'open' ? 'Open' : 'Closed'}Positions`,\n addressOrId,\n chain ?? null,\n // sort is not used for open positions (v2 endpoint dropped it),\n // so exclude it from the key to avoid redundant cache entries\n status === 'closed' ? (sort ?? null) : null,\n limit ?? null,\n page ?? null,\n ],\n queryFn: async () => {\n const url = new URL(\n `${this.#v2Url}/traders/${encodeURIComponent(addressOrId)}/positions/${status}`,\n );\n if (chain) {\n url.searchParams.append('chain', chain);\n }\n // sort is not supported on the v2 open-positions endpoint\n if (sort && status === 'closed') {\n url.searchParams.append('sort', sort);\n }\n if (limit !== undefined) {\n url.searchParams.append('limit', String(limit));\n }\n if (page !== undefined) {\n url.searchParams.append('page', String(page));\n }\n\n const response = await fetch(url.toString());\n SocialService.#throwIfNotOk(response, failedMessage);\n const positionsData = await response.json();\n if (!is(positionsData, PositionsResponseStruct)) {\n throw new Error(invalidMessage);\n }\n return positionsData as PositionsResponse;\n },\n });\n\n return positionsResponse;\n }\n}\n"]}
1
+ {"version":3,"file":"SocialService.mjs","sourceRoot":"","sources":["../src/SocialService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAE9D,OAAO,EAAE,SAAS,EAAE,mCAAmC;AAGvD,OAAO,EACL,KAAK,EACL,OAAO,EACP,EAAE,EACF,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,IAAI,UAAU,EACnB,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,+BAA2B;AAiB5E,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAG7C,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,UAAU,CAAC;IACrC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACjC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,UAAU,CAAC;IACtC,SAAS,EAAE,MAA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K,SAAS,EAAE,CAAC;gBACxB,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAClD,CAAC;YACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YAChD,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,+DAAgB,MAApB,IAAI,CAAkB,CAAC;YACjD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;gBAC3C,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YACH,uBAAA,EAAa,uCAAc,MAA3B,EAAa,EAAe,QAAQ,EAAE,aAAa,CAAC,CAAC;YACrD,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,uBAAuB,CAAC,EAAE,CAAC;gBAChD,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,aAAkC,CAAC;QAC5C,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport {\n array,\n boolean,\n is,\n nullable,\n number,\n optional,\n record,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { serviceName, SocialServiceErrorMessage } from './social-constants';\nimport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardResponse,\n PositionsResponse,\n TraderProfileResponse,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\nimport { TradeStruct } from './social-types';\nimport type { SocialServiceMethodActions } from './SocialService-method-action-types';\n\n// ---------------------------------------------------------------------------\n// Superstruct validation schemas\n// ---------------------------------------------------------------------------\n\nconst SocialHandlesStruct = structType({\n twitter: optional(nullable(string())),\n farcaster: optional(nullable(string())),\n ens: optional(nullable(string())),\n lens: optional(nullable(string())),\n});\n\nconst ProfileSummaryStruct = structType({\n profileId: string(),\n address: string(),\n name: string(),\n imageUrl: optional(nullable(string())),\n});\n\nconst PositionStruct = structType({\n tokenSymbol: string(),\n tokenName: string(),\n tokenAddress: string(),\n chain: string(),\n positionAmount: number(),\n boughtUsd: number(),\n soldUsd: number(),\n realizedPnl: number(),\n costBasis: number(),\n trades: array(TradeStruct),\n lastTradeAt: number(),\n tokenImageUrl: optional(nullable(string())),\n currentValueUSD: optional(nullable(number())),\n pnlValueUsd: optional(nullable(number())),\n pnlPercent: optional(nullable(number())),\n});\n\nconst PaginationStruct = structType({\n hasMore: boolean(),\n nextPage: optional(number()),\n});\n\nconst LeaderboardEntryStruct = structType({\n rank: number(),\n addresses: array(string()),\n profileId: string(),\n name: string(),\n imageUrl: optional(nullable(string())),\n pnl30d: number(),\n winRate30d: optional(nullable(number())),\n roiPercent30d: optional(nullable(number())),\n tradeCount30d: optional(nullable(number())),\n pnl7d: optional(nullable(number())),\n winRate7d: optional(nullable(number())),\n roiPercent7d: optional(nullable(number())),\n tradeCount7d: optional(nullable(number())),\n pnlPerChain: record(string(), number()),\n followerCount: number(),\n socialHandles: SocialHandlesStruct,\n});\n\nconst LeaderboardResponseStruct = structType({\n traders: array(LeaderboardEntryStruct),\n});\n\nconst TraderProfileStruct = structType({\n profileId: string(),\n address: string(),\n allAddresses: array(string()),\n name: string(),\n imageUrl: optional(nullable(string())),\n});\n\nconst TraderStatsStruct = structType({\n pnl30d: optional(nullable(number())),\n winRate30d: optional(nullable(number())),\n roiPercent30d: optional(nullable(number())),\n tradeCount30d: optional(nullable(number())),\n pnl7d: optional(nullable(number())),\n winRate7d: optional(nullable(number())),\n roiPercent7d: optional(nullable(number())),\n tradeCount7d: optional(nullable(number())),\n medianHoldMinutes: optional(nullable(number())),\n});\n\nconst PerChainBreakdownStruct = structType({\n perChainPnl: record(string(), number()),\n perChainRoi: record(string(), nullable(number())),\n perChainVolume: record(string(), number()),\n});\n\nconst TraderProfileResponseStruct = structType({\n profile: TraderProfileStruct,\n stats: TraderStatsStruct,\n perChainBreakdown: PerChainBreakdownStruct,\n socialHandles: SocialHandlesStruct,\n followerCount: number(),\n followingCount: number(),\n});\n\nconst PositionsResponseStruct = structType({\n positions: array(PositionStruct),\n pagination: PaginationStruct,\n computedAt: optional(nullable(string())),\n});\n\nconst FollowersResponseStruct = structType({\n followers: array(ProfileSummaryStruct),\n count: number(),\n});\n\nconst FollowingResponseStruct = structType({\n following: array(ProfileSummaryStruct),\n count: number(),\n});\n\nconst FollowResponseStruct = structType({\n followed: array(ProfileSummaryStruct),\n});\n\nconst UnfollowResponseStruct = structType({\n unfollowed: array(ProfileSummaryStruct),\n});\n\n// ---------------------------------------------------------------------------\n// Messenger types\n// ---------------------------------------------------------------------------\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchLeaderboard',\n 'fetchTraderProfile',\n 'fetchOpenPositions',\n 'fetchClosedPositions',\n 'fetchFollowers',\n 'fetchFollowing',\n 'follow',\n 'unfollow',\n] as const;\n\nexport type SocialServiceActions =\n | SocialServiceMethodActions\n | DataServiceInvalidateQueriesAction<typeof serviceName>;\n\nexport type SocialServiceEvents =\n | DataServiceCacheUpdatedEvent<typeof serviceName>\n | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\ntype AllowedEvents = never;\n\nexport type SocialServiceMessenger = Messenger<\n typeof serviceName,\n SocialServiceActions | AllowedActions,\n SocialServiceEvents | AllowedEvents\n>;\n\n// ---------------------------------------------------------------------------\n// Service\n// ---------------------------------------------------------------------------\n\n/**\n * Data service wrapping social-api endpoints.\n */\nexport class SocialService extends BaseDataService<\n typeof serviceName,\n SocialServiceMessenger\n> {\n readonly #baseUrl: string;\n\n get #v1Url(): string {\n return `${this.#baseUrl}/api/v1`;\n }\n\n get #v2Url(): string {\n return `${this.#baseUrl}/api/v2`;\n }\n\n constructor({\n messenger,\n baseUrl,\n policyOptions,\n }: {\n messenger: SocialServiceMessenger;\n baseUrl: string;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Throws an HttpError if the response is not ok.\n *\n * @param response - The fetch response to check.\n * @param message - The error message prefix from SocialServiceErrorMessage.\n */\n static #throwIfNotOk(response: Response, message: string): void {\n if (!response.ok) {\n throw new HttpError(response.status, `${message}: ${response.status}`);\n }\n }\n\n /**\n * Returns an Authorization header with a JWT bearer token obtained from the\n * AuthenticationController.\n *\n * @returns A headers object containing the Authorization header.\n */\n async #getAuthHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return { Authorization: `Bearer ${token}` };\n }\n\n /**\n * Fetches the leaderboard of top traders.\n *\n * Calls `GET ${baseUrl}/leaderboard`.\n *\n * @param options - Optional query parameters for sorting, chain filtering, and limit.\n * @returns The leaderboard response with ranked traders.\n */\n async fetchLeaderboard(\n options?: FetchLeaderboardOptions,\n ): Promise<LeaderboardResponse> {\n const leaderboardResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchLeaderboard`, options ?? null],\n queryFn: async () => {\n const { sort, chains, limit } = options ?? {};\n const url = new URL(`${this.#v1Url}/leaderboard`);\n if (sort) {\n url.searchParams.append('sort', sort);\n }\n if (chains) {\n for (const chain of chains) {\n url.searchParams.append('chains', chain);\n }\n }\n if (limit !== undefined) {\n url.searchParams.append('limit', String(limit));\n }\n\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url.toString(), {\n headers: authHeaders,\n });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED,\n );\n const leaderboardData = await response.json();\n if (!is(leaderboardData, LeaderboardResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_LEADERBOARD_INVALID_RESPONSE,\n );\n }\n return leaderboardData as LeaderboardResponse;\n },\n });\n\n return leaderboardResponse;\n }\n\n /**\n * Fetches a trader's profile by address or profile ID.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The trader profile response.\n */\n async fetchTraderProfile(\n options: FetchTraderProfileOptions,\n ): Promise<TraderProfileResponse> {\n const { addressOrId } = options;\n\n const traderProfileResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchTraderProfile`, addressOrId],\n queryFn: async () => {\n const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/profile`;\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url, { headers: authHeaders });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED,\n );\n const traderProfileData = await response.json();\n if (!is(traderProfileData, TraderProfileResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_TRADER_PROFILE_INVALID_RESPONSE,\n );\n }\n return traderProfileData as TraderProfileResponse;\n },\n });\n\n return traderProfileResponse;\n }\n\n /**\n * Fetches a trader's open positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\n async fetchOpenPositions(\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n return this.#fetchPositions('open', options);\n }\n\n /**\n * Fetches a trader's closed positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\n async fetchClosedPositions(\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n return this.#fetchPositions('closed', options);\n }\n\n /**\n * Fetches a trader's MetaMask followers.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The followers response.\n */\n async fetchFollowers(\n options: FetchFollowersOptions,\n ): Promise<FollowersResponse> {\n const { addressOrId } = options;\n\n const followersResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchFollowers`, addressOrId],\n queryFn: async () => {\n const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/followers`;\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url, { headers: authHeaders });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED,\n );\n const followersData = await response.json();\n if (!is(followersData, FollowersResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_FOLLOWERS_INVALID_RESPONSE,\n );\n }\n return followersData as FollowersResponse;\n },\n });\n\n return followersResponse;\n }\n\n /**\n * Fetches the list of traders a user is following.\n *\n * Calls `GET ${baseUrl}/users/${addressOrUid}/following`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID.\n * @returns The following response.\n */\n async fetchFollowing(\n options: FetchFollowingOptions,\n ): Promise<FollowingResponse> {\n const { addressOrUid } = options;\n\n const followingResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchFollowing`, addressOrUid],\n staleTime: 0,\n queryFn: async () => {\n const url = `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/following`;\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url, { headers: authHeaders });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED,\n );\n const followingData = await response.json();\n if (!is(followingData, FollowingResponseStruct)) {\n throw new Error(\n SocialServiceErrorMessage.FETCH_FOLLOWING_INVALID_RESPONSE,\n );\n }\n return followingData as FollowingResponse;\n },\n });\n\n return followingResponse;\n }\n\n /**\n * Follows one or more traders.\n *\n * Calls `PUT ${baseUrl}/users/${addressOrUid}/follows`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\n * @param options.targets - Array of wallet addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\n async follow(options: FollowOptions): Promise<FollowResponse> {\n const { addressOrUid, targets } = options;\n\n const followResponse = await this.fetchQuery({\n queryKey: [`${this.name}:follow`, addressOrUid, targets],\n staleTime: 0,\n queryFn: async () => {\n const url = `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/follows`;\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url, {\n method: 'PUT',\n headers: { ...authHeaders, 'Content-Type': 'application/json' },\n body: JSON.stringify({ targets }),\n });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.FOLLOW_FAILED,\n );\n const followData = await response.json();\n if (!is(followData, FollowResponseStruct)) {\n throw new Error(SocialServiceErrorMessage.FOLLOW_INVALID_RESPONSE);\n }\n return followData as FollowResponse;\n },\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders.\n *\n * Calls `DELETE ${baseUrl}/users/${addressOrUid}/follows?targets=...`.\n * Targets are sent as query params because Fastify does not parse\n * request bodies on DELETE requests per RFC 9110.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\n * @param options.targets - Array of wallet addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\n async unfollow(options: UnfollowOptions): Promise<UnfollowResponse> {\n const { addressOrUid, targets } = options;\n\n const unfollowResponse = await this.fetchQuery({\n queryKey: [`${this.name}:unfollow`, addressOrUid, targets],\n staleTime: 0,\n queryFn: async () => {\n const url = new URL(\n `${this.#v1Url}/users/${encodeURIComponent(addressOrUid)}/follows`,\n );\n for (const target of targets) {\n url.searchParams.append('targets', target);\n }\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url.toString(), {\n method: 'DELETE',\n headers: authHeaders,\n });\n SocialService.#throwIfNotOk(\n response,\n SocialServiceErrorMessage.UNFOLLOW_FAILED,\n );\n const unfollowData = await response.json();\n if (!is(unfollowData, UnfollowResponseStruct)) {\n throw new Error(SocialServiceErrorMessage.UNFOLLOW_INVALID_RESPONSE);\n }\n return unfollowData as UnfollowResponse;\n },\n });\n\n return unfollowResponse;\n }\n\n /**\n * Shared helper for fetching open/closed positions.\n *\n * @param status - \"open\" or \"closed\".\n * @param options - Options bag including addressOrId and query parameters.\n * @returns The positions response.\n */\n async #fetchPositions(\n status: 'open' | 'closed',\n options: FetchPositionsOptions,\n ): Promise<PositionsResponse> {\n const { addressOrId, chain, sort, limit, page } = options;\n\n const failedMessage =\n status === 'open'\n ? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_FAILED\n : SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_FAILED;\n const invalidMessage =\n status === 'open'\n ? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_INVALID_RESPONSE\n : SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_INVALID_RESPONSE;\n\n const positionsResponse = await this.fetchQuery({\n queryKey: [\n `${this.name}:fetch${status === 'open' ? 'Open' : 'Closed'}Positions`,\n addressOrId,\n chain ?? null,\n // sort is not used for open positions (v2 endpoint dropped it),\n // so exclude it from the key to avoid redundant cache entries\n status === 'closed' ? (sort ?? null) : null,\n limit ?? null,\n page ?? null,\n ],\n queryFn: async () => {\n const baseUrl = status === 'open' ? this.#v2Url : this.#v1Url;\n const url = new URL(\n `${baseUrl}/traders/${encodeURIComponent(addressOrId)}/positions/${status}`,\n );\n if (chain) {\n url.searchParams.append('chain', chain);\n }\n // sort is not supported on the v2 open-positions endpoint\n if (sort && status === 'closed') {\n url.searchParams.append('sort', sort);\n }\n if (limit !== undefined) {\n url.searchParams.append('limit', String(limit));\n }\n if (page !== undefined) {\n url.searchParams.append('page', String(page));\n }\n\n const authHeaders = await this.#getAuthHeaders();\n const response = await fetch(url.toString(), {\n headers: authHeaders,\n });\n SocialService.#throwIfNotOk(response, failedMessage);\n const positionsData = await response.json();\n if (!is(positionsData, PositionsResponseStruct)) {\n throw new Error(invalidMessage);\n }\n return positionsData as PositionsResponse;\n },\n });\n\n return positionsResponse;\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SocialServiceErrorMessage = exports.socialServiceName = exports.SocialService = exports.getDefaultSocialControllerState = exports.SocialController = void 0;
3
+ exports.SocialServiceErrorMessage = exports.socialServiceName = exports.TradeStruct = exports.SocialService = exports.getDefaultSocialControllerState = exports.SocialController = void 0;
4
4
  var SocialController_1 = require("./SocialController.cjs");
5
5
  Object.defineProperty(exports, "SocialController", { enumerable: true, get: function () { return SocialController_1.SocialController; } });
6
6
  Object.defineProperty(exports, "getDefaultSocialControllerState", { enumerable: true, get: function () { return SocialController_1.getDefaultSocialControllerState; } });
7
7
  var SocialService_1 = require("./SocialService.cjs");
8
8
  Object.defineProperty(exports, "SocialService", { enumerable: true, get: function () { return SocialService_1.SocialService; } });
9
+ var social_types_1 = require("./social-types.cjs");
10
+ Object.defineProperty(exports, "TradeStruct", { enumerable: true, get: function () { return social_types_1.TradeStruct; } });
9
11
  var social_constants_1 = require("./social-constants.cjs");
10
12
  Object.defineProperty(exports, "socialServiceName", { enumerable: true, get: function () { return social_constants_1.serviceName; } });
11
13
  Object.defineProperty(exports, "SocialServiceErrorMessage", { enumerable: true, get: function () { return social_constants_1.SocialServiceErrorMessage; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAejC,qDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAwCtB,2DAG4B;AAF1B,qHAAA,WAAW,OAAqB;AAChC,6HAAA,yBAAyB,OAAA","sourcesContent":["export type {\n SocialControllerActions,\n SocialControllerEvents,\n SocialControllerGetStateAction,\n SocialControllerMessenger,\n SocialControllerOptions,\n SocialControllerStateChangeEvent,\n} from './SocialController';\nexport {\n SocialController,\n getDefaultSocialControllerState,\n} from './SocialController';\n\nexport type {\n SocialControllerFollowTraderAction,\n SocialControllerUnfollowTraderAction,\n SocialControllerUpdateFollowingAction,\n SocialControllerUpdateLeaderboardAction,\n} from './SocialController-method-action-types';\n\nexport type {\n SocialServiceActions,\n SocialServiceEvents,\n SocialServiceMessenger,\n} from './SocialService';\nexport { SocialService } from './SocialService';\n\nexport type {\n SocialServiceFetchClosedPositionsAction,\n SocialServiceFetchFollowersAction,\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFetchOpenPositionsAction,\n SocialServiceFetchTraderProfileAction,\n SocialServiceFollowAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types';\n\nexport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardEntry,\n LeaderboardResponse,\n Pagination,\n PerChainBreakdown,\n Position,\n PositionsResponse,\n ProfileSummary,\n SocialControllerState,\n SocialHandles,\n Trade,\n TraderProfile,\n TraderProfileResponse,\n TraderStats,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\n\nexport {\n serviceName as socialServiceName,\n SocialServiceErrorMessage,\n} from './social-constants';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAejC,qDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAatB,mDAA6C;AAApC,2GAAA,WAAW,OAAA;AA4BpB,2DAG4B;AAF1B,qHAAA,WAAW,OAAqB;AAChC,6HAAA,yBAAyB,OAAA","sourcesContent":["export type {\n SocialControllerActions,\n SocialControllerEvents,\n SocialControllerGetStateAction,\n SocialControllerMessenger,\n SocialControllerOptions,\n SocialControllerStateChangeEvent,\n} from './SocialController';\nexport {\n SocialController,\n getDefaultSocialControllerState,\n} from './SocialController';\n\nexport type {\n SocialControllerFollowTraderAction,\n SocialControllerUnfollowTraderAction,\n SocialControllerUpdateFollowingAction,\n SocialControllerUpdateLeaderboardAction,\n} from './SocialController-method-action-types';\n\nexport type {\n SocialServiceActions,\n SocialServiceEvents,\n SocialServiceMessenger,\n} from './SocialService';\nexport { SocialService } from './SocialService';\n\nexport type {\n SocialServiceFetchClosedPositionsAction,\n SocialServiceFetchFollowersAction,\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFetchOpenPositionsAction,\n SocialServiceFetchTraderProfileAction,\n SocialServiceFollowAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types';\n\nexport { TradeStruct } from './social-types';\nexport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardEntry,\n LeaderboardResponse,\n Pagination,\n PerChainBreakdown,\n Position,\n PositionsResponse,\n ProfileSummary,\n SocialControllerState,\n SocialHandles,\n Trade,\n TraderProfile,\n TraderProfileResponse,\n TraderStats,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\n\nexport {\n serviceName as socialServiceName,\n SocialServiceErrorMessage,\n} from './social-constants';\n"]}
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ export type { SocialControllerFollowTraderAction, SocialControllerUnfollowTrader
4
4
  export type { SocialServiceActions, SocialServiceEvents, SocialServiceMessenger, } from "./SocialService.cjs";
5
5
  export { SocialService } from "./SocialService.cjs";
6
6
  export type { SocialServiceFetchClosedPositionsAction, SocialServiceFetchFollowersAction, SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFetchOpenPositionsAction, SocialServiceFetchTraderProfileAction, SocialServiceFollowAction, SocialServiceUnfollowAction, } from "./SocialService-method-action-types.cjs";
7
+ export { TradeStruct } from "./social-types.cjs";
7
8
  export type { FetchFollowersOptions, FetchFollowingOptions, FetchLeaderboardOptions, FetchPositionsOptions, FetchTraderProfileOptions, FollowersResponse, FollowingResponse, FollowOptions, FollowResponse, LeaderboardEntry, LeaderboardResponse, Pagination, PerChainBreakdown, Position, PositionsResponse, ProfileSummary, SocialControllerState, SocialHandles, Trade, TraderProfile, TraderProfileResponse, TraderStats, UnfollowOptions, UnfollowResponse, } from "./social-types.cjs";
8
9
  export { serviceName as socialServiceName, SocialServiceErrorMessage, } from "./social-constants.cjs";
9
10
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,GACjC,+BAA2B;AAC5B,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,kCAAkC,EAClC,oCAAoC,EACpC,qCAAqC,EACrC,uCAAuC,GACxC,mDAA+C;AAEhD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,uCAAuC,EACvC,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,EACnC,qCAAqC,EACrC,qCAAqC,EACrC,yBAAyB,EACzB,2BAA2B,GAC5B,gDAA4C;AAE7C,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,2BAAuB;AAExB,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,GAC1B,+BAA2B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,GACjC,+BAA2B;AAC5B,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,kCAAkC,EAClC,oCAAoC,EACpC,qCAAqC,EACrC,uCAAuC,GACxC,mDAA+C;AAEhD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,uCAAuC,EACvC,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,EACnC,qCAAqC,EACrC,qCAAqC,EACrC,yBAAyB,EACzB,2BAA2B,GAC5B,gDAA4C;AAE7C,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,2BAAuB;AAExB,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,GAC1B,+BAA2B"}
package/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ export type { SocialControllerFollowTraderAction, SocialControllerUnfollowTrader
4
4
  export type { SocialServiceActions, SocialServiceEvents, SocialServiceMessenger, } from "./SocialService.mjs";
5
5
  export { SocialService } from "./SocialService.mjs";
6
6
  export type { SocialServiceFetchClosedPositionsAction, SocialServiceFetchFollowersAction, SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFetchOpenPositionsAction, SocialServiceFetchTraderProfileAction, SocialServiceFollowAction, SocialServiceUnfollowAction, } from "./SocialService-method-action-types.mjs";
7
+ export { TradeStruct } from "./social-types.mjs";
7
8
  export type { FetchFollowersOptions, FetchFollowingOptions, FetchLeaderboardOptions, FetchPositionsOptions, FetchTraderProfileOptions, FollowersResponse, FollowingResponse, FollowOptions, FollowResponse, LeaderboardEntry, LeaderboardResponse, Pagination, PerChainBreakdown, Position, PositionsResponse, ProfileSummary, SocialControllerState, SocialHandles, Trade, TraderProfile, TraderProfileResponse, TraderStats, UnfollowOptions, UnfollowResponse, } from "./social-types.mjs";
8
9
  export { serviceName as socialServiceName, SocialServiceErrorMessage, } from "./social-constants.mjs";
9
10
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,GACjC,+BAA2B;AAC5B,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,kCAAkC,EAClC,oCAAoC,EACpC,qCAAqC,EACrC,uCAAuC,GACxC,mDAA+C;AAEhD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,uCAAuC,EACvC,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,EACnC,qCAAqC,EACrC,qCAAqC,EACrC,yBAAyB,EACzB,2BAA2B,GAC5B,gDAA4C;AAE7C,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,2BAAuB;AAExB,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,GAC1B,+BAA2B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,GACjC,+BAA2B;AAC5B,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,kCAAkC,EAClC,oCAAoC,EACpC,qCAAqC,EACrC,uCAAuC,GACxC,mDAA+C;AAEhD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,uCAAuC,EACvC,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,EACnC,qCAAqC,EACrC,qCAAqC,EACrC,yBAAyB,EACzB,2BAA2B,GAC5B,gDAA4C;AAE7C,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,2BAAuB;AAExB,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,GAC1B,+BAA2B"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export { SocialController, getDefaultSocialControllerState } from "./SocialController.mjs";
2
2
  export { SocialService } from "./SocialService.mjs";
3
+ export { TradeStruct } from "./social-types.mjs";
3
4
  export { serviceName as socialServiceName, SocialServiceErrorMessage } from "./social-constants.mjs";
4
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAc5B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAwChD,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,EAC1B,+BAA2B","sourcesContent":["export type {\n SocialControllerActions,\n SocialControllerEvents,\n SocialControllerGetStateAction,\n SocialControllerMessenger,\n SocialControllerOptions,\n SocialControllerStateChangeEvent,\n} from './SocialController';\nexport {\n SocialController,\n getDefaultSocialControllerState,\n} from './SocialController';\n\nexport type {\n SocialControllerFollowTraderAction,\n SocialControllerUnfollowTraderAction,\n SocialControllerUpdateFollowingAction,\n SocialControllerUpdateLeaderboardAction,\n} from './SocialController-method-action-types';\n\nexport type {\n SocialServiceActions,\n SocialServiceEvents,\n SocialServiceMessenger,\n} from './SocialService';\nexport { SocialService } from './SocialService';\n\nexport type {\n SocialServiceFetchClosedPositionsAction,\n SocialServiceFetchFollowersAction,\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFetchOpenPositionsAction,\n SocialServiceFetchTraderProfileAction,\n SocialServiceFollowAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types';\n\nexport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardEntry,\n LeaderboardResponse,\n Pagination,\n PerChainBreakdown,\n Position,\n PositionsResponse,\n ProfileSummary,\n SocialControllerState,\n SocialHandles,\n Trade,\n TraderProfile,\n TraderProfileResponse,\n TraderStats,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\n\nexport {\n serviceName as socialServiceName,\n SocialServiceErrorMessage,\n} from './social-constants';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAc5B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAahD,OAAO,EAAE,WAAW,EAAE,2BAAuB;AA4B7C,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,yBAAyB,EAC1B,+BAA2B","sourcesContent":["export type {\n SocialControllerActions,\n SocialControllerEvents,\n SocialControllerGetStateAction,\n SocialControllerMessenger,\n SocialControllerOptions,\n SocialControllerStateChangeEvent,\n} from './SocialController';\nexport {\n SocialController,\n getDefaultSocialControllerState,\n} from './SocialController';\n\nexport type {\n SocialControllerFollowTraderAction,\n SocialControllerUnfollowTraderAction,\n SocialControllerUpdateFollowingAction,\n SocialControllerUpdateLeaderboardAction,\n} from './SocialController-method-action-types';\n\nexport type {\n SocialServiceActions,\n SocialServiceEvents,\n SocialServiceMessenger,\n} from './SocialService';\nexport { SocialService } from './SocialService';\n\nexport type {\n SocialServiceFetchClosedPositionsAction,\n SocialServiceFetchFollowersAction,\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFetchOpenPositionsAction,\n SocialServiceFetchTraderProfileAction,\n SocialServiceFollowAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types';\n\nexport { TradeStruct } from './social-types';\nexport type {\n FetchFollowersOptions,\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FetchPositionsOptions,\n FetchTraderProfileOptions,\n FollowersResponse,\n FollowingResponse,\n FollowOptions,\n FollowResponse,\n LeaderboardEntry,\n LeaderboardResponse,\n Pagination,\n PerChainBreakdown,\n Position,\n PositionsResponse,\n ProfileSummary,\n SocialControllerState,\n SocialHandles,\n Trade,\n TraderProfile,\n TraderProfileResponse,\n TraderStats,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\n\nexport {\n serviceName as socialServiceName,\n SocialServiceErrorMessage,\n} from './social-constants';\n"]}
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
- // ---------------------------------------------------------------------------
3
- // Shared sub-types
4
- // ---------------------------------------------------------------------------
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TradeStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ exports.TradeStruct = (0, superstruct_1.type)({
6
+ direction: (0, superstruct_1.enums)(['buy', 'sell']),
7
+ intent: (0, superstruct_1.enums)(['enter', 'exit']),
8
+ category: (0, superstruct_1.optional)((0, superstruct_1.string)()),
9
+ tokenAmount: (0, superstruct_1.number)(),
10
+ usdCost: (0, superstruct_1.number)(),
11
+ timestamp: (0, superstruct_1.number)(),
12
+ transactionHash: (0, superstruct_1.string)(),
13
+ });
6
14
  //# sourceMappingURL=social-types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"social-types.cjs","sourceRoot":"","sources":["../src/social-types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * Minimal profile summary used across follow/follower responses.\n */\nexport type ProfileSummary = {\n /** Clicker profile ID (UUID). */\n profileId: string;\n /** Primary wallet address. */\n address: string;\n /** Display name or truncated address. */\n name: string;\n /** Profile avatar URL. */\n imageUrl?: string | null;\n};\n\n/**\n * Social media handles attached to a trader profile.\n */\nexport type SocialHandles = {\n twitter?: string | null;\n farcaster?: string | null;\n ens?: string | null;\n lens?: string | null;\n};\n\n/**\n * A single trade within a position.\n */\nexport type Trade = {\n /** \"buy\" or \"sell\". */\n direction: string;\n /** Quantity traded. */\n tokenAmount: number;\n /** USD value of the trade. */\n usdCost: number;\n /** Unix timestamp. */\n timestamp: number;\n /** On-chain transaction hash. */\n transactionHash: string;\n};\n\n// ---------------------------------------------------------------------------\n// Leaderboard\n// ---------------------------------------------------------------------------\n\n/**\n * A single entry in the leaderboard response.\n */\nexport type LeaderboardEntry = {\n rank: number;\n addresses: string[];\n profileId: string;\n name: string;\n imageUrl?: string | null;\n pnl30d: number;\n winRate30d?: number | null;\n /** Renamed from roi30d. */\n roiPercent30d?: number | null;\n /** Renamed from tradeCount. */\n tradeCount30d?: number | null;\n pnl7d?: number | null;\n winRate7d?: number | null;\n roiPercent7d?: number | null;\n tradeCount7d?: number | null;\n pnlPerChain: Record<string, number>;\n followerCount: number;\n socialHandles: SocialHandles;\n};\n\n/**\n * Response from `GET /v1/leaderboard`.\n */\nexport type LeaderboardResponse = {\n traders: LeaderboardEntry[];\n};\n\n// ---------------------------------------------------------------------------\n// Trader profile\n// ---------------------------------------------------------------------------\n\nexport type TraderProfile = {\n profileId: string;\n address: string;\n allAddresses: string[];\n name: string;\n imageUrl?: string | null;\n};\n\nexport type TraderStats = {\n pnl30d?: number | null;\n winRate30d?: number | null;\n /** Renamed from roi30d. */\n roiPercent30d?: number | null;\n /** Renamed from tradeCount. */\n tradeCount30d?: number | null;\n pnl7d?: number | null;\n winRate7d?: number | null;\n roiPercent7d?: number | null;\n tradeCount7d?: number | null;\n};\n\nexport type PerChainBreakdown = {\n perChainPnl: Record<string, number>;\n /** ROI can be null for chains with no trading activity (zero cost-basis). */\n perChainRoi: Record<string, number | null>;\n perChainVolume: Record<string, number>;\n};\n\n/**\n * Response from `GET /v1/traders/:addressOrId/profile`.\n */\nexport type TraderProfileResponse = {\n profile: TraderProfile;\n stats: TraderStats;\n perChainBreakdown: PerChainBreakdown;\n socialHandles: SocialHandles;\n followerCount: number;\n followingCount: number;\n};\n\n// ---------------------------------------------------------------------------\n// Positions\n// ---------------------------------------------------------------------------\n\nexport type Position = {\n tokenSymbol: string;\n tokenName: string;\n tokenAddress: string;\n chain: string;\n positionAmount: number;\n boughtUsd: number;\n soldUsd: number;\n realizedPnl: number;\n costBasis: number;\n trades: Trade[];\n lastTradeAt: number;\n /** Current USD value of the remaining position (open positions only). */\n currentValueUSD?: number | null;\n /** Unrealized + realized PnL in USD. */\n pnlValueUsd?: number | null;\n /** PnL as a percentage of cost basis. */\n pnlPercent?: number | null;\n};\n\nexport type Pagination = {\n hasMore: boolean;\n nextPage?: number;\n};\n\n/**\n * Response from `GET /v1/traders/:addressOrId/positions/open`\n * and `GET /v1/traders/:addressOrId/positions/closed`.\n */\nexport type PositionsResponse = {\n positions: Position[];\n pagination: Pagination;\n /** ISO 8601 timestamp indicating when the response was computed server-side. */\n computedAt?: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Followers\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `GET /v1/traders/:addressOrId/followers`.\n */\nexport type FollowersResponse = {\n followers: ProfileSummary[];\n count: number;\n};\n\n// ---------------------------------------------------------------------------\n// Following\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `GET /v1/users/:addressOrUid/following`.\n */\nexport type FollowingResponse = {\n following: ProfileSummary[];\n count: number;\n};\n\n// ---------------------------------------------------------------------------\n// Follow / Unfollow\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `PUT /v1/users/:addressOrUid/follows`.\n */\nexport type FollowResponse = {\n followed: ProfileSummary[];\n};\n\n/**\n * Response from `DELETE /v1/users/:addressOrUid/follows`.\n */\nexport type UnfollowResponse = {\n unfollowed: ProfileSummary[];\n};\n\n// ---------------------------------------------------------------------------\n// Fetch options\n// ---------------------------------------------------------------------------\n\nexport type FetchLeaderboardOptions = {\n sort?: 'pnl' | 'winRate' | 'roi';\n chains?: string[];\n limit?: number;\n};\n\nexport type FetchTraderProfileOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n};\n\nexport type FetchPositionsOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n chain?: string;\n sort?: 'value' | 'latest';\n limit?: number;\n page?: number;\n};\n\nexport type FetchFollowersOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n};\n\nexport type FetchFollowingOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrUid: string;\n};\n\nexport type FollowOptions = {\n /** Wallet address or Clicker profile ID of the user. */\n addressOrUid: string;\n /** Array of wallet addresses or profile IDs to follow. */\n targets: string[];\n};\n\nexport type UnfollowOptions = {\n /** Wallet address or Clicker profile ID of the user. */\n addressOrUid: string;\n /** Array of wallet addresses or profile IDs to unfollow. */\n targets: string[];\n};\n\n// ---------------------------------------------------------------------------\n// Controller state\n// ---------------------------------------------------------------------------\n\n/**\n * State managed by the SocialController.\n *\n * The controller acts as a simple store — no TTL or eviction logic.\n * The UI decides when to re-fetch; the social-api's own cache layer\n * handles upstream rate-limiting.\n */\nexport type SocialControllerState = {\n /** Cached ranked trader list from the last `updateLeaderboard` call. */\n leaderboardEntries: LeaderboardEntry[];\n /** Addresses the current user follows — drives Follow/Following button state. */\n followingAddresses: string[];\n};\n"]}
1
+ {"version":3,"file":"social-types.cjs","sourceRoot":"","sources":["../src/social-types.ts"],"names":[],"mappings":";;;AACA,uDAM+B;AA8BlB,QAAA,WAAW,GAAG,IAAA,kBAAU,EAAC;IACpC,SAAS,EAAE,IAAA,mBAAK,EAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC5B,WAAW,EAAE,IAAA,oBAAM,GAAE;IACrB,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,eAAe,EAAE,IAAA,oBAAM,GAAE;CAC1B,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n enums,\n number,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\n// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * Minimal profile summary used across follow/follower responses.\n */\nexport type ProfileSummary = {\n /** Clicker profile ID (UUID). */\n profileId: string;\n /** Primary wallet address. */\n address: string;\n /** Display name or truncated address. */\n name: string;\n /** Profile avatar URL. */\n imageUrl?: string | null;\n};\n\n/**\n * Social media handles attached to a trader profile.\n */\nexport type SocialHandles = {\n twitter?: string | null;\n farcaster?: string | null;\n ens?: string | null;\n lens?: string | null;\n};\n\nexport const TradeStruct = structType({\n direction: enums(['buy', 'sell']),\n intent: enums(['enter', 'exit']),\n category: optional(string()),\n tokenAmount: number(),\n usdCost: number(),\n timestamp: number(),\n transactionHash: string(),\n});\n\nexport type Trade = Infer<typeof TradeStruct>;\n\n// ---------------------------------------------------------------------------\n// Leaderboard\n// ---------------------------------------------------------------------------\n\n/**\n * A single entry in the leaderboard response.\n */\nexport type LeaderboardEntry = {\n rank: number;\n addresses: string[];\n profileId: string;\n name: string;\n imageUrl?: string | null;\n pnl30d: number;\n winRate30d?: number | null;\n /** Renamed from roi30d. */\n roiPercent30d?: number | null;\n /** Renamed from tradeCount. */\n tradeCount30d?: number | null;\n pnl7d?: number | null;\n winRate7d?: number | null;\n roiPercent7d?: number | null;\n tradeCount7d?: number | null;\n pnlPerChain: Record<string, number>;\n followerCount: number;\n socialHandles: SocialHandles;\n};\n\n/**\n * Response from `GET /v1/leaderboard`.\n */\nexport type LeaderboardResponse = {\n traders: LeaderboardEntry[];\n};\n\n// ---------------------------------------------------------------------------\n// Trader profile\n// ---------------------------------------------------------------------------\n\nexport type TraderProfile = {\n profileId: string;\n address: string;\n allAddresses: string[];\n name: string;\n imageUrl?: string | null;\n};\n\nexport type TraderStats = {\n pnl30d?: number | null;\n winRate30d?: number | null;\n /** Renamed from roi30d. */\n roiPercent30d?: number | null;\n /** Renamed from tradeCount. */\n tradeCount30d?: number | null;\n pnl7d?: number | null;\n winRate7d?: number | null;\n roiPercent7d?: number | null;\n tradeCount7d?: number | null;\n /** Median holding time in minutes. */\n medianHoldMinutes?: number | null;\n};\n\nexport type PerChainBreakdown = {\n perChainPnl: Record<string, number>;\n /** ROI can be null for chains with no trading activity (zero cost-basis). */\n perChainRoi: Record<string, number | null>;\n perChainVolume: Record<string, number>;\n};\n\n/**\n * Response from `GET /v1/traders/:addressOrId/profile`.\n */\nexport type TraderProfileResponse = {\n profile: TraderProfile;\n stats: TraderStats;\n perChainBreakdown: PerChainBreakdown;\n socialHandles: SocialHandles;\n followerCount: number;\n followingCount: number;\n};\n\n// ---------------------------------------------------------------------------\n// Positions\n// ---------------------------------------------------------------------------\n\nexport type Position = {\n tokenSymbol: string;\n tokenName: string;\n tokenAddress: string;\n chain: string;\n positionAmount: number;\n boughtUsd: number;\n soldUsd: number;\n realizedPnl: number;\n costBasis: number;\n trades: Trade[];\n lastTradeAt: number;\n /** Daylight-hosted token image URL. */\n tokenImageUrl?: string | null;\n /** Current USD value of the remaining position (open positions only). */\n currentValueUSD?: number | null;\n /** Unrealized + realized PnL in USD. */\n pnlValueUsd?: number | null;\n /** PnL as a percentage of cost basis. */\n pnlPercent?: number | null;\n};\n\nexport type Pagination = {\n hasMore: boolean;\n nextPage?: number;\n};\n\n/**\n * Response from `GET /v1/traders/:addressOrId/positions/open`\n * and `GET /v1/traders/:addressOrId/positions/closed`.\n */\nexport type PositionsResponse = {\n positions: Position[];\n pagination: Pagination;\n /** ISO 8601 timestamp indicating when the response was computed server-side. */\n computedAt?: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Followers\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `GET /v1/traders/:addressOrId/followers`.\n */\nexport type FollowersResponse = {\n followers: ProfileSummary[];\n count: number;\n};\n\n// ---------------------------------------------------------------------------\n// Following\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `GET /v1/users/:addressOrUid/following`.\n */\nexport type FollowingResponse = {\n following: ProfileSummary[];\n count: number;\n};\n\n// ---------------------------------------------------------------------------\n// Follow / Unfollow\n// ---------------------------------------------------------------------------\n\n/**\n * Response from `PUT /v1/users/:addressOrUid/follows`.\n */\nexport type FollowResponse = {\n followed: ProfileSummary[];\n};\n\n/**\n * Response from `DELETE /v1/users/:addressOrUid/follows`.\n */\nexport type UnfollowResponse = {\n unfollowed: ProfileSummary[];\n};\n\n// ---------------------------------------------------------------------------\n// Fetch options\n// ---------------------------------------------------------------------------\n\nexport type FetchLeaderboardOptions = {\n sort?: 'pnl' | 'winRate' | 'roi';\n chains?: string[];\n limit?: number;\n};\n\nexport type FetchTraderProfileOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n};\n\nexport type FetchPositionsOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n chain?: string;\n sort?: 'value' | 'latest';\n limit?: number;\n page?: number;\n};\n\nexport type FetchFollowersOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrId: string;\n};\n\nexport type FetchFollowingOptions = {\n /** Wallet address or Clicker profile ID. */\n addressOrUid: string;\n};\n\nexport type FollowOptions = {\n /** Wallet address or Clicker profile ID of the user. */\n addressOrUid: string;\n /** Array of wallet addresses or profile IDs to follow. */\n targets: string[];\n};\n\nexport type UnfollowOptions = {\n /** Wallet address or Clicker profile ID of the user. */\n addressOrUid: string;\n /** Array of wallet addresses or profile IDs to unfollow. */\n targets: string[];\n};\n\n// ---------------------------------------------------------------------------\n// Controller state\n// ---------------------------------------------------------------------------\n\n/**\n * State managed by the SocialController.\n *\n * The controller acts as a simple store — no TTL or eviction logic.\n * The UI decides when to re-fetch; the social-api's own cache layer\n * handles upstream rate-limiting.\n */\nexport type SocialControllerState = {\n /** Cached ranked trader list from the last `updateLeaderboard` call. */\n leaderboardEntries: LeaderboardEntry[];\n /** Wallet addresses the current user follows. */\n followingAddresses: string[];\n /** Clicker profile IDs the current user follows used by mobile UI. */\n followingProfileIds: string[];\n};\n"]}
@@ -1,3 +1,4 @@
1
+ import type { Infer } from "@metamask/superstruct";
1
2
  /**
2
3
  * Minimal profile summary used across follow/follower responses.
3
4
  */
@@ -20,21 +21,30 @@ export type SocialHandles = {
20
21
  ens?: string | null;
21
22
  lens?: string | null;
22
23
  };
23
- /**
24
- * A single trade within a position.
25
- */
26
- export type Trade = {
27
- /** "buy" or "sell". */
28
- direction: string;
29
- /** Quantity traded. */
24
+ export declare const TradeStruct: import("@metamask/superstruct").Struct<{
25
+ direction: "buy" | "sell";
26
+ intent: "enter" | "exit";
30
27
  tokenAmount: number;
31
- /** USD value of the trade. */
32
28
  usdCost: number;
33
- /** Unix timestamp. */
34
29
  timestamp: number;
35
- /** On-chain transaction hash. */
36
30
  transactionHash: string;
37
- };
31
+ category?: string | undefined;
32
+ }, {
33
+ direction: import("@metamask/superstruct").Struct<"buy" | "sell", {
34
+ buy: "buy";
35
+ sell: "sell";
36
+ }>;
37
+ intent: import("@metamask/superstruct").Struct<"enter" | "exit", {
38
+ enter: "enter";
39
+ exit: "exit";
40
+ }>;
41
+ category: import("@metamask/superstruct").Struct<string | undefined, null>;
42
+ tokenAmount: import("@metamask/superstruct").Struct<number, null>;
43
+ usdCost: import("@metamask/superstruct").Struct<number, null>;
44
+ timestamp: import("@metamask/superstruct").Struct<number, null>;
45
+ transactionHash: import("@metamask/superstruct").Struct<string, null>;
46
+ }>;
47
+ export type Trade = Infer<typeof TradeStruct>;
38
48
  /**
39
49
  * A single entry in the leaderboard response.
40
50
  */
@@ -82,6 +92,8 @@ export type TraderStats = {
82
92
  winRate7d?: number | null;
83
93
  roiPercent7d?: number | null;
84
94
  tradeCount7d?: number | null;
95
+ /** Median holding time in minutes. */
96
+ medianHoldMinutes?: number | null;
85
97
  };
86
98
  export type PerChainBreakdown = {
87
99
  perChainPnl: Record<string, number>;
@@ -112,6 +124,8 @@ export type Position = {
112
124
  costBasis: number;
113
125
  trades: Trade[];
114
126
  lastTradeAt: number;
127
+ /** Daylight-hosted token image URL. */
128
+ tokenImageUrl?: string | null;
115
129
  /** Current USD value of the remaining position (open positions only). */
116
130
  currentValueUSD?: number | null;
117
131
  /** Unrealized + realized PnL in USD. */
@@ -206,7 +220,9 @@ export type UnfollowOptions = {
206
220
  export type SocialControllerState = {
207
221
  /** Cached ranked trader list from the last `updateLeaderboard` call. */
208
222
  leaderboardEntries: LeaderboardEntry[];
209
- /** Addresses the current user follows — drives Follow/Following button state. */
223
+ /** Wallet addresses the current user follows. */
210
224
  followingAddresses: string[];
225
+ /** Clicker profile IDs the current user follows — used by mobile UI. */
226
+ followingProfileIds: string[];
211
227
  };
212
228
  //# sourceMappingURL=social-types.d.cts.map