@sun-protocol/sun-sdk-api 0.1.0-beta.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.
@@ -0,0 +1,214 @@
1
+ import { Network } from '@sun-protocol/sun-sdk-core';
2
+
3
+ interface SunApiEnvelope<T> {
4
+ readonly code: number;
5
+ readonly msg?: string;
6
+ readonly message?: string;
7
+ readonly data: T;
8
+ readonly pagination?: {
9
+ pageNum: number;
10
+ pageSize: number;
11
+ total: number;
12
+ };
13
+ }
14
+ declare function parseApiEnvelope<T>(payload: SunApiEnvelope<T>): T;
15
+
16
+ type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
17
+ type JsonParser = (text: string) => unknown;
18
+ declare const defaultFetch: FetchLike;
19
+ declare const defaultJsonParser: JsonParser;
20
+ interface RequestJsonOptions {
21
+ readonly service: string;
22
+ readonly fetchImpl: FetchLike;
23
+ readonly init?: RequestInit;
24
+ readonly jsonParser?: JsonParser;
25
+ }
26
+ declare function requestJson<T = unknown>(url: string, opts: RequestJsonOptions): Promise<T>;
27
+
28
+ interface HttpClientOptions {
29
+ readonly fetchImpl?: FetchLike;
30
+ readonly jsonParser?: JsonParser;
31
+ }
32
+ declare class SunHttpClient {
33
+ private readonly fetchImpl;
34
+ private readonly jsonParser;
35
+ constructor(options?: HttpClientOptions);
36
+ getEnvelope<T>(url: string): Promise<T>;
37
+ }
38
+
39
+ interface RouterUniversalParams {
40
+ readonly fromToken: string;
41
+ readonly toToken: string;
42
+ readonly amountIn: string;
43
+ readonly typeList?: string;
44
+ readonly includeUnverifiedV4Hook?: boolean;
45
+ }
46
+ interface RouterRouteAmountFields {
47
+ /** Decimal display value returned by Router. */
48
+ readonly amountIn: string;
49
+ /** Integer input amount in the input token's base units. */
50
+ readonly amountInRaw: string;
51
+ /** Decimal display value returned by Router. */
52
+ readonly amountOut: string;
53
+ /** Integer output amount in the output token's base units. */
54
+ readonly amountOutRaw: string;
55
+ /** Decimal display value after Router's minimum-output calculation. */
56
+ readonly amountOutMinimum?: string;
57
+ /** Integer minimum output in the output token's base units. */
58
+ readonly amountOutMinimumRaw?: string;
59
+ }
60
+ interface RouterRoute extends RouterRouteAmountFields {
61
+ readonly [key: string]: unknown;
62
+ }
63
+ interface RouterUniversalResponse {
64
+ readonly code: number;
65
+ readonly message?: string;
66
+ readonly data: RouterRoute[];
67
+ }
68
+ declare function buildRouterUniversalUrl(baseUrl: string, params: RouterUniversalParams): string;
69
+
70
+ declare const PRICE_DEFAULT_BASE_URL = "https://c.tronlink.org";
71
+ interface PriceOptions {
72
+ baseUrl?: string;
73
+ fetchImpl?: FetchLike;
74
+ jsonParser?: JsonParser;
75
+ }
76
+ declare class PriceClient {
77
+ private readonly baseUrl;
78
+ private readonly fetchImpl;
79
+ private readonly jsonParser;
80
+ constructor(opts?: PriceOptions);
81
+ getPrice<T = unknown>(symbols: string[], convert?: string): Promise<T>;
82
+ }
83
+ interface RouterApiOptions {
84
+ fetchImpl?: FetchLike;
85
+ jsonParser?: JsonParser;
86
+ }
87
+ declare class RouterApiClient {
88
+ private readonly fetchImpl;
89
+ private readonly jsonParser;
90
+ constructor(opts?: RouterApiOptions);
91
+ getRoutes(baseUrl: string, params: RouterUniversalParams): Promise<RouterUniversalResponse>;
92
+ }
93
+
94
+ declare const SUN_OPEN_API_DEFAULT_BASE_URL = "https://open.sun.io";
95
+ interface ApiResponse<T = unknown> {
96
+ code: number;
97
+ message?: string;
98
+ msg?: string;
99
+ data: T;
100
+ }
101
+ interface SunApiOptions {
102
+ baseUrl?: string;
103
+ fetchImpl?: FetchLike;
104
+ jsonParser?: JsonParser;
105
+ }
106
+ declare class SunApiClient {
107
+ private readonly baseUrl;
108
+ private readonly fetchImpl;
109
+ private readonly jsonParser;
110
+ constructor(opts?: SunApiOptions);
111
+ private get;
112
+ scanTransactions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
113
+ getTokens(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
114
+ searchTokens(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
115
+ getPrice(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
116
+ getProtocol(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
117
+ getVolHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
118
+ getLiqHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
119
+ getUsersCountHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
120
+ getTransactionsHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
121
+ getPoolsCountHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
122
+ getUserPositions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
123
+ getPoolUserPositionTick(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
124
+ getPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
125
+ getTopApyPoolList(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
126
+ searchPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
127
+ searchCountPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
128
+ getPoolHooks(): Promise<ApiResponse<unknown>>;
129
+ getPoolVolHistory(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
130
+ getPoolLiqHistory(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
131
+ getPairs(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
132
+ getFarms(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
133
+ getFarmTransactions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
134
+ getFarmPositions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
135
+ }
136
+
137
+ declare const SUNPUMP_DEFAULT_BASE_URL: string;
138
+ declare function buildSunPumpUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | undefined>): string;
139
+ type QueryValue = string | number | boolean | null | undefined;
140
+ type SunPumpQuery = Record<string, QueryValue>;
141
+ interface SunPumpEnvelope<T = unknown> {
142
+ readonly code: number;
143
+ readonly msg?: string;
144
+ readonly data: T;
145
+ readonly pagination?: {
146
+ pageNum: number;
147
+ pageSize: number;
148
+ total: number;
149
+ };
150
+ }
151
+ interface AgentTokenLaunchParams {
152
+ name: string;
153
+ symbol: string;
154
+ description: string;
155
+ imageBase64?: string;
156
+ twitterUrl?: string;
157
+ telegramUrl?: string;
158
+ websiteUrl?: string;
159
+ tweetUsername?: string;
160
+ }
161
+ interface SunPumpApiOptions {
162
+ network?: Network;
163
+ baseUrl?: string;
164
+ fetchImpl?: FetchLike;
165
+ jsonParser?: JsonParser;
166
+ }
167
+ declare class SunPumpApiClient {
168
+ private readonly baseUrl;
169
+ private readonly fetchImpl;
170
+ private readonly jsonParser;
171
+ constructor(opts?: SunPumpApiOptions);
172
+ private request;
173
+ private post;
174
+ listTokens(query?: SunPumpQuery): Promise<unknown>;
175
+ getToken(contractAddress: string): Promise<unknown>;
176
+ searchTokens(query?: SunPumpQuery): Promise<unknown>;
177
+ searchTokensV2(query?: SunPumpQuery): Promise<unknown>;
178
+ tokensByOwner(query: SunPumpQuery): Promise<unknown>;
179
+ tokenHolders(query: SunPumpQuery): Promise<unknown>;
180
+ tokenHoldersV2(query: SunPumpQuery): Promise<unknown>;
181
+ userFavors(query: SunPumpQuery): Promise<unknown>;
182
+ ranking(query: SunPumpQuery): Promise<unknown>;
183
+ kingOfHill(): Promise<unknown>;
184
+ pumpTokenList(): Promise<unknown>;
185
+ tokenTransactions(contractAddress: string, query?: SunPumpQuery): Promise<unknown>;
186
+ userTransactions(ownerAddress: string, query?: SunPumpQuery): Promise<unknown>;
187
+ portfolio(address: string, query?: SunPumpQuery): Promise<unknown>;
188
+ agentTokenLaunch(params: AgentTokenLaunchParams): Promise<unknown>;
189
+ }
190
+
191
+ /** Reads Unix milliseconds from the SUN time service, with a 3-second limit. */
192
+ declare function getServerTime(url: string, fetchImpl?: FetchLike, jsonParser?: JsonParser): Promise<number>;
193
+
194
+ declare const TRONSCAN_DEFAULT_BASE_URL: string;
195
+ interface TronScanOptions {
196
+ network?: Network;
197
+ baseUrl?: string;
198
+ fetchImpl?: FetchLike;
199
+ apiKey?: string;
200
+ jsonParser?: JsonParser;
201
+ }
202
+ declare class TronScanClient {
203
+ private readonly baseUrl;
204
+ private readonly fetchImpl;
205
+ private readonly jsonParser;
206
+ private readonly apiKey;
207
+ constructor(opts?: TronScanOptions);
208
+ private get;
209
+ getTokenTrc20(params: Record<string, unknown>): Promise<unknown>;
210
+ getTokenHolderBalance(params: Record<string, unknown>): Promise<unknown>;
211
+ getAccountTokens(params: Record<string, unknown>): Promise<unknown>;
212
+ }
213
+
214
+ export { type AgentTokenLaunchParams, type ApiResponse, type FetchLike, type HttpClientOptions, type JsonParser, PRICE_DEFAULT_BASE_URL, PriceClient, type PriceOptions, type RequestJsonOptions, RouterApiClient, type RouterApiOptions, type RouterRoute, type RouterRouteAmountFields, type RouterUniversalParams, type RouterUniversalResponse, SUNPUMP_DEFAULT_BASE_URL, SUN_OPEN_API_DEFAULT_BASE_URL, SunApiClient, type SunApiEnvelope, type SunApiOptions, SunHttpClient, SunPumpApiClient, type SunPumpApiOptions, type SunPumpEnvelope, type SunPumpQuery, TRONSCAN_DEFAULT_BASE_URL, TronScanClient, type TronScanOptions, buildRouterUniversalUrl, buildSunPumpUrl, defaultFetch, defaultJsonParser, getServerTime, parseApiEnvelope, requestJson };
@@ -0,0 +1,214 @@
1
+ import { Network } from '@sun-protocol/sun-sdk-core';
2
+
3
+ interface SunApiEnvelope<T> {
4
+ readonly code: number;
5
+ readonly msg?: string;
6
+ readonly message?: string;
7
+ readonly data: T;
8
+ readonly pagination?: {
9
+ pageNum: number;
10
+ pageSize: number;
11
+ total: number;
12
+ };
13
+ }
14
+ declare function parseApiEnvelope<T>(payload: SunApiEnvelope<T>): T;
15
+
16
+ type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
17
+ type JsonParser = (text: string) => unknown;
18
+ declare const defaultFetch: FetchLike;
19
+ declare const defaultJsonParser: JsonParser;
20
+ interface RequestJsonOptions {
21
+ readonly service: string;
22
+ readonly fetchImpl: FetchLike;
23
+ readonly init?: RequestInit;
24
+ readonly jsonParser?: JsonParser;
25
+ }
26
+ declare function requestJson<T = unknown>(url: string, opts: RequestJsonOptions): Promise<T>;
27
+
28
+ interface HttpClientOptions {
29
+ readonly fetchImpl?: FetchLike;
30
+ readonly jsonParser?: JsonParser;
31
+ }
32
+ declare class SunHttpClient {
33
+ private readonly fetchImpl;
34
+ private readonly jsonParser;
35
+ constructor(options?: HttpClientOptions);
36
+ getEnvelope<T>(url: string): Promise<T>;
37
+ }
38
+
39
+ interface RouterUniversalParams {
40
+ readonly fromToken: string;
41
+ readonly toToken: string;
42
+ readonly amountIn: string;
43
+ readonly typeList?: string;
44
+ readonly includeUnverifiedV4Hook?: boolean;
45
+ }
46
+ interface RouterRouteAmountFields {
47
+ /** Decimal display value returned by Router. */
48
+ readonly amountIn: string;
49
+ /** Integer input amount in the input token's base units. */
50
+ readonly amountInRaw: string;
51
+ /** Decimal display value returned by Router. */
52
+ readonly amountOut: string;
53
+ /** Integer output amount in the output token's base units. */
54
+ readonly amountOutRaw: string;
55
+ /** Decimal display value after Router's minimum-output calculation. */
56
+ readonly amountOutMinimum?: string;
57
+ /** Integer minimum output in the output token's base units. */
58
+ readonly amountOutMinimumRaw?: string;
59
+ }
60
+ interface RouterRoute extends RouterRouteAmountFields {
61
+ readonly [key: string]: unknown;
62
+ }
63
+ interface RouterUniversalResponse {
64
+ readonly code: number;
65
+ readonly message?: string;
66
+ readonly data: RouterRoute[];
67
+ }
68
+ declare function buildRouterUniversalUrl(baseUrl: string, params: RouterUniversalParams): string;
69
+
70
+ declare const PRICE_DEFAULT_BASE_URL = "https://c.tronlink.org";
71
+ interface PriceOptions {
72
+ baseUrl?: string;
73
+ fetchImpl?: FetchLike;
74
+ jsonParser?: JsonParser;
75
+ }
76
+ declare class PriceClient {
77
+ private readonly baseUrl;
78
+ private readonly fetchImpl;
79
+ private readonly jsonParser;
80
+ constructor(opts?: PriceOptions);
81
+ getPrice<T = unknown>(symbols: string[], convert?: string): Promise<T>;
82
+ }
83
+ interface RouterApiOptions {
84
+ fetchImpl?: FetchLike;
85
+ jsonParser?: JsonParser;
86
+ }
87
+ declare class RouterApiClient {
88
+ private readonly fetchImpl;
89
+ private readonly jsonParser;
90
+ constructor(opts?: RouterApiOptions);
91
+ getRoutes(baseUrl: string, params: RouterUniversalParams): Promise<RouterUniversalResponse>;
92
+ }
93
+
94
+ declare const SUN_OPEN_API_DEFAULT_BASE_URL = "https://open.sun.io";
95
+ interface ApiResponse<T = unknown> {
96
+ code: number;
97
+ message?: string;
98
+ msg?: string;
99
+ data: T;
100
+ }
101
+ interface SunApiOptions {
102
+ baseUrl?: string;
103
+ fetchImpl?: FetchLike;
104
+ jsonParser?: JsonParser;
105
+ }
106
+ declare class SunApiClient {
107
+ private readonly baseUrl;
108
+ private readonly fetchImpl;
109
+ private readonly jsonParser;
110
+ constructor(opts?: SunApiOptions);
111
+ private get;
112
+ scanTransactions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
113
+ getTokens(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
114
+ searchTokens(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
115
+ getPrice(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
116
+ getProtocol(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
117
+ getVolHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
118
+ getLiqHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
119
+ getUsersCountHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
120
+ getTransactionsHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
121
+ getPoolsCountHistory(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
122
+ getUserPositions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
123
+ getPoolUserPositionTick(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
124
+ getPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
125
+ getTopApyPoolList(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
126
+ searchPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
127
+ searchCountPools(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
128
+ getPoolHooks(): Promise<ApiResponse<unknown>>;
129
+ getPoolVolHistory(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
130
+ getPoolLiqHistory(params: Record<string, unknown>): Promise<ApiResponse<unknown>>;
131
+ getPairs(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
132
+ getFarms(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
133
+ getFarmTransactions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
134
+ getFarmPositions(params?: Record<string, unknown>): Promise<ApiResponse<unknown>>;
135
+ }
136
+
137
+ declare const SUNPUMP_DEFAULT_BASE_URL: string;
138
+ declare function buildSunPumpUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | undefined>): string;
139
+ type QueryValue = string | number | boolean | null | undefined;
140
+ type SunPumpQuery = Record<string, QueryValue>;
141
+ interface SunPumpEnvelope<T = unknown> {
142
+ readonly code: number;
143
+ readonly msg?: string;
144
+ readonly data: T;
145
+ readonly pagination?: {
146
+ pageNum: number;
147
+ pageSize: number;
148
+ total: number;
149
+ };
150
+ }
151
+ interface AgentTokenLaunchParams {
152
+ name: string;
153
+ symbol: string;
154
+ description: string;
155
+ imageBase64?: string;
156
+ twitterUrl?: string;
157
+ telegramUrl?: string;
158
+ websiteUrl?: string;
159
+ tweetUsername?: string;
160
+ }
161
+ interface SunPumpApiOptions {
162
+ network?: Network;
163
+ baseUrl?: string;
164
+ fetchImpl?: FetchLike;
165
+ jsonParser?: JsonParser;
166
+ }
167
+ declare class SunPumpApiClient {
168
+ private readonly baseUrl;
169
+ private readonly fetchImpl;
170
+ private readonly jsonParser;
171
+ constructor(opts?: SunPumpApiOptions);
172
+ private request;
173
+ private post;
174
+ listTokens(query?: SunPumpQuery): Promise<unknown>;
175
+ getToken(contractAddress: string): Promise<unknown>;
176
+ searchTokens(query?: SunPumpQuery): Promise<unknown>;
177
+ searchTokensV2(query?: SunPumpQuery): Promise<unknown>;
178
+ tokensByOwner(query: SunPumpQuery): Promise<unknown>;
179
+ tokenHolders(query: SunPumpQuery): Promise<unknown>;
180
+ tokenHoldersV2(query: SunPumpQuery): Promise<unknown>;
181
+ userFavors(query: SunPumpQuery): Promise<unknown>;
182
+ ranking(query: SunPumpQuery): Promise<unknown>;
183
+ kingOfHill(): Promise<unknown>;
184
+ pumpTokenList(): Promise<unknown>;
185
+ tokenTransactions(contractAddress: string, query?: SunPumpQuery): Promise<unknown>;
186
+ userTransactions(ownerAddress: string, query?: SunPumpQuery): Promise<unknown>;
187
+ portfolio(address: string, query?: SunPumpQuery): Promise<unknown>;
188
+ agentTokenLaunch(params: AgentTokenLaunchParams): Promise<unknown>;
189
+ }
190
+
191
+ /** Reads Unix milliseconds from the SUN time service, with a 3-second limit. */
192
+ declare function getServerTime(url: string, fetchImpl?: FetchLike, jsonParser?: JsonParser): Promise<number>;
193
+
194
+ declare const TRONSCAN_DEFAULT_BASE_URL: string;
195
+ interface TronScanOptions {
196
+ network?: Network;
197
+ baseUrl?: string;
198
+ fetchImpl?: FetchLike;
199
+ apiKey?: string;
200
+ jsonParser?: JsonParser;
201
+ }
202
+ declare class TronScanClient {
203
+ private readonly baseUrl;
204
+ private readonly fetchImpl;
205
+ private readonly jsonParser;
206
+ private readonly apiKey;
207
+ constructor(opts?: TronScanOptions);
208
+ private get;
209
+ getTokenTrc20(params: Record<string, unknown>): Promise<unknown>;
210
+ getTokenHolderBalance(params: Record<string, unknown>): Promise<unknown>;
211
+ getAccountTokens(params: Record<string, unknown>): Promise<unknown>;
212
+ }
213
+
214
+ export { type AgentTokenLaunchParams, type ApiResponse, type FetchLike, type HttpClientOptions, type JsonParser, PRICE_DEFAULT_BASE_URL, PriceClient, type PriceOptions, type RequestJsonOptions, RouterApiClient, type RouterApiOptions, type RouterRoute, type RouterRouteAmountFields, type RouterUniversalParams, type RouterUniversalResponse, SUNPUMP_DEFAULT_BASE_URL, SUN_OPEN_API_DEFAULT_BASE_URL, SunApiClient, type SunApiEnvelope, type SunApiOptions, SunHttpClient, SunPumpApiClient, type SunPumpApiOptions, type SunPumpEnvelope, type SunPumpQuery, TRONSCAN_DEFAULT_BASE_URL, TronScanClient, type TronScanOptions, buildRouterUniversalUrl, buildSunPumpUrl, defaultFetch, defaultJsonParser, getServerTime, parseApiEnvelope, requestJson };