# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# ---------------------------------------------------------------------------- #
#                                  Metamask                                    #
# ---------------------------------------------------------------------------- #

# Ethereum

# 0x881d40237659c251811cec9c364ef91dc08d300c - Metamask: Swap Router
# TODO: expand as needed

# BUY
if %from_address (^0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640$)
& %blockchain ^ethereum$
& %type (^erc-20$|^internal$)
& %amount_ [1-9]
  account2 equity:%account_name:%subaccount_name:conversion:%blockchain:%symbol
  comment blockchain:%blockchain, type:%type, block:%block_number, blockid:%block_hash, index:%tx_index, swapper:metamask, subaccount_address:%subaccount_address, contract_address:%contract_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH
  comment2 %tx_hash,%date +0000,BUY,%account_name:%subaccount_name:%blockchain,%symbol,%amount_

# BUY (remove unused tags)
if %from_address (^0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640$)
& %blockchain ^ethereum$
& %type ^internal$
& %amount_ [1-9]
  comment blockchain:%blockchain, type:%type, block:%block_number, swapper:metamask, subaccount_address:%subaccount_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH

# SELL/FEE
if %to_address (^0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640$)
& %blockchain ^ethereum$
& %type (^erc-20$|^internal$)
& %amount_ [1-9]
& %fees [1-9]
  account2 equity:%account_name:%subaccount_name:conversion:%blockchain:%symbol
  comment blockchain:%blockchain, type:%type, block:%block_number, blockid:%block_hash, index:%tx_index, swapper:metamask, subaccount_address:%subaccount_address, contract_address:%contract_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH
  comment2 %tx_hash,%date +0000,SELL,%account_name:%subaccount_name:%blockchain,%symbol,%amount_
  comment3 %tx_hash,%date +0000,FEE,%account_name:%subaccount_name:%blockchain,%symbol,%fees

# SELL/FEE (remove accounts with 0 amounts)
if %to_address (^0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640$)
& %blockchain ^ethereum$
& %type (^erc-20$|^internal$)
& %amount_ ^[^1-9]*$
& %fees [1-9]
  account1
  account2

# SELL/FEE (remove unused tags)
# NOTE: only needed for internal
if %to_address (^0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640$)
& %blockchain ^ethereum$
& %type ^internal$
& %amount_ [1-9]
& %fees [1-9]
  comment blockchain:%blockchain, type:%type, block:%block_number, swapper:metamask, subaccount_address:%subaccount_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH

# Polygon

# 0x1a1ec25DC08e98e5E93F1104B5e5cdD298707d31 - Metamask: Swap Router
# TODO: expand as needed

if %from_address ^0x1a1ec25DC08e98e5E93F1104B5e5cdD298707d31$
& %blockchain ^polygon$
& %amount_ [1-9]
  account2 equity:%account_name:%subaccount_name:conversion:%blockchain:%symbol
  comment blockchain:%blockchain, type:%type, block:%block_number, blockid:%block_hash, index:%tx_index, method:%method_id, swapper:metamask, subaccount_address:%subaccount_address, contract_address:%contract_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH
  comment2 %tx_hash,%date +0000,BUY,%account_name:%subaccount_name:%blockchain,%symbol,%amount_

if %to_address ^0x1a1ec25DC08e98e5E93F1104B5e5cdD298707d31$
& %blockchain ^polygon$
& %amount_ [1-9]
& %fees [1-9]
  account2 equity:%account_name:%subaccount_name:conversion:%blockchain:%symbol
  comment blockchain:%blockchain, type:%type, block:%block_number, blockid:%block_hash, index:%tx_index, method:%method_id, swapper:metamask, subaccount_address:%subaccount_address, contract_address:%contract_address, from_address:%from_address, to_address:%to_address, txid:%tx_hash, direction:%direction, taxed_as:MATCH
  comment2 %tx_hash,%date +0000,SELL,%account_name:%subaccount_name:%blockchain,%symbol,%amount_
  comment3 %tx_hash,%date +0000,FEE,%account_name:%subaccount_name:%blockchain,%symbol,%fees

# SELL/FEE (remove accounts with 0 amounts)
if %to_address ^0x1a1ec25DC08e98e5E93F1104B5e5cdD298707d31$
& %blockchain ^polygon$
& %amount_ ^[^1-9]*$
& %fees [1-9]
  account1
  account2

# vim: sw=2 sts=2 si ai et
