diff --git a/.changeset/witty-glasses-matter.md b/.changeset/witty-glasses-matter.md new file mode 100644 index 0000000..66767ec --- /dev/null +++ b/.changeset/witty-glasses-matter.md @@ -0,0 +1,5 @@ +--- +"@delvtech/drift-viem": minor +--- + +Remove forced `simulateContract` from viem adapter `write` diff --git a/packages/drift-viem/src/ViemReadWriteAdapter.ts b/packages/drift-viem/src/ViemReadWriteAdapter.ts index 7729269..1ac25fb 100644 --- a/packages/drift-viem/src/ViemReadWriteAdapter.ts +++ b/packages/drift-viem/src/ViemReadWriteAdapter.ts @@ -66,28 +66,22 @@ export class ViemReadWriteAdapter< }) as FunctionReturn; } - async write< - TAbi extends Abi, - TFunctionName extends FunctionName, - >(params: WriteParams) { - const viemParams = createSimulateContractParameters( - Object.assign({}, params, { - from: params.from || (await this.getSignerAddress()), - }), - ); - const writePromise = this.publicClient - .simulateContract(viemParams) - .then(({ request }) => - this.walletClient.writeContract(request as WriteContractParameters), - ); + async write>( + params: WriteParams + ) { + const writeParams = { + ...params, + functionName: params.fn, + chain: this.walletClient.chain, + account: await this.getSignerAddress(), + } as WriteContractParameters; + + const hash = await this.walletClient.writeContract(writeParams); if (params.onMined) { - writePromise.then((hash) => { - this.waitForTransaction({ hash }).then(params.onMined); - return hash; - }); + this.waitForTransaction({ hash }).then(params.onMined); } - return writePromise; + return hash; } }