Skip to content

feat: fermiswap integration#1034

Open
zach030 wants to merge 18 commits into
mainfrom
feat/fermiswap
Open

feat: fermiswap integration#1034
zach030 wants to merge 18 commits into
mainfrom
feat/fermiswap

Conversation

@zach030

@zach030 zach030 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds the FermiSwap integration based on the VM integration plan:

https://propeller-heads.atlassian.net/wiki/spaces/~71202094d3d73818b5447b85231f4bd027b78c/pages/3679518721/FermiSwap+Integration+Plan+VM

There is one extra part compared to the original plan: balance tracking for the trader_vault.

FermiSwap keeps all tokens in the trader_vault, but we still need balances on each component to calculate TVL. To handle that, I added two stores:

  • store_token_pairs: {key: token, value: list of pairs that use this token}
  • store_token_balances: {key: token, value: absolute token balance in the trader_vault}

With these two stores, when a token balance changes in the trader_vault, we can update all related components that depend on that token.

This PR also emits token balance updates for the trader_vault itself, since the VM integration needs to read the vault token balances during simulation.

@github-project-automation github-project-automation Bot moved this to Todo in Tycho May 21, 2026
@zach030 zach030 marked this pull request as ready for review May 26, 2026 08:46

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@gitguardian

gitguardian Bot commented May 29, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
33459105 Triggered Generic High Entropy Secret cfdef47 protocols/substreams/ethereum-fermiswap/substreams.yaml View secret
33671167 Triggered Generic High Entropy Secret ff14c49 protocols/substreams/ethereum-fermiswap/substreams.yaml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Comment thread crates/tycho-execution/contracts/src/executors/FermiSwapExecutor.sol Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/pb/.last_generated_hash Outdated
Comment thread protocols/substreams/ethereum-fermiswap/substreams.yaml Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/utils.rs
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread crates/tycho-simulation/src/evm/protocol/fermiswap/decoder.rs Outdated
Comment thread crates/tycho-simulation/src/evm/protocol/fermiswap/vm.rs Outdated
Comment thread crates/tycho-simulation/src/evm/protocol/fermiswap/state.rs Outdated
Comment thread crates/tycho-simulation/src/evm/protocol/fermiswap/state.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/abi/.gitkeep Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
Comment thread protocols/substreams/ethereum-fermiswap/src/modules.rs Outdated
format!("0x{}", hex::encode(out))
}

pub fn lane_index(base_asset: &[u8], quote_asset: &[u8]) -> String {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add docs that explains what this does with reference to the code please?

Comment on lines +509 to +514
if target != config.engine_address.as_slice() {
return None;
}
if update_timestamp.to_u64() != block_timestamp {
return None;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the logic behind these? Do we expect them or not and why is it safe to ignore them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I need to remove this check. In theory target should be engine_address and update_timestamp should match the current block, but the registry already allows some deviation here: (MAX_UPDATE_AGE and MAX_UPDATE_LEAD_TIME are both 0 now)

uint256 ts = updateTimestamp;
// Comparing a user-supplied timestamp against `block.timestamp` within a configurable
// window is the intended freshness check, not a vulnerability to miner manipulation.
// slither-disable-next-line timestamp
if (ts + MAX_UPDATE_AGE < block.timestamp) revert InvalidUpdateTimestamp();
// slither-disable-next-line timestamp
if (ts > block.timestamp + MAX_UPDATE_LEAD_TIME) revert InvalidUpdateTimestamp();

it’s better to stay consistent with the onchain state.

Comment on lines +115 to +116
store.set_if_not_exists(0, lane_index(base_asset, quote_asset), &component.id);
store.set_if_not_exists(0, lane_index(quote_asset, base_asset), &component.id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Safe because there can only be one component per token pairs, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the contract code, (token0, token1) and (token1, token0) are actually two different pairs, so they should be treated as different components. I already changed this and now only keep the lane_index(base_asset, quote_asset) key.

Comment on lines +530 to +534
// A batch can include repeated updates for the same component. The override value is
// block-wide, so emit it once per component per transaction.
if !block_overridden_components.insert(component_id.clone()) {
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to emit these whenever there is an update, even if it somehow happens twice in the same block

Comment on lines +516 to +518
// Registry calldata only contains `laneIndex`, not the token pair. `laneIndex` is
// keccak256(abi.encode(tokenA, tokenB)), so this is a one-way lookup through the lane store
// populated when the pair was created.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Interesting, so updates target specific pairs, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants