diff --git a/eth_defi/enzyme/vault.py b/eth_defi/enzyme/vault.py index 126a9fda..8077898f 100644 --- a/eth_defi/enzyme/vault.py +++ b/eth_defi/enzyme/vault.py @@ -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 @@ -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 @@ -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 diff --git a/tests/enzyme/test_guard_enzyme_uniswap_v2.py b/tests/enzyme/test_guard_enzyme_uniswap_v2.py index 5429fc73..b037441d 100644 --- a/tests/enzyme/test_guard_enzyme_uniswap_v2.py +++ b/tests/enzyme/test_guard_enzyme_uniswap_v2.py @@ -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,