@bluefin-exchange/pro-sdk 0.1.23 → 0.1.24
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 +2 -0
- package/dist/src/api.d.ts +112 -0
- package/dist/src/api.js +83 -3
- package/dist/src/request-signer.d.ts +6 -1
- package/dist/src/request-signer.js +28 -0
- package/dist/src/sdk.d.ts +1 -0
- package/dist/src/sdk.js +22 -0
- package/example.ts +3 -0
- package/package.json +1 -1
- package/src/api.ts +161 -1
- package/src/request-signer.ts +56 -0
- package/src/sdk.ts +26 -0
package/dist/example.js
CHANGED
|
@@ -176,6 +176,8 @@ function main() {
|
|
|
176
176
|
logger.info("Authorize account request success");
|
|
177
177
|
yield client.deauthorizeAccount(bfSigner.getAddress());
|
|
178
178
|
logger.info("Deauthorize account request success");
|
|
179
|
+
yield client.adjustIsolatedMargin(symbol, "10000000000", true);
|
|
180
|
+
logger.info("Adjust isolated margin request success");
|
|
179
181
|
// Keep connection alive
|
|
180
182
|
yield new Promise((resolve) => setTimeout(resolve, 50000));
|
|
181
183
|
}
|
package/dist/src/api.d.ts
CHANGED
|
@@ -251,6 +251,7 @@ export declare const AccountEventReason: {
|
|
|
251
251
|
readonly OrdersForMarketCancelled: "OrdersForMarketCancelled";
|
|
252
252
|
readonly LeverageUpdated: "LeverageUpdated";
|
|
253
253
|
readonly IsolatedMarginUpdated: "IsolatedMarginUpdated";
|
|
254
|
+
readonly FundingRatePayment: "FundingRatePayment";
|
|
254
255
|
};
|
|
255
256
|
export type AccountEventReason = typeof AccountEventReason[keyof typeof AccountEventReason];
|
|
256
257
|
/**
|
|
@@ -881,6 +882,84 @@ export interface ActiveOrderUpdate {
|
|
|
881
882
|
*/
|
|
882
883
|
'updatedAtMillis': number;
|
|
883
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
*
|
|
887
|
+
* @export
|
|
888
|
+
* @interface AdjustIsolatedMarginRequest
|
|
889
|
+
*/
|
|
890
|
+
export interface AdjustIsolatedMarginRequest {
|
|
891
|
+
/**
|
|
892
|
+
*
|
|
893
|
+
* @type {AdjustIsolatedMarginRequestSignedFields}
|
|
894
|
+
* @memberof AdjustIsolatedMarginRequest
|
|
895
|
+
*/
|
|
896
|
+
'signedFields': AdjustIsolatedMarginRequestSignedFields;
|
|
897
|
+
/**
|
|
898
|
+
* The signature of the request, encoded from the signedFields
|
|
899
|
+
* @type {string}
|
|
900
|
+
* @memberof AdjustIsolatedMarginRequest
|
|
901
|
+
*/
|
|
902
|
+
'signature': string;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
*
|
|
906
|
+
* @export
|
|
907
|
+
* @interface AdjustIsolatedMarginRequestSignedFields
|
|
908
|
+
*/
|
|
909
|
+
export interface AdjustIsolatedMarginRequestSignedFields {
|
|
910
|
+
/**
|
|
911
|
+
* the ID of the internal datastore for the target network
|
|
912
|
+
* @type {string}
|
|
913
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
914
|
+
*/
|
|
915
|
+
'idsId': string;
|
|
916
|
+
/**
|
|
917
|
+
* The account address of the account for which to adjust margin
|
|
918
|
+
* @type {string}
|
|
919
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
920
|
+
*/
|
|
921
|
+
'accountAddress': string;
|
|
922
|
+
/**
|
|
923
|
+
* The symbol of the isolated position for which to adjust margin
|
|
924
|
+
* @type {string}
|
|
925
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
926
|
+
*/
|
|
927
|
+
'symbol': string;
|
|
928
|
+
/**
|
|
929
|
+
*
|
|
930
|
+
* @type {AdjustMarginOperation}
|
|
931
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
932
|
+
*/
|
|
933
|
+
'operation': AdjustMarginOperation;
|
|
934
|
+
/**
|
|
935
|
+
* The quantity of margin to adjust for the isolated position
|
|
936
|
+
* @type {string}
|
|
937
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
938
|
+
*/
|
|
939
|
+
'quantityE9': string;
|
|
940
|
+
/**
|
|
941
|
+
* The random generated SALT. Should always be a number
|
|
942
|
+
* @type {string}
|
|
943
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
944
|
+
*/
|
|
945
|
+
'salt': string;
|
|
946
|
+
/**
|
|
947
|
+
* The timestamp in millis at which the request was signed
|
|
948
|
+
* @type {number}
|
|
949
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
950
|
+
*/
|
|
951
|
+
'signedAtMillis': number;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* The operation to perform on the margin
|
|
955
|
+
* @export
|
|
956
|
+
* @enum {string}
|
|
957
|
+
*/
|
|
958
|
+
export declare const AdjustMarginOperation: {
|
|
959
|
+
readonly Add: "ADD";
|
|
960
|
+
readonly Subtract: "SUBTRACT";
|
|
961
|
+
};
|
|
962
|
+
export type AdjustMarginOperation = typeof AdjustMarginOperation[keyof typeof AdjustMarginOperation];
|
|
884
963
|
/**
|
|
885
964
|
* Details about an asset in the account.
|
|
886
965
|
* @export
|
|
@@ -4164,6 +4243,14 @@ export declare const TradeApiAxiosParamCreator: (configuration?: Configuration)
|
|
|
4164
4243
|
* @throws {RequiredError}
|
|
4165
4244
|
*/
|
|
4166
4245
|
postWithdraw: (withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
4246
|
+
/**
|
|
4247
|
+
* Adjust margin for an isolated position for a symbol
|
|
4248
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
4249
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
4250
|
+
* @param {*} [options] Override http request option.
|
|
4251
|
+
* @throws {RequiredError}
|
|
4252
|
+
*/
|
|
4253
|
+
putAdjustIsolatedMargin: (adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
4167
4254
|
/**
|
|
4168
4255
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
4169
4256
|
* @summary Authorizes an account
|
|
@@ -4226,6 +4313,14 @@ export declare const TradeApiFp: (configuration?: Configuration) => {
|
|
|
4226
4313
|
* @throws {RequiredError}
|
|
4227
4314
|
*/
|
|
4228
4315
|
postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
4316
|
+
/**
|
|
4317
|
+
* Adjust margin for an isolated position for a symbol
|
|
4318
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
4319
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
4320
|
+
* @param {*} [options] Override http request option.
|
|
4321
|
+
* @throws {RequiredError}
|
|
4322
|
+
*/
|
|
4323
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
4229
4324
|
/**
|
|
4230
4325
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
4231
4326
|
* @summary Authorizes an account
|
|
@@ -4288,6 +4383,14 @@ export declare const TradeApiFactory: (configuration?: Configuration, basePath?:
|
|
|
4288
4383
|
* @throws {RequiredError}
|
|
4289
4384
|
*/
|
|
4290
4385
|
postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
4386
|
+
/**
|
|
4387
|
+
* Adjust margin for an isolated position for a symbol
|
|
4388
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
4389
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
4390
|
+
* @param {*} [options] Override http request option.
|
|
4391
|
+
* @throws {RequiredError}
|
|
4392
|
+
*/
|
|
4393
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;
|
|
4291
4394
|
/**
|
|
4292
4395
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
4293
4396
|
* @summary Authorizes an account
|
|
@@ -4356,6 +4459,15 @@ export declare class TradeApi extends BaseAPI {
|
|
|
4356
4459
|
* @memberof TradeApi
|
|
4357
4460
|
*/
|
|
4358
4461
|
postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
|
|
4462
|
+
/**
|
|
4463
|
+
* Adjust margin for an isolated position for a symbol
|
|
4464
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
4465
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
4466
|
+
* @param {*} [options] Override http request option.
|
|
4467
|
+
* @throws {RequiredError}
|
|
4468
|
+
* @memberof TradeApi
|
|
4469
|
+
*/
|
|
4470
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
|
|
4359
4471
|
/**
|
|
4360
4472
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
4361
4473
|
* @summary Authorizes an account
|
package/dist/src/api.js
CHANGED
|
@@ -22,8 +22,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
26
|
-
exports.TradeApi = void 0;
|
|
25
|
+
exports.TradeApiFp = exports.TradeApiAxiosParamCreator = exports.WebSocketMarketDataSecWebSocketVersionEnum = exports.WebSocketMarketDataUpgradeEnum = exports.WebSocketAccountDataSecWebSocketVersionEnum = exports.WebSocketAccountDataUpgradeEnum = exports.StreamsApi = exports.StreamsApiFactory = exports.StreamsApiFp = exports.StreamsApiAxiosParamCreator = exports.GetRecentTradesTradeTypeEnum = exports.ExchangeApi = exports.ExchangeApiFactory = exports.ExchangeApiFp = exports.ExchangeApiAxiosParamCreator = exports.AuthApi = exports.AuthApiFactory = exports.AuthApiFp = exports.AuthApiAxiosParamCreator = exports.AccountDataApi = exports.AccountDataApiFactory = exports.AccountDataApiFp = exports.AccountDataApiAxiosParamCreator = exports.TransactionType = exports.TradeType = exports.TradeSide = exports.SubscriptionType = exports.SelfTradePreventionType = exports.PositionSide = exports.OrderbookPartialDepthUpdateDepthLevelEnum = exports.OrderType = exports.OrderTimeInForce = exports.OrderStatus = exports.OrderSide = exports.OrderCancellationFailureReason = exports.OrderCancelReason = exports.OraclePriceUpdateSourceEnum = exports.MarketStatus = exports.MarketPriceUpdateSourceEnum = exports.MarketEventType = exports.MarketDataStreamName = exports.MarkPriceUpdateSourceEnum = exports.MarginType = exports.KlineInterval = exports.ContractsConfigNetworkEnum = exports.CandlePriceType = exports.AdjustMarginOperation = exports.AccountEventType = exports.AccountEventReason = exports.AccountDataStream = void 0;
|
|
26
|
+
exports.TradeApi = exports.TradeApiFactory = void 0;
|
|
27
27
|
const axios_1 = require("axios");
|
|
28
28
|
// Some imports not used depending on template conditions
|
|
29
29
|
// @ts-ignore
|
|
@@ -57,7 +57,8 @@ exports.AccountEventReason = {
|
|
|
57
57
|
OrderCancelled: 'OrderCancelled',
|
|
58
58
|
OrdersForMarketCancelled: 'OrdersForMarketCancelled',
|
|
59
59
|
LeverageUpdated: 'LeverageUpdated',
|
|
60
|
-
IsolatedMarginUpdated: 'IsolatedMarginUpdated'
|
|
60
|
+
IsolatedMarginUpdated: 'IsolatedMarginUpdated',
|
|
61
|
+
FundingRatePayment: 'FundingRatePayment'
|
|
61
62
|
};
|
|
62
63
|
/**
|
|
63
64
|
* The type of account-related event.
|
|
@@ -73,6 +74,15 @@ exports.AccountEventType = {
|
|
|
73
74
|
AccountTransactionUpdate: 'AccountTransactionUpdate',
|
|
74
75
|
AccountLeverageFailureUpdate: 'AccountLeverageFailureUpdate'
|
|
75
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* The operation to perform on the margin
|
|
79
|
+
* @export
|
|
80
|
+
* @enum {string}
|
|
81
|
+
*/
|
|
82
|
+
exports.AdjustMarginOperation = {
|
|
83
|
+
Add: 'ADD',
|
|
84
|
+
Subtract: 'SUBTRACT'
|
|
85
|
+
};
|
|
76
86
|
/**
|
|
77
87
|
*
|
|
78
88
|
* @export
|
|
@@ -2098,6 +2108,39 @@ const TradeApiAxiosParamCreator = function (configuration) {
|
|
|
2098
2108
|
options: localVarRequestOptions,
|
|
2099
2109
|
};
|
|
2100
2110
|
}),
|
|
2111
|
+
/**
|
|
2112
|
+
* Adjust margin for an isolated position for a symbol
|
|
2113
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
2114
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
2115
|
+
* @param {*} [options] Override http request option.
|
|
2116
|
+
* @throws {RequiredError}
|
|
2117
|
+
*/
|
|
2118
|
+
putAdjustIsolatedMargin: (adjustIsolatedMarginRequest_1, ...args_1) => __awaiter(this, [adjustIsolatedMarginRequest_1, ...args_1], void 0, function* (adjustIsolatedMarginRequest, options = {}) {
|
|
2119
|
+
// verify required parameter 'adjustIsolatedMarginRequest' is not null or undefined
|
|
2120
|
+
(0, common_1.assertParamExists)('putAdjustIsolatedMargin', 'adjustIsolatedMarginRequest', adjustIsolatedMarginRequest);
|
|
2121
|
+
const localVarPath = `/api/v1/trade/adjustIsolatedMargin`;
|
|
2122
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
2123
|
+
const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
2124
|
+
let baseOptions;
|
|
2125
|
+
if (configuration) {
|
|
2126
|
+
baseOptions = configuration.baseOptions;
|
|
2127
|
+
}
|
|
2128
|
+
const localVarRequestOptions = Object.assign(Object.assign({ method: 'PUT' }, baseOptions), options);
|
|
2129
|
+
const localVarHeaderParameter = {};
|
|
2130
|
+
const localVarQueryParameter = {};
|
|
2131
|
+
// authentication bearerAuth required
|
|
2132
|
+
// http bearer authentication required
|
|
2133
|
+
yield (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration);
|
|
2134
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
2135
|
+
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
2136
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
2137
|
+
localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
|
|
2138
|
+
localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(adjustIsolatedMarginRequest, localVarRequestOptions, configuration);
|
|
2139
|
+
return {
|
|
2140
|
+
url: (0, common_1.toPathString)(localVarUrlObj),
|
|
2141
|
+
options: localVarRequestOptions,
|
|
2142
|
+
};
|
|
2143
|
+
}),
|
|
2101
2144
|
/**
|
|
2102
2145
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
2103
2146
|
* @summary Authorizes an account
|
|
@@ -2271,6 +2314,22 @@ const TradeApiFp = function (configuration) {
|
|
|
2271
2314
|
return (axios, basePath) => (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
|
2272
2315
|
});
|
|
2273
2316
|
},
|
|
2317
|
+
/**
|
|
2318
|
+
* Adjust margin for an isolated position for a symbol
|
|
2319
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
2320
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
2321
|
+
* @param {*} [options] Override http request option.
|
|
2322
|
+
* @throws {RequiredError}
|
|
2323
|
+
*/
|
|
2324
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options) {
|
|
2325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2326
|
+
var _a, _b, _c;
|
|
2327
|
+
const localVarAxiosArgs = yield localVarAxiosParamCreator.putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options);
|
|
2328
|
+
const localVarOperationServerIndex = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.serverIndex) !== null && _a !== void 0 ? _a : 0;
|
|
2329
|
+
const localVarOperationServerBasePath = (_c = (_b = base_1.operationServerMap['TradeApi.putAdjustIsolatedMargin']) === null || _b === void 0 ? void 0 : _b[localVarOperationServerIndex]) === null || _c === void 0 ? void 0 : _c.url;
|
|
2330
|
+
return (axios, basePath) => (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
|
2331
|
+
});
|
|
2332
|
+
},
|
|
2274
2333
|
/**
|
|
2275
2334
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
2276
2335
|
* @summary Authorizes an account
|
|
@@ -2369,6 +2428,16 @@ const TradeApiFactory = function (configuration, basePath, axios) {
|
|
|
2369
2428
|
postWithdraw(withdrawRequest, options) {
|
|
2370
2429
|
return localVarFp.postWithdraw(withdrawRequest, options).then((request) => request(axios, basePath));
|
|
2371
2430
|
},
|
|
2431
|
+
/**
|
|
2432
|
+
* Adjust margin for an isolated position for a symbol
|
|
2433
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
2434
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
2435
|
+
* @param {*} [options] Override http request option.
|
|
2436
|
+
* @throws {RequiredError}
|
|
2437
|
+
*/
|
|
2438
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options) {
|
|
2439
|
+
return localVarFp.putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options).then((request) => request(axios, basePath));
|
|
2440
|
+
},
|
|
2372
2441
|
/**
|
|
2373
2442
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
2374
2443
|
* @summary Authorizes an account
|
|
@@ -2453,6 +2522,17 @@ class TradeApi extends base_1.BaseAPI {
|
|
|
2453
2522
|
postWithdraw(withdrawRequest, options) {
|
|
2454
2523
|
return (0, exports.TradeApiFp)(this.configuration).postWithdraw(withdrawRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2455
2524
|
}
|
|
2525
|
+
/**
|
|
2526
|
+
* Adjust margin for an isolated position for a symbol
|
|
2527
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
2528
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
2529
|
+
* @param {*} [options] Override http request option.
|
|
2530
|
+
* @throws {RequiredError}
|
|
2531
|
+
* @memberof TradeApi
|
|
2532
|
+
*/
|
|
2533
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options) {
|
|
2534
|
+
return (0, exports.TradeApiFp)(this.configuration).putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2535
|
+
}
|
|
2456
2536
|
/**
|
|
2457
2537
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
2458
2538
|
* @summary Authorizes an account
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Keypair, Signer } from "@mysten/sui/cryptography";
|
|
2
|
-
import { LoginRequest, AccountPositionLeverageUpdateRequestSignedFields, CreateOrderRequestSignedFields, WithdrawRequestSignedFields, AccountAuthorizationRequestSignedFields } from "./api";
|
|
2
|
+
import { LoginRequest, AccountPositionLeverageUpdateRequestSignedFields, CreateOrderRequestSignedFields, WithdrawRequestSignedFields, AccountAuthorizationRequestSignedFields, AdjustIsolatedMarginRequestSignedFields } from "./api";
|
|
3
3
|
import { DryRunTransactionBlockResponse, SuiClient, SuiTransactionBlockResponse, TransactionBlock } from "@firefly-exchange/library-sui";
|
|
4
4
|
export interface IBluefinSigner {
|
|
5
5
|
getAddress(): string;
|
|
@@ -7,6 +7,7 @@ export interface IBluefinSigner {
|
|
|
7
7
|
signOrderRequest: (fields: CreateOrderRequestSignedFields) => Promise<string>;
|
|
8
8
|
signWithdrawRequest: (fields: WithdrawRequestSignedFields) => Promise<string>;
|
|
9
9
|
signAccountAuthorizationRequest: (fields: AccountAuthorizationRequestSignedFields, isAuthorize: boolean) => Promise<string>;
|
|
10
|
+
signAdjustIsolatedMarginRequest: (fields: AdjustIsolatedMarginRequestSignedFields) => Promise<string>;
|
|
10
11
|
signLoginRequest: (request: LoginRequest) => Promise<string>;
|
|
11
12
|
executeTx: (txb: TransactionBlock, suiClient: SuiClient) => Promise<DryRunTransactionBlockResponse | SuiTransactionBlockResponse>;
|
|
12
13
|
}
|
|
@@ -38,6 +39,10 @@ export declare class BluefinRequestSigner implements IBluefinSigner {
|
|
|
38
39
|
* Sign an account authorization request
|
|
39
40
|
*/
|
|
40
41
|
signAccountAuthorizationRequest(signedFields: AccountAuthorizationRequestSignedFields, is_authorize: boolean): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Sign an isolated margin adjustment request
|
|
44
|
+
*/
|
|
45
|
+
signAdjustIsolatedMarginRequest(signedFields: AdjustIsolatedMarginRequestSignedFields): Promise<string>;
|
|
41
46
|
executeTx(txb: TransactionBlock, suiClient: SuiClient): Promise<DryRunTransactionBlockResponse | SuiTransactionBlockResponse>;
|
|
42
47
|
/**
|
|
43
48
|
* Get the wallet's address
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BluefinRequestSigner = void 0;
|
|
13
13
|
exports.makeSigner = makeSigner;
|
|
14
14
|
const cryptography_1 = require("@mysten/sui/cryptography");
|
|
15
|
+
const api_1 = require("./api");
|
|
15
16
|
const library_sui_1 = require("@firefly-exchange/library-sui");
|
|
16
17
|
function makeSigner(keyPair, isUIWallet) {
|
|
17
18
|
return Object.assign(keyPair, {
|
|
@@ -27,6 +28,7 @@ var ClientPayloadType;
|
|
|
27
28
|
ClientPayloadType["OrderRequest"] = "Bluefin Pro Order";
|
|
28
29
|
ClientPayloadType["LeverageAdjustment"] = "Bluefin Pro Leverage Adjustment";
|
|
29
30
|
ClientPayloadType["AuthorizeAccount"] = "Bluefin Pro Authorize Account";
|
|
31
|
+
ClientPayloadType["AdjustIsolatedMargin"] = "Bluefin Pro Margin Adjustment";
|
|
30
32
|
})(ClientPayloadType || (ClientPayloadType = {}));
|
|
31
33
|
var PositionType;
|
|
32
34
|
(function (PositionType) {
|
|
@@ -94,6 +96,18 @@ function toUIDeAuthorizeAccountRequest(val) {
|
|
|
94
96
|
signedAt: val.signedAtMillis.toString(),
|
|
95
97
|
};
|
|
96
98
|
}
|
|
99
|
+
function toUIAdjustIsolatedMarginRequest(val) {
|
|
100
|
+
return {
|
|
101
|
+
type: ClientPayloadType.AdjustIsolatedMargin,
|
|
102
|
+
ids: val.idsId,
|
|
103
|
+
account: val.accountAddress,
|
|
104
|
+
market: val.symbol,
|
|
105
|
+
add: val.operation === api_1.AdjustMarginOperation.Add,
|
|
106
|
+
amount: val.quantityE9,
|
|
107
|
+
salt: val.salt,
|
|
108
|
+
signedAt: val.signedAtMillis.toString(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
97
111
|
// ---------- Utils ----------
|
|
98
112
|
function toJson(val) {
|
|
99
113
|
return JSON.stringify(val, null, 2);
|
|
@@ -171,6 +185,20 @@ class BluefinRequestSigner {
|
|
|
171
185
|
return signedMessageSerialized.signature;
|
|
172
186
|
});
|
|
173
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Sign an isolated margin adjustment request
|
|
190
|
+
*/
|
|
191
|
+
signAdjustIsolatedMarginRequest(signedFields) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const requestJson = toJson(toUIAdjustIsolatedMarginRequest(signedFields));
|
|
194
|
+
const signedMessageSerialized = yield this.wallet.signPersonalMessage(new TextEncoder().encode(requestJson));
|
|
195
|
+
const parsedSignature = (0, cryptography_1.parseSerializedSignature)(signedMessageSerialized.signature);
|
|
196
|
+
if (parsedSignature.signatureScheme == "MultiSig") {
|
|
197
|
+
throw new Error("MultiSig not supported");
|
|
198
|
+
}
|
|
199
|
+
return signedMessageSerialized.signature;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
174
202
|
executeTx(txb, suiClient) {
|
|
175
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
204
|
return library_sui_1.SuiBlocks.execCall(txb, suiClient, this.wallet, false, this.wallet.isUIWallet());
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare class BluefinProSdk {
|
|
|
61
61
|
withdraw(assetSymbol: string, amountE9: string): Promise<void>;
|
|
62
62
|
authorizeAccount(accountAddress: string): Promise<void>;
|
|
63
63
|
deauthorizeAccount(accountAddress: string): Promise<void>;
|
|
64
|
+
adjustIsolatedMargin(symbol: string, amountE9: string, add: boolean): Promise<void>;
|
|
64
65
|
deposit(amountE9: string, accountAddress?: string): Promise<import("@firefly-exchange/library-sui").DryRunTransactionBlockResponse | import("@firefly-exchange/library-sui").SuiTransactionBlockResponse>;
|
|
65
66
|
private setAccessToken;
|
|
66
67
|
refreshToken(): Promise<void>;
|
package/dist/src/sdk.js
CHANGED
|
@@ -330,6 +330,28 @@ class BluefinProSdk {
|
|
|
330
330
|
console.log("Deauthorize account request sent:", signedFields);
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
|
+
adjustIsolatedMargin(symbol, amountE9, add) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
+
if (!this.contractsConfig) {
|
|
336
|
+
throw new Error("Missing contractsConfig");
|
|
337
|
+
}
|
|
338
|
+
const signedFields = {
|
|
339
|
+
symbol,
|
|
340
|
+
idsId: this.contractsConfig.idsId,
|
|
341
|
+
accountAddress: this.currentAccountAddress,
|
|
342
|
+
operation: add ? api_1.AdjustMarginOperation.Add : api_1.AdjustMarginOperation.Subtract,
|
|
343
|
+
quantityE9: amountE9,
|
|
344
|
+
salt: this.generateSalt(),
|
|
345
|
+
signedAtMillis: Date.now(),
|
|
346
|
+
};
|
|
347
|
+
const signature = yield this.bfSigner.signAdjustIsolatedMarginRequest(signedFields);
|
|
348
|
+
yield this.tradeApi.putAdjustIsolatedMargin({
|
|
349
|
+
signedFields,
|
|
350
|
+
signature,
|
|
351
|
+
});
|
|
352
|
+
console.log("Adjust isolated margin request sent:", signedFields);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
333
355
|
deposit(amountE9, accountAddress) {
|
|
334
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
335
357
|
var _a, _b, _c;
|
package/example.ts
CHANGED
|
@@ -263,6 +263,9 @@ async function main() {
|
|
|
263
263
|
await client.deauthorizeAccount(bfSigner.getAddress());
|
|
264
264
|
logger.info("Deauthorize account request success");
|
|
265
265
|
|
|
266
|
+
await client.adjustIsolatedMargin(symbol, "10000000000", true);
|
|
267
|
+
logger.info("Adjust isolated margin request success");
|
|
268
|
+
|
|
266
269
|
// Keep connection alive
|
|
267
270
|
await new Promise((resolve) => setTimeout(resolve, 50000));
|
|
268
271
|
} finally {
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -265,7 +265,8 @@ export const AccountEventReason = {
|
|
|
265
265
|
OrderCancelled: 'OrderCancelled',
|
|
266
266
|
OrdersForMarketCancelled: 'OrdersForMarketCancelled',
|
|
267
267
|
LeverageUpdated: 'LeverageUpdated',
|
|
268
|
-
IsolatedMarginUpdated: 'IsolatedMarginUpdated'
|
|
268
|
+
IsolatedMarginUpdated: 'IsolatedMarginUpdated',
|
|
269
|
+
FundingRatePayment: 'FundingRatePayment'
|
|
269
270
|
} as const;
|
|
270
271
|
|
|
271
272
|
export type AccountEventReason = typeof AccountEventReason[keyof typeof AccountEventReason];
|
|
@@ -919,6 +920,90 @@ export interface ActiveOrderUpdate {
|
|
|
919
920
|
}
|
|
920
921
|
|
|
921
922
|
|
|
923
|
+
/**
|
|
924
|
+
*
|
|
925
|
+
* @export
|
|
926
|
+
* @interface AdjustIsolatedMarginRequest
|
|
927
|
+
*/
|
|
928
|
+
export interface AdjustIsolatedMarginRequest {
|
|
929
|
+
/**
|
|
930
|
+
*
|
|
931
|
+
* @type {AdjustIsolatedMarginRequestSignedFields}
|
|
932
|
+
* @memberof AdjustIsolatedMarginRequest
|
|
933
|
+
*/
|
|
934
|
+
'signedFields': AdjustIsolatedMarginRequestSignedFields;
|
|
935
|
+
/**
|
|
936
|
+
* The signature of the request, encoded from the signedFields
|
|
937
|
+
* @type {string}
|
|
938
|
+
* @memberof AdjustIsolatedMarginRequest
|
|
939
|
+
*/
|
|
940
|
+
'signature': string;
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
*
|
|
944
|
+
* @export
|
|
945
|
+
* @interface AdjustIsolatedMarginRequestSignedFields
|
|
946
|
+
*/
|
|
947
|
+
export interface AdjustIsolatedMarginRequestSignedFields {
|
|
948
|
+
/**
|
|
949
|
+
* the ID of the internal datastore for the target network
|
|
950
|
+
* @type {string}
|
|
951
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
952
|
+
*/
|
|
953
|
+
'idsId': string;
|
|
954
|
+
/**
|
|
955
|
+
* The account address of the account for which to adjust margin
|
|
956
|
+
* @type {string}
|
|
957
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
958
|
+
*/
|
|
959
|
+
'accountAddress': string;
|
|
960
|
+
/**
|
|
961
|
+
* The symbol of the isolated position for which to adjust margin
|
|
962
|
+
* @type {string}
|
|
963
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
964
|
+
*/
|
|
965
|
+
'symbol': string;
|
|
966
|
+
/**
|
|
967
|
+
*
|
|
968
|
+
* @type {AdjustMarginOperation}
|
|
969
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
970
|
+
*/
|
|
971
|
+
'operation': AdjustMarginOperation;
|
|
972
|
+
/**
|
|
973
|
+
* The quantity of margin to adjust for the isolated position
|
|
974
|
+
* @type {string}
|
|
975
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
976
|
+
*/
|
|
977
|
+
'quantityE9': string;
|
|
978
|
+
/**
|
|
979
|
+
* The random generated SALT. Should always be a number
|
|
980
|
+
* @type {string}
|
|
981
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
982
|
+
*/
|
|
983
|
+
'salt': string;
|
|
984
|
+
/**
|
|
985
|
+
* The timestamp in millis at which the request was signed
|
|
986
|
+
* @type {number}
|
|
987
|
+
* @memberof AdjustIsolatedMarginRequestSignedFields
|
|
988
|
+
*/
|
|
989
|
+
'signedAtMillis': number;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* The operation to perform on the margin
|
|
995
|
+
* @export
|
|
996
|
+
* @enum {string}
|
|
997
|
+
*/
|
|
998
|
+
|
|
999
|
+
export const AdjustMarginOperation = {
|
|
1000
|
+
Add: 'ADD',
|
|
1001
|
+
Subtract: 'SUBTRACT'
|
|
1002
|
+
} as const;
|
|
1003
|
+
|
|
1004
|
+
export type AdjustMarginOperation = typeof AdjustMarginOperation[keyof typeof AdjustMarginOperation];
|
|
1005
|
+
|
|
1006
|
+
|
|
922
1007
|
/**
|
|
923
1008
|
* Details about an asset in the account.
|
|
924
1009
|
* @export
|
|
@@ -5288,6 +5373,46 @@ export const TradeApiAxiosParamCreator = function (configuration?: Configuration
|
|
|
5288
5373
|
options: localVarRequestOptions,
|
|
5289
5374
|
};
|
|
5290
5375
|
},
|
|
5376
|
+
/**
|
|
5377
|
+
* Adjust margin for an isolated position for a symbol
|
|
5378
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
5379
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
5380
|
+
* @param {*} [options] Override http request option.
|
|
5381
|
+
* @throws {RequiredError}
|
|
5382
|
+
*/
|
|
5383
|
+
putAdjustIsolatedMargin: async (adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
5384
|
+
// verify required parameter 'adjustIsolatedMarginRequest' is not null or undefined
|
|
5385
|
+
assertParamExists('putAdjustIsolatedMargin', 'adjustIsolatedMarginRequest', adjustIsolatedMarginRequest)
|
|
5386
|
+
const localVarPath = `/api/v1/trade/adjustIsolatedMargin`;
|
|
5387
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
5388
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
5389
|
+
let baseOptions;
|
|
5390
|
+
if (configuration) {
|
|
5391
|
+
baseOptions = configuration.baseOptions;
|
|
5392
|
+
}
|
|
5393
|
+
|
|
5394
|
+
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
|
|
5395
|
+
const localVarHeaderParameter = {} as any;
|
|
5396
|
+
const localVarQueryParameter = {} as any;
|
|
5397
|
+
|
|
5398
|
+
// authentication bearerAuth required
|
|
5399
|
+
// http bearer authentication required
|
|
5400
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
|
5401
|
+
|
|
5402
|
+
|
|
5403
|
+
|
|
5404
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
5405
|
+
|
|
5406
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
5407
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
5408
|
+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
|
5409
|
+
localVarRequestOptions.data = serializeDataIfNeeded(adjustIsolatedMarginRequest, localVarRequestOptions, configuration)
|
|
5410
|
+
|
|
5411
|
+
return {
|
|
5412
|
+
url: toPathString(localVarUrlObj),
|
|
5413
|
+
options: localVarRequestOptions,
|
|
5414
|
+
};
|
|
5415
|
+
},
|
|
5291
5416
|
/**
|
|
5292
5417
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
5293
5418
|
* @summary Authorizes an account
|
|
@@ -5470,6 +5595,19 @@ export const TradeApiFp = function(configuration?: Configuration) {
|
|
|
5470
5595
|
const localVarOperationServerBasePath = operationServerMap['TradeApi.postWithdraw']?.[localVarOperationServerIndex]?.url;
|
|
5471
5596
|
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
|
5472
5597
|
},
|
|
5598
|
+
/**
|
|
5599
|
+
* Adjust margin for an isolated position for a symbol
|
|
5600
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
5601
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
5602
|
+
* @param {*} [options] Override http request option.
|
|
5603
|
+
* @throws {RequiredError}
|
|
5604
|
+
*/
|
|
5605
|
+
async putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
|
5606
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options);
|
|
5607
|
+
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
5608
|
+
const localVarOperationServerBasePath = operationServerMap['TradeApi.putAdjustIsolatedMargin']?.[localVarOperationServerIndex]?.url;
|
|
5609
|
+
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
|
5610
|
+
},
|
|
5473
5611
|
/**
|
|
5474
5612
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
5475
5613
|
* @summary Authorizes an account
|
|
@@ -5559,6 +5697,16 @@ export const TradeApiFactory = function (configuration?: Configuration, basePath
|
|
|
5559
5697
|
postWithdraw(withdrawRequest: WithdrawRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
|
|
5560
5698
|
return localVarFp.postWithdraw(withdrawRequest, options).then((request) => request(axios, basePath));
|
|
5561
5699
|
},
|
|
5700
|
+
/**
|
|
5701
|
+
* Adjust margin for an isolated position for a symbol
|
|
5702
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
5703
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
5704
|
+
* @param {*} [options] Override http request option.
|
|
5705
|
+
* @throws {RequiredError}
|
|
5706
|
+
*/
|
|
5707
|
+
putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
|
|
5708
|
+
return localVarFp.putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options).then((request) => request(axios, basePath));
|
|
5709
|
+
},
|
|
5562
5710
|
/**
|
|
5563
5711
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
5564
5712
|
* @summary Authorizes an account
|
|
@@ -5647,6 +5795,18 @@ export class TradeApi extends BaseAPI {
|
|
|
5647
5795
|
return TradeApiFp(this.configuration).postWithdraw(withdrawRequest, options).then((request) => request(this.axios, this.basePath));
|
|
5648
5796
|
}
|
|
5649
5797
|
|
|
5798
|
+
/**
|
|
5799
|
+
* Adjust margin for an isolated position for a symbol
|
|
5800
|
+
* @summary Adjust margin for an isolated position for a symbol
|
|
5801
|
+
* @param {AdjustIsolatedMarginRequest} adjustIsolatedMarginRequest
|
|
5802
|
+
* @param {*} [options] Override http request option.
|
|
5803
|
+
* @throws {RequiredError}
|
|
5804
|
+
* @memberof TradeApi
|
|
5805
|
+
*/
|
|
5806
|
+
public putAdjustIsolatedMargin(adjustIsolatedMarginRequest: AdjustIsolatedMarginRequest, options?: RawAxiosRequestConfig) {
|
|
5807
|
+
return TradeApiFp(this.configuration).putAdjustIsolatedMargin(adjustIsolatedMarginRequest, options).then((request) => request(this.axios, this.basePath));
|
|
5808
|
+
}
|
|
5809
|
+
|
|
5650
5810
|
/**
|
|
5651
5811
|
* Authorizes an account to trade, perform liquidations and more, on behalf of another account
|
|
5652
5812
|
* @summary Authorizes an account
|
package/src/request-signer.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
CreateOrderRequestSignedFields,
|
|
10
10
|
WithdrawRequestSignedFields,
|
|
11
11
|
AccountAuthorizationRequestSignedFields,
|
|
12
|
+
AdjustMarginOperation,
|
|
13
|
+
AdjustIsolatedMarginRequestSignedFields,
|
|
12
14
|
} from "./api";
|
|
13
15
|
import {
|
|
14
16
|
DryRunTransactionBlockResponse,
|
|
@@ -26,6 +28,7 @@ export interface IBluefinSigner {
|
|
|
26
28
|
signOrderRequest: (fields: CreateOrderRequestSignedFields) => Promise<string>;
|
|
27
29
|
signWithdrawRequest: (fields: WithdrawRequestSignedFields) => Promise<string>;
|
|
28
30
|
signAccountAuthorizationRequest: (fields: AccountAuthorizationRequestSignedFields, isAuthorize: boolean) => Promise<string>;
|
|
31
|
+
signAdjustIsolatedMarginRequest: (fields: AdjustIsolatedMarginRequestSignedFields) => Promise<string>;
|
|
29
32
|
signLoginRequest: (request: LoginRequest) => Promise<string>;
|
|
30
33
|
executeTx: (
|
|
31
34
|
txb: TransactionBlock,
|
|
@@ -57,6 +60,7 @@ enum ClientPayloadType {
|
|
|
57
60
|
OrderRequest = "Bluefin Pro Order",
|
|
58
61
|
LeverageAdjustment = "Bluefin Pro Leverage Adjustment",
|
|
59
62
|
AuthorizeAccount = "Bluefin Pro Authorize Account",
|
|
63
|
+
AdjustIsolatedMargin = "Bluefin Pro Margin Adjustment",
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
enum PositionType {
|
|
@@ -120,6 +124,17 @@ interface UIDeAuthorizeAccountRequest {
|
|
|
120
124
|
signedAt: string;
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
interface UIAdjustIsolatedMarginRequest {
|
|
128
|
+
type: string;
|
|
129
|
+
ids: string;
|
|
130
|
+
account: string;
|
|
131
|
+
market: string;
|
|
132
|
+
add: boolean;
|
|
133
|
+
amount: string;
|
|
134
|
+
salt: string;
|
|
135
|
+
signedAt: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
// Conversion functions
|
|
124
139
|
function toUIWithdrawRequest(
|
|
125
140
|
val: WithdrawRequestSignedFields
|
|
@@ -196,6 +211,21 @@ function toUIDeAuthorizeAccountRequest(
|
|
|
196
211
|
};
|
|
197
212
|
}
|
|
198
213
|
|
|
214
|
+
function toUIAdjustIsolatedMarginRequest(
|
|
215
|
+
val: AdjustIsolatedMarginRequestSignedFields
|
|
216
|
+
): UIAdjustIsolatedMarginRequest {
|
|
217
|
+
return {
|
|
218
|
+
type: ClientPayloadType.AdjustIsolatedMargin,
|
|
219
|
+
ids: val.idsId,
|
|
220
|
+
account: val.accountAddress,
|
|
221
|
+
market: val.symbol,
|
|
222
|
+
add: val.operation === AdjustMarginOperation.Add,
|
|
223
|
+
amount: val.quantityE9,
|
|
224
|
+
salt: val.salt,
|
|
225
|
+
signedAt: val.signedAtMillis.toString(),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
199
229
|
// ---------- Utils ----------
|
|
200
230
|
|
|
201
231
|
function toJson(
|
|
@@ -205,6 +235,7 @@ function toJson(
|
|
|
205
235
|
| UIWithdrawRequest
|
|
206
236
|
| UIAuthorizeAccountRequest
|
|
207
237
|
| UIDeAuthorizeAccountRequest
|
|
238
|
+
| UIAdjustIsolatedMarginRequest
|
|
208
239
|
): string {
|
|
209
240
|
return JSON.stringify(val, null, 2);
|
|
210
241
|
}
|
|
@@ -329,6 +360,31 @@ export class BluefinRequestSigner implements IBluefinSigner {
|
|
|
329
360
|
return signedMessageSerialized.signature;
|
|
330
361
|
}
|
|
331
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Sign an isolated margin adjustment request
|
|
365
|
+
*/
|
|
366
|
+
async signAdjustIsolatedMarginRequest(
|
|
367
|
+
signedFields: AdjustIsolatedMarginRequestSignedFields
|
|
368
|
+
): Promise<string> {
|
|
369
|
+
const requestJson = toJson(
|
|
370
|
+
toUIAdjustIsolatedMarginRequest(signedFields)
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const signedMessageSerialized = await this.wallet.signPersonalMessage(
|
|
374
|
+
new TextEncoder().encode(requestJson)
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const parsedSignature = parseSerializedSignature(
|
|
378
|
+
signedMessageSerialized.signature
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
if (parsedSignature.signatureScheme == "MultiSig") {
|
|
382
|
+
throw new Error("MultiSig not supported");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return signedMessageSerialized.signature;
|
|
386
|
+
}
|
|
387
|
+
|
|
332
388
|
async executeTx(txb: TransactionBlock, suiClient: SuiClient) {
|
|
333
389
|
return SuiBlocks.execCall(txb, suiClient, this.wallet, false, this.wallet.isUIWallet());
|
|
334
390
|
}
|
package/src/sdk.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
ContractsConfig,
|
|
20
20
|
AssetConfig,
|
|
21
21
|
AccountAuthorizationRequestSignedFields,
|
|
22
|
+
AdjustIsolatedMarginRequestSignedFields,
|
|
23
|
+
AdjustMarginOperation,
|
|
22
24
|
} from "./api";
|
|
23
25
|
|
|
24
26
|
import { Configuration } from "./configuration";
|
|
@@ -431,6 +433,30 @@ export class BluefinProSdk {
|
|
|
431
433
|
console.log("Deauthorize account request sent:", signedFields);
|
|
432
434
|
}
|
|
433
435
|
|
|
436
|
+
public async adjustIsolatedMargin(symbol: string, amountE9: string, add: boolean) {
|
|
437
|
+
if (!this.contractsConfig) {
|
|
438
|
+
throw new Error("Missing contractsConfig");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const signedFields: AdjustIsolatedMarginRequestSignedFields = {
|
|
442
|
+
symbol,
|
|
443
|
+
idsId: this.contractsConfig.idsId,
|
|
444
|
+
accountAddress: this.currentAccountAddress!,
|
|
445
|
+
operation: add ? AdjustMarginOperation.Add : AdjustMarginOperation.Subtract,
|
|
446
|
+
quantityE9: amountE9,
|
|
447
|
+
salt: this.generateSalt(),
|
|
448
|
+
signedAtMillis: Date.now(),
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const signature = await this.bfSigner.signAdjustIsolatedMarginRequest(signedFields);
|
|
452
|
+
|
|
453
|
+
await this.tradeApi.putAdjustIsolatedMargin({
|
|
454
|
+
signedFields,
|
|
455
|
+
signature,
|
|
456
|
+
});
|
|
457
|
+
console.log("Adjust isolated margin request sent:", signedFields);
|
|
458
|
+
}
|
|
459
|
+
|
|
434
460
|
public async deposit(amountE9: string, accountAddress?: string) {
|
|
435
461
|
const assetSymbol = "USDC";
|
|
436
462
|
const txb = new TransactionBlock();
|