Add configs for Uniswap v3 tx actions

pull/7312/head
POA 2 years ago
parent 19a4d71bde
commit 523351d2a6
  1. 30
      apps/indexer/lib/indexer/transform/transaction_actions.ex
  2. 2
      config/config_helper.exs
  3. 12
      config/runtime.exs

@ -18,11 +18,10 @@ defmodule Indexer.Transform.TransactionActions do
@goerli 5
@optimism 10
@polygon 137
@base_goerli 84531
# @gnosis 100
@burn_address "0x0000000000000000000000000000000000000000"
@uniswap_v3_positions_nft "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
@uniswap_v3_factory "0x1F98431c8aD98523631AE4a59f267346ea31F984"
@uniswap_v3_factory_abi [
%{
"inputs" => [
@ -162,13 +161,18 @@ defmodule Indexer.Transform.TransactionActions do
end
defp parse_uniswap_v3(logs, actions, protocols_to_rewrite, chain_id) do
if Enum.member?([@mainnet, @goerli, @optimism, @polygon], chain_id) and
if Enum.member?([@mainnet, @goerli, @optimism, @polygon, @base_goerli], chain_id) and
(is_nil(protocols_to_rewrite) or Enum.empty?(protocols_to_rewrite) or
Enum.member?(protocols_to_rewrite, "uniswap_v3")) do
uniswap_v3_positions_nft =
String.downcase(
Application.get_all_env(:indexer)[Indexer.Fetcher.TransactionAction][:uniswap_v3_nft_position_manager]
)
logs
|> uniswap_filter_logs()
|> uniswap_filter_logs(uniswap_v3_positions_nft)
|> logs_group_by_txs()
|> uniswap(actions, chain_id)
|> uniswap(actions, chain_id, uniswap_v3_positions_nft)
else
actions
end
@ -362,14 +366,14 @@ defmodule Indexer.Transform.TransactionActions do
end
end
defp uniswap(logs_grouped, actions, chain_id) do
defp uniswap(logs_grouped, actions, chain_id, uniswap_v3_positions_nft) do
# create a list of UniswapV3Pool legitimate contracts
legitimate = uniswap_legitimate_pools(logs_grouped)
# iterate for each transaction
Enum.reduce(logs_grouped, actions, fn {tx_hash, tx_logs}, actions_acc ->
# trying to find `mint_nft` actions
actions_acc = uniswap_handle_mint_nft_actions(tx_hash, tx_logs, actions_acc)
actions_acc = uniswap_handle_mint_nft_actions(tx_hash, tx_logs, actions_acc, uniswap_v3_positions_nft)
# go through other actions
Enum.reduce(tx_logs, actions_acc, fn log, acc ->
@ -378,7 +382,7 @@ defmodule Indexer.Transform.TransactionActions do
end)
end
defp uniswap_filter_logs(logs) do
defp uniswap_filter_logs(logs, uniswap_v3_positions_nft) do
logs
|> Enum.filter(fn log ->
first_topic = sanitize_first_topic(log.first_topic)
@ -393,7 +397,7 @@ defmodule Indexer.Transform.TransactionActions do
first_topic
) ||
(first_topic == @uniswap_v3_transfer_nft_event &&
address_hash_to_string(log.address_hash) == String.downcase(@uniswap_v3_positions_nft))
address_hash_to_string(log.address_hash) == uniswap_v3_positions_nft)
end)
end
@ -434,7 +438,7 @@ defmodule Indexer.Transform.TransactionActions do
end
end
defp uniswap_handle_mint_nft_actions(tx_hash, tx_logs, actions_acc) do
defp uniswap_handle_mint_nft_actions(tx_hash, tx_logs, actions_acc, uniswap_v3_positions_nft) do
first_log = Enum.at(tx_logs, 0)
local_acc =
@ -468,7 +472,7 @@ defmodule Indexer.Transform.TransactionActions do
data: %{
name: "Uniswap V3: Positions NFT",
symbol: "UNI-V3-POS",
address: @uniswap_v3_positions_nft,
address: uniswap_v3_positions_nft,
to: Address.checksum(to),
ids: ids,
block_number: first_log.block_number
@ -629,6 +633,8 @@ defmodule Indexer.Transform.TransactionActions do
end
defp uniswap_request_get_pools({requests_tokens_and_fees, responses_tokens_and_fees}) do
uniswap_v3_factory = Application.get_all_env(:indexer)[Indexer.Fetcher.TransactionAction][:uniswap_v3_factory]
requests_get_pool =
requests_tokens_and_fees
|> Enum.zip(responses_tokens_and_fees)
@ -651,7 +657,7 @@ defmodule Indexer.Transform.TransactionActions do
# we will call getPool(token0, token1, fee) public getter
%{
pool_address: pool_address,
contract_address: @uniswap_v3_factory,
contract_address: uniswap_v3_factory,
method_id: "1698ee82",
args: [token0, token1, fee]
}

@ -47,7 +47,7 @@ defmodule ConfigHelper do
end
end
defp safe_get_env(env_var, default_value) do
def safe_get_env(env_var, default_value) do
env_var
|> System.get_env(default_value)
|> case do

@ -402,7 +402,17 @@ config :indexer, Indexer.Fetcher.TransactionAction,
reindex_first_block: System.get_env("INDEXER_TX_ACTIONS_REINDEX_FIRST_BLOCK"),
reindex_last_block: System.get_env("INDEXER_TX_ACTIONS_REINDEX_LAST_BLOCK"),
reindex_protocols: System.get_env("INDEXER_TX_ACTIONS_REINDEX_PROTOCOLS", ""),
aave_v3_pool: System.get_env("INDEXER_TX_ACTIONS_AAVE_V3_POOL_CONTRACT")
aave_v3_pool: System.get_env("INDEXER_TX_ACTIONS_AAVE_V3_POOL_CONTRACT"),
uniswap_v3_factory:
ConfigHelper.safe_get_env(
"INDEXER_TX_ACTIONS_UNISWAP_V3_FACTORY_CONTRACT",
"0x1F98431c8aD98523631AE4a59f267346ea31F984"
),
uniswap_v3_nft_position_manager:
ConfigHelper.safe_get_env(
"INDEXER_TX_ACTIONS_UNISWAP_V3_NFT_POSITION_MANAGER_CONTRACT",
"0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
)
config :indexer, Indexer.Fetcher.PendingTransaction.Supervisor,
disabled?:

Loading…
Cancel
Save