<reponame>fentas/staketaxcsv<gh_stars>0
import logging
from terra import util_terra
from terra.execute_type import (
    _execute_type,
    EXECUTE_TYPE_UNKNOWN,
    EXECUTE_TYPE_SWAP,
    EXECUTE_TYPE_ASSERT_LIMIT_ORDER,
    EXECUTE_TYPE_WITHDRAW_LIQUIDITY,
)

# known contracts from protocol
"""
# Terraswap bLUNA-LUNA LP
"<KEY>",
# Terraswap ANC-UST LP
"<KEY>",
# Terraswap ANC-UST Pair
"<KEY>",
# Nexus Psi-UST Terraswap LP
"<KEY>",
# terraswap liquidity token (uLP) / VKR-UST Pair
"<KEY>",
# TerraWorld TWD-UST LP Token
"<KEY>",
# Nexus nETH-Psi Terraswap LP
"<KEY>",
# terraswap liquidity token
"<KEY>",
"terra14ffp0waxcck733a9jfd58d86h9rac2chf5xhev",
# MINE-UST Pair
"<KEY>",
# bLUNA-LUNA Pair
"terra1jxazgm67et0ce260kvrpfv50acuushpjsz2y0p",
# bETH-UST Pair
"terra1c0afrdc5253tkp5wt7rxhuj42xwyf2lcre0s7c",
"""


def handle(exporter, elem, txinfo, index):
    execute_msg = util_terra._execute_msg(elem, index)
    
    if "swap" in execute_msg:
        return EXECUTE_TYPE_SWAP
    
    if "assert_limit_order" in execute_msg:
        return EXECUTE_TYPE_ASSERT_LIMIT_ORDER

    if "send" in execute_msg:
        msg = execute_msg["send"]["msg"]

        if "swap" in msg:
            return EXECUTE_TYPE_SWAP

        if "withdraw_liquidity" in msg:
            return EXECUTE_TYPE_WITHDRAW_LIQUIDITY

    execute_type = _execute_type(elem, txinfo, index)
    logging.debug("[terraswap] General transaction type=%s txid=%s", execute_type, elem["txhash"])
    return execute_type