Skip to content

Conversation

@miguelmota
Copy link
Contributor

@miguelmota miguelmota commented Oct 1, 2025

Previously TrailsBalanceInjector was called as separate contract call and while it worked for ERC20 sweep and call, it did not work for native sweep and call because there's no such thing as transferFrom with native token. The changes in PR are to make it work with DelegateCall: true from meta tx so it's called in context of intent wallet so it can properly call with value for native token destination call, and properly inject (replace placeholder) and call if it's ERC20 token destination call.

Dependents

https://github.com/0xsequence/trails-api/pull/6


There's a lot of overlap with TrailsTokenSweeper, maybe it makes sense to combine these two contracts at some point or move the shared functionality out to a shared contract to dry things up

…l patterns

Add injectSweepAndCall (regular calls with transferFrom) and injectAndCall
(delegatecalls reading address(this) balance) while keeping shared logic
DRY in _executeCall.

This enables both backward-compatible external calls and native Sequence
wallet delegatecall integration.
@miguelmota miguelmota changed the title [DO NOT MERGE] refactor: separate TrailsBalanceInjector into regular and delegatecall refactor: separate TrailsBalanceInjector into regular and delegatecall Oct 1, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the TrailsBalanceInjector contract to support both regular calls and delegatecalls from Sequence wallets. The refactoring separates the injection logic into two distinct functions with different behavior patterns.

Key changes:

  • Adds delegatecall support for Sequence wallets through new injectAndCall and handleSequenceDelegateCall functions
  • Renames sweepAndCall to injectSweepAndCall for clarity and consistency
  • Implements conditional placeholder replacement logic to handle cases where replacement should be skipped

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/TrailsBalanceInjector.sol Adds IDelegatedExtension interface, new delegatecall functions, refactors existing logic into internal helpers, and implements conditional placeholder replacement
test/TrailsBalanceInjector.t.sol Updates test function names, adds MockWallet for delegatecall testing, and adds comprehensive test coverage for new delegatecall functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@miguelmota miguelmota changed the title refactor: separate TrailsBalanceInjector into regular and delegatecall refactor: add TrailsBalanceInjector delegatecall support for injectAndCall (previously sweepAndCall) Oct 1, 2025
Updated the ETH balance retrieval logic to always use address(this).balance, ensuring the contract has ETH available before execution. Removed unnecessary checks for msg.value and clarified the require statement for better error handling.
@miguelmota miguelmota requested a review from Copilot October 1, 2025 06:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// Always use address(this).balance, regardless of call type.
// The contract must have ETH available before calling this function.
callerBalance = address(this).balance;
require(callerBalance > 0, "No ETH available in contract");
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The error message 'No ETH available in contract' is inconsistent with other ETH-related error messages in the codebase. Consider using 'No ETH sent' to maintain consistency with the existing error message pattern.

Suggested change
require(callerBalance > 0, "No ETH available in contract");
require(callerBalance > 0, "No ETH sent");

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@shunkakinoki shunkakinoki left a comment

Choose a reason for hiding this comment

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

LGTM

@shunkakinoki
Copy link
Collaborator

Thank you for this! Makes a lot of sense especially the native transfer on the destination intent call w/ the EXACT_INPUT is probably a very frequent usecase - and thank you again for the super fast implementation along w/ the trails-api PR update

@shunkakinoki
Copy link
Collaborator

shunkakinoki commented Oct 1, 2025

There's a lot of overlap with TrailsTokenSweeper, maybe it makes sense to combine these two contracts at some point or move the shared functionality out to a shared contract to dry things up

Agreed with this; let's ship the existing contracts w/ the current intentmachine optimizations pushed to production and take it from there 🙌

@shunkakinoki shunkakinoki merged commit c3c3690 into master Oct 1, 2025
2 checks passed
@miguelmota
Copy link
Contributor Author

miguelmota commented Oct 1, 2025

Thank you @shunkakinoki! Will contracts be redeployed once this is merged?

@pkieltyka pkieltyka deleted the feat/balance-injector-delegatecall-refactor branch October 23, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants