Skip to content

Commit

Permalink
WIP: tempest swell usde integration
Browse files Browse the repository at this point in the history
  • Loading branch information
anhvietnguyennva committed Dec 19, 2024
1 parent 24cd82b commit b34505d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=''
1 change: 1 addition & 0 deletions constants/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Chain(Enum):
MODE = "Mode"
OPTIMISM = "Optimism"
Lyra = "Lyra"
SWELL = "Scroll"
2 changes: 2 additions & 0 deletions constants/summary_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions integrations/integration_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions utils/web3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -55,6 +57,9 @@
Chain.Lyra: {
"w3": w3_lyra,
},
Chain.SWELL: {
"w3": w3_swell,
},
}


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit b34505d

Please sign in to comment.