@chainstream-io/sdk 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +76 -60
- package/dist/esm/openapi/apis/BlockchainApi.js +61 -44
- package/dist/esm/openapi/apis/DefiSolanaMoonshotApi.js +67 -50
- package/dist/esm/openapi/apis/DefiSolanaPumpfunApi.js +38 -25
- package/dist/esm/openapi/apis/DexApi.js +205 -176
- package/dist/esm/openapi/apis/DexPoolApi.js +41 -28
- package/dist/esm/openapi/apis/EndpointApi.js +212 -175
- package/dist/esm/openapi/apis/IpfsApi.js +38 -25
- package/dist/esm/openapi/apis/JobsApi.js +65 -48
- package/dist/esm/openapi/apis/RankingApi.js +278 -249
- package/dist/esm/openapi/apis/RedPacketApi.js +294 -253
- package/dist/esm/openapi/apis/TokenApi.js +1145 -1056
- package/dist/esm/openapi/apis/TradeApi.js +233 -208
- package/dist/esm/openapi/apis/TransactionApi.js +42 -29
- package/dist/esm/openapi/apis/WalletApi.js +148 -123
- package/dist/esm/openapi/apis/WatchlistApi.js +41 -28
- package/dist/esm/openapi/runtime.js +81 -69
- package/dist/esm/stream/index.d.ts +3 -0
- package/dist/esm/stream/index.js +3 -0
- package/dist/esm/{api → stream}/stream.js +36 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -59
- package/dist/openapi/apis/BlockchainApi.js +62 -78
- package/dist/openapi/apis/DefiSolanaMoonshotApi.js +68 -84
- package/dist/openapi/apis/DefiSolanaPumpfunApi.js +39 -59
- package/dist/openapi/apis/DexApi.js +206 -210
- package/dist/openapi/apis/DexPoolApi.js +42 -62
- package/dist/openapi/apis/EndpointApi.js +213 -209
- package/dist/openapi/apis/IpfsApi.js +39 -59
- package/dist/openapi/apis/JobsApi.js +66 -82
- package/dist/openapi/apis/RankingApi.js +279 -283
- package/dist/openapi/apis/RedPacketApi.js +295 -287
- package/dist/openapi/apis/TokenApi.js +1146 -1090
- package/dist/openapi/apis/TradeApi.js +234 -242
- package/dist/openapi/apis/TransactionApi.js +43 -63
- package/dist/openapi/apis/WalletApi.js +149 -157
- package/dist/openapi/apis/WatchlistApi.js +42 -62
- package/dist/openapi/runtime.js +81 -69
- package/dist/stream/index.d.ts +3 -0
- package/dist/stream/index.js +19 -0
- package/dist/{api → stream}/stream.js +36 -29
- package/package.json +29 -26
- package/src/api/stream.fields.ts +0 -271
- package/src/api/stream.model.ts +0 -307
- package/src/api/stream.ts +0 -1086
- package/src/index.ts +0 -188
- package/src/openapi/apis/BlockchainApi.ts +0 -140
- package/src/openapi/apis/DefiSolanaMoonshotApi.ts +0 -145
- package/src/openapi/apis/DefiSolanaPumpfunApi.ts +0 -86
- package/src/openapi/apis/DexApi.ts +0 -490
- package/src/openapi/apis/DexPoolApi.ts +0 -107
- package/src/openapi/apis/EndpointApi.ts +0 -421
- package/src/openapi/apis/IpfsApi.ts +0 -66
- package/src/openapi/apis/JobsApi.ts +0 -135
- package/src/openapi/apis/RankingApi.ts +0 -939
- package/src/openapi/apis/RedPacketApi.ts +0 -621
- package/src/openapi/apis/TokenApi.ts +0 -2569
- package/src/openapi/apis/TradeApi.ts +0 -596
- package/src/openapi/apis/TransactionApi.ts +0 -95
- package/src/openapi/apis/WalletApi.ts +0 -365
- package/src/openapi/apis/WatchlistApi.ts +0 -107
- package/src/openapi/apis/index.ts +0 -17
- package/src/openapi/index.ts +0 -5
- package/src/openapi/models/BlockchainDTO.ts +0 -93
- package/src/openapi/models/BlockchainLatestBlockDTO.ts +0 -75
- package/src/openapi/models/BooleanResultDTO.ts +0 -66
- package/src/openapi/models/CalculatePnlInput.ts +0 -65
- package/src/openapi/models/Candle.ts +0 -130
- package/src/openapi/models/ClaimRedPacketInput.ts +0 -90
- package/src/openapi/models/CreateEndpointInput.ts +0 -121
- package/src/openapi/models/CreateRedPacketInput.ts +0 -124
- package/src/openapi/models/CreateRedPacketReply.ts +0 -75
- package/src/openapi/models/CreateTokenInput.ts +0 -139
- package/src/openapi/models/CreateTokenReply.ts +0 -75
- package/src/openapi/models/DexDTO.ts +0 -90
- package/src/openapi/models/DexPage.ts +0 -114
- package/src/openapi/models/DexPoolDTO.ts +0 -141
- package/src/openapi/models/EndpointListResponse.ts +0 -97
- package/src/openapi/models/EndpointOperationResponse.ts +0 -65
- package/src/openapi/models/EndpointResponse.ts +0 -145
- package/src/openapi/models/EndpointSecretResponse.ts +0 -65
- package/src/openapi/models/FilterCondition.ts +0 -135
- package/src/openapi/models/GainersAndLosersDTO.ts +0 -93
- package/src/openapi/models/GainersAndLosersPage.ts +0 -114
- package/src/openapi/models/JobDTO.ts +0 -75
- package/src/openapi/models/JobStreamingDTO.ts +0 -75
- package/src/openapi/models/Link.ts +0 -88
- package/src/openapi/models/MoonshotCreateTokenInput.ts +0 -182
- package/src/openapi/models/MoonshotCreateTokenReply.ts +0 -75
- package/src/openapi/models/MoonshotSubmitCreateToken200Response.ts +0 -73
- package/src/openapi/models/MoonshotSubmitCreateTokenInput.ts +0 -74
- package/src/openapi/models/PumpCreateTokenInput.ts +0 -180
- package/src/openapi/models/PumpCreateTokenReply.ts +0 -74
- package/src/openapi/models/QuoteResponse.ts +0 -105
- package/src/openapi/models/RedPacketClaimDTO.ts +0 -148
- package/src/openapi/models/RedPacketClaimsPage.ts +0 -110
- package/src/openapi/models/RedPacketDTO.ts +0 -229
- package/src/openapi/models/RedPacketReply.ts +0 -66
- package/src/openapi/models/RedPacketSendTxInput.ts +0 -66
- package/src/openapi/models/RedPacketSendTxResponse.ts +0 -66
- package/src/openapi/models/RedPacketsPage.ts +0 -110
- package/src/openapi/models/Resolution.ts +0 -61
- package/src/openapi/models/SendTxInput.ts +0 -93
- package/src/openapi/models/SendTxResponse.ts +0 -84
- package/src/openapi/models/SwapInput.ts +0 -157
- package/src/openapi/models/SwapReply.ts +0 -75
- package/src/openapi/models/SwapRouteInput.ts +0 -186
- package/src/openapi/models/SwapRouteResponse.ts +0 -101
- package/src/openapi/models/Token.ts +0 -251
- package/src/openapi/models/TokenCreationDTO.ts +0 -131
- package/src/openapi/models/TokenCreationPage.ts +0 -114
- package/src/openapi/models/TokenCreatorsDTO.ts +0 -81
- package/src/openapi/models/TokenExtraDTO.ts +0 -225
- package/src/openapi/models/TokenHolder.ts +0 -93
- package/src/openapi/models/TokenHolderPage.ts +0 -114
- package/src/openapi/models/TokenListPage.ts +0 -114
- package/src/openapi/models/TokenMarketData.ts +0 -190
- package/src/openapi/models/TokenMetadata.ts +0 -188
- package/src/openapi/models/TokenPage.ts +0 -122
- package/src/openapi/models/TokenPriceDTO.ts +0 -93
- package/src/openapi/models/TokenPricePage.ts +0 -114
- package/src/openapi/models/TokenSocialMediasDTO.ts +0 -161
- package/src/openapi/models/TokenStat.ts +0 -1152
- package/src/openapi/models/TopTradersDTO.ts +0 -164
- package/src/openapi/models/TopTradersPage.ts +0 -114
- package/src/openapi/models/TradeDetailDTO.ts +0 -282
- package/src/openapi/models/TradeEvent.ts +0 -184
- package/src/openapi/models/TradePage.ts +0 -114
- package/src/openapi/models/TradeType.ts +0 -53
- package/src/openapi/models/UpdateEndpointInput.ts +0 -129
- package/src/openapi/models/WalletBalanceDetailDTO.ts +0 -282
- package/src/openapi/models/WalletBalancesDTO.ts +0 -92
- package/src/openapi/models/WalletPnlDTO.ts +0 -264
- package/src/openapi/models/index.ts +0 -72
- package/src/openapi/runtime.ts +0 -432
- /package/dist/{api → esm/stream}/stream.d.ts +0 -0
- /package/dist/{api → esm/stream}/stream.fields.d.ts +0 -0
- /package/dist/esm/{api → stream}/stream.fields.js +0 -0
- /package/dist/{api → esm/stream}/stream.model.d.ts +0 -0
- /package/dist/esm/{api → stream}/stream.model.js +0 -0
- /package/dist/{esm/api → stream}/stream.d.ts +0 -0
- /package/dist/{esm/api → stream}/stream.fields.d.ts +0 -0
- /package/dist/{api → stream}/stream.fields.js +0 -0
- /package/dist/{esm/api → stream}/stream.model.d.ts +0 -0
- /package/dist/{api → stream}/stream.model.js +0 -0
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
* https://openapi-generator.tech
|
|
12
12
|
* Do not edit the class manually.
|
|
13
13
|
*/
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
14
23
|
export const BASE_PATH = "https://api-dex.chainstream.io".replace(/\/+$/, "");
|
|
15
24
|
export class Configuration {
|
|
16
25
|
constructor(configuration = {}) {
|
|
@@ -47,7 +56,7 @@ export class Configuration {
|
|
|
47
56
|
get accessToken() {
|
|
48
57
|
const accessToken = this.configuration.accessToken;
|
|
49
58
|
if (accessToken) {
|
|
50
|
-
return typeof accessToken === 'function' ? accessToken :
|
|
59
|
+
return typeof accessToken === 'function' ? accessToken : () => __awaiter(this, void 0, void 0, function* () { return accessToken; });
|
|
51
60
|
}
|
|
52
61
|
return undefined;
|
|
53
62
|
}
|
|
@@ -65,30 +74,27 @@ export const DefaultConfig = new Configuration();
|
|
|
65
74
|
export class BaseAPI {
|
|
66
75
|
constructor(configuration = DefaultConfig) {
|
|
67
76
|
this.configuration = configuration;
|
|
68
|
-
this.fetchApi =
|
|
77
|
+
this.fetchApi = (url, init) => __awaiter(this, void 0, void 0, function* () {
|
|
69
78
|
let fetchParams = { url, init };
|
|
70
79
|
for (const middleware of this.middleware) {
|
|
71
80
|
if (middleware.pre) {
|
|
72
|
-
fetchParams =
|
|
73
|
-
fetch: this.fetchApi,
|
|
74
|
-
...fetchParams,
|
|
75
|
-
}) || fetchParams;
|
|
81
|
+
fetchParams = (yield middleware.pre(Object.assign({ fetch: this.fetchApi }, fetchParams))) || fetchParams;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
let response = undefined;
|
|
79
85
|
try {
|
|
80
|
-
response =
|
|
86
|
+
response = yield (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
81
87
|
}
|
|
82
88
|
catch (e) {
|
|
83
89
|
for (const middleware of this.middleware) {
|
|
84
90
|
if (middleware.onError) {
|
|
85
|
-
response =
|
|
91
|
+
response = (yield middleware.onError({
|
|
86
92
|
fetch: this.fetchApi,
|
|
87
93
|
url: fetchParams.url,
|
|
88
94
|
init: fetchParams.init,
|
|
89
95
|
error: e,
|
|
90
96
|
response: response ? response.clone() : undefined,
|
|
91
|
-
}) || response;
|
|
97
|
+
})) || response;
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
if (response === undefined) {
|
|
@@ -102,16 +108,16 @@ export class BaseAPI {
|
|
|
102
108
|
}
|
|
103
109
|
for (const middleware of this.middleware) {
|
|
104
110
|
if (middleware.post) {
|
|
105
|
-
response =
|
|
111
|
+
response = (yield middleware.post({
|
|
106
112
|
fetch: this.fetchApi,
|
|
107
113
|
url: fetchParams.url,
|
|
108
114
|
init: fetchParams.init,
|
|
109
115
|
response: response.clone(),
|
|
110
|
-
}) || response;
|
|
116
|
+
})) || response;
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
return response;
|
|
114
|
-
};
|
|
120
|
+
});
|
|
115
121
|
this.middleware = configuration.middleware;
|
|
116
122
|
}
|
|
117
123
|
withMiddleware(...middlewares) {
|
|
@@ -143,57 +149,55 @@ export class BaseAPI {
|
|
|
143
149
|
}
|
|
144
150
|
return BaseAPI.jsonRegex.test(mime);
|
|
145
151
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
152
|
+
request(context, initOverrides) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const { url, init } = yield this.createFetchParams(context, initOverrides);
|
|
155
|
+
const response = yield this.fetchApi(url, init);
|
|
156
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
157
|
+
return response;
|
|
158
|
+
}
|
|
159
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
createFetchParams(context, initOverrides) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
let url = this.configuration.basePath + context.path;
|
|
165
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
166
|
+
// only add the querystring to the URL if there are query parameters.
|
|
167
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
168
|
+
// do not handle correctly sometimes.
|
|
169
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
170
|
+
}
|
|
171
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
172
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
173
|
+
const initOverrideFn = typeof initOverrides === "function"
|
|
174
|
+
? initOverrides
|
|
175
|
+
: () => __awaiter(this, void 0, void 0, function* () { return initOverrides; });
|
|
176
|
+
const initParams = {
|
|
177
|
+
method: context.method,
|
|
178
|
+
headers,
|
|
179
|
+
body: context.body,
|
|
180
|
+
credentials: this.configuration.credentials,
|
|
181
|
+
};
|
|
182
|
+
const overriddenInit = Object.assign(Object.assign({}, initParams), (yield initOverrideFn({
|
|
176
183
|
init: initParams,
|
|
177
184
|
context,
|
|
178
|
-
}))
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
body
|
|
195
|
-
};
|
|
196
|
-
return { url, init };
|
|
185
|
+
})));
|
|
186
|
+
let body;
|
|
187
|
+
if (isFormData(overriddenInit.body)
|
|
188
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
189
|
+
|| isBlob(overriddenInit.body)) {
|
|
190
|
+
body = overriddenInit.body;
|
|
191
|
+
}
|
|
192
|
+
else if (this.isJsonMime(headers['Content-Type'])) {
|
|
193
|
+
body = JSON.stringify(overriddenInit.body);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
body = overriddenInit.body;
|
|
197
|
+
}
|
|
198
|
+
const init = Object.assign(Object.assign({}, overriddenInit), { body });
|
|
199
|
+
return { url, init };
|
|
200
|
+
});
|
|
197
201
|
}
|
|
198
202
|
/**
|
|
199
203
|
* Create a shallow clone of `this` by constructing a new instance
|
|
@@ -290,24 +294,30 @@ export class JSONApiResponse {
|
|
|
290
294
|
this.raw = raw;
|
|
291
295
|
this.transformer = transformer;
|
|
292
296
|
}
|
|
293
|
-
|
|
294
|
-
return this
|
|
297
|
+
value() {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
return this.transformer(yield this.raw.json());
|
|
300
|
+
});
|
|
295
301
|
}
|
|
296
302
|
}
|
|
297
303
|
export class VoidApiResponse {
|
|
298
304
|
constructor(raw) {
|
|
299
305
|
this.raw = raw;
|
|
300
306
|
}
|
|
301
|
-
|
|
302
|
-
return
|
|
307
|
+
value() {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
return undefined;
|
|
310
|
+
});
|
|
303
311
|
}
|
|
304
312
|
}
|
|
305
313
|
export class BlobApiResponse {
|
|
306
314
|
constructor(raw) {
|
|
307
315
|
this.raw = raw;
|
|
308
316
|
}
|
|
309
|
-
|
|
310
|
-
return
|
|
317
|
+
value() {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
+
return yield this.raw.blob();
|
|
320
|
+
});
|
|
311
321
|
}
|
|
312
322
|
;
|
|
313
323
|
}
|
|
@@ -315,8 +325,10 @@ export class TextApiResponse {
|
|
|
315
325
|
constructor(raw) {
|
|
316
326
|
this.raw = raw;
|
|
317
327
|
}
|
|
318
|
-
|
|
319
|
-
return
|
|
328
|
+
value() {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
return yield this.raw.text();
|
|
331
|
+
});
|
|
320
332
|
}
|
|
321
333
|
;
|
|
322
334
|
}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { Centrifuge } from "@chainstream-io/centrifuge";
|
|
2
11
|
import { replaceFilterFields } from "./stream.fields";
|
|
3
12
|
export class StreamApi {
|
|
4
13
|
constructor(context) {
|
|
5
14
|
const realtimeEndpoint = context.streamUrl;
|
|
6
15
|
this.realtimeClient = new Centrifuge(realtimeEndpoint, {
|
|
7
|
-
getToken:
|
|
16
|
+
getToken: (_ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
8
17
|
return typeof context.accessToken === "string"
|
|
9
18
|
? context.accessToken
|
|
10
|
-
:
|
|
11
|
-
},
|
|
19
|
+
: yield context.accessToken.getToken();
|
|
20
|
+
}),
|
|
12
21
|
});
|
|
13
22
|
this.realtimeClient
|
|
14
23
|
.on("connected", () => {
|
|
@@ -79,10 +88,7 @@ export class StreamApi {
|
|
|
79
88
|
console.log("[xrealtime] create new sub: ", channel);
|
|
80
89
|
// Process filter expression with method-specific field mappings
|
|
81
90
|
const processedFilter = filter && methodName ? replaceFilterFields(filter, methodName) : filter;
|
|
82
|
-
sub = this.realtimeClient.newSubscription(channel, {
|
|
83
|
-
delta: "fossil",
|
|
84
|
-
...(processedFilter && { filter: processedFilter }),
|
|
85
|
-
});
|
|
91
|
+
sub = this.realtimeClient.newSubscription(channel, Object.assign({ delta: "fossil" }, (processedFilter && { filter: processedFilter })));
|
|
86
92
|
sub
|
|
87
93
|
.on("subscribed", () => {
|
|
88
94
|
console.log("[xrealtime] subscribed", channel);
|
|
@@ -92,11 +98,11 @@ export class StreamApi {
|
|
|
92
98
|
})
|
|
93
99
|
.on("publication", (ctx) => {
|
|
94
100
|
// console.log('[xrealtime] publication, ctx.data: ', ctx.data);
|
|
95
|
-
listeners
|
|
101
|
+
listeners === null || listeners === void 0 ? void 0 : listeners.forEach((it) => it(ctx.data));
|
|
96
102
|
})
|
|
97
103
|
.subscribe();
|
|
98
104
|
}
|
|
99
|
-
listeners
|
|
105
|
+
listeners === null || listeners === void 0 ? void 0 : listeners.add(fn);
|
|
100
106
|
return new StreamUnsubscrible(this, channel, fn);
|
|
101
107
|
}
|
|
102
108
|
unsubscribe(channel, fn) {
|
|
@@ -267,44 +273,45 @@ export class StreamApi {
|
|
|
267
273
|
imageUrl: it.iu,
|
|
268
274
|
description: it.de,
|
|
269
275
|
socialMedia: (() => {
|
|
276
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
270
277
|
const socialMedia = {};
|
|
271
|
-
if (it.sm
|
|
278
|
+
if ((_a = it.sm) === null || _a === void 0 ? void 0 : _a.tw) {
|
|
272
279
|
socialMedia.twitter = it.sm.tw;
|
|
273
280
|
}
|
|
274
|
-
if (it.sm
|
|
281
|
+
if ((_b = it.sm) === null || _b === void 0 ? void 0 : _b.tg) {
|
|
275
282
|
socialMedia.telegram = it.sm.tg;
|
|
276
283
|
}
|
|
277
|
-
if (it.sm
|
|
284
|
+
if ((_c = it.sm) === null || _c === void 0 ? void 0 : _c.w) {
|
|
278
285
|
socialMedia.website = it.sm.w;
|
|
279
286
|
}
|
|
280
|
-
if (it.sm
|
|
287
|
+
if ((_d = it.sm) === null || _d === void 0 ? void 0 : _d.tt) {
|
|
281
288
|
socialMedia.tiktok = it.sm.tt;
|
|
282
289
|
}
|
|
283
|
-
if (it.sm
|
|
290
|
+
if ((_e = it.sm) === null || _e === void 0 ? void 0 : _e.dc) {
|
|
284
291
|
socialMedia.discord = it.sm.dc;
|
|
285
292
|
}
|
|
286
|
-
if (it.sm
|
|
293
|
+
if ((_f = it.sm) === null || _f === void 0 ? void 0 : _f.fb) {
|
|
287
294
|
socialMedia.facebook = it.sm.fb;
|
|
288
295
|
}
|
|
289
|
-
if (it.sm
|
|
296
|
+
if ((_g = it.sm) === null || _g === void 0 ? void 0 : _g.gh) {
|
|
290
297
|
socialMedia.github = it.sm.gh;
|
|
291
298
|
}
|
|
292
|
-
if (it.sm
|
|
299
|
+
if ((_h = it.sm) === null || _h === void 0 ? void 0 : _h.ig) {
|
|
293
300
|
socialMedia.instagram = it.sm.ig;
|
|
294
301
|
}
|
|
295
|
-
if (it.sm
|
|
302
|
+
if ((_j = it.sm) === null || _j === void 0 ? void 0 : _j.li) {
|
|
296
303
|
socialMedia.linkedin = it.sm.li;
|
|
297
304
|
}
|
|
298
|
-
if (it.sm
|
|
305
|
+
if ((_k = it.sm) === null || _k === void 0 ? void 0 : _k.md) {
|
|
299
306
|
socialMedia.medium = it.sm.md;
|
|
300
307
|
}
|
|
301
|
-
if (it.sm
|
|
308
|
+
if ((_l = it.sm) === null || _l === void 0 ? void 0 : _l.rd) {
|
|
302
309
|
socialMedia.reddit = it.sm.rd;
|
|
303
310
|
}
|
|
304
|
-
if (it.sm
|
|
311
|
+
if ((_m = it.sm) === null || _m === void 0 ? void 0 : _m.yt) {
|
|
305
312
|
socialMedia.youtube = it.sm.yt;
|
|
306
313
|
}
|
|
307
|
-
if (it.sm
|
|
314
|
+
if ((_o = it.sm) === null || _o === void 0 ? void 0 : _o.bb) {
|
|
308
315
|
socialMedia.bitbucket = it.sm.bb;
|
|
309
316
|
}
|
|
310
317
|
return socialMedia;
|
|
@@ -355,7 +362,7 @@ export class StreamApi {
|
|
|
355
362
|
}
|
|
356
363
|
subscribeRankingTokensLiquidity({ chain, channelType, callback, }) {
|
|
357
364
|
const channel = `dex-ranking-token-general_stat_num-list:${chain}_${channelType}`;
|
|
358
|
-
return this.subscribe(channel, (data) => callback(data
|
|
365
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
359
366
|
tokenAddress: it.a,
|
|
360
367
|
metricType: it.t,
|
|
361
368
|
value: it.v,
|
|
@@ -366,7 +373,7 @@ export class StreamApi {
|
|
|
366
373
|
const channel = dex
|
|
367
374
|
? `dex-ranking-list:${chain}_${ranking_type}_${dex}`
|
|
368
375
|
: `dex-ranking-list:${chain}_${ranking_type}`;
|
|
369
|
-
return this.subscribe(channel, (data) => callback(data
|
|
376
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((item) => {
|
|
370
377
|
const result = {};
|
|
371
378
|
// TokenMetadata (t)
|
|
372
379
|
if (item.t) {
|
|
@@ -721,7 +728,7 @@ export class StreamApi {
|
|
|
721
728
|
}
|
|
722
729
|
subscribeRankingTokensStats({ chain, channelType, callback, }) {
|
|
723
730
|
const channel = `dex-ranking-token-stats-list:${chain}_${channelType}`;
|
|
724
|
-
return this.subscribe(channel, (data) => callback(data
|
|
731
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
725
732
|
address: it.a,
|
|
726
733
|
timestamp: it.t,
|
|
727
734
|
buys1m: it.b1m,
|
|
@@ -792,7 +799,7 @@ export class StreamApi {
|
|
|
792
799
|
}
|
|
793
800
|
subscribeRankingTokensHolders({ chain, channelType, callback, }) {
|
|
794
801
|
const channel = `dex-ranking-token-holding-list:${chain}_${channelType}`;
|
|
795
|
-
return this.subscribe(channel, (data) => callback(data
|
|
802
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
796
803
|
tokenAddress: it.a,
|
|
797
804
|
holders: it.h,
|
|
798
805
|
top100Amount: this.formatScientificNotation(it.t100a),
|
|
@@ -806,7 +813,7 @@ export class StreamApi {
|
|
|
806
813
|
}
|
|
807
814
|
subscribeRankingTokensSupply({ chain, channelType, callback, }) {
|
|
808
815
|
const channel = `dex-ranking-token-supply-list:${chain}_${channelType}`;
|
|
809
|
-
return this.subscribe(channel, (data) => callback(data
|
|
816
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
810
817
|
tokenAddress: it.a,
|
|
811
818
|
supply: it.s,
|
|
812
819
|
marketCapInUsd: it.mc,
|
|
@@ -815,7 +822,7 @@ export class StreamApi {
|
|
|
815
822
|
}
|
|
816
823
|
subscribeRankingTokensBondingCurve({ chain, callback, }) {
|
|
817
824
|
const channel = `dex-ranking-token-bounding-curve-list:${chain}_new`;
|
|
818
|
-
return this.subscribe(channel, (data) => callback(data
|
|
825
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
819
826
|
tokenAddress: it.a,
|
|
820
827
|
progressRatio: it.pr,
|
|
821
828
|
}))));
|
|
@@ -898,7 +905,7 @@ export class StreamApi {
|
|
|
898
905
|
}
|
|
899
906
|
subscribeWalletPnlList({ chain, walletAddress, callback, }) {
|
|
900
907
|
const channel = `dex-wallet-pnl-list:${chain}_${walletAddress}`;
|
|
901
|
-
return this.subscribe(channel, (data) => callback(data
|
|
908
|
+
return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
|
|
902
909
|
walletAddress: it.a,
|
|
903
910
|
buys: it.bs,
|
|
904
911
|
buyAmount: it.ba,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamApi } from "./
|
|
1
|
+
import { StreamApi } from "./stream";
|
|
2
2
|
import { DexApi, Configuration, TransactionApi, DefiSolanaMoonshotApi, DefiSolanaPumpfunApi, DexPoolApi, TokenApi, RankingApi, TradeApi, WalletApi, RedPacketApi, IpfsApi, WatchlistApi, BlockchainApi, JobsApi } from "./openapi";
|
|
3
3
|
export interface TokenProvider {
|
|
4
4
|
getToken(): Promise<string> | string;
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DexClient = exports.LIB_VERSION = void 0;
|
|
4
|
-
const stream_1 = require("./
|
|
13
|
+
const stream_1 = require("./stream");
|
|
5
14
|
const openapi_1 = require("./openapi");
|
|
6
15
|
const event_source_polyfill_1 = require("event-source-polyfill");
|
|
7
16
|
exports.LIB_VERSION = "0.1.5";
|
|
8
17
|
class UserAgentMiddleware {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
context.init.headers
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
context.init.headers
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
pre(context) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (!context.init.headers) {
|
|
21
|
+
context.init.headers = {};
|
|
22
|
+
}
|
|
23
|
+
if (context.init.headers instanceof Headers) {
|
|
24
|
+
context.init.headers.set("User-Agent", `dex/${exports.LIB_VERSION}/javascript`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
context.init.headers["User-Agent"] = `dex/${exports.LIB_VERSION}/javascript`;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
19
30
|
}
|
|
20
|
-
|
|
31
|
+
post(context) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
class DexClient {
|
|
24
36
|
constructor(accessToken, options = {}) {
|
|
25
|
-
|
|
26
|
-
const
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const baseUrl = (_a = options.serverUrl) !== null && _a !== void 0 ? _a : "https://api-dex.chainstream.io";
|
|
39
|
+
const streamUrl = (_b = options.streamUrl) !== null && _b !== void 0 ? _b : "wss://realtime-dex.chainstream.io/connection/websocket";
|
|
27
40
|
const tokenProvider = typeof accessToken === "string"
|
|
28
41
|
? {
|
|
29
42
|
getToken: () => accessToken,
|
|
@@ -33,14 +46,14 @@ class DexClient {
|
|
|
33
46
|
const config = new openapi_1.Configuration({
|
|
34
47
|
basePath: baseUrl,
|
|
35
48
|
middleware: [new UserAgentMiddleware()],
|
|
36
|
-
accessToken:
|
|
49
|
+
accessToken: () => __awaiter(this, void 0, void 0, function* () {
|
|
37
50
|
return typeof accessToken === "string"
|
|
38
51
|
? accessToken
|
|
39
|
-
:
|
|
40
|
-
},
|
|
52
|
+
: yield accessToken.getToken();
|
|
53
|
+
}),
|
|
41
54
|
headers: {
|
|
42
|
-
|
|
43
|
-
}
|
|
55
|
+
"User-Agent": `dex/${exports.LIB_VERSION}/javascript`,
|
|
56
|
+
},
|
|
44
57
|
});
|
|
45
58
|
this._configuration = config;
|
|
46
59
|
this.dex = new openapi_1.DexApi(config);
|
|
@@ -60,52 +73,55 @@ class DexClient {
|
|
|
60
73
|
this.jobs = new openapi_1.JobsApi(config);
|
|
61
74
|
this.stream.connect();
|
|
62
75
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
waitForJob(jobId_1) {
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* (jobId, timeout = 60000) {
|
|
78
|
+
const accessToken = typeof this.requestCtx.accessToken === "string"
|
|
79
|
+
? this.requestCtx.accessToken
|
|
80
|
+
: yield this.requestCtx.accessToken.getToken();
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const sse = new event_source_polyfill_1.EventSourcePolyfill(`${this.requestCtx.baseUrl}/jobs/${jobId}/streaming`, {
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: `Bearer ${accessToken}`,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const timeoutId = setTimeout(() => {
|
|
88
|
+
sse.close();
|
|
89
|
+
reject(new Error(`Job ${jobId} timed out after ${timeout}ms`));
|
|
90
|
+
}, timeout);
|
|
91
|
+
sse.onmessage = (event) => {
|
|
92
|
+
try {
|
|
93
|
+
console.log("event.data: ", event.data);
|
|
94
|
+
const data = JSON.parse(event.data);
|
|
95
|
+
if (data.status === "error") {
|
|
96
|
+
sse.close();
|
|
97
|
+
reject(new Error(`Error: ${data.message}`));
|
|
98
|
+
}
|
|
99
|
+
else if (data.status === "completed") {
|
|
100
|
+
clearTimeout(timeoutId);
|
|
101
|
+
sse.close();
|
|
102
|
+
resolve(data);
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
|
-
|
|
105
|
+
catch (e) {
|
|
86
106
|
clearTimeout(timeoutId);
|
|
87
107
|
sse.close();
|
|
88
|
-
|
|
108
|
+
reject(new Error("Error parsing event data"));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
sse.onopen = () => {
|
|
112
|
+
console.log("SSE connection opened");
|
|
113
|
+
};
|
|
114
|
+
sse.onerror = (error) => {
|
|
115
|
+
var _a;
|
|
116
|
+
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("No activity within")) {
|
|
117
|
+
console.log("SSE reconnecting due to inactivity...");
|
|
118
|
+
return;
|
|
89
119
|
}
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
120
|
clearTimeout(timeoutId);
|
|
93
121
|
sse.close();
|
|
94
|
-
reject(new Error(
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
sse.onopen = () => {
|
|
98
|
-
console.log("SSE connection opened");
|
|
99
|
-
};
|
|
100
|
-
sse.onerror = (error) => {
|
|
101
|
-
if (error.message?.includes("No activity within")) {
|
|
102
|
-
console.log("SSE reconnecting due to inactivity...");
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
clearTimeout(timeoutId);
|
|
106
|
-
sse.close();
|
|
107
|
-
reject(new Error(`Error in SSE connection: ${error}`));
|
|
108
|
-
};
|
|
122
|
+
reject(new Error(`Error in SSE connection: ${error}`));
|
|
123
|
+
};
|
|
124
|
+
});
|
|
109
125
|
});
|
|
110
126
|
}
|
|
111
127
|
}
|