From cda2ed0c063e05cc69667885d0e52dd04cfb9fb2 Mon Sep 17 00:00:00 2001 From: MjCage Date: Fri, 22 Sep 2023 09:16:59 +0200 Subject: [PATCH] feat: decode memo v2 --- components/instructions/programs/memo.tsx | 26 ++++++++++++++++++++++ components/instructions/tools.tsx | 27 ++++++++++++++--------- 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 components/instructions/programs/memo.tsx diff --git a/components/instructions/programs/memo.tsx b/components/instructions/programs/memo.tsx new file mode 100644 index 0000000000..e8deafbc84 --- /dev/null +++ b/components/instructions/programs/memo.tsx @@ -0,0 +1,26 @@ +import { Connection, PublicKey } from '@solana/web3.js' +import { AccountMetaData } from '@solana/spl-governance' +import * as BufferLayout from '@solana/buffer-layout' + +export const MEMO_INSTRUCTIONS = { + MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr: { + 123: { + name: 'Memo Program v2', + accounts: [{ name: 'Stake Account' }], + getDataUI: async ( + _connection: Connection, + _data: Uint8Array, + _accounts: AccountMetaData[] + ) => { + const layout = BufferLayout.utf8(_data.length, 'memoData') + const decodedData = layout.decode(Buffer.from(_data)) + + return ( + <> +

Memo: {decodedData}

+ + ) + }, + }, + }, +} diff --git a/components/instructions/tools.tsx b/components/instructions/tools.tsx index de49a181c9..f23817e8c4 100644 --- a/components/instructions/tools.tsx +++ b/components/instructions/tools.tsx @@ -27,6 +27,7 @@ import { ConnectionContext } from '@utils/connection' import { NFT_VOTER_INSTRUCTIONS } from './programs/nftVotingClient' import { FORESIGHT_INSTRUCTIONS } from './programs/foresight' import { LIDO_INSTRUCTIONS } from './programs/lido' +import { MEMO_INSTRUCTIONS } from './programs/memo' import { NAME_SERVICE_INSTRUCTIONS } from './programs/nameService' import { TOKEN_AUCTION_INSTRUCTIONS } from './programs/tokenAuction' import { VALIDATORDAO_INSTRUCTIONS } from './programs/validatordao' @@ -304,11 +305,16 @@ export const ACCOUNT_NAMES = { '8XU6iRnVGp1DSWsbXWQVG3BofKncULJPEcU6YV6VRXDv': 'AllDomains Council Mint', Hq1ffpMA4368gerKRAdVy7KFrUUMo2NwGwVwcXoFy1Th: 'AllDomains Community Rewards', rP3eHs6uEDhQLqJHPLAwaNVENRezAgSnZK6opUtjhhT: 'AllDomains Grants', - '27Ma5zSVb8Sv9fuSZcXH2ZghTzdDXuWtzST4NJjXKKVo': 'AllDomains Rewards Governance', - '82s94bsTpcXfYbP7vTSwFfoi4cJEkoeQTfMif1h9s1AU': 'AllDomains Community Governance', - 'CnixsSAVZqvaJEdkFHXXRQmot7RCSJFRHYMJvupbPoiE': 'AllDomains Foundation Governance 1', - '95vv4h7GWeBG7DbnzMwB15ZinFKBUiPeg6ea7ZqdGjZx': 'AllDomains Foundation Governance 2', - '6gwjRFcW1Y9iuJwXPdz1zZUa3Hcu855dH6APA5LjD8qK': 'AllDomains Treasury Governance', + '27Ma5zSVb8Sv9fuSZcXH2ZghTzdDXuWtzST4NJjXKKVo': + 'AllDomains Rewards Governance', + '82s94bsTpcXfYbP7vTSwFfoi4cJEkoeQTfMif1h9s1AU': + 'AllDomains Community Governance', + CnixsSAVZqvaJEdkFHXXRQmot7RCSJFRHYMJvupbPoiE: + 'AllDomains Foundation Governance 1', + '95vv4h7GWeBG7DbnzMwB15ZinFKBUiPeg6ea7ZqdGjZx': + 'AllDomains Foundation Governance 2', + '6gwjRFcW1Y9iuJwXPdz1zZUa3Hcu855dH6APA5LjD8qK': + 'AllDomains Treasury Governance', AWVUWfRnHCTgo123mRXB9BRWaxt6JdZXXKhFMQ5mryKJ: 'AllDomains DAO Governance', } @@ -435,6 +441,7 @@ export const INSTRUCTION_DESCRIPTORS = { ...MANGO_V4_INSTRUCTIONS, ...DUAL_INSTRUCTIONS, ...STAKE_INSTRUCTIONS, + ...MEMO_INSTRUCTIONS, } export async function getInstructionDescriptor( @@ -458,11 +465,11 @@ export async function getInstructionDescriptor( const descriptor = !instruction.data.length ? descriptors : descriptors && descriptors[instruction.data[0]] - ? descriptors[instruction.data[0]] - : //backup if first number is same for couple of instructions inside same idl - descriptors && descriptors[`${instruction.data[0]}${instruction.data[1]}`] - ? descriptors[`${instruction.data[0]}${instruction.data[1]}`] - : descriptors + ? descriptors[instruction.data[0]] + : //backup if first number is same for couple of instructions inside same idl + descriptors && descriptors[`${instruction.data[0]}${instruction.data[1]}`] + ? descriptors[`${instruction.data[0]}${instruction.data[1]}`] + : descriptors const dataUI = (descriptor?.getDataUI && (await descriptor?.getDataUI(