@drift-labs/sdk 2.104.0-beta.35 → 2.104.0-beta.36

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.104.0-beta.35
1
+ 2.104.0-beta.36
@@ -400,8 +400,8 @@ export declare class DriftClient {
400
400
  placeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
401
401
  }>;
402
402
  getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
403
- fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
404
- getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
403
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
404
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
405
405
  addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount): void;
406
406
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
407
407
  addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
@@ -255,6 +255,34 @@ class BigNum {
255
255
  const isNeg = this.isNeg();
256
256
  const printString = this.abs().print();
257
257
  const thisString = this.abs().toString();
258
+ // Handle small numbers (those with leading zeros after decimal)
259
+ if (printString.includes(BigNum.delim)) {
260
+ const [leftSide, rightSide] = printString.split(BigNum.delim);
261
+ if (leftSide === '0' && rightSide) {
262
+ // Count leading zeros
263
+ let leadingZeros = 0;
264
+ for (let i = 0; i < rightSide.length; i++) {
265
+ if (rightSide[i] === '0') {
266
+ leadingZeros++;
267
+ }
268
+ else {
269
+ break;
270
+ }
271
+ }
272
+ // Get significant digits starting after leading zeros
273
+ const significantPart = rightSide.slice(leadingZeros);
274
+ let significantDigits = significantPart.slice(0, fixedPrecision);
275
+ // Remove trailing zeros if not requested
276
+ if (!trailingZeroes) {
277
+ significantDigits = significantDigits.replace(/0+$/, '');
278
+ }
279
+ // Only return result if we have significant digits
280
+ if (significantDigits.length > 0) {
281
+ const result = `${isNeg ? '-' : ''}0${BigNum.delim}${rightSide.slice(0, leadingZeros)}${significantDigits}`;
282
+ return result;
283
+ }
284
+ }
285
+ }
258
286
  let precisionPrintString = printString.slice(0, fixedPrecision + 1);
259
287
  if (!printString.includes(BigNum.delim) &&
260
288
  thisString.length < fixedPrecision) {
@@ -400,8 +400,8 @@ export declare class DriftClient {
400
400
  placeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
401
401
  }>;
402
402
  getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
403
- fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
404
- getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
403
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
404
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
405
405
  addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount): void;
406
406
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
407
407
  addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
@@ -255,6 +255,34 @@ class BigNum {
255
255
  const isNeg = this.isNeg();
256
256
  const printString = this.abs().print();
257
257
  const thisString = this.abs().toString();
258
+ // Handle small numbers (those with leading zeros after decimal)
259
+ if (printString.includes(BigNum.delim)) {
260
+ const [leftSide, rightSide] = printString.split(BigNum.delim);
261
+ if (leftSide === '0' && rightSide) {
262
+ // Count leading zeros
263
+ let leadingZeros = 0;
264
+ for (let i = 0; i < rightSide.length; i++) {
265
+ if (rightSide[i] === '0') {
266
+ leadingZeros++;
267
+ }
268
+ else {
269
+ break;
270
+ }
271
+ }
272
+ // Get significant digits starting after leading zeros
273
+ const significantPart = rightSide.slice(leadingZeros);
274
+ let significantDigits = significantPart.slice(0, fixedPrecision);
275
+ // Remove trailing zeros if not requested
276
+ if (!trailingZeroes) {
277
+ significantDigits = significantDigits.replace(/0+$/, '');
278
+ }
279
+ // Only return result if we have significant digits
280
+ if (significantDigits.length > 0) {
281
+ const result = `${isNeg ? '-' : ''}0${BigNum.delim}${rightSide.slice(0, leadingZeros)}${significantDigits}`;
282
+ return result;
283
+ }
284
+ }
285
+ }
258
286
  let precisionPrintString = printString.slice(0, fixedPrecision + 1);
259
287
  if (!printString.includes(BigNum.delim) &&
260
288
  thisString.length < fixedPrecision) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.104.0-beta.35",
3
+ "version": "2.104.0-beta.36",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -4189,7 +4189,7 @@ export class DriftClient {
4189
4189
  public async fillSpotOrder(
4190
4190
  userAccountPublicKey: PublicKey,
4191
4191
  user: UserAccount,
4192
- order?: Order,
4192
+ order?: Pick<Order, 'marketIndex' | 'orderId'>,
4193
4193
  fulfillmentConfig?:
4194
4194
  | SerumV3FulfillmentConfigAccount
4195
4195
  | PhoenixV1FulfillmentConfigAccount
@@ -4219,7 +4219,7 @@ export class DriftClient {
4219
4219
  public async getFillSpotOrderIx(
4220
4220
  userAccountPublicKey: PublicKey,
4221
4221
  userAccount: UserAccount,
4222
- order?: Order,
4222
+ order?: Pick<Order, 'marketIndex' | 'orderId'>,
4223
4223
  fulfillmentConfig?:
4224
4224
  | SerumV3FulfillmentConfigAccount
4225
4225
  | PhoenixV1FulfillmentConfigAccount
@@ -386,10 +386,42 @@ export class BigNum {
386
386
  }
387
387
 
388
388
  const isNeg = this.isNeg();
389
-
390
389
  const printString = this.abs().print();
391
390
  const thisString = this.abs().toString();
392
391
 
392
+ // Handle small numbers (those with leading zeros after decimal)
393
+ if (printString.includes(BigNum.delim)) {
394
+ const [leftSide, rightSide] = printString.split(BigNum.delim);
395
+ if (leftSide === '0' && rightSide) {
396
+ // Count leading zeros
397
+ let leadingZeros = 0;
398
+ for (let i = 0; i < rightSide.length; i++) {
399
+ if (rightSide[i] === '0') {
400
+ leadingZeros++;
401
+ } else {
402
+ break;
403
+ }
404
+ }
405
+ // Get significant digits starting after leading zeros
406
+ const significantPart = rightSide.slice(leadingZeros);
407
+ let significantDigits = significantPart.slice(0, fixedPrecision);
408
+
409
+ // Remove trailing zeros if not requested
410
+ if (!trailingZeroes) {
411
+ significantDigits = significantDigits.replace(/0+$/, '');
412
+ }
413
+
414
+ // Only return result if we have significant digits
415
+ if (significantDigits.length > 0) {
416
+ const result = `${isNeg ? '-' : ''}0${BigNum.delim}${rightSide.slice(
417
+ 0,
418
+ leadingZeros
419
+ )}${significantDigits}`;
420
+ return result;
421
+ }
422
+ }
423
+ }
424
+
393
425
  let precisionPrintString = printString.slice(0, fixedPrecision + 1);
394
426
 
395
427
  if (
package/tests/bn/test.ts CHANGED
@@ -11,6 +11,13 @@ import {
11
11
  // if you used the '@types/mocha' method to install mocha type definitions, uncomment the following line
12
12
  // import 'mocha';
13
13
 
14
+ const bn = (value: number, precision: number) =>
15
+ new BigNum(Math.round(value * 10 ** precision), precision);
16
+ const _bnPrice = (value: number) => bn(value, 6); // Price precision (6 decimals)
17
+ const _bnNotional = (value: number) => bn(value, 6); // USDC precision (6 decimals)
18
+ const _bnPercentage = (value: number) => bn(value, 4); // Percentage precision (4 decimals)
19
+ const bnBaseAmount = (value: number) => bn(value, 8); // BTC-like precision (8 decimals)
20
+
14
21
  describe('BigNum Tests', () => {
15
22
  it('basic string representations are correct', () => {
16
23
  const bn = BigNum.from(TEN_THOUSAND);
@@ -108,6 +115,12 @@ describe('BigNum Tests', () => {
108
115
  expect(val4.toNum().toFixed(3)).to.equal('0.025');
109
116
  expect(val4.toPrecision(4)).to.equal('0.025');
110
117
 
118
+ expect(bnBaseAmount(0.001234).toPrecision(4)).to.equal('0.001234');
119
+
120
+ expect(bnBaseAmount(0.001004).toPrecision(4)).to.equal('0.001004');
121
+
122
+ expect(bnBaseAmount(0.001).toPrecision(4)).to.equal('0.001');
123
+
111
124
  // Case 5
112
125
  expect(BigNum.fromPrint('1').toMillified()).to.equal('1.00');
113
126
  expect(BigNum.fromPrint('12').toMillified()).to.equal('12.0');