@drift-labs/sdk 2.115.0-beta.1 → 2.115.0-beta.11

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.
Files changed (84) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/constants/perpMarkets.js +2 -2
  3. package/lib/browser/dlob/DLOB.d.ts +3 -3
  4. package/lib/browser/dlob/DLOB.js +8 -5
  5. package/lib/browser/dlob/DLOBNode.d.ts +5 -5
  6. package/lib/browser/dlob/DLOBNode.js +12 -13
  7. package/lib/browser/dlob/DLOBSubscriber.d.ts +2 -1
  8. package/lib/browser/dlob/DLOBSubscriber.js +8 -2
  9. package/lib/browser/dlob/NodeList.d.ts +2 -2
  10. package/lib/browser/dlob/NodeList.js +2 -2
  11. package/lib/browser/dlob/types.d.ts +6 -1
  12. package/lib/browser/driftClient.d.ts +4 -4
  13. package/lib/browser/driftClient.js +27 -23
  14. package/lib/browser/idl/drift.json +25 -2
  15. package/lib/browser/math/orders.d.ts +3 -2
  16. package/lib/browser/math/orders.js +22 -10
  17. package/lib/browser/math/protectedMakerParams.d.ts +4 -0
  18. package/lib/browser/math/protectedMakerParams.js +32 -0
  19. package/lib/browser/openbook/openbookV2Subscriber.d.ts +2 -0
  20. package/lib/browser/openbook/openbookV2Subscriber.js +16 -6
  21. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -2
  22. package/lib/browser/orderSubscriber/OrderSubscriber.js +4 -4
  23. package/lib/browser/phoenix/phoenixSubscriber.d.ts +2 -0
  24. package/lib/browser/phoenix/phoenixSubscriber.js +19 -10
  25. package/lib/browser/types.d.ts +8 -1
  26. package/lib/browser/userMap/userMap.d.ts +2 -2
  27. package/lib/browser/userMap/userMap.js +2 -2
  28. package/lib/node/constants/perpMarkets.js +2 -2
  29. package/lib/node/dlob/DLOB.d.ts +3 -3
  30. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  31. package/lib/node/dlob/DLOB.js +8 -5
  32. package/lib/node/dlob/DLOBNode.d.ts +5 -5
  33. package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
  34. package/lib/node/dlob/DLOBNode.js +12 -13
  35. package/lib/node/dlob/DLOBSubscriber.d.ts +2 -1
  36. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  37. package/lib/node/dlob/DLOBSubscriber.js +8 -2
  38. package/lib/node/dlob/NodeList.d.ts +2 -2
  39. package/lib/node/dlob/NodeList.d.ts.map +1 -1
  40. package/lib/node/dlob/NodeList.js +2 -2
  41. package/lib/node/dlob/types.d.ts +6 -1
  42. package/lib/node/dlob/types.d.ts.map +1 -1
  43. package/lib/node/driftClient.d.ts +4 -4
  44. package/lib/node/driftClient.d.ts.map +1 -1
  45. package/lib/node/driftClient.js +27 -23
  46. package/lib/node/idl/drift.json +25 -2
  47. package/lib/node/math/orders.d.ts +3 -2
  48. package/lib/node/math/orders.d.ts.map +1 -1
  49. package/lib/node/math/orders.js +22 -10
  50. package/lib/node/math/protectedMakerParams.d.ts +5 -0
  51. package/lib/node/math/protectedMakerParams.d.ts.map +1 -0
  52. package/lib/node/math/protectedMakerParams.js +32 -0
  53. package/lib/node/openbook/openbookV2Subscriber.d.ts +2 -0
  54. package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
  55. package/lib/node/openbook/openbookV2Subscriber.js +16 -6
  56. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -2
  57. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  58. package/lib/node/orderSubscriber/OrderSubscriber.js +4 -4
  59. package/lib/node/phoenix/phoenixSubscriber.d.ts +2 -0
  60. package/lib/node/phoenix/phoenixSubscriber.d.ts.map +1 -1
  61. package/lib/node/phoenix/phoenixSubscriber.js +19 -10
  62. package/lib/node/types.d.ts +8 -1
  63. package/lib/node/types.d.ts.map +1 -1
  64. package/lib/node/userMap/userMap.d.ts +2 -2
  65. package/lib/node/userMap/userMap.d.ts.map +1 -1
  66. package/lib/node/userMap/userMap.js +2 -2
  67. package/package.json +2 -2
  68. package/src/constants/perpMarkets.ts +2 -2
  69. package/src/dlob/DLOB.ts +14 -6
  70. package/src/dlob/DLOBNode.ts +25 -15
  71. package/src/dlob/DLOBSubscriber.ts +10 -2
  72. package/src/dlob/NodeList.ts +3 -3
  73. package/src/dlob/types.ts +10 -1
  74. package/src/driftClient.ts +36 -21
  75. package/src/idl/drift.json +16 -1
  76. package/src/math/orders.ts +39 -9
  77. package/src/math/protectedMakerParams.ts +37 -0
  78. package/src/openbook/openbookV2Subscriber.ts +20 -10
  79. package/src/orderSubscriber/OrderSubscriber.ts +5 -5
  80. package/src/phoenix/phoenixSubscriber.ts +28 -16
  81. package/src/types.ts +9 -1
  82. package/src/userMap/userMap.ts +3 -2
  83. package/tests/dlob/helpers.ts +6 -0
  84. package/tests/dlob/test.ts +4 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.115.0-beta.1
1
+ 2.115.0-beta.11
@@ -58,9 +58,9 @@ exports.DevnetPerpMarkets = [
58
58
  symbol: '1MBONK-PERP',
59
59
  baseAssetSymbol: '1MBONK',
60
60
  marketIndex: 4,
61
- oracle: new web3_js_1.PublicKey('GojbSnJuPdKDT1ZuHuAM5t9oz6bxTo1xhUKpTua2F72p'),
61
+ oracle: new web3_js_1.PublicKey('BERaNi6cpEresbq6HC1EQGaB1H1UjvEo4NGnmYSSJof4'),
62
62
  launchTs: 1677068931000,
63
- oracleSource: __1.OracleSource.PYTH_1M_PULL,
63
+ oracleSource: __1.OracleSource.PYTH_LAZER_1M,
64
64
  pythFeedId: '0x72b021217ca3fe68922a19aaf990109cb9d84e9ad004b4d2025ad6f529314419',
65
65
  pythLazerId: 9,
66
66
  },
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { NodeList } from './NodeList';
3
- import { BN, DLOBNode, DLOBNodeType, DriftClient, MarketType, MarketTypeStr, OraclePriceData, Order, PerpMarketAccount, PositionDirection, SlotSubscriber, SpotMarketAccount, StateAccount, TriggerOrderNode, UserMap } from '..';
3
+ import { BN, DLOBNode, DLOBNodeType, DriftClient, MarketType, MarketTypeStr, OraclePriceData, Order, PerpMarketAccount, PositionDirection, ProtectMakerParamsMap, SlotSubscriber, SpotMarketAccount, StateAccount, TriggerOrderNode, UserMap } from '..';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { L2OrderBook, L2OrderBookGenerator, L3OrderBook } from './orderBookLevels';
6
6
  export type DLOBOrder = {
@@ -58,8 +58,8 @@ export declare class DLOB {
58
58
  orderLists: Map<MarketTypeStr, Map<number, MarketNodeLists>>;
59
59
  maxSlotForRestingLimitOrders: number;
60
60
  initialized: boolean;
61
- protectedMakerView: boolean;
62
- constructor(protectedMakerView?: boolean);
61
+ protectedMakerParamsMap: ProtectMakerParamsMap;
62
+ constructor(protectedMakerParamsMap?: ProtectMakerParamsMap);
63
63
  private init;
64
64
  clear(): void;
65
65
  /**
@@ -14,12 +14,15 @@ const SUPPORTED_ORDER_TYPES = [
14
14
  'oracle',
15
15
  ];
16
16
  class DLOB {
17
- constructor(protectedMakerView) {
17
+ constructor(protectedMakerParamsMap) {
18
18
  this.openOrders = new Map();
19
19
  this.orderLists = new Map();
20
20
  this.maxSlotForRestingLimitOrders = 0;
21
21
  this.initialized = false;
22
- this.protectedMakerView = protectedMakerView || false;
22
+ this.protectedMakerParamsMap = protectedMakerParamsMap || {
23
+ perp: new Map(),
24
+ spot: new Map(),
25
+ };
23
26
  this.init();
24
27
  }
25
28
  init() {
@@ -88,7 +91,7 @@ class DLOB {
88
91
  .get(marketType)
89
92
  .add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
90
93
  }
91
- (_a = this.getListForOnChainOrder(order, slot, isUserProtectedMaker)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerView);
94
+ (_a = this.getListForOnChainOrder(order, slot, isUserProtectedMaker)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerParamsMap[marketType].get(order.marketIndex));
92
95
  if (onInsert) {
93
96
  onInsert();
94
97
  }
@@ -106,7 +109,7 @@ class DLOB {
106
109
  this.orderLists
107
110
  .get(marketType)
108
111
  .get(marketIndex)
109
- .signedMsg[bidOrAsk].insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerView);
112
+ .signedMsg[bidOrAsk].insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerParamsMap[marketType].get(order.marketIndex));
110
113
  if (onInsert) {
111
114
  onInsert();
112
115
  }
@@ -215,7 +218,7 @@ class DLOB {
215
218
  for (const nodeToUpdate of nodesToUpdate) {
216
219
  const { side, node } = nodeToUpdate;
217
220
  nodeLists.takingLimit[side].remove(node.order, node.userAccount);
218
- nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount, node.isProtectedMaker, this.protectedMakerView);
221
+ nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount, node.isProtectedMaker, this.protectedMakerParamsMap[marketTypeStr].get(node.order.marketIndex));
219
222
  }
220
223
  }
221
224
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="bn.js" />
2
- import { BN, OraclePriceData, Order } from '..';
2
+ import { BN, OraclePriceData, Order, ProtectedMakerParams } from '..';
3
3
  export interface DLOBNode {
4
4
  getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
5
5
  isVammNode(): boolean;
@@ -8,7 +8,7 @@ export interface DLOBNode {
8
8
  haveFilled: boolean;
9
9
  userAccount: string | undefined;
10
10
  isProtectedMaker: boolean;
11
- applyProtectedMakerOffset: boolean;
11
+ protectedMakerParams?: ProtectedMakerParams;
12
12
  isSignedMsg: boolean | undefined;
13
13
  }
14
14
  export declare abstract class OrderNode implements DLOBNode {
@@ -18,9 +18,9 @@ export declare abstract class OrderNode implements DLOBNode {
18
18
  haveFilled: boolean;
19
19
  haveTrigger: boolean;
20
20
  isProtectedMaker: boolean;
21
- applyProtectedMakerOffset: boolean;
21
+ protectedMakerParams?: ProtectedMakerParams;
22
22
  isSignedMsg: boolean;
23
- constructor(order: Order, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean, isSignedMsg?: boolean);
23
+ constructor(order: Order, userAccount: string, isProtectedMaker: boolean, protectedMakerParams?: ProtectedMakerParams, isSignedMsg?: boolean);
24
24
  abstract getSortValue(order: Order): BN;
25
25
  getLabel(): string;
26
26
  getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
@@ -68,4 +68,4 @@ export type DLOBNodeMap = {
68
68
  signedMsg: SignedMsgOrderNode;
69
69
  };
70
70
  export type DLOBNodeType = 'signedMsg' | 'restingLimit' | 'takingLimit' | 'floatingLimit' | 'protectedFloatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
71
- export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean): DLOBNodeMap[T];
71
+ export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, userAccount: string, isProtectedMaker: boolean, protectedMakerParams?: ProtectedMakerParams): DLOBNodeMap[T];
@@ -2,10 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNode = exports.SignedMsgOrderNode = exports.TriggerOrderNode = exports.MarketOrderNode = exports.FloatingLimitOrderNode = exports.RestingLimitOrderNode = exports.TakingLimitOrderNode = exports.OrderNode = void 0;
4
4
  const __1 = require("..");
5
- // import { PublicKey } from '@solana/web3.js';
6
5
  const NodeList_1 = require("./NodeList");
7
6
  class OrderNode {
8
- constructor(order, userAccount, isProtectedMaker, applyProtectedMakerOffset, isSignedMsg = false) {
7
+ constructor(order, userAccount, isProtectedMaker, protectedMakerParams, isSignedMsg = false) {
9
8
  this.haveFilled = false;
10
9
  this.haveTrigger = false;
11
10
  // Copy the order over to the node
@@ -13,7 +12,7 @@ class OrderNode {
13
12
  this.userAccount = userAccount;
14
13
  this.sortValue = this.getSortValue(order);
15
14
  this.isProtectedMaker = isProtectedMaker;
16
- this.applyProtectedMakerOffset = applyProtectedMakerOffset;
15
+ this.protectedMakerParams = protectedMakerParams;
17
16
  this.isSignedMsg = isSignedMsg;
18
17
  }
19
18
  getLabel() {
@@ -30,7 +29,7 @@ class OrderNode {
30
29
  return msg;
31
30
  }
32
31
  getPrice(oraclePriceData, slot) {
33
- return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot, undefined, this.applyProtectedMakerOffset && this.isProtectedMaker);
32
+ return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot, undefined, this.isProtectedMaker ? this.protectedMakerParams : undefined);
34
33
  }
35
34
  isBaseFilled() {
36
35
  return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
@@ -49,7 +48,7 @@ exports.TakingLimitOrderNode = TakingLimitOrderNode;
49
48
  class RestingLimitOrderNode extends OrderNode {
50
49
  getSortValue(order) {
51
50
  let sortValue = order.price;
52
- if (this.applyProtectedMakerOffset && this.isProtectedMaker) {
51
+ if (this.protectedMakerParams && this.isProtectedMaker) {
53
52
  const offset = sortValue.divn(1000);
54
53
  if ((0, __1.isVariant)(order.direction, 'long')) {
55
54
  sortValue = sortValue.sub(offset);
@@ -83,27 +82,27 @@ exports.TriggerOrderNode = TriggerOrderNode;
83
82
  // We'll use the signedMsg uuid for the order id since it's not yet on-chain
84
83
  class SignedMsgOrderNode extends OrderNode {
85
84
  constructor(order, userAccount) {
86
- super(order, userAccount, false, false, true);
85
+ super(order, userAccount, false, undefined, true);
87
86
  }
88
87
  getSortValue(order) {
89
88
  return order.slot;
90
89
  }
91
90
  }
92
91
  exports.SignedMsgOrderNode = SignedMsgOrderNode;
93
- function createNode(nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
92
+ function createNode(nodeType, order, userAccount, isProtectedMaker, protectedMakerParams) {
94
93
  switch (nodeType) {
95
94
  case 'floatingLimit':
96
- return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
95
+ return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, protectedMakerParams);
97
96
  case 'protectedFloatingLimit':
98
- return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
97
+ return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, protectedMakerParams);
99
98
  case 'restingLimit':
100
- return new RestingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
99
+ return new RestingLimitOrderNode(order, userAccount, isProtectedMaker, protectedMakerParams);
101
100
  case 'takingLimit':
102
- return new TakingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
101
+ return new TakingLimitOrderNode(order, userAccount, isProtectedMaker, protectedMakerParams);
103
102
  case 'market':
104
- return new MarketOrderNode(order, userAccount, isProtectedMaker, false);
103
+ return new MarketOrderNode(order, userAccount, isProtectedMaker, undefined);
105
104
  case 'trigger':
106
- return new TriggerOrderNode(order, userAccount, isProtectedMaker, false);
105
+ return new TriggerOrderNode(order, userAccount, isProtectedMaker, undefined);
107
106
  case 'signedMsg':
108
107
  return new SignedMsgOrderNode(order, userAccount);
109
108
  default:
@@ -3,7 +3,7 @@
3
3
  import { DLOB } from './DLOB';
4
4
  import { EventEmitter } from 'events';
5
5
  import StrictEventEmitter from 'strict-event-emitter-types';
6
- import { DLOBSource, DLOBSubscriberEvents, DLOBSubscriptionConfig, SlotSource } from './types';
6
+ import { DLOBSource, DLOBSubscriberEvents, DLOBSubscriptionConfig, ProtectMakerParamsMap, SlotSource } from './types';
7
7
  import { DriftClient } from '../driftClient';
8
8
  import { MarketType } from '../types';
9
9
  import { L2OrderBook, L2OrderBookGenerator, L3OrderBook } from './orderBookLevels';
@@ -18,6 +18,7 @@ export declare class DLOBSubscriber {
18
18
  protectedMakerView: boolean;
19
19
  constructor(config: DLOBSubscriptionConfig);
20
20
  subscribe(): Promise<void>;
21
+ getProtectedMakerParamsMap(): ProtectMakerParamsMap | undefined;
21
22
  updateDLOB(): Promise<void>;
22
23
  getDLOB(): DLOB;
23
24
  /**
@@ -5,6 +5,7 @@ const DLOB_1 = require("./DLOB");
5
5
  const events_1 = require("events");
6
6
  const types_1 = require("../types");
7
7
  const orderBookLevels_1 = require("./orderBookLevels");
8
+ const protectedMakerParams_1 = require("../math/protectedMakerParams");
8
9
  class DLOBSubscriber {
9
10
  constructor(config) {
10
11
  this.driftClient = config.driftClient;
@@ -12,7 +13,7 @@ class DLOBSubscriber {
12
13
  this.slotSource = config.slotSource;
13
14
  this.updateFrequency = config.updateFrequency;
14
15
  this.protectedMakerView = config.protectedMakerView || false;
15
- this.dlob = new DLOB_1.DLOB(this.protectedMakerView);
16
+ this.dlob = new DLOB_1.DLOB(this.getProtectedMakerParamsMap());
16
17
  this.eventEmitter = new events_1.EventEmitter();
17
18
  }
18
19
  async subscribe() {
@@ -30,8 +31,13 @@ class DLOBSubscriber {
30
31
  }
31
32
  }, this.updateFrequency);
32
33
  }
34
+ getProtectedMakerParamsMap() {
35
+ return this.protectedMakerView
36
+ ? (0, protectedMakerParams_1.getProtectedMakerParamsMap)(this.driftClient.getPerpMarketAccounts())
37
+ : undefined;
38
+ }
33
39
  async updateDLOB() {
34
- this.dlob = await this.dlobSource.getDLOB(this.slotSource.getSlot(), this.protectedMakerView);
40
+ this.dlob = await this.dlobSource.getDLOB(this.slotSource.getSlot(), this.getProtectedMakerParamsMap());
35
41
  }
36
42
  getDLOB() {
37
43
  return this.dlob;
@@ -1,4 +1,4 @@
1
- import { MarketTypeStr, Order } from '..';
1
+ import { MarketTypeStr, Order, ProtectedMakerParams } from '..';
2
2
  import { DLOBNode, DLOBNodeMap } from './DLOBNode';
3
3
  export type SortDirection = 'asc' | 'desc';
4
4
  export declare function getOrderSignature(orderId: number, userAccount: string): string;
@@ -13,7 +13,7 @@ export declare class NodeList<NodeType extends keyof DLOBNodeMap> implements DLO
13
13
  nodeMap: Map<string, DLOBNodeMap[NodeType]>;
14
14
  constructor(nodeType: NodeType, sortDirection: SortDirection);
15
15
  clear(): void;
16
- insert(order: Order, marketType: MarketTypeStr, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean): void;
16
+ insert(order: Order, marketType: MarketTypeStr, userAccount: string, isProtectedMaker: boolean, protectedMakerParamsMap?: ProtectedMakerParams): void;
17
17
  prependNode(currentNode: DLOBNodeMap[NodeType], newNode: DLOBNodeMap[NodeType]): boolean;
18
18
  update(order: Order, userAccount: string): void;
19
19
  remove(order: Order, userAccount: string): void;
@@ -19,11 +19,11 @@ class NodeList {
19
19
  this.length = 0;
20
20
  this.nodeMap.clear();
21
21
  }
22
- insert(order, marketType, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
22
+ insert(order, marketType, userAccount, isProtectedMaker, protectedMakerParamsMap) {
23
23
  if (!(0, __1.isVariant)(order.status, 'open')) {
24
24
  return;
25
25
  }
26
- const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
26
+ const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker, protectedMakerParamsMap);
27
27
  const orderSignature = getOrderSignature(order.orderId, userAccount);
28
28
  if (this.nodeMap.has(orderSignature)) {
29
29
  return;
@@ -1,5 +1,7 @@
1
1
  import { DLOB } from './DLOB';
2
2
  import { DriftClient } from '../driftClient';
3
+ import { ProtectedMakerParams } from '../types';
4
+ import { MarketTypeStr } from '../types';
3
5
  export type DLOBSubscriptionConfig = {
4
6
  driftClient: DriftClient;
5
7
  dlobSource: DLOBSource;
@@ -12,8 +14,11 @@ export interface DLOBSubscriberEvents {
12
14
  error: (e: Error) => void;
13
15
  }
14
16
  export interface DLOBSource {
15
- getDLOB(slot: number, protectedMakerView?: boolean): Promise<DLOB>;
17
+ getDLOB(slot: number, protectedMakerParamsMap?: ProtectMakerParamsMap): Promise<DLOB>;
16
18
  }
17
19
  export interface SlotSource {
18
20
  getSlot(): number;
19
21
  }
22
+ export type ProtectMakerParamsMap = {
23
+ [marketType in MarketTypeStr]: Map<number, ProtectedMakerParams>;
24
+ };
@@ -167,8 +167,8 @@ export declare class DriftClient {
167
167
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
168
168
  initializeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
169
169
  getInitializeSignedMsgUserOrdersAccountIx(authority: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
170
- resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
171
- getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
170
+ resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, userSubaccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
171
+ getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number, userSubaccountId?: number): Promise<TransactionInstruction>;
172
172
  initializeSignedMsgWsDelegatesAccount(authority: PublicKey, delegates?: PublicKey[], txParams?: TxParams): Promise<TransactionSignature>;
173
173
  getInitializeSignedMsgWsDelegatesAccountIx(authority: PublicKey, delegates?: PublicKey[]): Promise<TransactionInstruction>;
174
174
  addSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
@@ -245,8 +245,8 @@ export declare class DriftClient {
245
245
  * Forces a fetch to rpc before returning accounts. Useful for anchor tests.
246
246
  * @param subAccountId
247
247
  */
248
- forceGetUserAccount(subAccountId?: number): Promise<UserAccount | undefined>;
249
- getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
248
+ forceGetUserAccount(subAccountId?: number, authority?: PublicKey): Promise<UserAccount | undefined>;
249
+ getUserAccountAndSlot(subAccountId?: number, authority?: PublicKey): DataAndSlot<UserAccount> | undefined;
250
250
  getSpotPosition(marketIndex: number, subAccountId?: number): SpotPosition | undefined;
251
251
  getQuoteAssetTokenAmount(): BN;
252
252
  /**
@@ -642,7 +642,7 @@ class DriftClient {
642
642
  const initializeUserAccountIx = await this.program.instruction.initializeSignedMsgUserOrders(numOrders, {
643
643
  accounts: {
644
644
  signedMsgUserOrders: signedMsgUserAccountPublicKey,
645
- authority: this.wallet.publicKey,
645
+ authority,
646
646
  payer: this.wallet.publicKey,
647
647
  rent: anchor.web3.SYSVAR_RENT_PUBKEY,
648
648
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -650,19 +650,21 @@ class DriftClient {
650
650
  });
651
651
  return [signedMsgUserAccountPublicKey, initializeUserAccountIx];
652
652
  }
653
- async resizeSignedMsgUserOrders(authority, numOrders, txParams) {
654
- const resizeUserAccountIx = await this.getResizeSignedMsgUserOrdersInstruction(authority, numOrders);
653
+ async resizeSignedMsgUserOrders(authority, numOrders, userSubaccountId, txParams) {
654
+ const resizeUserAccountIx = await this.getResizeSignedMsgUserOrdersInstruction(authority, numOrders, userSubaccountId);
655
655
  const tx = await this.buildTransaction([resizeUserAccountIx], txParams);
656
656
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
657
657
  return txSig;
658
658
  }
659
- async getResizeSignedMsgUserOrdersInstruction(authority, numOrders) {
659
+ async getResizeSignedMsgUserOrdersInstruction(authority, numOrders, userSubaccountId) {
660
660
  const signedMsgUserAccountPublicKey = (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority);
661
661
  const resizeUserAccountIx = await this.program.instruction.resizeSignedMsgUserOrders(numOrders, {
662
662
  accounts: {
663
663
  signedMsgUserOrders: signedMsgUserAccountPublicKey,
664
- authority: this.wallet.publicKey,
664
+ authority,
665
+ payer: this.wallet.publicKey,
665
666
  systemProgram: anchor.web3.SystemProgram.programId,
667
+ user: await (0, pda_1.getUserAccountPublicKey)(this.program.programId, authority, userSubaccountId),
666
668
  },
667
669
  });
668
670
  return resizeUserAccountIx;
@@ -1193,12 +1195,12 @@ class DriftClient {
1193
1195
  * Forces a fetch to rpc before returning accounts. Useful for anchor tests.
1194
1196
  * @param subAccountId
1195
1197
  */
1196
- async forceGetUserAccount(subAccountId) {
1197
- await this.getUser(subAccountId).fetchAccounts();
1198
- return this.getUser(subAccountId).getUserAccount();
1198
+ async forceGetUserAccount(subAccountId, authority) {
1199
+ await this.getUser(subAccountId, authority).fetchAccounts();
1200
+ return this.getUser(subAccountId, authority).getUserAccount();
1199
1201
  }
1200
- getUserAccountAndSlot(subAccountId) {
1201
- return this.getUser(subAccountId).getUserAccountAndSlot();
1202
+ getUserAccountAndSlot(subAccountId, authority) {
1203
+ return this.getUser(subAccountId, authority).getUserAccountAndSlot();
1202
1204
  }
1203
1205
  getSpotPosition(marketIndex, subAccountId) {
1204
1206
  return this.getUserAccount(subAccountId).spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
@@ -1271,9 +1273,11 @@ class DriftClient {
1271
1273
  var _a;
1272
1274
  const { oracleAccountMap, spotMarketAccountMap, perpMarketAccountMap } = this.getRemainingAccountMapsForUsers(params.userAccounts);
1273
1275
  if (params.useMarketLastSlotCache) {
1274
- const lastUserSlot = (_a = this.getUserAccountAndSlot(params.userAccounts.length === 1
1276
+ const lastUserSlot = (_a = this.getUserAccountAndSlot(params.userAccounts.length > 0
1275
1277
  ? params.userAccounts[0].subAccountId
1276
- : this.activeSubAccountId)) === null || _a === void 0 ? void 0 : _a.slot;
1278
+ : this.activeSubAccountId, params.userAccounts.length > 0
1279
+ ? params.userAccounts[0].authority
1280
+ : this.authority)) === null || _a === void 0 ? void 0 : _a.slot;
1277
1281
  for (const [marketIndex, slot,] of this.perpMarketLastSlotCache.entries()) {
1278
1282
  // if cache has more recent slot than user positions account slot, add market to remaining accounts
1279
1283
  // otherwise remove from slot
@@ -1471,7 +1475,7 @@ class DriftClient {
1471
1475
  let remainingAccounts = [];
1472
1476
  if (userInitialized) {
1473
1477
  remainingAccounts = this.getRemainingAccounts({
1474
- userAccounts: [await this.forceGetUserAccount()],
1478
+ userAccounts: [await this.forceGetUserAccount(subAccountId)],
1475
1479
  useMarketLastSlotCache: true,
1476
1480
  writableSpotMarketIndexes: [marketIndex],
1477
1481
  });
@@ -1856,8 +1860,8 @@ class DriftClient {
1856
1860
  return txSig;
1857
1861
  }
1858
1862
  async getTransferPerpPositionIx(fromSubAccountId, toSubAccountId, marketIndex, amount) {
1859
- const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, fromSubAccountId);
1860
- const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, toSubAccountId);
1863
+ const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, fromSubAccountId);
1864
+ const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, toSubAccountId);
1861
1865
  const remainingAccounts = this.getRemainingAccounts({
1862
1866
  userAccounts: [
1863
1867
  this.getUserAccount(fromSubAccountId),
@@ -1922,7 +1926,7 @@ class DriftClient {
1922
1926
  const userAccount = (await this.program.account.user.fetch(userAccountPublicKey));
1923
1927
  const remainingAccounts = this.getRemainingAccounts({
1924
1928
  userAccounts: [userAccount],
1925
- useMarketLastSlotCache: true,
1929
+ useMarketLastSlotCache: false,
1926
1930
  writablePerpMarketIndexes: [marketIndex],
1927
1931
  });
1928
1932
  if (sharesToBurn == undefined) {
@@ -3416,7 +3420,7 @@ class DriftClient {
3416
3420
  async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex) {
3417
3421
  const remainingAccounts = this.getRemainingAccounts({
3418
3422
  userAccounts: [takerInfo.takerUserAccount],
3419
- useMarketLastSlotCache: true,
3423
+ useMarketLastSlotCache: false,
3420
3424
  readablePerpMarketIndex: marketIndex,
3421
3425
  });
3422
3426
  const messageLengthBuffer = Buffer.alloc(2);
@@ -3458,7 +3462,7 @@ class DriftClient {
3458
3462
  this.getUserAccount(subAccountId),
3459
3463
  takerInfo.takerUserAccount,
3460
3464
  ],
3461
- useMarketLastSlotCache: true,
3465
+ useMarketLastSlotCache: false,
3462
3466
  writablePerpMarketIndexes: [orderParams.marketIndex],
3463
3467
  });
3464
3468
  if (referrerInfo) {
@@ -3897,7 +3901,7 @@ class DriftClient {
3897
3901
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
3898
3902
  const remainingAccounts = this.getRemainingAccounts({
3899
3903
  userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
3900
- useMarketLastSlotCache: true,
3904
+ useMarketLastSlotCache: false,
3901
3905
  writablePerpMarketIndexes: [marketIndex],
3902
3906
  });
3903
3907
  return await this.program.instruction.liquidatePerp(marketIndex, maxBaseAssetAmount, limitPrice !== null && limitPrice !== void 0 ? limitPrice : null, {
@@ -3926,7 +3930,7 @@ class DriftClient {
3926
3930
  userAccount,
3927
3931
  ...makerInfos.map((makerInfo) => makerInfo.makerUserAccount),
3928
3932
  ],
3929
- useMarketLastSlotCache: true,
3933
+ useMarketLastSlotCache: false,
3930
3934
  writablePerpMarketIndexes: [marketIndex],
3931
3935
  });
3932
3936
  for (const makerInfo of makerInfos) {
@@ -3965,7 +3969,7 @@ class DriftClient {
3965
3969
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
3966
3970
  const remainingAccounts = this.getRemainingAccounts({
3967
3971
  userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
3968
- useMarketLastSlotCache: true,
3972
+ useMarketLastSlotCache: false,
3969
3973
  writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
3970
3974
  });
3971
3975
  return await this.program.instruction.liquidateSpot(assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice || null, {
@@ -4591,7 +4595,7 @@ class DriftClient {
4591
4595
  async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
4592
4596
  const remainingAccounts = this.getRemainingAccounts({
4593
4597
  userAccounts: [this.getUserAccount()],
4594
- useMarketLastSlotCache: true,
4598
+ useMarketLastSlotCache: false,
4595
4599
  writablePerpMarketIndexes: [perpMarketIndex],
4596
4600
  writableSpotMarketIndexes: [spotMarketIndex],
4597
4601
  });
@@ -4862,7 +4866,7 @@ class DriftClient {
4862
4866
  this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
4863
4867
  }
4864
4868
  }
4865
- const [pullIxs, _responses, success] = await on_demand_1.PullFeed.fetchUpdateManyIx(program, {
4869
+ const [pullIxs, _responses, success] = await on_demand_1.PullFeed.fetchUpdateManyLightIx(program, {
4866
4870
  feeds,
4867
4871
  numSignatures,
4868
4872
  recentSlothashes: recentSlothash
@@ -104,7 +104,7 @@
104
104
  {
105
105
  "name": "authority",
106
106
  "isMut": false,
107
- "isSigner": true
107
+ "isSigner": false
108
108
  },
109
109
  {
110
110
  "name": "payer",
@@ -139,6 +139,16 @@
139
139
  },
140
140
  {
141
141
  "name": "authority",
142
+ "isMut": false,
143
+ "isSigner": false
144
+ },
145
+ {
146
+ "name": "user",
147
+ "isMut": false,
148
+ "isSigner": false
149
+ },
150
+ {
151
+ "name": "payer",
142
152
  "isMut": true,
143
153
  "isSigner": true
144
154
  },
@@ -7687,12 +7697,20 @@
7687
7697
  "name": "highLeverageMarginRatioMaintenance",
7688
7698
  "type": "u16"
7689
7699
  },
7700
+ {
7701
+ "name": "protectedMakerLimitPriceDivisor",
7702
+ "type": "u8"
7703
+ },
7704
+ {
7705
+ "name": "protectedMakerDynamicDivisor",
7706
+ "type": "u8"
7707
+ },
7690
7708
  {
7691
7709
  "name": "padding",
7692
7710
  "type": {
7693
7711
  "array": [
7694
7712
  "u8",
7695
- 38
7713
+ 36
7696
7714
  ]
7697
7715
  }
7698
7716
  }
@@ -14986,6 +15004,11 @@
14986
15004
  "code": 6312,
14987
15005
  "name": "InvalidTransferPerpPosition",
14988
15006
  "msg": "Invalid Transfer Perp Position"
15007
+ },
15008
+ {
15009
+ "code": 6313,
15010
+ "name": "InvalidSignedMsgUserOrdersResize",
15011
+ "msg": "Invalid SignedMsgUserOrders resize"
14989
15012
  }
14990
15013
  ],
14991
15014
  "metadata": {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { User } from '../user';
3
- import { PerpMarketAccount, AMM, Order, PositionDirection } from '../types';
3
+ import { PerpMarketAccount, AMM, Order, PositionDirection, ProtectedMakerParams } from '../types';
4
4
  import { BN } from '@coral-xyz/anchor';
5
5
  import { OraclePriceData } from '../oracles/types';
6
6
  export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
@@ -8,7 +8,8 @@ export declare function isOrderRiskIncreasingInSameDirection(user: User, order:
8
8
  export declare function isOrderReduceOnly(user: User, order: Order): boolean;
9
9
  export declare function standardizeBaseAssetAmount(baseAssetAmount: BN, stepSize: BN): BN;
10
10
  export declare function standardizePrice(price: BN, tickSize: BN, direction: PositionDirection): BN;
11
- export declare function getLimitPrice(order: Order, oraclePriceData: OraclePriceData, slot: number, fallbackPrice?: BN, protectedMaker?: boolean): BN | undefined;
11
+ export declare function getLimitPrice(order: Order, oraclePriceData: OraclePriceData, slot: number, fallbackPrice?: BN, protectedMakerParams?: ProtectedMakerParams): BN | undefined;
12
+ export declare function applyProtectedMakerParams(limitPrice: BN, direction: PositionDirection, protectedMakerParams: ProtectedMakerParams): BN;
12
13
  export declare function hasLimitPrice(order: Order, slot: number): boolean;
13
14
  export declare function hasAuctionPrice(order: Order, slot: number): boolean;
14
15
  export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number, ts: number, minAuctionDuration: number): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSignedMsgOrder = exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
3
+ exports.isSignedMsgOrder = exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.applyProtectedMakerParams = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const anchor_1 = require("@coral-xyz/anchor");
@@ -96,7 +96,7 @@ function standardizePrice(price, tickSize, direction) {
96
96
  }
97
97
  }
98
98
  exports.standardizePrice = standardizePrice;
99
- function getLimitPrice(order, oraclePriceData, slot, fallbackPrice, protectedMaker) {
99
+ function getLimitPrice(order, oraclePriceData, slot, fallbackPrice, protectedMakerParams) {
100
100
  let limitPrice;
101
101
  if (hasAuctionPrice(order, slot)) {
102
102
  limitPrice = (0, auction_1.getAuctionPrice)(order, slot, oraclePriceData.price);
@@ -110,18 +110,30 @@ function getLimitPrice(order, oraclePriceData, slot, fallbackPrice, protectedMak
110
110
  else {
111
111
  limitPrice = order.price;
112
112
  }
113
- if (protectedMaker) {
114
- const offset = limitPrice.divn(1000);
115
- if ((0, types_1.isVariant)(order.direction, 'long')) {
116
- limitPrice = limitPrice.sub(offset);
117
- }
118
- else {
119
- limitPrice = limitPrice.add(offset);
120
- }
113
+ if (protectedMakerParams) {
114
+ limitPrice = applyProtectedMakerParams(limitPrice, order.direction, protectedMakerParams);
121
115
  }
122
116
  return limitPrice;
123
117
  }
124
118
  exports.getLimitPrice = getLimitPrice;
119
+ function applyProtectedMakerParams(limitPrice, direction, protectedMakerParams) {
120
+ const minOffset = protectedMakerParams.tickSize.muln(8);
121
+ let limitPriceBpsDivisor;
122
+ if (protectedMakerParams.limitPriceDivisor > 0) {
123
+ limitPriceBpsDivisor = 10000 / protectedMakerParams.limitPriceDivisor;
124
+ }
125
+ else {
126
+ limitPriceBpsDivisor = 1000;
127
+ }
128
+ const limitPriceOffset = anchor_1.BN.min(anchor_1.BN.max(anchor_1.BN.max(limitPrice.divn(limitPriceBpsDivisor), minOffset), protectedMakerParams.dynamicOffset), limitPrice.divn(20));
129
+ if ((0, types_1.isVariant)(direction, 'long')) {
130
+ return anchor_1.BN.max(limitPrice.sub(limitPriceOffset), protectedMakerParams.tickSize);
131
+ }
132
+ else {
133
+ return limitPrice.add(limitPriceOffset);
134
+ }
135
+ }
136
+ exports.applyProtectedMakerParams = applyProtectedMakerParams;
125
137
  function hasLimitPrice(order, slot) {
126
138
  return (order.price.gt(numericConstants_1.ZERO) ||
127
139
  order.oraclePriceOffset != 0 ||
@@ -0,0 +1,4 @@
1
+ import { ProtectMakerParamsMap } from '..';
2
+ import { PerpMarketAccount, ProtectedMakerParams } from '../types';
3
+ export declare function getProtectedMakerParams(perpMarket: PerpMarketAccount): ProtectedMakerParams;
4
+ export declare function getProtectedMakerParamsMap(perpMarkets: PerpMarketAccount[]): ProtectMakerParamsMap;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProtectedMakerParamsMap = exports.getProtectedMakerParams = void 0;
4
+ const __1 = require("..");
5
+ function getProtectedMakerParams(perpMarket) {
6
+ let dynamicOffset;
7
+ if (perpMarket.protectedMakerDynamicDivisor > 0) {
8
+ dynamicOffset = __1.BN.max(perpMarket.amm.oracleStd, perpMarket.amm.markStd).divn(perpMarket.protectedMakerDynamicDivisor);
9
+ }
10
+ else {
11
+ dynamicOffset = 0;
12
+ }
13
+ return {
14
+ tickSize: perpMarket.amm.orderTickSize,
15
+ limitPriceDivisor: perpMarket.protectedMakerLimitPriceDivisor,
16
+ dynamicOffset: dynamicOffset,
17
+ };
18
+ }
19
+ exports.getProtectedMakerParams = getProtectedMakerParams;
20
+ function getProtectedMakerParamsMap(perpMarkets) {
21
+ const map = {
22
+ perp: new Map(),
23
+ spot: new Map(),
24
+ };
25
+ for (const perpMarket of perpMarkets) {
26
+ const marketIndex = perpMarket.marketIndex;
27
+ const protectedMakerParams = getProtectedMakerParams(perpMarket);
28
+ map.perp.set(marketIndex, protectedMakerParams);
29
+ }
30
+ return map;
31
+ }
32
+ exports.getProtectedMakerParamsMap = getProtectedMakerParamsMap;