Skip to content

Commit

Permalink
get subaccount Id from order message (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordy25519 authored Nov 5, 2024
1 parent a02468c commit 0905835
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/experimental-bots/swift/makerExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,30 @@ export class SwiftMaker {
if (message['order'] && this.driftClient.isSubscribed) {
const order = JSON.parse(message['order']);
console.info(`received order. uuid: ${order['uuid']}`);
const takerAuthority = new PublicKey(order['taker_authority']);
const takerSubaccountId = order['taker_sub_account_id'] ?? 0;
const takerUserPubkey = await getUserAccountPublicKey(
this.driftClient.program.programId,
takerAuthority,
takerSubaccountId
);
const takerUserAccount = (
await this.userMap.mustGet(takerUserPubkey.toString())
).getUserAccount();

const swiftOrderParamsBuf = Buffer.from(
order['order_message'],
'base64'
);
const { swiftOrderParams }: SwiftOrderParamsMessage =
const {
swiftOrderParams,
subAccountId: takerSubaccountId,
}: SwiftOrderParamsMessage =
this.driftClient.program.coder.types.decode(
'SwiftOrderParamsMessage',
swiftOrderParamsBuf
);

const takerAuthority = new PublicKey(order['taker_authority']);
const takerUserPubkey = await getUserAccountPublicKey(
this.driftClient.program.programId,
takerAuthority,
takerSubaccountId
);
const takerUserAccount = (
await this.userMap.mustGet(takerUserPubkey.toString())
).getUserAccount();

const isOrderLong = isVariant(swiftOrderParams.direction, 'long');
if (!swiftOrderParams.price) {
console.error(
Expand Down

0 comments on commit 0905835

Please sign in to comment.