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
45 changes: 45 additions & 0 deletions libs/tangle-shared-ui/src/abi/tangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,51 @@ const ABI = [
],
stateMutability: 'view',
},
{
type: 'function',
name: 'getSlashConfig',
inputs: [],
outputs: [
{
name: '',
type: 'tuple',
internalType: 'struct SlashingLib.SlashConfig',
components: [
{
name: 'disputeWindow',
type: 'uint64',
internalType: 'uint64',
},
{
name: 'instantSlashEnabled',
type: 'bool',
internalType: 'bool',
},
{
name: 'maxSlashBps',
type: 'uint16',
internalType: 'uint16',
},
{
name: 'disputeResolutionDeadline',
type: 'uint64',
internalType: 'uint64',
},
{
name: 'disputeBond',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'maxPendingSlashesPerOperator',
type: 'uint16',
internalType: 'uint16',
},
],
},
],
stateMutability: 'view',
},
{
type: 'function',
name: 'getSlashProposal',
Expand Down
33 changes: 33 additions & 0 deletions libs/tangle-shared-ui/src/data/graphql/useSlashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,32 @@ export const useProposableServices = (options?: {
});
};

/**
* Reads the active slashing configuration from the Tangle contract.
* Exposes disputeBond so callers can attach msg.value when disputing.
*/
export const useSlashConfig = (options?: { enabled?: boolean }) => {
const { enabled = true } = options ?? {};
const chainId = useChainId();
const publicClient = usePublicClient();

return useQuery({
queryKey: ['slashing', 'config', chainId],
queryFn: async () => {
if (!publicClient) throw new Error('Public client not available');
const contracts = getContractsByChainId(chainId);
return publicClient.readContract({
address: contracts.tangle,
abi: TANGLE_ABI,
functionName: 'getSlashConfig',
args: [],
});
},
enabled: enabled && !!publicClient,
staleTime: 60_000,
});
};

/**
* Reads an on-chain slash proposal directly from the Tangle contract.
*/
Expand Down Expand Up @@ -1130,9 +1156,14 @@ export const useProposeSlashTx = () => {

/**
* Hook to dispute a slash proposal.
* Automatically reads disputeBond from the active SlashConfig and forwards
* it as msg.value — required when the admin has set a non-zero bond.
*/
export const useDisputeSlashTx = () => {
const chainId = useChainId();
const { data: slashConfig } = useSlashConfig();
const disputeBond = slashConfig?.disputeBond ?? BigInt(0);

const hook = useContractWrite(
TANGLE_ABI,
(params: SlashReasonParams) => {
Expand All @@ -1148,6 +1179,7 @@ export const useDisputeSlashTx = () => {
abi: TANGLE_ABI,
functionName: 'disputeSlash' as const,
args: [params.slashId, params.reason] as const,
value: disputeBond > BigInt(0) ? disputeBond : undefined,
};
},
{
Expand All @@ -1168,6 +1200,7 @@ export const useDisputeSlashTx = () => {

return {
disputeSlash,
disputeBond,
status: mapContractWriteStatus(hook.status),
error: hook.error,
reset: hook.reset,
Expand Down
Loading