@drift-labs/sdk 2.65.0-beta.6 → 2.65.0-beta.8

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.65.0-beta.6
1
+ 2.65.0-beta.8
@@ -108,6 +108,7 @@ exports.MainnetSpotMarkets = [
108
108
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
109
109
  precisionExp: numericConstants_1.NINE,
110
110
  serumMarket: new web3_js_1.PublicKey('DkbVbMhFxswS32xnn1K2UY4aoBugXooBTxdzkWWDWRkH'),
111
+ phoenixMarket: new web3_js_1.PublicKey('5LQLfGtqcC5rm2WuGxJf4tjqYmDjsQAbKo2AMLQ8KB7p'),
111
112
  },
112
113
  {
113
114
  symbol: 'PYTH',
@@ -395,7 +395,7 @@ class DriftClient {
395
395
  * Adds and subscribes to users based on params set by the constructor or by updateWallet.
396
396
  */
397
397
  async addAndSubscribeToUsers() {
398
- var _a, _b, _c, _d, _e, _f, _g, _h;
398
+ var _a, _b, _c, _d, _e, _f, _g;
399
399
  // save the rpc calls if driftclient is initialized without a real wallet
400
400
  if (this.skipLoadUsers)
401
401
  return true;
@@ -412,19 +412,27 @@ class DriftClient {
412
412
  }
413
413
  }
414
414
  else {
415
- const userAccounts = (_c = (await this.getUserAccountsForAuthority(this.wallet.publicKey))) !== null && _c !== void 0 ? _c : [];
415
+ let userAccounts = [];
416
416
  let delegatedAccounts = [];
417
+ const userAccountsPromise = this.getUserAccountsForAuthority(this.wallet.publicKey);
417
418
  if (this.includeDelegates) {
418
- delegatedAccounts =
419
- (_d = (await this.getUserAccountsForDelegate(this.wallet.publicKey))) !== null && _d !== void 0 ? _d : [];
419
+ const delegatedAccountsPromise = this.getUserAccountsForDelegate(this.wallet.publicKey);
420
+ [userAccounts, delegatedAccounts] = await Promise.all([
421
+ userAccountsPromise,
422
+ delegatedAccountsPromise,
423
+ ]);
424
+ !userAccounts && (userAccounts = []);
425
+ !delegatedAccounts && (delegatedAccounts = []);
420
426
  }
421
- for (const account of userAccounts.concat(delegatedAccounts)) {
422
- result =
423
- result &&
424
- (await this.addUser(account.subAccountId, account.authority, account));
427
+ else {
428
+ userAccounts = (_c = (await userAccountsPromise)) !== null && _c !== void 0 ? _c : [];
425
429
  }
430
+ const allAccounts = userAccounts.concat(delegatedAccounts);
431
+ const addAllAccountsPromise = allAccounts.map((acc) => this.addUser(acc.subAccountId, acc.authority, acc));
432
+ const addAllAccountsResults = await Promise.all(addAllAccountsPromise);
433
+ result = addAllAccountsResults.every((res) => !!res);
426
434
  if (this.activeSubAccountId == undefined) {
427
- this.switchActiveUser((_f = (_e = userAccounts.concat(delegatedAccounts)[0]) === null || _e === void 0 ? void 0 : _e.subAccountId) !== null && _f !== void 0 ? _f : 0, (_h = (_g = userAccounts.concat(delegatedAccounts)[0]) === null || _g === void 0 ? void 0 : _g.authority) !== null && _h !== void 0 ? _h : this.authority);
435
+ this.switchActiveUser((_e = (_d = userAccounts.concat(delegatedAccounts)[0]) === null || _d === void 0 ? void 0 : _d.subAccountId) !== null && _e !== void 0 ? _e : 0, (_g = (_f = userAccounts.concat(delegatedAccounts)[0]) === null || _f === void 0 ? void 0 : _f.authority) !== null && _g !== void 0 ? _g : this.authority);
428
436
  }
429
437
  }
430
438
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.65.0-beta.6",
3
+ "version": "2.65.0-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -137,6 +137,9 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
137
137
  precision: new BN(10).pow(NINE),
138
138
  precisionExp: NINE,
139
139
  serumMarket: new PublicKey('DkbVbMhFxswS32xnn1K2UY4aoBugXooBTxdzkWWDWRkH'),
140
+ phoenixMarket: new PublicKey(
141
+ '5LQLfGtqcC5rm2WuGxJf4tjqYmDjsQAbKo2AMLQ8KB7p'
142
+ ),
140
143
  },
141
144
  {
142
145
  symbol: 'PYTH',
@@ -693,25 +693,36 @@ export class DriftClient {
693
693
  );
694
694
  }
695
695
  } else {
696
- const userAccounts =
697
- (await this.getUserAccountsForAuthority(this.wallet.publicKey)) ?? [];
696
+ let userAccounts = [];
698
697
  let delegatedAccounts = [];
699
698
 
699
+ const userAccountsPromise = this.getUserAccountsForAuthority(
700
+ this.wallet.publicKey
701
+ );
702
+
700
703
  if (this.includeDelegates) {
701
- delegatedAccounts =
702
- (await this.getUserAccountsForDelegate(this.wallet.publicKey)) ?? [];
703
- }
704
+ const delegatedAccountsPromise = this.getUserAccountsForDelegate(
705
+ this.wallet.publicKey
706
+ );
707
+ [userAccounts, delegatedAccounts] = await Promise.all([
708
+ userAccountsPromise,
709
+ delegatedAccountsPromise,
710
+ ]);
704
711
 
705
- for (const account of userAccounts.concat(delegatedAccounts)) {
706
- result =
707
- result &&
708
- (await this.addUser(
709
- account.subAccountId,
710
- account.authority,
711
- account
712
- ));
712
+ !userAccounts && (userAccounts = []);
713
+ !delegatedAccounts && (delegatedAccounts = []);
714
+ } else {
715
+ userAccounts = (await userAccountsPromise) ?? [];
713
716
  }
714
717
 
718
+ const allAccounts = userAccounts.concat(delegatedAccounts);
719
+ const addAllAccountsPromise = allAccounts.map((acc) =>
720
+ this.addUser(acc.subAccountId, acc.authority, acc)
721
+ );
722
+
723
+ const addAllAccountsResults = await Promise.all(addAllAccountsPromise);
724
+ result = addAllAccountsResults.every((res) => !!res);
725
+
715
726
  if (this.activeSubAccountId == undefined) {
716
727
  this.switchActiveUser(
717
728
  userAccounts.concat(delegatedAccounts)[0]?.subAccountId ?? 0,
@@ -6613,53 +6613,50 @@ describe('Uncross L2', () => {
6613
6613
  new BN(1).mul(BASE_PRECISION).toString()
6614
6614
  );
6615
6615
  });
6616
-
6617
- it('Handles edge case bide and asks with large cross and an overlapping level', () => {
6618
6616
 
6617
+ it('Handles edge case bide and asks with large cross and an overlapping level', () => {
6619
6618
  const bids = [
6620
- "104411000",
6621
- "103835800",
6622
- "103826259",
6623
- "103825000",
6624
- "103822000",
6625
- "103821500",
6626
- "103820283",
6627
- "103816900",
6628
- "103816000",
6629
- "103815121",
6630
- ].map(priceStr => (
6631
- {
6632
- price: new BN(priceStr),
6633
- size: new BN(1).mul(BASE_PRECISION),
6634
- sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6635
- }
6636
- ));
6619
+ '104411000',
6620
+ '103835800',
6621
+ '103826259',
6622
+ '103825000',
6623
+ '103822000',
6624
+ '103821500',
6625
+ '103820283',
6626
+ '103816900',
6627
+ '103816000',
6628
+ '103815121',
6629
+ ].map((priceStr) => ({
6630
+ price: new BN(priceStr),
6631
+ size: new BN(1).mul(BASE_PRECISION),
6632
+ sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6633
+ }));
6637
6634
 
6638
6635
  const asks = [
6639
- "103822000",
6640
- "103838354",
6641
- "103843087",
6642
- "103843351",
6643
- "103843880",
6644
- "103845114",
6645
- "103846148",
6646
- "103850100",
6647
- "103851300",
6648
- "103854304",
6649
- ].map(priceStr => ({
6636
+ '103822000',
6637
+ '103838354',
6638
+ '103843087',
6639
+ '103843351',
6640
+ '103843880',
6641
+ '103845114',
6642
+ '103846148',
6643
+ '103850100',
6644
+ '103851300',
6645
+ '103854304',
6646
+ ].map((priceStr) => ({
6650
6647
  price: new BN(priceStr),
6651
6648
  size: new BN(1).mul(BASE_PRECISION),
6652
6649
  sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6653
6650
  }));
6654
6651
 
6655
- expect(asksAreSortedAsc(asks), "Input asks are ascending").to.be.true;
6656
- expect(bidsAreSortedDesc(bids), "Input bids are descending").to.be.true;
6652
+ expect(asksAreSortedAsc(asks), 'Input asks are ascending').to.be.true;
6653
+ expect(bidsAreSortedDesc(bids), 'Input bids are descending').to.be.true;
6657
6654
 
6658
- const oraclePrice = new BN("103649895");
6659
- const oraclePrice5Min = new BN("103285000");
6660
- const markPrice5Min = new BN("103371000");
6655
+ const oraclePrice = new BN('103649895');
6656
+ const oraclePrice5Min = new BN('103285000');
6657
+ const markPrice5Min = new BN('103371000');
6661
6658
 
6662
- const groupingSize = new BN("100");
6659
+ const groupingSize = new BN('100');
6663
6660
 
6664
6661
  const userAsks = new Set<string>();
6665
6662
 
@@ -6674,55 +6671,55 @@ describe('Uncross L2', () => {
6674
6671
  userAsks
6675
6672
  );
6676
6673
 
6677
- expect(asksAreSortedAsc(newAsks), "Uncrossed asks are ascending").to.be.true;
6678
- expect(bidsAreSortedDesc(newBids), "Uncrossed bids are descending").to.be.true;
6674
+ expect(asksAreSortedAsc(newAsks), 'Uncrossed asks are ascending').to.be
6675
+ .true;
6676
+ expect(bidsAreSortedDesc(newBids), 'Uncrossed bids are descending').to.be
6677
+ .true;
6679
6678
  });
6680
-
6679
+
6681
6680
  it('Crossing edge case : top bid and ask have a big cross, following ones dont - shouldnt get uncrossed out of order', () => {
6682
6681
  const bids = [
6683
- "101825900",
6684
- "101783900",
6685
- "101783000",
6686
- "101782600",
6687
- "101770700",
6688
- "101770200",
6689
- "101749857",
6690
- "101735900",
6691
- "101729994",
6692
- "101726900",
6693
- ].map(priceStr => (
6694
- {
6695
- price: new BN(priceStr),
6696
- size: new BN(1).mul(BASE_PRECISION),
6697
- sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6698
- }
6699
- ));
6682
+ '101825900',
6683
+ '101783900',
6684
+ '101783000',
6685
+ '101782600',
6686
+ '101770700',
6687
+ '101770200',
6688
+ '101749857',
6689
+ '101735900',
6690
+ '101729994',
6691
+ '101726900',
6692
+ ].map((priceStr) => ({
6693
+ price: new BN(priceStr),
6694
+ size: new BN(1).mul(BASE_PRECISION),
6695
+ sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6696
+ }));
6700
6697
 
6701
6698
  const asks = [
6702
- "101750700",
6703
- "101790467",
6704
- "101793400",
6705
- "101794116",
6706
- "101798548",
6707
- "101799532",
6708
- "101803500",
6709
- "101820927",
6710
- "101823900",
6711
- "101827638",
6712
- ].map(priceStr => ({
6699
+ '101750700',
6700
+ '101790467',
6701
+ '101793400',
6702
+ '101794116',
6703
+ '101798548',
6704
+ '101799532',
6705
+ '101803500',
6706
+ '101820927',
6707
+ '101823900',
6708
+ '101827638',
6709
+ ].map((priceStr) => ({
6713
6710
  price: new BN(priceStr),
6714
6711
  size: new BN(1).mul(BASE_PRECISION),
6715
6712
  sources: { vamm: new BN(1).mul(BASE_PRECISION) },
6716
6713
  }));
6717
6714
 
6718
- expect(asksAreSortedAsc(asks), "Input asks are ascending").to.be.true;
6719
- expect(bidsAreSortedDesc(bids), "Input bids are descending").to.be.true;
6715
+ expect(asksAreSortedAsc(asks), 'Input asks are ascending').to.be.true;
6716
+ expect(bidsAreSortedDesc(bids), 'Input bids are descending').to.be.true;
6720
6717
 
6721
- const oraclePrice = new BN("101711384");
6722
- const oraclePrice5Min = new BN("101805000");
6723
- const markPrice5Min = new BN("101867000");
6718
+ const oraclePrice = new BN('101711384');
6719
+ const oraclePrice5Min = new BN('101805000');
6720
+ const markPrice5Min = new BN('101867000');
6724
6721
 
6725
- const groupingSize = new BN("100");
6722
+ const groupingSize = new BN('100');
6726
6723
 
6727
6724
  const userAsks = new Set<string>();
6728
6725
 
@@ -6737,7 +6734,9 @@ describe('Uncross L2', () => {
6737
6734
  userAsks
6738
6735
  );
6739
6736
 
6740
- expect(asksAreSortedAsc(newAsks), "Uncrossed asks are ascending").to.be.true;
6741
- expect(bidsAreSortedDesc(newBids), "Uncrossed bids are descending").to.be.true;
6737
+ expect(asksAreSortedAsc(newAsks), 'Uncrossed asks are ascending').to.be
6738
+ .true;
6739
+ expect(bidsAreSortedDesc(newBids), 'Uncrossed bids are descending').to.be
6740
+ .true;
6742
6741
  });
6743
6742
  });