"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transactionStrategy = exports.cosmosTransaction = exports.elrondTransaction = exports.solanaTransaction = exports.bitcoinTransaction = exports.withoutGasLimitTransaction = exports.rippleTransaction = exports.stellarTransaction = exports.modeSendTransaction = exports.defaultTransaction = void 0;
const bignumber_js_1 = require("bignumber.js");
function defaultTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        family,
        amount,
        recipient,
        ...customFeeConfig,
    };
}
exports.defaultTransaction = defaultTransaction;
function modeSendTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        mode: "send",
    };
}
exports.modeSendTransaction = modeSendTransaction;
function stellarTransaction({ family, amount, recipient, customFeeConfig, payinExtraId, customErrorType, }) {
    if (!payinExtraId)
        throw {
            error: new Error("Missing payinExtraId"),
            step: "PayinExtraIdStepError",
            customErrorType,
        };
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "stellar",
        memoValue: payinExtraId,
        memoType: "MEMO_TEXT",
    };
}
exports.stellarTransaction = stellarTransaction;
function rippleTransaction({ amount, recipient, customFeeConfig, payinExtraId, customErrorType, }) {
    if (!payinExtraId)
        throw {
            error: new Error("Missing payinExtraId"),
            step: "PayinExtraIdStepError",
            customErrorType,
        };
    const transaction = {
        family: "ripple",
        amount,
        recipient,
        ...customFeeConfig,
        tag: new bignumber_js_1.BigNumber(payinExtraId).toNumber(),
    };
    return transaction;
}
exports.rippleTransaction = rippleTransaction;
// Function to remove gasLimit from customFeeConfig for Ethereum or Bitcoin
function withoutGasLimitTransaction({ family, amount, recipient, customFeeConfig, extraTransactionParameters, }) {
    if (customFeeConfig?.gasLimit) {
        delete customFeeConfig.gasLimit;
    }
    if (extraTransactionParameters) {
        return {
            family,
            amount,
            recipient,
            ...customFeeConfig,
            data: Buffer.from(extraTransactionParameters, "hex"),
        };
    }
    return defaultTransaction({ family, amount, recipient, customFeeConfig });
}
exports.withoutGasLimitTransaction = withoutGasLimitTransaction;
function bitcoinTransaction({ amount, recipient, customFeeConfig, extraTransactionParameters, }) {
    if (extraTransactionParameters) {
        return {
            family: "bitcoin",
            amount,
            recipient,
            ...customFeeConfig,
            opReturnData: Buffer.from(extraTransactionParameters, "utf-8"),
        };
    }
    return {
        family: "bitcoin",
        amount,
        recipient,
        ...customFeeConfig,
    };
}
exports.bitcoinTransaction = bitcoinTransaction;
function solanaTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "solana",
        model: { kind: "transfer", uiState: {} },
    };
}
exports.solanaTransaction = solanaTransaction;
function elrondTransaction({ amount, recipient, customFeeConfig, }) {
    const transaction = {
        family: "elrond",
        amount,
        recipient,
        mode: "send",
        ...customFeeConfig,
        gasLimit: 0, // FIXME: Placeholder, adjust as needed
    };
    return transaction;
}
exports.elrondTransaction = elrondTransaction;
function tonTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "ton",
        comment: { isEncrypted: false, text: "" },
        fees: new bignumber_js_1.BigNumber(0), // Set default value as completeExchange call prepareTransaction, which set again fees.
    };
}
function cosmosTransaction({ family, amount, recipient, customFeeConfig, payinExtraId, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "cosmos",
        mode: "send",
        memo: payinExtraId ?? undefined,
    };
}
exports.cosmosTransaction = cosmosTransaction;
exports.transactionStrategy = {
    algorand: defaultTransaction,
    aptos: defaultTransaction,
    bitcoin: bitcoinTransaction,
    cardano: modeSendTransaction,
    celo: defaultTransaction,
    cosmos: cosmosTransaction,
    crypto_org: defaultTransaction,
    elrond: elrondTransaction,
    ethereum: withoutGasLimitTransaction,
    filecoin: defaultTransaction,
    hedera: defaultTransaction,
    near: modeSendTransaction,
    neo: defaultTransaction,
    polkadot: defaultTransaction,
    ripple: rippleTransaction,
    solana: solanaTransaction,
    stacks: defaultTransaction,
    stellar: stellarTransaction,
    tezos: modeSendTransaction,
    ton: tonTransaction,
    tron: modeSendTransaction,
    vechain: defaultTransaction,
    casper: defaultTransaction,
    sui: defaultTransaction,
    internet_computer: defaultTransaction,
};
//# sourceMappingURL=transactionStrategies.js.map