Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export const testDepositContract = async ({

const validatorData = generateValidatorData()

const initialAccountBalance = await publicClient.getBalance({
address: account.address,
})

const depositTx = await walletClient.deposit({
address: deployedContractAddress,
nodePubkey: validatorData.nodePubkey,
Expand All @@ -206,6 +210,21 @@ export const testDepositContract = async ({

expect(depositReceipt.logs.length).toBeGreaterThan(0)

const finalAccountBalance = await publicClient.getBalance({
address: account.address,
})

const contractBalance = await publicClient.getBalance({
address: deployedContractAddress,
})

const balanceDifference = initialAccountBalance - finalAccountBalance
const expectedDeposit = parseEther(VALIDATOR_MINIMUM_STAKE.toString())

expect(contractBalance).toBe(expectedDeposit)

expect(balanceDifference).toBeGreaterThanOrEqual(expectedDeposit)

const newDepositCount = await publicClient.getDepositCount({
address: deployedContractAddress,
})
Expand All @@ -226,5 +245,8 @@ export const testDepositContract = async ({
newDepositCount,
newDepositRoot,
validatorData,
initialAccountBalance,
finalAccountBalance,
contractBalance,
}
}
4 changes: 2 additions & 2 deletions packages/seismic-viem/src/actions/depositContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
WalletClient,
} from 'viem'
import type { WriteContractReturnType } from 'viem'
import { readContract, writeContract } from 'viem/actions'
import { readContract } from 'viem/actions'

import { depositContractAbi } from '@sviem/abis/depositContract.ts'

Expand Down Expand Up @@ -90,7 +90,7 @@ export const depositContractWalletActions = <
client: WalletClient<TTransport, TChain, TAccount>
): DepositContractWalletActions => ({
deposit: async (args) =>
writeContract(client, {
client.writeContract({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Deposit now uses shielded instead of transparent transactions

The change from writeContract(client, {...}) to client.writeContract({...}) alters transaction behavior. The standalone writeContract from viem/actions sends standard (unencrypted) transactions. However, due to the client extension order in client.ts, client.writeContract is the shielded version (from shieldedWalletActions) that encrypts calldata. This means deposits now use encrypted transactions instead of transparent ones, which may not be intended for this deposit contract functionality. The transparent version is available as twriteContract.

Fix in Cursor Fix in Web

abi: depositContractAbi,
address: args.address || DEPOSIT_CONTRACT_ADDRESS,
functionName: 'deposit',
Expand Down
5 changes: 4 additions & 1 deletion packages/seismic-viem/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import { compressPublicKey } from '@sviem/crypto/secp.ts'
* This is the same as viem's public client, with a few notable differences:
* - `getTeePublicKey`: a new function specific to Seismic. It takes no parameters and returns a Promise that resolves to the network's public key
* - `getStorageAt` and `getTransaction`: both of these will return an error since Seismic does not support these endpoints
* - `deposit`: deposit into the deposit contract
* - `getDepositRoot`: get the deposit root from the deposit contract
* - `getDepositCount`: get the deposit count from the deposit contract
*/
export type ShieldedPublicClient<
transport extends Transport = Transport,
Expand Down Expand Up @@ -76,7 +79,7 @@ export type ShieldedPublicClient<
* - `treadContract`: call a contract function with an unsigned read (from the zero address)
* - `writeContract`: execute a function on a contract via a Seismic transaction, encrypting the calldata
* - `twriteContract`: execute a function on a contract via a standard ethereum transaction

* - `deposit`: deposit into the deposit contract
*/
export type ShieldedWalletClient<
transport extends Transport = Transport,
Expand Down