Skip to content

Commit

Permalink
Export TermsOfService contract in Vault data structure (#199)
Browse files Browse the repository at this point in the history
- Export `termsOfService` contract as the part of Vault data structure
  • Loading branch information
miohtama authored Jan 30, 2024
1 parent 6f48751 commit 009b375
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions eth_defi/enzyme/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class Vault:
#:
guard_contract: Optional[Contract] = None

#: Terms of service contract.
#:
#: - We must have a TermedVaultUSDCPaymentForwarder
#: - Resolved from TermedVaultUSDCPaymentForwarder.termsOfService() accessor
#:
terms_of_service_contract: Optional[Contract] = None

#: What was the block number when this vault was deployed
#:
deployed_at_block: int | None = None
Expand Down Expand Up @@ -381,10 +388,14 @@ def fetch(
else:
generic_adapter_contract = None

terms_of_service_contract = None
if payment_forwarder is not None:
try:
payment_forwarder_contract = get_deployed_contract(web3, f"TermedVaultUSDCPaymentForwarder.json", payment_forwarder)
payment_forwarder_contract.functions.isTermsOfServiceEnabled().call()
terms_of_service_address = payment_forwarder_contract.functions.termsOfService().call()
terms_of_service_contract = get_deployed_contract(web3, "terms-of-service/TermsOfService.json", terms_of_service_address)

except (ValueError, ContractLogicError):
# EVMTester will give ValueError if the function does not exist
# Legacy
Expand All @@ -411,6 +422,7 @@ def fetch(
generic_adapter_contract,
payment_forwarder_contract,
guard_contract,
terms_of_service_contract,
deployed_at_block=deployed_at_block,
nominated_owner=nominated_owner,
asset_manager=asset_manager, # We cannot read asset manager back from the vault because it's just EVM hash map
Expand Down
6 changes: 6 additions & 0 deletions tests/enzyme/test_guard_enzyme_uniswap_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ def test_enzyme_usdc_payment_forwarder_transfer_with_authorization_and_terms(
assert terms_of_service.functions.canAddressProceed(vault_investor.address).call()


def test_fetch_terms_of_service(web3: Web3, vault: Vault):
"""Resolve terms of service based on the vault."""
vault2 = Vault.fetch(web3, vault.address, payment_forwarder=vault.payment_forwarder.address)
assert vault2.terms_of_service_contract is not None


def test_enzyme_guarded_trade_singlehop_uniswap_v2(
web3: Web3,
deployer: HexAddress,
Expand Down

0 comments on commit 009b375

Please sign in to comment.