@drift-labs/sdk 2.63.0-beta.3 → 2.63.0-beta.5

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.63.0-beta.3
1
+ 2.63.0-beta.5
@@ -1,4 +1,4 @@
1
- import { User, DriftClient, UserAccount, OrderRecord, WrappedEvent, DLOB } from '..';
1
+ import { User, DriftClient, UserAccount, OrderRecord, WrappedEvent, DLOB, UserSubscriptionConfig } from '..';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { UserAccountFilterCriteria as UserFilterCriteria, UserMapConfig } from './userMapConfig';
4
4
  export interface UserMapInterface {
@@ -31,7 +31,7 @@ export declare class UserMap implements UserMapInterface {
31
31
  */
32
32
  constructor(config: UserMapConfig);
33
33
  subscribe(): Promise<void>;
34
- addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number): Promise<void>;
34
+ addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number, accountSubscription?: UserSubscriptionConfig): Promise<void>;
35
35
  has(key: string): boolean;
36
36
  /**
37
37
  * gets the User for a particular userAccountPublicKey, if no User exists, undefined is returned
@@ -44,7 +44,7 @@ export declare class UserMap implements UserMapInterface {
44
44
  * @param key userAccountPublicKey to get User for
45
45
  * @returns User
46
46
  */
47
- mustGet(key: string): Promise<User>;
47
+ mustGet(key: string, accountSubscription?: UserSubscriptionConfig): Promise<User>;
48
48
  /**
49
49
  * gets the Authority for a particular userAccountPublicKey, if no User exists, undefined is returned
50
50
  * @param key userAccountPublicKey to get User for
@@ -72,11 +72,11 @@ class UserMap {
72
72
  }
73
73
  await this.subscription.subscribe();
74
74
  }
75
- async addPubkey(userAccountPublicKey, userAccount, slot) {
75
+ async addPubkey(userAccountPublicKey, userAccount, slot, accountSubscription) {
76
76
  const user = new __1.User({
77
77
  driftClient: this.driftClient,
78
78
  userAccountPublicKey,
79
- accountSubscription: {
79
+ accountSubscription: accountSubscription !== null && accountSubscription !== void 0 ? accountSubscription : {
80
80
  type: 'custom',
81
81
  userAccountSubscriber: new __1.OneShotUserAccountSubscriber(this.driftClient.program, userAccountPublicKey, userAccount, slot, this.commitment),
82
82
  },
@@ -100,9 +100,9 @@ class UserMap {
100
100
  * @param key userAccountPublicKey to get User for
101
101
  * @returns User
102
102
  */
103
- async mustGet(key) {
103
+ async mustGet(key, accountSubscription) {
104
104
  if (!this.has(key)) {
105
- await this.addPubkey(new web3_js_1.PublicKey(key));
105
+ await this.addPubkey(new web3_js_1.PublicKey(key), undefined, undefined, accountSubscription);
106
106
  }
107
107
  const user = this.userMap.get(key);
108
108
  return user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.63.0-beta.3",
3
+ "version": "2.63.0-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -15,6 +15,7 @@ import {
15
15
  DLOB,
16
16
  OneShotUserAccountSubscriber,
17
17
  BN,
18
+ UserSubscriptionConfig,
18
19
  } from '..';
19
20
 
20
21
  import {
@@ -131,12 +132,13 @@ export class UserMap implements UserMapInterface {
131
132
  public async addPubkey(
132
133
  userAccountPublicKey: PublicKey,
133
134
  userAccount?: UserAccount,
134
- slot?: number
135
+ slot?: number,
136
+ accountSubscription?: UserSubscriptionConfig
135
137
  ) {
136
138
  const user = new User({
137
139
  driftClient: this.driftClient,
138
140
  userAccountPublicKey,
139
- accountSubscription: {
141
+ accountSubscription: accountSubscription ?? {
140
142
  type: 'custom',
141
143
  userAccountSubscriber: new OneShotUserAccountSubscriber(
142
144
  this.driftClient.program,
@@ -169,9 +171,17 @@ export class UserMap implements UserMapInterface {
169
171
  * @param key userAccountPublicKey to get User for
170
172
  * @returns User
171
173
  */
172
- public async mustGet(key: string): Promise<User> {
174
+ public async mustGet(
175
+ key: string,
176
+ accountSubscription?: UserSubscriptionConfig
177
+ ): Promise<User> {
173
178
  if (!this.has(key)) {
174
- await this.addPubkey(new PublicKey(key));
179
+ await this.addPubkey(
180
+ new PublicKey(key),
181
+ undefined,
182
+ undefined,
183
+ accountSubscription
184
+ );
175
185
  }
176
186
  const user = this.userMap.get(key);
177
187
  return user;
package/tests/amm/test.ts CHANGED
@@ -332,8 +332,8 @@ describe('AMM Tests', () => {
332
332
  new BN(928097825691666),
333
333
  new BN(907979542352912),
334
334
  new BN(945977491145601),
335
- new BN(161188),
336
- new BN(1459632439),
335
+ new BN(161188), // mark std
336
+ new BN(145963), // oracle std
337
337
  new BN(12358265776),
338
338
  new BN(72230366233),
339
339
  new BN(432067603632),
@@ -342,9 +342,9 @@ describe('AMM Tests', () => {
342
342
 
343
343
  // console.log(terms2);
344
344
  assert(terms2.effectiveLeverageCapped >= 1.0002);
345
- assert(terms2.inventorySpreadScale == 1.73492);
346
- assert(terms2.longSpread == 4262);
347
- assert(terms2.shortSpread == 43238);
345
+ assert(terms2.inventorySpreadScale == 4.717646);
346
+ assert(terms2.longSpread == 160);
347
+ assert(terms2.shortSpread == 4430);
348
348
 
349
349
  // add spread offset
350
350
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -365,19 +365,19 @@ describe('AMM Tests', () => {
365
365
  new BN(907979542352912),
366
366
  new BN(945977491145601),
367
367
  new BN(161188),
368
- new BN(1459632439),
368
+ new BN(145963), // oracle std
369
369
  new BN(12358265776),
370
370
  new BN(72230366233),
371
371
  new BN(432067603632),
372
372
  true
373
373
  );
374
374
 
375
- console.log(terms3);
375
+ // console.log(terms3);
376
376
  assert(terms3.effectiveLeverageCapped >= 1.0002);
377
- assert(terms3.inventorySpreadScale == 1.73492);
378
- assert(terms3.longSpread == 4262);
379
- assert(terms3.shortSpread == 43238);
380
- assert(terms3.longSpread + terms3.shortSpread == 47500);
377
+ assert(terms3.inventorySpreadScale == 4.717646);
378
+ assert(terms3.longSpread == 160);
379
+ assert(terms3.shortSpread == 4430);
380
+ assert(terms3.longSpread + terms3.shortSpread == 4430 + 160);
381
381
 
382
382
  // add spread offset
383
383
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -398,7 +398,7 @@ describe('AMM Tests', () => {
398
398
  new BN(907979542352912),
399
399
  new BN(945977491145601),
400
400
  new BN(161188),
401
- new BN(1459632439),
401
+ new BN(1459632439), // oracle std (unchanged)
402
402
  new BN(12358265776),
403
403
  new BN(72230366233),
404
404
  new BN(432067603632),
@@ -408,9 +408,9 @@ describe('AMM Tests', () => {
408
408
  console.log(terms4);
409
409
  assert(terms4.effectiveLeverageCapped >= 1.0002);
410
410
  assert(terms4.inventorySpreadScale == 1.73492);
411
- assert(terms4.longSpread == 4262);
412
- assert(terms4.shortSpread == 43238);
413
- assert(terms4.longSpread + terms4.shortSpread == 47500);
411
+ assert(terms4.longSpread == 89746);
412
+ assert(terms4.shortSpread == 910254);
413
+ assert(terms4.longSpread + terms4.shortSpread == 1000000);
414
414
  });
415
415
 
416
416
  it('Corner Case Spreads', () => {