-
Notifications
You must be signed in to change notification settings - Fork 8
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
Change viem usage for EAS to get typed data #131
Change viem usage for EAS to get typed data #131
Conversation
the input type cannot be 'narrowed' to just Abi if we want viem to infer types correctly
ty viem for finding this bug!
ty abitype for finding this bug!
let decoded: ReturnType<typeof decodeTransactionInputViem<typeof ABIs.EAS>>; | ||
try { | ||
decoded = decodeTransactionInputViem( | ||
transaction.input as Hex, | ||
ABIs.EAS as Abi, | ||
); | ||
decoded = decodeTransactionInputViem(transaction.input as Hex, ABIs.EAS); |
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 could be simplified so that someone that implements a detect function doesn't have to define the return type like this. A suggestion:
const decoded = tryDecodeTransactionInput(transaction.input, ABIs.EAS);
if (!decoded) return false;
} catch (err) { | ||
return false; | ||
} | ||
|
||
if (!decoded || !decoded.functionName) return false; | ||
return [ | ||
const handledFunctions: ExtractAbiFunctionNames<typeof ABIs.EAS>[] = [ |
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 should also be simplified into a helper function, maybe something like
return pickABIFunctionNames([
'attest',
'attestByDelegation',
'...',
], ABIs.EAS).includes(decoded.functionName);
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 awesome
@@ -1,4 +1,4 @@ | |||
[ | |||
const abi = [ |
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.
can we leave this abi file as json? and handle types in constants?
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.
Unfortunately not :( microsoft/TypeScript#32063
It needs to be a const type and typescript doesn't support that for json files
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.
yeah, maybe we can leave abis as json, and then import as const in constants.ts
?
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.
No that doesn't work unfortunately, typescript cannot infer a const type for a json file regardless of where/how it is imported
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.
okay,
8b9096c
into
benguyen0214/ou-1358-switch-from-ethers-to-viem-in-context-repo
Viem helped catch a bug here! I made a typo in one of the function names,
multiRevokeOffchain
. I had writtenmultiRevokeOffChain
with a capital C, and tsc knew thatswitch (decoded.functionName)
could never match on that name with a cpaital C because the data is typed :)