Skip to content

Commit

Permalink
feat: decode memo v2
Browse files Browse the repository at this point in the history
  • Loading branch information
MjCage committed Sep 25, 2023
1 parent 18458f9 commit cda2ed0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
26 changes: 26 additions & 0 deletions components/instructions/programs/memo.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<p>Memo: {decodedData}</p>
</>
)
},
},
},
}
27 changes: 17 additions & 10 deletions components/instructions/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
}

Expand Down Expand Up @@ -435,6 +441,7 @@ export const INSTRUCTION_DESCRIPTORS = {
...MANGO_V4_INSTRUCTIONS,
...DUAL_INSTRUCTIONS,
...STAKE_INSTRUCTIONS,
...MEMO_INSTRUCTIONS,
}

export async function getInstructionDescriptor(
Expand All @@ -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(
Expand Down

0 comments on commit cda2ed0

Please sign in to comment.