Computing a commitment
The commitment is plain abi.encode then keccak256. Compute it off-chain; commitmentOf exists to check your code against the contract.
TypeScript, with viem
import { encodeAbiParameters, keccak256, toHex } from "viem";
const salt = toHex(crypto.getRandomValues(new Uint8Array(32)));
const commitment = keccak256(
encodeAbiParameters(
[
{ type: "address" }, { type: "uint256" }, { type: "uint256" },
{ type: "uint8" }, { type: "uint256" }, { type: "uint256" }, { type: "bytes32" },
],
[trader, batch, market, side, amount, limitPx, salt],
),
);
Units
amountfor a buy is USDG in raw units (6 decimals) and includes the fee budget. For a sell it is shares in raw units (18 decimals).limitPxis USDG raw per 1e18 share raw. A limit of $226.10 per share is226100000.
Which batch
Read currentBatch() and commit while the phase is 0. If the phase flips to reveal before your transaction lands, commit reverts with WrongPhase and nothing is lost but gas. Commit early in the window.