@drift-labs/sdk 2.98.0-beta.13 → 2.98.0-beta.15

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.98.0-beta.13
1
+ 2.98.0-beta.15
@@ -9,6 +9,7 @@ export declare function getUserAccountPublicKey(programId: PublicKey, authority:
9
9
  export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
10
10
  export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
11
11
  export declare function getRFQUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
+ export declare function getSwiftUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
13
  export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
13
14
  export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
14
15
  export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  const spl_token_1 = require("@solana/spl-token");
@@ -69,6 +69,13 @@ function getRFQUserAccountPublicKey(programId, userAccountPublicKey) {
69
69
  ], programId)[0];
70
70
  }
71
71
  exports.getRFQUserAccountPublicKey = getRFQUserAccountPublicKey;
72
+ function getSwiftUserAccountPublicKey(programId, userAccountPublicKey) {
73
+ return web3_js_1.PublicKey.findProgramAddressSync([
74
+ Buffer.from(anchor.utils.bytes.utf8.encode('SWIFT')),
75
+ userAccountPublicKey.toBuffer(),
76
+ ], programId)[0];
77
+ }
78
+ exports.getSwiftUserAccountPublicKey = getSwiftUserAccountPublicKey;
72
79
  async function getPerpMarketPublicKey(programId, marketIndex) {
73
80
  return (await web3_js_1.PublicKey.findProgramAddress([
74
81
  Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
@@ -140,6 +140,8 @@ export declare class DriftClient {
140
140
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
141
141
  initializeRFQUser(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
142
142
  getInitializeRFQUserInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
143
+ initializeSwiftUserOrdersAccount(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
144
+ getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
143
145
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
144
146
  getNextSubAccountId(): Promise<number>;
145
147
  initializeReferrerName(name: string): Promise<TransactionSignature>;
@@ -531,12 +533,12 @@ export declare class DriftClient {
531
533
  takerStats: PublicKey;
532
534
  takerUserAccount: UserAccount;
533
535
  }): Promise<TransactionInstruction[]>;
534
- placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
536
+ placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
535
537
  taker: PublicKey;
536
538
  takerStats: PublicKey;
537
539
  takerUserAccount: UserAccount;
538
540
  }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
539
- getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
541
+ getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
540
542
  taker: PublicKey;
541
543
  takerStats: PublicKey;
542
544
  takerUserAccount: UserAccount;
@@ -186,7 +186,7 @@ class DriftClient {
186
186
  if (config.env && !this.marketLookupTable) {
187
187
  this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
188
188
  }
189
- const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Subscribe;
189
+ const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
190
190
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
191
191
  config.spotMarketIndexes === undefined &&
192
192
  config.oracleInfos === undefined;
@@ -600,6 +600,28 @@ class DriftClient {
600
600
  });
601
601
  return [rfqUserAccountPublicKey, initializeUserAccountIx];
602
602
  }
603
+ async initializeSwiftUserOrdersAccount(userAccountPublicKey, txParams) {
604
+ const initializeIxs = [];
605
+ const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey);
606
+ initializeIxs.push(initializeUserAccountIx);
607
+ const tx = await this.buildTransaction(initializeIxs, txParams);
608
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
609
+ return [txSig, swiftUserAccountPublicKey];
610
+ }
611
+ async getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey) {
612
+ const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
613
+ const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders({
614
+ accounts: {
615
+ swiftUserOrders: swiftUserAccountPublicKey,
616
+ authority: this.wallet.publicKey,
617
+ user: userAccountPublicKey,
618
+ payer: this.wallet.publicKey,
619
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
620
+ systemProgram: anchor.web3.SystemProgram.programId,
621
+ },
622
+ });
623
+ return [swiftUserAccountPublicKey, initializeUserAccountIx];
624
+ }
603
625
  async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
604
626
  const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
605
627
  const remainingAccounts = new Array();
@@ -2993,15 +3015,12 @@ class DriftClient {
2993
3015
  });
2994
3016
  }
2995
3017
  encodeSwiftServerMessage(message) {
2996
- const messageWithBuffer = {
2997
- slot: message.slot,
2998
- swiftOrderSignature: message.swiftOrderSignature,
2999
- };
3000
- return this.program.coder.types.encode('SwiftServerMessage', messageWithBuffer);
3018
+ return this.program.coder.types.encode('SwiftServerMessage', message);
3001
3019
  }
3002
3020
  decodeSwiftServerMessage(encodedMessage) {
3003
3021
  const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3004
3022
  return {
3023
+ uuid: decodedSwiftMessage.uuid,
3005
3024
  slot: decodedSwiftMessage.slot,
3006
3025
  swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3007
3026
  };
@@ -3049,6 +3068,7 @@ class DriftClient {
3049
3068
  state: await this.getStatePublicKey(),
3050
3069
  user: takerInfo.taker,
3051
3070
  userStats: takerInfo.takerStats,
3071
+ swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3052
3072
  authority: this.wallet.publicKey,
3053
3073
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3054
3074
  },
@@ -3060,13 +3080,13 @@ class DriftClient {
3060
3080
  placeTakerSwiftPerpOrderIx,
3061
3081
  ];
3062
3082
  }
3063
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3064
- const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId);
3083
+ async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3084
+ const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3065
3085
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3066
3086
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3067
3087
  return txSig;
3068
3088
  }
3069
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId) {
3089
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3070
3090
  const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3071
3091
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3072
3092
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -3091,7 +3111,7 @@ class DriftClient {
3091
3111
  isSigner: false,
3092
3112
  });
3093
3113
  }
3094
- const placeAndMakeIx = await this.program.instruction.placeAndMakePerpOrder(orderParams, takerExpectedOrderId, {
3114
+ const placeAndMakeIx = await this.program.instruction.placeAndMakeSwiftPerpOrder(orderParams, swiftOrderUuid, {
3095
3115
  accounts: {
3096
3116
  state: await this.getStatePublicKey(),
3097
3117
  user,
@@ -3099,6 +3119,7 @@ class DriftClient {
3099
3119
  taker: takerInfo.taker,
3100
3120
  takerStats: takerInfo.takerStats,
3101
3121
  authority: this.wallet.publicKey,
3122
+ takerSwiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3102
3123
  },
3103
3124
  remainingAccounts,
3104
3125
  });
@@ -129,6 +129,42 @@
129
129
  ],
130
130
  "args": []
131
131
  },
132
+ {
133
+ "name": "initializeSwiftUserOrders",
134
+ "accounts": [
135
+ {
136
+ "name": "swiftUserOrders",
137
+ "isMut": true,
138
+ "isSigner": false
139
+ },
140
+ {
141
+ "name": "authority",
142
+ "isMut": false,
143
+ "isSigner": true
144
+ },
145
+ {
146
+ "name": "user",
147
+ "isMut": true,
148
+ "isSigner": false
149
+ },
150
+ {
151
+ "name": "payer",
152
+ "isMut": true,
153
+ "isSigner": true
154
+ },
155
+ {
156
+ "name": "rent",
157
+ "isMut": false,
158
+ "isSigner": false
159
+ },
160
+ {
161
+ "name": "systemProgram",
162
+ "isMut": false,
163
+ "isSigner": false
164
+ }
165
+ ],
166
+ "args": []
167
+ },
132
168
  {
133
169
  "name": "initializeReferrerName",
134
170
  "accounts": [
@@ -644,6 +680,63 @@
644
680
  }
645
681
  ]
646
682
  },
683
+ {
684
+ "name": "placeAndMakeSwiftPerpOrder",
685
+ "accounts": [
686
+ {
687
+ "name": "state",
688
+ "isMut": false,
689
+ "isSigner": false
690
+ },
691
+ {
692
+ "name": "user",
693
+ "isMut": true,
694
+ "isSigner": false
695
+ },
696
+ {
697
+ "name": "userStats",
698
+ "isMut": true,
699
+ "isSigner": false
700
+ },
701
+ {
702
+ "name": "taker",
703
+ "isMut": true,
704
+ "isSigner": false
705
+ },
706
+ {
707
+ "name": "takerStats",
708
+ "isMut": true,
709
+ "isSigner": false
710
+ },
711
+ {
712
+ "name": "takerSwiftUserOrders",
713
+ "isMut": false,
714
+ "isSigner": false
715
+ },
716
+ {
717
+ "name": "authority",
718
+ "isMut": false,
719
+ "isSigner": true
720
+ }
721
+ ],
722
+ "args": [
723
+ {
724
+ "name": "params",
725
+ "type": {
726
+ "defined": "OrderParams"
727
+ }
728
+ },
729
+ {
730
+ "name": "swiftOrderUuid",
731
+ "type": {
732
+ "array": [
733
+ "u8",
734
+ 8
735
+ ]
736
+ }
737
+ }
738
+ ]
739
+ },
647
740
  {
648
741
  "name": "placeSwiftTakerOrder",
649
742
  "accounts": [
@@ -662,6 +755,11 @@
662
755
  "isMut": true,
663
756
  "isSigner": false
664
757
  },
758
+ {
759
+ "name": "swiftUserOrders",
760
+ "isMut": true,
761
+ "isSigner": false
762
+ },
665
763
  {
666
764
  "name": "authority",
667
765
  "isMut": false,
@@ -7468,6 +7566,29 @@
7468
7566
  ]
7469
7567
  }
7470
7568
  },
7569
+ {
7570
+ "name": "SwiftUserOrders",
7571
+ "type": {
7572
+ "kind": "struct",
7573
+ "fields": [
7574
+ {
7575
+ "name": "userPubkey",
7576
+ "type": "publicKey"
7577
+ },
7578
+ {
7579
+ "name": "swiftOrderData",
7580
+ "type": {
7581
+ "array": [
7582
+ {
7583
+ "defined": "SwiftOrderId"
7584
+ },
7585
+ 32
7586
+ ]
7587
+ }
7588
+ }
7589
+ ]
7590
+ }
7591
+ },
7471
7592
  {
7472
7593
  "name": "User",
7473
7594
  "type": {
@@ -8432,6 +8553,15 @@
8432
8553
  "type": {
8433
8554
  "kind": "struct",
8434
8555
  "fields": [
8556
+ {
8557
+ "name": "uuid",
8558
+ "type": {
8559
+ "array": [
8560
+ "u8",
8561
+ 8
8562
+ ]
8563
+ }
8564
+ },
8435
8565
  {
8436
8566
  "name": "swiftOrderSignature",
8437
8567
  "type": {
@@ -8459,10 +8589,6 @@
8459
8589
  "defined": "OrderParams"
8460
8590
  }
8461
8591
  },
8462
- {
8463
- "name": "expectedOrderId",
8464
- "type": "i32"
8465
- },
8466
8592
  {
8467
8593
  "name": "subAccountId",
8468
8594
  "type": "u16"
@@ -9642,6 +9768,31 @@
9642
9768
  ]
9643
9769
  }
9644
9770
  },
9771
+ {
9772
+ "name": "SwiftOrderId",
9773
+ "type": {
9774
+ "kind": "struct",
9775
+ "fields": [
9776
+ {
9777
+ "name": "uuid",
9778
+ "type": {
9779
+ "array": [
9780
+ "u8",
9781
+ 8
9782
+ ]
9783
+ }
9784
+ },
9785
+ {
9786
+ "name": "maxSlot",
9787
+ "type": "u64"
9788
+ },
9789
+ {
9790
+ "name": "orderId",
9791
+ "type": "u32"
9792
+ }
9793
+ ]
9794
+ }
9795
+ },
9645
9796
  {
9646
9797
  "name": "UserFees",
9647
9798
  "type": {
@@ -11541,13 +11692,28 @@
11541
11692
  "index": false
11542
11693
  },
11543
11694
  {
11544
- "name": "swiftOrderSlot",
11695
+ "name": "userOrderId",
11696
+ "type": "u32",
11697
+ "index": false
11698
+ },
11699
+ {
11700
+ "name": "swiftOrderMaxSlot",
11545
11701
  "type": "u64",
11546
11702
  "index": false
11547
11703
  },
11548
11704
  {
11549
- "name": "userNextOrderId",
11550
- "type": "u32",
11705
+ "name": "swiftOrderUuid",
11706
+ "type": {
11707
+ "array": [
11708
+ "u8",
11709
+ 8
11710
+ ]
11711
+ },
11712
+ "index": false
11713
+ },
11714
+ {
11715
+ "name": "ts",
11716
+ "type": "i64",
11551
11717
  "index": false
11552
11718
  }
11553
11719
  ]
@@ -13671,6 +13837,31 @@
13671
13837
  "code": 6296,
13672
13838
  "name": "InvalidRFQMatch",
13673
13839
  "msg": "RFQ matches must be valid"
13840
+ },
13841
+ {
13842
+ "code": 6297,
13843
+ "name": "InvalidSwiftUserAccount",
13844
+ "msg": "Invalid swift user account"
13845
+ },
13846
+ {
13847
+ "code": 6298,
13848
+ "name": "SwiftUserAccountWrongMutability",
13849
+ "msg": "Swift account wrong mutability"
13850
+ },
13851
+ {
13852
+ "code": 6299,
13853
+ "name": "SwiftUserOrdersAccountFull",
13854
+ "msg": "SwiftUserAccount has too many active orders"
13855
+ },
13856
+ {
13857
+ "code": 6300,
13858
+ "name": "SwiftOrderDoesNotExist",
13859
+ "msg": "Order with swift uuid does not exist"
13860
+ },
13861
+ {
13862
+ "code": 6301,
13863
+ "name": "InvalidSwiftOrderId",
13864
+ "msg": "Swift order id cannot be 0s"
13674
13865
  }
13675
13866
  ],
13676
13867
  "metadata": {
@@ -647,8 +647,9 @@ export type SwiftOrderRecord = {
647
647
  user: PublicKey;
648
648
  hash: string;
649
649
  matchingOrderParams: OrderParams;
650
- swiftOrderSlot: BN;
651
- userNextOrderId: number;
650
+ swiftOrderMaxSlot: BN;
651
+ swiftOrderUuid: Uint8Array;
652
+ userOrderId: number;
652
653
  };
653
654
  export type OrderRecord = {
654
655
  ts: BN;
@@ -1118,10 +1119,10 @@ export declare const DefaultOrderParams: OrderParams;
1118
1119
  export type SwiftServerMessage = {
1119
1120
  slot: BN;
1120
1121
  swiftOrderSignature: Uint8Array;
1122
+ uuid: Uint8Array;
1121
1123
  };
1122
1124
  export type SwiftOrderParamsMessage = {
1123
1125
  swiftOrderParams: OptionalOrderParams;
1124
- expectedOrderId: number;
1125
1126
  subAccountId: number;
1126
1127
  takeProfitOrderParams: SwiftTriggerOrderParams | null;
1127
1128
  stopLossOrderParams: SwiftTriggerOrderParams | null;
@@ -1,3 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  export declare function digest(data: Buffer): Buffer;
4
+ export declare function digestSignature(signature: Uint8Array): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.digest = void 0;
3
+ exports.digestSignature = exports.digest = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  function digest(data) {
6
6
  const hash = (0, crypto_1.createHash)('sha256');
@@ -8,3 +8,7 @@ function digest(data) {
8
8
  return hash.digest();
9
9
  }
10
10
  exports.digest = digest;
11
+ function digestSignature(signature) {
12
+ return (0, crypto_1.createHash)('sha256').update(signature).digest('base64');
13
+ }
14
+ exports.digestSignature = digestSignature;
@@ -9,6 +9,7 @@ export declare function getUserAccountPublicKey(programId: PublicKey, authority:
9
9
  export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
10
10
  export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
11
11
  export declare function getRFQUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
+ export declare function getSwiftUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
13
  export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
13
14
  export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
14
15
  export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  const spl_token_1 = require("@solana/spl-token");
@@ -69,6 +69,13 @@ function getRFQUserAccountPublicKey(programId, userAccountPublicKey) {
69
69
  ], programId)[0];
70
70
  }
71
71
  exports.getRFQUserAccountPublicKey = getRFQUserAccountPublicKey;
72
+ function getSwiftUserAccountPublicKey(programId, userAccountPublicKey) {
73
+ return web3_js_1.PublicKey.findProgramAddressSync([
74
+ Buffer.from(anchor.utils.bytes.utf8.encode('SWIFT')),
75
+ userAccountPublicKey.toBuffer(),
76
+ ], programId)[0];
77
+ }
78
+ exports.getSwiftUserAccountPublicKey = getSwiftUserAccountPublicKey;
72
79
  async function getPerpMarketPublicKey(programId, marketIndex) {
73
80
  return (await web3_js_1.PublicKey.findProgramAddress([
74
81
  Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
@@ -140,6 +140,8 @@ export declare class DriftClient {
140
140
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
141
141
  initializeRFQUser(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
142
142
  getInitializeRFQUserInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
143
+ initializeSwiftUserOrdersAccount(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
144
+ getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
143
145
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
144
146
  getNextSubAccountId(): Promise<number>;
145
147
  initializeReferrerName(name: string): Promise<TransactionSignature>;
@@ -531,12 +533,12 @@ export declare class DriftClient {
531
533
  takerStats: PublicKey;
532
534
  takerUserAccount: UserAccount;
533
535
  }): Promise<TransactionInstruction[]>;
534
- placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
536
+ placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
535
537
  taker: PublicKey;
536
538
  takerStats: PublicKey;
537
539
  takerUserAccount: UserAccount;
538
540
  }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
539
- getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
541
+ getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
540
542
  taker: PublicKey;
541
543
  takerStats: PublicKey;
542
544
  takerUserAccount: UserAccount;
@@ -186,7 +186,7 @@ class DriftClient {
186
186
  if (config.env && !this.marketLookupTable) {
187
187
  this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
188
188
  }
189
- const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Subscribe;
189
+ const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
190
190
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
191
191
  config.spotMarketIndexes === undefined &&
192
192
  config.oracleInfos === undefined;
@@ -600,6 +600,28 @@ class DriftClient {
600
600
  });
601
601
  return [rfqUserAccountPublicKey, initializeUserAccountIx];
602
602
  }
603
+ async initializeSwiftUserOrdersAccount(userAccountPublicKey, txParams) {
604
+ const initializeIxs = [];
605
+ const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey);
606
+ initializeIxs.push(initializeUserAccountIx);
607
+ const tx = await this.buildTransaction(initializeIxs, txParams);
608
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
609
+ return [txSig, swiftUserAccountPublicKey];
610
+ }
611
+ async getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey) {
612
+ const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
613
+ const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders({
614
+ accounts: {
615
+ swiftUserOrders: swiftUserAccountPublicKey,
616
+ authority: this.wallet.publicKey,
617
+ user: userAccountPublicKey,
618
+ payer: this.wallet.publicKey,
619
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
620
+ systemProgram: anchor.web3.SystemProgram.programId,
621
+ },
622
+ });
623
+ return [swiftUserAccountPublicKey, initializeUserAccountIx];
624
+ }
603
625
  async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
604
626
  const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
605
627
  const remainingAccounts = new Array();
@@ -2993,15 +3015,12 @@ class DriftClient {
2993
3015
  });
2994
3016
  }
2995
3017
  encodeSwiftServerMessage(message) {
2996
- const messageWithBuffer = {
2997
- slot: message.slot,
2998
- swiftOrderSignature: message.swiftOrderSignature,
2999
- };
3000
- return this.program.coder.types.encode('SwiftServerMessage', messageWithBuffer);
3018
+ return this.program.coder.types.encode('SwiftServerMessage', message);
3001
3019
  }
3002
3020
  decodeSwiftServerMessage(encodedMessage) {
3003
3021
  const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3004
3022
  return {
3023
+ uuid: decodedSwiftMessage.uuid,
3005
3024
  slot: decodedSwiftMessage.slot,
3006
3025
  swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3007
3026
  };
@@ -3049,6 +3068,7 @@ class DriftClient {
3049
3068
  state: await this.getStatePublicKey(),
3050
3069
  user: takerInfo.taker,
3051
3070
  userStats: takerInfo.takerStats,
3071
+ swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3052
3072
  authority: this.wallet.publicKey,
3053
3073
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3054
3074
  },
@@ -3060,13 +3080,13 @@ class DriftClient {
3060
3080
  placeTakerSwiftPerpOrderIx,
3061
3081
  ];
3062
3082
  }
3063
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3064
- const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId);
3083
+ async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3084
+ const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3065
3085
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3066
3086
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3067
3087
  return txSig;
3068
3088
  }
3069
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId) {
3089
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3070
3090
  const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3071
3091
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3072
3092
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -3091,7 +3111,7 @@ class DriftClient {
3091
3111
  isSigner: false,
3092
3112
  });
3093
3113
  }
3094
- const placeAndMakeIx = await this.program.instruction.placeAndMakePerpOrder(orderParams, takerExpectedOrderId, {
3114
+ const placeAndMakeIx = await this.program.instruction.placeAndMakeSwiftPerpOrder(orderParams, swiftOrderUuid, {
3095
3115
  accounts: {
3096
3116
  state: await this.getStatePublicKey(),
3097
3117
  user,
@@ -3099,6 +3119,7 @@ class DriftClient {
3099
3119
  taker: takerInfo.taker,
3100
3120
  takerStats: takerInfo.takerStats,
3101
3121
  authority: this.wallet.publicKey,
3122
+ takerSwiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3102
3123
  },
3103
3124
  remainingAccounts,
3104
3125
  });