From 8a96ab4ee7765832f3e217f233f879d1840b95bb Mon Sep 17 00:00:00 2001 From: Sebastian Conybeare Date: Wed, 24 Feb 2021 22:14:20 +0800 Subject: [PATCH] Fix dex3 transaction parsing --- src/components/instructions/NewOrder.js | 6 +++--- src/pages/PopupPage.js | 5 +++++ src/utils/tokens/instructions.js | 20 +++++++++++++++++++- src/utils/transactions.js | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/components/instructions/NewOrder.js b/src/components/instructions/NewOrder.js index c570b54..052c6e8 100644 --- a/src/components/instructions/NewOrder.js +++ b/src/components/instructions/NewOrder.js @@ -3,11 +3,9 @@ import Typography from '@material-ui/core/Typography'; import LabelValue from './LabelValue'; import { useWallet } from '../../utils/wallet'; -export default function Neworder({ instruction, onOpenAddress }) { +export default function Neworder({ instruction, onOpenAddress, v3=false }) { const wallet = useWallet(); const { data, market, marketInfo } = instruction; - const { side, limitPrice, maxQuantity, orderType, ownerPubkey } = data; - const marketLabel = (marketInfo && marketInfo?.name + (marketInfo?.deprecated ? ' (deprecated)' : '')) || @@ -19,6 +17,8 @@ export default function Neworder({ instruction, onOpenAddress }) { return isOwner ? 'This wallet' : address?.toBase58() || 'Unknown'; }; + const { side, limitPrice, orderType, ownerPubkey } = data; + const maxQuantity = v3 ? data.maxBaseQuantity : data.maxQuantity; return ( <> { switch (instruction?.type) { case 'cancelOrder': + case 'cancelOrderV2': case 'matchOrders': case 'settleFunds': return ( @@ -496,6 +497,10 @@ function ApproveSignatureForm({ return ( ); + case 'newOrderV3': + return ( + + ); default: return ; } diff --git a/src/utils/tokens/instructions.js b/src/utils/tokens/instructions.js index 6bec93d..6a4dbac 100644 --- a/src/utils/tokens/instructions.js +++ b/src/utils/tokens/instructions.js @@ -4,7 +4,6 @@ import { SYSVAR_RENT_PUBKEY, TransactionInstruction, } from '@solana/web3.js'; -import { publicKeyLayout } from '@project-serum/serum/lib/layout'; export const TOKEN_PROGRAM_ID = new PublicKey( 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', @@ -152,6 +151,25 @@ export function memoInstruction(memo) { }); } +class PublicKeyLayout extends BufferLayout.Blob { + constructor(property) { + super(32, property); + } + + decode(b, offset) { + return new PublicKey(super.decode(b, offset)); + } + + encode(src, b, offset) { + return super.encode(src.toBuffer(), b, offset); + } +} + +function publicKeyLayout(property) { + return new PublicKeyLayout(property); +} + + export const OWNER_VALIDATION_PROGRAM_ID = new PublicKey( '4MNPdKu9wFMvEeZBMt3Eipfs5ovVWTJb31pEXDJAAxX5', ); diff --git a/src/utils/transactions.js b/src/utils/transactions.js index 7636a76..b4dd8fb 100644 --- a/src/utils/transactions.js +++ b/src/utils/transactions.js @@ -10,6 +10,8 @@ import { SETTLE_FUNDS_QUOTE_WALLET_INDEX, NEW_ORDER_OPEN_ORDERS_INDEX, NEW_ORDER_OWNER_INDEX, + NEW_ORDER_V3_OPEN_ORDERS_INDEX, + NEW_ORDER_V3_OWNER_INDEX, } from '@project-serum/serum'; import { PublicKey } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID } from './tokens/instructions'; @@ -233,6 +235,9 @@ const handleDexInstruction = async ( } else if (type === 'newOrder') { const newOrderData = getNewOrderData(accounts, accountKeys); data = { ...data, ...newOrderData }; + } else if (type === 'newOrderV3') { + const newOrderData = getNewOrderV3Data(accounts, accountKeys); + data = { ...data, ...newOrderData }; } return { type, @@ -379,6 +384,20 @@ const getNewOrderData = (accounts, accountKeys) => { return { openOrdersPubkey, ownerPubkey }; }; +const getNewOrderV3Data = (accounts, accountKeys) => { + const openOrdersPubkey = getAccountByIndex( + accounts, + accountKeys, + NEW_ORDER_V3_OPEN_ORDERS_INDEX, + ); + const ownerPubkey = getAccountByIndex( + accounts, + accountKeys, + NEW_ORDER_V3_OWNER_INDEX, + ); + return { openOrdersPubkey, ownerPubkey }; +} + const getSettleFundsData = (accounts, accountKeys) => { const basePubkey = getAccountByIndex( accounts,