@drift-labs/sdk 0.1.36-master.2 → 0.1.36-master.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.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import * as anchor from '@project-serum/anchor';
3
- import { Program, Provider } from '@project-serum/anchor';
3
+ import { AnchorProvider, Program } from '@project-serum/anchor';
4
4
  import { AccountInfo } from '@solana/spl-token';
5
5
  import { ConfirmOptions, Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
6
6
  import { BN } from '.';
@@ -9,7 +9,7 @@ export declare class MockUSDCFaucet {
9
9
  connection: Connection;
10
10
  wallet: IWallet;
11
11
  program: Program;
12
- provider: Provider;
12
+ provider: AnchorProvider;
13
13
  opts?: ConfirmOptions;
14
14
  constructor(connection: Connection, wallet: IWallet, programId: PublicKey, opts?: ConfirmOptions);
15
15
  getMockUSDCFaucetStatePublicKeyAndNonce(): Promise<[
@@ -45,8 +45,8 @@ class MockUSDCFaucet {
45
45
  constructor(connection, wallet, programId, opts) {
46
46
  this.connection = connection;
47
47
  this.wallet = wallet;
48
- this.opts = opts || anchor_1.Provider.defaultOptions();
49
- const provider = new anchor_1.Provider(connection, wallet, this.opts);
48
+ this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
49
+ const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
50
50
  this.provider = provider;
51
51
  this.program = new anchor_1.Program(mock_usdc_faucet_json_1.default, programId, provider);
52
52
  }
@@ -117,7 +117,7 @@ class MockUSDCFaucet {
117
117
  return __awaiter(this, void 0, void 0, function* () {
118
118
  const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = yield this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
119
119
  const tx = new web3_js_1.Transaction().add(createAssociatedAccountIx).add(mintToTx);
120
- const txSig = yield this.program.provider.send(tx, [], this.opts);
120
+ const txSig = yield this.program.provider.sendAndConfirm(tx, [], this.opts);
121
121
  return [associatedTokenPublicKey, txSig];
122
122
  });
123
123
  }
@@ -64,7 +64,7 @@ function getSwitchboardProgram(env, connection) {
64
64
  const DEFAULT_KEYPAIR = web3_js_1.Keypair.fromSeed(new Uint8Array(32).fill(1));
65
65
  const programId = (0, switchboard_v2_1.getSwitchboardPid)(env);
66
66
  const wallet = new wallet_1.Wallet(DEFAULT_KEYPAIR);
67
- const provider = new anchor_1.Provider(connection, wallet, {});
67
+ const provider = new anchor_1.AnchorProvider(connection, wallet, {});
68
68
  return new anchor_1.Program(switchboard_v2_json_1.default, programId, provider);
69
69
  });
70
70
  }
@@ -1,8 +1,8 @@
1
1
  import { TxSender } from './types';
2
2
  import { ConfirmOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
3
- import { Provider } from '@project-serum/anchor';
3
+ import { AnchorProvider } from '@project-serum/anchor';
4
4
  export declare class DefaultTxSender implements TxSender {
5
- provider: Provider;
6
- constructor(provider: Provider);
5
+ provider: AnchorProvider;
6
+ constructor(provider: AnchorProvider);
7
7
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TransactionSignature>;
8
8
  }
@@ -6,7 +6,7 @@ class DefaultTxSender {
6
6
  this.provider = provider;
7
7
  }
8
8
  send(tx, additionalSigners, opts) {
9
- return this.provider.send(tx, additionalSigners, opts);
9
+ return this.provider.sendAndConfirm(tx, additionalSigners, opts);
10
10
  }
11
11
  }
12
12
  exports.DefaultTxSender = DefaultTxSender;
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
2
  import { TxSender } from './types';
3
3
  import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection } from '@solana/web3.js';
4
- import { Provider } from '@project-serum/anchor';
4
+ import { AnchorProvider } from '@project-serum/anchor';
5
5
  declare type ResolveReference = {
6
6
  resolve?: () => void;
7
7
  };
8
8
  export declare class RetryTxSender implements TxSender {
9
- provider: Provider;
9
+ provider: AnchorProvider;
10
10
  timeout: number;
11
11
  retrySleep: number;
12
12
  additionalConnections: Connection[];
13
- constructor(provider: Provider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
13
+ constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
14
14
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TransactionSignature>;
15
15
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
16
16
  confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.36-master.2",
3
+ "version": "0.1.36-master.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@project-serum/anchor": "0.19.1-beta.1",
31
+ "@project-serum/anchor": "0.24.2",
32
32
  "@pythnetwork/client": "^2.5.1",
33
33
  "@solana/spl-token": "^0.1.6",
34
34
  "@solana/web3.js": "^1.22.0",
@@ -1,5 +1,5 @@
1
1
  import { AccountData, AccountSubscriber } from './types';
2
- import { Program } from '@project-serum/anchor';
2
+ import { AnchorProvider, Program } from '@project-serum/anchor';
3
3
  import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
4
4
  import { capitalize } from './utils';
5
5
  import * as Buffer from 'buffer';
@@ -36,7 +36,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
36
36
  (accountInfo, context) => {
37
37
  this.handleRpcResponse(context, accountInfo);
38
38
  },
39
- this.program.provider.opts.commitment
39
+ (this.program.provider as AnchorProvider).opts.commitment
40
40
  );
41
41
  }
42
42
 
@@ -44,7 +44,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
44
44
  const rpcResponse =
45
45
  await this.program.provider.connection.getAccountInfoAndContext(
46
46
  this.accountPublicKey,
47
- this.program.provider.opts.commitment
47
+ (this.program.provider as AnchorProvider).opts.commitment
48
48
  );
49
49
  this.handleRpcResponse(rpcResponse.context, rpcResponse?.value);
50
50
  }
package/src/admin.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  OracleSource,
13
13
  OrderFillerRewardStructure,
14
14
  } from './types';
15
- import { BN, Provider } from '@project-serum/anchor';
15
+ import { BN, AnchorProvider } from '@project-serum/anchor';
16
16
  import * as anchor from '@project-serum/anchor';
17
17
  import {
18
18
  getClearingHouseStateAccountPublicKey,
@@ -34,7 +34,7 @@ export class Admin extends ClearingHouse {
34
34
  connection: Connection,
35
35
  wallet: IWallet,
36
36
  clearingHouseProgramId: PublicKey,
37
- opts: ConfirmOptions = Provider.defaultOptions()
37
+ opts: ConfirmOptions = AnchorProvider.defaultOptions()
38
38
  ): Admin {
39
39
  const config = getWebSocketClearingHouseConfig(
40
40
  connection,
@@ -1,4 +1,4 @@
1
- import { BN, Idl, Program, Provider } from '@project-serum/anchor';
1
+ import { AnchorProvider, BN, Idl, Program } from '@project-serum/anchor';
2
2
  import {
3
3
  ASSOCIATED_TOKEN_PROGRAM_ID,
4
4
  Token,
@@ -71,7 +71,7 @@ export class ClearingHouse {
71
71
  connection: Connection;
72
72
  wallet: IWallet;
73
73
  public program: Program;
74
- provider: Provider;
74
+ provider: AnchorProvider;
75
75
  opts?: ConfirmOptions;
76
76
  accountSubscriber: ClearingHouseAccountSubscriber;
77
77
  eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
@@ -98,7 +98,7 @@ export class ClearingHouse {
98
98
  connection: Connection,
99
99
  wallet: IWallet,
100
100
  clearingHouseProgramId: PublicKey,
101
- opts: ConfirmOptions = Provider.defaultOptions()
101
+ opts: ConfirmOptions = AnchorProvider.defaultOptions()
102
102
  ): ClearingHouse {
103
103
  const config = getWebSocketClearingHouseConfig(
104
104
  connection,
@@ -245,7 +245,11 @@ export class ClearingHouse {
245
245
  * @param newWallet
246
246
  */
247
247
  public updateWallet(newWallet: IWallet): void {
248
- const newProvider = new Provider(this.connection, newWallet, this.opts);
248
+ const newProvider = new AnchorProvider(
249
+ this.connection,
250
+ newWallet,
251
+ this.opts
252
+ );
249
253
  const newProgram = new Program(
250
254
  clearingHouseIDL as Idl,
251
255
  this.program.programId,
@@ -503,7 +507,7 @@ export class ClearingHouse {
503
507
  .add(initializeUserOrdersAccountIx)
504
508
  .add(depositCollateralIx);
505
509
 
506
- const txSig = await this.program.provider.send(tx, [userPositionsAccount]);
510
+ const txSig = await this.txSender.send(tx, [userPositionsAccount]);
507
511
 
508
512
  return [txSig, userAccountPublicKey];
509
513
  }
@@ -538,7 +542,9 @@ export class ClearingHouse {
538
542
  .add(initializeUserOrdersAccountIx)
539
543
  .add(depositCollateralIx);
540
544
 
541
- const txSig = await this.program.provider.send(tx, [userPositionsAccount]);
545
+ const txSig = await this.program.provider.sendAndConfirm(tx, [
546
+ userPositionsAccount,
547
+ ]);
542
548
 
543
549
  return [txSig, userAccountPublicKey];
544
550
  }
@@ -911,17 +917,19 @@ export class ClearingHouse {
911
917
  }
912
918
 
913
919
  public async cancelAllOrders(
914
- oracles?: PublicKey[]
920
+ oracles?: PublicKey[],
921
+ bestEffort?: boolean
915
922
  ): Promise<TransactionSignature> {
916
923
  return await this.txSender.send(
917
- wrapInTx(await this.getCancelAllOrdersIx(oracles)),
924
+ wrapInTx(await this.getCancelAllOrdersIx(oracles, bestEffort)),
918
925
  [],
919
926
  this.opts
920
927
  );
921
928
  }
922
929
 
923
930
  public async getCancelAllOrdersIx(
924
- oracles: PublicKey[]
931
+ oracles: PublicKey[],
932
+ bestEffort?: boolean
925
933
  ): Promise<TransactionInstruction> {
926
934
  const userAccountPublicKey = await this.getUserAccountPublicKey();
927
935
  const userAccount = await this.getUserAccount();
@@ -938,7 +946,7 @@ export class ClearingHouse {
938
946
  });
939
947
  }
940
948
 
941
- return await this.program.instruction.cancelAllOrders({
949
+ return await this.program.instruction.cancelAllOrders(bestEffort, {
942
950
  accounts: {
943
951
  state: await this.getStatePublicKey(),
944
952
  user: userAccountPublicKey,
@@ -955,6 +963,69 @@ export class ClearingHouse {
955
963
  });
956
964
  }
957
965
 
966
+ public async cancelOrdersByMarketAndSide(
967
+ oracles?: PublicKey[],
968
+ bestEffort?: boolean,
969
+ marketIndexOnly?: BN,
970
+ directionOnly?: PositionDirection
971
+ ): Promise<TransactionSignature> {
972
+ return await this.txSender.send(
973
+ wrapInTx(
974
+ await this.getCancelOrdersByMarketAndSideIx(
975
+ oracles,
976
+ bestEffort,
977
+ marketIndexOnly,
978
+ directionOnly
979
+ )
980
+ ),
981
+ [],
982
+ this.opts
983
+ );
984
+ }
985
+
986
+ public async getCancelOrdersByMarketAndSideIx(
987
+ oracles: PublicKey[],
988
+ bestEffort?: boolean,
989
+ marketIndexOnly?: BN,
990
+ directionOnly?: PositionDirection
991
+ ): Promise<TransactionInstruction> {
992
+ const userAccountPublicKey = await this.getUserAccountPublicKey();
993
+ const userAccount = await this.getUserAccount();
994
+
995
+ const state = this.getStateAccount();
996
+ const orderState = this.getOrderStateAccount();
997
+
998
+ const remainingAccounts = [];
999
+ for (const oracle of oracles) {
1000
+ remainingAccounts.push({
1001
+ pubkey: oracle,
1002
+ isWritable: false,
1003
+ isSigner: false,
1004
+ });
1005
+ }
1006
+
1007
+ return await this.program.instruction.cancelOrdersByMarketAndSide(
1008
+ bestEffort,
1009
+ marketIndexOnly,
1010
+ directionOnly,
1011
+ {
1012
+ accounts: {
1013
+ state: await this.getStatePublicKey(),
1014
+ user: userAccountPublicKey,
1015
+ authority: this.wallet.publicKey,
1016
+ markets: state.markets,
1017
+ userOrders: await this.getUserOrdersAccountPublicKey(),
1018
+ userPositions: userAccount.positions,
1019
+ fundingPaymentHistory: state.fundingPaymentHistory,
1020
+ fundingRateHistory: state.fundingRateHistory,
1021
+ orderState: await this.getOrderStatePublicKey(),
1022
+ orderHistory: orderState.orderHistory,
1023
+ },
1024
+ remainingAccounts,
1025
+ }
1026
+ );
1027
+ }
1028
+
958
1029
  public async fillOrder(
959
1030
  userAccountPublicKey: PublicKey,
960
1031
  userOrdersAccountPublicKey: PublicKey,
@@ -1,4 +1,4 @@
1
- import { BN, Provider } from '@project-serum/anchor';
1
+ import { AnchorProvider, BN } from '@project-serum/anchor';
2
2
  import { Wallet } from '..';
3
3
  import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
4
4
  import { Connection, Keypair, PublicKey } from '@solana/web3.js';
@@ -43,7 +43,11 @@ const main = async () => {
43
43
  const connection = new Connection(rpcAddress);
44
44
 
45
45
  // Set up the Provider
46
- const provider = new Provider(connection, wallet, Provider.defaultOptions());
46
+ const provider = new AnchorProvider(
47
+ connection,
48
+ wallet,
49
+ AnchorProvider.defaultOptions()
50
+ );
47
51
 
48
52
  // Check SOL Balance
49
53
  const lamportsBalance = await connection.getBalance(wallet.publicKey);
@@ -2,7 +2,7 @@ import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
2
2
  import { IWallet } from '../types';
3
3
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
4
  import { TxSender } from '../tx/types';
5
- import { Idl, Program, Provider } from '@project-serum/anchor';
5
+ import { AnchorProvider, Idl, Program } from '@project-serum/anchor';
6
6
  import { ClearingHouse } from '../clearingHouse';
7
7
  import clearingHouseIDL from '../idl/clearing_house.json';
8
8
  import { WebSocketClearingHouseAccountSubscriber } from '../accounts/webSocketClearingHouseAccountSubscriber';
@@ -53,7 +53,7 @@ export function getWebSocketClearingHouseConfig(
53
53
  connection: Connection,
54
54
  wallet: IWallet,
55
55
  programID: PublicKey,
56
- opts: ConfirmOptions = Provider.defaultOptions(),
56
+ opts: ConfirmOptions = AnchorProvider.defaultOptions(),
57
57
  txSenderConfig?: TxSenderConfig
58
58
  ): WebSocketClearingHouseConfiguration {
59
59
  return {
@@ -71,7 +71,7 @@ export function getPollingClearingHouseConfig(
71
71
  wallet: IWallet,
72
72
  programID: PublicKey,
73
73
  accountLoader: BulkAccountLoader,
74
- opts: ConfirmOptions = Provider.defaultOptions(),
74
+ opts: ConfirmOptions = AnchorProvider.defaultOptions(),
75
75
  txSenderConfig?: TxSenderConfig
76
76
  ): PollingClearingHouseConfiguration {
77
77
  return {
@@ -86,7 +86,11 @@ export function getPollingClearingHouseConfig(
86
86
  }
87
87
 
88
88
  export function getClearingHouse(config: ClearingHouseConfig): ClearingHouse {
89
- const provider = new Provider(config.connection, config.wallet, config.opts);
89
+ const provider = new AnchorProvider(
90
+ config.connection,
91
+ config.wallet,
92
+ config.opts
93
+ );
90
94
  const program = new Program(
91
95
  clearingHouseIDL as Idl,
92
96
  config.programID,
@@ -126,7 +130,11 @@ export function getClearingHouse(config: ClearingHouseConfig): ClearingHouse {
126
130
  }
127
131
 
128
132
  export function getAdmin(config: ClearingHouseConfig): Admin {
129
- const provider = new Provider(config.connection, config.wallet, config.opts);
133
+ const provider = new AnchorProvider(
134
+ config.connection,
135
+ config.wallet,
136
+ config.opts
137
+ );
130
138
  const program = new Program(
131
139
  clearingHouseIDL as Idl,
132
140
  config.programID,