Tracking Contract Balances
Sometimes the balances a component uses is stored on a contract that is not a dedicated single pool contract. During Tycho VM simulations, token contracts are mocked and any balances checked or used during a swap need to be overwritten for a simulation to succeed. Default behavior is for the component balances reported to be used to overwrite the pool contract balances. This assumes 2 things: there is a one-to-one relationship between contracts and components, and the hex-encoded contract address serves as the component ID.
If a protocol deviates from this assumption, the balances for each appropriate contract needs to be tracked for that contract. All contracts that have their balances checked/accessed during a simulation need to be tracked in this way.
Implementation Steps:
Implement logic/a helper function to extract the absolute balances of the contract. This is protocol specific and might be obtained from an event, or extracted from a storage slot if an appropriate one is identified.
Create an
InterimContractChange
for the contract and add the contract balances usingupsert_token_balance
.Add these contract changes to the appropriate
TransactionChangesBuilder
usingadd_contract_changes
.
An example for a protocol that uses a single vault contract is as follows:
Last updated