@nightlylabs/dex-sdk 0.0.74 → 0.0.76
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 +275 -408
- package/dist/index.d.cts +142 -129
- package/dist/index.d.ts +142 -129
- package/dist/index.js +275 -408
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
16
16
|
|
|
17
17
|
// generated_types/addApiKey.ts
|
|
18
18
|
var ABI = {
|
|
19
|
-
"address": "
|
|
19
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
20
20
|
"name": "add_api_key",
|
|
21
21
|
"friends": [],
|
|
22
22
|
"exposed_functions": [
|
|
@@ -41,7 +41,7 @@ var addApiKey_default = ABI;
|
|
|
41
41
|
|
|
42
42
|
// generated_types/cancelAllPerpOrders.ts
|
|
43
43
|
var ABI2 = {
|
|
44
|
-
"address": "
|
|
44
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
45
45
|
"name": "cancel_all_perp_orders",
|
|
46
46
|
"friends": [],
|
|
47
47
|
"exposed_functions": [
|
|
@@ -64,7 +64,7 @@ var cancelAllPerpOrders_default = ABI2;
|
|
|
64
64
|
|
|
65
65
|
// generated_types/cancelPerpOrders.ts
|
|
66
66
|
var ABI3 = {
|
|
67
|
-
"address": "
|
|
67
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
68
68
|
"name": "cancel_perp_orders",
|
|
69
69
|
"friends": [],
|
|
70
70
|
"exposed_functions": [
|
|
@@ -89,7 +89,7 @@ var cancelPerpOrders_default = ABI3;
|
|
|
89
89
|
|
|
90
90
|
// generated_types/createUser.ts
|
|
91
91
|
var ABI4 = {
|
|
92
|
-
"address": "
|
|
92
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
93
93
|
"name": "create_user",
|
|
94
94
|
"friends": [],
|
|
95
95
|
"exposed_functions": [
|
|
@@ -114,7 +114,7 @@ var createUser_default = ABI4;
|
|
|
114
114
|
|
|
115
115
|
// generated_types/depositToVault.ts
|
|
116
116
|
var ABI5 = {
|
|
117
|
-
"address": "
|
|
117
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
118
118
|
"name": "deposit_to_vault",
|
|
119
119
|
"friends": [],
|
|
120
120
|
"exposed_functions": [
|
|
@@ -139,7 +139,7 @@ var depositToVault_default = ABI5;
|
|
|
139
139
|
|
|
140
140
|
// generated_types/depositToken.ts
|
|
141
141
|
var ABI6 = {
|
|
142
|
-
"address": "
|
|
142
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
143
143
|
"name": "deposit_token",
|
|
144
144
|
"friends": [],
|
|
145
145
|
"exposed_functions": [
|
|
@@ -164,7 +164,7 @@ var depositToken_default = ABI6;
|
|
|
164
164
|
|
|
165
165
|
// generated_types/lendToken.ts
|
|
166
166
|
var ABI7 = {
|
|
167
|
-
"address": "
|
|
167
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
168
168
|
"name": "lend_token",
|
|
169
169
|
"friends": [],
|
|
170
170
|
"exposed_functions": [
|
|
@@ -190,7 +190,7 @@ var lendToken_default = ABI7;
|
|
|
190
190
|
|
|
191
191
|
// generated_types/placePerpLimitOrder.ts
|
|
192
192
|
var ABI8 = {
|
|
193
|
-
"address": "
|
|
193
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
194
194
|
"name": "place_perp_limit_order",
|
|
195
195
|
"friends": [],
|
|
196
196
|
"exposed_functions": [
|
|
@@ -219,7 +219,7 @@ var placePerpLimitOrder_default = ABI8;
|
|
|
219
219
|
|
|
220
220
|
// generated_types/changePerpOrderPrice.ts
|
|
221
221
|
var ABI9 = {
|
|
222
|
-
"address": "
|
|
222
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
223
223
|
"name": "change_perp_order_price",
|
|
224
224
|
"friends": [],
|
|
225
225
|
"exposed_functions": [
|
|
@@ -246,7 +246,7 @@ var changePerpOrderPrice_default = ABI9;
|
|
|
246
246
|
|
|
247
247
|
// generated_types/placePerpMarketOrder.ts
|
|
248
248
|
var ABI10 = {
|
|
249
|
-
"address": "
|
|
249
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
250
250
|
"name": "place_perp_market_order",
|
|
251
251
|
"friends": [],
|
|
252
252
|
"exposed_functions": [
|
|
@@ -274,7 +274,7 @@ var placePerpMarketOrder_default = ABI10;
|
|
|
274
274
|
|
|
275
275
|
// generated_types/redeemToken.ts
|
|
276
276
|
var ABI11 = {
|
|
277
|
-
"address": "
|
|
277
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
278
278
|
"name": "redeem_token",
|
|
279
279
|
"friends": [],
|
|
280
280
|
"exposed_functions": [
|
|
@@ -300,7 +300,7 @@ var redeemToken_default = ABI11;
|
|
|
300
300
|
|
|
301
301
|
// generated_types/removeApiKey.ts
|
|
302
302
|
var ABI12 = {
|
|
303
|
-
"address": "
|
|
303
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
304
304
|
"name": "remove_api_key",
|
|
305
305
|
"friends": [],
|
|
306
306
|
"exposed_functions": [
|
|
@@ -324,7 +324,7 @@ var removeApiKey_default = ABI12;
|
|
|
324
324
|
|
|
325
325
|
// generated_types/setAliasName.ts
|
|
326
326
|
var ABI13 = {
|
|
327
|
-
"address": "
|
|
327
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
328
328
|
"name": "set_alias_name",
|
|
329
329
|
"friends": [],
|
|
330
330
|
"exposed_functions": [
|
|
@@ -348,7 +348,7 @@ var setAliasName_default = ABI13;
|
|
|
348
348
|
|
|
349
349
|
// generated_types/setAutolend.ts
|
|
350
350
|
var ABI14 = {
|
|
351
|
-
"address": "
|
|
351
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
352
352
|
"name": "set_autolend",
|
|
353
353
|
"friends": [],
|
|
354
354
|
"exposed_functions": [
|
|
@@ -372,7 +372,7 @@ var setAutolend_default = ABI14;
|
|
|
372
372
|
|
|
373
373
|
// generated_types/claimReferralFees.ts
|
|
374
374
|
var ABI15 = {
|
|
375
|
-
"address": "
|
|
375
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
376
376
|
"name": "claim_referral_fees",
|
|
377
377
|
"friends": [],
|
|
378
378
|
"exposed_functions": [
|
|
@@ -396,7 +396,7 @@ var claimReferralFees_default = ABI15;
|
|
|
396
396
|
|
|
397
397
|
// generated_types/transferToUser.ts
|
|
398
398
|
var ABI16 = {
|
|
399
|
-
"address": "
|
|
399
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
400
400
|
"name": "transfer_to_user",
|
|
401
401
|
"friends": [],
|
|
402
402
|
"exposed_functions": [
|
|
@@ -421,6 +421,35 @@ var ABI16 = {
|
|
|
421
421
|
};
|
|
422
422
|
var transferToUser_default = ABI16;
|
|
423
423
|
|
|
424
|
+
// generated_types/placeMultiplePerpOrders.ts
|
|
425
|
+
var ABI17 = {
|
|
426
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
427
|
+
"name": "place_multiple_perp_orders",
|
|
428
|
+
"friends": [],
|
|
429
|
+
"exposed_functions": [
|
|
430
|
+
{
|
|
431
|
+
"name": "place_multiple_perp_orders",
|
|
432
|
+
"visibility": "public",
|
|
433
|
+
"is_entry": true,
|
|
434
|
+
"is_view": false,
|
|
435
|
+
"generic_type_params": [],
|
|
436
|
+
"params": [
|
|
437
|
+
"&signer",
|
|
438
|
+
"u64",
|
|
439
|
+
"vector<vector<u8>>",
|
|
440
|
+
"vector<bool>",
|
|
441
|
+
"vector<u64>",
|
|
442
|
+
"vector<u64>",
|
|
443
|
+
"vector<bool>",
|
|
444
|
+
"vector<bool>"
|
|
445
|
+
],
|
|
446
|
+
"return": []
|
|
447
|
+
}
|
|
448
|
+
],
|
|
449
|
+
"structs": []
|
|
450
|
+
};
|
|
451
|
+
var placeMultiplePerpOrders_default = ABI17;
|
|
452
|
+
|
|
424
453
|
// generated_types/typeshareTypes.ts
|
|
425
454
|
var PerpetualMarketStatus = /* @__PURE__ */ ((PerpetualMarketStatus2) => {
|
|
426
455
|
PerpetualMarketStatus2["Halted"] = "halted";
|
|
@@ -429,15 +458,15 @@ var PerpetualMarketStatus = /* @__PURE__ */ ((PerpetualMarketStatus2) => {
|
|
|
429
458
|
PerpetualMarketStatus2["Live"] = "live";
|
|
430
459
|
return PerpetualMarketStatus2;
|
|
431
460
|
})(PerpetualMarketStatus || {});
|
|
432
|
-
var ChartInterval = /* @__PURE__ */ ((
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return
|
|
461
|
+
var ChartInterval = /* @__PURE__ */ ((ChartInterval2) => {
|
|
462
|
+
ChartInterval2["OneMinute"] = "OneMinute";
|
|
463
|
+
ChartInterval2["FiveMinutes"] = "FiveMinutes";
|
|
464
|
+
ChartInterval2["FifteenMinutes"] = "FifteenMinutes";
|
|
465
|
+
ChartInterval2["ThirtyMinutes"] = "ThirtyMinutes";
|
|
466
|
+
ChartInterval2["OneHour"] = "OneHour";
|
|
467
|
+
ChartInterval2["FourHours"] = "FourHours";
|
|
468
|
+
ChartInterval2["OneDay"] = "OneDay";
|
|
469
|
+
return ChartInterval2;
|
|
441
470
|
})(ChartInterval || {});
|
|
442
471
|
var OrderSide = /* @__PURE__ */ ((OrderSide2) => {
|
|
443
472
|
OrderSide2["Bid"] = "Bid";
|
|
@@ -505,8 +534,8 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
|
505
534
|
})(UserStatus || {});
|
|
506
535
|
|
|
507
536
|
// generated_types/withdrawFromVault.ts
|
|
508
|
-
var
|
|
509
|
-
"address": "
|
|
537
|
+
var ABI18 = {
|
|
538
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
510
539
|
"name": "withdraw_from_vault",
|
|
511
540
|
"friends": [],
|
|
512
541
|
"exposed_functions": [
|
|
@@ -528,7 +557,7 @@ var ABI17 = {
|
|
|
528
557
|
],
|
|
529
558
|
"structs": []
|
|
530
559
|
};
|
|
531
|
-
var withdrawFromVault_default =
|
|
560
|
+
var withdrawFromVault_default = ABI18;
|
|
532
561
|
|
|
533
562
|
// src/utils.ts
|
|
534
563
|
import { Account } from "@aptos-labs/ts-sdk";
|
|
@@ -637,6 +666,8 @@ var getTopicFromMessage = (data) => {
|
|
|
637
666
|
return data.content.senderId;
|
|
638
667
|
case "UserTransferReceived":
|
|
639
668
|
return data.content.receiverId;
|
|
669
|
+
case "ReferralUpdate":
|
|
670
|
+
return data.content.userId;
|
|
640
671
|
}
|
|
641
672
|
};
|
|
642
673
|
|
|
@@ -821,11 +852,29 @@ var AccountSequenceNumber = class {
|
|
|
821
852
|
// src/client.ts
|
|
822
853
|
var getRandomId = () => uuidv4();
|
|
823
854
|
var Client = class _Client {
|
|
824
|
-
constructor(connection,
|
|
855
|
+
constructor(connection, enableWs, url, apiKey, chainId) {
|
|
825
856
|
this._apiKeySequenceNumber = 0;
|
|
826
857
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
827
858
|
this.timeout = 5e3;
|
|
828
|
-
|
|
859
|
+
/////////////////////////////////// Sponsored transactions
|
|
860
|
+
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
861
|
+
const payload = {
|
|
862
|
+
sender: tx.rawTransaction.sender.toString(),
|
|
863
|
+
sequenceNumber: tx.rawTransaction.sequence_number.toString(),
|
|
864
|
+
payload: Array.from(tx.rawTransaction.payload.bcsToBytes()),
|
|
865
|
+
maxGasAmount: tx.rawTransaction.max_gas_amount.toString(),
|
|
866
|
+
gasUnitPrice: tx.rawTransaction.gas_unit_price.toString(),
|
|
867
|
+
expirationTimestampSecs: tx.rawTransaction.expiration_timestamp_secs.toString(),
|
|
868
|
+
chainId: parseInt(tx.rawTransaction.chain_id.toString()).toString(),
|
|
869
|
+
authenticator: Array.from(signature.bcsToBytes())
|
|
870
|
+
};
|
|
871
|
+
const response = await this.sendPostJson(
|
|
872
|
+
payload,
|
|
873
|
+
"/v1/submit_sponsored_transaction" /* SubmitSponsoredTransactionRequest */
|
|
874
|
+
);
|
|
875
|
+
return response;
|
|
876
|
+
};
|
|
877
|
+
//////////////////////////////////////// GETTERS
|
|
829
878
|
this.sendGetJson = async (endpoint, message) => {
|
|
830
879
|
let URL = this._serverUrl + endpoint;
|
|
831
880
|
if (message) {
|
|
@@ -881,23 +930,6 @@ var Client = class _Client {
|
|
|
881
930
|
throw new Error(error);
|
|
882
931
|
}
|
|
883
932
|
};
|
|
884
|
-
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
885
|
-
const payload = {
|
|
886
|
-
sender: tx.rawTransaction.sender.toString(),
|
|
887
|
-
sequenceNumber: tx.rawTransaction.sequence_number.toString(),
|
|
888
|
-
payload: Array.from(tx.rawTransaction.payload.bcsToBytes()),
|
|
889
|
-
maxGasAmount: tx.rawTransaction.max_gas_amount.toString(),
|
|
890
|
-
gasUnitPrice: tx.rawTransaction.gas_unit_price.toString(),
|
|
891
|
-
expirationTimestampSecs: tx.rawTransaction.expiration_timestamp_secs.toString(),
|
|
892
|
-
chainId: parseInt(tx.rawTransaction.chain_id.toString()).toString(),
|
|
893
|
-
authenticator: Array.from(signature.bcsToBytes())
|
|
894
|
-
};
|
|
895
|
-
const response = await this.sendPostJson(
|
|
896
|
-
payload,
|
|
897
|
-
"/v1/submit_sponsored_transaction" /* SubmitSponsoredTransactionRequest */
|
|
898
|
-
);
|
|
899
|
-
return response;
|
|
900
|
-
};
|
|
901
933
|
this.getConfig = async () => {
|
|
902
934
|
const response = await this.sendGetJson("/v1/get_config" /* GetConfig */);
|
|
903
935
|
return response;
|
|
@@ -1036,34 +1068,64 @@ var Client = class _Client {
|
|
|
1036
1068
|
this._surf = createSurfClient(this._aptos);
|
|
1037
1069
|
this._apiKey = apiKey || generateApiKey();
|
|
1038
1070
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
1039
|
-
this._serverUrl = url;
|
|
1071
|
+
this._serverUrl = url || "https://api.dev.nightly.exchange";
|
|
1040
1072
|
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1041
|
-
this._ws = ws;
|
|
1042
|
-
if (this._ws) {
|
|
1043
|
-
this._ws.onmessage = async (msg) => {
|
|
1044
|
-
let data;
|
|
1045
|
-
if (msg.data.arrayBuffer) {
|
|
1046
|
-
data = new TextDecoder().decode(new Uint8Array(await msg.data.arrayBuffer()));
|
|
1047
|
-
} else {
|
|
1048
|
-
data = msg.data;
|
|
1049
|
-
}
|
|
1050
|
-
const decodedMsg = JSON.parse(data);
|
|
1051
|
-
const topic = getTopicFromMessage(decodedMsg);
|
|
1052
|
-
const callback = this._subscriptions.get(topic);
|
|
1053
|
-
if (callback) {
|
|
1054
|
-
callback(decodedMsg);
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
static async init(connection, apiKey, url = "http://127.0.0.1:4567", enableWs = true, chainId = 178) {
|
|
1060
|
-
let ws = void 0;
|
|
1061
1073
|
if (enableWs) {
|
|
1062
|
-
|
|
1074
|
+
this.connectWebSocket();
|
|
1063
1075
|
}
|
|
1076
|
+
}
|
|
1077
|
+
static async init(connection, enableWs = true, url, apiKey, chainId) {
|
|
1064
1078
|
const id = chainId || await connection.getChainId();
|
|
1065
|
-
|
|
1066
|
-
|
|
1079
|
+
return new _Client(connection, enableWs, url, apiKey, id);
|
|
1080
|
+
}
|
|
1081
|
+
static async create(connection, enableWs = true, url, apiKey) {
|
|
1082
|
+
return _Client.init(connection, enableWs, url, apiKey);
|
|
1083
|
+
}
|
|
1084
|
+
async setApiKey(apiKey) {
|
|
1085
|
+
this._apiKey = apiKey;
|
|
1086
|
+
this._apiKeySequenceNumber = await this.fetchApiKeySequenceNumber();
|
|
1087
|
+
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1088
|
+
await this._sequenceNumberManager.initialize();
|
|
1089
|
+
}
|
|
1090
|
+
getApiKeySequenceNumber() {
|
|
1091
|
+
return this._sequenceNumberManager.nextSequenceNumber();
|
|
1092
|
+
}
|
|
1093
|
+
async fetchApiKeySequenceNumber() {
|
|
1094
|
+
const accInfo = await this._aptos.getAccountInfo({
|
|
1095
|
+
accountAddress: this._apiKey.accountAddress
|
|
1096
|
+
});
|
|
1097
|
+
return Number(await accInfo.sequence_number);
|
|
1098
|
+
}
|
|
1099
|
+
//////////////////////////////////////// Websocket functions
|
|
1100
|
+
async connectWebSocket() {
|
|
1101
|
+
if (this._ws) {
|
|
1102
|
+
console.warn("WebSocket is already connected");
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
this._ws = await _Client.initWebSocket(this._serverUrl, this.timeout);
|
|
1107
|
+
this._setupWebSocketHandlers();
|
|
1108
|
+
return;
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
throw new Error(`Failed to connect WebSocket: ${error}`);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
_setupWebSocketHandlers() {
|
|
1114
|
+
if (!this._ws) return;
|
|
1115
|
+
this._ws.onmessage = async (msg) => {
|
|
1116
|
+
let data;
|
|
1117
|
+
if (msg.data.arrayBuffer) {
|
|
1118
|
+
data = new TextDecoder().decode(new Uint8Array(await msg.data.arrayBuffer()));
|
|
1119
|
+
} else {
|
|
1120
|
+
data = msg.data;
|
|
1121
|
+
}
|
|
1122
|
+
const decodedMsg = JSON.parse(data);
|
|
1123
|
+
const topic = getTopicFromMessage(decodedMsg);
|
|
1124
|
+
const callback = this._subscriptions.get(topic);
|
|
1125
|
+
if (callback) {
|
|
1126
|
+
callback(decodedMsg);
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1067
1129
|
}
|
|
1068
1130
|
static async initWebSocket(url, timeout = 5e3) {
|
|
1069
1131
|
return new Promise((resolve, reject) => {
|
|
@@ -1083,7 +1145,21 @@ var Client = class _Client {
|
|
|
1083
1145
|
};
|
|
1084
1146
|
});
|
|
1085
1147
|
}
|
|
1148
|
+
async disconnectWebSocket() {
|
|
1149
|
+
if (!this._ws) {
|
|
1150
|
+
console.warn("WebSocket is not connected");
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
this._subscriptions.clear();
|
|
1154
|
+
this._ws.close();
|
|
1155
|
+
this._ws = void 0;
|
|
1156
|
+
}
|
|
1157
|
+
// Method to check if WebSocket is connected
|
|
1158
|
+
isWebSocketConnected() {
|
|
1159
|
+
return this._ws !== void 0 && this._ws.readyState === WebSocket.OPEN;
|
|
1160
|
+
}
|
|
1086
1161
|
sendWsMessage(message) {
|
|
1162
|
+
if (!this._ws) throw new Error("WebSocket is not connected");
|
|
1087
1163
|
return new Promise((resolve, reject) => {
|
|
1088
1164
|
const topic = message.content.id;
|
|
1089
1165
|
const timer = setTimeout(() => {
|
|
@@ -1103,57 +1179,6 @@ var Client = class _Client {
|
|
|
1103
1179
|
this._ws?.send(JSON.stringify(message));
|
|
1104
1180
|
});
|
|
1105
1181
|
}
|
|
1106
|
-
static async create(connection, apiKey, url = "https://api.dev.nightly.exchange", enableWs = true) {
|
|
1107
|
-
return _Client.init(connection, apiKey, url, enableWs);
|
|
1108
|
-
}
|
|
1109
|
-
async setApiKey(apiKey) {
|
|
1110
|
-
this._apiKey = apiKey;
|
|
1111
|
-
this._apiKeySequenceNumber = await this.fetchApiKeySequenceNumber();
|
|
1112
|
-
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1113
|
-
await this._sequenceNumberManager.initialize();
|
|
1114
|
-
}
|
|
1115
|
-
getApiKeySequenceNumber() {
|
|
1116
|
-
return this._sequenceNumberManager.nextSequenceNumber();
|
|
1117
|
-
}
|
|
1118
|
-
async fetchApiKeySequenceNumber() {
|
|
1119
|
-
const accInfo = await this._aptos.getAccountInfo({
|
|
1120
|
-
accountAddress: this._apiKey.accountAddress
|
|
1121
|
-
});
|
|
1122
|
-
return Number(await accInfo.sequence_number);
|
|
1123
|
-
}
|
|
1124
|
-
// needs to be signed by user and sent to blockchain
|
|
1125
|
-
async createUser(params) {
|
|
1126
|
-
const apiKey = generateApiKey();
|
|
1127
|
-
const payload = await generateTransactionPayload({
|
|
1128
|
-
aptosConfig: this._aptos.config,
|
|
1129
|
-
abi: parseEntryFunctionAbi({
|
|
1130
|
-
moduleAbi: createUser_default,
|
|
1131
|
-
functionName: createUser_default.name,
|
|
1132
|
-
moduleAddress: createUser_default.address,
|
|
1133
|
-
moduleName: createUser_default.name
|
|
1134
|
-
}),
|
|
1135
|
-
function: `${createUser_default.address}::${createUser_default.name}::create_user`,
|
|
1136
|
-
typeArguments: [],
|
|
1137
|
-
functionArguments: [params.name, params.referralId]
|
|
1138
|
-
});
|
|
1139
|
-
const tx = new MultiAgentTransaction(
|
|
1140
|
-
await generateRawTransaction({
|
|
1141
|
-
sender: params.sender,
|
|
1142
|
-
aptosConfig: this._aptos.config,
|
|
1143
|
-
payload
|
|
1144
|
-
}),
|
|
1145
|
-
[apiKey.accountAddress]
|
|
1146
|
-
);
|
|
1147
|
-
const signature = this._aptos.sign({
|
|
1148
|
-
signer: apiKey,
|
|
1149
|
-
transaction: tx
|
|
1150
|
-
});
|
|
1151
|
-
return {
|
|
1152
|
-
tx,
|
|
1153
|
-
signature,
|
|
1154
|
-
apiKey
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
1182
|
async subscribeIndexPricesUpdates(callback) {
|
|
1158
1183
|
const command = {
|
|
1159
1184
|
type: "SubscribeOracle",
|
|
@@ -1230,7 +1255,39 @@ var Client = class _Client {
|
|
|
1230
1255
|
const topic = getTopicFromCommand(command);
|
|
1231
1256
|
this._subscriptions.delete(topic);
|
|
1232
1257
|
}
|
|
1233
|
-
|
|
1258
|
+
/////////////////////////////////// Functions which needs to be signed by user and sent to blockchain
|
|
1259
|
+
async createUser(params) {
|
|
1260
|
+
const apiKey = generateApiKey();
|
|
1261
|
+
const payload = await generateTransactionPayload({
|
|
1262
|
+
aptosConfig: this._aptos.config,
|
|
1263
|
+
abi: parseEntryFunctionAbi({
|
|
1264
|
+
moduleAbi: createUser_default,
|
|
1265
|
+
functionName: createUser_default.name,
|
|
1266
|
+
moduleAddress: createUser_default.address,
|
|
1267
|
+
moduleName: createUser_default.name
|
|
1268
|
+
}),
|
|
1269
|
+
function: `${createUser_default.address}::${createUser_default.name}::create_user`,
|
|
1270
|
+
typeArguments: [],
|
|
1271
|
+
functionArguments: [params.name, params.referralId]
|
|
1272
|
+
});
|
|
1273
|
+
const tx = new MultiAgentTransaction(
|
|
1274
|
+
await generateRawTransaction({
|
|
1275
|
+
sender: params.sender,
|
|
1276
|
+
aptosConfig: this._aptos.config,
|
|
1277
|
+
payload
|
|
1278
|
+
}),
|
|
1279
|
+
[apiKey.accountAddress]
|
|
1280
|
+
);
|
|
1281
|
+
const signature = this._aptos.sign({
|
|
1282
|
+
signer: apiKey,
|
|
1283
|
+
transaction: tx
|
|
1284
|
+
});
|
|
1285
|
+
return {
|
|
1286
|
+
tx,
|
|
1287
|
+
signature,
|
|
1288
|
+
apiKey
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1234
1291
|
async addApiKey(params) {
|
|
1235
1292
|
return await generateTransactionPayload({
|
|
1236
1293
|
aptosConfig: this._aptos.config,
|
|
@@ -1245,27 +1302,33 @@ var Client = class _Client {
|
|
|
1245
1302
|
functionArguments: [params.userId, params.expiration]
|
|
1246
1303
|
});
|
|
1247
1304
|
}
|
|
1248
|
-
async
|
|
1249
|
-
|
|
1250
|
-
const aptosPayload = await generateTransactionPayload({
|
|
1305
|
+
async depositTokenPayload(params) {
|
|
1306
|
+
return await generateTransactionPayload({
|
|
1251
1307
|
aptosConfig: this._aptos.config,
|
|
1252
1308
|
abi: parseEntryFunctionAbi({
|
|
1253
|
-
moduleAbi:
|
|
1254
|
-
functionName:
|
|
1255
|
-
moduleAddress:
|
|
1256
|
-
moduleName:
|
|
1309
|
+
moduleAbi: depositToken_default,
|
|
1310
|
+
functionName: depositToken_default.name,
|
|
1311
|
+
moduleAddress: depositToken_default.address,
|
|
1312
|
+
moduleName: depositToken_default.name
|
|
1257
1313
|
}),
|
|
1258
|
-
function: `${
|
|
1314
|
+
function: `${depositToken_default.address}::${depositToken_default.name}::deposit_token`,
|
|
1259
1315
|
typeArguments: [],
|
|
1260
|
-
functionArguments: [params.
|
|
1316
|
+
functionArguments: [params.userId, params.amount, params.tokenAddress]
|
|
1261
1317
|
});
|
|
1318
|
+
}
|
|
1319
|
+
// Helper function to submit sponsored transaction
|
|
1320
|
+
async createAndSubmitTransaction(aptosPayload) {
|
|
1321
|
+
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1262
1322
|
const rawTx = new RawTransaction(
|
|
1263
1323
|
AccountAddress.from(this._apiKey.accountAddress),
|
|
1264
1324
|
BigInt(sequenceNumber),
|
|
1265
1325
|
aptosPayload,
|
|
1266
1326
|
BigInt(1e6),
|
|
1327
|
+
// max gas
|
|
1267
1328
|
BigInt(100),
|
|
1329
|
+
// gas unit price
|
|
1268
1330
|
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1331
|
+
// expiration timestamp
|
|
1269
1332
|
new ChainId(this._chainId)
|
|
1270
1333
|
);
|
|
1271
1334
|
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
@@ -1275,8 +1338,22 @@ var Client = class _Client {
|
|
|
1275
1338
|
});
|
|
1276
1339
|
return await this.submitSponsoredTransaction(tx, signature);
|
|
1277
1340
|
}
|
|
1341
|
+
async removeApiKey(params) {
|
|
1342
|
+
const aptosPayload = await generateTransactionPayload({
|
|
1343
|
+
aptosConfig: this._aptos.config,
|
|
1344
|
+
abi: parseEntryFunctionAbi({
|
|
1345
|
+
moduleAbi: removeApiKey_default,
|
|
1346
|
+
functionName: removeApiKey_default.name,
|
|
1347
|
+
moduleAddress: removeApiKey_default.address,
|
|
1348
|
+
moduleName: removeApiKey_default.name
|
|
1349
|
+
}),
|
|
1350
|
+
function: `${removeApiKey_default.address}::${removeApiKey_default.name}::remove_api_key`,
|
|
1351
|
+
typeArguments: [],
|
|
1352
|
+
functionArguments: [params.apiKey, params.userId]
|
|
1353
|
+
});
|
|
1354
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1355
|
+
}
|
|
1278
1356
|
async setAliasName(params) {
|
|
1279
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1280
1357
|
const aptosPayload = await generateTransactionPayload({
|
|
1281
1358
|
aptosConfig: this._aptos.config,
|
|
1282
1359
|
abi: parseEntryFunctionAbi({
|
|
@@ -1289,24 +1366,9 @@ var Client = class _Client {
|
|
|
1289
1366
|
typeArguments: [],
|
|
1290
1367
|
functionArguments: [params.userId, params.alias]
|
|
1291
1368
|
});
|
|
1292
|
-
|
|
1293
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1294
|
-
BigInt(sequenceNumber),
|
|
1295
|
-
aptosPayload,
|
|
1296
|
-
BigInt(1e6),
|
|
1297
|
-
BigInt(100),
|
|
1298
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1299
|
-
new ChainId(this._chainId)
|
|
1300
|
-
);
|
|
1301
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1302
|
-
const signature = this._aptos.sign({
|
|
1303
|
-
signer: this._apiKey,
|
|
1304
|
-
transaction: tx
|
|
1305
|
-
});
|
|
1306
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1369
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1307
1370
|
}
|
|
1308
1371
|
async placePerpLimitOrder(params) {
|
|
1309
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1310
1372
|
const aptosPayload = await generateTransactionPayload({
|
|
1311
1373
|
aptosConfig: this._aptos.config,
|
|
1312
1374
|
abi: parseEntryFunctionAbi({
|
|
@@ -1319,32 +1381,17 @@ var Client = class _Client {
|
|
|
1319
1381
|
typeArguments: [],
|
|
1320
1382
|
functionArguments: [
|
|
1321
1383
|
params.userId,
|
|
1322
|
-
params.market,
|
|
1323
|
-
params.isBid,
|
|
1324
|
-
params.price,
|
|
1325
|
-
params.size,
|
|
1326
|
-
params.postOnly,
|
|
1327
|
-
params.reduceOnly
|
|
1384
|
+
params.orderData.market,
|
|
1385
|
+
params.orderData.isBid,
|
|
1386
|
+
params.orderData.price,
|
|
1387
|
+
params.orderData.size,
|
|
1388
|
+
params.orderData.postOnly || false,
|
|
1389
|
+
params.orderData.reduceOnly || false
|
|
1328
1390
|
]
|
|
1329
1391
|
});
|
|
1330
|
-
|
|
1331
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1332
|
-
BigInt(sequenceNumber),
|
|
1333
|
-
aptosPayload,
|
|
1334
|
-
BigInt(1e6),
|
|
1335
|
-
BigInt(100),
|
|
1336
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1337
|
-
new ChainId(this._chainId)
|
|
1338
|
-
);
|
|
1339
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1340
|
-
const signature = this._aptos.sign({
|
|
1341
|
-
signer: this._apiKey,
|
|
1342
|
-
transaction: tx
|
|
1343
|
-
});
|
|
1344
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1392
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1345
1393
|
}
|
|
1346
1394
|
async placePerpMarketOrder(params) {
|
|
1347
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1348
1395
|
const aptosPayload = await generateTransactionPayload({
|
|
1349
1396
|
aptosConfig: this._aptos.config,
|
|
1350
1397
|
abi: parseEntryFunctionAbi({
|
|
@@ -1357,31 +1404,16 @@ var Client = class _Client {
|
|
|
1357
1404
|
typeArguments: [],
|
|
1358
1405
|
functionArguments: [
|
|
1359
1406
|
params.userId,
|
|
1360
|
-
params.market,
|
|
1361
|
-
params.isBid,
|
|
1362
|
-
params.
|
|
1363
|
-
params.size,
|
|
1364
|
-
params.reduceOnly
|
|
1407
|
+
params.orderData.market,
|
|
1408
|
+
params.orderData.isBid,
|
|
1409
|
+
params.orderData.price,
|
|
1410
|
+
params.orderData.size,
|
|
1411
|
+
params.orderData.reduceOnly || false
|
|
1365
1412
|
]
|
|
1366
1413
|
});
|
|
1367
|
-
|
|
1368
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1369
|
-
BigInt(sequenceNumber),
|
|
1370
|
-
aptosPayload,
|
|
1371
|
-
BigInt(1e6),
|
|
1372
|
-
BigInt(100),
|
|
1373
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1374
|
-
new ChainId(this._chainId)
|
|
1375
|
-
);
|
|
1376
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1377
|
-
const signature = this._aptos.sign({
|
|
1378
|
-
signer: this._apiKey,
|
|
1379
|
-
transaction: tx
|
|
1380
|
-
});
|
|
1381
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1414
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1382
1415
|
}
|
|
1383
1416
|
async changePerpOrderPrice(params) {
|
|
1384
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1385
1417
|
const aptosPayload = await generateTransactionPayload({
|
|
1386
1418
|
aptosConfig: this._aptos.config,
|
|
1387
1419
|
abi: parseEntryFunctionAbi({
|
|
@@ -1400,24 +1432,9 @@ var Client = class _Client {
|
|
|
1400
1432
|
params.postOnly
|
|
1401
1433
|
]
|
|
1402
1434
|
});
|
|
1403
|
-
|
|
1404
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1405
|
-
BigInt(sequenceNumber),
|
|
1406
|
-
aptosPayload,
|
|
1407
|
-
BigInt(1e6),
|
|
1408
|
-
BigInt(100),
|
|
1409
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1410
|
-
new ChainId(this._chainId)
|
|
1411
|
-
);
|
|
1412
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1413
|
-
const signature = this._aptos.sign({
|
|
1414
|
-
signer: this._apiKey,
|
|
1415
|
-
transaction: tx
|
|
1416
|
-
});
|
|
1417
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1435
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1418
1436
|
}
|
|
1419
1437
|
async cancelPerpOrders(params) {
|
|
1420
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1421
1438
|
const aptosPayload = await generateTransactionPayload({
|
|
1422
1439
|
aptosConfig: this._aptos.config,
|
|
1423
1440
|
abi: parseEntryFunctionAbi({
|
|
@@ -1430,27 +1447,9 @@ var Client = class _Client {
|
|
|
1430
1447
|
typeArguments: [],
|
|
1431
1448
|
functionArguments: [params.userId, params.markets, params.orderIds]
|
|
1432
1449
|
});
|
|
1433
|
-
|
|
1434
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1435
|
-
BigInt(sequenceNumber),
|
|
1436
|
-
aptosPayload,
|
|
1437
|
-
BigInt(1e6),
|
|
1438
|
-
// maxGasAmount
|
|
1439
|
-
BigInt(100),
|
|
1440
|
-
// gasUnitPrice
|
|
1441
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1442
|
-
// expirationTimestampSecs
|
|
1443
|
-
new ChainId(this._chainId)
|
|
1444
|
-
);
|
|
1445
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1446
|
-
const signature = this._aptos.sign({
|
|
1447
|
-
signer: this._apiKey,
|
|
1448
|
-
transaction: tx
|
|
1449
|
-
});
|
|
1450
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1450
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1451
1451
|
}
|
|
1452
1452
|
async cancelAllPerpOrders(params) {
|
|
1453
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1454
1453
|
const aptosPayload = await generateTransactionPayload({
|
|
1455
1454
|
aptosConfig: this._aptos.config,
|
|
1456
1455
|
abi: parseEntryFunctionAbi({
|
|
@@ -1463,27 +1462,9 @@ var Client = class _Client {
|
|
|
1463
1462
|
typeArguments: [],
|
|
1464
1463
|
functionArguments: [params.userId]
|
|
1465
1464
|
});
|
|
1466
|
-
|
|
1467
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1468
|
-
BigInt(sequenceNumber),
|
|
1469
|
-
aptosPayload,
|
|
1470
|
-
BigInt(1e6),
|
|
1471
|
-
// maxGasAmount
|
|
1472
|
-
BigInt(100),
|
|
1473
|
-
// gasUnitPrice
|
|
1474
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1475
|
-
// expirationTimestampSecs
|
|
1476
|
-
new ChainId(this._chainId)
|
|
1477
|
-
);
|
|
1478
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1479
|
-
const signature = this._aptos.sign({
|
|
1480
|
-
signer: this._apiKey,
|
|
1481
|
-
transaction: tx
|
|
1482
|
-
});
|
|
1483
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1465
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1484
1466
|
}
|
|
1485
1467
|
async setAutolend(params) {
|
|
1486
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1487
1468
|
const aptosPayload = await generateTransactionPayload({
|
|
1488
1469
|
aptosConfig: this._aptos.config,
|
|
1489
1470
|
abi: parseEntryFunctionAbi({
|
|
@@ -1496,41 +1477,9 @@ var Client = class _Client {
|
|
|
1496
1477
|
typeArguments: [],
|
|
1497
1478
|
functionArguments: [params.userId, params.enabled]
|
|
1498
1479
|
});
|
|
1499
|
-
|
|
1500
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1501
|
-
BigInt(sequenceNumber),
|
|
1502
|
-
aptosPayload,
|
|
1503
|
-
BigInt(1e6),
|
|
1504
|
-
// maxGasAmount
|
|
1505
|
-
BigInt(100),
|
|
1506
|
-
// gasUnitPrice
|
|
1507
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1508
|
-
// expirationTimestampSecs
|
|
1509
|
-
new ChainId(this._chainId)
|
|
1510
|
-
);
|
|
1511
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1512
|
-
const signature = this._aptos.sign({
|
|
1513
|
-
signer: this._apiKey,
|
|
1514
|
-
transaction: tx
|
|
1515
|
-
});
|
|
1516
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1517
|
-
}
|
|
1518
|
-
async depositTokenPayload(params) {
|
|
1519
|
-
return await generateTransactionPayload({
|
|
1520
|
-
aptosConfig: this._aptos.config,
|
|
1521
|
-
abi: parseEntryFunctionAbi({
|
|
1522
|
-
moduleAbi: depositToken_default,
|
|
1523
|
-
functionName: depositToken_default.name,
|
|
1524
|
-
moduleAddress: depositToken_default.address,
|
|
1525
|
-
moduleName: depositToken_default.name
|
|
1526
|
-
}),
|
|
1527
|
-
function: `${depositToken_default.address}::${depositToken_default.name}::deposit_token`,
|
|
1528
|
-
typeArguments: [],
|
|
1529
|
-
functionArguments: [params.userId, params.amount, params.tokenAddress]
|
|
1530
|
-
});
|
|
1480
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1531
1481
|
}
|
|
1532
1482
|
async depositToVault(params) {
|
|
1533
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1534
1483
|
const aptosPayload = await generateTransactionPayload({
|
|
1535
1484
|
aptosConfig: this._aptos.config,
|
|
1536
1485
|
abi: parseEntryFunctionAbi({
|
|
@@ -1543,27 +1492,9 @@ var Client = class _Client {
|
|
|
1543
1492
|
typeArguments: [],
|
|
1544
1493
|
functionArguments: [params.userId, params.vaultId, toSystemValue(params.amount)]
|
|
1545
1494
|
});
|
|
1546
|
-
|
|
1547
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1548
|
-
BigInt(sequenceNumber),
|
|
1549
|
-
aptosPayload,
|
|
1550
|
-
BigInt(1e6),
|
|
1551
|
-
// maxGasAmount
|
|
1552
|
-
BigInt(100),
|
|
1553
|
-
// gasUnitPrice
|
|
1554
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1555
|
-
// expirationTimestampSecs
|
|
1556
|
-
new ChainId(this._chainId)
|
|
1557
|
-
);
|
|
1558
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1559
|
-
const signature = this._aptos.sign({
|
|
1560
|
-
signer: this._apiKey,
|
|
1561
|
-
transaction: tx
|
|
1562
|
-
});
|
|
1563
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1495
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1564
1496
|
}
|
|
1565
1497
|
async withdrawFromVault(params) {
|
|
1566
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1567
1498
|
const aptosPayload = await generateTransactionPayload({
|
|
1568
1499
|
aptosConfig: this._aptos.config,
|
|
1569
1500
|
abi: parseEntryFunctionAbi({
|
|
@@ -1581,27 +1512,9 @@ var Client = class _Client {
|
|
|
1581
1512
|
params.max
|
|
1582
1513
|
]
|
|
1583
1514
|
});
|
|
1584
|
-
|
|
1585
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1586
|
-
BigInt(sequenceNumber),
|
|
1587
|
-
aptosPayload,
|
|
1588
|
-
BigInt(1e6),
|
|
1589
|
-
// maxGasAmount
|
|
1590
|
-
BigInt(100),
|
|
1591
|
-
// gasUnitPrice
|
|
1592
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1593
|
-
// expirationTimestampSecs
|
|
1594
|
-
new ChainId(this._chainId)
|
|
1595
|
-
);
|
|
1596
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1597
|
-
const signature = this._aptos.sign({
|
|
1598
|
-
signer: this._apiKey,
|
|
1599
|
-
transaction: tx
|
|
1600
|
-
});
|
|
1601
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1515
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1602
1516
|
}
|
|
1603
1517
|
async redeemToken(params) {
|
|
1604
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1605
1518
|
const aptosPayload = await generateTransactionPayload({
|
|
1606
1519
|
aptosConfig: this._aptos.config,
|
|
1607
1520
|
abi: parseEntryFunctionAbi({
|
|
@@ -1619,27 +1532,9 @@ var Client = class _Client {
|
|
|
1619
1532
|
params.max
|
|
1620
1533
|
]
|
|
1621
1534
|
});
|
|
1622
|
-
|
|
1623
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1624
|
-
BigInt(sequenceNumber),
|
|
1625
|
-
aptosPayload,
|
|
1626
|
-
BigInt(1e6),
|
|
1627
|
-
// maxGasAmount
|
|
1628
|
-
BigInt(100),
|
|
1629
|
-
// gasUnitPrice
|
|
1630
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1631
|
-
// expirationTimestampSecs
|
|
1632
|
-
new ChainId(this._chainId)
|
|
1633
|
-
);
|
|
1634
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1635
|
-
const signature = this._aptos.sign({
|
|
1636
|
-
signer: this._apiKey,
|
|
1637
|
-
transaction: tx
|
|
1638
|
-
});
|
|
1639
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1535
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1640
1536
|
}
|
|
1641
1537
|
async lendToken(params) {
|
|
1642
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1643
1538
|
const aptosPayload = await generateTransactionPayload({
|
|
1644
1539
|
aptosConfig: this._aptos.config,
|
|
1645
1540
|
abi: parseEntryFunctionAbi({
|
|
@@ -1657,27 +1552,9 @@ var Client = class _Client {
|
|
|
1657
1552
|
params.max
|
|
1658
1553
|
]
|
|
1659
1554
|
});
|
|
1660
|
-
|
|
1661
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1662
|
-
BigInt(sequenceNumber),
|
|
1663
|
-
aptosPayload,
|
|
1664
|
-
BigInt(1e6),
|
|
1665
|
-
// maxGasAmount
|
|
1666
|
-
BigInt(100),
|
|
1667
|
-
// gasUnitPrice
|
|
1668
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1669
|
-
// expirationTimestampSecs
|
|
1670
|
-
new ChainId(this._chainId)
|
|
1671
|
-
);
|
|
1672
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1673
|
-
const signature = this._aptos.sign({
|
|
1674
|
-
signer: this._apiKey,
|
|
1675
|
-
transaction: tx
|
|
1676
|
-
});
|
|
1677
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1555
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1678
1556
|
}
|
|
1679
1557
|
async claimReferralFees(params) {
|
|
1680
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1681
1558
|
const aptosPayload = await generateTransactionPayload({
|
|
1682
1559
|
aptosConfig: this._aptos.config,
|
|
1683
1560
|
abi: parseEntryFunctionAbi({
|
|
@@ -1690,27 +1567,9 @@ var Client = class _Client {
|
|
|
1690
1567
|
typeArguments: [],
|
|
1691
1568
|
functionArguments: [params.userId, params.referrals]
|
|
1692
1569
|
});
|
|
1693
|
-
|
|
1694
|
-
AccountAddress.from(this._apiKey.accountAddress),
|
|
1695
|
-
BigInt(sequenceNumber),
|
|
1696
|
-
aptosPayload,
|
|
1697
|
-
BigInt(1e6),
|
|
1698
|
-
// maxGasAmount
|
|
1699
|
-
BigInt(100),
|
|
1700
|
-
// gasUnitPrice
|
|
1701
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1702
|
-
// expirationTimestampSecs
|
|
1703
|
-
new ChainId(this._chainId)
|
|
1704
|
-
);
|
|
1705
|
-
const tx = new SimpleTransaction(rawTx, AccountAddress.ZERO);
|
|
1706
|
-
const signature = this._aptos.sign({
|
|
1707
|
-
signer: this._apiKey,
|
|
1708
|
-
transaction: tx
|
|
1709
|
-
});
|
|
1710
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1570
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1711
1571
|
}
|
|
1712
1572
|
async transferToUser(params) {
|
|
1713
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1714
1573
|
const aptosPayload = await generateTransactionPayload({
|
|
1715
1574
|
aptosConfig: this._aptos.config,
|
|
1716
1575
|
abi: parseEntryFunctionAbi({
|
|
@@ -1729,24 +1588,36 @@ var Client = class _Client {
|
|
|
1729
1588
|
params.recipient
|
|
1730
1589
|
]
|
|
1731
1590
|
});
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1591
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1592
|
+
}
|
|
1593
|
+
async placeMultiplePerpOrders(params) {
|
|
1594
|
+
const markets = params.perpOrders.map((order) => order.market);
|
|
1595
|
+
const isBids = params.perpOrders.map((order) => order.isBid);
|
|
1596
|
+
const prices = params.perpOrders.map((order) => toSystemValue(order.price));
|
|
1597
|
+
const sizes = params.perpOrders.map((order) => toSystemValue(order.size));
|
|
1598
|
+
const postOnly = params.perpOrders.map((order) => order.postOnly || false);
|
|
1599
|
+
const reduceOnly = params.perpOrders.map((order) => order.reduceOnly || false);
|
|
1600
|
+
const aptosPayload = await generateTransactionPayload({
|
|
1601
|
+
aptosConfig: this._aptos.config,
|
|
1602
|
+
abi: parseEntryFunctionAbi({
|
|
1603
|
+
moduleAbi: placeMultiplePerpOrders_default,
|
|
1604
|
+
functionName: placeMultiplePerpOrders_default.name,
|
|
1605
|
+
moduleAddress: placeMultiplePerpOrders_default.address,
|
|
1606
|
+
moduleName: placeMultiplePerpOrders_default.name
|
|
1607
|
+
}),
|
|
1608
|
+
function: `${placeMultiplePerpOrders_default.address}::${placeMultiplePerpOrders_default.name}::place_multiple_perp_orders`,
|
|
1609
|
+
typeArguments: [],
|
|
1610
|
+
functionArguments: [
|
|
1611
|
+
params.userId,
|
|
1612
|
+
markets,
|
|
1613
|
+
isBids,
|
|
1614
|
+
prices,
|
|
1615
|
+
sizes,
|
|
1616
|
+
postOnly,
|
|
1617
|
+
reduceOnly
|
|
1618
|
+
]
|
|
1748
1619
|
});
|
|
1749
|
-
return await this.
|
|
1620
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1750
1621
|
}
|
|
1751
1622
|
};
|
|
1752
1623
|
var client_default = Client;
|
|
@@ -1779,8 +1650,8 @@ function parseEntryFunctionAbi(args) {
|
|
|
1779
1650
|
import { createEntryPayload } from "@thalalabs/surf";
|
|
1780
1651
|
|
|
1781
1652
|
// generated_types/faucetEntrypoints.ts
|
|
1782
|
-
var
|
|
1783
|
-
"address": "
|
|
1653
|
+
var ABI19 = {
|
|
1654
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
1784
1655
|
"name": "faucet_entrypoints",
|
|
1785
1656
|
"friends": [],
|
|
1786
1657
|
"exposed_functions": [
|
|
@@ -1811,11 +1682,11 @@ var ABI18 = {
|
|
|
1811
1682
|
],
|
|
1812
1683
|
"structs": []
|
|
1813
1684
|
};
|
|
1814
|
-
var faucetEntrypoints_default =
|
|
1685
|
+
var faucetEntrypoints_default = ABI19;
|
|
1815
1686
|
|
|
1816
1687
|
// generated_types/testFaucet.ts
|
|
1817
|
-
var
|
|
1818
|
-
"address": "
|
|
1688
|
+
var ABI20 = {
|
|
1689
|
+
"address": "0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da",
|
|
1819
1690
|
"name": "test_faucet",
|
|
1820
1691
|
"friends": [],
|
|
1821
1692
|
"exposed_functions": [
|
|
@@ -1852,7 +1723,7 @@ var ABI19 = {
|
|
|
1852
1723
|
],
|
|
1853
1724
|
"return": [
|
|
1854
1725
|
"0x1::object::ConstructorRef",
|
|
1855
|
-
"0x1::object::Object<
|
|
1726
|
+
"0x1::object::Object<0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da::test_faucet::Token>"
|
|
1856
1727
|
]
|
|
1857
1728
|
},
|
|
1858
1729
|
{
|
|
@@ -2003,7 +1874,7 @@ var ABI19 = {
|
|
|
2003
1874
|
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
2004
1875
|
],
|
|
2005
1876
|
"return": [
|
|
2006
|
-
"
|
|
1877
|
+
"0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da::test_faucet::FaucetToken"
|
|
2007
1878
|
]
|
|
2008
1879
|
}
|
|
2009
1880
|
],
|
|
@@ -2035,7 +1906,7 @@ var ABI19 = {
|
|
|
2035
1906
|
"fields": [
|
|
2036
1907
|
{
|
|
2037
1908
|
"name": "tokens",
|
|
2038
|
-
"type": "0x1::smart_table::SmartTable<vector<u8>,
|
|
1909
|
+
"type": "0x1::smart_table::SmartTable<vector<u8>, 0xff3f360cd9dd43c86e8661b91d25fb45248eeaf4264fce558fc370ab8bb981da::test_faucet::FaucetToken>"
|
|
2039
1910
|
}
|
|
2040
1911
|
]
|
|
2041
1912
|
},
|
|
@@ -2060,19 +1931,15 @@ var ABI19 = {
|
|
|
2060
1931
|
}
|
|
2061
1932
|
]
|
|
2062
1933
|
};
|
|
2063
|
-
var testFaucet_default =
|
|
1934
|
+
var testFaucet_default = ABI20;
|
|
2064
1935
|
|
|
2065
1936
|
// src/testFaucet.ts
|
|
2066
1937
|
var TestFaucet = class _TestFaucet extends client_default {
|
|
2067
|
-
constructor(connection,
|
|
2068
|
-
super(connection,
|
|
1938
|
+
constructor(connection, enableWs, url, apiKey) {
|
|
1939
|
+
super(connection, enableWs, url, apiKey);
|
|
2069
1940
|
}
|
|
2070
|
-
static async create(connection,
|
|
2071
|
-
|
|
2072
|
-
if (enableWs) {
|
|
2073
|
-
ws = await client_default.initWebSocket(url);
|
|
2074
|
-
}
|
|
2075
|
-
return new _TestFaucet(connection, url, ws, apiKey);
|
|
1941
|
+
static async create(connection, enableWs = false, url = "https://api.dev.nightly.exchange", apiKey) {
|
|
1942
|
+
return new _TestFaucet(connection, enableWs, url, apiKey);
|
|
2076
1943
|
}
|
|
2077
1944
|
initFaucetPayload() {
|
|
2078
1945
|
return createEntryPayload(faucetEntrypoints_default, {
|