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

Simulated Token Balances for Verified Quotes #1

Open
wants to merge 1 commit into
base: feat/token-state-override
Choose a base branch
from

Commits on Nov 22, 2024

  1. Simulated Token Balances for Verified Quotes

    This PR is a follow up to cowprotocol#3125 and uses the component introduced in the
    aforementioned PR for setting up a simulated token balance using state
    overrides in order for quote verification to work even when the trader
    does not have sufficient balance.
    
    The way it works is by configuring known mapping slots for the
    `mapping(address => uint256) balances` in ERC20 token contract
    implementations and using this to compute the slot for overriding the
    **solver's** token balance for the simulation. The solver can then use
    this balance to top up the trader's account if needed (in the case were
    we allow mocking preconditions in the simulation - currently this is
    determined by whether or not the quote has hooks). We intentionally do
    not override the trader's balance in order to not interfere with hook
    execution in verified quotes.
    
    Note that the type of the state override changed slightly. This is
    because it was wrong to begin with. Node implementations I tested with
    (Geth and Anvil) expect both the slot and the value for state overrides
    to be exactly 32-bytes long (so `H256`). I guess this feature of the
    state override in the `ethrpc` crate was not used in the past and
    therefore no one noticed 🤷.
    
     ### Test Plan
    
    Added an E2E test that uses the new token balance override feature in
    order to produce a verified quote for a trader with no balances. Note
    that commenting out the API arguments causes the test to fail as
    expected.
    nlordell committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    529d019 View commit details
    Browse the repository at this point in the history