From db3a6d0e052fe1cf2ad6188040a1686efe3a8cb9 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 9 Jan 2025 21:55:07 +0800 Subject: [PATCH] fix swift localValidator test --- sdk/src/swift/swiftOrderSubscriber.ts | 6 +++++- tests/placeAndMakeSwiftPerp.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sdk/src/swift/swiftOrderSubscriber.ts b/sdk/src/swift/swiftOrderSubscriber.ts index 606353141..9c62f6036 100644 --- a/sdk/src/swift/swiftOrderSubscriber.ts +++ b/sdk/src/swift/swiftOrderSubscriber.ts @@ -153,6 +153,10 @@ export class SwiftOrderSubscriber { swiftOrderParamsMessage: SwiftOrderParamsMessage, makerOrderParams: OptionalOrderParams ): Promise { + const swiftOrderParamsBuf = Buffer.from( + orderMessageRaw['order_message'], + 'hex' + ); const takerAuthority = new PublicKey(orderMessageRaw['taker_authority']); const takerUserPubkey = await getUserAccountPublicKey( this.driftClient.program.programId, @@ -164,7 +168,7 @@ export class SwiftOrderSubscriber { ).getUserAccount(); const ixs = await this.driftClient.getPlaceAndMakeSwiftPerpOrderIxs( { - orderParams: orderMessageRaw['order_message'], + orderParams: swiftOrderParamsBuf, signature: Buffer.from(orderMessageRaw['order_signature'], 'base64'), }, decodeUTF8(orderMessageRaw['uuid']), diff --git a/tests/placeAndMakeSwiftPerp.ts b/tests/placeAndMakeSwiftPerp.ts index 349c3e4cc..f7c07ac84 100644 --- a/tests/placeAndMakeSwiftPerp.ts +++ b/tests/placeAndMakeSwiftPerp.ts @@ -365,8 +365,11 @@ describe('place and make swift order', () => { immediateOrCancel: true, }); - const signedOrderParams = takerDriftClient.signSwiftOrderParamsMessage( - takerOrderParamsMessage + const takerOrderParamsMessageEncoded = + takerDriftClient.encodeSwiftOrderParamsMessage(takerOrderParamsMessage); + const takerOrderParamsSig = takerDriftClient.signMessage( + Buffer.from(takerOrderParamsMessageEncoded.toString('hex')), + makerDriftClient.wallet.payer ); const ixs = [ @@ -376,7 +379,12 @@ describe('place and make swift order', () => { ]; ixs.push( ...(await makerDriftClient.getPlaceAndMakeSwiftPerpOrderIxs( - signedOrderParams, + { + orderParams: Buffer.from( + takerOrderParamsMessageEncoded.toString('hex') + ), + signature: takerOrderParamsSig, + }, uuid, { taker: await takerDriftClient.getUserAccountPublicKey(),