diff --git a/packages/seismic-viem-tests/src/tests/contract/depositContract.ts b/packages/seismic-viem-tests/src/tests/contract/depositContract.ts index b360517..7bcc7f2 100644 --- a/packages/seismic-viem-tests/src/tests/contract/depositContract.ts +++ b/packages/seismic-viem-tests/src/tests/contract/depositContract.ts @@ -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, @@ -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, }) @@ -226,5 +245,8 @@ export const testDepositContract = async ({ newDepositCount, newDepositRoot, validatorData, + initialAccountBalance, + finalAccountBalance, + contractBalance, } } diff --git a/packages/seismic-viem/src/actions/depositContract.ts b/packages/seismic-viem/src/actions/depositContract.ts index 190ba14..e8bc408 100644 --- a/packages/seismic-viem/src/actions/depositContract.ts +++ b/packages/seismic-viem/src/actions/depositContract.ts @@ -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' @@ -90,7 +90,7 @@ export const depositContractWalletActions = < client: WalletClient ): DepositContractWalletActions => ({ deposit: async (args) => - writeContract(client, { + client.writeContract({ abi: depositContractAbi, address: args.address || DEPOSIT_CONTRACT_ADDRESS, functionName: 'deposit', diff --git a/packages/seismic-viem/src/client.ts b/packages/seismic-viem/src/client.ts index a11e9de..ec1e890 100644 --- a/packages/seismic-viem/src/client.ts +++ b/packages/seismic-viem/src/client.ts @@ -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, @@ -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,