@bluefin-exchange/pro-sdk 0.1.13 → 0.1.14

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/example.js CHANGED
@@ -174,6 +174,10 @@ function main() {
174
174
  // Withdraw 10 USD
175
175
  yield client.withdraw("USDC", "10000000000");
176
176
  logger.info("Withdraw request success");
177
+ yield client.authorizeAccount(bfSigner.getAddress());
178
+ logger.info("Authorize account request success");
179
+ yield client.deauthorizeAccount(bfSigner.getAddress());
180
+ logger.info("Deauthorize account request success");
177
181
  // Keep connection alive
178
182
  yield new Promise((resolve) => setTimeout(resolve, 50000));
179
183
  }
package/dist/src/api.d.ts CHANGED
@@ -122,6 +122,68 @@ export interface Account {
122
122
  */
123
123
  'positions': Array<Position>;
124
124
  }
125
+ /**
126
+ *
127
+ * @export
128
+ * @interface AccountAuthorizationRequest
129
+ */
130
+ export interface AccountAuthorizationRequest {
131
+ /**
132
+ *
133
+ * @type {AccountAuthorizationRequestSignedFields}
134
+ * @memberof AccountAuthorizationRequest
135
+ */
136
+ 'signedFields': AccountAuthorizationRequestSignedFields;
137
+ /**
138
+ * The signature of the request, encoded from the signedFields
139
+ * @type {string}
140
+ * @memberof AccountAuthorizationRequest
141
+ */
142
+ 'signature': string;
143
+ /**
144
+ * Used to uniquely identify the request. Created by hex encoding the bcs encoded signedFields.
145
+ * @type {string}
146
+ * @memberof AccountAuthorizationRequest
147
+ */
148
+ 'requestHash': string;
149
+ }
150
+ /**
151
+ *
152
+ * @export
153
+ * @interface AccountAuthorizationRequestSignedFields
154
+ */
155
+ export interface AccountAuthorizationRequestSignedFields {
156
+ /**
157
+ * The account address of the parent account that is authorizing/deauthorizing this account
158
+ * @type {string}
159
+ * @memberof AccountAuthorizationRequestSignedFields
160
+ */
161
+ 'accountAddress': string;
162
+ /**
163
+ * The address of the account that should be authorized/deauthorized
164
+ * @type {string}
165
+ * @memberof AccountAuthorizationRequestSignedFields
166
+ */
167
+ 'authorizedAccountAddress': string;
168
+ /**
169
+ * The random generated salt. Should always be a number
170
+ * @type {string}
171
+ * @memberof AccountAuthorizationRequestSignedFields
172
+ */
173
+ 'salt': string;
174
+ /**
175
+ * the ID of the internal datastore for the target network
176
+ * @type {string}
177
+ * @memberof AccountAuthorizationRequestSignedFields
178
+ */
179
+ 'idsId': string;
180
+ /**
181
+ * The timestamp when the request was signed
182
+ * @type {number}
183
+ * @memberof AccountAuthorizationRequestSignedFields
184
+ */
185
+ 'signedAtUtcMillis': number;
186
+ }
125
187
  /**
126
188
  * Represents the type of account data stream.
127
189
  * @export
@@ -4324,6 +4386,22 @@ export declare const TradeApiAxiosParamCreator: (configuration?: Configuration)
4324
4386
  * @throws {RequiredError}
4325
4387
  */
4326
4388
  postWithdraw: (withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
4389
+ /**
4390
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
4391
+ * @summary Authorizes an account
4392
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4393
+ * @param {*} [options] Override http request option.
4394
+ * @throws {RequiredError}
4395
+ */
4396
+ putAuthorizeAccount: (accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
4397
+ /**
4398
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
4399
+ * @summary Deauthorizes an account
4400
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4401
+ * @param {*} [options] Override http request option.
4402
+ * @throws {RequiredError}
4403
+ */
4404
+ putDeauthorizeAccount: (accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
4327
4405
  /**
4328
4406
  * Updates leverage for positions of a given market, closes all open orders for that market
4329
4407
  * @summary Updates leverage for positions
@@ -4370,6 +4448,22 @@ export declare const TradeApiFp: (configuration?: Configuration) => {
4370
4448
  * @throws {RequiredError}
4371
4449
  */
4372
4450
  postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
4451
+ /**
4452
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
4453
+ * @summary Authorizes an account
4454
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4455
+ * @param {*} [options] Override http request option.
4456
+ * @throws {RequiredError}
4457
+ */
4458
+ putAuthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
4459
+ /**
4460
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
4461
+ * @summary Deauthorizes an account
4462
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4463
+ * @param {*} [options] Override http request option.
4464
+ * @throws {RequiredError}
4465
+ */
4466
+ putDeauthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
4373
4467
  /**
4374
4468
  * Updates leverage for positions of a given market, closes all open orders for that market
4375
4469
  * @summary Updates leverage for positions
@@ -4416,6 +4510,22 @@ export declare const TradeApiFactory: (configuration?: Configuration, basePath?:
4416
4510
  * @throws {RequiredError}
4417
4511
  */
4418
4512
  postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
4513
+ /**
4514
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
4515
+ * @summary Authorizes an account
4516
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4517
+ * @param {*} [options] Override http request option.
4518
+ * @throws {RequiredError}
4519
+ */
4520
+ putAuthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
4521
+ /**
4522
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
4523
+ * @summary Deauthorizes an account
4524
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4525
+ * @param {*} [options] Override http request option.
4526
+ * @throws {RequiredError}
4527
+ */
4528
+ putDeauthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
4419
4529
  /**
4420
4530
  * Updates leverage for positions of a given market, closes all open orders for that market
4421
4531
  * @summary Updates leverage for positions
@@ -4468,6 +4578,24 @@ export declare class TradeApi extends BaseAPI {
4468
4578
  * @memberof TradeApi
4469
4579
  */
4470
4580
  postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
4581
+ /**
4582
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
4583
+ * @summary Authorizes an account
4584
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4585
+ * @param {*} [options] Override http request option.
4586
+ * @throws {RequiredError}
4587
+ * @memberof TradeApi
4588
+ */
4589
+ putAuthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
4590
+ /**
4591
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
4592
+ * @summary Deauthorizes an account
4593
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
4594
+ * @param {*} [options] Override http request option.
4595
+ * @throws {RequiredError}
4596
+ * @memberof TradeApi
4597
+ */
4598
+ putDeauthorizeAccount(accountAuthorizationRequest: AccountAuthorizationRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
4471
4599
  /**
4472
4600
  * Updates leverage for positions of a given market, closes all open orders for that market
4473
4601
  * @summary Updates leverage for positions
package/dist/src/api.js CHANGED
@@ -2088,6 +2088,72 @@ const TradeApiAxiosParamCreator = function (configuration) {
2088
2088
  options: localVarRequestOptions,
2089
2089
  };
2090
2090
  }),
2091
+ /**
2092
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
2093
+ * @summary Authorizes an account
2094
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2095
+ * @param {*} [options] Override http request option.
2096
+ * @throws {RequiredError}
2097
+ */
2098
+ putAuthorizeAccount: (accountAuthorizationRequest_1, ...args_1) => __awaiter(this, [accountAuthorizationRequest_1, ...args_1], void 0, function* (accountAuthorizationRequest, options = {}) {
2099
+ // verify required parameter 'accountAuthorizationRequest' is not null or undefined
2100
+ (0, common_1.assertParamExists)('putAuthorizeAccount', 'accountAuthorizationRequest', accountAuthorizationRequest);
2101
+ const localVarPath = `/api/v1/trade/accounts/authorize`;
2102
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
2103
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
2104
+ let baseOptions;
2105
+ if (configuration) {
2106
+ baseOptions = configuration.baseOptions;
2107
+ }
2108
+ const localVarRequestOptions = Object.assign(Object.assign({ method: 'PUT' }, baseOptions), options);
2109
+ const localVarHeaderParameter = {};
2110
+ const localVarQueryParameter = {};
2111
+ // authentication bearerAuth required
2112
+ // http bearer authentication required
2113
+ yield (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration);
2114
+ localVarHeaderParameter['Content-Type'] = 'application/json';
2115
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
2116
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
2117
+ localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
2118
+ localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(accountAuthorizationRequest, localVarRequestOptions, configuration);
2119
+ return {
2120
+ url: (0, common_1.toPathString)(localVarUrlObj),
2121
+ options: localVarRequestOptions,
2122
+ };
2123
+ }),
2124
+ /**
2125
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
2126
+ * @summary Deauthorizes an account
2127
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2128
+ * @param {*} [options] Override http request option.
2129
+ * @throws {RequiredError}
2130
+ */
2131
+ putDeauthorizeAccount: (accountAuthorizationRequest_1, ...args_1) => __awaiter(this, [accountAuthorizationRequest_1, ...args_1], void 0, function* (accountAuthorizationRequest, options = {}) {
2132
+ // verify required parameter 'accountAuthorizationRequest' is not null or undefined
2133
+ (0, common_1.assertParamExists)('putDeauthorizeAccount', 'accountAuthorizationRequest', accountAuthorizationRequest);
2134
+ const localVarPath = `/api/v1/trade/accounts/deauthorize`;
2135
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
2136
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
2137
+ let baseOptions;
2138
+ if (configuration) {
2139
+ baseOptions = configuration.baseOptions;
2140
+ }
2141
+ const localVarRequestOptions = Object.assign(Object.assign({ method: 'PUT' }, baseOptions), options);
2142
+ const localVarHeaderParameter = {};
2143
+ const localVarQueryParameter = {};
2144
+ // authentication bearerAuth required
2145
+ // http bearer authentication required
2146
+ yield (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration);
2147
+ localVarHeaderParameter['Content-Type'] = 'application/json';
2148
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
2149
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
2150
+ localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
2151
+ localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(accountAuthorizationRequest, localVarRequestOptions, configuration);
2152
+ return {
2153
+ url: (0, common_1.toPathString)(localVarUrlObj),
2154
+ options: localVarRequestOptions,
2155
+ };
2156
+ }),
2091
2157
  /**
2092
2158
  * Updates leverage for positions of a given market, closes all open orders for that market
2093
2159
  * @summary Updates leverage for positions
@@ -2195,6 +2261,38 @@ const TradeApiFp = function (configuration) {
2195
2261
  return (axios, basePath) => (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
2196
2262
  });
2197
2263
  },
2264
+ /**
2265
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
2266
+ * @summary Authorizes an account
2267
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2268
+ * @param {*} [options] Override http request option.
2269
+ * @throws {RequiredError}
2270
+ */
2271
+ putAuthorizeAccount(accountAuthorizationRequest, options) {
2272
+ return __awaiter(this, void 0, void 0, function* () {
2273
+ var _a, _b, _c;
2274
+ const localVarAxiosArgs = yield localVarAxiosParamCreator.putAuthorizeAccount(accountAuthorizationRequest, options);
2275
+ const localVarOperationServerIndex = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.serverIndex) !== null && _a !== void 0 ? _a : 0;
2276
+ const localVarOperationServerBasePath = (_c = (_b = base_1.operationServerMap['TradeApi.putAuthorizeAccount']) === null || _b === void 0 ? void 0 : _b[localVarOperationServerIndex]) === null || _c === void 0 ? void 0 : _c.url;
2277
+ return (axios, basePath) => (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
2278
+ });
2279
+ },
2280
+ /**
2281
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
2282
+ * @summary Deauthorizes an account
2283
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2284
+ * @param {*} [options] Override http request option.
2285
+ * @throws {RequiredError}
2286
+ */
2287
+ putDeauthorizeAccount(accountAuthorizationRequest, options) {
2288
+ return __awaiter(this, void 0, void 0, function* () {
2289
+ var _a, _b, _c;
2290
+ const localVarAxiosArgs = yield localVarAxiosParamCreator.putDeauthorizeAccount(accountAuthorizationRequest, options);
2291
+ const localVarOperationServerIndex = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.serverIndex) !== null && _a !== void 0 ? _a : 0;
2292
+ const localVarOperationServerBasePath = (_c = (_b = base_1.operationServerMap['TradeApi.putDeauthorizeAccount']) === null || _b === void 0 ? void 0 : _b[localVarOperationServerIndex]) === null || _c === void 0 ? void 0 : _c.url;
2293
+ return (axios, basePath) => (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
2294
+ });
2295
+ },
2198
2296
  /**
2199
2297
  * Updates leverage for positions of a given market, closes all open orders for that market
2200
2298
  * @summary Updates leverage for positions
@@ -2261,6 +2359,26 @@ const TradeApiFactory = function (configuration, basePath, axios) {
2261
2359
  postWithdraw(withdrawRequest, options) {
2262
2360
  return localVarFp.postWithdraw(withdrawRequest, options).then((request) => request(axios, basePath));
2263
2361
  },
2362
+ /**
2363
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
2364
+ * @summary Authorizes an account
2365
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2366
+ * @param {*} [options] Override http request option.
2367
+ * @throws {RequiredError}
2368
+ */
2369
+ putAuthorizeAccount(accountAuthorizationRequest, options) {
2370
+ return localVarFp.putAuthorizeAccount(accountAuthorizationRequest, options).then((request) => request(axios, basePath));
2371
+ },
2372
+ /**
2373
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
2374
+ * @summary Deauthorizes an account
2375
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2376
+ * @param {*} [options] Override http request option.
2377
+ * @throws {RequiredError}
2378
+ */
2379
+ putDeauthorizeAccount(accountAuthorizationRequest, options) {
2380
+ return localVarFp.putDeauthorizeAccount(accountAuthorizationRequest, options).then((request) => request(axios, basePath));
2381
+ },
2264
2382
  /**
2265
2383
  * Updates leverage for positions of a given market, closes all open orders for that market
2266
2384
  * @summary Updates leverage for positions
@@ -2325,6 +2443,28 @@ class TradeApi extends base_1.BaseAPI {
2325
2443
  postWithdraw(withdrawRequest, options) {
2326
2444
  return (0, exports.TradeApiFp)(this.configuration).postWithdraw(withdrawRequest, options).then((request) => request(this.axios, this.basePath));
2327
2445
  }
2446
+ /**
2447
+ * Authorizes an account to trade, perform liquidations and more, on behalf of another account
2448
+ * @summary Authorizes an account
2449
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2450
+ * @param {*} [options] Override http request option.
2451
+ * @throws {RequiredError}
2452
+ * @memberof TradeApi
2453
+ */
2454
+ putAuthorizeAccount(accountAuthorizationRequest, options) {
2455
+ return (0, exports.TradeApiFp)(this.configuration).putAuthorizeAccount(accountAuthorizationRequest, options).then((request) => request(this.axios, this.basePath));
2456
+ }
2457
+ /**
2458
+ * Deauthorizes an account to trade, perform liquidations and more, on behalf of another account
2459
+ * @summary Deauthorizes an account
2460
+ * @param {AccountAuthorizationRequest} accountAuthorizationRequest
2461
+ * @param {*} [options] Override http request option.
2462
+ * @throws {RequiredError}
2463
+ * @memberof TradeApi
2464
+ */
2465
+ putDeauthorizeAccount(accountAuthorizationRequest, options) {
2466
+ return (0, exports.TradeApiFp)(this.configuration).putDeauthorizeAccount(accountAuthorizationRequest, options).then((request) => request(this.axios, this.basePath));
2467
+ }
2328
2468
  /**
2329
2469
  * Updates leverage for positions of a given market, closes all open orders for that market
2330
2470
  * @summary Updates leverage for positions
@@ -1,11 +1,12 @@
1
1
  import { Keypair, Signer } from "@mysten/sui/cryptography";
2
- import { LoginRequest, AccountPositionLeverageUpdateRequestSignedFields, CreateOrderRequestSignedFields, WithdrawRequestSignedFields } from "./api";
2
+ import { LoginRequest, AccountPositionLeverageUpdateRequestSignedFields, CreateOrderRequestSignedFields, WithdrawRequestSignedFields, AccountAuthorizationRequestSignedFields } from "./api";
3
3
  import { DryRunTransactionBlockResponse, SuiClient, SuiTransactionBlockResponse, TransactionBlock } from "@firefly-exchange/library-sui";
4
4
  export interface IBluefinSigner {
5
5
  getAddress(): string;
6
6
  signLeverageUpdateRequest: (fields: AccountPositionLeverageUpdateRequestSignedFields) => Promise<string>;
7
7
  signOrderRequest: (fields: CreateOrderRequestSignedFields) => Promise<string>;
8
8
  signWithdrawRequest: (fields: WithdrawRequestSignedFields) => Promise<string>;
9
+ signAccountAuthorizationRequest: (fields: AccountAuthorizationRequestSignedFields, isAuthorize: boolean) => Promise<string>;
9
10
  signLoginRequest: (request: LoginRequest) => Promise<string>;
10
11
  executeTx: (txb: TransactionBlock, suiClient: SuiClient) => Promise<DryRunTransactionBlockResponse | SuiTransactionBlockResponse>;
11
12
  }
@@ -32,6 +33,10 @@ export declare class BluefinRequestSigner implements IBluefinSigner {
32
33
  * Sign a leverage update request
33
34
  */
34
35
  signLeverageUpdateRequest(signedFields: AccountPositionLeverageUpdateRequestSignedFields): Promise<string>;
36
+ /**
37
+ * Sign an account authorization request
38
+ */
39
+ signAccountAuthorizationRequest(signedFields: AccountAuthorizationRequestSignedFields, is_authorize: boolean): Promise<string>;
35
40
  executeTx(txb: TransactionBlock, suiClient: SuiClient): Promise<DryRunTransactionBlockResponse | SuiTransactionBlockResponse>;
36
41
  /**
37
42
  * Get the wallet's address
@@ -25,6 +25,7 @@ var ClientPayloadType;
25
25
  ClientPayloadType["WithdrawRequest"] = "Bluefin Pro Withdrawal";
26
26
  ClientPayloadType["OrderRequest"] = "Bluefin Pro Order";
27
27
  ClientPayloadType["LeverageAdjustment"] = "Bluefin Pro Leverage Adjustment";
28
+ ClientPayloadType["AuthorizeAccount"] = "Bluefin Pro Authorize Account";
28
29
  })(ClientPayloadType || (ClientPayloadType = {}));
29
30
  var PositionType;
30
31
  (function (PositionType) {
@@ -70,6 +71,28 @@ function toUIUpdateAccountPositionLeverageRequest(val) {
70
71
  signedAt: val.signedAtUtcMillis.toString(),
71
72
  };
72
73
  }
74
+ function toUIAuthorizeAccountRequest(val) {
75
+ return {
76
+ type: ClientPayloadType.AuthorizeAccount,
77
+ ids: val.idsId,
78
+ account: val.accountAddress,
79
+ user: val.authorizedAccountAddress,
80
+ status: true,
81
+ salt: val.salt,
82
+ signedAt: val.signedAtUtcMillis.toString(),
83
+ };
84
+ }
85
+ function toUIDeauthorizeAccountRequest(val) {
86
+ return {
87
+ type: ClientPayloadType.AuthorizeAccount,
88
+ ids: val.idsId,
89
+ account: val.accountAddress,
90
+ user: val.authorizedAccountAddress,
91
+ status: false,
92
+ salt: val.salt,
93
+ signedAt: val.signedAtUtcMillis.toString(),
94
+ };
95
+ }
73
96
  // ---------- Utils ----------
74
97
  function toJson(val) {
75
98
  return JSON.stringify(val, null, 2);
@@ -131,6 +154,22 @@ class BluefinRequestSigner {
131
154
  return signedMessageSerialized.signature;
132
155
  });
133
156
  }
157
+ /**
158
+ * Sign an account authorization request
159
+ */
160
+ signAccountAuthorizationRequest(signedFields, is_authorize) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const requestJson = toJson(is_authorize
163
+ ? toUIAuthorizeAccountRequest(signedFields)
164
+ : toUIDeauthorizeAccountRequest(signedFields));
165
+ const signedMessageSerialized = yield this.wallet.signPersonalMessage(new TextEncoder().encode(requestJson));
166
+ const parsedSignature = (0, cryptography_1.parseSerializedSignature)(signedMessageSerialized.signature);
167
+ if (parsedSignature.signatureScheme == "MultiSig") {
168
+ throw new Error("MultiSig not supported");
169
+ }
170
+ return signedMessageSerialized.signature;
171
+ });
172
+ }
134
173
  executeTx(txb, suiClient) {
135
174
  return __awaiter(this, void 0, void 0, function* () {
136
175
  return library_sui_1.SuiBlocks.execCall(txb, suiClient, this.wallet, false);
package/dist/src/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OrderType, OrderTimeInForce, SelfTradePreventionType, OrderSide, CancelOrdersRequest, AccountDataApi, ExchangeApi, MarketStreamMessage, AccountStreamMessage } from "./api";
1
+ import { OrderType, OrderTimeInForce, SelfTradePreventionType, OrderSide, CancelOrdersRequest, AccountDataApi, ExchangeApi, MarketStreamMessage, AccountStreamMessage, LoginResponse } from "./api";
2
2
  import { IBluefinSigner } from "./request-signer";
3
3
  import { WebSocket } from "ws";
4
4
  import { SuiClient } from "@firefly-exchange/library-sui";
@@ -18,18 +18,20 @@ export interface OrderParams {
18
18
  triggerPriceE9?: string;
19
19
  selfTradePreventionType?: SelfTradePreventionType;
20
20
  }
21
- type BasePathConfig = {
22
- authHost: string | null;
23
- apiHost: string | null;
24
- tradeHost: string | null;
25
- marketWsHost: string | null;
26
- accountWsHost: string | null;
27
- };
21
+ export interface BluefinProSdkOptions {
22
+ currentAccountAddress?: string;
23
+ refreshToken?: string;
24
+ refreshTokenValidForSeconds?: number;
25
+ authHost?: string;
26
+ apiHost?: string;
27
+ tradeHost?: string;
28
+ marketWsHost?: string;
29
+ accountWsHost?: string;
30
+ }
28
31
  export declare class BluefinProSdk {
29
32
  private readonly bfSigner;
30
33
  private environment;
31
34
  private suiClient;
32
- private currentAccountAddress;
33
35
  private readonly configs;
34
36
  readonly exchangeDataApi: ExchangeApi;
35
37
  readonly accountDataApi: AccountDataApi;
@@ -42,7 +44,9 @@ export declare class BluefinProSdk {
42
44
  private contractsConfig;
43
45
  private assets;
44
46
  private txBuilder;
45
- constructor(bfSigner: IBluefinSigner, environment: "mainnet" | "testnet" | "devnet" | undefined, suiClient: SuiClient, currentAccountAddress?: string | null, basePathConfig?: BasePathConfig | null);
47
+ private currentAccountAddress;
48
+ constructor(bfSigner: IBluefinSigner, environment: "mainnet" | "testnet" | "devnet" | undefined, suiClient: SuiClient, opts?: BluefinProSdkOptions);
49
+ getTokenResponse(): LoginResponse | null;
46
50
  private generateSalt;
47
51
  private initializeTxBuilder;
48
52
  initialize(): Promise<void>;
@@ -55,11 +59,12 @@ export declare class BluefinProSdk {
55
59
  createOrder(params: OrderParams): Promise<any>;
56
60
  cancelOrder(cancelOrdersRequest: CancelOrdersRequest): Promise<import("axios").AxiosResponse<void, any>>;
57
61
  withdraw(assetSymbol: string, amountE9: string): Promise<void>;
62
+ authorizeAccount(accountAddress: string): Promise<void>;
63
+ deauthorizeAccount(accountAddress: string): Promise<void>;
58
64
  deposit(amountE9: string, accountAddress?: string): Promise<import("@firefly-exchange/library-sui").DryRunTransactionBlockResponse | import("@firefly-exchange/library-sui").SuiTransactionBlockResponse>;
59
65
  private setAccessToken;
60
- private refreshToken;
66
+ refreshToken(): Promise<void>;
61
67
  createAccountDataStreamListener(handler: (data: AccountStreamMessage) => Promise<void>): Promise<WebSocket>;
62
68
  createMarketDataStreamListener(handler: (data: MarketStreamMessage) => Promise<void>): Promise<WebSocket>;
63
69
  dispose(): Promise<void>;
64
70
  }
65
- export {};
package/dist/src/sdk.js CHANGED
@@ -48,33 +48,33 @@ var Services;
48
48
  Services[Services["AccountWebsocket"] = 5] = "AccountWebsocket";
49
49
  })(Services || (Services = {}));
50
50
  class BluefinProSdk {
51
- constructor(bfSigner, environment = "mainnet", suiClient, currentAccountAddress = null, basePathConfig = null) {
51
+ constructor(bfSigner, environment = "mainnet", suiClient, opts) {
52
+ var _a, _b, _c, _d, _e;
52
53
  this.bfSigner = bfSigner;
53
54
  this.environment = environment;
54
55
  this.suiClient = suiClient;
55
- this.currentAccountAddress = currentAccountAddress;
56
56
  this.configs = {};
57
+ this.currentAccountAddress = opts === null || opts === void 0 ? void 0 : opts.currentAccountAddress;
57
58
  this.isConnected = false;
58
59
  this.updateTokenInterval = null;
59
60
  this.contractsConfig = undefined;
60
61
  this.tokenResponse = null;
61
62
  this.tokenSetAtSeconds = null;
63
+ if ((opts === null || opts === void 0 ? void 0 : opts.refreshToken) && (opts === null || opts === void 0 ? void 0 : opts.refreshTokenValidForSeconds)) {
64
+ this.tokenResponse = {
65
+ accessToken: "",
66
+ accessTokenValidForSeconds: 0,
67
+ refreshToken: opts.refreshToken,
68
+ refreshTokenValidForSeconds: opts.refreshTokenValidForSeconds,
69
+ };
70
+ }
71
+ const defaultConfig = environmentConfig[this.environment];
62
72
  const basePaths = {
63
- authHost: basePathConfig && (basePathConfig === null || basePathConfig === void 0 ? void 0 : basePathConfig.authHost)
64
- ? basePathConfig.authHost
65
- : environmentConfig[this.environment].authHost,
66
- apiHost: basePathConfig && (basePathConfig === null || basePathConfig === void 0 ? void 0 : basePathConfig.apiHost)
67
- ? basePathConfig.apiHost
68
- : environmentConfig[this.environment].apiHost,
69
- tradeHost: basePathConfig && (basePathConfig === null || basePathConfig === void 0 ? void 0 : basePathConfig.tradeHost)
70
- ? basePathConfig.tradeHost
71
- : environmentConfig[this.environment].tradeHost,
72
- marketWsHost: basePathConfig && (basePathConfig === null || basePathConfig === void 0 ? void 0 : basePathConfig.marketWsHost)
73
- ? basePathConfig.marketWsHost
74
- : environmentConfig[this.environment].marketWsHost,
75
- accountWsHost: basePathConfig && (basePathConfig === null || basePathConfig === void 0 ? void 0 : basePathConfig.accountWsHost)
76
- ? basePathConfig.accountWsHost
77
- : environmentConfig[this.environment].accountWsHost,
73
+ authHost: (_a = opts === null || opts === void 0 ? void 0 : opts.authHost) !== null && _a !== void 0 ? _a : defaultConfig.authHost,
74
+ apiHost: (_b = opts === null || opts === void 0 ? void 0 : opts.apiHost) !== null && _b !== void 0 ? _b : defaultConfig.apiHost,
75
+ tradeHost: (_c = opts === null || opts === void 0 ? void 0 : opts.tradeHost) !== null && _c !== void 0 ? _c : defaultConfig.tradeHost,
76
+ marketWsHost: (_d = opts === null || opts === void 0 ? void 0 : opts.marketWsHost) !== null && _d !== void 0 ? _d : defaultConfig.marketWsHost,
77
+ accountWsHost: (_e = opts === null || opts === void 0 ? void 0 : opts.accountWsHost) !== null && _e !== void 0 ? _e : defaultConfig.accountWsHost,
78
78
  };
79
79
  const authApiConfig = new configuration_1.Configuration({
80
80
  basePath: basePaths.authHost,
@@ -105,6 +105,9 @@ class BluefinProSdk {
105
105
  });
106
106
  this.configs[Services.AccountWebsocket] = accountWsConfig;
107
107
  }
108
+ getTokenResponse() {
109
+ return this.tokenResponse;
110
+ }
108
111
  generateSalt() {
109
112
  return (Date.now() + Math.floor(Math.random() * 1000000)).toString();
110
113
  }
@@ -290,6 +293,48 @@ class BluefinProSdk {
290
293
  console.log("Withdraw request sent:", signedFields);
291
294
  });
292
295
  }
296
+ authorizeAccount(accountAddress) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ if (!this.contractsConfig) {
299
+ throw new Error("Missing contractsConfig");
300
+ }
301
+ const signedFields = {
302
+ accountAddress: this.currentAccountAddress,
303
+ idsId: this.contractsConfig.idsId,
304
+ authorizedAccountAddress: accountAddress,
305
+ salt: this.generateSalt(),
306
+ signedAtUtcMillis: Date.now(),
307
+ };
308
+ const signature = yield this.bfSigner.signAccountAuthorizationRequest(signedFields, true);
309
+ yield this.tradeApi.putAuthorizeAccount({
310
+ signedFields,
311
+ signature,
312
+ requestHash: "",
313
+ });
314
+ console.log("Authorize account request sent:", signedFields);
315
+ });
316
+ }
317
+ deauthorizeAccount(accountAddress) {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ if (!this.contractsConfig) {
320
+ throw new Error("Missing contractsConfig");
321
+ }
322
+ const signedFields = {
323
+ accountAddress: this.currentAccountAddress,
324
+ idsId: this.contractsConfig.idsId,
325
+ authorizedAccountAddress: accountAddress,
326
+ salt: this.generateSalt(),
327
+ signedAtUtcMillis: Date.now(),
328
+ };
329
+ const signature = yield this.bfSigner.signAccountAuthorizationRequest(signedFields, false);
330
+ yield this.tradeApi.putDeauthorizeAccount({
331
+ signedFields,
332
+ signature,
333
+ requestHash: "",
334
+ });
335
+ console.log("Deauthorize account request sent:", signedFields);
336
+ });
337
+ }
293
338
  deposit(amountE9, accountAddress) {
294
339
  return __awaiter(this, void 0, void 0, function* () {
295
340
  var _a, _b, _c;
@@ -342,7 +387,7 @@ class BluefinProSdk {
342
387
  }
343
388
  createAccountDataStreamListener(handler) {
344
389
  return __awaiter(this, void 0, void 0, function* () {
345
- return new Promise((resolve, reject) => {
390
+ return new Promise((resolve) => {
346
391
  if (!this.tokenResponse) {
347
392
  throw new Error("Missing tokenResponse");
348
393
  }
@@ -362,7 +407,7 @@ class BluefinProSdk {
362
407
  }
363
408
  createMarketDataStreamListener(handler) {
364
409
  return __awaiter(this, void 0, void 0, function* () {
365
- return new Promise((resolve, reject) => {
410
+ return new Promise((resolve) => {
366
411
  const ws = new ws_1.WebSocket(this.configs[Services.MarketWebsocket].basePath);
367
412
  ws.onmessage = (event) => __awaiter(this, void 0, void 0, function* () {
368
413
  yield handler(JSON.parse(event.data));