/**
 * 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
 */
import { __assign, __awaiter, __generator } from "tslib";
import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from "@solana/kit";
import { findEventAuthorityPda, findTransferLiabilityPda } from "../pdas";
import { SVM_SPOKE_PROGRAM_ADDRESS } from "../programs";
import { expectAddress, getAccountMetaFactory, } from "../shared";
export var BRIDGE_TOKENS_TO_HUB_POOL_DISCRIMINATOR = new Uint8Array([
    1, 83, 255, 59, 232, 55, 64, 216,
]);
export function getBridgeTokensToHubPoolDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(BRIDGE_TOKENS_TO_HUB_POOL_DISCRIMINATOR);
}
export function getBridgeTokensToHubPoolInstructionDataEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["amount", getU64Encoder()],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: BRIDGE_TOKENS_TO_HUB_POOL_DISCRIMINATOR })); });
}
export function getBridgeTokensToHubPoolInstructionDataDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["amount", getU64Decoder()],
    ]);
}
export function getBridgeTokensToHubPoolInstructionDataCodec() {
    return combineCodec(getBridgeTokensToHubPoolInstructionDataEncoder(), getBridgeTokensToHubPoolInstructionDataDecoder());
}
export function getBridgeTokensToHubPoolInstructionAsync(input, config) {
    return __awaiter(this, void 0, void 0, function () {
        var programAddress, originalAccounts, accounts, args, _a, _b, _c, getAccountMeta;
        var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
        return __generator(this, function (_0) {
            switch (_0.label) {
                case 0:
                    programAddress = (_d = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _d !== void 0 ? _d : SVM_SPOKE_PROGRAM_ADDRESS;
                    originalAccounts = {
                        signer: { value: (_e = input.signer) !== null && _e !== void 0 ? _e : null, isWritable: false },
                        payer: { value: (_f = input.payer) !== null && _f !== void 0 ? _f : null, isWritable: true },
                        mint: { value: (_g = input.mint) !== null && _g !== void 0 ? _g : null, isWritable: true },
                        state: { value: (_h = input.state) !== null && _h !== void 0 ? _h : null, isWritable: false },
                        transferLiability: {
                            value: (_j = input.transferLiability) !== null && _j !== void 0 ? _j : null,
                            isWritable: true,
                        },
                        vault: { value: (_k = input.vault) !== null && _k !== void 0 ? _k : null, isWritable: true },
                        tokenMessengerMinterSenderAuthority: {
                            value: (_l = input.tokenMessengerMinterSenderAuthority) !== null && _l !== void 0 ? _l : null,
                            isWritable: false,
                        },
                        messageTransmitter: {
                            value: (_m = input.messageTransmitter) !== null && _m !== void 0 ? _m : null,
                            isWritable: true,
                        },
                        tokenMessenger: { value: (_o = input.tokenMessenger) !== null && _o !== void 0 ? _o : null, isWritable: false },
                        remoteTokenMessenger: {
                            value: (_p = input.remoteTokenMessenger) !== null && _p !== void 0 ? _p : null,
                            isWritable: false,
                        },
                        tokenMinter: { value: (_q = input.tokenMinter) !== null && _q !== void 0 ? _q : null, isWritable: false },
                        localToken: { value: (_r = input.localToken) !== null && _r !== void 0 ? _r : null, isWritable: true },
                        cctpEventAuthority: {
                            value: (_s = input.cctpEventAuthority) !== null && _s !== void 0 ? _s : null,
                            isWritable: false,
                        },
                        messageSentEventData: {
                            value: (_t = input.messageSentEventData) !== null && _t !== void 0 ? _t : null,
                            isWritable: true,
                        },
                        messageTransmitterProgram: {
                            value: (_u = input.messageTransmitterProgram) !== null && _u !== void 0 ? _u : null,
                            isWritable: false,
                        },
                        tokenMessengerMinterProgram: {
                            value: (_v = input.tokenMessengerMinterProgram) !== null && _v !== void 0 ? _v : null,
                            isWritable: false,
                        },
                        tokenProgram: { value: (_w = input.tokenProgram) !== null && _w !== void 0 ? _w : null, isWritable: false },
                        systemProgram: { value: (_x = input.systemProgram) !== null && _x !== void 0 ? _x : null, isWritable: false },
                        eventAuthority: { value: (_y = input.eventAuthority) !== null && _y !== void 0 ? _y : null, isWritable: false },
                        program: { value: (_z = input.program) !== null && _z !== void 0 ? _z : null, isWritable: false },
                    };
                    accounts = originalAccounts;
                    args = __assign({}, input);
                    if (!!accounts.transferLiability.value) return [3 /*break*/, 2];
                    _a = accounts.transferLiability;
                    return [4 /*yield*/, findTransferLiabilityPda({
                            mint: expectAddress(accounts.mint.value),
                        })];
                case 1:
                    _a.value = _0.sent();
                    _0.label = 2;
                case 2:
                    if (!accounts.tokenProgram.value) {
                        accounts.tokenProgram.value =
                            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
                    }
                    if (!!accounts.vault.value) return [3 /*break*/, 4];
                    _b = accounts.vault;
                    return [4 /*yield*/, getProgramDerivedAddress({
                            programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
                            seeds: [
                                getAddressEncoder().encode(expectAddress(accounts.state.value)),
                                getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
                                getAddressEncoder().encode(expectAddress(accounts.mint.value)),
                            ],
                        })];
                case 3:
                    _b.value = _0.sent();
                    _0.label = 4;
                case 4:
                    if (!accounts.messageTransmitterProgram.value) {
                        accounts.messageTransmitterProgram.value =
                            "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
                    }
                    if (!accounts.tokenMessengerMinterProgram.value) {
                        accounts.tokenMessengerMinterProgram.value =
                            "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3";
                    }
                    if (!accounts.systemProgram.value) {
                        accounts.systemProgram.value =
                            "11111111111111111111111111111111";
                    }
                    if (!!accounts.eventAuthority.value) return [3 /*break*/, 6];
                    _c = accounts.eventAuthority;
                    return [4 /*yield*/, findEventAuthorityPda()];
                case 5:
                    _c.value = _0.sent();
                    _0.label = 6;
                case 6:
                    getAccountMeta = getAccountMetaFactory(programAddress, "programId");
                    return [2 /*return*/, Object.freeze({
                            accounts: [
                                getAccountMeta(accounts.signer),
                                getAccountMeta(accounts.payer),
                                getAccountMeta(accounts.mint),
                                getAccountMeta(accounts.state),
                                getAccountMeta(accounts.transferLiability),
                                getAccountMeta(accounts.vault),
                                getAccountMeta(accounts.tokenMessengerMinterSenderAuthority),
                                getAccountMeta(accounts.messageTransmitter),
                                getAccountMeta(accounts.tokenMessenger),
                                getAccountMeta(accounts.remoteTokenMessenger),
                                getAccountMeta(accounts.tokenMinter),
                                getAccountMeta(accounts.localToken),
                                getAccountMeta(accounts.cctpEventAuthority),
                                getAccountMeta(accounts.messageSentEventData),
                                getAccountMeta(accounts.messageTransmitterProgram),
                                getAccountMeta(accounts.tokenMessengerMinterProgram),
                                getAccountMeta(accounts.tokenProgram),
                                getAccountMeta(accounts.systemProgram),
                                getAccountMeta(accounts.eventAuthority),
                                getAccountMeta(accounts.program),
                            ],
                            data: getBridgeTokensToHubPoolInstructionDataEncoder().encode(args),
                            programAddress: programAddress,
                        })];
            }
        });
    });
}
export function getBridgeTokensToHubPoolInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
    // Program address.
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : SVM_SPOKE_PROGRAM_ADDRESS;
    // Original accounts.
    var originalAccounts = {
        signer: { value: (_b = input.signer) !== null && _b !== void 0 ? _b : null, isWritable: false },
        payer: { value: (_c = input.payer) !== null && _c !== void 0 ? _c : null, isWritable: true },
        mint: { value: (_d = input.mint) !== null && _d !== void 0 ? _d : null, isWritable: true },
        state: { value: (_e = input.state) !== null && _e !== void 0 ? _e : null, isWritable: false },
        transferLiability: {
            value: (_f = input.transferLiability) !== null && _f !== void 0 ? _f : null,
            isWritable: true,
        },
        vault: { value: (_g = input.vault) !== null && _g !== void 0 ? _g : null, isWritable: true },
        tokenMessengerMinterSenderAuthority: {
            value: (_h = input.tokenMessengerMinterSenderAuthority) !== null && _h !== void 0 ? _h : null,
            isWritable: false,
        },
        messageTransmitter: {
            value: (_j = input.messageTransmitter) !== null && _j !== void 0 ? _j : null,
            isWritable: true,
        },
        tokenMessenger: { value: (_k = input.tokenMessenger) !== null && _k !== void 0 ? _k : null, isWritable: false },
        remoteTokenMessenger: {
            value: (_l = input.remoteTokenMessenger) !== null && _l !== void 0 ? _l : null,
            isWritable: false,
        },
        tokenMinter: { value: (_m = input.tokenMinter) !== null && _m !== void 0 ? _m : null, isWritable: false },
        localToken: { value: (_o = input.localToken) !== null && _o !== void 0 ? _o : null, isWritable: true },
        cctpEventAuthority: {
            value: (_p = input.cctpEventAuthority) !== null && _p !== void 0 ? _p : null,
            isWritable: false,
        },
        messageSentEventData: {
            value: (_q = input.messageSentEventData) !== null && _q !== void 0 ? _q : null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: (_r = input.messageTransmitterProgram) !== null && _r !== void 0 ? _r : null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: (_s = input.tokenMessengerMinterProgram) !== null && _s !== void 0 ? _s : null,
            isWritable: false,
        },
        tokenProgram: { value: (_t = input.tokenProgram) !== null && _t !== void 0 ? _t : null, isWritable: false },
        systemProgram: { value: (_u = input.systemProgram) !== null && _u !== void 0 ? _u : null, isWritable: false },
        eventAuthority: { value: (_v = input.eventAuthority) !== null && _v !== void 0 ? _v : null, isWritable: false },
        program: { value: (_w = input.program) !== null && _w !== void 0 ? _w : null, isWritable: false },
    };
    var accounts = originalAccounts;
    // Original args.
    var args = __assign({}, input);
    // Resolve default values.
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    }
    if (!accounts.messageTransmitterProgram.value) {
        accounts.messageTransmitterProgram.value =
            "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
    }
    if (!accounts.tokenMessengerMinterProgram.value) {
        accounts.tokenMessengerMinterProgram.value =
            "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3";
    }
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            "11111111111111111111111111111111";
    }
    var getAccountMeta = getAccountMetaFactory(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.signer),
            getAccountMeta(accounts.payer),
            getAccountMeta(accounts.mint),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.transferLiability),
            getAccountMeta(accounts.vault),
            getAccountMeta(accounts.tokenMessengerMinterSenderAuthority),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.cctpEventAuthority),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.messageTransmitterProgram),
            getAccountMeta(accounts.tokenMessengerMinterProgram),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getBridgeTokensToHubPoolInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
export function parseBridgeTokensToHubPoolInstruction(instruction) {
    if (instruction.accounts.length < 20) {
        // TODO: Coded error.
        throw new Error("Not enough accounts");
    }
    var accountIndex = 0;
    var getNextAccount = function () {
        var accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            signer: getNextAccount(),
            payer: getNextAccount(),
            mint: getNextAccount(),
            state: getNextAccount(),
            transferLiability: getNextAccount(),
            vault: getNextAccount(),
            tokenMessengerMinterSenderAuthority: getNextAccount(),
            messageTransmitter: getNextAccount(),
            tokenMessenger: getNextAccount(),
            remoteTokenMessenger: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            cctpEventAuthority: getNextAccount(),
            messageSentEventData: getNextAccount(),
            messageTransmitterProgram: getNextAccount(),
            tokenMessengerMinterProgram: getNextAccount(),
            tokenProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getBridgeTokensToHubPoolInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=bridgeTokensToHubPool.js.map