Skip to content

Commit

Permalink
Replace names to addresses for eth contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
nebolax authored and LefterisJP committed Apr 18, 2023
1 parent 49935f2 commit e0b4cf5
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 138 deletions.
51 changes: 26 additions & 25 deletions rotkehlchen/chain/ethereum/defi/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from rotkehlchen.assets.asset import EvmToken
from rotkehlchen.chain.evm.contracts import EvmContract
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.constants.assets import (
A_CRV_3CRV,
A_CRV_3CRVSUSD,
Expand Down Expand Up @@ -150,128 +151,128 @@ def handle_defi_price_query(
if token == A_YV1_DAIUSDCTTUSD:
usd_value = _handle_yearn_curve_vault(
ethereum=ethereum,
curve_contract=ethereum.contracts.contract('CURVEFI_YSWAP'),
yearn_contract=ethereum.contracts.contract('YEARN_YCRV_VAULT'),
curve_contract=ethereum.contracts.contract(string_to_evm_address('0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51')), # noqa: E501
yearn_contract=ethereum.contracts.contract(string_to_evm_address('0x5dbcF33D8c2E976c6b560249878e6F1491Bca25c')), # noqa: E501
div_decimals=36,
asset_price=ONE, # assuming price of $1 for all stablecoins in pool
)
elif token == A_YV1_DAIUSDCTBUSD:
usd_value = _handle_yearn_curve_vault(
ethereum=ethereum,
curve_contract=ethereum.contracts.contract('CURVEFI_BUSDSWAP'),
yearn_contract=ethereum.contracts.contract('YEARN_BCURVE_VAULT'),
curve_contract=ethereum.contracts.contract(string_to_evm_address('0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27')), # noqa: E501
yearn_contract=ethereum.contracts.contract(string_to_evm_address('0x2994529C0652D127b7842094103715ec5299bBed')), # noqa: E501
div_decimals=36,
asset_price=ONE, # assuming price of $1 for all stablecoins in pool
)
elif token == A_YV1_RENWSBTC:
assert underlying_asset_price
usd_value = _handle_yearn_curve_vault(
ethereum=ethereum,
curve_contract=ethereum.contracts.contract('CURVEFI_SRENSWAP'),
yearn_contract=ethereum.contracts.contract('YEARN_SRENCURVE_VAULT'),
curve_contract=ethereum.contracts.contract(string_to_evm_address('0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714')), # noqa: E501
yearn_contract=ethereum.contracts.contract(string_to_evm_address('0x7Ff566E1d69DEfF32a7b244aE7276b9f90e9D0f6')), # noqa: E501
div_decimals=36,
asset_price=underlying_asset_price,
)
elif token == A_YV1_3CRV:
usd_value = _handle_yearn_curve_vault(
ethereum=ethereum,
curve_contract=ethereum.contracts.contract('CURVEFI_3POOLSWAP'),
yearn_contract=ethereum.contracts.contract('YEARN_3CRV_VAULT'),
curve_contract=ethereum.contracts.contract(string_to_evm_address('0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7')), # noqa: E501
yearn_contract=ethereum.contracts.contract(string_to_evm_address('0x9cA85572E6A3EbF24dEDd195623F188735A5179f')), # noqa: E501
div_decimals=36,
asset_price=ONE, # assuming price of $1 for all stablecoins in pool
)
elif token == A_CRVP_DAIUSDCTTUSD:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_YSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51')), token.decimals, ONE) # noqa: E501
elif token == A_CRV_YPAX:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_PAXSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0x06364f10B501e868329afBc005b3492902d6C763')), token.decimals, ONE) # noqa: E501
elif token == A_CRV_RENWBTC:
assert underlying_asset_price
usd_value = _handle_curvepool_price(
ethereum=ethereum,
contract=ethereum.contracts.contract('CURVEFI_RENSWAP'),
contract=ethereum.contracts.contract(string_to_evm_address('0x93054188d876f558f4a66B2EF1d97d16eDf0895B')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_CRVP_RENWSBTC:
assert underlying_asset_price
usd_value = _handle_curvepool_price(
ethereum=ethereum,
contract=ethereum.contracts.contract('CURVEFI_SRENSWAP'),
contract=ethereum.contracts.contract(string_to_evm_address('0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_CRV_3CRVSUSD:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_SUSDV2SWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0xA5407eAE9Ba41422680e2e00537571bcC53efBfD')), token.decimals, ONE) # noqa: E501
elif token == A_CRV_3CRV:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_3POOLSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7')), token.decimals, ONE) # noqa: E501
# a3CRV: Comparing address since constant won't be found if user has not updated their DB
elif token.evm_address == '0xFd2a8fA60Abd58Efe3EeE34dd494cD491dC14900':
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_A3CRVSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0xDeBF20617708857ebe4F679508E7b7863a8A8EeE')), token.decimals, ONE) # noqa: E501
elif token == A_CRV_GUSD:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_GUSDC3CRVSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0x4f062658EaAF2C1ccf8C8e36D6824CDf41167956')), token.decimals, ONE) # noqa: E501
elif token == A_CRVP_DAIUSDCTBUSD:
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract('CURVEFI_BUSDSWAP'), token.decimals, ONE) # noqa: E501
usd_value = _handle_curvepool_price(ethereum, ethereum.contracts.contract(string_to_evm_address('0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27')), token.decimals, ONE) # noqa: E501
elif token == A_YV1_ALINK:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_ALINK_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0x29E240CFD7946BA20895a7a02eDb25C210f9f324')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_DAI:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_DAI_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0xACd43E627e64355f1861cEC6d3a6688B31a6F952')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_WETH:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_WETH_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0xe1237aA7f535b0CC33Fd973D66cBf830354D16c7')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_YFI:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_YFI_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0xBA2E7Fed597fd0E3e70f5130BcDbbFE06bB94fe1')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_USDT:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_USDT_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0x2f08119C6f07c006695E079AAFc638b8789FAf18')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_USDC:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_USDC_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0x597aD1e0c13Bfe8025993D9e79C69E1c0233522e')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_TUSD:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_TUSD_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0x37d19d1c4E1fa9DC47bD1eA12f742a0887eDa74a')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
elif token == A_YV1_GUSD:
assert underlying_asset_price
usd_value = handle_underlying_price_yearn_vault(
ethereum=ethereum,
contract=ethereum.contracts.contract('YEARN_GUSD_VAULT'),
contract=ethereum.contracts.contract(string_to_evm_address('0xec0d8D3ED5477106c6D4ea27D90a60e594693C90')), # noqa: E501
div_decimals=token.decimals,
asset_price=underlying_asset_price,
)
Expand Down
5 changes: 3 additions & 2 deletions rotkehlchen/chain/ethereum/modules/aave/aave.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rotkehlchen.assets.asset import CryptoAsset, EvmToken
from rotkehlchen.chain.ethereum.constants import RAY
from rotkehlchen.chain.ethereum.defi.structures import GIVEN_DEFI_BALANCES
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.constants.misc import ZERO
from rotkehlchen.constants.resolver import ethaddress_to_identifier
from rotkehlchen.errors.asset import UnknownAsset, WrongAssetType
Expand Down Expand Up @@ -143,7 +144,7 @@ def _get_balances(
if reserve_data is None:

if balance_entry.protocol.name == 'Aave':
contract = self.ethereum.contracts.contract('AAVE_V1_LENDING_POOL')
contract = self.ethereum.contracts.contract(string_to_evm_address('0x398eC7346DcD622eDc5ae82352F02bE94C62d119')) # noqa: E501
reserve_result = contract.call(
node_inquirer=self.ethereum,
method_name='getReserveData',
Expand All @@ -155,7 +156,7 @@ def _get_balances(
stable_borrow_rate=FVal(reserve_result[6] / RAY),
)
else: # Aave V2
contract = self.ethereum.contracts.contract('AAVE_V2_LENDING_POOL')
contract = self.ethereum.contracts.contract(string_to_evm_address('0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9')) # noqa: E501
reserve_result = contract.call(
node_inquirer=self.ethereum,
method_name='getReserveData',
Expand Down
3 changes: 2 additions & 1 deletion rotkehlchen/chain/ethereum/modules/aave/v1/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from rotkehlchen.chain.evm.decoding.types import CounterpartyDetails, EventCategory
from rotkehlchen.chain.evm.decoding.utils import maybe_reshuffle_events
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.types import ChecksumEvmAddress, DecoderEventMappingType
from rotkehlchen.utils.misc import hex_or_bytes_to_address, hex_or_bytes_to_int

Expand Down Expand Up @@ -122,7 +123,7 @@ def possible_events(self) -> DecoderEventMappingType:

def addresses_to_decoders(self) -> dict[ChecksumEvmAddress, tuple[Any, ...]]:
return {
self.evm_inquirer.contracts.contract('AAVE_V1_LENDING_POOL').address: (self._decode_pool_event,), # noqa: E501
string_to_evm_address('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'): (self._decode_pool_event,), # AAVE_V1_LENDING_POOL # noqa: E501
}

def counterparties(self) -> list[CounterpartyDetails]:
Expand Down
3 changes: 2 additions & 1 deletion rotkehlchen/chain/ethereum/modules/aave/v2/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from rotkehlchen.chain.evm.decoding.types import CounterpartyDetails, EventCategory
from rotkehlchen.chain.evm.structures import EvmTxReceiptLog
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.constants.resolver import evm_address_to_identifier
from rotkehlchen.fval import FVal
from rotkehlchen.types import (
Expand Down Expand Up @@ -272,7 +273,7 @@ def possible_events(self) -> DecoderEventMappingType:

def addresses_to_decoders(self) -> dict[ChecksumEvmAddress, tuple[Any, ...]]:
return {
self.evm_inquirer.contracts.contract('AAVE_V2_LENDING_POOL').address: (self._decode_lending_pool_events,), # noqa: E501
string_to_evm_address('0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9'): (self._decode_lending_pool_events,), # AAVE_V2_LENDING_POOL # noqa: E501
}

def counterparties(self) -> list[CounterpartyDetails]:
Expand Down
5 changes: 3 additions & 2 deletions rotkehlchen/chain/ethereum/modules/convex/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rotkehlchen.chain.ethereum.utils import asset_normalized_value
from rotkehlchen.chain.evm.contracts import EvmContract
from rotkehlchen.chain.evm.tokens import get_chunk_size_call_order
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.constants.assets import A_CVX
from rotkehlchen.constants.misc import ZERO
from rotkehlchen.db.dbhandler import DBHandler
Expand Down Expand Up @@ -114,10 +115,10 @@ def query_balances(self) -> BalancesType:
)

# query CVX locked but not staked
cvx_lock_contract = self.evm_inquirer.contracts.contract('CVX_REWARD_POOL')
cvx_lock_contract = self.evm_inquirer.contracts.contract(string_to_evm_address('0xCF50b810E57Ac33B91dCF525C6ddd9881B139332')) # noqa: E501
self._query_staked_cvx(balances, cvx_lock_contract)
# query CVX staked
cvx_lock_contract = self.evm_inquirer.contracts.contract('CVX_LOCKER_V2')
cvx_lock_contract = self.evm_inquirer.contracts.contract(string_to_evm_address('0x72a19342e8F1838460eBFCCEf09F6585e32db86E')) # noqa: E501
self._query_staked_cvx(balances, cvx_lock_contract)

return balances
2 changes: 1 addition & 1 deletion rotkehlchen/chain/ethereum/modules/curve/curve_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def query_curve_data_from_chain(
May raise:
- RemoteError if failed to query chain
"""
address_provider = ethereum.contracts.contract('CURVE_ADDRESS_PROVIDER')
address_provider = ethereum.contracts.contract(string_to_evm_address('0x0000000022D53366457F9d5E68Ec105046FC4383')) # noqa: E501
try:
metaregistry_address = deserialize_evm_address(address_provider.call(
node_inquirer=ethereum,
Expand Down
4 changes: 2 additions & 2 deletions rotkehlchen/chain/ethereum/modules/ens/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _decode_ens_registry_with_fallback_event(self, context: DecoderContext) -> D
if context.tx_log.topics[0] == NEW_RESOLVER:
node = context.tx_log.topics[1]
try:
ens_name = self.ethereum.contracts.contract('ENS_REVERSE_RESOLVER').call(
ens_name = self.ethereum.contracts.contract(string_to_evm_address('0xA2C122BE93b0074270ebeE7f6b7292C7deB45047')).call( # noqa: E501
node_inquirer=self.ethereum,
method_name='name',
arguments=[node],
Expand Down Expand Up @@ -186,7 +186,7 @@ def _decode_ens_public_resolver_2_events(self, context: DecoderContext) -> Decod

node = context.tx_log.topics[1]
try:
address = self.ethereum.contracts.contract('ENS_PUBLIC_RESOLVER_2').call(
address = self.ethereum.contracts.contract(string_to_evm_address('0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41')).call( # noqa: E501
node_inquirer=self.ethereum,
method_name='addr',
arguments=[node],
Expand Down
7 changes: 4 additions & 3 deletions rotkehlchen/chain/ethereum/modules/liquity/trove.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rotkehlchen.accounting.structures.balance import AssetBalance, Balance
from rotkehlchen.chain.ethereum.defi.defisaver_proxy import HasDSProxy
from rotkehlchen.chain.ethereum.utils import token_normalized_value_decimals
from rotkehlchen.chain.evm.types import string_to_evm_address
from rotkehlchen.constants.assets import A_ETH, A_LQTY, A_LUSD
from rotkehlchen.errors.misc import BlockchainQueryError, RemoteError
from rotkehlchen.errors.serialization import DeserializationError
Expand Down Expand Up @@ -70,9 +71,9 @@ def __init__(
msg_aggregator=msg_aggregator,
)
self.history_lock = Semaphore()
self.trove_manager_contract = self.ethereum.contracts.contract('LIQUITY_TROVE_MANAGER')
self.stability_pool_contract = self.ethereum.contracts.contract('LIQUITY_STABILITY_POOL')
self.staking_contract = self.ethereum.contracts.contract('LIQUITY_STAKING')
self.trove_manager_contract = self.ethereum.contracts.contract(string_to_evm_address('0xA39739EF8b0231DbFA0DcdA07d7e29faAbCf4bb2')) # noqa: E501
self.stability_pool_contract = self.ethereum.contracts.contract(string_to_evm_address('0x66017D22b0f8556afDd19FC67041899Eb65a21bb')) # noqa: E501
self.staking_contract = self.ethereum.contracts.contract(string_to_evm_address('0x4f9Fbb3f1E99B56e0Fe2892e623Ed36A76Fc605d')) # noqa: E501

def get_positions(
self,
Expand Down
2 changes: 1 addition & 1 deletion rotkehlchen/chain/ethereum/modules/makerdao/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def query_ilk_registry(
- RemoteError if any of the remote queries fail
"""
ilks_mapping = {}
ilk_registry = ethereum.contracts.contract('ILK_REGISTRY')
ilk_registry = ethereum.contracts.contract(string_to_evm_address('0x5a464C28D19848f44199D003BeF5ecc87d090F87')) # noqa: E501
ilks_num = ilk_registry.call(ethereum, method_name='count')
step = 20 # split into multiple multi-calls to not hit etherscan or gas limits
for idx in range(0, ilks_num, step):
Expand Down
Loading

0 comments on commit e0b4cf5

Please sign in to comment.