mango-token-sale/models/withFlagInstructionError.ts

57 lines
1.2 KiB
TypeScript

import {
PublicKey,
SYSVAR_CLOCK_PUBKEY,
TransactionInstruction,
} from '@solana/web3.js'
import { GOVERNANCE_SCHEMA } from './serialisation'
import { serialize } from 'borsh'
import { FlagInstructionErrorArgs } from './instructions'
export const withFlagInstructionError = (
instructions: TransactionInstruction[],
programId: PublicKey,
proposal: PublicKey,
tokenOwnerRecord: PublicKey,
governanceAuthority: PublicKey,
proposalInstruction: PublicKey
) => {
const args = new FlagInstructionErrorArgs()
const data = Buffer.from(serialize(GOVERNANCE_SCHEMA, args))
const keys = [
{
pubkey: proposal,
isWritable: true,
isSigner: false,
},
{
pubkey: tokenOwnerRecord,
isWritable: false,
isSigner: false,
},
{
pubkey: governanceAuthority,
isWritable: false,
isSigner: true,
},
{
pubkey: proposalInstruction,
isWritable: true,
isSigner: false,
},
{
pubkey: SYSVAR_CLOCK_PUBKEY,
isSigner: false,
isWritable: false,
},
]
instructions.push(
new TransactionInstruction({
keys,
programId,
data,
})
)
}