import { BigNumber } from "bignumber.js";
export function defaultTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        family,
        amount,
        recipient,
        ...customFeeConfig,
    };
}
export function modeSendTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        mode: "send",
    };
}
export 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",
    };
}
export 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(payinExtraId).toNumber(),
    };
    return transaction;
}
// Function to remove gasLimit from customFeeConfig for Ethereum or Bitcoin
export 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 });
}
export 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,
    };
}
export function solanaTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "solana",
        model: { kind: "transfer", uiState: {} },
    };
}
export function elrondTransaction({ amount, recipient, customFeeConfig, }) {
    const transaction = {
        family: "elrond",
        amount,
        recipient,
        mode: "send",
        ...customFeeConfig,
        gasLimit: 0, // FIXME: Placeholder, adjust as needed
    };
    return transaction;
}
function tonTransaction({ family, amount, recipient, customFeeConfig, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "ton",
        comment: { isEncrypted: false, text: "" },
        fees: new BigNumber(0), // Set default value as completeExchange call prepareTransaction, which set again fees.
    };
}
export function cosmosTransaction({ family, amount, recipient, customFeeConfig, payinExtraId, }) {
    return {
        ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
        family: "cosmos",
        mode: "send",
        memo: payinExtraId ?? undefined,
    };
}
export const 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