@drift-labs/sdk 2.110.0-beta.15 → 2.110.0-beta.16

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.110.0-beta.15
1
+ 2.110.0-beta.16
@@ -64,6 +64,7 @@ const pyth_solana_receiver_1 = require("@pythnetwork/pyth-solana-receiver");
64
64
  const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
65
65
  const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
66
66
  const pythOracleUtils_1 = require("./util/pythOracleUtils");
67
+ const ed25519Utils_1 = require("./signedMsg/ed25519Utils");
67
68
  const utils_2 = require("./tx/utils");
68
69
  const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
69
70
  const on_demand_1 = require("@switchboard-xyz/on-demand");
@@ -3265,7 +3266,7 @@ class DriftClient {
3265
3266
  messageLengthBuffer,
3266
3267
  signedSignedMsgOrderParams.orderParams,
3267
3268
  ]);
3268
- const signedMsgOrderParamsSignatureIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, signedMsgIxData, 0);
3269
+ const signedMsgOrderParamsSignatureIx = (0, ed25519Utils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, signedMsgIxData, 0);
3269
3270
  const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
3270
3271
  const placeTakerSignedMsgPerpOrderIx = this.program.instruction.placeSignedMsgTakerOrder(signedMsgIxData, isDelegateSigner, {
3271
3272
  accounts: {
@@ -4670,7 +4671,7 @@ class DriftClient {
4670
4671
  }
4671
4672
  async getPostPythLazerOracleUpdateIxs(feedIds, pythMessageHex, precedingIxs = [], overrideIxCount) {
4672
4673
  const pythMessageBytes = Buffer.from(pythMessageHex, 'hex');
4673
- const verifyIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, pythMessageBytes);
4674
+ const verifyIx = (0, ed25519Utils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, pythMessageBytes);
4674
4675
  const remainingAccountsMeta = feedIds.map((feedId) => {
4675
4676
  return {
4676
4677
  pubkey: (0, pda_1.getPythLazerOraclePublicKey)(this.program.programId, feedId),
@@ -87,7 +87,7 @@ export * from './oracles/pythPullClient';
87
87
  export * from './oracles/pythLazerClient';
88
88
  export * from './oracles/switchboardOnDemandClient';
89
89
  export * from './oracles/oracleId';
90
- export * from './swift/swiftOrderSubscriber';
90
+ export * from './signedMsg/signedMsgOrderSubscriber';
91
91
  export * from './tx/fastSingleTxSender';
92
92
  export * from './tx/retryTxSender';
93
93
  export * from './tx/whileValidTxSender';
@@ -110,7 +110,7 @@ __exportStar(require("./oracles/pythPullClient"), exports);
110
110
  __exportStar(require("./oracles/pythLazerClient"), exports);
111
111
  __exportStar(require("./oracles/switchboardOnDemandClient"), exports);
112
112
  __exportStar(require("./oracles/oracleId"), exports);
113
- __exportStar(require("./swift/swiftOrderSubscriber"), exports);
113
+ __exportStar(require("./signedMsg/signedMsgOrderSubscriber"), exports);
114
114
  __exportStar(require("./tx/fastSingleTxSender"), exports);
115
115
  __exportStar(require("./tx/retryTxSender"), exports);
116
116
  __exportStar(require("./tx/whileValidTxSender"), exports);
@@ -0,0 +1,10 @@
1
+ import { TransactionInstruction } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a minimal Ed25519 verification instruction that references the data
4
+ * inside the drift custom instruction (e.g. postPythLazerOracleUpdate, placeSignedMsgTakerOrder).
5
+ *
6
+ * @param customInstructionIndex The index of the custom instruction in the transaction (e.g. if tx contains compute budget limit, compute budget price, ed25519 verify, custom ix, this would be 3).
7
+ * @param messageOffset The offset within the custom instruction data where the signed message begins.
8
+ * @param customInstructionData The entire instruction data array for the custom instruction.
9
+ */
10
+ export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createMinimalEd25519VerifyIx = void 0;
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const BufferLayout = __importStar(require("@solana/buffer-layout"));
29
+ const ED25519_INSTRUCTION_LEN = 16;
30
+ const SIGNATURE_LEN = 64;
31
+ const PUBKEY_LEN = 32;
32
+ const MAGIC_LEN = 4;
33
+ const MESSAGE_SIZE_LEN = 2;
34
+ const readUint16LE = (data, offset) => {
35
+ return data[offset] | (data[offset + 1] << 8);
36
+ };
37
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
38
+ BufferLayout.u8('numSignatures'),
39
+ BufferLayout.u8('padding'),
40
+ BufferLayout.u16('signatureOffset'),
41
+ BufferLayout.u16('signatureInstructionIndex'),
42
+ BufferLayout.u16('publicKeyOffset'),
43
+ BufferLayout.u16('publicKeyInstructionIndex'),
44
+ BufferLayout.u16('messageDataOffset'),
45
+ BufferLayout.u16('messageDataSize'),
46
+ BufferLayout.u16('messageInstructionIndex'),
47
+ ]);
48
+ /**
49
+ * Constructs a minimal Ed25519 verification instruction that references the data
50
+ * inside the drift custom instruction (e.g. postPythLazerOracleUpdate, placeSignedMsgTakerOrder).
51
+ *
52
+ * @param customInstructionIndex The index of the custom instruction in the transaction (e.g. if tx contains compute budget limit, compute budget price, ed25519 verify, custom ix, this would be 3).
53
+ * @param messageOffset The offset within the custom instruction data where the signed message begins.
54
+ * @param customInstructionData The entire instruction data array for the custom instruction.
55
+ */
56
+ function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
57
+ const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
58
+ const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
59
+ const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
60
+ const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
61
+ const messageDataSize = readUint16LE(customInstructionData, messageDataSizeOffset - messageOffset);
62
+ const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
63
+ ED25519_INSTRUCTION_LAYOUT.encode({
64
+ numSignatures: 1,
65
+ padding: 0,
66
+ signatureOffset,
67
+ signatureInstructionIndex: customInstructionIndex,
68
+ publicKeyOffset,
69
+ publicKeyInstructionIndex: customInstructionIndex,
70
+ messageDataOffset,
71
+ messageDataSize: messageDataSize,
72
+ messageInstructionIndex: customInstructionIndex,
73
+ }, instructionData);
74
+ return new web3_js_1.TransactionInstruction({
75
+ keys: [],
76
+ programId: web3_js_1.Ed25519Program.programId,
77
+ data: instructionData,
78
+ });
79
+ }
80
+ exports.createMinimalEd25519VerifyIx = createMinimalEd25519VerifyIx;
@@ -70,7 +70,7 @@ class SignedMsgOrderSubscriber {
70
70
  this.handleAuthMessage(message);
71
71
  }
72
72
  if (message['order']) {
73
- const order = JSON.parse(message['order']);
73
+ const order = message['order'];
74
74
  const signedMsgOrderParamsBuf = Buffer.from(order['order_message'], 'hex');
75
75
  const signedMsgOrderParamsMessage = this.driftClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf);
76
76
  if (!signedMsgOrderParamsMessage.signedMsgOrderParams.price) {
@@ -1,18 +1,2 @@
1
- import { TransactionInstruction } from '@solana/web3.js';
2
1
  export declare function trimFeedId(feedId: string): string;
3
2
  export declare function getFeedIdUint8Array(feedId: string): Uint8Array;
4
- export declare function getEd25519ArgsFromHex(hex: string, customInstructionIndex?: number): {
5
- publicKey: Uint8Array;
6
- signature: Uint8Array;
7
- message: Uint8Array;
8
- instructionIndex?: number;
9
- };
10
- /**
11
- * Constructs a minimal Ed25519 verification instruction that references the data
12
- * inside the main instruction (postPythLazerOracleUpdate).
13
- *
14
- * @param customInstructionIndex The index of the custom instruction in the transaction (typically 1 if this is second).
15
- * @param messageOffset The offset within the custom instruction data where the pythMessage begins.
16
- * @param customInstructionData The entire instruction data array for the custom instruction.
17
- */
18
- export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
@@ -1,31 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createMinimalEd25519VerifyIx = exports.getEd25519ArgsFromHex = exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
27
- const web3_js_1 = require("@solana/web3.js");
28
- const BufferLayout = __importStar(require("@solana/buffer-layout"));
3
+ exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
29
4
  function trimFeedId(feedId) {
30
5
  if (feedId.startsWith('0x')) {
31
6
  return feedId.slice(2);
@@ -38,80 +13,3 @@ function getFeedIdUint8Array(feedId) {
38
13
  return Uint8Array.from(Buffer.from(trimmedFeedId, 'hex'));
39
14
  }
40
15
  exports.getFeedIdUint8Array = getFeedIdUint8Array;
41
- const ED25519_INSTRUCTION_LEN = 16;
42
- const SIGNATURE_LEN = 64;
43
- const PUBKEY_LEN = 32;
44
- const MAGIC_LEN = 4;
45
- const MESSAGE_SIZE_LEN = 2;
46
- function getEd25519ArgsFromHex(hex, customInstructionIndex) {
47
- const cleanedHex = hex.startsWith('0x') ? hex.slice(2) : hex;
48
- const buffer = new Uint8Array(Buffer.from(cleanedHex, 'hex'));
49
- const signatureOffset = MAGIC_LEN;
50
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
51
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
52
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
53
- const signature = buffer.slice(signatureOffset, signatureOffset + SIGNATURE_LEN);
54
- const publicKey = buffer.slice(publicKeyOffset, publicKeyOffset + PUBKEY_LEN);
55
- const messageSize = buffer[messageDataSizeOffset] | (buffer[messageDataSizeOffset + 1] << 8);
56
- const message = buffer.slice(messageDataOffset, messageDataOffset + messageSize);
57
- if (publicKey.length !== PUBKEY_LEN) {
58
- throw new Error('Invalid public key length');
59
- }
60
- if (signature.length !== SIGNATURE_LEN) {
61
- throw new Error('Invalid signature length');
62
- }
63
- return {
64
- publicKey,
65
- signature,
66
- message,
67
- instructionIndex: customInstructionIndex,
68
- };
69
- }
70
- exports.getEd25519ArgsFromHex = getEd25519ArgsFromHex;
71
- const readUint16LE = (data, offset) => {
72
- return data[offset] | (data[offset + 1] << 8);
73
- };
74
- const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
75
- BufferLayout.u8('numSignatures'),
76
- BufferLayout.u8('padding'),
77
- BufferLayout.u16('signatureOffset'),
78
- BufferLayout.u16('signatureInstructionIndex'),
79
- BufferLayout.u16('publicKeyOffset'),
80
- BufferLayout.u16('publicKeyInstructionIndex'),
81
- BufferLayout.u16('messageDataOffset'),
82
- BufferLayout.u16('messageDataSize'),
83
- BufferLayout.u16('messageInstructionIndex'),
84
- ]);
85
- /**
86
- * Constructs a minimal Ed25519 verification instruction that references the data
87
- * inside the main instruction (postPythLazerOracleUpdate).
88
- *
89
- * @param customInstructionIndex The index of the custom instruction in the transaction (typically 1 if this is second).
90
- * @param messageOffset The offset within the custom instruction data where the pythMessage begins.
91
- * @param customInstructionData The entire instruction data array for the custom instruction.
92
- */
93
- function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
94
- const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
95
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
96
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
97
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
98
- const messageDataSize = readUint16LE(customInstructionData, messageDataSizeOffset - messageOffset);
99
- const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
100
- ED25519_INSTRUCTION_LAYOUT.encode({
101
- numSignatures: 1,
102
- padding: 0,
103
- signatureOffset,
104
- signatureInstructionIndex: customInstructionIndex,
105
- publicKeyOffset,
106
- publicKeyInstructionIndex: customInstructionIndex,
107
- messageDataOffset,
108
- messageDataSize: messageDataSize,
109
- messageInstructionIndex: customInstructionIndex,
110
- }, instructionData);
111
- return new web3_js_1.TransactionInstruction({
112
- keys: [],
113
- programId: web3_js_1.Ed25519Program.programId,
114
- data: instructionData,
115
- });
116
- }
117
- exports.createMinimalEd25519VerifyIx = createMinimalEd25519VerifyIx;
@@ -64,6 +64,7 @@ const pyth_solana_receiver_1 = require("@pythnetwork/pyth-solana-receiver");
64
64
  const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
65
65
  const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
66
66
  const pythOracleUtils_1 = require("./util/pythOracleUtils");
67
+ const ed25519Utils_1 = require("./signedMsg/ed25519Utils");
67
68
  const utils_2 = require("./tx/utils");
68
69
  const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
69
70
  const on_demand_1 = require("@switchboard-xyz/on-demand");
@@ -3265,7 +3266,7 @@ class DriftClient {
3265
3266
  messageLengthBuffer,
3266
3267
  signedSignedMsgOrderParams.orderParams,
3267
3268
  ]);
3268
- const signedMsgOrderParamsSignatureIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, signedMsgIxData, 0);
3269
+ const signedMsgOrderParamsSignatureIx = (0, ed25519Utils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, signedMsgIxData, 0);
3269
3270
  const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
3270
3271
  const placeTakerSignedMsgPerpOrderIx = this.program.instruction.placeSignedMsgTakerOrder(signedMsgIxData, isDelegateSigner, {
3271
3272
  accounts: {
@@ -4670,7 +4671,7 @@ class DriftClient {
4670
4671
  }
4671
4672
  async getPostPythLazerOracleUpdateIxs(feedIds, pythMessageHex, precedingIxs = [], overrideIxCount) {
4672
4673
  const pythMessageBytes = Buffer.from(pythMessageHex, 'hex');
4673
- const verifyIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, pythMessageBytes);
4674
+ const verifyIx = (0, ed25519Utils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, pythMessageBytes);
4674
4675
  const remainingAccountsMeta = feedIds.map((feedId) => {
4675
4676
  return {
4676
4677
  pubkey: (0, pda_1.getPythLazerOraclePublicKey)(this.program.programId, feedId),
@@ -87,7 +87,7 @@ export * from './oracles/pythPullClient';
87
87
  export * from './oracles/pythLazerClient';
88
88
  export * from './oracles/switchboardOnDemandClient';
89
89
  export * from './oracles/oracleId';
90
- export * from './swift/swiftOrderSubscriber';
90
+ export * from './signedMsg/signedMsgOrderSubscriber';
91
91
  export * from './tx/fastSingleTxSender';
92
92
  export * from './tx/retryTxSender';
93
93
  export * from './tx/whileValidTxSender';
package/lib/node/index.js CHANGED
@@ -110,7 +110,7 @@ __exportStar(require("./oracles/pythPullClient"), exports);
110
110
  __exportStar(require("./oracles/pythLazerClient"), exports);
111
111
  __exportStar(require("./oracles/switchboardOnDemandClient"), exports);
112
112
  __exportStar(require("./oracles/oracleId"), exports);
113
- __exportStar(require("./swift/swiftOrderSubscriber"), exports);
113
+ __exportStar(require("./signedMsg/signedMsgOrderSubscriber"), exports);
114
114
  __exportStar(require("./tx/fastSingleTxSender"), exports);
115
115
  __exportStar(require("./tx/retryTxSender"), exports);
116
116
  __exportStar(require("./tx/whileValidTxSender"), exports);
@@ -0,0 +1,10 @@
1
+ import { TransactionInstruction } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a minimal Ed25519 verification instruction that references the data
4
+ * inside the drift custom instruction (e.g. postPythLazerOracleUpdate, placeSignedMsgTakerOrder).
5
+ *
6
+ * @param customInstructionIndex The index of the custom instruction in the transaction (e.g. if tx contains compute budget limit, compute budget price, ed25519 verify, custom ix, this would be 3).
7
+ * @param messageOffset The offset within the custom instruction data where the signed message begins.
8
+ * @param customInstructionData The entire instruction data array for the custom instruction.
9
+ */
10
+ export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createMinimalEd25519VerifyIx = void 0;
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const BufferLayout = __importStar(require("@solana/buffer-layout"));
29
+ const ED25519_INSTRUCTION_LEN = 16;
30
+ const SIGNATURE_LEN = 64;
31
+ const PUBKEY_LEN = 32;
32
+ const MAGIC_LEN = 4;
33
+ const MESSAGE_SIZE_LEN = 2;
34
+ const readUint16LE = (data, offset) => {
35
+ return data[offset] | (data[offset + 1] << 8);
36
+ };
37
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
38
+ BufferLayout.u8('numSignatures'),
39
+ BufferLayout.u8('padding'),
40
+ BufferLayout.u16('signatureOffset'),
41
+ BufferLayout.u16('signatureInstructionIndex'),
42
+ BufferLayout.u16('publicKeyOffset'),
43
+ BufferLayout.u16('publicKeyInstructionIndex'),
44
+ BufferLayout.u16('messageDataOffset'),
45
+ BufferLayout.u16('messageDataSize'),
46
+ BufferLayout.u16('messageInstructionIndex'),
47
+ ]);
48
+ /**
49
+ * Constructs a minimal Ed25519 verification instruction that references the data
50
+ * inside the drift custom instruction (e.g. postPythLazerOracleUpdate, placeSignedMsgTakerOrder).
51
+ *
52
+ * @param customInstructionIndex The index of the custom instruction in the transaction (e.g. if tx contains compute budget limit, compute budget price, ed25519 verify, custom ix, this would be 3).
53
+ * @param messageOffset The offset within the custom instruction data where the signed message begins.
54
+ * @param customInstructionData The entire instruction data array for the custom instruction.
55
+ */
56
+ function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
57
+ const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
58
+ const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
59
+ const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
60
+ const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
61
+ const messageDataSize = readUint16LE(customInstructionData, messageDataSizeOffset - messageOffset);
62
+ const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
63
+ ED25519_INSTRUCTION_LAYOUT.encode({
64
+ numSignatures: 1,
65
+ padding: 0,
66
+ signatureOffset,
67
+ signatureInstructionIndex: customInstructionIndex,
68
+ publicKeyOffset,
69
+ publicKeyInstructionIndex: customInstructionIndex,
70
+ messageDataOffset,
71
+ messageDataSize: messageDataSize,
72
+ messageInstructionIndex: customInstructionIndex,
73
+ }, instructionData);
74
+ return new web3_js_1.TransactionInstruction({
75
+ keys: [],
76
+ programId: web3_js_1.Ed25519Program.programId,
77
+ data: instructionData,
78
+ });
79
+ }
80
+ exports.createMinimalEd25519VerifyIx = createMinimalEd25519VerifyIx;
@@ -70,7 +70,7 @@ class SignedMsgOrderSubscriber {
70
70
  this.handleAuthMessage(message);
71
71
  }
72
72
  if (message['order']) {
73
- const order = JSON.parse(message['order']);
73
+ const order = message['order'];
74
74
  const signedMsgOrderParamsBuf = Buffer.from(order['order_message'], 'hex');
75
75
  const signedMsgOrderParamsMessage = this.driftClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf);
76
76
  if (!signedMsgOrderParamsMessage.signedMsgOrderParams.price) {
@@ -1,18 +1,2 @@
1
- import { TransactionInstruction } from '@solana/web3.js';
2
1
  export declare function trimFeedId(feedId: string): string;
3
2
  export declare function getFeedIdUint8Array(feedId: string): Uint8Array;
4
- export declare function getEd25519ArgsFromHex(hex: string, customInstructionIndex?: number): {
5
- publicKey: Uint8Array;
6
- signature: Uint8Array;
7
- message: Uint8Array;
8
- instructionIndex?: number;
9
- };
10
- /**
11
- * Constructs a minimal Ed25519 verification instruction that references the data
12
- * inside the main instruction (postPythLazerOracleUpdate).
13
- *
14
- * @param customInstructionIndex The index of the custom instruction in the transaction (typically 1 if this is second).
15
- * @param messageOffset The offset within the custom instruction data where the pythMessage begins.
16
- * @param customInstructionData The entire instruction data array for the custom instruction.
17
- */
18
- export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
@@ -1,31 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createMinimalEd25519VerifyIx = exports.getEd25519ArgsFromHex = exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
27
- const web3_js_1 = require("@solana/web3.js");
28
- const BufferLayout = __importStar(require("@solana/buffer-layout"));
3
+ exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
29
4
  function trimFeedId(feedId) {
30
5
  if (feedId.startsWith('0x')) {
31
6
  return feedId.slice(2);
@@ -38,80 +13,3 @@ function getFeedIdUint8Array(feedId) {
38
13
  return Uint8Array.from(Buffer.from(trimmedFeedId, 'hex'));
39
14
  }
40
15
  exports.getFeedIdUint8Array = getFeedIdUint8Array;
41
- const ED25519_INSTRUCTION_LEN = 16;
42
- const SIGNATURE_LEN = 64;
43
- const PUBKEY_LEN = 32;
44
- const MAGIC_LEN = 4;
45
- const MESSAGE_SIZE_LEN = 2;
46
- function getEd25519ArgsFromHex(hex, customInstructionIndex) {
47
- const cleanedHex = hex.startsWith('0x') ? hex.slice(2) : hex;
48
- const buffer = new Uint8Array(Buffer.from(cleanedHex, 'hex'));
49
- const signatureOffset = MAGIC_LEN;
50
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
51
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
52
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
53
- const signature = buffer.slice(signatureOffset, signatureOffset + SIGNATURE_LEN);
54
- const publicKey = buffer.slice(publicKeyOffset, publicKeyOffset + PUBKEY_LEN);
55
- const messageSize = buffer[messageDataSizeOffset] | (buffer[messageDataSizeOffset + 1] << 8);
56
- const message = buffer.slice(messageDataOffset, messageDataOffset + messageSize);
57
- if (publicKey.length !== PUBKEY_LEN) {
58
- throw new Error('Invalid public key length');
59
- }
60
- if (signature.length !== SIGNATURE_LEN) {
61
- throw new Error('Invalid signature length');
62
- }
63
- return {
64
- publicKey,
65
- signature,
66
- message,
67
- instructionIndex: customInstructionIndex,
68
- };
69
- }
70
- exports.getEd25519ArgsFromHex = getEd25519ArgsFromHex;
71
- const readUint16LE = (data, offset) => {
72
- return data[offset] | (data[offset + 1] << 8);
73
- };
74
- const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
75
- BufferLayout.u8('numSignatures'),
76
- BufferLayout.u8('padding'),
77
- BufferLayout.u16('signatureOffset'),
78
- BufferLayout.u16('signatureInstructionIndex'),
79
- BufferLayout.u16('publicKeyOffset'),
80
- BufferLayout.u16('publicKeyInstructionIndex'),
81
- BufferLayout.u16('messageDataOffset'),
82
- BufferLayout.u16('messageDataSize'),
83
- BufferLayout.u16('messageInstructionIndex'),
84
- ]);
85
- /**
86
- * Constructs a minimal Ed25519 verification instruction that references the data
87
- * inside the main instruction (postPythLazerOracleUpdate).
88
- *
89
- * @param customInstructionIndex The index of the custom instruction in the transaction (typically 1 if this is second).
90
- * @param messageOffset The offset within the custom instruction data where the pythMessage begins.
91
- * @param customInstructionData The entire instruction data array for the custom instruction.
92
- */
93
- function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
94
- const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
95
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
96
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
97
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
98
- const messageDataSize = readUint16LE(customInstructionData, messageDataSizeOffset - messageOffset);
99
- const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
100
- ED25519_INSTRUCTION_LAYOUT.encode({
101
- numSignatures: 1,
102
- padding: 0,
103
- signatureOffset,
104
- signatureInstructionIndex: customInstructionIndex,
105
- publicKeyOffset,
106
- publicKeyInstructionIndex: customInstructionIndex,
107
- messageDataOffset,
108
- messageDataSize: messageDataSize,
109
- messageInstructionIndex: customInstructionIndex,
110
- }, instructionData);
111
- return new web3_js_1.TransactionInstruction({
112
- keys: [],
113
- programId: web3_js_1.Ed25519Program.programId,
114
- data: instructionData,
115
- });
116
- }
117
- exports.createMinimalEd25519VerifyIx = createMinimalEd25519VerifyIx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.110.0-beta.15",
3
+ "version": "2.110.0-beta.16",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -166,11 +166,8 @@ import {
166
166
  } from '@pythnetwork/pyth-solana-receiver/lib/address';
167
167
  import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
168
168
  import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
169
- import {
170
- getFeedIdUint8Array,
171
- trimFeedId,
172
- createMinimalEd25519VerifyIx,
173
- } from './util/pythOracleUtils';
169
+ import { getFeedIdUint8Array, trimFeedId } from './util/pythOracleUtils';
170
+ import { createMinimalEd25519VerifyIx } from './signedMsg/ed25519Utils';
174
171
  import { isVersionedTransaction } from './tx/utils';
175
172
  import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
176
173
  import { asV0Tx, PullFeed } from '@switchboard-xyz/on-demand';
package/src/index.ts CHANGED
@@ -88,7 +88,7 @@ export * from './oracles/pythPullClient';
88
88
  export * from './oracles/pythLazerClient';
89
89
  export * from './oracles/switchboardOnDemandClient';
90
90
  export * from './oracles/oracleId';
91
- export * from './swift/swiftOrderSubscriber';
91
+ export * from './signedMsg/signedMsgOrderSubscriber';
92
92
  export * from './tx/fastSingleTxSender';
93
93
  export * from './tx/retryTxSender';
94
94
  export * from './tx/whileValidTxSender';
@@ -0,0 +1,85 @@
1
+ import { Ed25519Program, TransactionInstruction } from '@solana/web3.js';
2
+ import * as BufferLayout from '@solana/buffer-layout';
3
+
4
+ const ED25519_INSTRUCTION_LEN = 16;
5
+ const SIGNATURE_LEN = 64;
6
+ const PUBKEY_LEN = 32;
7
+ const MAGIC_LEN = 4;
8
+ const MESSAGE_SIZE_LEN = 2;
9
+
10
+ const readUint16LE = (data: Uint8Array, offset: number) => {
11
+ return data[offset] | (data[offset + 1] << 8);
12
+ };
13
+
14
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct<
15
+ Readonly<{
16
+ messageDataOffset: number;
17
+ messageDataSize: number;
18
+ messageInstructionIndex: number;
19
+ numSignatures: number;
20
+ padding: number;
21
+ publicKeyInstructionIndex: number;
22
+ publicKeyOffset: number;
23
+ signatureInstructionIndex: number;
24
+ signatureOffset: number;
25
+ }>
26
+ >([
27
+ BufferLayout.u8('numSignatures'),
28
+ BufferLayout.u8('padding'),
29
+ BufferLayout.u16('signatureOffset'),
30
+ BufferLayout.u16('signatureInstructionIndex'),
31
+ BufferLayout.u16('publicKeyOffset'),
32
+ BufferLayout.u16('publicKeyInstructionIndex'),
33
+ BufferLayout.u16('messageDataOffset'),
34
+ BufferLayout.u16('messageDataSize'),
35
+ BufferLayout.u16('messageInstructionIndex'),
36
+ ]);
37
+
38
+ /**
39
+ * Constructs a minimal Ed25519 verification instruction that references the data
40
+ * inside the drift custom instruction (e.g. postPythLazerOracleUpdate, placeSignedMsgTakerOrder).
41
+ *
42
+ * @param customInstructionIndex The index of the custom instruction in the transaction (e.g. if tx contains compute budget limit, compute budget price, ed25519 verify, custom ix, this would be 3).
43
+ * @param messageOffset The offset within the custom instruction data where the signed message begins.
44
+ * @param customInstructionData The entire instruction data array for the custom instruction.
45
+ */
46
+ export function createMinimalEd25519VerifyIx(
47
+ customInstructionIndex: number,
48
+ messageOffset: number,
49
+ customInstructionData: Uint8Array,
50
+ magicLen?: number
51
+ ): TransactionInstruction {
52
+ const signatureOffset =
53
+ messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
54
+ const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
55
+ const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
56
+ const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
57
+
58
+ const messageDataSize = readUint16LE(
59
+ customInstructionData,
60
+ messageDataSizeOffset - messageOffset
61
+ );
62
+
63
+ const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
64
+
65
+ ED25519_INSTRUCTION_LAYOUT.encode(
66
+ {
67
+ numSignatures: 1,
68
+ padding: 0,
69
+ signatureOffset,
70
+ signatureInstructionIndex: customInstructionIndex,
71
+ publicKeyOffset,
72
+ publicKeyInstructionIndex: customInstructionIndex,
73
+ messageDataOffset,
74
+ messageDataSize: messageDataSize,
75
+ messageInstructionIndex: customInstructionIndex,
76
+ },
77
+ instructionData
78
+ );
79
+
80
+ return new TransactionInstruction({
81
+ keys: [],
82
+ programId: Ed25519Program.programId,
83
+ data: instructionData,
84
+ });
85
+ }
@@ -118,7 +118,7 @@ export class SignedMsgOrderSubscriber {
118
118
  }
119
119
 
120
120
  if (message['order']) {
121
- const order = JSON.parse(message['order']);
121
+ const order = message['order'];
122
122
  const signedMsgOrderParamsBuf = Buffer.from(
123
123
  order['order_message'],
124
124
  'hex'
@@ -1,6 +1,3 @@
1
- import { TransactionInstruction, Ed25519Program } from '@solana/web3.js';
2
- import * as BufferLayout from '@solana/buffer-layout';
3
-
4
1
  export function trimFeedId(feedId: string): string {
5
2
  if (feedId.startsWith('0x')) {
6
3
  return feedId.slice(2);
@@ -12,131 +9,3 @@ export function getFeedIdUint8Array(feedId: string): Uint8Array {
12
9
  const trimmedFeedId = trimFeedId(feedId);
13
10
  return Uint8Array.from(Buffer.from(trimmedFeedId, 'hex'));
14
11
  }
15
-
16
- const ED25519_INSTRUCTION_LEN = 16;
17
- const SIGNATURE_LEN = 64;
18
- const PUBKEY_LEN = 32;
19
- const MAGIC_LEN = 4;
20
- const MESSAGE_SIZE_LEN = 2;
21
-
22
- export function getEd25519ArgsFromHex(
23
- hex: string,
24
- customInstructionIndex?: number
25
- ): {
26
- publicKey: Uint8Array;
27
- signature: Uint8Array;
28
- message: Uint8Array;
29
- instructionIndex?: number;
30
- } {
31
- const cleanedHex = hex.startsWith('0x') ? hex.slice(2) : hex;
32
- const buffer = new Uint8Array(Buffer.from(cleanedHex, 'hex'));
33
-
34
- const signatureOffset = MAGIC_LEN;
35
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
36
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
37
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
38
-
39
- const signature = buffer.slice(
40
- signatureOffset,
41
- signatureOffset + SIGNATURE_LEN
42
- );
43
- const publicKey = buffer.slice(publicKeyOffset, publicKeyOffset + PUBKEY_LEN);
44
- const messageSize =
45
- buffer[messageDataSizeOffset] | (buffer[messageDataSizeOffset + 1] << 8);
46
- const message = buffer.slice(
47
- messageDataOffset,
48
- messageDataOffset + messageSize
49
- );
50
-
51
- if (publicKey.length !== PUBKEY_LEN) {
52
- throw new Error('Invalid public key length');
53
- }
54
-
55
- if (signature.length !== SIGNATURE_LEN) {
56
- throw new Error('Invalid signature length');
57
- }
58
-
59
- return {
60
- publicKey,
61
- signature,
62
- message,
63
- instructionIndex: customInstructionIndex,
64
- };
65
- }
66
-
67
- const readUint16LE = (data: Uint8Array, offset: number) => {
68
- return data[offset] | (data[offset + 1] << 8);
69
- };
70
-
71
- const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct<
72
- Readonly<{
73
- messageDataOffset: number;
74
- messageDataSize: number;
75
- messageInstructionIndex: number;
76
- numSignatures: number;
77
- padding: number;
78
- publicKeyInstructionIndex: number;
79
- publicKeyOffset: number;
80
- signatureInstructionIndex: number;
81
- signatureOffset: number;
82
- }>
83
- >([
84
- BufferLayout.u8('numSignatures'),
85
- BufferLayout.u8('padding'),
86
- BufferLayout.u16('signatureOffset'),
87
- BufferLayout.u16('signatureInstructionIndex'),
88
- BufferLayout.u16('publicKeyOffset'),
89
- BufferLayout.u16('publicKeyInstructionIndex'),
90
- BufferLayout.u16('messageDataOffset'),
91
- BufferLayout.u16('messageDataSize'),
92
- BufferLayout.u16('messageInstructionIndex'),
93
- ]);
94
-
95
- /**
96
- * Constructs a minimal Ed25519 verification instruction that references the data
97
- * inside the main instruction (postPythLazerOracleUpdate).
98
- *
99
- * @param customInstructionIndex The index of the custom instruction in the transaction (typically 1 if this is second).
100
- * @param messageOffset The offset within the custom instruction data where the pythMessage begins.
101
- * @param customInstructionData The entire instruction data array for the custom instruction.
102
- */
103
- export function createMinimalEd25519VerifyIx(
104
- customInstructionIndex: number,
105
- messageOffset: number,
106
- customInstructionData: Uint8Array,
107
- magicLen?: number
108
- ): TransactionInstruction {
109
- const signatureOffset =
110
- messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
111
- const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
112
- const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
113
- const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
114
-
115
- const messageDataSize = readUint16LE(
116
- customInstructionData,
117
- messageDataSizeOffset - messageOffset
118
- );
119
-
120
- const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
121
-
122
- ED25519_INSTRUCTION_LAYOUT.encode(
123
- {
124
- numSignatures: 1,
125
- padding: 0,
126
- signatureOffset,
127
- signatureInstructionIndex: customInstructionIndex,
128
- publicKeyOffset,
129
- publicKeyInstructionIndex: customInstructionIndex,
130
- messageDataOffset,
131
- messageDataSize: messageDataSize,
132
- messageInstructionIndex: customInstructionIndex,
133
- },
134
- instructionData
135
- );
136
-
137
- return new TransactionInstruction({
138
- keys: [],
139
- programId: Ed25519Program.programId,
140
- data: instructionData,
141
- });
142
- }