Skip to content
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

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

Open
dpekar opened this issue Aug 8, 2024 · 5 comments
Open

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

dpekar opened this issue Aug 8, 2024 · 5 comments

Comments

@dpekar
Copy link
Contributor

dpekar commented Aug 8, 2024

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
Copy link
Owner

vacekj commented Aug 12, 2024

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

@dpekar
Copy link
Contributor Author

dpekar commented Aug 14, 2024

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

@dpekar
Copy link
Contributor Author

dpekar commented Aug 21, 2024

@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
Copy link
Owner

vacekj commented Aug 21, 2024

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

@dpekar
Copy link
Contributor Author

dpekar commented Sep 12, 2024

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

thanks!

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

No branches or pull requests

2 participants