Skip to content

Commit

Permalink
refactor(common): cleanup some inferred types, add TS benchmark (#2956)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
ssalbdivad and holic authored Jul 19, 2024
1 parent 69e23a3 commit 6189540
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ test-data/world-logs-bulk-*.json
test-data/world-logs-query.json

.attest
.tstrace
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"package.json": "pnpm sort-package-json"
},
"devDependencies": {
"@ark/attest": "0.9.2",
"@changesets/cli": "^2.26.1",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "7.1.1",
Expand All @@ -51,6 +52,7 @@
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1",
"rimraf": "^3.0.2",
"tsx": "4.16.2",
"turbo": "^1.9.3",
"typescript": "5.4.2"
},
Expand Down
28 changes: 14 additions & 14 deletions packages/common/src/getContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

if (contract.write) {
// Replace write calls with our own. Implemented ~the same as viem, but adds better handling of nonces (via queue + retries).
Expand All @@ -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?.({
Expand All @@ -134,5 +134,5 @@ export function getContract<
);
}

return contract as unknown as GetContractReturnType<TAbi, { public: TPublicClient; wallet: TWalletClient }, TAddress>;
return contract;
}
Loading

0 comments on commit 6189540

Please sign in to comment.