-
Notifications
You must be signed in to change notification settings - Fork 196
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
refactor(common): cleanup some inferred types, add TS benchmark #2956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ test-data/world-logs-bulk-*.json | |
test-data/world-logs-query.json | ||
|
||
.attest | ||
.tstrace |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,16 +79,16 @@ export function getContract< | |
TPublicClient, | ||
TWalletClient | ||
>): GetContractReturnType<TAbi, { public: TPublicClient; wallet: TWalletClient }, TAddress> { | ||
const contract = viem_getContract({ | ||
const contract: GetContractReturnType<TAbi, { public: TPublicClient; wallet: TWalletClient }, TAddress> & { | ||
write: unknown; | ||
} = viem_getContract({ | ||
abi, | ||
address, | ||
client: { | ||
public: publicClient, | ||
wallet: walletClient, | ||
}, | ||
}) as unknown as GetContractReturnType<TAbi, { public: TPublicClient; wallet: TWalletClient }, TAddress> & { | ||
write: unknown; | ||
}; | ||
}) as never; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any practical benefit to this approach? iirc we copied the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, a few things:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. happy with this change, but just FYI, I reverted this back to what's in main and I see no change in instantiations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I should have been clearer, I made this change while optimizing perf based on the traces I saw but it just led me to the variance issue in viem. I know there is no perfect impact here, and specifically casting The problem is if |
||
|
||
if (contract.write) { | ||
// Replace write calls with our own. Implemented ~the same as viem, but adds better handling of nonces (via queue + retries). | ||
|
@@ -104,21 +104,21 @@ export function getContract< | |
] | ||
) => { | ||
const { args, options } = getFunctionParameters(parameters); | ||
const request = { | ||
const request: WriteContractParameters< | ||
TAbi, | ||
ContractFunctionName<TAbi, "nonpayable" | "payable">, | ||
ContractFunctionArgs<TAbi, "nonpayable" | "payable">, | ||
TChain, | ||
TAccount | ||
> = { | ||
abi, | ||
address, | ||
functionName, | ||
args, | ||
...options, | ||
onWrite, | ||
} as unknown as WriteContractParameters< | ||
TAbi, | ||
ContractFunctionName<TAbi, "nonpayable" | "payable">, | ||
ContractFunctionArgs<TAbi, "nonpayable" | "payable">, | ||
TChain, | ||
TAccount | ||
>; | ||
const result = writeContract(walletClient, request, { publicClient }); | ||
} as never; | ||
const result = writeContract(walletClient, request, { publicClient }) as never; | ||
|
||
const id = `${walletClient.chain.id}:${walletClient.account.address}:${nextWriteId++}`; | ||
onWrite?.({ | ||
|
@@ -134,5 +134,5 @@ export function getContract< | |
); | ||
} | ||
|
||
return contract as unknown as GetContractReturnType<TAbi, { public: TPublicClient; wallet: TWalletClient }, TAddress>; | ||
return 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.
I saw you did this in another PR and I had moved it out of the workspace root in a follow up PR to be consistent with how we've historically managed deps. Open to changing this approach though and curious to hear your thoughts - should common test deps be added to the workspace root instead of individual packages?
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.
Yes, devDependencies should generally be managed at the monorepo root in my opinion. It prevents having to manage multiple versions and continue to install them in new packages as needed, and there's really no downside as long as you're not importing them in source. I have an eslint rule that warns if I'm importing from a package not listed in dependencies.
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.
cool, added a follow up here: #2962