From b773aae3748ebd8e2d6bb04cae47e7bb67c5397b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezi=C5=84ski?= Date: Tue, 10 Dec 2024 12:06:22 +0400 Subject: [PATCH] add forwarder + fix (#54) * add forwarder + fix * remove comment --- .../ExecuteAllInstructionButton.tsx | 4 +++- .../proposal/[pk]/ProposalWarnings.tsx | 24 +++++++++++-------- .../instructions/Mango/MangoV4/IxGateSet.tsx | 15 ++++++++++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/components/instructions/ExecuteAllInstructionButton.tsx b/components/instructions/ExecuteAllInstructionButton.tsx index 6d00ebd19..5ce8c3a9d 100644 --- a/components/instructions/ExecuteAllInstructionButton.tsx +++ b/components/instructions/ExecuteAllInstructionButton.tsx @@ -49,7 +49,9 @@ const useSignersNeeded = ( //we need to remove the governance and its treasury from the signers const signers = propInstructions - .map((x) => x.account.instructions.flatMap((inst) => inst.accounts)) + .map( + (x) => x.account.instructions?.flatMap((inst) => inst.accounts) || [] + ) .filter((x) => x) .flatMap((x) => x) .filter((x) => x.isSigner) diff --git a/pages/dao/[symbol]/proposal/[pk]/ProposalWarnings.tsx b/pages/dao/[symbol]/proposal/[pk]/ProposalWarnings.tsx index 1957a813d..34458b876 100644 --- a/pages/dao/[symbol]/proposal/[pk]/ProposalWarnings.tsx +++ b/pages/dao/[symbol]/proposal/[pk]/ProposalWarnings.tsx @@ -28,10 +28,11 @@ const SetRealmConfigWarning = () => (

- This proposal writes to your realm configuration, which could affect how - votes are counted. Both the instruction data AND accounts list contain parameters. - Before you vote, make sure you review the proposal's instructions and the concerned - accounts, and understand the implications of passing this proposal. + This proposal writes to your realm configuration, which could affect + how votes are counted. Both the instruction data AND accounts list + contain parameters. Before you vote, make sure you review the + proposal's instructions and the concerned accounts, and + understand the implications of passing this proposal.

@@ -79,10 +80,11 @@ const SetGovernanceConfig = () => (

- This proposal writes to your governance configuration, which could affect how - votes are counted. Both the instruction data AND accounts list contain parameters. - Before you vote, make sure you review the proposal's instructions and the concerned - accounts, and understand the implications of passing this proposal. + This proposal writes to your governance configuration, which could + affect how votes are counted. Both the instruction data AND accounts + list contain parameters. Before you vote, make sure you review the + proposal's instructions and the concerned accounts, and + understand the implications of passing this proposal.

@@ -190,8 +192,10 @@ const useProposalSafetyCheck = (proposal: Proposal) => { ?.result const isUsingForwardProgram = transactions - ?.flatMap((tx) => - tx.account.instructions.flatMap((ins) => ins.programId.toBase58()) + ?.flatMap( + (tx) => + tx.account.instructions?.flatMap((ins) => ins.programId.toBase58()) || + [] ) .filter((x) => x === MANGO_INSTRUCTION_FORWARDER).length diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mango/MangoV4/IxGateSet.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mango/MangoV4/IxGateSet.tsx index 92ce41b6a..89d411316 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Mango/MangoV4/IxGateSet.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Mango/MangoV4/IxGateSet.tsx @@ -17,6 +17,9 @@ import { IxGateParams } from '@blockworks-foundation/mango-v4/dist/types/src/cli import useWalletOnePointOh from '@hooks/useWalletOnePointOh' import useProgramSelector from '@components/Mango/useProgramSelector' import ProgramSelector from '@components/Mango/ProgramSelector' +import ForwarderProgram, { + useForwarderProgramHelpers, +} from '@components/ForwarderProgram/ForwarderProgram' type IxGateSetForm = IxGateParams & { governedAccount: AssetAccount | null @@ -31,6 +34,7 @@ const IxGateSet = ({ governance: ProgramAccount | null }) => { const wallet = useWalletOnePointOh() + const forwarderProgramHelpers = useForwarderProgramHelpers() const programSelectorHook = useProgramSelector() const { mangoClient, mangoGroup } = UseMangoV4( programSelectorHook.program?.val, @@ -153,7 +157,9 @@ const IxGateSet = ({ }) .instruction() - serializedInstruction = serializeInstructionToBase64(ix) + serializedInstruction = serializeInstructionToBase64( + forwarderProgramHelpers.withForwarderWrapper(ix) + ) } const obj: UiInstruction = { serializedInstruction: serializedInstruction, @@ -170,7 +176,11 @@ const IxGateSet = ({ index ) // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO please fix, it can cause difficult bugs. You might wanna check out https://bobbyhadz.com/blog/react-hooks-exhaustive-deps for info. -@asktree - }, [form]) + }, [ + form, + forwarderProgramHelpers.form, + forwarderProgramHelpers.withForwarderWrapper, + ]) const schema = yup.object().shape({ governedAccount: yup .object() @@ -684,6 +694,7 @@ const IxGateSet = ({ formErrors={formErrors} > )} + ) }