Skip to main content
Version: 1.x

Home Channel Deposit Flow

This document provides a comprehensive breakdown of the Home Channel Deposit flow as defined in the Nitrolite v1.0 protocol. This operation allows a user to deposit additional funds into their existing home channel on their Home Chain -- the blockchain where their channel currently exists.

This is a single-chain operation that creates a new state with a deposit transition, gets it co-signed by the Node, and then enforces it on-chain via depositToChannel.

info

This flow is for subsequent deposits to an existing channel. For the initial deposit (creating a channel), see Home Channel Creation Flow.


Actors in the Flow

ActorRole
UserThe human user initiating the deposit
ClientSDK/Application managing states on behalf of the user
NodeThe Clearnode that validates and stores state transitions
HomeChainThe blockchain where the user's home channel exists

Prerequisites

Before the home channel deposit flow begins:

  1. Client is connected to the Node via WebSocket.
  2. User already has a home channel on the HomeChain.
  3. Node contains the user's state with Home Channel information.
  4. User has funds on the HomeChain to deposit (ERC-20 tokens).
  5. No ongoing operation exists for this channel (the Clearnode will deny the request otherwise).
note

The "no ongoing operation" requirement applies to ALL operations except finalize_escrow_deposit, finalize_escrow_withdrawal, and finalize_migration.


Key Concepts

Deposit vs Other Operations

OperationDirectionOn-Chain Action
home_depositExternal to ChannelcreateChannel (first deposit) or depositToChannel
home_withdrawalChannel to ExternalwithdrawFromChannel (can also be done with createChannel)
escrow_withdrawChannel to Non-Home ChaininitiateEscrowWithdrawal

The depositToChannel Mechanism

The depositToChannel on-chain call enforces the latest signed state for deposits. It:

  • Updates the on-chain state version
  • Pulls funds from the user (via ERC-20 approve/transferFrom)
  • Adds funds to the channel's locked balance
  • Provides settlement guarantees

Phase 1: Deposit Initiation

The User calls the deposit function on the Client SDK with three parameters:

ParameterDescriptionExample
blockchainIdThe blockchain ID to deposit on (home chain)137 (Polygon)
assetThe asset symbol to depositusdc
amountThe amount to deposit100.0

Phase 2: Fetching Current State

  1. Client requests the latest state from the Node.
  2. The Node looks up the state using UserWallet and asset.
  3. The Node returns the current state object containing Home Channel information, current balances, and latest version.

Phase 3: Building the Deposit State

3.1 Create Next State

createNextState(currentState) -> state

The Client creates a new state object based on the current state with an incremented version. The State ID is computed internally by this method.

3.2 Apply Deposit Transition

state.ApplyHomeDepositTransition(amount)

Creates and applies the deposit transition internally:

FieldValue
typehome_deposit
tx_hashState ID reference
account_idUser wallet address
amountDeposit amount

The transition updates the state:

  • user_balance increases by the deposit amount
  • user_net_flow becomes positive (funds flowing in)

3.3 Sign

signState(state) -> userSig

The user signs the state.


Phase 4: Submitting State to Node

Node Validation Steps

StepOperationPurpose
1GetLastState(...)Fetch current user state
2EnsureNoOngoingTransitions()Prevent conflicts with other operations
3ValidateStateTransition(...)Verify version, signatures, balances
4StoreState(state)Persist the new state

Validation Rules

The Node validates:

  • Version is currentState.version + 1
  • User signature is valid
  • No ongoing transitions (atomic operations)
  • Deposit amount is positive

A state with intent DEPOSIT must include a positive user net-flow delta.


Phase 5: On-Chain Deposit

5.1 Pack State for On-Chain

PackState(channelId, state) -> packedState

Serializes the state for smart contract consumption.

5.2 On-Chain Deposit

depositToChannel(channelId, packedState)

The Client submits a transaction to the HomeChain smart contract, which:

  • Validates the state signatures (User + Node)
  • Verifies the state version is newer than on-chain version
  • Calculates the net-flow delta
  • Pulls funds from user (via ERC-20 approve/transferFrom)
  • Increases the locked funds in the channel
  • Emits ChannelDeposited event

On-Chain State Changes

FieldChange
state_versionUpdated to new version
locked_fundsIncreased by deposit amount
User's token balanceDecreased by deposit amount

Phase 6: Event Handling and Completion

The Node listens for blockchain events and:

  1. HandleChannelDeposited() -- Processes the deposit event.
  2. UpdateChannel(channel) -- Updates the channel's on-chain state version and locked funds.
EventDescription
ChannelUpdateNotifies client of new channel state
BalanceUpdateNotifies client of new balance

Complete Flow Diagram


Key Concepts Summary

State Transition Flow

Deposit vs On-Chain Enforcement

AspectDescription
Off-chain (SubmitState)Updates state with Node, gets dual signature
On-chain (depositToChannel)Enforces state, locks actual funds

Without the on-chain deposit call, the deposit is only recorded off-chain. The depositToChannel is what actually moves the tokens from the user's wallet into the channel.

Net Flow Semantics

  • User signs a state with intent = DEPOSIT.
  • User net flow becomes positive.
  • On enforcement: funds are pulled from User, channel locked funds increase.

FlowOn-Chain ActionDirection
Home Deposit (this flow)depositToChannelExternal to Channel
Home Deposit (first time)createChannelExternal to Channel
Home WithdrawalwithdrawFromChannelChannel to External
Escrow WithdrawalinitiateEscrowWithdrawalChannel to Non-Home
TransferNone (off-chain only)User to User

Security Guarantees

Validation Invariants

InvariantDescription
Version monotonicityEvery valid state has a strictly increasing version
Version uniquenessNo two different states with the same version
Signature authorizationState must be signed by both User and Node
Positive depositDeposit amount must be greater than zero

What Protects the User?

  1. Dual signatures -- Both User and Node must agree to the state.
  2. On-chain enforcement -- depositToChannel validates all signatures.
  3. Challenge mechanism -- User can challenge if Node misbehaves.
  4. ERC-20 approval -- User explicitly approves the token transfer.

Error Scenarios

ScenarioCauseResolution
No existing channelUser hasn't created a channel yetUse "From Scratch" creation flow
Ongoing transitionAtomic operation in progressWait for completion
Invalid signatureCorrupted or wrong keyRegenerate signature
Stale versionRace conditionRefetch state and retry
Insufficient ERC-20 balanceUser lacks tokensObtain tokens first
Missing approvalERC-20 not approved for contractApprove contract first