From eb02fc3130f14cfc39573592d5d2aca051a3a3db Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Wed, 17 Mar 2021 03:18:54 +0100 Subject: [PATCH] Add mango auto approve support (#148) --- src/pages/PopupPage.js | 2 ++ src/utils/transactions.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/pages/PopupPage.js b/src/pages/PopupPage.js index 931bb1b..d18dbb7 100644 --- a/src/pages/PopupPage.js +++ b/src/pages/PopupPage.js @@ -430,6 +430,8 @@ function isSafeInstruction(publicKeys, owner, txInstructions) { } else { if (instruction.type === 'raydium') { // Whitelist raydium for now. + } else if (instruction.type === 'mango') { + // Whitelist mango for now. } else if ( ['cancelOrder', 'matchOrders', 'cancelOrderV3'].includes( instruction.type, diff --git a/src/utils/transactions.js b/src/utils/transactions.js index 4a10dc4..b666106 100644 --- a/src/utils/transactions.js +++ b/src/utils/transactions.js @@ -23,6 +23,10 @@ const RAYDIUM_LP_PROGRAM_ID = new PublicKey( 'RVKd61ztZW9GUwhRbbLoYVRE5Xf1B2tVscKqwZqXgEr', ); +const MANGO_PROGRAM_ID = new PublicKey( + 'JD3bq9hGdy38PuWQ4h2YJpELmHVGPPfFSuFkpzAd9zfu', +); + const marketCache = {}; let marketCacheConnection = null; const cacheDuration = 15 * 1000; @@ -129,6 +133,15 @@ const toInstruction = async ( accountKeys, decodedInstruction, ); + } else if (programId.equals(MANGO_PROGRAM_ID)) { + console.log('[' + index + '] Handled as mango markets instruction'); + let decodedInstruction = decodeMangoInstruction(decoded); + return await handleMangoInstruction( + connection, + instruction, + accountKeys, + decodedInstruction, + ); } else { return { type: 'Unknown', @@ -147,6 +160,18 @@ const toInstruction = async ( return; }; +const handleMangoInstruction = async ( + connection, + instruction, + accountKeys, + decodedInstruction, +) => { + // TODO + return { + type: 'mango', + }; +}; + const handleRayStakeInstruction = async ( connection, instruction, @@ -171,6 +196,11 @@ const handleRayLpInstruction = async ( }; }; +const decodeMangoInstruction = () => { + // TODO + return undefined; +}; + const decodeStakeInstruction = () => { // TODO return undefined;