Skip to main content

Kernel

The ACTPKernel module provides direct control over transaction lifecycle and state management.


Overview

ACTPKernel is the core smart contract wrapper that manages:

  • Transaction creation and state transitions
  • State machine enforcement (8-state lifecycle)
  • Access control validation
  • Gas optimization with operation-specific buffers

Constructor

The Kernel is accessed through ACTPClient:

// Level 2: Advanced API - Direct protocol control
const client = await ACTPClient.create({ mode: 'mock', requesterAddress: '0x...' });
const kernel = client.advanced;

Methods

createTransaction()

Create a new ACTP transaction.

// Level 2: Advanced API - Direct protocol control
const txId = await kernel.createTransaction({
provider: '0x2222222222222222222222222222222222222222',
requester: '0x1111111111111111111111111111111111111111',
amount: '100000000', // 100 USDC (6 decimals)
deadline: Math.floor(Date.now() / 1000) + 86400, // 24 hours
disputeWindow: 172800, // 48 hours
serviceHash: '0x...', // Optional: hash of service description
});

console.log('Created transaction:', txId);

Parameters:

ParameterTypeDescription
providerstringProvider's Ethereum address
requesterstringRequester's Ethereum address
amountstringAmount in wei (USDC has 6 decimals)
deadlinenumberUnix timestamp for acceptance deadline
disputeWindownumberSeconds for dispute window after delivery
serviceHashstring?Optional hash of service description

Returns: Promise<string> - Transaction ID (bytes32)


getTransaction()

Get transaction details by ID.

// Level 2: Advanced API - Direct protocol control
const tx = await kernel.getTransaction(txId);

console.log('State:', tx.state);
console.log('Amount:', tx.amount);
console.log('Provider:', tx.provider);
console.log('Requester:', tx.requester);
console.log('Created:', new Date(tx.createdAt * 1000));
console.log('Deadline:', new Date(tx.deadline * 1000));

Returns: Promise<Transaction | null>

// Level 2: Advanced API - Direct protocol control
interface Transaction {
txId: string;
requester: string;
provider: string;
amount: bigint;
state: State;
createdAt: number;
updatedAt: number;
deadline: number;
disputeWindow: number;
escrowContract: string;
escrowId: string;
serviceHash: string;
attestationUID: string;
metadata: string;
platformFeeBpsLocked: number;
}

transitionState()

Transition transaction to a new state.

// Level 2: Advanced API - Direct protocol control
// Provider signals work started
await kernel.transitionState(txId, State.IN_PROGRESS);

// Provider delivers work
await kernel.transitionState(txId, State.DELIVERED);

Valid Transitions:

FromToWho
INITIATEDQUOTEDProvider
INITIATED/QUOTEDCOMMITTEDSystem (via linkEscrow)
COMMITTEDIN_PROGRESSProvider
COMMITTED/IN_PROGRESSDELIVEREDProvider
Any (before DELIVERED)CANCELLEDRequester
DELIVEREDDISPUTEDEither
DELIVERED/DISPUTEDSETTLEDSystem

linkEscrow()

Link escrow to transaction (automatically transitions to COMMITTED).

// Level 2: Advanced API - Direct protocol control
// Approve USDC first
await client.escrow.approveToken(USDC_ADDRESS, amount);

// Link escrow - auto-transitions to COMMITTED
await kernel.linkEscrow(txId, escrowVaultAddress, escrowId);

Parameters:

ParameterTypeDescription
txIdstringTransaction ID
escrowVaultstringEscrowVault contract address
escrowIdstringUnique escrow identifier

anchorAttestation()

Anchor EAS attestation UID to transaction.

// Level 2: Advanced API - Direct protocol control
// After creating attestation via EASHelper
await kernel.anchorAttestation(txId, attestationUID);

releaseEscrow()

Release escrowed funds to provider (after dispute window).

// Level 2: Advanced API - Direct protocol control
await kernel.releaseEscrow(txId);

Requirements:

  • Transaction must be in DELIVERED state
  • Dispute window must have expired
  • Called by requester or automatically

raiseDispute()

Raise a dispute on a delivered transaction.

// Level 2: Advanced API - Direct protocol control
await kernel.raiseDispute(txId, disputeProof);

Parameters:

ParameterTypeDescription
txIdstringTransaction ID
proofbytesABI-encoded dispute proof

resolveDispute()

Resolve a dispute (mediator only).

// Level 2: Advanced API - Direct protocol control
await kernel.resolveDispute(txId, {
decision: DisputeResolution.PROVIDER_WINS,
requesterAmount: '0',
providerAmount: '100000000',
});

Resolution Options:

DecisionDescription
PROVIDER_WINSFull amount to provider
REQUESTER_WINSFull refund to requester
SPLITCustom split between parties

cancelTransaction()

Cancel transaction before delivery.

// Level 2: Advanced API - Direct protocol control
// Requester cancels (refunds escrow if linked)
await kernel.cancelTransaction(txId);

Requirements:

  • Must be before DELIVERED state
  • Only requester can cancel
  • Refunds escrowed funds automatically

Gas Optimization

ACTPKernel uses operation-specific gas buffers:

OperationGas BufferMin Floor
createTransaction15%120k
transitionState20%80k
releaseEscrow30%220k
raiseDispute25%100k
resolveDispute30%250k
cancelTransaction15%60k

Error Handling

// Level 2: Advanced API - Direct protocol control
import {
TransactionNotFoundError,
InvalidStateTransitionError,
DeadlineExpiredError,
} from '@agirails/sdk';

try {
await kernel.transitionState(txId, State.DELIVERED);
} catch (error) {
if (error instanceof InvalidStateTransitionError) {
console.log('From:', error.details.from);
console.log('To:', error.details.to);
console.log('Valid:', error.details.validTransitions);
}
}

Next Steps

  • Escrow - Fund management
  • Events - Real-time monitoring
  • EAS - Attestation creation