Skip to content

tx: 7702 examples #4039

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

tx: 7702 examples #4039

wants to merge 10 commits into from

Conversation

gabrocheleau
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 0% with 74 lines in your changes missing coverage. Please review.

Project coverage is 79.40%. Comparing base (060f690) to head (73f8ee4).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 84.33% <ø> (ø)
blockchain 89.32% <ø> (ø)
client 67.99% <ø> (?)
common 97.51% <ø> (ø)
devp2p 86.78% <ø> (ø)
evm 73.11% <ø> (ø)
mpt 89.74% <ø> (-0.31%) ⬇️
statemanager 69.06% <ø> (ø)
static 99.11% <ø> (ø)
tx 89.89% <ø> (ø)
util 89.19% <ø> (ø)
vm 54.07% <0.00%> (-1.43%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gabrocheleau gabrocheleau marked this pull request as ready for review April 27, 2025 16:37
Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Some comments regarding the example 😄 👍 Great start, but I think the example does not do what we want it to do.

const common = new Common({
chain: Mainnet,
hardfork: Hardfork.Cancun,
eips: [7702],
Copy link
Member

Choose a reason for hiding this comment

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

While this works, I think for the examples we should just run it on Prague and not on Cancun+7702.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, adjusted

// ─── sign authorization for each ──────
const targets: PrefixedHexString[] = [DAI, UNISWAP_V3_ROUTER, WETH]
const auths = targets.map((address, i) =>
eoaCode7702SignAuthorization({ chainId: '0x1', address, nonce: `0x${i}` }, privateKey),
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. This will delegate the user EOA first to DAI, then to UNISWAP_V3_ROUTER, and then to WETH (in the same transaction). The net result is that the EOA will point to WETH. We want to point it to the BATCH_CONTRACT, such that if we call into our EOA it will batch-call the targets (as implied by the encoding)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you are so right! That's an oversight on my part, adjusting.

const UNISWAP_V3_ROUTER = '0xE592427A0AEce92De3Edee1F18E0157C05861564'
const WETH = '0xC02aaa39b223FE8D0A0e5c4F27EaD9083C756Cc2'
const COLD_WALLET = `0x${'42'.repeat(20)}`
const BATCH_CONTRACT = '0xYourBatchContractAddressHere'
Copy link
Member

Choose a reason for hiding this comment

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

A note should be placed here what the BATCH_CONTRACT does and the interface. It seems that there is a method which seems to have this type signature: executeBatch([calldata,address][]) (I'm not sure if this is a valid ABI signature)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That signature does not seem to be valid. Will add a note.

Copy link
Member

Choose a reason for hiding this comment

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

I think a signature which works could be executeBatch(bytes[],address[]). If you use MulticallV3 then use aggregate(Call[]) (not sure how solidity constructs/decontstructs these structures): https://github.com/EthereumClassicDAO/multicall3/blob/743c0015fac7f9331c24ca8bd8075e49f19f2ddd/src/Multicall3.sol#L41

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just seeing this now, but yes I've adjusted to bytes[] address[], fixes the next steps too

'function transfer(address _to, uint256 _value) public returns (bool success)',
]
const routerAbi = ['function exactInput(bytes)']
const batchAbi = ['function executeBatch(bytes[] calldata) external']
Copy link
Member

Choose a reason for hiding this comment

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

Oh nvm this interface is here. But it seems that the encoding done in this example is done differently 🤔

)

// ─── build & send your single 7702 tx ───────────────────────────────
const batchData = batchContract.encodeFunctionData('executeBatch', [calls]) as `0x${string}`
Copy link
Member

Choose a reason for hiding this comment

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

The calldata is mapped to an array (which is fine). How does the executeBatch know which target it should call?

gasLimit: 1_000_000n,
maxFeePerGas: parseUnits('10', 9), // 10 gwei
maxPriorityFeePerGas: parseUnits('5', 9), // 5 gwei
to: BATCH_CONTRACT,
Copy link
Member

Choose a reason for hiding this comment

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

This will call the batch contract. It will therfore interact with WETH/DAI/Uniswap from the batch contract. We want to interact with it from our EOA (which is why EOA should be delegated to BATCH_CONTRACT)

nonce: '0x1',
yParity: '0x1',
r: ones32,
s: ones32,
Copy link
Member

Choose a reason for hiding this comment

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

This does not show how to sign the authorization list item, which is necessary, because the authorization signer does not necessarily have to be the tx signer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I just refactored this one initially (didn't actually work on it) so that it had at least correct types. We can certainly improve it.

console.log(
'🔀 Batch swap DAI→WETH → your wallet:',
execResult.exceptionError ? '❌ Failed' : '✅ Success',
)
Copy link
Member

Choose a reason for hiding this comment

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

We could also query the VM here to see the changes (deposit to wallet for instance)

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

Successfully merging this pull request may close these issues.

2 participants