diff --git a/package.json b/package.json index e14f5c2..8666c3a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@ledgerhq/hw-transport-webusb": "^5.34.0", "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", - "@project-serum/serum": "^0.13.23", + "@project-serum/serum": "^0.13.24", "@solana/web3.js": "^0.87.2", "@testing-library/jest-dom": "^5.11.6", "@testing-library/react": "^11.2.2", 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 bb5374c..7ca0081 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'; @@ -237,6 +239,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, @@ -383,6 +388,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, diff --git a/yarn.lock b/yarn.lock index ac70dfc..c1bfe4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1861,12 +1861,12 @@ schema-utils "^2.6.5" source-map "^0.7.3" -"@project-serum/serum@^0.13.23": - version "0.13.23" - resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.13.23.tgz#70a4206e3fe926ef2f6e41da1b562399a20b3c9d" - integrity sha512-Atg2sSdQLEp4JIg4jp3vy1T9u9O5wObVTcGe0hX7e7zDmDc4zxBbTJXxdvMRxaz4pfrETyithX//zIMyIHMA8Q== +"@project-serum/serum@^0.13.24": + version "0.13.24" + resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.13.24.tgz#42ab28052924c4b754ed078790a192ae23fffab9" + integrity sha512-ux2MuO2kGGUV/QYBVx+e3roM/zATI6Fi2ThVaEo4aBdQKosbuNA60uAfSnYK9Du0kz7UjGoZHv2FnkCq8web3A== dependencies: - "@solana/web3.js" "0.86.1" + "@solana/web3.js" "^0.90.0" bn.js "^5.1.2" buffer-layout "^1.2.0" @@ -1917,15 +1917,15 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@solana/web3.js@0.86.1": - version "0.86.1" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-0.86.1.tgz#034a2cef742569f74dfc9960dfbcabc92e674b08" - integrity sha512-9mjWs17ym7PIm7bHA37wnnYyD7rIVHwkx1RI6BzGhMO5h8E+HlZM8ISLgOx+NItg8XRCfFhlrVgJTzK4om1s0g== +"@solana/web3.js@^0.87.2": + version "0.87.2" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-0.87.2.tgz#92c8d344695c6113d4e0eb3339117fbc6b22d0d2" + integrity sha512-BtrOGfg7zUud/zLL/BxXV3E84qpXK1HknqncNQDNr8JlJ4tGc+Xsip5DzSMP/fNUJgbAWblHqWWJxFdN2mtO6A== dependencies: "@babel/runtime" "^7.3.1" bn.js "^5.0.0" bs58 "^4.0.1" - buffer "^5.4.3" + buffer "^6.0.1" buffer-layout "^1.2.0" crypto-hash "^1.2.2" esdoc-inject-style-plugin "^1.0.0" @@ -1940,10 +1940,10 @@ tweetnacl "^1.0.0" ws "^7.0.0" -"@solana/web3.js@^0.87.2": - version "0.87.2" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-0.87.2.tgz#92c8d344695c6113d4e0eb3339117fbc6b22d0d2" - integrity sha512-BtrOGfg7zUud/zLL/BxXV3E84qpXK1HknqncNQDNr8JlJ4tGc+Xsip5DzSMP/fNUJgbAWblHqWWJxFdN2mtO6A== +"@solana/web3.js@^0.90.0": + version "0.90.5" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-0.90.5.tgz#5be7d78a19f0b5e01bf82c52e3cbf0bb72a38cfd" + integrity sha512-2elnwfIkdtrUjLdTBKu7Rc3mTv95k2cn+JtNtmO2fY/PFRZm7mnGS/gk/wWzGCpBVLiqz2o6o21oONqyDtLG/w== dependencies: "@babel/runtime" "^7.3.1" bn.js "^5.0.0" @@ -3692,7 +3692,7 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" -buffer@^5.0.5, buffer@^5.4.3, buffer@^5.5.0, buffer@^5.6.0: +buffer@^5.0.5, buffer@^5.5.0, buffer@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786" integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==