dragonfly-xyz / useful-solidity-patterns

MIT License
1.48k stars 161 forks source link

Permit2: Example for PermitBatchTransferFrom #10

Closed clement-ux closed 1 year ago

clement-ux commented 1 year ago

Hello 👋

I've followed your patterns for PermitTransferFrom utilization and I've tried to apply it to the PermitBatchTransferFrom version. But because the signature for the user, for "batched version" is different from the "original" version, I've modified the helpers functions : _signPermitt() and especially _getEIP712Hash in order to fit to the new version. Attached the modification I've done. Capture d’écran 2023-01-03 à 17 08 35

But I receive this error with I'm testing it : "InvalidSigner()". So I assume that the hash that I'm generating is wrong. I've you can provide a quick example on how generate the hash for batched permit2 transfer, this could be really useful!

Thanks a lot in advance 😁

clement-ux commented 1 year ago

Update : I've solved the issue by doing something like this. Capture d’écran 2023-01-04 à 10 55 28

Note : I've merged the _getEIP712Hash and _signPermit function.

merklejerk commented 1 year ago

Nice, beat me to it! Yup, arrays of structs need to be hashed individually then their concatenation is hashed again. :dizzy: