-
Notifications
You must be signed in to change notification settings - Fork 817
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
base: master
Are you sure you want to change the base?
tx: 7702 examples #4039
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Co-authored-by: Avdhesh Charjan <[email protected]>
10ac6b5
to
723e789
Compare
There was a problem hiding this 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], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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}` |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', | ||
) |
There was a problem hiding this comment.
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)
No description provided.