vacekj / wagmi-permit

All you need to sign ERC2612 and DAI permits with wagmi and viem
https://vacekj.github.io/wagmi-permit
GNU Affero General Public License v3.0
29 stars 1 forks source link

Permit fails when token contract returns unexpected "version" #5

Open dpekar opened 1 month ago

dpekar commented 1 month ago

When using wagmi-permit, I noticed my permits were failing when interacting with Balancer contracts.

When I looked in a bit closer, I realized that the version function on the balancer pool contracts return a json string, obviously used for some other reason: {"name":"WeightedPool","version":4,"deployment":"20230320-weighted-pool-v4"}

The balancer contracts do support permits, but since wagmi-permit uses the wrong version, the permits fails.

    const { data: versionFromContract } = useContractRead({
        chainId,
        address: contractAddress,
        abi: ERC20ABI,
        functionName: "version",
    });
    const version = permitVersion ?? versionFromContract ?? "1";

What about adding some simple validation to versionFromContract and using "1" unless versionFromContract is an integer?

vacekj commented 1 month ago

Hey, thanks for the bug report. I agree with your proposed solution - would you like to submit a PR? Cheers!

dpekar commented 1 month ago

Will do when I get a minute in the next week or so!

dpekar commented 3 weeks ago

@vacekj - I don't have write access to push up my branch and submit my PR, but I was just thinking something like:

const validatedVersionFromContract = [1, 2, '1', '2'].includes(versionFromContract)
    ? versionFromContract
    : null;

const version = permitVersion ?? validatedVersionFromContract ?? '1';

How does that look?

Do you wanna open up access or feel free to just use code above if it looks good to you.

vacekj commented 3 weeks ago

@dpekar thanks for the suggestion, that looks good to me. You can fork the repo and submit a PR from your fork

dpekar commented 1 day ago

hey @vacekj - do you mind to push an updated version up to npm?

thanks!