@bluefin-exchange/pro-sdk 0.1.56 → 0.1.57

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
@@ -88,6 +88,19 @@ function main() {
88
88
  const otherBfSigner = new index_1.BluefinRequestSigner((0, index_1.makeSigner)(otherSuiWallet, false));
89
89
  const client = new index_1.BluefinProSdk(bfSigner, "testnet", new library_sui_1.SuiClient({ url: "https://fullnode.testnet.sui.io:443" }));
90
90
  yield client.initialize();
91
+ // Example: Creating SDK with custom time offset
92
+ // const customTime = Date.now() + 5000; // 5 seconds in the future
93
+ // const clientWithTimeOffset = new BluefinProSdk(
94
+ // bfSigner,
95
+ // "testnet",
96
+ // new SuiClient({ url: "https://fullnode.testnet.sui.io:443" }),
97
+ // { currentTimeMs: customTime }
98
+ // );
99
+ // await clientWithTimeOffset.initialize();
100
+ //
101
+ // Later, you can update the time offset:
102
+ // const newCustomTime = Date.now() + 10000; // 10 seconds in the future
103
+ // clientWithTimeOffset.updateCurrentTimeMs(newCustomTime);
91
104
  try {
92
105
  // Disable for now as the account does not have enough coins
93
106
  // await client.deposit((0.03*1e9).toString());
package/dist/src/sdk.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface BluefinProSdkOptions {
24
24
  refreshToken?: string;
25
25
  refreshTokenValidForSeconds?: number;
26
26
  disableLoginPromptOnLogout?: boolean;
27
+ currentTimeMs?: number;
27
28
  onLogout?: () => void;
28
29
  onAccessTokenUpdate?: (accessToken: string) => void;
29
30
  authHost?: string;
@@ -64,6 +65,7 @@ export declare class BluefinProSdk {
64
65
  private visibilityChangeHandler?;
65
66
  private onlineHandler?;
66
67
  private offlineHandler?;
68
+ private timeOffsetMs;
67
69
  constructor(bfSigner: IBluefinSigner, environment: "mainnet" | "testnet" | "devnet" | undefined, suiClient: SuiClient, opts?: BluefinProSdkOptions);
68
70
  createWallet(): {
69
71
  privateKey: string;
@@ -71,6 +73,8 @@ export declare class BluefinProSdk {
71
73
  };
72
74
  getTokenResponse(): LoginResponse | null;
73
75
  private generateSalt;
76
+ private getCurrentTimeMs;
77
+ updateCurrentTimeMs(currentTimeMs: number): void;
74
78
  private isRefreshTokenValid;
75
79
  private isAccessTokenExpired;
76
80
  private initializeTxBuilder;
package/dist/src/sdk.js CHANGED
@@ -70,6 +70,13 @@ class BluefinProSdk {
70
70
  this.visibilityChangeHandler = undefined;
71
71
  this.onlineHandler = undefined;
72
72
  this.offlineHandler = undefined;
73
+ // Initialize time offset based on provided currentTimeMs
74
+ if ((opts === null || opts === void 0 ? void 0 : opts.currentTimeMs) !== undefined) {
75
+ this.timeOffsetMs = opts.currentTimeMs - Date.now();
76
+ }
77
+ else {
78
+ this.timeOffsetMs = 0;
79
+ }
73
80
  if ((opts === null || opts === void 0 ? void 0 : opts.refreshToken) && (opts === null || opts === void 0 ? void 0 : opts.refreshTokenValidForSeconds)) {
74
81
  this.tokenResponse = {
75
82
  accessToken: '',
@@ -138,6 +145,12 @@ class BluefinProSdk {
138
145
  generateSalt() {
139
146
  return (Date.now() + Math.floor(Math.random() * 1000000)).toString();
140
147
  }
148
+ getCurrentTimeMs() {
149
+ return Date.now() + this.timeOffsetMs;
150
+ }
151
+ updateCurrentTimeMs(currentTimeMs) {
152
+ this.timeOffsetMs = currentTimeMs - Date.now();
153
+ }
141
154
  isRefreshTokenValid() {
142
155
  var _a;
143
156
  if (!((_a = this.tokenResponse) === null || _a === void 0 ? void 0 : _a.refreshToken) || !this.tokenSetAtSeconds) {
@@ -320,7 +333,7 @@ class BluefinProSdk {
320
333
  try {
321
334
  const loginRequest = {
322
335
  accountAddress: this.currentAccountAddress,
323
- signedAtMillis: Date.now(),
336
+ signedAtMillis: this.getCurrentTimeMs(),
324
337
  audience: 'api',
325
338
  };
326
339
  const signature = yield this.bfSigner.signLoginRequest(loginRequest);
@@ -367,7 +380,7 @@ class BluefinProSdk {
367
380
  symbol: symbol,
368
381
  leverageE9: leverageE9,
369
382
  salt: this.generateSalt(),
370
- signedAtMillis: Date.now(),
383
+ signedAtMillis: this.getCurrentTimeMs(),
371
384
  };
372
385
  const request = yield this.bfSigner.signLeverageUpdateRequest(signedFields);
373
386
  return yield this.tradeApi.putLeverageUpdate({
@@ -393,7 +406,7 @@ class BluefinProSdk {
393
406
  isIsolated: params.isIsolated,
394
407
  salt: this.generateSalt(),
395
408
  expiresAtMillis: params.expiresAtMillis,
396
- signedAtMillis: Date.now(),
409
+ signedAtMillis: this.getCurrentTimeMs(),
397
410
  };
398
411
  const signature = yield this.bfSigner.signOrderRequest(signedFields);
399
412
  const createOrderRequest = {
@@ -437,7 +450,7 @@ class BluefinProSdk {
437
450
  accountAddress: this.currentAccountAddress,
438
451
  amountE9,
439
452
  salt: this.generateSalt(),
440
- signedAtMillis: Date.now(),
453
+ signedAtMillis: this.getCurrentTimeMs(),
441
454
  };
442
455
  const signature = yield this.bfSigner.signWithdrawRequest(signedFields);
443
456
  yield this.tradeApi.postWithdraw({
@@ -457,7 +470,7 @@ class BluefinProSdk {
457
470
  idsId: this.contractsConfig.idsId,
458
471
  authorizedAccountAddress: accountAddress,
459
472
  salt: this.generateSalt(),
460
- signedAtMillis: Date.now(),
473
+ signedAtMillis: this.getCurrentTimeMs(),
461
474
  };
462
475
  const signature = yield this.bfSigner.signAccountAuthorizationRequest(signedFields, true);
463
476
  yield this.tradeApi.putAuthorizeAccount({
@@ -478,7 +491,7 @@ class BluefinProSdk {
478
491
  idsId: this.contractsConfig.idsId,
479
492
  authorizedAccountAddress: accountAddress,
480
493
  salt: this.generateSalt(),
481
- signedAtMillis: Date.now(),
494
+ signedAtMillis: this.getCurrentTimeMs(),
482
495
  };
483
496
  const signature = yield this.bfSigner.signAccountAuthorizationRequest(signedFields, false);
484
497
  yield this.tradeApi.putDeauthorizeAccount({
@@ -502,7 +515,7 @@ class BluefinProSdk {
502
515
  : api_1.AdjustMarginOperation.Subtract,
503
516
  quantityE9: amountE9,
504
517
  salt: this.generateSalt(),
505
- signedAtMillis: Date.now(),
518
+ signedAtMillis: this.getCurrentTimeMs(),
506
519
  };
507
520
  const signature = yield this.bfSigner.signAdjustIsolatedMarginRequest(signedFields);
508
521
  yield this.tradeApi.putAdjustIsolatedMargin({
package/example.ts CHANGED
@@ -115,6 +115,20 @@ async function main() {
115
115
  );
116
116
  await client.initialize();
117
117
 
118
+ // Example: Creating SDK with custom time offset
119
+ // const customTime = Date.now() + 5000; // 5 seconds in the future
120
+ // const clientWithTimeOffset = new BluefinProSdk(
121
+ // bfSigner,
122
+ // "testnet",
123
+ // new SuiClient({ url: "https://fullnode.testnet.sui.io:443" }),
124
+ // { currentTimeMs: customTime }
125
+ // );
126
+ // await clientWithTimeOffset.initialize();
127
+ //
128
+ // Later, you can update the time offset:
129
+ // const newCustomTime = Date.now() + 10000; // 10 seconds in the future
130
+ // clientWithTimeOffset.updateCurrentTimeMs(newCustomTime);
131
+
118
132
  try {
119
133
  // Disable for now as the account does not have enough coins
120
134
  // await client.deposit((0.03*1e9).toString());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluefin-exchange/pro-sdk",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "description": "OpenAPI client for @bluefin-exchange/pro-sdk",
5
5
  "author": "Bluefin",
6
6
  "repository": {
package/src/sdk.ts CHANGED
@@ -105,6 +105,7 @@ export interface BluefinProSdkOptions {
105
105
  refreshToken?: string;
106
106
  refreshTokenValidForSeconds?: number;
107
107
  disableLoginPromptOnLogout?: boolean;
108
+ currentTimeMs?: number;
108
109
  onLogout?: () => void;
109
110
  onAccessTokenUpdate?: (accessToken: string) => void;
110
111
 
@@ -146,6 +147,7 @@ export class BluefinProSdk {
146
147
  private visibilityChangeHandler?: () => void;
147
148
  private onlineHandler?: () => void;
148
149
  private offlineHandler?: () => void;
150
+ private timeOffsetMs: number;
149
151
 
150
152
  constructor(
151
153
  private readonly bfSigner: IBluefinSigner,
@@ -167,6 +169,13 @@ export class BluefinProSdk {
167
169
  this.visibilityChangeHandler = undefined;
168
170
  this.onlineHandler = undefined;
169
171
  this.offlineHandler = undefined;
172
+
173
+ // Initialize time offset based on provided currentTimeMs
174
+ if (opts?.currentTimeMs !== undefined) {
175
+ this.timeOffsetMs = opts.currentTimeMs - Date.now();
176
+ } else {
177
+ this.timeOffsetMs = 0;
178
+ }
170
179
 
171
180
  if (opts?.refreshToken && opts?.refreshTokenValidForSeconds) {
172
181
  this.tokenResponse = {
@@ -251,6 +260,14 @@ export class BluefinProSdk {
251
260
  return (Date.now() + Math.floor(Math.random() * 1000000)).toString();
252
261
  }
253
262
 
263
+ private getCurrentTimeMs(): number {
264
+ return Date.now() + this.timeOffsetMs;
265
+ }
266
+
267
+ public updateCurrentTimeMs(currentTimeMs: number): void {
268
+ this.timeOffsetMs = currentTimeMs - Date.now();
269
+ }
270
+
254
271
  private isRefreshTokenValid(): boolean {
255
272
  if (!this.tokenResponse?.refreshToken || !this.tokenSetAtSeconds) {
256
273
  return false;
@@ -469,7 +486,7 @@ export class BluefinProSdk {
469
486
  try {
470
487
  const loginRequest: LoginRequest = {
471
488
  accountAddress: this.currentAccountAddress,
472
- signedAtMillis: Date.now(),
489
+ signedAtMillis: this.getCurrentTimeMs(),
473
490
  audience: 'api',
474
491
  };
475
492
 
@@ -524,7 +541,7 @@ export class BluefinProSdk {
524
541
  symbol: symbol,
525
542
  leverageE9: leverageE9,
526
543
  salt: this.generateSalt(),
527
- signedAtMillis: Date.now(),
544
+ signedAtMillis: this.getCurrentTimeMs(),
528
545
  };
529
546
 
530
547
  const request = await this.bfSigner.signLeverageUpdateRequest(signedFields);
@@ -551,7 +568,7 @@ export class BluefinProSdk {
551
568
  isIsolated: params.isIsolated,
552
569
  salt: this.generateSalt(),
553
570
  expiresAtMillis: params.expiresAtMillis,
554
- signedAtMillis: Date.now(),
571
+ signedAtMillis: this.getCurrentTimeMs(),
555
572
  };
556
573
 
557
574
  const signature = await this.bfSigner.signOrderRequest(signedFields);
@@ -599,7 +616,7 @@ export class BluefinProSdk {
599
616
  accountAddress: this.currentAccountAddress!,
600
617
  amountE9,
601
618
  salt: this.generateSalt(),
602
- signedAtMillis: Date.now(),
619
+ signedAtMillis: this.getCurrentTimeMs(),
603
620
  };
604
621
 
605
622
  const signature = await this.bfSigner.signWithdrawRequest(signedFields);
@@ -621,7 +638,7 @@ export class BluefinProSdk {
621
638
  idsId: this.contractsConfig.idsId,
622
639
  authorizedAccountAddress: accountAddress,
623
640
  salt: this.generateSalt(),
624
- signedAtMillis: Date.now(),
641
+ signedAtMillis: this.getCurrentTimeMs(),
625
642
  };
626
643
 
627
644
  const signature = await this.bfSigner.signAccountAuthorizationRequest(
@@ -647,7 +664,7 @@ export class BluefinProSdk {
647
664
  idsId: this.contractsConfig.idsId,
648
665
  authorizedAccountAddress: accountAddress,
649
666
  salt: this.generateSalt(),
650
- signedAtMillis: Date.now(),
667
+ signedAtMillis: this.getCurrentTimeMs(),
651
668
  };
652
669
 
653
670
  const signature = await this.bfSigner.signAccountAuthorizationRequest(
@@ -680,7 +697,7 @@ export class BluefinProSdk {
680
697
  : AdjustMarginOperation.Subtract,
681
698
  quantityE9: amountE9,
682
699
  salt: this.generateSalt(),
683
- signedAtMillis: Date.now(),
700
+ signedAtMillis: this.getCurrentTimeMs(),
684
701
  };
685
702
 
686
703
  const signature = await this.bfSigner.signAdjustIsolatedMarginRequest(