"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCreateWrappedAccounts = exports.createCreateWrappedInstruction = void 0;
const spl_token_1 = require("@solana/spl-token");
const web3_js_1 = require("@solana/web3.js");
const connect_sdk_1 = require("@wormhole-foundation/connect-sdk");
const connect_sdk_solana_core_1 = require("@wormhole-foundation/connect-sdk-solana-core");
const splMetadata_1 = require("../../splMetadata");
const accounts_1 = require("../accounts");
const program_1 = require("../program");
function createCreateWrappedInstruction(connection, tokenBridgeProgramId, wormholeProgramId, payer, vaa) {
    const methods = (0, program_1.createReadOnlyTokenBridgeProgramInterface)(tokenBridgeProgramId, connection).methods.createWrapped();
    // @ts-ignore
    return methods._ixFn(...methods._args, {
        accounts: getCreateWrappedAccounts(tokenBridgeProgramId, wormholeProgramId, payer, vaa),
        signers: undefined,
        remainingAccounts: undefined,
        preInstructions: undefined,
        postInstructions: undefined,
    });
}
exports.createCreateWrappedInstruction = createCreateWrappedInstruction;
function getCreateWrappedAccounts(tokenBridgeProgramId, wormholeProgramId, payer, vaa) {
    const mint = (0, accounts_1.deriveWrappedMintKey)(tokenBridgeProgramId, (0, connect_sdk_1.toChainId)(vaa.payload.token.chain), vaa.payload.token.address.toUint8Array());
    return {
        payer: new web3_js_1.PublicKey(payer),
        config: (0, accounts_1.deriveTokenBridgeConfigKey)(tokenBridgeProgramId),
        endpoint: (0, accounts_1.deriveEndpointKey)(tokenBridgeProgramId, (0, connect_sdk_1.toChainId)(vaa.emitterChain), vaa.emitterAddress.toUint8Array()),
        vaa: connect_sdk_solana_core_1.utils.derivePostedVaaKey(wormholeProgramId, Buffer.from(vaa.hash)),
        claim: connect_sdk_solana_core_1.utils.deriveClaimKey(tokenBridgeProgramId, vaa.emitterAddress.toUint8Array(), (0, connect_sdk_1.toChainId)(vaa.emitterChain), vaa.sequence),
        mint,
        wrappedMeta: (0, accounts_1.deriveWrappedMetaKey)(tokenBridgeProgramId, mint),
        splMetadata: (0, splMetadata_1.deriveSplTokenMetadataKey)(mint),
        mintAuthority: (0, accounts_1.deriveMintAuthorityKey)(tokenBridgeProgramId),
        rent: web3_js_1.SYSVAR_RENT_PUBKEY,
        systemProgram: web3_js_1.SystemProgram.programId,
        tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
        splMetadataProgram: splMetadata_1.SplTokenMetadataProgram.programId,
        wormholeProgram: new web3_js_1.PublicKey(wormholeProgramId),
    };
}
exports.getCreateWrappedAccounts = getCreateWrappedAccounts;
//# sourceMappingURL=createWrapped.js.map