Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Config Read #2138

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions beamer/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import structlog
from eth_typing import ChecksumAddress
from web3 import Web3
from web3.exceptions import ContractLogicError

import beamer.contracts
import beamer.util
Expand Down Expand Up @@ -50,16 +51,28 @@ def _replay_event(w3: Web3, deployment: Deployment, config: Configuration, event
config.request_manager.protocol_fee_ppm = event.protocol_fee_ppm

case TokenUpdated():
removal = event.transfer_limit == 0 and event.eth_in_token == 0

token = w3.eth.contract(address=event.token_address, abi=get_ERC20_abi())
symbol = token.functions.symbol().call()
config.request_manager.tokens[symbol] = TokenConfig(
transfer_limit=event.transfer_limit, eth_in_token=event.eth_in_token
)
address = config.token_addresses.get(symbol)
if address is None:
config.token_addresses[symbol] = event.token_address
try:
symbol = token.functions.symbol().call()
except ContractLogicError:
# If token symbol is not available, use address instead
symbol = event.token_address
fredo marked this conversation as resolved.
Show resolved Hide resolved

# If the symbol already exists for a different token address,
# default to use token address as a symbol
if config.token_addresses.get(symbol, event.token_address) != event.token_address:
symbol = event.token_address

if removal:
config.request_manager.tokens.pop(symbol, None)
config.token_addresses.pop(symbol, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the first call being

updateToken(address, 0, 0)

is there any other case where these entries may not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, since the above code piece is the production code, I could simply do this call on chain and the code would break.

else:
assert address == event.token_address
config.request_manager.tokens[symbol] = TokenConfig(
transfer_limit=event.transfer_limit, eth_in_token=event.eth_in_token
)
config.token_addresses[symbol] = event.token_address
istankovic marked this conversation as resolved.
Show resolved Hide resolved

case LpAdded():
if event.event_address == deployment.chain.contracts["RequestManager"].address:
Expand Down
2 changes: 1 addition & 1 deletion beamer/tests/config/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def deployment_objects(tmp_deployment_path, deployer, token):
# Call updateToken so that the eventual 'config read' command can pick up the token.
address = deployment.chain.contracts["RequestManager"].address
request_manager: Any = ape.project.RequestManager.at(address)
request_manager.updateToken(token.address, 0, 0)
request_manager.updateToken(token.address, 999, 1999)

return rpc_file, artifact, deployment

Expand Down