Skip to content

Commit

Permalink
fix: configure UiInstruction correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
MjCage committed Sep 25, 2023
1 parent 8379b59 commit 18458f9
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,14 @@ const DeactivateValidatorStake = ({
return true
}

async function getInstruction(): Promise<UiInstruction[]> {
async function getInstruction(): Promise<UiInstruction> {
const isValid = await validateInstruction()
const returnInvalid = (): UiInstruction[] => {
return [
{
serializedInstruction: '',
isValid: false,
governance: undefined,
},
]
}
const returnInvalid = (): UiInstruction => ({
serializedInstruction: '',
isValid: false,
governance: undefined,
})

if (
!connection ||
!isValid ||
Expand All @@ -176,31 +173,39 @@ const DeactivateValidatorStake = ({
return returnInvalid()
}

const instructions: web3.TransactionInstruction[] = []
const instruction: UiInstruction = {
serializedInstruction: '',
isValid: true,
governance: form.governedTokenAccount!.governance,
}

if (
form.stakingAccount.stakingAuthority.toString() !==
MARINADE_NATIVE_STAKING_AUTHORITY.toString()
) {
instructions.push(
...web3.StakeProgram.deactivate({
stakePubkey: form.stakingAccount.stakeAccount,
authorizedPubkey: form.governedTokenAccount.pubkey,
}).instructions
const instructions = web3.StakeProgram.deactivate({
stakePubkey: form.stakingAccount.stakeAccount,
authorizedPubkey: form.governedTokenAccount.pubkey,
}).instructions

instruction.serializedInstruction = serializeInstructionToBase64(
instructions[0]
)
} else {
const mNativeSdk = new NativeStakingSDK()
const { payFees } = await mNativeSdk.initPrepareForRevoke(
const { payFees, onPaid } = await mNativeSdk.initPrepareForRevoke(
form.governedTokenAccount.pubkey
)
instructions.push(...payFees)

instruction.serializedInstruction = serializeInstructionToBase64(
payFees[0]
)
instruction.additionalSerializedInstructions = [
serializeInstructionToBase64(payFees[1]),
]
}

return instructions.map((ix) => ({
serializedInstruction: serializeInstructionToBase64(ix),
isValid: true,
governance: form.governedTokenAccount!.governance,
}))
return instruction
}

useEffect(() => {
Expand Down

0 comments on commit 18458f9

Please sign in to comment.