@nightlylabs/dex-sdk 0.0.75 → 0.0.77
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 +276 -409
- package/dist/index.d.cts +142 -129
- package/dist/index.d.ts +142 -129
- package/dist/index.js +276 -409
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -65,7 +65,7 @@ var import_uuid = require("uuid");
|
|
|
65
65
|
|
|
66
66
|
// generated_types/addApiKey.ts
|
|
67
67
|
var ABI = {
|
|
68
|
-
"address": "
|
|
68
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
69
69
|
"name": "add_api_key",
|
|
70
70
|
"friends": [],
|
|
71
71
|
"exposed_functions": [
|
|
@@ -90,7 +90,7 @@ var addApiKey_default = ABI;
|
|
|
90
90
|
|
|
91
91
|
// generated_types/cancelAllPerpOrders.ts
|
|
92
92
|
var ABI2 = {
|
|
93
|
-
"address": "
|
|
93
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
94
94
|
"name": "cancel_all_perp_orders",
|
|
95
95
|
"friends": [],
|
|
96
96
|
"exposed_functions": [
|
|
@@ -113,7 +113,7 @@ var cancelAllPerpOrders_default = ABI2;
|
|
|
113
113
|
|
|
114
114
|
// generated_types/cancelPerpOrders.ts
|
|
115
115
|
var ABI3 = {
|
|
116
|
-
"address": "
|
|
116
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
117
117
|
"name": "cancel_perp_orders",
|
|
118
118
|
"friends": [],
|
|
119
119
|
"exposed_functions": [
|
|
@@ -138,7 +138,7 @@ var cancelPerpOrders_default = ABI3;
|
|
|
138
138
|
|
|
139
139
|
// generated_types/createUser.ts
|
|
140
140
|
var ABI4 = {
|
|
141
|
-
"address": "
|
|
141
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
142
142
|
"name": "create_user",
|
|
143
143
|
"friends": [],
|
|
144
144
|
"exposed_functions": [
|
|
@@ -163,7 +163,7 @@ var createUser_default = ABI4;
|
|
|
163
163
|
|
|
164
164
|
// generated_types/depositToVault.ts
|
|
165
165
|
var ABI5 = {
|
|
166
|
-
"address": "
|
|
166
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
167
167
|
"name": "deposit_to_vault",
|
|
168
168
|
"friends": [],
|
|
169
169
|
"exposed_functions": [
|
|
@@ -188,7 +188,7 @@ var depositToVault_default = ABI5;
|
|
|
188
188
|
|
|
189
189
|
// generated_types/depositToken.ts
|
|
190
190
|
var ABI6 = {
|
|
191
|
-
"address": "
|
|
191
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
192
192
|
"name": "deposit_token",
|
|
193
193
|
"friends": [],
|
|
194
194
|
"exposed_functions": [
|
|
@@ -213,7 +213,7 @@ var depositToken_default = ABI6;
|
|
|
213
213
|
|
|
214
214
|
// generated_types/lendToken.ts
|
|
215
215
|
var ABI7 = {
|
|
216
|
-
"address": "
|
|
216
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
217
217
|
"name": "lend_token",
|
|
218
218
|
"friends": [],
|
|
219
219
|
"exposed_functions": [
|
|
@@ -239,7 +239,7 @@ var lendToken_default = ABI7;
|
|
|
239
239
|
|
|
240
240
|
// generated_types/placePerpLimitOrder.ts
|
|
241
241
|
var ABI8 = {
|
|
242
|
-
"address": "
|
|
242
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
243
243
|
"name": "place_perp_limit_order",
|
|
244
244
|
"friends": [],
|
|
245
245
|
"exposed_functions": [
|
|
@@ -268,7 +268,7 @@ var placePerpLimitOrder_default = ABI8;
|
|
|
268
268
|
|
|
269
269
|
// generated_types/changePerpOrderPrice.ts
|
|
270
270
|
var ABI9 = {
|
|
271
|
-
"address": "
|
|
271
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
272
272
|
"name": "change_perp_order_price",
|
|
273
273
|
"friends": [],
|
|
274
274
|
"exposed_functions": [
|
|
@@ -295,7 +295,7 @@ var changePerpOrderPrice_default = ABI9;
|
|
|
295
295
|
|
|
296
296
|
// generated_types/placePerpMarketOrder.ts
|
|
297
297
|
var ABI10 = {
|
|
298
|
-
"address": "
|
|
298
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
299
299
|
"name": "place_perp_market_order",
|
|
300
300
|
"friends": [],
|
|
301
301
|
"exposed_functions": [
|
|
@@ -323,7 +323,7 @@ var placePerpMarketOrder_default = ABI10;
|
|
|
323
323
|
|
|
324
324
|
// generated_types/redeemToken.ts
|
|
325
325
|
var ABI11 = {
|
|
326
|
-
"address": "
|
|
326
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
327
327
|
"name": "redeem_token",
|
|
328
328
|
"friends": [],
|
|
329
329
|
"exposed_functions": [
|
|
@@ -349,7 +349,7 @@ var redeemToken_default = ABI11;
|
|
|
349
349
|
|
|
350
350
|
// generated_types/removeApiKey.ts
|
|
351
351
|
var ABI12 = {
|
|
352
|
-
"address": "
|
|
352
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
353
353
|
"name": "remove_api_key",
|
|
354
354
|
"friends": [],
|
|
355
355
|
"exposed_functions": [
|
|
@@ -373,7 +373,7 @@ var removeApiKey_default = ABI12;
|
|
|
373
373
|
|
|
374
374
|
// generated_types/setAliasName.ts
|
|
375
375
|
var ABI13 = {
|
|
376
|
-
"address": "
|
|
376
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
377
377
|
"name": "set_alias_name",
|
|
378
378
|
"friends": [],
|
|
379
379
|
"exposed_functions": [
|
|
@@ -397,7 +397,7 @@ var setAliasName_default = ABI13;
|
|
|
397
397
|
|
|
398
398
|
// generated_types/setAutolend.ts
|
|
399
399
|
var ABI14 = {
|
|
400
|
-
"address": "
|
|
400
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
401
401
|
"name": "set_autolend",
|
|
402
402
|
"friends": [],
|
|
403
403
|
"exposed_functions": [
|
|
@@ -421,7 +421,7 @@ var setAutolend_default = ABI14;
|
|
|
421
421
|
|
|
422
422
|
// generated_types/claimReferralFees.ts
|
|
423
423
|
var ABI15 = {
|
|
424
|
-
"address": "
|
|
424
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
425
425
|
"name": "claim_referral_fees",
|
|
426
426
|
"friends": [],
|
|
427
427
|
"exposed_functions": [
|
|
@@ -445,7 +445,7 @@ var claimReferralFees_default = ABI15;
|
|
|
445
445
|
|
|
446
446
|
// generated_types/transferToUser.ts
|
|
447
447
|
var ABI16 = {
|
|
448
|
-
"address": "
|
|
448
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
449
449
|
"name": "transfer_to_user",
|
|
450
450
|
"friends": [],
|
|
451
451
|
"exposed_functions": [
|
|
@@ -470,6 +470,35 @@ var ABI16 = {
|
|
|
470
470
|
};
|
|
471
471
|
var transferToUser_default = ABI16;
|
|
472
472
|
|
|
473
|
+
// generated_types/placeMultiplePerpOrders.ts
|
|
474
|
+
var ABI17 = {
|
|
475
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
476
|
+
"name": "place_multiple_perp_orders",
|
|
477
|
+
"friends": [],
|
|
478
|
+
"exposed_functions": [
|
|
479
|
+
{
|
|
480
|
+
"name": "place_multiple_perp_orders",
|
|
481
|
+
"visibility": "public",
|
|
482
|
+
"is_entry": true,
|
|
483
|
+
"is_view": false,
|
|
484
|
+
"generic_type_params": [],
|
|
485
|
+
"params": [
|
|
486
|
+
"&signer",
|
|
487
|
+
"u64",
|
|
488
|
+
"vector<vector<u8>>",
|
|
489
|
+
"vector<bool>",
|
|
490
|
+
"vector<u64>",
|
|
491
|
+
"vector<u64>",
|
|
492
|
+
"vector<bool>",
|
|
493
|
+
"vector<bool>"
|
|
494
|
+
],
|
|
495
|
+
"return": []
|
|
496
|
+
}
|
|
497
|
+
],
|
|
498
|
+
"structs": []
|
|
499
|
+
};
|
|
500
|
+
var placeMultiplePerpOrders_default = ABI17;
|
|
501
|
+
|
|
473
502
|
// generated_types/typeshareTypes.ts
|
|
474
503
|
var PerpetualMarketStatus = /* @__PURE__ */ ((PerpetualMarketStatus2) => {
|
|
475
504
|
PerpetualMarketStatus2["Halted"] = "halted";
|
|
@@ -478,15 +507,15 @@ var PerpetualMarketStatus = /* @__PURE__ */ ((PerpetualMarketStatus2) => {
|
|
|
478
507
|
PerpetualMarketStatus2["Live"] = "live";
|
|
479
508
|
return PerpetualMarketStatus2;
|
|
480
509
|
})(PerpetualMarketStatus || {});
|
|
481
|
-
var ChartInterval = /* @__PURE__ */ ((
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return
|
|
510
|
+
var ChartInterval = /* @__PURE__ */ ((ChartInterval2) => {
|
|
511
|
+
ChartInterval2["OneMinute"] = "OneMinute";
|
|
512
|
+
ChartInterval2["FiveMinutes"] = "FiveMinutes";
|
|
513
|
+
ChartInterval2["FifteenMinutes"] = "FifteenMinutes";
|
|
514
|
+
ChartInterval2["ThirtyMinutes"] = "ThirtyMinutes";
|
|
515
|
+
ChartInterval2["OneHour"] = "OneHour";
|
|
516
|
+
ChartInterval2["FourHours"] = "FourHours";
|
|
517
|
+
ChartInterval2["OneDay"] = "OneDay";
|
|
518
|
+
return ChartInterval2;
|
|
490
519
|
})(ChartInterval || {});
|
|
491
520
|
var OrderSide = /* @__PURE__ */ ((OrderSide2) => {
|
|
492
521
|
OrderSide2["Bid"] = "Bid";
|
|
@@ -554,8 +583,8 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
|
554
583
|
})(UserStatus || {});
|
|
555
584
|
|
|
556
585
|
// generated_types/withdrawFromVault.ts
|
|
557
|
-
var
|
|
558
|
-
"address": "
|
|
586
|
+
var ABI18 = {
|
|
587
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
559
588
|
"name": "withdraw_from_vault",
|
|
560
589
|
"friends": [],
|
|
561
590
|
"exposed_functions": [
|
|
@@ -577,7 +606,7 @@ var ABI17 = {
|
|
|
577
606
|
],
|
|
578
607
|
"structs": []
|
|
579
608
|
};
|
|
580
|
-
var withdrawFromVault_default =
|
|
609
|
+
var withdrawFromVault_default = ABI18;
|
|
581
610
|
|
|
582
611
|
// src/utils.ts
|
|
583
612
|
var import_ts_sdk = require("@aptos-labs/ts-sdk");
|
|
@@ -686,6 +715,8 @@ var getTopicFromMessage = (data) => {
|
|
|
686
715
|
return data.content.senderId;
|
|
687
716
|
case "UserTransferReceived":
|
|
688
717
|
return data.content.receiverId;
|
|
718
|
+
case "ReferralUpdate":
|
|
719
|
+
return data.content.userId;
|
|
689
720
|
}
|
|
690
721
|
};
|
|
691
722
|
|
|
@@ -870,11 +901,29 @@ var AccountSequenceNumber = class {
|
|
|
870
901
|
// src/client.ts
|
|
871
902
|
var getRandomId = () => (0, import_uuid.v4)();
|
|
872
903
|
var Client = class _Client {
|
|
873
|
-
constructor(connection,
|
|
904
|
+
constructor(connection, enableWs, url, apiKey, chainId) {
|
|
874
905
|
this._apiKeySequenceNumber = 0;
|
|
875
906
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
876
907
|
this.timeout = 5e3;
|
|
877
|
-
|
|
908
|
+
/////////////////////////////////// Sponsored transactions
|
|
909
|
+
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
910
|
+
const payload = {
|
|
911
|
+
sender: tx.rawTransaction.sender.toString(),
|
|
912
|
+
sequenceNumber: tx.rawTransaction.sequence_number.toString(),
|
|
913
|
+
payload: Array.from(tx.rawTransaction.payload.bcsToBytes()),
|
|
914
|
+
maxGasAmount: tx.rawTransaction.max_gas_amount.toString(),
|
|
915
|
+
gasUnitPrice: tx.rawTransaction.gas_unit_price.toString(),
|
|
916
|
+
expirationTimestampSecs: tx.rawTransaction.expiration_timestamp_secs.toString(),
|
|
917
|
+
chainId: parseInt(tx.rawTransaction.chain_id.toString()).toString(),
|
|
918
|
+
authenticator: Array.from(signature.bcsToBytes())
|
|
919
|
+
};
|
|
920
|
+
const response = await this.sendPostJson(
|
|
921
|
+
payload,
|
|
922
|
+
"/v1/submit_sponsored_transaction" /* SubmitSponsoredTransactionRequest */
|
|
923
|
+
);
|
|
924
|
+
return response;
|
|
925
|
+
};
|
|
926
|
+
//////////////////////////////////////// GETTERS
|
|
878
927
|
this.sendGetJson = async (endpoint, message) => {
|
|
879
928
|
let URL = this._serverUrl + endpoint;
|
|
880
929
|
if (message) {
|
|
@@ -930,23 +979,6 @@ var Client = class _Client {
|
|
|
930
979
|
throw new Error(error);
|
|
931
980
|
}
|
|
932
981
|
};
|
|
933
|
-
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
934
|
-
const payload = {
|
|
935
|
-
sender: tx.rawTransaction.sender.toString(),
|
|
936
|
-
sequenceNumber: tx.rawTransaction.sequence_number.toString(),
|
|
937
|
-
payload: Array.from(tx.rawTransaction.payload.bcsToBytes()),
|
|
938
|
-
maxGasAmount: tx.rawTransaction.max_gas_amount.toString(),
|
|
939
|
-
gasUnitPrice: tx.rawTransaction.gas_unit_price.toString(),
|
|
940
|
-
expirationTimestampSecs: tx.rawTransaction.expiration_timestamp_secs.toString(),
|
|
941
|
-
chainId: parseInt(tx.rawTransaction.chain_id.toString()).toString(),
|
|
942
|
-
authenticator: Array.from(signature.bcsToBytes())
|
|
943
|
-
};
|
|
944
|
-
const response = await this.sendPostJson(
|
|
945
|
-
payload,
|
|
946
|
-
"/v1/submit_sponsored_transaction" /* SubmitSponsoredTransactionRequest */
|
|
947
|
-
);
|
|
948
|
-
return response;
|
|
949
|
-
};
|
|
950
982
|
this.getConfig = async () => {
|
|
951
983
|
const response = await this.sendGetJson("/v1/get_config" /* GetConfig */);
|
|
952
984
|
return response;
|
|
@@ -1081,38 +1113,68 @@ var Client = class _Client {
|
|
|
1081
1113
|
return response.time;
|
|
1082
1114
|
};
|
|
1083
1115
|
this._aptos = connection;
|
|
1084
|
-
this._chainId = chainId ||
|
|
1116
|
+
this._chainId = chainId || 179;
|
|
1085
1117
|
this._surf = (0, import_surf.createSurfClient)(this._aptos);
|
|
1086
1118
|
this._apiKey = apiKey || generateApiKey();
|
|
1087
1119
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
1088
|
-
this._serverUrl = url;
|
|
1120
|
+
this._serverUrl = url || "https://api.dev.nightly.exchange";
|
|
1089
1121
|
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1090
|
-
this._ws = ws;
|
|
1091
|
-
if (this._ws) {
|
|
1092
|
-
this._ws.onmessage = async (msg) => {
|
|
1093
|
-
let data;
|
|
1094
|
-
if (msg.data.arrayBuffer) {
|
|
1095
|
-
data = new TextDecoder().decode(new Uint8Array(await msg.data.arrayBuffer()));
|
|
1096
|
-
} else {
|
|
1097
|
-
data = msg.data;
|
|
1098
|
-
}
|
|
1099
|
-
const decodedMsg = JSON.parse(data);
|
|
1100
|
-
const topic = getTopicFromMessage(decodedMsg);
|
|
1101
|
-
const callback = this._subscriptions.get(topic);
|
|
1102
|
-
if (callback) {
|
|
1103
|
-
callback(decodedMsg);
|
|
1104
|
-
}
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
static async init(connection, apiKey, url = "http://127.0.0.1:4567", enableWs = true, chainId = 178) {
|
|
1109
|
-
let ws = void 0;
|
|
1110
1122
|
if (enableWs) {
|
|
1111
|
-
|
|
1123
|
+
this.connectWebSocket();
|
|
1112
1124
|
}
|
|
1125
|
+
}
|
|
1126
|
+
static async init(connection, enableWs = true, url, apiKey, chainId) {
|
|
1113
1127
|
const id = chainId || await connection.getChainId();
|
|
1114
|
-
|
|
1115
|
-
|
|
1128
|
+
return new _Client(connection, enableWs, url, apiKey, id);
|
|
1129
|
+
}
|
|
1130
|
+
static async create(connection, enableWs = true, url, apiKey) {
|
|
1131
|
+
return _Client.init(connection, enableWs, url, apiKey);
|
|
1132
|
+
}
|
|
1133
|
+
async setApiKey(apiKey) {
|
|
1134
|
+
this._apiKey = apiKey;
|
|
1135
|
+
this._apiKeySequenceNumber = await this.fetchApiKeySequenceNumber();
|
|
1136
|
+
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1137
|
+
await this._sequenceNumberManager.initialize();
|
|
1138
|
+
}
|
|
1139
|
+
getApiKeySequenceNumber() {
|
|
1140
|
+
return this._sequenceNumberManager.nextSequenceNumber();
|
|
1141
|
+
}
|
|
1142
|
+
async fetchApiKeySequenceNumber() {
|
|
1143
|
+
const accInfo = await this._aptos.getAccountInfo({
|
|
1144
|
+
accountAddress: this._apiKey.accountAddress
|
|
1145
|
+
});
|
|
1146
|
+
return Number(await accInfo.sequence_number);
|
|
1147
|
+
}
|
|
1148
|
+
//////////////////////////////////////// Websocket functions
|
|
1149
|
+
async connectWebSocket() {
|
|
1150
|
+
if (this._ws) {
|
|
1151
|
+
console.warn("WebSocket is already connected");
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
try {
|
|
1155
|
+
this._ws = await _Client.initWebSocket(this._serverUrl, this.timeout);
|
|
1156
|
+
this._setupWebSocketHandlers();
|
|
1157
|
+
return;
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
throw new Error(`Failed to connect WebSocket: ${error}`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
_setupWebSocketHandlers() {
|
|
1163
|
+
if (!this._ws) return;
|
|
1164
|
+
this._ws.onmessage = async (msg) => {
|
|
1165
|
+
let data;
|
|
1166
|
+
if (msg.data.arrayBuffer) {
|
|
1167
|
+
data = new TextDecoder().decode(new Uint8Array(await msg.data.arrayBuffer()));
|
|
1168
|
+
} else {
|
|
1169
|
+
data = msg.data;
|
|
1170
|
+
}
|
|
1171
|
+
const decodedMsg = JSON.parse(data);
|
|
1172
|
+
const topic = getTopicFromMessage(decodedMsg);
|
|
1173
|
+
const callback = this._subscriptions.get(topic);
|
|
1174
|
+
if (callback) {
|
|
1175
|
+
callback(decodedMsg);
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1116
1178
|
}
|
|
1117
1179
|
static async initWebSocket(url, timeout = 5e3) {
|
|
1118
1180
|
return new Promise((resolve, reject) => {
|
|
@@ -1132,7 +1194,21 @@ var Client = class _Client {
|
|
|
1132
1194
|
};
|
|
1133
1195
|
});
|
|
1134
1196
|
}
|
|
1197
|
+
async disconnectWebSocket() {
|
|
1198
|
+
if (!this._ws) {
|
|
1199
|
+
console.warn("WebSocket is not connected");
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
this._subscriptions.clear();
|
|
1203
|
+
this._ws.close();
|
|
1204
|
+
this._ws = void 0;
|
|
1205
|
+
}
|
|
1206
|
+
// Method to check if WebSocket is connected
|
|
1207
|
+
isWebSocketConnected() {
|
|
1208
|
+
return this._ws !== void 0 && this._ws.readyState === import_isomorphic_ws.default.OPEN;
|
|
1209
|
+
}
|
|
1135
1210
|
sendWsMessage(message) {
|
|
1211
|
+
if (!this._ws) throw new Error("WebSocket is not connected");
|
|
1136
1212
|
return new Promise((resolve, reject) => {
|
|
1137
1213
|
const topic = message.content.id;
|
|
1138
1214
|
const timer = setTimeout(() => {
|
|
@@ -1152,57 +1228,6 @@ var Client = class _Client {
|
|
|
1152
1228
|
this._ws?.send(JSON.stringify(message));
|
|
1153
1229
|
});
|
|
1154
1230
|
}
|
|
1155
|
-
static async create(connection, apiKey, url = "https://api.dev.nightly.exchange", enableWs = true) {
|
|
1156
|
-
return _Client.init(connection, apiKey, url, enableWs);
|
|
1157
|
-
}
|
|
1158
|
-
async setApiKey(apiKey) {
|
|
1159
|
-
this._apiKey = apiKey;
|
|
1160
|
-
this._apiKeySequenceNumber = await this.fetchApiKeySequenceNumber();
|
|
1161
|
-
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
1162
|
-
await this._sequenceNumberManager.initialize();
|
|
1163
|
-
}
|
|
1164
|
-
getApiKeySequenceNumber() {
|
|
1165
|
-
return this._sequenceNumberManager.nextSequenceNumber();
|
|
1166
|
-
}
|
|
1167
|
-
async fetchApiKeySequenceNumber() {
|
|
1168
|
-
const accInfo = await this._aptos.getAccountInfo({
|
|
1169
|
-
accountAddress: this._apiKey.accountAddress
|
|
1170
|
-
});
|
|
1171
|
-
return Number(await accInfo.sequence_number);
|
|
1172
|
-
}
|
|
1173
|
-
// needs to be signed by user and sent to blockchain
|
|
1174
|
-
async createUser(params) {
|
|
1175
|
-
const apiKey = generateApiKey();
|
|
1176
|
-
const payload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1177
|
-
aptosConfig: this._aptos.config,
|
|
1178
|
-
abi: parseEntryFunctionAbi({
|
|
1179
|
-
moduleAbi: createUser_default,
|
|
1180
|
-
functionName: createUser_default.name,
|
|
1181
|
-
moduleAddress: createUser_default.address,
|
|
1182
|
-
moduleName: createUser_default.name
|
|
1183
|
-
}),
|
|
1184
|
-
function: `${createUser_default.address}::${createUser_default.name}::create_user`,
|
|
1185
|
-
typeArguments: [],
|
|
1186
|
-
functionArguments: [params.name, params.referralId]
|
|
1187
|
-
});
|
|
1188
|
-
const tx = new import_ts_sdk2.MultiAgentTransaction(
|
|
1189
|
-
await (0, import_ts_sdk2.generateRawTransaction)({
|
|
1190
|
-
sender: params.sender,
|
|
1191
|
-
aptosConfig: this._aptos.config,
|
|
1192
|
-
payload
|
|
1193
|
-
}),
|
|
1194
|
-
[apiKey.accountAddress]
|
|
1195
|
-
);
|
|
1196
|
-
const signature = this._aptos.sign({
|
|
1197
|
-
signer: apiKey,
|
|
1198
|
-
transaction: tx
|
|
1199
|
-
});
|
|
1200
|
-
return {
|
|
1201
|
-
tx,
|
|
1202
|
-
signature,
|
|
1203
|
-
apiKey
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
1231
|
async subscribeIndexPricesUpdates(callback) {
|
|
1207
1232
|
const command = {
|
|
1208
1233
|
type: "SubscribeOracle",
|
|
@@ -1279,7 +1304,39 @@ var Client = class _Client {
|
|
|
1279
1304
|
const topic = getTopicFromCommand(command);
|
|
1280
1305
|
this._subscriptions.delete(topic);
|
|
1281
1306
|
}
|
|
1282
|
-
|
|
1307
|
+
/////////////////////////////////// Functions which needs to be signed by user and sent to blockchain
|
|
1308
|
+
async createUser(params) {
|
|
1309
|
+
const apiKey = generateApiKey();
|
|
1310
|
+
const payload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1311
|
+
aptosConfig: this._aptos.config,
|
|
1312
|
+
abi: parseEntryFunctionAbi({
|
|
1313
|
+
moduleAbi: createUser_default,
|
|
1314
|
+
functionName: createUser_default.name,
|
|
1315
|
+
moduleAddress: createUser_default.address,
|
|
1316
|
+
moduleName: createUser_default.name
|
|
1317
|
+
}),
|
|
1318
|
+
function: `${createUser_default.address}::${createUser_default.name}::create_user`,
|
|
1319
|
+
typeArguments: [],
|
|
1320
|
+
functionArguments: [params.name, params.referralId]
|
|
1321
|
+
});
|
|
1322
|
+
const tx = new import_ts_sdk2.MultiAgentTransaction(
|
|
1323
|
+
await (0, import_ts_sdk2.generateRawTransaction)({
|
|
1324
|
+
sender: params.sender,
|
|
1325
|
+
aptosConfig: this._aptos.config,
|
|
1326
|
+
payload
|
|
1327
|
+
}),
|
|
1328
|
+
[apiKey.accountAddress]
|
|
1329
|
+
);
|
|
1330
|
+
const signature = this._aptos.sign({
|
|
1331
|
+
signer: apiKey,
|
|
1332
|
+
transaction: tx
|
|
1333
|
+
});
|
|
1334
|
+
return {
|
|
1335
|
+
tx,
|
|
1336
|
+
signature,
|
|
1337
|
+
apiKey
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1283
1340
|
async addApiKey(params) {
|
|
1284
1341
|
return await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1285
1342
|
aptosConfig: this._aptos.config,
|
|
@@ -1294,27 +1351,33 @@ var Client = class _Client {
|
|
|
1294
1351
|
functionArguments: [params.userId, params.expiration]
|
|
1295
1352
|
});
|
|
1296
1353
|
}
|
|
1297
|
-
async
|
|
1298
|
-
|
|
1299
|
-
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1354
|
+
async depositTokenPayload(params) {
|
|
1355
|
+
return await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1300
1356
|
aptosConfig: this._aptos.config,
|
|
1301
1357
|
abi: parseEntryFunctionAbi({
|
|
1302
|
-
moduleAbi:
|
|
1303
|
-
functionName:
|
|
1304
|
-
moduleAddress:
|
|
1305
|
-
moduleName:
|
|
1358
|
+
moduleAbi: depositToken_default,
|
|
1359
|
+
functionName: depositToken_default.name,
|
|
1360
|
+
moduleAddress: depositToken_default.address,
|
|
1361
|
+
moduleName: depositToken_default.name
|
|
1306
1362
|
}),
|
|
1307
|
-
function: `${
|
|
1363
|
+
function: `${depositToken_default.address}::${depositToken_default.name}::deposit_token`,
|
|
1308
1364
|
typeArguments: [],
|
|
1309
|
-
functionArguments: [params.
|
|
1365
|
+
functionArguments: [params.userId, params.amount, params.tokenAddress]
|
|
1310
1366
|
});
|
|
1367
|
+
}
|
|
1368
|
+
// Helper function to submit sponsored transaction
|
|
1369
|
+
async createAndSubmitTransaction(aptosPayload) {
|
|
1370
|
+
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1311
1371
|
const rawTx = new import_ts_sdk2.RawTransaction(
|
|
1312
1372
|
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1313
1373
|
BigInt(sequenceNumber),
|
|
1314
1374
|
aptosPayload,
|
|
1315
1375
|
BigInt(1e6),
|
|
1376
|
+
// max gas
|
|
1316
1377
|
BigInt(100),
|
|
1378
|
+
// gas unit price
|
|
1317
1379
|
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1380
|
+
// expiration timestamp
|
|
1318
1381
|
new import_ts_sdk2.ChainId(this._chainId)
|
|
1319
1382
|
);
|
|
1320
1383
|
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
@@ -1324,8 +1387,22 @@ var Client = class _Client {
|
|
|
1324
1387
|
});
|
|
1325
1388
|
return await this.submitSponsoredTransaction(tx, signature);
|
|
1326
1389
|
}
|
|
1390
|
+
async removeApiKey(params) {
|
|
1391
|
+
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1392
|
+
aptosConfig: this._aptos.config,
|
|
1393
|
+
abi: parseEntryFunctionAbi({
|
|
1394
|
+
moduleAbi: removeApiKey_default,
|
|
1395
|
+
functionName: removeApiKey_default.name,
|
|
1396
|
+
moduleAddress: removeApiKey_default.address,
|
|
1397
|
+
moduleName: removeApiKey_default.name
|
|
1398
|
+
}),
|
|
1399
|
+
function: `${removeApiKey_default.address}::${removeApiKey_default.name}::remove_api_key`,
|
|
1400
|
+
typeArguments: [],
|
|
1401
|
+
functionArguments: [params.apiKey, params.userId]
|
|
1402
|
+
});
|
|
1403
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1404
|
+
}
|
|
1327
1405
|
async setAliasName(params) {
|
|
1328
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1329
1406
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1330
1407
|
aptosConfig: this._aptos.config,
|
|
1331
1408
|
abi: parseEntryFunctionAbi({
|
|
@@ -1338,24 +1415,9 @@ var Client = class _Client {
|
|
|
1338
1415
|
typeArguments: [],
|
|
1339
1416
|
functionArguments: [params.userId, params.alias]
|
|
1340
1417
|
});
|
|
1341
|
-
|
|
1342
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1343
|
-
BigInt(sequenceNumber),
|
|
1344
|
-
aptosPayload,
|
|
1345
|
-
BigInt(1e6),
|
|
1346
|
-
BigInt(100),
|
|
1347
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1348
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1349
|
-
);
|
|
1350
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1351
|
-
const signature = this._aptos.sign({
|
|
1352
|
-
signer: this._apiKey,
|
|
1353
|
-
transaction: tx
|
|
1354
|
-
});
|
|
1355
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1418
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1356
1419
|
}
|
|
1357
1420
|
async placePerpLimitOrder(params) {
|
|
1358
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1359
1421
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1360
1422
|
aptosConfig: this._aptos.config,
|
|
1361
1423
|
abi: parseEntryFunctionAbi({
|
|
@@ -1368,32 +1430,17 @@ var Client = class _Client {
|
|
|
1368
1430
|
typeArguments: [],
|
|
1369
1431
|
functionArguments: [
|
|
1370
1432
|
params.userId,
|
|
1371
|
-
params.market,
|
|
1372
|
-
params.isBid,
|
|
1373
|
-
params.price,
|
|
1374
|
-
params.size,
|
|
1375
|
-
params.postOnly,
|
|
1376
|
-
params.reduceOnly
|
|
1433
|
+
params.orderData.market,
|
|
1434
|
+
params.orderData.isBid,
|
|
1435
|
+
params.orderData.price,
|
|
1436
|
+
params.orderData.size,
|
|
1437
|
+
params.orderData.postOnly || false,
|
|
1438
|
+
params.orderData.reduceOnly || false
|
|
1377
1439
|
]
|
|
1378
1440
|
});
|
|
1379
|
-
|
|
1380
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1381
|
-
BigInt(sequenceNumber),
|
|
1382
|
-
aptosPayload,
|
|
1383
|
-
BigInt(1e6),
|
|
1384
|
-
BigInt(100),
|
|
1385
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1386
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1387
|
-
);
|
|
1388
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1389
|
-
const signature = this._aptos.sign({
|
|
1390
|
-
signer: this._apiKey,
|
|
1391
|
-
transaction: tx
|
|
1392
|
-
});
|
|
1393
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1441
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1394
1442
|
}
|
|
1395
1443
|
async placePerpMarketOrder(params) {
|
|
1396
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1397
1444
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1398
1445
|
aptosConfig: this._aptos.config,
|
|
1399
1446
|
abi: parseEntryFunctionAbi({
|
|
@@ -1406,31 +1453,16 @@ var Client = class _Client {
|
|
|
1406
1453
|
typeArguments: [],
|
|
1407
1454
|
functionArguments: [
|
|
1408
1455
|
params.userId,
|
|
1409
|
-
params.market,
|
|
1410
|
-
params.isBid,
|
|
1411
|
-
params.
|
|
1412
|
-
params.size,
|
|
1413
|
-
params.reduceOnly
|
|
1456
|
+
params.orderData.market,
|
|
1457
|
+
params.orderData.isBid,
|
|
1458
|
+
params.orderData.price,
|
|
1459
|
+
params.orderData.size,
|
|
1460
|
+
params.orderData.reduceOnly || false
|
|
1414
1461
|
]
|
|
1415
1462
|
});
|
|
1416
|
-
|
|
1417
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1418
|
-
BigInt(sequenceNumber),
|
|
1419
|
-
aptosPayload,
|
|
1420
|
-
BigInt(1e6),
|
|
1421
|
-
BigInt(100),
|
|
1422
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1423
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1424
|
-
);
|
|
1425
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1426
|
-
const signature = this._aptos.sign({
|
|
1427
|
-
signer: this._apiKey,
|
|
1428
|
-
transaction: tx
|
|
1429
|
-
});
|
|
1430
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1463
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1431
1464
|
}
|
|
1432
1465
|
async changePerpOrderPrice(params) {
|
|
1433
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1434
1466
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1435
1467
|
aptosConfig: this._aptos.config,
|
|
1436
1468
|
abi: parseEntryFunctionAbi({
|
|
@@ -1449,24 +1481,9 @@ var Client = class _Client {
|
|
|
1449
1481
|
params.postOnly
|
|
1450
1482
|
]
|
|
1451
1483
|
});
|
|
1452
|
-
|
|
1453
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1454
|
-
BigInt(sequenceNumber),
|
|
1455
|
-
aptosPayload,
|
|
1456
|
-
BigInt(1e6),
|
|
1457
|
-
BigInt(100),
|
|
1458
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1459
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1460
|
-
);
|
|
1461
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1462
|
-
const signature = this._aptos.sign({
|
|
1463
|
-
signer: this._apiKey,
|
|
1464
|
-
transaction: tx
|
|
1465
|
-
});
|
|
1466
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1484
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1467
1485
|
}
|
|
1468
1486
|
async cancelPerpOrders(params) {
|
|
1469
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1470
1487
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1471
1488
|
aptosConfig: this._aptos.config,
|
|
1472
1489
|
abi: parseEntryFunctionAbi({
|
|
@@ -1479,27 +1496,9 @@ var Client = class _Client {
|
|
|
1479
1496
|
typeArguments: [],
|
|
1480
1497
|
functionArguments: [params.userId, params.markets, params.orderIds]
|
|
1481
1498
|
});
|
|
1482
|
-
|
|
1483
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1484
|
-
BigInt(sequenceNumber),
|
|
1485
|
-
aptosPayload,
|
|
1486
|
-
BigInt(1e6),
|
|
1487
|
-
// maxGasAmount
|
|
1488
|
-
BigInt(100),
|
|
1489
|
-
// gasUnitPrice
|
|
1490
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1491
|
-
// expirationTimestampSecs
|
|
1492
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1493
|
-
);
|
|
1494
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1495
|
-
const signature = this._aptos.sign({
|
|
1496
|
-
signer: this._apiKey,
|
|
1497
|
-
transaction: tx
|
|
1498
|
-
});
|
|
1499
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1499
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1500
1500
|
}
|
|
1501
1501
|
async cancelAllPerpOrders(params) {
|
|
1502
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1503
1502
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1504
1503
|
aptosConfig: this._aptos.config,
|
|
1505
1504
|
abi: parseEntryFunctionAbi({
|
|
@@ -1512,27 +1511,9 @@ var Client = class _Client {
|
|
|
1512
1511
|
typeArguments: [],
|
|
1513
1512
|
functionArguments: [params.userId]
|
|
1514
1513
|
});
|
|
1515
|
-
|
|
1516
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1517
|
-
BigInt(sequenceNumber),
|
|
1518
|
-
aptosPayload,
|
|
1519
|
-
BigInt(1e6),
|
|
1520
|
-
// maxGasAmount
|
|
1521
|
-
BigInt(100),
|
|
1522
|
-
// gasUnitPrice
|
|
1523
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1524
|
-
// expirationTimestampSecs
|
|
1525
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1526
|
-
);
|
|
1527
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1528
|
-
const signature = this._aptos.sign({
|
|
1529
|
-
signer: this._apiKey,
|
|
1530
|
-
transaction: tx
|
|
1531
|
-
});
|
|
1532
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1514
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1533
1515
|
}
|
|
1534
1516
|
async setAutolend(params) {
|
|
1535
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1536
1517
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1537
1518
|
aptosConfig: this._aptos.config,
|
|
1538
1519
|
abi: parseEntryFunctionAbi({
|
|
@@ -1545,41 +1526,9 @@ var Client = class _Client {
|
|
|
1545
1526
|
typeArguments: [],
|
|
1546
1527
|
functionArguments: [params.userId, params.enabled]
|
|
1547
1528
|
});
|
|
1548
|
-
|
|
1549
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1550
|
-
BigInt(sequenceNumber),
|
|
1551
|
-
aptosPayload,
|
|
1552
|
-
BigInt(1e6),
|
|
1553
|
-
// maxGasAmount
|
|
1554
|
-
BigInt(100),
|
|
1555
|
-
// gasUnitPrice
|
|
1556
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1557
|
-
// expirationTimestampSecs
|
|
1558
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1559
|
-
);
|
|
1560
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1561
|
-
const signature = this._aptos.sign({
|
|
1562
|
-
signer: this._apiKey,
|
|
1563
|
-
transaction: tx
|
|
1564
|
-
});
|
|
1565
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1566
|
-
}
|
|
1567
|
-
async depositTokenPayload(params) {
|
|
1568
|
-
return await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1569
|
-
aptosConfig: this._aptos.config,
|
|
1570
|
-
abi: parseEntryFunctionAbi({
|
|
1571
|
-
moduleAbi: depositToken_default,
|
|
1572
|
-
functionName: depositToken_default.name,
|
|
1573
|
-
moduleAddress: depositToken_default.address,
|
|
1574
|
-
moduleName: depositToken_default.name
|
|
1575
|
-
}),
|
|
1576
|
-
function: `${depositToken_default.address}::${depositToken_default.name}::deposit_token`,
|
|
1577
|
-
typeArguments: [],
|
|
1578
|
-
functionArguments: [params.userId, params.amount, params.tokenAddress]
|
|
1579
|
-
});
|
|
1529
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1580
1530
|
}
|
|
1581
1531
|
async depositToVault(params) {
|
|
1582
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1583
1532
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1584
1533
|
aptosConfig: this._aptos.config,
|
|
1585
1534
|
abi: parseEntryFunctionAbi({
|
|
@@ -1592,27 +1541,9 @@ var Client = class _Client {
|
|
|
1592
1541
|
typeArguments: [],
|
|
1593
1542
|
functionArguments: [params.userId, params.vaultId, toSystemValue(params.amount)]
|
|
1594
1543
|
});
|
|
1595
|
-
|
|
1596
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1597
|
-
BigInt(sequenceNumber),
|
|
1598
|
-
aptosPayload,
|
|
1599
|
-
BigInt(1e6),
|
|
1600
|
-
// maxGasAmount
|
|
1601
|
-
BigInt(100),
|
|
1602
|
-
// gasUnitPrice
|
|
1603
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1604
|
-
// expirationTimestampSecs
|
|
1605
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1606
|
-
);
|
|
1607
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1608
|
-
const signature = this._aptos.sign({
|
|
1609
|
-
signer: this._apiKey,
|
|
1610
|
-
transaction: tx
|
|
1611
|
-
});
|
|
1612
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1544
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1613
1545
|
}
|
|
1614
1546
|
async withdrawFromVault(params) {
|
|
1615
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1616
1547
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1617
1548
|
aptosConfig: this._aptos.config,
|
|
1618
1549
|
abi: parseEntryFunctionAbi({
|
|
@@ -1630,27 +1561,9 @@ var Client = class _Client {
|
|
|
1630
1561
|
params.max
|
|
1631
1562
|
]
|
|
1632
1563
|
});
|
|
1633
|
-
|
|
1634
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1635
|
-
BigInt(sequenceNumber),
|
|
1636
|
-
aptosPayload,
|
|
1637
|
-
BigInt(1e6),
|
|
1638
|
-
// maxGasAmount
|
|
1639
|
-
BigInt(100),
|
|
1640
|
-
// gasUnitPrice
|
|
1641
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1642
|
-
// expirationTimestampSecs
|
|
1643
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1644
|
-
);
|
|
1645
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1646
|
-
const signature = this._aptos.sign({
|
|
1647
|
-
signer: this._apiKey,
|
|
1648
|
-
transaction: tx
|
|
1649
|
-
});
|
|
1650
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1564
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1651
1565
|
}
|
|
1652
1566
|
async redeemToken(params) {
|
|
1653
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1654
1567
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1655
1568
|
aptosConfig: this._aptos.config,
|
|
1656
1569
|
abi: parseEntryFunctionAbi({
|
|
@@ -1668,27 +1581,9 @@ var Client = class _Client {
|
|
|
1668
1581
|
params.max
|
|
1669
1582
|
]
|
|
1670
1583
|
});
|
|
1671
|
-
|
|
1672
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1673
|
-
BigInt(sequenceNumber),
|
|
1674
|
-
aptosPayload,
|
|
1675
|
-
BigInt(1e6),
|
|
1676
|
-
// maxGasAmount
|
|
1677
|
-
BigInt(100),
|
|
1678
|
-
// gasUnitPrice
|
|
1679
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1680
|
-
// expirationTimestampSecs
|
|
1681
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1682
|
-
);
|
|
1683
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1684
|
-
const signature = this._aptos.sign({
|
|
1685
|
-
signer: this._apiKey,
|
|
1686
|
-
transaction: tx
|
|
1687
|
-
});
|
|
1688
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1584
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1689
1585
|
}
|
|
1690
1586
|
async lendToken(params) {
|
|
1691
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1692
1587
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1693
1588
|
aptosConfig: this._aptos.config,
|
|
1694
1589
|
abi: parseEntryFunctionAbi({
|
|
@@ -1706,27 +1601,9 @@ var Client = class _Client {
|
|
|
1706
1601
|
params.max
|
|
1707
1602
|
]
|
|
1708
1603
|
});
|
|
1709
|
-
|
|
1710
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1711
|
-
BigInt(sequenceNumber),
|
|
1712
|
-
aptosPayload,
|
|
1713
|
-
BigInt(1e6),
|
|
1714
|
-
// maxGasAmount
|
|
1715
|
-
BigInt(100),
|
|
1716
|
-
// gasUnitPrice
|
|
1717
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1718
|
-
// expirationTimestampSecs
|
|
1719
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1720
|
-
);
|
|
1721
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1722
|
-
const signature = this._aptos.sign({
|
|
1723
|
-
signer: this._apiKey,
|
|
1724
|
-
transaction: tx
|
|
1725
|
-
});
|
|
1726
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1604
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1727
1605
|
}
|
|
1728
1606
|
async claimReferralFees(params) {
|
|
1729
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1730
1607
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1731
1608
|
aptosConfig: this._aptos.config,
|
|
1732
1609
|
abi: parseEntryFunctionAbi({
|
|
@@ -1739,27 +1616,9 @@ var Client = class _Client {
|
|
|
1739
1616
|
typeArguments: [],
|
|
1740
1617
|
functionArguments: [params.userId, params.referrals]
|
|
1741
1618
|
});
|
|
1742
|
-
|
|
1743
|
-
import_ts_sdk2.AccountAddress.from(this._apiKey.accountAddress),
|
|
1744
|
-
BigInt(sequenceNumber),
|
|
1745
|
-
aptosPayload,
|
|
1746
|
-
BigInt(1e6),
|
|
1747
|
-
// maxGasAmount
|
|
1748
|
-
BigInt(100),
|
|
1749
|
-
// gasUnitPrice
|
|
1750
|
-
BigInt(Math.floor(Date.now() / 1e3) + 10),
|
|
1751
|
-
// expirationTimestampSecs
|
|
1752
|
-
new import_ts_sdk2.ChainId(this._chainId)
|
|
1753
|
-
);
|
|
1754
|
-
const tx = new import_ts_sdk2.SimpleTransaction(rawTx, import_ts_sdk2.AccountAddress.ZERO);
|
|
1755
|
-
const signature = this._aptos.sign({
|
|
1756
|
-
signer: this._apiKey,
|
|
1757
|
-
transaction: tx
|
|
1758
|
-
});
|
|
1759
|
-
return await this.submitSponsoredTransaction(tx, signature);
|
|
1619
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1760
1620
|
}
|
|
1761
1621
|
async transferToUser(params) {
|
|
1762
|
-
const sequenceNumber = await this.getApiKeySequenceNumber();
|
|
1763
1622
|
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1764
1623
|
aptosConfig: this._aptos.config,
|
|
1765
1624
|
abi: parseEntryFunctionAbi({
|
|
@@ -1778,24 +1637,36 @@ var Client = class _Client {
|
|
|
1778
1637
|
params.recipient
|
|
1779
1638
|
]
|
|
1780
1639
|
});
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1640
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1641
|
+
}
|
|
1642
|
+
async placeMultiplePerpOrders(params) {
|
|
1643
|
+
const markets = params.perpOrders.map((order) => order.market);
|
|
1644
|
+
const isBids = params.perpOrders.map((order) => order.isBid);
|
|
1645
|
+
const prices = params.perpOrders.map((order) => toSystemValue(order.price));
|
|
1646
|
+
const sizes = params.perpOrders.map((order) => toSystemValue(order.size));
|
|
1647
|
+
const postOnly = params.perpOrders.map((order) => order.postOnly || false);
|
|
1648
|
+
const reduceOnly = params.perpOrders.map((order) => order.reduceOnly || false);
|
|
1649
|
+
const aptosPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
1650
|
+
aptosConfig: this._aptos.config,
|
|
1651
|
+
abi: parseEntryFunctionAbi({
|
|
1652
|
+
moduleAbi: placeMultiplePerpOrders_default,
|
|
1653
|
+
functionName: placeMultiplePerpOrders_default.name,
|
|
1654
|
+
moduleAddress: placeMultiplePerpOrders_default.address,
|
|
1655
|
+
moduleName: placeMultiplePerpOrders_default.name
|
|
1656
|
+
}),
|
|
1657
|
+
function: `${placeMultiplePerpOrders_default.address}::${placeMultiplePerpOrders_default.name}::place_multiple_perp_orders`,
|
|
1658
|
+
typeArguments: [],
|
|
1659
|
+
functionArguments: [
|
|
1660
|
+
params.userId,
|
|
1661
|
+
markets,
|
|
1662
|
+
isBids,
|
|
1663
|
+
prices,
|
|
1664
|
+
sizes,
|
|
1665
|
+
postOnly,
|
|
1666
|
+
reduceOnly
|
|
1667
|
+
]
|
|
1797
1668
|
});
|
|
1798
|
-
return await this.
|
|
1669
|
+
return await this.createAndSubmitTransaction(aptosPayload);
|
|
1799
1670
|
}
|
|
1800
1671
|
};
|
|
1801
1672
|
var client_default = Client;
|
|
@@ -1828,8 +1699,8 @@ function parseEntryFunctionAbi(args) {
|
|
|
1828
1699
|
var import_surf2 = require("@thalalabs/surf");
|
|
1829
1700
|
|
|
1830
1701
|
// generated_types/faucetEntrypoints.ts
|
|
1831
|
-
var
|
|
1832
|
-
"address": "
|
|
1702
|
+
var ABI19 = {
|
|
1703
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
1833
1704
|
"name": "faucet_entrypoints",
|
|
1834
1705
|
"friends": [],
|
|
1835
1706
|
"exposed_functions": [
|
|
@@ -1860,11 +1731,11 @@ var ABI18 = {
|
|
|
1860
1731
|
],
|
|
1861
1732
|
"structs": []
|
|
1862
1733
|
};
|
|
1863
|
-
var faucetEntrypoints_default =
|
|
1734
|
+
var faucetEntrypoints_default = ABI19;
|
|
1864
1735
|
|
|
1865
1736
|
// generated_types/testFaucet.ts
|
|
1866
|
-
var
|
|
1867
|
-
"address": "
|
|
1737
|
+
var ABI20 = {
|
|
1738
|
+
"address": "0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1",
|
|
1868
1739
|
"name": "test_faucet",
|
|
1869
1740
|
"friends": [],
|
|
1870
1741
|
"exposed_functions": [
|
|
@@ -1901,7 +1772,7 @@ var ABI19 = {
|
|
|
1901
1772
|
],
|
|
1902
1773
|
"return": [
|
|
1903
1774
|
"0x1::object::ConstructorRef",
|
|
1904
|
-
"0x1::object::Object<
|
|
1775
|
+
"0x1::object::Object<0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1::test_faucet::Token>"
|
|
1905
1776
|
]
|
|
1906
1777
|
},
|
|
1907
1778
|
{
|
|
@@ -2052,7 +1923,7 @@ var ABI19 = {
|
|
|
2052
1923
|
"0x1::object::Object<0x1::fungible_asset::Metadata>"
|
|
2053
1924
|
],
|
|
2054
1925
|
"return": [
|
|
2055
|
-
"
|
|
1926
|
+
"0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1::test_faucet::FaucetToken"
|
|
2056
1927
|
]
|
|
2057
1928
|
}
|
|
2058
1929
|
],
|
|
@@ -2084,7 +1955,7 @@ var ABI19 = {
|
|
|
2084
1955
|
"fields": [
|
|
2085
1956
|
{
|
|
2086
1957
|
"name": "tokens",
|
|
2087
|
-
"type": "0x1::smart_table::SmartTable<vector<u8>,
|
|
1958
|
+
"type": "0x1::smart_table::SmartTable<vector<u8>, 0xbfb63c243ab7f41c653f442ed47d009af14771c6fef4259244ddf0b0fb7b12e1::test_faucet::FaucetToken>"
|
|
2088
1959
|
}
|
|
2089
1960
|
]
|
|
2090
1961
|
},
|
|
@@ -2109,19 +1980,15 @@ var ABI19 = {
|
|
|
2109
1980
|
}
|
|
2110
1981
|
]
|
|
2111
1982
|
};
|
|
2112
|
-
var testFaucet_default =
|
|
1983
|
+
var testFaucet_default = ABI20;
|
|
2113
1984
|
|
|
2114
1985
|
// src/testFaucet.ts
|
|
2115
1986
|
var TestFaucet = class _TestFaucet extends client_default {
|
|
2116
|
-
constructor(connection,
|
|
2117
|
-
super(connection,
|
|
1987
|
+
constructor(connection, enableWs, url, apiKey) {
|
|
1988
|
+
super(connection, enableWs, url, apiKey);
|
|
2118
1989
|
}
|
|
2119
|
-
static async create(connection,
|
|
2120
|
-
|
|
2121
|
-
if (enableWs) {
|
|
2122
|
-
ws = await client_default.initWebSocket(url);
|
|
2123
|
-
}
|
|
2124
|
-
return new _TestFaucet(connection, url, ws, apiKey);
|
|
1990
|
+
static async create(connection, enableWs = false, url = "https://api.dev.nightly.exchange", apiKey) {
|
|
1991
|
+
return new _TestFaucet(connection, enableWs, url, apiKey);
|
|
2125
1992
|
}
|
|
2126
1993
|
initFaucetPayload() {
|
|
2127
1994
|
return (0, import_surf2.createEntryPayload)(faucetEntrypoints_default, {
|