"use strict";
/**
 * This code was AUTOGENERATED using the codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXECUTE_RELAYER_REFUND_LEAF_DISCRIMINATOR = void 0;
exports.getExecuteRelayerRefundLeafDiscriminatorBytes = getExecuteRelayerRefundLeafDiscriminatorBytes;
exports.getExecuteRelayerRefundLeafInstructionDataEncoder = getExecuteRelayerRefundLeafInstructionDataEncoder;
exports.getExecuteRelayerRefundLeafInstructionDataDecoder = getExecuteRelayerRefundLeafInstructionDataDecoder;
exports.getExecuteRelayerRefundLeafInstructionDataCodec = getExecuteRelayerRefundLeafInstructionDataCodec;
exports.getExecuteRelayerRefundLeafInstructionAsync = getExecuteRelayerRefundLeafInstructionAsync;
exports.getExecuteRelayerRefundLeafInstruction = getExecuteRelayerRefundLeafInstruction;
exports.parseExecuteRelayerRefundLeafInstruction = parseExecuteRelayerRefundLeafInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.EXECUTE_RELAYER_REFUND_LEAF_DISCRIMINATOR = new Uint8Array([
    27, 136, 159, 240, 127, 68, 123, 164,
]);
function getExecuteRelayerRefundLeafDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.EXECUTE_RELAYER_REFUND_LEAF_DISCRIMINATOR);
}
function getExecuteRelayerRefundLeafInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({
        ...value,
        discriminator: exports.EXECUTE_RELAYER_REFUND_LEAF_DISCRIMINATOR,
    }));
}
function getExecuteRelayerRefundLeafInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getExecuteRelayerRefundLeafInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getExecuteRelayerRefundLeafInstructionDataEncoder(), getExecuteRelayerRefundLeafInstructionDataDecoder());
}
async function getExecuteRelayerRefundLeafInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SVM_SPOKE_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        signer: { value: input.signer ?? null, isWritable: true },
        instructionParams: {
            value: input.instructionParams ?? null,
            isWritable: true,
        },
        state: { value: input.state ?? null, isWritable: false },
        rootBundle: { value: input.rootBundle ?? null, isWritable: true },
        vault: { value: input.vault ?? null, isWritable: true },
        mint: { value: input.mint ?? null, isWritable: false },
        transferLiability: {
            value: input.transferLiability ?? null,
            isWritable: true,
        },
        tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
        systemProgram: { value: input.systemProgram ?? null, isWritable: false },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Resolve default values.
    if (!accounts.instructionParams.value) {
        accounts.instructionParams.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    105, 110, 115, 116, 114, 117, 99, 116, 105, 111, 110, 95, 112, 97,
                    114, 97, 109, 115,
                ])),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.signer.value)),
            ],
        });
    }
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
    }
    if (!accounts.vault.value) {
        accounts.vault.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.state.value)),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.tokenProgram.value)),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)),
            ],
        });
    }
    if (!accounts.transferLiability.value) {
        accounts.transferLiability.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    116, 114, 97, 110, 115, 102, 101, 114, 95, 108, 105, 97, 98, 105,
                    108, 105, 116, 121,
                ])),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)),
            ],
        });
    }
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            '11111111111111111111111111111111';
    }
    if (!accounts.eventAuthority.value) {
        accounts.eventAuthority.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    95, 95, 101, 118, 101, 110, 116, 95, 97, 117, 116, 104, 111, 114,
                    105, 116, 121,
                ])),
            ],
        });
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.signer),
            getAccountMeta(accounts.instructionParams),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.rootBundle),
            getAccountMeta(accounts.vault),
            getAccountMeta(accounts.mint),
            getAccountMeta(accounts.transferLiability),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getExecuteRelayerRefundLeafInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function getExecuteRelayerRefundLeafInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SVM_SPOKE_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        signer: { value: input.signer ?? null, isWritable: true },
        instructionParams: {
            value: input.instructionParams ?? null,
            isWritable: true,
        },
        state: { value: input.state ?? null, isWritable: false },
        rootBundle: { value: input.rootBundle ?? null, isWritable: true },
        vault: { value: input.vault ?? null, isWritable: true },
        mint: { value: input.mint ?? null, isWritable: false },
        transferLiability: {
            value: input.transferLiability ?? null,
            isWritable: true,
        },
        tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
        systemProgram: { value: input.systemProgram ?? null, isWritable: false },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Resolve default values.
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
    }
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            '11111111111111111111111111111111';
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.signer),
            getAccountMeta(accounts.instructionParams),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.rootBundle),
            getAccountMeta(accounts.vault),
            getAccountMeta(accounts.mint),
            getAccountMeta(accounts.transferLiability),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getExecuteRelayerRefundLeafInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function parseExecuteRelayerRefundLeafInstruction(instruction) {
    if (instruction.accounts.length < 11) {
        // TODO: Coded error.
        throw new Error('Not enough accounts');
    }
    let accountIndex = 0;
    const getNextAccount = () => {
        const accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            signer: getNextAccount(),
            instructionParams: getNextAccount(),
            state: getNextAccount(),
            rootBundle: getNextAccount(),
            vault: getNextAccount(),
            mint: getNextAccount(),
            transferLiability: getNextAccount(),
            tokenProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getExecuteRelayerRefundLeafInstructionDataDecoder().decode(instruction.data),
    };
}
