@nightlylabs/dex-sdk 0.0.1
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/dist/index.cjs +1306 -0
- package/dist/index.d.cts +590 -0
- package/dist/index.d.ts +590 -0
- package/dist/index.js +1254 -0
- package/package.json +55 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AdminEndpoints: () => AdminEndpoints,
|
|
34
|
+
BaseEndpoints: () => BaseEndpoints,
|
|
35
|
+
Client: () => Client,
|
|
36
|
+
EndpointsV1: () => EndpointsV1,
|
|
37
|
+
ExchangeProxies: () => ExchangeProxies,
|
|
38
|
+
GLOBAL_DENOMINATOR: () => GLOBAL_DENOMINATOR,
|
|
39
|
+
Network: () => Network,
|
|
40
|
+
OrderSide: () => OrderSide,
|
|
41
|
+
OrderStatus: () => OrderStatus,
|
|
42
|
+
OrderType: () => OrderType,
|
|
43
|
+
PerpetualMarketStatus: () => PerpetualMarketStatus,
|
|
44
|
+
Status: () => Status,
|
|
45
|
+
TestFaucet: () => TestFaucet,
|
|
46
|
+
TradeRole: () => TradeRole,
|
|
47
|
+
UserStatus: () => UserStatus,
|
|
48
|
+
getRandomId: () => getRandomId
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(index_exports);
|
|
51
|
+
|
|
52
|
+
// src/client.ts
|
|
53
|
+
var import_surf = require("@thalalabs/surf");
|
|
54
|
+
var import_isomorphic_ws = __toESM(require("isomorphic-ws"), 1);
|
|
55
|
+
var import_uuid = require("uuid");
|
|
56
|
+
|
|
57
|
+
// generated_types/addApiKey.ts
|
|
58
|
+
var ABI = {
|
|
59
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
60
|
+
"name": "add_api_key",
|
|
61
|
+
"friends": [],
|
|
62
|
+
"exposed_functions": [
|
|
63
|
+
{
|
|
64
|
+
"name": "add_api_key",
|
|
65
|
+
"visibility": "public",
|
|
66
|
+
"is_entry": true,
|
|
67
|
+
"is_view": false,
|
|
68
|
+
"generic_type_params": [],
|
|
69
|
+
"params": [
|
|
70
|
+
"&signer",
|
|
71
|
+
"&signer",
|
|
72
|
+
"u64",
|
|
73
|
+
"u64"
|
|
74
|
+
],
|
|
75
|
+
"return": []
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"structs": []
|
|
79
|
+
};
|
|
80
|
+
var addApiKey_default = ABI;
|
|
81
|
+
|
|
82
|
+
// generated_types/cancelAllPerpOrders.ts
|
|
83
|
+
var ABI2 = {
|
|
84
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
85
|
+
"name": "cancel_all_perp_orders",
|
|
86
|
+
"friends": [],
|
|
87
|
+
"exposed_functions": [
|
|
88
|
+
{
|
|
89
|
+
"name": "cancel_all_perp_orders",
|
|
90
|
+
"visibility": "public",
|
|
91
|
+
"is_entry": true,
|
|
92
|
+
"is_view": false,
|
|
93
|
+
"generic_type_params": [],
|
|
94
|
+
"params": [
|
|
95
|
+
"&signer",
|
|
96
|
+
"u64"
|
|
97
|
+
],
|
|
98
|
+
"return": []
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"structs": []
|
|
102
|
+
};
|
|
103
|
+
var cancelAllPerpOrders_default = ABI2;
|
|
104
|
+
|
|
105
|
+
// generated_types/cancelPerpOrders.ts
|
|
106
|
+
var ABI3 = {
|
|
107
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
108
|
+
"name": "cancel_perp_orders",
|
|
109
|
+
"friends": [],
|
|
110
|
+
"exposed_functions": [
|
|
111
|
+
{
|
|
112
|
+
"name": "cancel_perp_orders",
|
|
113
|
+
"visibility": "public",
|
|
114
|
+
"is_entry": true,
|
|
115
|
+
"is_view": false,
|
|
116
|
+
"generic_type_params": [],
|
|
117
|
+
"params": [
|
|
118
|
+
"&signer",
|
|
119
|
+
"u64",
|
|
120
|
+
"vector<vector<u8>>",
|
|
121
|
+
"vector<vector<u64>>"
|
|
122
|
+
],
|
|
123
|
+
"return": []
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"structs": []
|
|
127
|
+
};
|
|
128
|
+
var cancelPerpOrders_default = ABI3;
|
|
129
|
+
|
|
130
|
+
// generated_types/createUser.ts
|
|
131
|
+
var ABI4 = {
|
|
132
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
133
|
+
"name": "create_user",
|
|
134
|
+
"friends": [],
|
|
135
|
+
"exposed_functions": [
|
|
136
|
+
{
|
|
137
|
+
"name": "create_user",
|
|
138
|
+
"visibility": "public",
|
|
139
|
+
"is_entry": true,
|
|
140
|
+
"is_view": false,
|
|
141
|
+
"generic_type_params": [],
|
|
142
|
+
"params": [
|
|
143
|
+
"&signer",
|
|
144
|
+
"&signer",
|
|
145
|
+
"vector<u8>",
|
|
146
|
+
"u64"
|
|
147
|
+
],
|
|
148
|
+
"return": []
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"structs": []
|
|
152
|
+
};
|
|
153
|
+
var createUser_default = ABI4;
|
|
154
|
+
|
|
155
|
+
// generated_types/depositToVault.ts
|
|
156
|
+
var ABI5 = {
|
|
157
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
158
|
+
"name": "deposit_to_vault",
|
|
159
|
+
"friends": [],
|
|
160
|
+
"exposed_functions": [
|
|
161
|
+
{
|
|
162
|
+
"name": "deposit_to_vault",
|
|
163
|
+
"visibility": "public",
|
|
164
|
+
"is_entry": true,
|
|
165
|
+
"is_view": false,
|
|
166
|
+
"generic_type_params": [],
|
|
167
|
+
"params": [
|
|
168
|
+
"&signer",
|
|
169
|
+
"u64",
|
|
170
|
+
"u64",
|
|
171
|
+
"u128"
|
|
172
|
+
],
|
|
173
|
+
"return": []
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"structs": []
|
|
177
|
+
};
|
|
178
|
+
var depositToVault_default = ABI5;
|
|
179
|
+
|
|
180
|
+
// generated_types/lendToken.ts
|
|
181
|
+
var ABI6 = {
|
|
182
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
183
|
+
"name": "lend_token",
|
|
184
|
+
"friends": [],
|
|
185
|
+
"exposed_functions": [
|
|
186
|
+
{
|
|
187
|
+
"name": "lend_token",
|
|
188
|
+
"visibility": "public",
|
|
189
|
+
"is_entry": true,
|
|
190
|
+
"is_view": false,
|
|
191
|
+
"generic_type_params": [],
|
|
192
|
+
"params": [
|
|
193
|
+
"&signer",
|
|
194
|
+
"u64",
|
|
195
|
+
"address",
|
|
196
|
+
"u128",
|
|
197
|
+
"bool"
|
|
198
|
+
],
|
|
199
|
+
"return": []
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
"structs": []
|
|
203
|
+
};
|
|
204
|
+
var lendToken_default = ABI6;
|
|
205
|
+
|
|
206
|
+
// generated_types/placePerpLimitOrder.ts
|
|
207
|
+
var ABI7 = {
|
|
208
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
209
|
+
"name": "place_perp_limit_order",
|
|
210
|
+
"friends": [],
|
|
211
|
+
"exposed_functions": [
|
|
212
|
+
{
|
|
213
|
+
"name": "place_perp_limit_order",
|
|
214
|
+
"visibility": "public",
|
|
215
|
+
"is_entry": true,
|
|
216
|
+
"is_view": false,
|
|
217
|
+
"generic_type_params": [],
|
|
218
|
+
"params": [
|
|
219
|
+
"&signer",
|
|
220
|
+
"u64",
|
|
221
|
+
"vector<u8>",
|
|
222
|
+
"bool",
|
|
223
|
+
"u64",
|
|
224
|
+
"u64",
|
|
225
|
+
"bool"
|
|
226
|
+
],
|
|
227
|
+
"return": []
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"structs": []
|
|
231
|
+
};
|
|
232
|
+
var placePerpLimitOrder_default = ABI7;
|
|
233
|
+
|
|
234
|
+
// generated_types/placePerpMarketOrder.ts
|
|
235
|
+
var ABI8 = {
|
|
236
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
237
|
+
"name": "place_perp_market_order",
|
|
238
|
+
"friends": [],
|
|
239
|
+
"exposed_functions": [
|
|
240
|
+
{
|
|
241
|
+
"name": "place_perp_market_order",
|
|
242
|
+
"visibility": "public",
|
|
243
|
+
"is_entry": true,
|
|
244
|
+
"is_view": false,
|
|
245
|
+
"generic_type_params": [],
|
|
246
|
+
"params": [
|
|
247
|
+
"&signer",
|
|
248
|
+
"u64",
|
|
249
|
+
"vector<u8>",
|
|
250
|
+
"bool",
|
|
251
|
+
"u64",
|
|
252
|
+
"u64"
|
|
253
|
+
],
|
|
254
|
+
"return": []
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
"structs": []
|
|
258
|
+
};
|
|
259
|
+
var placePerpMarketOrder_default = ABI8;
|
|
260
|
+
|
|
261
|
+
// generated_types/redeemToken.ts
|
|
262
|
+
var ABI9 = {
|
|
263
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
264
|
+
"name": "redeem_token",
|
|
265
|
+
"friends": [],
|
|
266
|
+
"exposed_functions": [
|
|
267
|
+
{
|
|
268
|
+
"name": "redeem_token",
|
|
269
|
+
"visibility": "public",
|
|
270
|
+
"is_entry": true,
|
|
271
|
+
"is_view": false,
|
|
272
|
+
"generic_type_params": [],
|
|
273
|
+
"params": [
|
|
274
|
+
"&signer",
|
|
275
|
+
"u64",
|
|
276
|
+
"address",
|
|
277
|
+
"u128",
|
|
278
|
+
"bool"
|
|
279
|
+
],
|
|
280
|
+
"return": []
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
"structs": []
|
|
284
|
+
};
|
|
285
|
+
var redeemToken_default = ABI9;
|
|
286
|
+
|
|
287
|
+
// generated_types/removeApiKey.ts
|
|
288
|
+
var ABI10 = {
|
|
289
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
290
|
+
"name": "remove_api_key",
|
|
291
|
+
"friends": [],
|
|
292
|
+
"exposed_functions": [
|
|
293
|
+
{
|
|
294
|
+
"name": "remove_api_key",
|
|
295
|
+
"visibility": "public",
|
|
296
|
+
"is_entry": true,
|
|
297
|
+
"is_view": false,
|
|
298
|
+
"generic_type_params": [],
|
|
299
|
+
"params": [
|
|
300
|
+
"&signer",
|
|
301
|
+
"address",
|
|
302
|
+
"u64"
|
|
303
|
+
],
|
|
304
|
+
"return": []
|
|
305
|
+
}
|
|
306
|
+
],
|
|
307
|
+
"structs": []
|
|
308
|
+
};
|
|
309
|
+
var removeApiKey_default = ABI10;
|
|
310
|
+
|
|
311
|
+
// generated_types/setAliasName.ts
|
|
312
|
+
var ABI11 = {
|
|
313
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
314
|
+
"name": "set_alias_name",
|
|
315
|
+
"friends": [],
|
|
316
|
+
"exposed_functions": [
|
|
317
|
+
{
|
|
318
|
+
"name": "set_alias_name",
|
|
319
|
+
"visibility": "public",
|
|
320
|
+
"is_entry": true,
|
|
321
|
+
"is_view": false,
|
|
322
|
+
"generic_type_params": [],
|
|
323
|
+
"params": [
|
|
324
|
+
"&signer",
|
|
325
|
+
"u64",
|
|
326
|
+
"vector<u8>"
|
|
327
|
+
],
|
|
328
|
+
"return": []
|
|
329
|
+
}
|
|
330
|
+
],
|
|
331
|
+
"structs": []
|
|
332
|
+
};
|
|
333
|
+
var setAliasName_default = ABI11;
|
|
334
|
+
|
|
335
|
+
// generated_types/setAutolend.ts
|
|
336
|
+
var ABI12 = {
|
|
337
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
338
|
+
"name": "set_autolend",
|
|
339
|
+
"friends": [],
|
|
340
|
+
"exposed_functions": [
|
|
341
|
+
{
|
|
342
|
+
"name": "set_autolend",
|
|
343
|
+
"visibility": "public",
|
|
344
|
+
"is_entry": true,
|
|
345
|
+
"is_view": false,
|
|
346
|
+
"generic_type_params": [],
|
|
347
|
+
"params": [
|
|
348
|
+
"&signer",
|
|
349
|
+
"u64",
|
|
350
|
+
"bool"
|
|
351
|
+
],
|
|
352
|
+
"return": []
|
|
353
|
+
}
|
|
354
|
+
],
|
|
355
|
+
"structs": []
|
|
356
|
+
};
|
|
357
|
+
var setAutolend_default = ABI12;
|
|
358
|
+
|
|
359
|
+
// generated_types/typeshareTypes.ts
|
|
360
|
+
var PerpetualMarketStatus = /* @__PURE__ */ ((PerpetualMarketStatus2) => {
|
|
361
|
+
PerpetualMarketStatus2["Halted"] = "halted";
|
|
362
|
+
PerpetualMarketStatus2["ReduceOnly"] = "reduceOnly";
|
|
363
|
+
PerpetualMarketStatus2["PostOnly"] = "postOnly";
|
|
364
|
+
PerpetualMarketStatus2["Live"] = "live";
|
|
365
|
+
return PerpetualMarketStatus2;
|
|
366
|
+
})(PerpetualMarketStatus || {});
|
|
367
|
+
var OrderSide = /* @__PURE__ */ ((OrderSide2) => {
|
|
368
|
+
OrderSide2["Bid"] = "Bid";
|
|
369
|
+
OrderSide2["Ask"] = "Ask";
|
|
370
|
+
return OrderSide2;
|
|
371
|
+
})(OrderSide || {});
|
|
372
|
+
var EndpointsV1 = /* @__PURE__ */ ((EndpointsV12) => {
|
|
373
|
+
EndpointsV12["Ws"] = "/v1/ws";
|
|
374
|
+
EndpointsV12["GetConfig"] = "/v1/get_config";
|
|
375
|
+
EndpointsV12["GetTokensConfig"] = "/v1/get_tokens_config";
|
|
376
|
+
EndpointsV12["GetPerpMarketsConfig"] = "/v1/get_perp_markets_config";
|
|
377
|
+
EndpointsV12["GetUserData"] = "/v1/get_user_data";
|
|
378
|
+
EndpointsV12["GetPriceIndexes"] = "/v1/get_price_indexes";
|
|
379
|
+
EndpointsV12["GetPerpOrderBookData"] = "/v1/get_perp_orderbook_data";
|
|
380
|
+
EndpointsV12["GetPerpMarketsData"] = "/v1/get_perp_markets_data";
|
|
381
|
+
EndpointsV12["GetBorrowLendingData"] = "/v1/get_borrow_lending_data";
|
|
382
|
+
EndpointsV12["SubmitSponsoredTransactionRequest"] = "/v1/submit_sponsored_transaction";
|
|
383
|
+
return EndpointsV12;
|
|
384
|
+
})(EndpointsV1 || {});
|
|
385
|
+
var AdminEndpoints = /* @__PURE__ */ ((AdminEndpoints2) => {
|
|
386
|
+
AdminEndpoints2["Placeholder"] = "/admin/placeholder";
|
|
387
|
+
return AdminEndpoints2;
|
|
388
|
+
})(AdminEndpoints || {});
|
|
389
|
+
var BaseEndpoints = /* @__PURE__ */ ((BaseEndpoints2) => {
|
|
390
|
+
BaseEndpoints2["Time"] = "/time";
|
|
391
|
+
BaseEndpoints2["Status"] = "/app_status";
|
|
392
|
+
return BaseEndpoints2;
|
|
393
|
+
})(BaseEndpoints || {});
|
|
394
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
395
|
+
OrderStatus2["Placed"] = "Placed";
|
|
396
|
+
OrderStatus2["Cancelled"] = "Cancelled";
|
|
397
|
+
OrderStatus2["Filled"] = "Filled";
|
|
398
|
+
OrderStatus2["PartiallyFilled"] = "PartiallyFilled";
|
|
399
|
+
OrderStatus2["Rejected"] = "Rejected";
|
|
400
|
+
OrderStatus2["Executed"] = "Executed";
|
|
401
|
+
return OrderStatus2;
|
|
402
|
+
})(OrderStatus || {});
|
|
403
|
+
var OrderType = /* @__PURE__ */ ((OrderType2) => {
|
|
404
|
+
OrderType2["Limit"] = "Limit";
|
|
405
|
+
OrderType2["Market"] = "Market";
|
|
406
|
+
return OrderType2;
|
|
407
|
+
})(OrderType || {});
|
|
408
|
+
var TradeRole = /* @__PURE__ */ ((TradeRole2) => {
|
|
409
|
+
TradeRole2["Maker"] = "Maker";
|
|
410
|
+
TradeRole2["Taker"] = "Taker";
|
|
411
|
+
return TradeRole2;
|
|
412
|
+
})(TradeRole || {});
|
|
413
|
+
var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
414
|
+
UserStatus2["Active"] = "Active";
|
|
415
|
+
UserStatus2["Locked"] = "Locked";
|
|
416
|
+
return UserStatus2;
|
|
417
|
+
})(UserStatus || {});
|
|
418
|
+
|
|
419
|
+
// generated_types/withdrawFromVault.ts
|
|
420
|
+
var ABI13 = {
|
|
421
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
422
|
+
"name": "withdraw_from_vault",
|
|
423
|
+
"friends": [],
|
|
424
|
+
"exposed_functions": [
|
|
425
|
+
{
|
|
426
|
+
"name": "withdraw_from_vault",
|
|
427
|
+
"visibility": "public",
|
|
428
|
+
"is_entry": true,
|
|
429
|
+
"is_view": false,
|
|
430
|
+
"generic_type_params": [],
|
|
431
|
+
"params": [
|
|
432
|
+
"&signer",
|
|
433
|
+
"u64",
|
|
434
|
+
"u64",
|
|
435
|
+
"u128",
|
|
436
|
+
"bool"
|
|
437
|
+
],
|
|
438
|
+
"return": []
|
|
439
|
+
}
|
|
440
|
+
],
|
|
441
|
+
"structs": []
|
|
442
|
+
};
|
|
443
|
+
var withdrawFromVault_default = ABI13;
|
|
444
|
+
|
|
445
|
+
// src/utils.ts
|
|
446
|
+
var import_ts_sdk = require("@aptos-labs/ts-sdk");
|
|
447
|
+
|
|
448
|
+
// src/types.ts
|
|
449
|
+
var Status = /* @__PURE__ */ ((Status2) => {
|
|
450
|
+
Status2[Status2["Halted"] = 0] = "Halted";
|
|
451
|
+
Status2[Status2["ReduceOnly"] = 1] = "ReduceOnly";
|
|
452
|
+
Status2[Status2["PostOnly"] = 2] = "PostOnly";
|
|
453
|
+
Status2[Status2["Live"] = 3] = "Live";
|
|
454
|
+
return Status2;
|
|
455
|
+
})(Status || {});
|
|
456
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
457
|
+
Network2["Devnet"] = "Devnet";
|
|
458
|
+
return Network2;
|
|
459
|
+
})(Network || {});
|
|
460
|
+
|
|
461
|
+
// src/static.ts
|
|
462
|
+
var ExchangeProxies = {
|
|
463
|
+
["Devnet" /* Devnet */]: ["0x1"]
|
|
464
|
+
// TODO define it
|
|
465
|
+
};
|
|
466
|
+
var GLOBAL_DENOMINATOR = 1e8;
|
|
467
|
+
|
|
468
|
+
// src/utils.ts
|
|
469
|
+
var import_decimal = require("decimal.js");
|
|
470
|
+
var toSystemValue = (value) => {
|
|
471
|
+
return new import_decimal.Decimal(value).mul(new import_decimal.Decimal(GLOBAL_DENOMINATOR)).toString();
|
|
472
|
+
};
|
|
473
|
+
var generateApiKey = () => {
|
|
474
|
+
return import_ts_sdk.Account.generate({ scheme: 0 });
|
|
475
|
+
};
|
|
476
|
+
var getTopicFromCommand = (data) => {
|
|
477
|
+
switch (data.type) {
|
|
478
|
+
case "SubscribeMarket":
|
|
479
|
+
return data.content.market;
|
|
480
|
+
case "UnsubscribeMarket":
|
|
481
|
+
return data.content.market;
|
|
482
|
+
case "SubscribeUser":
|
|
483
|
+
return data.content.user_id;
|
|
484
|
+
case "UnsubscribeUser":
|
|
485
|
+
return data.content.user_id;
|
|
486
|
+
case "SubscribeOracle":
|
|
487
|
+
return "OracleUpdates";
|
|
488
|
+
case "UnsubscribeOracle":
|
|
489
|
+
return "OracleUpdates";
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
var getTopicFromMessage = (data) => {
|
|
493
|
+
switch (data.type) {
|
|
494
|
+
case "Ack":
|
|
495
|
+
return data.content.id;
|
|
496
|
+
case "Error":
|
|
497
|
+
return data.content.id;
|
|
498
|
+
case "OracleUpdates":
|
|
499
|
+
return data.type;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/client.ts
|
|
504
|
+
var getRandomId = () => (0, import_uuid.v4)();
|
|
505
|
+
var Client = class _Client {
|
|
506
|
+
constructor(connection, ws, url, apiKey) {
|
|
507
|
+
this._subscriptions = /* @__PURE__ */ new Map();
|
|
508
|
+
this.timeout = 5e3;
|
|
509
|
+
// GETTERS
|
|
510
|
+
this.sendGetJson = async (endpoint, message) => {
|
|
511
|
+
let URL = "http://" + this._serverUrl + endpoint + "?";
|
|
512
|
+
if (message) {
|
|
513
|
+
for (const key of Object.keys(message)) {
|
|
514
|
+
if (Array.isArray(message[key])) {
|
|
515
|
+
message[key].forEach((value) => {
|
|
516
|
+
URL += key + "=" + value + "&";
|
|
517
|
+
});
|
|
518
|
+
} else if (message[key]) {
|
|
519
|
+
URL += key + "=" + message[key] + "&";
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
URL = URL.slice(0, -1);
|
|
523
|
+
}
|
|
524
|
+
let request = {
|
|
525
|
+
method: "GET",
|
|
526
|
+
headers: {
|
|
527
|
+
"Content-Type": "application/json"
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
try {
|
|
531
|
+
const a = await fetch(URL, request);
|
|
532
|
+
if (a.status !== 200) {
|
|
533
|
+
throw new Error(await a.text());
|
|
534
|
+
}
|
|
535
|
+
return await a.json();
|
|
536
|
+
} catch (e) {
|
|
537
|
+
console.log("Error:", e);
|
|
538
|
+
let error = e;
|
|
539
|
+
throw new Error(error);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
this.sendPostJson = async (message, endpoint) => {
|
|
543
|
+
const URL = this._serverUrl + endpoint;
|
|
544
|
+
const headers = {
|
|
545
|
+
"Content-Type": "application/json"
|
|
546
|
+
};
|
|
547
|
+
try {
|
|
548
|
+
let request = {
|
|
549
|
+
method: "POST",
|
|
550
|
+
body: JSON.stringify(message),
|
|
551
|
+
headers
|
|
552
|
+
};
|
|
553
|
+
const response = await fetch(URL, request);
|
|
554
|
+
if (response.status !== 200) {
|
|
555
|
+
let msg = await response.text();
|
|
556
|
+
throw new Error(msg);
|
|
557
|
+
}
|
|
558
|
+
return await response.json();
|
|
559
|
+
} catch (e) {
|
|
560
|
+
let error = e;
|
|
561
|
+
throw new Error(error);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
565
|
+
const payload = {
|
|
566
|
+
sender: tx.rawTransaction.sender.toString(),
|
|
567
|
+
sequenceNumber: tx.rawTransaction.sequence_number.toString(),
|
|
568
|
+
payload: Array.from(tx.rawTransaction.payload.bcsToBytes()),
|
|
569
|
+
maxGasAmount: tx.rawTransaction.max_gas_amount.toString(),
|
|
570
|
+
gasUnitPrice: tx.rawTransaction.gas_unit_price.toString(),
|
|
571
|
+
expirationTimestampSecs: tx.rawTransaction.expiration_timestamp_secs.toString(),
|
|
572
|
+
chainId: parseInt(tx.rawTransaction.chain_id.toString()).toString(),
|
|
573
|
+
authenticator: Array.from(signature.bcsToBytes())
|
|
574
|
+
};
|
|
575
|
+
const response = await this.sendPostJson(
|
|
576
|
+
payload,
|
|
577
|
+
"/v1/submit_sponsored_transaction" /* SubmitSponsoredTransactionRequest */
|
|
578
|
+
);
|
|
579
|
+
return response;
|
|
580
|
+
};
|
|
581
|
+
this.getConfig = async () => {
|
|
582
|
+
const response = await this.sendGetJson("/v1/get_config" /* GetConfig */);
|
|
583
|
+
return response;
|
|
584
|
+
};
|
|
585
|
+
this.getTokensConfig = async () => {
|
|
586
|
+
const response = await this.sendGetJson(
|
|
587
|
+
"/v1/get_tokens_config" /* GetTokensConfig */
|
|
588
|
+
);
|
|
589
|
+
return response;
|
|
590
|
+
};
|
|
591
|
+
this.getPerpetualMarketsConfig = async () => {
|
|
592
|
+
const response = await this.sendGetJson(
|
|
593
|
+
"/v1/get_perp_markets_config" /* GetPerpMarketsConfig */
|
|
594
|
+
);
|
|
595
|
+
return response;
|
|
596
|
+
};
|
|
597
|
+
this.getUserData = async (userId) => {
|
|
598
|
+
const response = await this.sendGetJson("/v1/get_user_data" /* GetUserData */, {
|
|
599
|
+
userId
|
|
600
|
+
});
|
|
601
|
+
return response;
|
|
602
|
+
};
|
|
603
|
+
this.getPerpOrderBookData = async (marketName) => {
|
|
604
|
+
const response = await this.sendGetJson("/v1/get_perp_orderbook_data" /* GetPerpOrderBookData */, {
|
|
605
|
+
marketName
|
|
606
|
+
});
|
|
607
|
+
return response;
|
|
608
|
+
};
|
|
609
|
+
this.getPerpMarketsData = async (markets) => {
|
|
610
|
+
const response = await this.sendGetJson("/v1/get_perp_markets_data" /* GetPerpMarketsData */, {
|
|
611
|
+
markets
|
|
612
|
+
});
|
|
613
|
+
return response;
|
|
614
|
+
};
|
|
615
|
+
this.getBorrowLendingData = async () => {
|
|
616
|
+
const response = await this.sendGetJson("/v1/get_borrow_lending_data" /* GetBorrowLendingData */);
|
|
617
|
+
return response;
|
|
618
|
+
};
|
|
619
|
+
this._aptos = connection;
|
|
620
|
+
this._surf = (0, import_surf.createSurfClient)(this._aptos);
|
|
621
|
+
this._apiKey = apiKey || generateApiKey();
|
|
622
|
+
this._subscriptions = /* @__PURE__ */ new Map();
|
|
623
|
+
this._serverUrl = url;
|
|
624
|
+
this._ws = ws;
|
|
625
|
+
this._ws.onmessage = async (msg) => {
|
|
626
|
+
let data;
|
|
627
|
+
if (msg.data.arrayBuffer) {
|
|
628
|
+
data = new TextDecoder().decode(new Uint8Array(await msg.data.arrayBuffer()));
|
|
629
|
+
} else {
|
|
630
|
+
data = msg.data;
|
|
631
|
+
}
|
|
632
|
+
const decodedMsg = JSON.parse(data);
|
|
633
|
+
const topic = getTopicFromMessage(decodedMsg);
|
|
634
|
+
const callback = this._subscriptions.get(topic);
|
|
635
|
+
if (callback) {
|
|
636
|
+
callback(decodedMsg);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
static async init(connection, apiKey, url = "http://127.0.0.1:4567") {
|
|
641
|
+
const ws = await _Client.initWebSocket(url);
|
|
642
|
+
const client = new _Client(connection, ws, url, apiKey);
|
|
643
|
+
return client;
|
|
644
|
+
}
|
|
645
|
+
static async initWebSocket(url, timeout = 5e3) {
|
|
646
|
+
return new Promise((resolve, reject) => {
|
|
647
|
+
const ws = new import_isomorphic_ws.default(
|
|
648
|
+
`${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */
|
|
649
|
+
);
|
|
650
|
+
const timer = setTimeout(() => {
|
|
651
|
+
reject(new Error("WebSocket connection timeout"));
|
|
652
|
+
}, timeout);
|
|
653
|
+
ws.onopen = () => {
|
|
654
|
+
clearTimeout(timer);
|
|
655
|
+
resolve(ws);
|
|
656
|
+
};
|
|
657
|
+
ws.onerror = (error) => {
|
|
658
|
+
clearTimeout(timer);
|
|
659
|
+
reject(error);
|
|
660
|
+
};
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
sendWsMessage(message) {
|
|
664
|
+
return new Promise((resolve, reject) => {
|
|
665
|
+
const topic = message.content.id;
|
|
666
|
+
const timer = setTimeout(() => {
|
|
667
|
+
reject(new Error(`Connection timed out after ${this.timeout} ms`));
|
|
668
|
+
}, this.timeout);
|
|
669
|
+
let handler = (response) => {
|
|
670
|
+
clearTimeout(timer);
|
|
671
|
+
if (response.type === "Error") {
|
|
672
|
+
this._subscriptions.delete(topic);
|
|
673
|
+
reject();
|
|
674
|
+
} else {
|
|
675
|
+
this._subscriptions.delete(topic);
|
|
676
|
+
resolve(response);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
this._subscriptions.set(topic, handler);
|
|
680
|
+
this._ws.send(JSON.stringify(message));
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
static async create(connection, apiKey, url = "http://127.0.0.1:4567") {
|
|
684
|
+
return _Client.init(connection, apiKey, url);
|
|
685
|
+
}
|
|
686
|
+
setApiKey(apiKey) {
|
|
687
|
+
this._apiKey = apiKey;
|
|
688
|
+
}
|
|
689
|
+
// needs to be signed by user and sent to blockchain
|
|
690
|
+
async createUser(params) {
|
|
691
|
+
const apiKey = generateApiKey();
|
|
692
|
+
const payload = (0, import_surf.createEntryPayload)(createUser_default, {
|
|
693
|
+
function: "create_user",
|
|
694
|
+
functionArguments: [params.name, params.referralId],
|
|
695
|
+
typeArguments: []
|
|
696
|
+
});
|
|
697
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
698
|
+
sender: params.sender,
|
|
699
|
+
data: payload
|
|
700
|
+
});
|
|
701
|
+
const signature = this._aptos.sign({
|
|
702
|
+
signer: apiKey,
|
|
703
|
+
transaction: tx
|
|
704
|
+
});
|
|
705
|
+
return {
|
|
706
|
+
tx,
|
|
707
|
+
signature,
|
|
708
|
+
apiKey
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
async subscribeToUserUpdates(userId, callback) {
|
|
712
|
+
const command = {
|
|
713
|
+
type: "SubscribeUser",
|
|
714
|
+
content: { id: getRandomId(), user_id: userId }
|
|
715
|
+
};
|
|
716
|
+
await this.sendWsMessage(command);
|
|
717
|
+
const topic = getTopicFromCommand(command);
|
|
718
|
+
this._subscriptions.set(topic, callback);
|
|
719
|
+
}
|
|
720
|
+
async unsubscribeFromUserUpdates(userId) {
|
|
721
|
+
const command = {
|
|
722
|
+
type: "UnsubscribeUser",
|
|
723
|
+
content: { id: getRandomId(), user_id: userId }
|
|
724
|
+
};
|
|
725
|
+
await this.sendWsMessage(command);
|
|
726
|
+
const topic = getTopicFromCommand(command);
|
|
727
|
+
this._subscriptions.delete(topic);
|
|
728
|
+
}
|
|
729
|
+
// needs to be signed by user and sent to blockchain
|
|
730
|
+
async addApiKey(params) {
|
|
731
|
+
return (0, import_surf.createEntryPayload)(addApiKey_default, {
|
|
732
|
+
function: "add_api_key",
|
|
733
|
+
functionArguments: [params.userId, params.expiration],
|
|
734
|
+
typeArguments: []
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
// needs to be signed by user and sent to blockchain
|
|
738
|
+
async removeApiKey(params) {
|
|
739
|
+
const payload = (0, import_surf.createEntryPayload)(removeApiKey_default, {
|
|
740
|
+
function: "remove_api_key",
|
|
741
|
+
functionArguments: [params.apiKey, params.userId],
|
|
742
|
+
typeArguments: []
|
|
743
|
+
});
|
|
744
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
745
|
+
sender: this._apiKey.accountAddress,
|
|
746
|
+
data: payload,
|
|
747
|
+
withFeePayer: true
|
|
748
|
+
});
|
|
749
|
+
const signature = this._aptos.sign({
|
|
750
|
+
signer: this._apiKey,
|
|
751
|
+
transaction: tx
|
|
752
|
+
});
|
|
753
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
754
|
+
}
|
|
755
|
+
async setAliasName(params) {
|
|
756
|
+
const payload = (0, import_surf.createEntryPayload)(setAliasName_default, {
|
|
757
|
+
function: "set_alias_name",
|
|
758
|
+
functionArguments: [params.userId, params.alias],
|
|
759
|
+
typeArguments: []
|
|
760
|
+
});
|
|
761
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
762
|
+
sender: this._apiKey.accountAddress,
|
|
763
|
+
data: payload,
|
|
764
|
+
withFeePayer: true
|
|
765
|
+
});
|
|
766
|
+
const signature = this._aptos.sign({
|
|
767
|
+
signer: this._apiKey,
|
|
768
|
+
transaction: tx
|
|
769
|
+
});
|
|
770
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
771
|
+
}
|
|
772
|
+
async placePerpLimitOrder(params) {
|
|
773
|
+
const payload = (0, import_surf.createEntryPayload)(placePerpLimitOrder_default, {
|
|
774
|
+
function: "place_perp_limit_order",
|
|
775
|
+
functionArguments: [
|
|
776
|
+
params.userId,
|
|
777
|
+
params.market,
|
|
778
|
+
params.isBid,
|
|
779
|
+
params.price,
|
|
780
|
+
params.size,
|
|
781
|
+
params.postOnly
|
|
782
|
+
],
|
|
783
|
+
typeArguments: []
|
|
784
|
+
});
|
|
785
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
786
|
+
sender: this._apiKey.accountAddress,
|
|
787
|
+
data: payload,
|
|
788
|
+
withFeePayer: true
|
|
789
|
+
});
|
|
790
|
+
const signature = this._aptos.sign({
|
|
791
|
+
signer: this._apiKey,
|
|
792
|
+
transaction: tx
|
|
793
|
+
});
|
|
794
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
795
|
+
}
|
|
796
|
+
async placePerpMarketOrder(params) {
|
|
797
|
+
const payload = (0, import_surf.createEntryPayload)(placePerpMarketOrder_default, {
|
|
798
|
+
function: "place_perp_market_order",
|
|
799
|
+
functionArguments: [
|
|
800
|
+
params.userId,
|
|
801
|
+
params.market,
|
|
802
|
+
params.isBid,
|
|
803
|
+
params.price,
|
|
804
|
+
params.size
|
|
805
|
+
],
|
|
806
|
+
typeArguments: []
|
|
807
|
+
});
|
|
808
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
809
|
+
sender: this._apiKey.accountAddress,
|
|
810
|
+
data: payload,
|
|
811
|
+
withFeePayer: true
|
|
812
|
+
});
|
|
813
|
+
const signature = this._aptos.sign({
|
|
814
|
+
signer: this._apiKey,
|
|
815
|
+
transaction: tx
|
|
816
|
+
});
|
|
817
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
818
|
+
}
|
|
819
|
+
async cancelPerpOrders(params) {
|
|
820
|
+
const payload = (0, import_surf.createEntryPayload)(cancelPerpOrders_default, {
|
|
821
|
+
function: "cancel_perp_orders",
|
|
822
|
+
functionArguments: [params.userId, params.markets, params.orderIds],
|
|
823
|
+
typeArguments: []
|
|
824
|
+
});
|
|
825
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
826
|
+
sender: this._apiKey.accountAddress,
|
|
827
|
+
data: payload,
|
|
828
|
+
withFeePayer: true
|
|
829
|
+
});
|
|
830
|
+
const signature = this._aptos.sign({
|
|
831
|
+
signer: this._apiKey,
|
|
832
|
+
transaction: tx
|
|
833
|
+
});
|
|
834
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
835
|
+
}
|
|
836
|
+
async cancelAllPerpOrders(params) {
|
|
837
|
+
const payload = (0, import_surf.createEntryPayload)(cancelAllPerpOrders_default, {
|
|
838
|
+
function: "cancel_all_perp_orders",
|
|
839
|
+
functionArguments: [params.userId],
|
|
840
|
+
typeArguments: []
|
|
841
|
+
});
|
|
842
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
843
|
+
sender: this._apiKey.accountAddress,
|
|
844
|
+
data: payload,
|
|
845
|
+
withFeePayer: true
|
|
846
|
+
});
|
|
847
|
+
const signature = this._aptos.sign({
|
|
848
|
+
signer: this._apiKey,
|
|
849
|
+
transaction: tx
|
|
850
|
+
});
|
|
851
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
852
|
+
}
|
|
853
|
+
async setAutolend(params) {
|
|
854
|
+
const payload = (0, import_surf.createEntryPayload)(setAutolend_default, {
|
|
855
|
+
function: "set_autolend",
|
|
856
|
+
functionArguments: [params.userId, params.enabled],
|
|
857
|
+
typeArguments: []
|
|
858
|
+
});
|
|
859
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
860
|
+
sender: this._apiKey.accountAddress,
|
|
861
|
+
data: payload,
|
|
862
|
+
withFeePayer: true
|
|
863
|
+
});
|
|
864
|
+
const signature = this._aptos.sign({
|
|
865
|
+
signer: this._apiKey,
|
|
866
|
+
transaction: tx
|
|
867
|
+
});
|
|
868
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
869
|
+
}
|
|
870
|
+
async depositToVault(params) {
|
|
871
|
+
const payload = (0, import_surf.createEntryPayload)(depositToVault_default, {
|
|
872
|
+
function: "deposit_to_vault",
|
|
873
|
+
functionArguments: [params.userId, params.vaultId, toSystemValue(params.amount)],
|
|
874
|
+
typeArguments: []
|
|
875
|
+
});
|
|
876
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
877
|
+
sender: this._apiKey.accountAddress,
|
|
878
|
+
data: payload,
|
|
879
|
+
withFeePayer: true
|
|
880
|
+
});
|
|
881
|
+
const signature = this._aptos.sign({
|
|
882
|
+
signer: this._apiKey,
|
|
883
|
+
transaction: tx
|
|
884
|
+
});
|
|
885
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
886
|
+
}
|
|
887
|
+
async withdrawFromVault(params) {
|
|
888
|
+
const payload = (0, import_surf.createEntryPayload)(withdrawFromVault_default, {
|
|
889
|
+
function: "withdraw_from_vault",
|
|
890
|
+
functionArguments: [
|
|
891
|
+
params.userId,
|
|
892
|
+
params.vaultId,
|
|
893
|
+
toSystemValue(params.amount),
|
|
894
|
+
params.max
|
|
895
|
+
],
|
|
896
|
+
typeArguments: []
|
|
897
|
+
});
|
|
898
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
899
|
+
sender: this._apiKey.accountAddress,
|
|
900
|
+
data: payload,
|
|
901
|
+
withFeePayer: true
|
|
902
|
+
});
|
|
903
|
+
const signature = this._aptos.sign({
|
|
904
|
+
signer: this._apiKey,
|
|
905
|
+
transaction: tx
|
|
906
|
+
});
|
|
907
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
908
|
+
}
|
|
909
|
+
async redeemToken(params) {
|
|
910
|
+
const payload = (0, import_surf.createEntryPayload)(redeemToken_default, {
|
|
911
|
+
function: "redeem_token",
|
|
912
|
+
functionArguments: [
|
|
913
|
+
params.userId,
|
|
914
|
+
params.token,
|
|
915
|
+
toSystemValue(params.amount),
|
|
916
|
+
params.max
|
|
917
|
+
],
|
|
918
|
+
typeArguments: []
|
|
919
|
+
});
|
|
920
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
921
|
+
sender: this._apiKey.accountAddress,
|
|
922
|
+
data: payload,
|
|
923
|
+
withFeePayer: true
|
|
924
|
+
});
|
|
925
|
+
const signature = this._aptos.sign({
|
|
926
|
+
signer: this._apiKey,
|
|
927
|
+
transaction: tx
|
|
928
|
+
});
|
|
929
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
930
|
+
}
|
|
931
|
+
async lendToken(params) {
|
|
932
|
+
const payload = (0, import_surf.createEntryPayload)(lendToken_default, {
|
|
933
|
+
function: "lend_token",
|
|
934
|
+
functionArguments: [
|
|
935
|
+
params.userId,
|
|
936
|
+
params.token,
|
|
937
|
+
toSystemValue(params.amount),
|
|
938
|
+
params.max
|
|
939
|
+
],
|
|
940
|
+
typeArguments: []
|
|
941
|
+
});
|
|
942
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
943
|
+
sender: this._apiKey.accountAddress,
|
|
944
|
+
data: payload,
|
|
945
|
+
withFeePayer: true
|
|
946
|
+
});
|
|
947
|
+
const signature = this._aptos.sign({
|
|
948
|
+
signer: this._apiKey,
|
|
949
|
+
transaction: tx
|
|
950
|
+
});
|
|
951
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
var client_default = Client;
|
|
955
|
+
|
|
956
|
+
// src/testFaucet.ts
|
|
957
|
+
var import_surf2 = require("@thalalabs/surf");
|
|
958
|
+
|
|
959
|
+
// generated_types/faucetEntrypoints.ts
|
|
960
|
+
var ABI14 = {
|
|
961
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
962
|
+
"name": "faucet_entrypoints",
|
|
963
|
+
"friends": [],
|
|
964
|
+
"exposed_functions": [
|
|
965
|
+
{
|
|
966
|
+
"name": "initialize_faucet",
|
|
967
|
+
"visibility": "public",
|
|
968
|
+
"is_entry": true,
|
|
969
|
+
"is_view": false,
|
|
970
|
+
"generic_type_params": [],
|
|
971
|
+
"params": [
|
|
972
|
+
"&signer"
|
|
973
|
+
],
|
|
974
|
+
"return": []
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
"name": "mint_test_token",
|
|
978
|
+
"visibility": "public",
|
|
979
|
+
"is_entry": true,
|
|
980
|
+
"is_view": false,
|
|
981
|
+
"generic_type_params": [],
|
|
982
|
+
"params": [
|
|
983
|
+
"address",
|
|
984
|
+
"vector<u8>",
|
|
985
|
+
"u64"
|
|
986
|
+
],
|
|
987
|
+
"return": []
|
|
988
|
+
}
|
|
989
|
+
],
|
|
990
|
+
"structs": []
|
|
991
|
+
};
|
|
992
|
+
var faucetEntrypoints_default = ABI14;
|
|
993
|
+
|
|
994
|
+
// generated_types/testFaucet.ts
|
|
995
|
+
var ABI15 = {
|
|
996
|
+
"address": "0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0",
|
|
997
|
+
"name": "test_faucet",
|
|
998
|
+
"friends": [],
|
|
999
|
+
"exposed_functions": [
|
|
1000
|
+
{
|
|
1001
|
+
"name": "create_fungible_asset",
|
|
1002
|
+
"visibility": "public",
|
|
1003
|
+
"is_entry": false,
|
|
1004
|
+
"is_view": false,
|
|
1005
|
+
"generic_type_params": [],
|
|
1006
|
+
"params": [
|
|
1007
|
+
"&signer",
|
|
1008
|
+
"vector<u8>",
|
|
1009
|
+
"vector<u8>",
|
|
1010
|
+
"u8",
|
|
1011
|
+
"u128"
|
|
1012
|
+
],
|
|
1013
|
+
"return": [
|
|
1014
|
+
"0x1::fungible_asset::MintRef",
|
|
1015
|
+
"0x1::fungible_asset::TransferRef",
|
|
1016
|
+
"0x1::fungible_asset::BurnRef",
|
|
1017
|
+
"0x1::fungible_asset::MutateMetadataRef",
|
|
1018
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1019
|
+
]
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
"name": "create_test_token",
|
|
1023
|
+
"visibility": "public",
|
|
1024
|
+
"is_entry": false,
|
|
1025
|
+
"is_view": false,
|
|
1026
|
+
"generic_type_params": [],
|
|
1027
|
+
"params": [
|
|
1028
|
+
"&signer",
|
|
1029
|
+
"vector<u8>"
|
|
1030
|
+
],
|
|
1031
|
+
"return": [
|
|
1032
|
+
"0x1::object::ConstructorRef",
|
|
1033
|
+
"0x1::object::Object<0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0::test_faucet::Token>"
|
|
1034
|
+
]
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
"name": "get_token_data",
|
|
1038
|
+
"visibility": "public",
|
|
1039
|
+
"is_entry": false,
|
|
1040
|
+
"is_view": true,
|
|
1041
|
+
"generic_type_params": [],
|
|
1042
|
+
"params": [
|
|
1043
|
+
"vector<u8>"
|
|
1044
|
+
],
|
|
1045
|
+
"return": [
|
|
1046
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1047
|
+
]
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
"name": "init_test_apt",
|
|
1051
|
+
"visibility": "public",
|
|
1052
|
+
"is_entry": false,
|
|
1053
|
+
"is_view": false,
|
|
1054
|
+
"generic_type_params": [],
|
|
1055
|
+
"params": [
|
|
1056
|
+
"&signer"
|
|
1057
|
+
],
|
|
1058
|
+
"return": [
|
|
1059
|
+
"0x1::fungible_asset::MintRef",
|
|
1060
|
+
"0x1::fungible_asset::TransferRef",
|
|
1061
|
+
"0x1::fungible_asset::BurnRef",
|
|
1062
|
+
"0x1::fungible_asset::MutateMetadataRef",
|
|
1063
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1064
|
+
]
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
"name": "init_test_btc",
|
|
1068
|
+
"visibility": "public",
|
|
1069
|
+
"is_entry": false,
|
|
1070
|
+
"is_view": false,
|
|
1071
|
+
"generic_type_params": [],
|
|
1072
|
+
"params": [
|
|
1073
|
+
"&signer"
|
|
1074
|
+
],
|
|
1075
|
+
"return": [
|
|
1076
|
+
"0x1::fungible_asset::MintRef",
|
|
1077
|
+
"0x1::fungible_asset::TransferRef",
|
|
1078
|
+
"0x1::fungible_asset::BurnRef",
|
|
1079
|
+
"0x1::fungible_asset::MutateMetadataRef",
|
|
1080
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1081
|
+
]
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
"name": "init_test_metadata",
|
|
1085
|
+
"visibility": "public",
|
|
1086
|
+
"is_entry": false,
|
|
1087
|
+
"is_view": false,
|
|
1088
|
+
"generic_type_params": [],
|
|
1089
|
+
"params": [
|
|
1090
|
+
"&0x1::object::ConstructorRef",
|
|
1091
|
+
"u128",
|
|
1092
|
+
"vector<u8>",
|
|
1093
|
+
"vector<u8>",
|
|
1094
|
+
"u8"
|
|
1095
|
+
],
|
|
1096
|
+
"return": [
|
|
1097
|
+
"0x1::fungible_asset::MintRef",
|
|
1098
|
+
"0x1::fungible_asset::TransferRef",
|
|
1099
|
+
"0x1::fungible_asset::BurnRef",
|
|
1100
|
+
"0x1::fungible_asset::MutateMetadataRef"
|
|
1101
|
+
]
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
"name": "init_test_sol",
|
|
1105
|
+
"visibility": "public",
|
|
1106
|
+
"is_entry": false,
|
|
1107
|
+
"is_view": false,
|
|
1108
|
+
"generic_type_params": [],
|
|
1109
|
+
"params": [
|
|
1110
|
+
"&signer"
|
|
1111
|
+
],
|
|
1112
|
+
"return": [
|
|
1113
|
+
"0x1::fungible_asset::MintRef",
|
|
1114
|
+
"0x1::fungible_asset::TransferRef",
|
|
1115
|
+
"0x1::fungible_asset::BurnRef",
|
|
1116
|
+
"0x1::fungible_asset::MutateMetadataRef",
|
|
1117
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1118
|
+
]
|
|
1119
|
+
},
|
|
1120
|
+
{
|
|
1121
|
+
"name": "init_test_usdc",
|
|
1122
|
+
"visibility": "public",
|
|
1123
|
+
"is_entry": false,
|
|
1124
|
+
"is_view": false,
|
|
1125
|
+
"generic_type_params": [],
|
|
1126
|
+
"params": [
|
|
1127
|
+
"&signer"
|
|
1128
|
+
],
|
|
1129
|
+
"return": [
|
|
1130
|
+
"0x1::fungible_asset::MintRef",
|
|
1131
|
+
"0x1::fungible_asset::TransferRef",
|
|
1132
|
+
"0x1::fungible_asset::BurnRef",
|
|
1133
|
+
"0x1::fungible_asset::MutateMetadataRef",
|
|
1134
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1135
|
+
]
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
"name": "initialize_faucet",
|
|
1139
|
+
"visibility": "public",
|
|
1140
|
+
"is_entry": false,
|
|
1141
|
+
"is_view": false,
|
|
1142
|
+
"generic_type_params": [],
|
|
1143
|
+
"params": [
|
|
1144
|
+
"&signer"
|
|
1145
|
+
],
|
|
1146
|
+
"return": []
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
"name": "mint_token",
|
|
1150
|
+
"visibility": "public",
|
|
1151
|
+
"is_entry": false,
|
|
1152
|
+
"is_view": false,
|
|
1153
|
+
"generic_type_params": [],
|
|
1154
|
+
"params": [
|
|
1155
|
+
"address",
|
|
1156
|
+
"vector<u8>",
|
|
1157
|
+
"u64"
|
|
1158
|
+
],
|
|
1159
|
+
"return": []
|
|
1160
|
+
},
|
|
1161
|
+
{
|
|
1162
|
+
"name": "new_faucet_token",
|
|
1163
|
+
"visibility": "public",
|
|
1164
|
+
"is_entry": false,
|
|
1165
|
+
"is_view": false,
|
|
1166
|
+
"generic_type_params": [],
|
|
1167
|
+
"params": [
|
|
1168
|
+
"0x1::fungible_asset::MintRef",
|
|
1169
|
+
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1170
|
+
],
|
|
1171
|
+
"return": [
|
|
1172
|
+
"0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0::test_faucet::FaucetToken"
|
|
1173
|
+
]
|
|
1174
|
+
}
|
|
1175
|
+
],
|
|
1176
|
+
"structs": [
|
|
1177
|
+
{
|
|
1178
|
+
"name": "Token",
|
|
1179
|
+
"is_native": false,
|
|
1180
|
+
"is_event": false,
|
|
1181
|
+
"abilities": [
|
|
1182
|
+
"key"
|
|
1183
|
+
],
|
|
1184
|
+
"generic_type_params": [],
|
|
1185
|
+
"fields": [
|
|
1186
|
+
{
|
|
1187
|
+
"name": "dummy_field",
|
|
1188
|
+
"type": "bool"
|
|
1189
|
+
}
|
|
1190
|
+
]
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
"name": "Faucet",
|
|
1194
|
+
"is_native": false,
|
|
1195
|
+
"is_event": false,
|
|
1196
|
+
"abilities": [
|
|
1197
|
+
"store",
|
|
1198
|
+
"key"
|
|
1199
|
+
],
|
|
1200
|
+
"generic_type_params": [],
|
|
1201
|
+
"fields": [
|
|
1202
|
+
{
|
|
1203
|
+
"name": "tokens",
|
|
1204
|
+
"type": "0x1::smart_table::SmartTable<vector<u8>, 0xa27c83bad46c33204010502c05c2f06e77173f487f580e08ae8e54e2419307a0::test_faucet::FaucetToken>"
|
|
1205
|
+
}
|
|
1206
|
+
]
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
"name": "FaucetToken",
|
|
1210
|
+
"is_native": false,
|
|
1211
|
+
"is_event": false,
|
|
1212
|
+
"abilities": [
|
|
1213
|
+
"store"
|
|
1214
|
+
],
|
|
1215
|
+
"generic_type_params": [],
|
|
1216
|
+
"fields": [
|
|
1217
|
+
{
|
|
1218
|
+
"name": "mint",
|
|
1219
|
+
"type": "0x1::fungible_asset::MintRef"
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
"name": "token",
|
|
1223
|
+
"type": "0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
1224
|
+
}
|
|
1225
|
+
]
|
|
1226
|
+
}
|
|
1227
|
+
]
|
|
1228
|
+
};
|
|
1229
|
+
var testFaucet_default = ABI15;
|
|
1230
|
+
|
|
1231
|
+
// src/testFaucet.ts
|
|
1232
|
+
var TestFaucet = class _TestFaucet extends client_default {
|
|
1233
|
+
constructor(connection, ws, url, apiKey) {
|
|
1234
|
+
super(connection, ws, url, apiKey);
|
|
1235
|
+
}
|
|
1236
|
+
static async create(connection, apiKey, url = "http://127.0.0.1:4567") {
|
|
1237
|
+
const ws = await client_default.initWebSocket(url);
|
|
1238
|
+
return new _TestFaucet(connection, ws, url, apiKey);
|
|
1239
|
+
}
|
|
1240
|
+
initFaucetPayload() {
|
|
1241
|
+
return (0, import_surf2.createEntryPayload)(faucetEntrypoints_default, {
|
|
1242
|
+
function: "initialize_faucet",
|
|
1243
|
+
functionArguments: [],
|
|
1244
|
+
typeArguments: []
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
async initFaucet() {
|
|
1248
|
+
const payload = this.initFaucetPayload();
|
|
1249
|
+
console.log(this._apiKey.accountAddress.toString());
|
|
1250
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
1251
|
+
sender: this._apiKey.accountAddress,
|
|
1252
|
+
data: payload,
|
|
1253
|
+
withFeePayer: true
|
|
1254
|
+
});
|
|
1255
|
+
const signature = this._aptos.sign({
|
|
1256
|
+
signer: this._apiKey,
|
|
1257
|
+
transaction: tx
|
|
1258
|
+
});
|
|
1259
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
1260
|
+
}
|
|
1261
|
+
mintTokenPayload(receiver, token, amount) {
|
|
1262
|
+
return (0, import_surf2.createEntryPayload)(faucetEntrypoints_default, {
|
|
1263
|
+
function: "mint_test_token",
|
|
1264
|
+
functionArguments: [receiver, token, amount],
|
|
1265
|
+
typeArguments: []
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
async mintToken(receiver, token, amount) {
|
|
1269
|
+
const payload = this.mintTokenPayload(receiver, token, amount);
|
|
1270
|
+
const tx = await this._aptos.transaction.build.simple({
|
|
1271
|
+
sender: this._apiKey.accountAddress,
|
|
1272
|
+
data: payload,
|
|
1273
|
+
withFeePayer: true
|
|
1274
|
+
});
|
|
1275
|
+
const signature = this._aptos.sign({
|
|
1276
|
+
signer: this._apiKey,
|
|
1277
|
+
transaction: tx
|
|
1278
|
+
});
|
|
1279
|
+
return await this.submitSponsoredTransaction(tx, signature);
|
|
1280
|
+
}
|
|
1281
|
+
async getUSDCAddress() {
|
|
1282
|
+
return (await this._surf.useABI(testFaucet_default).view.get_token_data({
|
|
1283
|
+
functionArguments: ["USDC"],
|
|
1284
|
+
typeArguments: []
|
|
1285
|
+
}))[0].inner;
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1289
|
+
0 && (module.exports = {
|
|
1290
|
+
AdminEndpoints,
|
|
1291
|
+
BaseEndpoints,
|
|
1292
|
+
Client,
|
|
1293
|
+
EndpointsV1,
|
|
1294
|
+
ExchangeProxies,
|
|
1295
|
+
GLOBAL_DENOMINATOR,
|
|
1296
|
+
Network,
|
|
1297
|
+
OrderSide,
|
|
1298
|
+
OrderStatus,
|
|
1299
|
+
OrderType,
|
|
1300
|
+
PerpetualMarketStatus,
|
|
1301
|
+
Status,
|
|
1302
|
+
TestFaucet,
|
|
1303
|
+
TradeRole,
|
|
1304
|
+
UserStatus,
|
|
1305
|
+
getRandomId
|
|
1306
|
+
});
|