@drift-labs/sdk 2.65.0-beta.6 → 2.65.0-beta.7
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 +1 -1
- package/lib/driftClient.js +17 -9
- package/package.json +1 -1
- package/src/driftClient.ts +24 -13
- package/tests/dlob/test.ts +74 -75
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.65.0-beta.
|
|
1
|
+
2.65.0-beta.7
|
package/lib/driftClient.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
415
|
+
let userAccounts = [];
|
|
416
416
|
let delegatedAccounts = [];
|
|
417
|
+
const userAccountsPromise = this.getUserAccountsForAuthority(this.wallet.publicKey);
|
|
417
418
|
if (this.includeDelegates) {
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
|
|
422
|
-
|
|
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((
|
|
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
package/src/driftClient.ts
CHANGED
|
@@ -693,25 +693,36 @@ export class DriftClient {
|
|
|
693
693
|
);
|
|
694
694
|
}
|
|
695
695
|
} else {
|
|
696
|
-
|
|
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
|
-
|
|
702
|
-
|
|
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
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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,
|
package/tests/dlob/test.ts
CHANGED
|
@@ -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
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
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
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
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),
|
|
6656
|
-
expect(bidsAreSortedDesc(bids),
|
|
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(
|
|
6659
|
-
const oraclePrice5Min = new BN(
|
|
6660
|
-
const markPrice5Min = new BN(
|
|
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(
|
|
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),
|
|
6678
|
-
|
|
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
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
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
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
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),
|
|
6719
|
-
expect(bidsAreSortedDesc(bids),
|
|
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(
|
|
6722
|
-
const oraclePrice5Min = new BN(
|
|
6723
|
-
const markPrice5Min = new BN(
|
|
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(
|
|
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),
|
|
6741
|
-
|
|
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
|
});
|