@drift-labs/sdk 2.105.0-beta.2 → 2.105.0-beta.3
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 +1 -1
- package/lib/browser/driftClient.d.ts +4 -4
- package/lib/browser/driftClient.js +18 -15
- package/lib/browser/idl/drift.json +35 -0
- package/lib/browser/util/pythOracleUtils.d.ts +1 -1
- package/lib/browser/util/pythOracleUtils.js +2 -2
- package/lib/node/driftClient.d.ts +4 -4
- package/lib/node/driftClient.js +18 -15
- package/lib/node/idl/drift.json +35 -0
- package/lib/node/util/pythOracleUtils.d.ts +1 -1
- package/lib/node/util/pythOracleUtils.js +2 -2
- package/package.json +1 -1
- package/src/driftClient.ts +54 -36
- package/src/idl/drift.json +35 -0
- package/src/util/pythOracleUtils.ts +4 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.105.0-beta.
|
|
1
|
+
2.105.0-beta.3
|
|
@@ -540,22 +540,22 @@ export declare class DriftClient {
|
|
|
540
540
|
taker: PublicKey;
|
|
541
541
|
takerStats: PublicKey;
|
|
542
542
|
takerUserAccount: UserAccount;
|
|
543
|
-
}, txParams?: TxParams): Promise<TransactionSignature>;
|
|
543
|
+
}, precedingIxs?: TransactionInstruction[], overrideIxCount?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
544
544
|
getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
|
|
545
545
|
taker: PublicKey;
|
|
546
546
|
takerStats: PublicKey;
|
|
547
547
|
takerUserAccount: UserAccount;
|
|
548
|
-
}, authority?: PublicKey): Promise<TransactionInstruction[]>;
|
|
548
|
+
}, authority?: PublicKey, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionInstruction[]>;
|
|
549
549
|
placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
|
|
550
550
|
taker: PublicKey;
|
|
551
551
|
takerStats: PublicKey;
|
|
552
552
|
takerUserAccount: UserAccount;
|
|
553
|
-
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
553
|
+
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionSignature>;
|
|
554
554
|
getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
|
|
555
555
|
taker: PublicKey;
|
|
556
556
|
takerStats: PublicKey;
|
|
557
557
|
takerUserAccount: UserAccount;
|
|
558
|
-
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction[]>;
|
|
558
|
+
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, subAccountId?: number, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionInstruction[]>;
|
|
559
559
|
encodeRFQMakerOrderParams(message: RFQMakerOrderParams): Buffer;
|
|
560
560
|
placeAndMatchRFQOrders(rfqMatches: RFQMatch[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
561
561
|
getPlaceAndMatchRFQOrdersIxs(rfqMatches: RFQMatch[]): Promise<TransactionInstruction[]>;
|
|
@@ -69,7 +69,6 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
|
|
|
69
69
|
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
70
70
|
const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
|
|
71
71
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
72
|
-
const digest_1 = require("./util/digest");
|
|
73
72
|
const oracleId_1 = require("./oracles/oracleId");
|
|
74
73
|
/**
|
|
75
74
|
* # DriftClient
|
|
@@ -3183,7 +3182,7 @@ class DriftClient {
|
|
|
3183
3182
|
}
|
|
3184
3183
|
signSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3185
3184
|
const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage);
|
|
3186
|
-
return this.signMessage(
|
|
3185
|
+
return this.signMessage(takerOrderParamsMessage);
|
|
3187
3186
|
}
|
|
3188
3187
|
encodeSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3189
3188
|
return this.program.coder.types.encode('SwiftOrderParamsMessage', orderParamsMessage);
|
|
@@ -3194,12 +3193,12 @@ class DriftClient {
|
|
|
3194
3193
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3195
3194
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
|
3196
3195
|
}
|
|
3197
|
-
async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
|
|
3198
|
-
const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
|
|
3196
|
+
async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, precedingIxs = [], overrideIxCount, txParams) {
|
|
3197
|
+
const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, undefined, precedingIxs, overrideIxCount);
|
|
3199
3198
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3200
3199
|
return txSig;
|
|
3201
3200
|
}
|
|
3202
|
-
async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
|
|
3201
|
+
async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority, precedingIxs = [], overrideIxCount) {
|
|
3203
3202
|
if (!authority && !takerInfo.takerUserAccount) {
|
|
3204
3203
|
throw new Error('authority or takerUserAccount must be provided');
|
|
3205
3204
|
}
|
|
@@ -3209,12 +3208,16 @@ class DriftClient {
|
|
|
3209
3208
|
readablePerpMarketIndex: marketIndex,
|
|
3210
3209
|
});
|
|
3211
3210
|
const authorityToUse = authority || takerInfo.takerUserAccount.authority;
|
|
3212
|
-
const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3211
|
+
const messageLengthBuffer = Buffer.alloc(2);
|
|
3212
|
+
messageLengthBuffer.writeUInt16LE(encodedSwiftOrderParamsMessage.length);
|
|
3213
|
+
const swiftIxData = Buffer.concat([
|
|
3214
|
+
swiftOrderParamsSignature,
|
|
3215
|
+
authorityToUse.toBytes(),
|
|
3216
|
+
messageLengthBuffer,
|
|
3217
|
+
encodedSwiftOrderParamsMessage,
|
|
3218
|
+
]);
|
|
3219
|
+
const swiftOrderParamsSignatureIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, swiftIxData, 0);
|
|
3220
|
+
const placeTakerSwiftPerpOrderIx = this.program.instruction.placeSwiftTakerOrder(swiftIxData, {
|
|
3218
3221
|
accounts: {
|
|
3219
3222
|
state: await this.getStatePublicKey(),
|
|
3220
3223
|
user: takerInfo.taker,
|
|
@@ -3227,14 +3230,14 @@ class DriftClient {
|
|
|
3227
3230
|
});
|
|
3228
3231
|
return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
|
|
3229
3232
|
}
|
|
3230
|
-
async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
|
|
3231
|
-
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
|
|
3233
|
+
async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3234
|
+
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs, overrideIxCount);
|
|
3232
3235
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3233
3236
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
3234
3237
|
return txSig;
|
|
3235
3238
|
}
|
|
3236
|
-
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
|
|
3237
|
-
const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
|
|
3239
|
+
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3240
|
+
const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo, undefined, precedingIxs, overrideIxCount);
|
|
3238
3241
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
3239
3242
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3240
3243
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
@@ -11749,6 +11749,41 @@
|
|
|
11749
11749
|
}
|
|
11750
11750
|
]
|
|
11751
11751
|
}
|
|
11752
|
+
},
|
|
11753
|
+
{
|
|
11754
|
+
"name": "SignatureVerificationError",
|
|
11755
|
+
"type": {
|
|
11756
|
+
"kind": "enum",
|
|
11757
|
+
"variants": [
|
|
11758
|
+
{
|
|
11759
|
+
"name": "InvalidEd25519InstructionProgramId"
|
|
11760
|
+
},
|
|
11761
|
+
{
|
|
11762
|
+
"name": "InvalidEd25519InstructionDataLength"
|
|
11763
|
+
},
|
|
11764
|
+
{
|
|
11765
|
+
"name": "InvalidSignatureIndex"
|
|
11766
|
+
},
|
|
11767
|
+
{
|
|
11768
|
+
"name": "InvalidSignatureOffset"
|
|
11769
|
+
},
|
|
11770
|
+
{
|
|
11771
|
+
"name": "InvalidPublicKeyOffset"
|
|
11772
|
+
},
|
|
11773
|
+
{
|
|
11774
|
+
"name": "InvalidMessageOffset"
|
|
11775
|
+
},
|
|
11776
|
+
{
|
|
11777
|
+
"name": "InvalidMessageDataSize"
|
|
11778
|
+
},
|
|
11779
|
+
{
|
|
11780
|
+
"name": "InvalidInstructionIndex"
|
|
11781
|
+
},
|
|
11782
|
+
{
|
|
11783
|
+
"name": "MessageOffsetOverflow"
|
|
11784
|
+
}
|
|
11785
|
+
]
|
|
11786
|
+
}
|
|
11752
11787
|
}
|
|
11753
11788
|
],
|
|
11754
11789
|
"events": [
|
|
@@ -15,4 +15,4 @@ export declare function getEd25519ArgsFromHex(hex: string, customInstructionInde
|
|
|
15
15
|
* @param messageOffset The offset within the custom instruction data where the pythMessage begins.
|
|
16
16
|
* @param customInstructionData The entire instruction data array for the custom instruction.
|
|
17
17
|
*/
|
|
18
|
-
export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array): TransactionInstruction;
|
|
18
|
+
export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
|
|
@@ -89,8 +89,8 @@ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
|
|
|
89
89
|
* @param messageOffset The offset within the custom instruction data where the pythMessage begins.
|
|
90
90
|
* @param customInstructionData The entire instruction data array for the custom instruction.
|
|
91
91
|
*/
|
|
92
|
-
function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData) {
|
|
93
|
-
const signatureOffset = messageOffset + MAGIC_LEN;
|
|
92
|
+
function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
|
|
93
|
+
const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
|
|
94
94
|
const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
|
|
95
95
|
const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
|
|
96
96
|
const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
|
|
@@ -540,22 +540,22 @@ export declare class DriftClient {
|
|
|
540
540
|
taker: PublicKey;
|
|
541
541
|
takerStats: PublicKey;
|
|
542
542
|
takerUserAccount: UserAccount;
|
|
543
|
-
}, txParams?: TxParams): Promise<TransactionSignature>;
|
|
543
|
+
}, precedingIxs?: TransactionInstruction[], overrideIxCount?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
544
544
|
getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
|
|
545
545
|
taker: PublicKey;
|
|
546
546
|
takerStats: PublicKey;
|
|
547
547
|
takerUserAccount: UserAccount;
|
|
548
|
-
}, authority?: PublicKey): Promise<TransactionInstruction[]>;
|
|
548
|
+
}, authority?: PublicKey, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionInstruction[]>;
|
|
549
549
|
placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
|
|
550
550
|
taker: PublicKey;
|
|
551
551
|
takerStats: PublicKey;
|
|
552
552
|
takerUserAccount: UserAccount;
|
|
553
|
-
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
553
|
+
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionSignature>;
|
|
554
554
|
getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
|
|
555
555
|
taker: PublicKey;
|
|
556
556
|
takerStats: PublicKey;
|
|
557
557
|
takerUserAccount: UserAccount;
|
|
558
|
-
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction[]>;
|
|
558
|
+
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, subAccountId?: number, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionInstruction[]>;
|
|
559
559
|
encodeRFQMakerOrderParams(message: RFQMakerOrderParams): Buffer;
|
|
560
560
|
placeAndMatchRFQOrders(rfqMatches: RFQMatch[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
561
561
|
getPlaceAndMatchRFQOrdersIxs(rfqMatches: RFQMatch[]): Promise<TransactionInstruction[]>;
|
package/lib/node/driftClient.js
CHANGED
|
@@ -69,7 +69,6 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
|
|
|
69
69
|
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
70
70
|
const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
|
|
71
71
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
72
|
-
const digest_1 = require("./util/digest");
|
|
73
72
|
const oracleId_1 = require("./oracles/oracleId");
|
|
74
73
|
/**
|
|
75
74
|
* # DriftClient
|
|
@@ -3183,7 +3182,7 @@ class DriftClient {
|
|
|
3183
3182
|
}
|
|
3184
3183
|
signSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3185
3184
|
const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage);
|
|
3186
|
-
return this.signMessage(
|
|
3185
|
+
return this.signMessage(takerOrderParamsMessage);
|
|
3187
3186
|
}
|
|
3188
3187
|
encodeSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3189
3188
|
return this.program.coder.types.encode('SwiftOrderParamsMessage', orderParamsMessage);
|
|
@@ -3194,12 +3193,12 @@ class DriftClient {
|
|
|
3194
3193
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3195
3194
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
|
3196
3195
|
}
|
|
3197
|
-
async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
|
|
3198
|
-
const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
|
|
3196
|
+
async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, precedingIxs = [], overrideIxCount, txParams) {
|
|
3197
|
+
const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, undefined, precedingIxs, overrideIxCount);
|
|
3199
3198
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3200
3199
|
return txSig;
|
|
3201
3200
|
}
|
|
3202
|
-
async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
|
|
3201
|
+
async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority, precedingIxs = [], overrideIxCount) {
|
|
3203
3202
|
if (!authority && !takerInfo.takerUserAccount) {
|
|
3204
3203
|
throw new Error('authority or takerUserAccount must be provided');
|
|
3205
3204
|
}
|
|
@@ -3209,12 +3208,16 @@ class DriftClient {
|
|
|
3209
3208
|
readablePerpMarketIndex: marketIndex,
|
|
3210
3209
|
});
|
|
3211
3210
|
const authorityToUse = authority || takerInfo.takerUserAccount.authority;
|
|
3212
|
-
const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3211
|
+
const messageLengthBuffer = Buffer.alloc(2);
|
|
3212
|
+
messageLengthBuffer.writeUInt16LE(encodedSwiftOrderParamsMessage.length);
|
|
3213
|
+
const swiftIxData = Buffer.concat([
|
|
3214
|
+
swiftOrderParamsSignature,
|
|
3215
|
+
authorityToUse.toBytes(),
|
|
3216
|
+
messageLengthBuffer,
|
|
3217
|
+
encodedSwiftOrderParamsMessage,
|
|
3218
|
+
]);
|
|
3219
|
+
const swiftOrderParamsSignatureIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, swiftIxData, 0);
|
|
3220
|
+
const placeTakerSwiftPerpOrderIx = this.program.instruction.placeSwiftTakerOrder(swiftIxData, {
|
|
3218
3221
|
accounts: {
|
|
3219
3222
|
state: await this.getStatePublicKey(),
|
|
3220
3223
|
user: takerInfo.taker,
|
|
@@ -3227,14 +3230,14 @@ class DriftClient {
|
|
|
3227
3230
|
});
|
|
3228
3231
|
return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
|
|
3229
3232
|
}
|
|
3230
|
-
async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
|
|
3231
|
-
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
|
|
3233
|
+
async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3234
|
+
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs, overrideIxCount);
|
|
3232
3235
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3233
3236
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
3234
3237
|
return txSig;
|
|
3235
3238
|
}
|
|
3236
|
-
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
|
|
3237
|
-
const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
|
|
3239
|
+
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3240
|
+
const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo, undefined, precedingIxs, overrideIxCount);
|
|
3238
3241
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
3239
3242
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3240
3243
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
package/lib/node/idl/drift.json
CHANGED
|
@@ -11749,6 +11749,41 @@
|
|
|
11749
11749
|
}
|
|
11750
11750
|
]
|
|
11751
11751
|
}
|
|
11752
|
+
},
|
|
11753
|
+
{
|
|
11754
|
+
"name": "SignatureVerificationError",
|
|
11755
|
+
"type": {
|
|
11756
|
+
"kind": "enum",
|
|
11757
|
+
"variants": [
|
|
11758
|
+
{
|
|
11759
|
+
"name": "InvalidEd25519InstructionProgramId"
|
|
11760
|
+
},
|
|
11761
|
+
{
|
|
11762
|
+
"name": "InvalidEd25519InstructionDataLength"
|
|
11763
|
+
},
|
|
11764
|
+
{
|
|
11765
|
+
"name": "InvalidSignatureIndex"
|
|
11766
|
+
},
|
|
11767
|
+
{
|
|
11768
|
+
"name": "InvalidSignatureOffset"
|
|
11769
|
+
},
|
|
11770
|
+
{
|
|
11771
|
+
"name": "InvalidPublicKeyOffset"
|
|
11772
|
+
},
|
|
11773
|
+
{
|
|
11774
|
+
"name": "InvalidMessageOffset"
|
|
11775
|
+
},
|
|
11776
|
+
{
|
|
11777
|
+
"name": "InvalidMessageDataSize"
|
|
11778
|
+
},
|
|
11779
|
+
{
|
|
11780
|
+
"name": "InvalidInstructionIndex"
|
|
11781
|
+
},
|
|
11782
|
+
{
|
|
11783
|
+
"name": "MessageOffsetOverflow"
|
|
11784
|
+
}
|
|
11785
|
+
]
|
|
11786
|
+
}
|
|
11752
11787
|
}
|
|
11753
11788
|
],
|
|
11754
11789
|
"events": [
|
|
@@ -15,4 +15,4 @@ export declare function getEd25519ArgsFromHex(hex: string, customInstructionInde
|
|
|
15
15
|
* @param messageOffset The offset within the custom instruction data where the pythMessage begins.
|
|
16
16
|
* @param customInstructionData The entire instruction data array for the custom instruction.
|
|
17
17
|
*/
|
|
18
|
-
export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array): TransactionInstruction;
|
|
18
|
+
export declare function createMinimalEd25519VerifyIx(customInstructionIndex: number, messageOffset: number, customInstructionData: Uint8Array, magicLen?: number): TransactionInstruction;
|
|
@@ -89,8 +89,8 @@ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
|
|
|
89
89
|
* @param messageOffset The offset within the custom instruction data where the pythMessage begins.
|
|
90
90
|
* @param customInstructionData The entire instruction data array for the custom instruction.
|
|
91
91
|
*/
|
|
92
|
-
function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData) {
|
|
93
|
-
const signatureOffset = messageOffset + MAGIC_LEN;
|
|
92
|
+
function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, customInstructionData, magicLen) {
|
|
93
|
+
const signatureOffset = messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
|
|
94
94
|
const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
|
|
95
95
|
const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
|
|
96
96
|
const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -179,7 +179,6 @@ import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
|
|
|
179
179
|
import { asV0Tx, PullFeed } from '@switchboard-xyz/on-demand';
|
|
180
180
|
import { gprcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
181
181
|
import nacl from 'tweetnacl';
|
|
182
|
-
import { digest } from './util/digest';
|
|
183
182
|
import { Slothash } from './slot/SlothashSubscriber';
|
|
184
183
|
import { getOracleId } from './oracles/oracleId';
|
|
185
184
|
|
|
@@ -5886,9 +5885,7 @@ export class DriftClient {
|
|
|
5886
5885
|
): Buffer {
|
|
5887
5886
|
const takerOrderParamsMessage =
|
|
5888
5887
|
this.encodeSwiftOrderParamsMessage(orderParamsMessage);
|
|
5889
|
-
return this.signMessage(
|
|
5890
|
-
new TextEncoder().encode(digest(takerOrderParamsMessage).toString('hex'))
|
|
5891
|
-
);
|
|
5888
|
+
return this.signMessage(takerOrderParamsMessage);
|
|
5892
5889
|
}
|
|
5893
5890
|
|
|
5894
5891
|
public encodeSwiftOrderParamsMessage(
|
|
@@ -5925,13 +5922,18 @@ export class DriftClient {
|
|
|
5925
5922
|
takerStats: PublicKey;
|
|
5926
5923
|
takerUserAccount: UserAccount;
|
|
5927
5924
|
},
|
|
5925
|
+
precedingIxs: TransactionInstruction[] = [],
|
|
5926
|
+
overrideIxCount?: number,
|
|
5928
5927
|
txParams?: TxParams
|
|
5929
5928
|
): Promise<TransactionSignature> {
|
|
5930
5929
|
const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(
|
|
5931
5930
|
swiftOrderParamsMessage,
|
|
5932
5931
|
swiftOrderParamsSignature,
|
|
5933
5932
|
marketIndex,
|
|
5934
|
-
takerInfo
|
|
5933
|
+
takerInfo,
|
|
5934
|
+
undefined,
|
|
5935
|
+
precedingIxs,
|
|
5936
|
+
overrideIxCount
|
|
5935
5937
|
);
|
|
5936
5938
|
const { txSig } = await this.sendTransaction(
|
|
5937
5939
|
await this.buildTransaction(ixs, txParams),
|
|
@@ -5950,7 +5952,9 @@ export class DriftClient {
|
|
|
5950
5952
|
takerStats: PublicKey;
|
|
5951
5953
|
takerUserAccount: UserAccount;
|
|
5952
5954
|
},
|
|
5953
|
-
authority?: PublicKey
|
|
5955
|
+
authority?: PublicKey,
|
|
5956
|
+
precedingIxs: TransactionInstruction[] = [],
|
|
5957
|
+
overrideIxCount?: number
|
|
5954
5958
|
): Promise<TransactionInstruction[]> {
|
|
5955
5959
|
if (!authority && !takerInfo.takerUserAccount) {
|
|
5956
5960
|
throw new Error('authority or takerUserAccount must be provided');
|
|
@@ -5963,33 +5967,39 @@ export class DriftClient {
|
|
|
5963
5967
|
});
|
|
5964
5968
|
|
|
5965
5969
|
const authorityToUse = authority || takerInfo.takerUserAccount.authority;
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5970
|
+
|
|
5971
|
+
const messageLengthBuffer = Buffer.alloc(2);
|
|
5972
|
+
messageLengthBuffer.writeUInt16LE(encodedSwiftOrderParamsMessage.length);
|
|
5973
|
+
|
|
5974
|
+
const swiftIxData = Buffer.concat([
|
|
5975
|
+
swiftOrderParamsSignature,
|
|
5976
|
+
authorityToUse.toBytes(),
|
|
5977
|
+
messageLengthBuffer,
|
|
5978
|
+
encodedSwiftOrderParamsMessage,
|
|
5979
|
+
]);
|
|
5980
|
+
|
|
5981
|
+
const swiftOrderParamsSignatureIx = createMinimalEd25519VerifyIx(
|
|
5982
|
+
overrideIxCount || precedingIxs.length + 1,
|
|
5983
|
+
12,
|
|
5984
|
+
swiftIxData,
|
|
5985
|
+
0
|
|
5986
|
+
);
|
|
5974
5987
|
|
|
5975
5988
|
const placeTakerSwiftPerpOrderIx =
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
remainingAccounts,
|
|
5991
|
-
}
|
|
5992
|
-
);
|
|
5989
|
+
this.program.instruction.placeSwiftTakerOrder(swiftIxData, {
|
|
5990
|
+
accounts: {
|
|
5991
|
+
state: await this.getStatePublicKey(),
|
|
5992
|
+
user: takerInfo.taker,
|
|
5993
|
+
userStats: takerInfo.takerStats,
|
|
5994
|
+
swiftUserOrders: getSwiftUserAccountPublicKey(
|
|
5995
|
+
this.program.programId,
|
|
5996
|
+
takerInfo.taker
|
|
5997
|
+
),
|
|
5998
|
+
authority: this.wallet.publicKey,
|
|
5999
|
+
ixSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6000
|
+
},
|
|
6001
|
+
remainingAccounts,
|
|
6002
|
+
});
|
|
5993
6003
|
|
|
5994
6004
|
return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
|
|
5995
6005
|
}
|
|
@@ -6006,7 +6016,9 @@ export class DriftClient {
|
|
|
6006
6016
|
orderParams: OptionalOrderParams,
|
|
6007
6017
|
referrerInfo?: ReferrerInfo,
|
|
6008
6018
|
txParams?: TxParams,
|
|
6009
|
-
subAccountId?: number
|
|
6019
|
+
subAccountId?: number,
|
|
6020
|
+
precedingIxs: TransactionInstruction[] = [],
|
|
6021
|
+
overrideIxCount?: number
|
|
6010
6022
|
): Promise<TransactionSignature> {
|
|
6011
6023
|
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(
|
|
6012
6024
|
encodedSwiftOrderParamsMessage,
|
|
@@ -6015,7 +6027,9 @@ export class DriftClient {
|
|
|
6015
6027
|
takerInfo,
|
|
6016
6028
|
orderParams,
|
|
6017
6029
|
referrerInfo,
|
|
6018
|
-
subAccountId
|
|
6030
|
+
subAccountId,
|
|
6031
|
+
precedingIxs,
|
|
6032
|
+
overrideIxCount
|
|
6019
6033
|
);
|
|
6020
6034
|
const { txSig, slot } = await this.sendTransaction(
|
|
6021
6035
|
await this.buildTransaction(ixs, txParams),
|
|
@@ -6038,14 +6052,19 @@ export class DriftClient {
|
|
|
6038
6052
|
},
|
|
6039
6053
|
orderParams: OptionalOrderParams,
|
|
6040
6054
|
referrerInfo?: ReferrerInfo,
|
|
6041
|
-
subAccountId?: number
|
|
6055
|
+
subAccountId?: number,
|
|
6056
|
+
precedingIxs: TransactionInstruction[] = [],
|
|
6057
|
+
overrideIxCount?: number
|
|
6042
6058
|
): Promise<TransactionInstruction[]> {
|
|
6043
6059
|
const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] =
|
|
6044
6060
|
await this.getPlaceSwiftTakerPerpOrderIxs(
|
|
6045
6061
|
encodedSwiftOrderParamsMessage,
|
|
6046
6062
|
swiftOrderParamsSignature,
|
|
6047
6063
|
orderParams.marketIndex,
|
|
6048
|
-
takerInfo
|
|
6064
|
+
takerInfo,
|
|
6065
|
+
undefined,
|
|
6066
|
+
precedingIxs,
|
|
6067
|
+
overrideIxCount
|
|
6049
6068
|
);
|
|
6050
6069
|
|
|
6051
6070
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
@@ -8952,7 +8971,6 @@ export class DriftClient {
|
|
|
8952
8971
|
preSigned?: boolean
|
|
8953
8972
|
): Promise<TxSigAndSlot> {
|
|
8954
8973
|
const isVersionedTx = this.isVersionedTransaction(tx);
|
|
8955
|
-
|
|
8956
8974
|
if (isVersionedTx) {
|
|
8957
8975
|
return this.txSender.sendVersionedTransaction(
|
|
8958
8976
|
tx as VersionedTransaction,
|
package/src/idl/drift.json
CHANGED
|
@@ -11749,6 +11749,41 @@
|
|
|
11749
11749
|
}
|
|
11750
11750
|
]
|
|
11751
11751
|
}
|
|
11752
|
+
},
|
|
11753
|
+
{
|
|
11754
|
+
"name": "SignatureVerificationError",
|
|
11755
|
+
"type": {
|
|
11756
|
+
"kind": "enum",
|
|
11757
|
+
"variants": [
|
|
11758
|
+
{
|
|
11759
|
+
"name": "InvalidEd25519InstructionProgramId"
|
|
11760
|
+
},
|
|
11761
|
+
{
|
|
11762
|
+
"name": "InvalidEd25519InstructionDataLength"
|
|
11763
|
+
},
|
|
11764
|
+
{
|
|
11765
|
+
"name": "InvalidSignatureIndex"
|
|
11766
|
+
},
|
|
11767
|
+
{
|
|
11768
|
+
"name": "InvalidSignatureOffset"
|
|
11769
|
+
},
|
|
11770
|
+
{
|
|
11771
|
+
"name": "InvalidPublicKeyOffset"
|
|
11772
|
+
},
|
|
11773
|
+
{
|
|
11774
|
+
"name": "InvalidMessageOffset"
|
|
11775
|
+
},
|
|
11776
|
+
{
|
|
11777
|
+
"name": "InvalidMessageDataSize"
|
|
11778
|
+
},
|
|
11779
|
+
{
|
|
11780
|
+
"name": "InvalidInstructionIndex"
|
|
11781
|
+
},
|
|
11782
|
+
{
|
|
11783
|
+
"name": "MessageOffsetOverflow"
|
|
11784
|
+
}
|
|
11785
|
+
]
|
|
11786
|
+
}
|
|
11752
11787
|
}
|
|
11753
11788
|
],
|
|
11754
11789
|
"events": [
|
|
@@ -102,9 +102,11 @@ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct<
|
|
|
102
102
|
export function createMinimalEd25519VerifyIx(
|
|
103
103
|
customInstructionIndex: number,
|
|
104
104
|
messageOffset: number,
|
|
105
|
-
customInstructionData: Uint8Array
|
|
105
|
+
customInstructionData: Uint8Array,
|
|
106
|
+
magicLen?: number
|
|
106
107
|
): TransactionInstruction {
|
|
107
|
-
const signatureOffset =
|
|
108
|
+
const signatureOffset =
|
|
109
|
+
messageOffset + (magicLen === undefined ? MAGIC_LEN : magicLen);
|
|
108
110
|
const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
|
|
109
111
|
const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
|
|
110
112
|
const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
|