From b34505dbeb4fc821c1c20dbc446cc4ec4801c268 Mon Sep 17 00:00:00 2001 From: anhnv Date: Thu, 19 Dec 2024 13:11:02 +0700 Subject: [PATCH] WIP: tempest swell usde integration --- .env.example | 1 + constants/chains.py | 1 + constants/summary_columns.py | 2 ++ integrations/integration_ids.py | 8 ++++++++ utils/web3_utils.py | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+) diff --git a/.env.example b/.env.example index 67d6f77..cde6c7d 100644 --- a/.env.example +++ b/.env.example @@ -5,5 +5,6 @@ SCROLL_NODE_URL='https://rpc.scroll.io' MODE_NODE_URL='https://mainnet.mode.network' FRAXTAL_NODE_URL='https://rpc.frax.com' LYRA_NODE_URL='https://rpc.derive.xyz' +SWELL_NODE_URL='https://rpc.scroll.io' DERIVE_SUBGRAPH_API_KEY='' \ No newline at end of file diff --git a/constants/chains.py b/constants/chains.py index 7b0c8d3..5ec0ac3 100644 --- a/constants/chains.py +++ b/constants/chains.py @@ -11,3 +11,4 @@ class Chain(Enum): MODE = "Mode" OPTIMISM = "Optimism" Lyra = "Lyra" + SWELL = "Scroll" diff --git a/constants/summary_columns.py b/constants/summary_columns.py index e0c35b4..0273744 100644 --- a/constants/summary_columns.py +++ b/constants/summary_columns.py @@ -38,6 +38,8 @@ class SummaryColumn(Enum): "beefy_cached_balance_example", SummaryColumnType.ETHENA_PTS, ) + + TEMPEST_SWELL_SHARDS = ("tempest_swell_shards", SummaryColumnType.ETHENA_PTS) def __init__(self, column_name: str, col_type: SummaryColumnType): self.column_name = column_name diff --git a/integrations/integration_ids.py b/integrations/integration_ids.py index 86e9618..71d26a5 100644 --- a/integrations/integration_ids.py +++ b/integrations/integration_ids.py @@ -396,6 +396,14 @@ class IntegrationID(Enum): # Upshift sUSDe UPSHIFT_UPSUSDE = ("upshift_upsusde", "Upshift upsUSDe", Token.SUSDE) + + # Tempest Finance + TEMPEST_SWELL_USDE = ( + "tempest_swell_usde_held", + "Tempest Swell USDe", + Token.USDE, + ) + def __init__(self, column_name: str, description: str, token: Token = Token.USDE): self.column_name = column_name self.description = description diff --git a/utils/web3_utils.py b/utils/web3_utils.py index c8150ef..6c2366c 100644 --- a/utils/web3_utils.py +++ b/utils/web3_utils.py @@ -29,6 +29,8 @@ w3_fraxtal = Web3(Web3.HTTPProvider(FRAXTAL_NODE_URL)) LYRA_NODE_URL = os.getenv("LYRA_NODE_URL") w3_lyra = Web3(Web3.HTTPProvider(LYRA_NODE_URL)) +SWELL_NODE_URL = os.getenv("SWELL_NODE_URL") +w3_swell = Web3(Web3.HTTPProvider(SWELL_NODE_URL)) W3_BY_CHAIN = { Chain.ETHEREUM: { @@ -55,6 +57,9 @@ Chain.Lyra: { "w3": w3_lyra, }, + Chain.SWELL: { + "w3": w3_swell, + }, } @@ -84,6 +89,10 @@ MULTICALL_ADDRESS = ( "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696" # Ethereum mainnet address ) +MULTICALL_ADDRESS_BY_CHAIN = { + Chain.SWELL: "0xcA11bde05977b3631167028862bE2a173976CA11", + Chain.SCROLL: "0xcA11bde05977b3631167028862bE2a173976CA11" +} def fetch_events_logs_with_retry( @@ -151,3 +160,27 @@ def multicall(w3: Web3, calls: list, block_identifier: BlockIdentifier = "latest decoded_results.append(decode(output_types, result[1][i])) return decoded_results + +def multicall_by_address(w3: Web3, multical_address: str, calls: list, block_identifier: BlockIdentifier = "latest"): + multicall_contract = w3.eth.contract( + address=Web3.to_checksum_address(multical_address), abi=MULTICALL_ABI + ) + + aggregate_calls = [] + for call in calls: + contract, fn_name, args = call + call_data = contract.encodeABI(fn_name=fn_name, args=args) + aggregate_calls.append((contract.address, call_data)) + + result = multicall_contract.functions.aggregate(aggregate_calls).call( + block_identifier=block_identifier + ) + + decoded_results = [] + for i, call in enumerate(calls): + contract, fn_name, _ = call + function = contract.get_function_by_name(fn_name) + output_types = [output["type"] for output in function.abi["outputs"]] + decoded_results.append(decode(output_types, result[1][i])) + + return decoded_results