Skip to content

Latest commit

 

History

History
122 lines (85 loc) · 3.98 KB

File metadata and controls

122 lines (85 loc) · 3.98 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

Socket DL (Data Layer) is a protocol for generic message passing between blockchains. It enables dapps ("plugs") to send and receive cross-chain messages with configurable security/speed tradeoffs. The protocol is deployed across 70+ EVM chains.

Build and Test Commands

# Install dependencies
forge install && yarn install

# Compile contracts
forge build          # or: yarn compile

# Run tests (formats changed files first)
yarn test            # runs: prettier + forge test

# Run specific test file
forge test --match-path test/socket/SocketSrc.t.sol

# Run specific test function
forge test --match-test testOutbound

# Lint/format
yarn lint

# Export ABIs
yarn abi             # or: hardhat export-abi

# Build TypeScript package
yarn build           # exports ABIs + compiles TS

Deployment

Deployment uses Hardhat. Three modes exist: dev, surge, prod (set via DEPLOYMENT_MODE env var).

# Full deployment flow
bash deploy.sh

# Individual steps
npx hardhat run scripts/deploy/deploy.ts      # Deploy contracts
npx hardhat run scripts/deploy/verify.ts      # Verify on explorers

Key deployment files:

Architecture

Core Message Flow

  1. Source Chain: Plug calls Socket.outbound() → message packed into Capacitor → Transmitter seals packet
  2. Destination Chain: Transmitter proposes packet root → Switchboard verifies → Executor calls Socket.execute() → Plug receives inbound()

Contract Hierarchy

Socket (main entry point)
├── SocketSrc - Outbound message handling, packet sealing
├── SocketDst - Inbound execution, packet verification
├── SocketConfig - Plug configuration, switchboard registration
└── SocketBase - Shared state (hasher, capacitorFactory, managers)

Key Contracts

Integration Pattern

Dapps implement the IPlug interface:

interface IPlug {
  function inbound(
    uint32 srcChainSlug_,
    bytes calldata payload_
  ) external payable;
}

Plugs connect to Socket specifying: sibling plug address, switchboard for inbound/outbound, and capacitor type.

TypeScript SDK (src/)

Published as @socket.tech/dl-core. Exports:

  • Chain enums (ChainSlug, ChainId)
  • Contract addresses by deployment mode
  • Transmission utilities

Code Style (Solidity)

  • Private/internal variables and functions: underscore prefix (_foo, _bar())
  • Function parameters: underscore postfix (param_)
  • Contract instances: double underscore postfix (contract__)
  • Events: past tense, emitted immediately after state change
  • All state variables should be private/internal with explicit getters where needed

Environment Variables

Required in .env:

  • DEPLOYMENT_MODE - dev/surge/prod
  • SOCKET_SIGNER_KEY - Deployer private key
  • SOCKET_OWNER_ADDRESS - Contract owner
  • Chain-specific RPCs and explorer API keys