@drift-labs/sdk 0.2.0-temp.0 → 0.2.0-temp.1

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 (115) hide show
  1. package/lib/admin.d.ts +7 -5
  2. package/lib/admin.js +34 -11
  3. package/lib/clearingHouse.d.ts +23 -9
  4. package/lib/clearingHouse.js +335 -95
  5. package/lib/clearingHouseUser.d.ts +2 -2
  6. package/lib/clearingHouseUser.js +8 -17
  7. package/lib/config.js +1 -1
  8. package/lib/constants/banks.js +9 -2
  9. package/lib/constants/numericConstants.d.ts +1 -0
  10. package/lib/constants/numericConstants.js +2 -1
  11. package/lib/idl/clearing_house.json +689 -153
  12. package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  13. package/lib/index.d.ts +3 -2
  14. package/lib/index.js +7 -2
  15. package/lib/math/amm.js +7 -35
  16. package/lib/math/auction.js +4 -1
  17. package/lib/math/orders.d.ts +2 -2
  18. package/lib/math/orders.js +19 -2
  19. package/lib/math/position.js +3 -1
  20. package/lib/math/trade.d.ts +1 -1
  21. package/lib/math/trade.js +7 -10
  22. package/lib/orderParams.d.ts +14 -5
  23. package/lib/orderParams.js +8 -96
  24. package/lib/orders.js +1 -1
  25. package/lib/slot/SlotSubscriber.d.ts +7 -0
  26. package/lib/slot/SlotSubscriber.js +3 -0
  27. package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
  28. package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
  29. package/lib/tx/utils.js +1 -1
  30. package/lib/types.d.ts +132 -14
  31. package/lib/types.js +52 -1
  32. package/lib/util/computeUnits.js +1 -1
  33. package/package.json +3 -3
  34. package/src/accounts/bulkAccountLoader.js +197 -0
  35. package/src/accounts/bulkUserSubscription.js +33 -0
  36. package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
  37. package/src/accounts/pollingOracleSubscriber.js +93 -0
  38. package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
  39. package/src/accounts/pollingUserAccountSubscriber.js +132 -0
  40. package/src/accounts/types.js +10 -0
  41. package/src/accounts/utils.js +7 -0
  42. package/src/accounts/webSocketAccountSubscriber.js +93 -0
  43. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
  44. package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
  45. package/src/addresses/marketAddresses.js +26 -0
  46. package/src/admin.js +517 -0
  47. package/src/admin.ts +53 -14
  48. package/src/assert/assert.js +9 -0
  49. package/src/clearingHouse.ts +510 -131
  50. package/src/clearingHouseConfig.js +2 -0
  51. package/src/clearingHouseUser.ts +12 -23
  52. package/src/clearingHouseUserConfig.js +2 -0
  53. package/src/config.js +67 -0
  54. package/src/config.ts +1 -1
  55. package/src/constants/banks.js +42 -0
  56. package/src/constants/banks.ts +9 -2
  57. package/src/constants/markets.js +42 -0
  58. package/src/constants/numericConstants.js +41 -0
  59. package/src/constants/numericConstants.ts +1 -0
  60. package/src/events/eventList.js +77 -0
  61. package/src/events/eventSubscriber.js +139 -0
  62. package/src/events/fetchLogs.js +50 -0
  63. package/src/events/pollingLogProvider.js +64 -0
  64. package/src/events/sort.js +44 -0
  65. package/src/events/txEventCache.js +71 -0
  66. package/src/events/types.js +20 -0
  67. package/src/events/webSocketLogProvider.js +41 -0
  68. package/src/examples/makeTradeExample.js +80 -0
  69. package/src/factory/bigNum.js +390 -0
  70. package/src/factory/oracleClient.js +20 -0
  71. package/src/idl/clearing_house.json +689 -153
  72. package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  73. package/src/index.js +69 -0
  74. package/src/index.ts +3 -2
  75. package/src/math/amm.js +369 -0
  76. package/src/math/amm.ts +19 -49
  77. package/src/math/auction.js +42 -0
  78. package/src/math/auction.ts +5 -1
  79. package/src/math/conversion.js +11 -0
  80. package/src/math/funding.js +248 -0
  81. package/src/math/oracles.js +26 -0
  82. package/src/math/orders.ts +17 -3
  83. package/src/math/position.ts +5 -1
  84. package/src/math/repeg.js +128 -0
  85. package/src/math/state.js +15 -0
  86. package/src/math/trade.js +253 -0
  87. package/src/math/trade.ts +23 -25
  88. package/src/math/utils.js +0 -1
  89. package/src/mockUSDCFaucet.js +280 -0
  90. package/src/oracles/oracleClientCache.js +19 -0
  91. package/src/oracles/pythClient.js +46 -0
  92. package/src/oracles/quoteAssetOracleClient.js +32 -0
  93. package/src/oracles/switchboardClient.js +69 -0
  94. package/src/oracles/types.js +2 -0
  95. package/src/orderParams.js +20 -0
  96. package/src/orderParams.ts +20 -141
  97. package/src/orders.ts +2 -1
  98. package/src/slot/SlotSubscriber.js +39 -0
  99. package/src/slot/SlotSubscriber.ts +11 -1
  100. package/src/token/index.js +38 -0
  101. package/src/tokenFaucet.js +189 -0
  102. package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
  103. package/src/tx/types.js +2 -0
  104. package/src/tx/utils.js +17 -0
  105. package/src/tx/utils.ts +1 -1
  106. package/src/types.js +125 -0
  107. package/src/types.ts +128 -15
  108. package/src/userName.js +20 -0
  109. package/src/util/computeUnits.js +21 -11
  110. package/src/util/computeUnits.ts +1 -1
  111. package/src/util/getTokenAddress.js +9 -0
  112. package/src/util/promiseTimeout.js +14 -0
  113. package/src/util/tps.js +27 -0
  114. package/src/wallet.js +35 -0
  115. package/src/util/computeUnits.js.map +0 -1
@@ -26,74 +26,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MockUSDCFaucet = void 0;
29
+ exports.TokenFaucet = void 0;
30
30
  const anchor = __importStar(require("@project-serum/anchor"));
31
31
  const anchor_1 = require("@project-serum/anchor");
32
32
  const spl_token_1 = require("@solana/spl-token");
33
33
  const web3_js_1 = require("@solana/web3.js");
34
- const mock_usdc_faucet_json_1 = __importDefault(require("./idl/mock_usdc_faucet.json"));
35
- class MockUSDCFaucet {
36
- constructor(connection, wallet, programId, opts) {
34
+ const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
35
+ class TokenFaucet {
36
+ constructor(connection, wallet, programId, mint, opts) {
37
37
  this.connection = connection;
38
38
  this.wallet = wallet;
39
39
  this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
40
40
  const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
41
41
  this.provider = provider;
42
- this.program = new anchor_1.Program(mock_usdc_faucet_json_1.default, programId, provider);
42
+ this.program = new anchor_1.Program(token_faucet_json_1.default, programId, provider);
43
+ this.mint = mint;
43
44
  }
44
- async getMockUSDCFaucetStatePublicKeyAndNonce() {
45
- return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('mock_usdc_faucet'))], this.program.programId);
45
+ async getFaucetConfigPublicKeyAndNonce() {
46
+ return anchor.web3.PublicKey.findProgramAddress([
47
+ Buffer.from(anchor.utils.bytes.utf8.encode('faucet_config')),
48
+ this.mint.toBuffer(),
49
+ ], this.program.programId);
46
50
  }
47
- async getMockUSDCFaucetStatePublicKey() {
48
- if (this.mockUSDCFaucetStatePublicKey) {
49
- return this.mockUSDCFaucetStatePublicKey;
50
- }
51
- this.mockUSDCFaucetStatePublicKey = (await this.getMockUSDCFaucetStatePublicKeyAndNonce())[0];
52
- return this.mockUSDCFaucetStatePublicKey;
51
+ async getMintAuthority() {
52
+ return (await anchor.web3.PublicKey.findProgramAddress([
53
+ Buffer.from(anchor.utils.bytes.utf8.encode('mint_authority')),
54
+ this.mint.toBuffer(),
55
+ ], this.program.programId))[0];
56
+ }
57
+ async getFaucetConfigPublicKey() {
58
+ return (await this.getFaucetConfigPublicKeyAndNonce())[0];
53
59
  }
54
60
  async initialize() {
55
- const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getMockUSDCFaucetStatePublicKey());
56
- if (stateAccountRPCResponse.value !== null) {
57
- throw new Error('Faucet already initialized');
58
- }
59
- const fakeUSDCMint = anchor.web3.Keypair.generate();
60
- const createUSDCMintAccountIx = web3_js_1.SystemProgram.createAccount({
61
- fromPubkey: this.wallet.publicKey,
62
- newAccountPubkey: fakeUSDCMint.publicKey,
63
- lamports: await spl_token_1.Token.getMinBalanceRentForExemptMint(this.connection),
64
- space: spl_token_1.MintLayout.span,
65
- programId: spl_token_1.TOKEN_PROGRAM_ID,
66
- });
67
- const [mintAuthority, _mintAuthorityNonce] = await web3_js_1.PublicKey.findProgramAddress([fakeUSDCMint.publicKey.toBuffer()], this.program.programId);
68
- const initUSDCMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, fakeUSDCMint.publicKey, 6, mintAuthority, null);
69
- const [mockUSDCFaucetStatePublicKey, mockUSDCFaucetStateNonce] = await this.getMockUSDCFaucetStatePublicKeyAndNonce();
70
- return await this.program.rpc.initialize(mockUSDCFaucetStateNonce, {
61
+ const [faucetConfigPublicKey] = await this.getFaucetConfigPublicKeyAndNonce();
62
+ return await this.program.rpc.initialize({
71
63
  accounts: {
72
- mockUsdcFaucetState: mockUSDCFaucetStatePublicKey,
64
+ faucetConfig: faucetConfigPublicKey,
73
65
  admin: this.wallet.publicKey,
74
- mintAccount: fakeUSDCMint.publicKey,
66
+ mintAccount: this.mint,
75
67
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
76
68
  systemProgram: anchor.web3.SystemProgram.programId,
69
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
77
70
  },
78
- instructions: [createUSDCMintAccountIx, initUSDCMintIx],
79
- signers: [fakeUSDCMint],
80
71
  });
81
72
  }
82
73
  async fetchState() {
83
- return await this.program.account.mockUsdcFaucetState.fetch(await this.getMockUSDCFaucetStatePublicKey());
74
+ return await this.program.account.faucetConfig.fetch(await this.getFaucetConfigPublicKey());
84
75
  }
85
76
  async mintToUser(userTokenAccount, amount) {
86
- const state = await this.fetchState();
87
77
  return await this.program.rpc.mintToUser(amount, {
88
78
  accounts: {
89
- mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
90
- mintAccount: state.mint,
79
+ faucetConfig: await this.getFaucetConfigPublicKey(),
80
+ mintAccount: this.mint,
91
81
  userTokenAccount,
92
- mintAuthority: state.mintAuthority,
82
+ mintAuthority: await this.getMintAuthority(),
93
83
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
94
84
  },
95
85
  });
96
86
  }
87
+ async transferMintAuthority() {
88
+ return await this.program.rpc.transferMintAuthority({
89
+ accounts: {
90
+ faucetConfig: await this.getFaucetConfigPublicKey(),
91
+ mintAccount: this.mint,
92
+ mintAuthority: await this.getMintAuthority(),
93
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
94
+ admin: this.wallet.publicKey,
95
+ },
96
+ });
97
+ }
97
98
  async createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
98
99
  const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = await this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
99
100
  const tx = new web3_js_1.Transaction().add(createAssociatedAccountIx).add(mintToTx);
@@ -106,7 +107,7 @@ class MockUSDCFaucet {
106
107
  const createAssociatedAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, associateTokenPublicKey, userPublicKey, this.wallet.publicKey);
107
108
  const mintToIx = await this.program.instruction.mintToUser(amount, {
108
109
  accounts: {
109
- mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
110
+ faucetConfig: await this.getFaucetConfigPublicKey(),
110
111
  mintAccount: state.mint,
111
112
  userTokenAccount: associateTokenPublicKey,
112
113
  mintAuthority: state.mintAuthority,
@@ -143,4 +144,4 @@ class MockUSDCFaucet {
143
144
  }
144
145
  }
145
146
  }
146
- exports.MockUSDCFaucet = MockUSDCFaucet;
147
+ exports.TokenFaucet = TokenFaucet;
package/lib/tx/utils.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wrapInTx = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const COMPUTE_UNITS_DEFAULT = 200000;
6
- function wrapInTx(instruction, computeUnits = 500000 // TODO, requires less code change
6
+ function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
7
7
  ) {
8
8
  const tx = new web3_js_1.Transaction();
9
9
  if (computeUnits != COMPUTE_UNITS_DEFAULT) {
package/lib/types.d.ts CHANGED
@@ -25,6 +25,14 @@ export declare class PositionDirection {
25
25
  short: {};
26
26
  };
27
27
  }
28
+ export declare class DepositDirection {
29
+ static readonly DEPOSIT: {
30
+ deposit: {};
31
+ };
32
+ static readonly WITHDRAW: {
33
+ withdraw: {};
34
+ };
35
+ }
28
36
  export declare class OracleSource {
29
37
  static readonly PYTH: {
30
38
  pyth: {};
@@ -92,6 +100,20 @@ export declare class OrderAction {
92
100
  trigger: {};
93
101
  };
94
102
  }
103
+ export declare class OrderActionExplanation {
104
+ static readonly NONE: {
105
+ none: {};
106
+ };
107
+ static readonly BREACHED_MARGIN_REQUIREMENT: {
108
+ breachedMarginRequirement: {};
109
+ };
110
+ static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE: {
111
+ oraclePriceBreachedLimitPrice: {};
112
+ };
113
+ static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE: {
114
+ marketOrderFilledToLimitPrice: {};
115
+ };
116
+ }
95
117
  export declare class OrderTriggerCondition {
96
118
  static readonly ABOVE: {
97
119
  above: {};
@@ -118,6 +140,7 @@ export declare type DepositRecord = {
118
140
  };
119
141
  bankIndex: BN;
120
142
  amount: BN;
143
+ oraclePrice: BN;
121
144
  from?: PublicKey;
122
145
  to?: PublicKey;
123
146
  };
@@ -164,20 +187,66 @@ export declare type FundingPaymentRecord = {
164
187
  };
165
188
  export declare type LiquidationRecord = {
166
189
  ts: BN;
167
- recordId: BN;
168
- userAuthority: PublicKey;
169
190
  user: PublicKey;
170
- partial: boolean;
171
- baseAssetValue: BN;
172
- baseAssetValueClosed: BN;
173
- liquidationFee: BN;
174
- feeToLiquidator: BN;
175
- feeToInsuranceFund: BN;
176
191
  liquidator: PublicKey;
192
+ liquidationType: LiquidationType;
193
+ marginRequirement: BN;
177
194
  totalCollateral: BN;
178
- collateral: BN;
179
- unrealizedPnl: BN;
180
- marginRatio: BN;
195
+ liquidatePerp: LiquidatePerpRecord;
196
+ liquidateBorrow: LiquidateBorrowRecord;
197
+ liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
198
+ liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
199
+ };
200
+ export declare class LiquidationType {
201
+ static readonly LIQUIDATE_PERP: {
202
+ liquidatePerp: {};
203
+ };
204
+ static readonly LIQUIDATE_BORROW: {
205
+ liquidateBorrow: {};
206
+ };
207
+ static readonly LIQUIDATE_BORROW_FOR_PERP_PNL: {
208
+ liquidateBorrowForPerpPnl: {};
209
+ };
210
+ static readonly LIQUIDATE_PERP_PNL_FOR_DEPOSIT: {
211
+ liquidatePerpPnlForDeposit: {};
212
+ };
213
+ }
214
+ export declare type LiquidatePerpRecord = {
215
+ marketIndex: BN;
216
+ orderIds: BN[];
217
+ oraclePrice: BN;
218
+ baseAssetAmount: BN;
219
+ quoteAssetAmount: BN;
220
+ userPnl: BN;
221
+ liquidatorPnl: BN;
222
+ canceledOrdersFee: BN;
223
+ userOrderId: BN;
224
+ liquidatorOrderId: BN;
225
+ fillRecordId: BN;
226
+ };
227
+ export declare type LiquidateBorrowRecord = {
228
+ assetBankIndex: BN;
229
+ assetPrice: BN;
230
+ assetTransfer: BN;
231
+ liabilityBankIndex: BN;
232
+ liabilityPrice: BN;
233
+ liabilityTransfer: BN;
234
+ };
235
+ export declare type LiquidateBorrowForPerpPnlRecord = {
236
+ marketIndex: BN;
237
+ marketOraclePrice: BN;
238
+ pnlTransfer: BN;
239
+ liabilityBankIndex: BN;
240
+ liabilityPrice: BN;
241
+ liabilityTransfer: BN;
242
+ };
243
+ export declare type LiquidatePerpPnlForDepositRecord = {
244
+ marketIndex: BN;
245
+ marketOraclePrice: BN;
246
+ pnlTransfer: BN;
247
+ assetBankIndex: BN;
248
+ assetPrice: BN;
249
+ assetTransfer: BN;
181
250
  };
182
251
  export declare type OrderRecord = {
183
252
  ts: BN;
@@ -185,7 +254,10 @@ export declare type OrderRecord = {
185
254
  maker: PublicKey;
186
255
  takerOrder: Order;
187
256
  makerOrder: Order;
257
+ takerUnsettledPnl: BN;
258
+ makerUnsettledPnl: BN;
188
259
  action: OrderAction;
260
+ actionExplanation: OrderActionExplanation;
189
261
  filler: PublicKey;
190
262
  fillRecordId: BN;
191
263
  marketIndex: BN;
@@ -238,9 +310,9 @@ export declare type MarketAccount = {
238
310
  openInterest: BN;
239
311
  marginRatioInitial: number;
240
312
  marginRatioMaintenance: number;
241
- marginRatioPartial: number;
242
313
  nextFillRecordId: BN;
243
314
  pnlPool: PoolBalance;
315
+ liquidationFee: BN;
244
316
  };
245
317
  export declare type BankAccount = {
246
318
  bankIndex: BN;
@@ -263,6 +335,7 @@ export declare type BankAccount = {
263
335
  maintenanceAssetWeight: BN;
264
336
  initialLiabilityWeight: BN;
265
337
  maintenanceLiabilityWeight: BN;
338
+ liquidationFee: BN;
266
339
  };
267
340
  export declare type PoolBalance = {
268
341
  balance: BN;
@@ -277,6 +350,8 @@ export declare type AMM = {
277
350
  lastMarkPriceTwapTs: BN;
278
351
  lastOraclePriceTwap: BN;
279
352
  lastOraclePriceTwapTs: BN;
353
+ lastOracleMarkSpreadPct: BN;
354
+ lastOracleConfPct: BN;
280
355
  oracle: PublicKey;
281
356
  oracleSource: OracleSource;
282
357
  fundingPeriod: BN;
@@ -291,6 +366,8 @@ export declare type AMM = {
291
366
  totalFee: BN;
292
367
  minimumQuoteAssetTradeSize: BN;
293
368
  baseAssetAmountStepSize: BN;
369
+ maxBaseAssetAmountRatio: number;
370
+ maxSlippageRatio: number;
294
371
  lastOraclePrice: BN;
295
372
  baseSpread: number;
296
373
  curveUpdateIntensity: number;
@@ -336,6 +413,7 @@ export declare type UserAccount = {
336
413
  };
337
414
  positions: UserPosition[];
338
415
  orders: Order[];
416
+ beingLiquidated: boolean;
339
417
  };
340
418
  export declare type UserBankBalance = {
341
419
  bankIndex: BN;
@@ -375,7 +453,6 @@ export declare type OrderParams = {
375
453
  orderType: OrderType;
376
454
  userOrderId: number;
377
455
  direction: PositionDirection;
378
- quoteAssetAmount: BN;
379
456
  baseAssetAmount: BN;
380
457
  price: BN;
381
458
  marketIndex: BN;
@@ -393,10 +470,50 @@ export declare type OrderParams = {
393
470
  referrer: boolean;
394
471
  };
395
472
  };
473
+ export declare type NecessaryOrderParams = {
474
+ orderType: OrderType;
475
+ marketIndex: BN;
476
+ baseAssetAmount: BN;
477
+ direction: PositionDirection;
478
+ };
479
+ export declare type OptionalOrderParams = {
480
+ [Property in keyof OrderParams]?: OrderParams[Property];
481
+ } & NecessaryOrderParams;
482
+ export declare const DefaultOrderParams: {
483
+ orderType: {
484
+ market: {};
485
+ };
486
+ userOrderId: number;
487
+ direction: {
488
+ long: {};
489
+ };
490
+ baseAssetAmount: BN;
491
+ price: BN;
492
+ marketIndex: BN;
493
+ reduceOnly: boolean;
494
+ postOnly: boolean;
495
+ immediateOrCancel: boolean;
496
+ triggerPrice: BN;
497
+ triggerCondition: {
498
+ above: {};
499
+ };
500
+ positionLimit: BN;
501
+ oraclePriceOffset: BN;
502
+ padding0: BN;
503
+ padding1: BN;
504
+ optionalAccounts: {
505
+ discountToken: boolean;
506
+ referrer: boolean;
507
+ };
508
+ };
396
509
  export declare type MakerInfo = {
397
510
  maker: PublicKey;
398
511
  order: Order;
399
512
  };
513
+ export declare type TakerInfo = {
514
+ taker: PublicKey;
515
+ order: Order;
516
+ };
400
517
  export interface IWallet {
401
518
  signTransaction(tx: Transaction): Promise<Transaction>;
402
519
  signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
@@ -436,6 +553,7 @@ export declare type FeeStructure = {
436
553
  makerRebateNumerator: BN;
437
554
  makerRebateDenominator: BN;
438
555
  fillerRewardStructure: OrderFillerRewardStructure;
556
+ cancelOrderFee: BN;
439
557
  };
440
558
  export declare type OracleGuardRails = {
441
559
  priceDivergence: {
@@ -454,4 +572,4 @@ export declare type OrderFillerRewardStructure = {
454
572
  rewardDenominator: BN;
455
573
  timeBasedRewardLowerBound: BN;
456
574
  };
457
- export declare type MarginCategory = 'Initial' | 'Partial' | 'Maintenance';
575
+ export declare type MarginCategory = 'Initial' | 'Maintenance';
package/lib/types.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
3
+ exports.DefaultOrderParams = exports.LiquidationType = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
4
+ const _1 = require(".");
4
5
  // # Utility Types / Enums / Constants
5
6
  class SwapDirection {
6
7
  }
@@ -17,6 +18,11 @@ class PositionDirection {
17
18
  exports.PositionDirection = PositionDirection;
18
19
  PositionDirection.LONG = { long: {} };
19
20
  PositionDirection.SHORT = { short: {} };
21
+ class DepositDirection {
22
+ }
23
+ exports.DepositDirection = DepositDirection;
24
+ DepositDirection.DEPOSIT = { deposit: {} };
25
+ DepositDirection.WITHDRAW = { withdraw: {} };
20
26
  class OracleSource {
21
27
  }
22
28
  exports.OracleSource = OracleSource;
@@ -51,6 +57,19 @@ OrderAction.CANCEL = { cancel: {} };
51
57
  OrderAction.EXPIRE = { expire: {} };
52
58
  OrderAction.FILL = { fill: {} };
53
59
  OrderAction.TRIGGER = { trigger: {} };
60
+ class OrderActionExplanation {
61
+ }
62
+ exports.OrderActionExplanation = OrderActionExplanation;
63
+ OrderActionExplanation.NONE = { none: {} };
64
+ OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
65
+ breachedMarginRequirement: {},
66
+ };
67
+ OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
68
+ oraclePriceBreachedLimitPrice: {},
69
+ };
70
+ OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
71
+ marketOrderFilledToLimitPrice: {},
72
+ };
54
73
  class OrderTriggerCondition {
55
74
  }
56
75
  exports.OrderTriggerCondition = OrderTriggerCondition;
@@ -72,3 +91,35 @@ var TradeSide;
72
91
  TradeSide[TradeSide["Buy"] = 1] = "Buy";
73
92
  TradeSide[TradeSide["Sell"] = 2] = "Sell";
74
93
  })(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
94
+ class LiquidationType {
95
+ }
96
+ exports.LiquidationType = LiquidationType;
97
+ LiquidationType.LIQUIDATE_PERP = { liquidatePerp: {} };
98
+ LiquidationType.LIQUIDATE_BORROW = { liquidateBorrow: {} };
99
+ LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
100
+ liquidateBorrowForPerpPnl: {},
101
+ };
102
+ LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
103
+ liquidatePerpPnlForDeposit: {},
104
+ };
105
+ exports.DefaultOrderParams = {
106
+ orderType: OrderType.MARKET,
107
+ userOrderId: 0,
108
+ direction: PositionDirection.LONG,
109
+ baseAssetAmount: _1.ZERO,
110
+ price: _1.ZERO,
111
+ marketIndex: _1.ZERO,
112
+ reduceOnly: false,
113
+ postOnly: false,
114
+ immediateOrCancel: false,
115
+ triggerPrice: _1.ZERO,
116
+ triggerCondition: OrderTriggerCondition.ABOVE,
117
+ positionLimit: _1.ZERO,
118
+ oraclePriceOffset: _1.ZERO,
119
+ padding0: _1.ZERO,
120
+ padding1: _1.ZERO,
121
+ optionalAccounts: {
122
+ discountToken: false,
123
+ referrer: false,
124
+ },
125
+ };
@@ -4,7 +4,7 @@ exports.findComputeUnitConsumption = void 0;
4
4
  async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
5
5
  const tx = await connection.getTransaction(txSignature, { commitment });
6
6
  const computeUnits = [];
7
- const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of 200000 compute units`);
7
+ const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
8
8
  tx.meta.logMessages.forEach((logMessage) => {
9
9
  const match = logMessage.match(regex);
10
10
  if (match && match[1]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.2.0-temp.0",
3
+ "version": "0.2.0-temp.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@project-serum/anchor": "0.24.2",
33
- "@pythnetwork/client": "2.5.1",
33
+ "@pythnetwork/client": "2.5.3",
34
34
  "@solana/spl-token": "^0.1.6",
35
35
  "@solana/web3.js": "1.41.0",
36
36
  "@switchboard-xyz/switchboard-v2": "^0.0.67",
@@ -39,10 +39,10 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/chai": "^4.3.1",
42
+ "@types/jest": "^28.1.3",
42
43
  "@types/mocha": "^9.1.1",
43
44
  "@typescript-eslint/eslint-plugin": "^4.28.0",
44
45
  "@typescript-eslint/parser": "^4.28.0",
45
- "@types/jest": "^28.1.3",
46
46
  "chai": "^4.3.6",
47
47
  "eslint": "^7.29.0",
48
48
  "eslint-config-prettier": "^8.3.0",