> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How the Deposit Contract Works

> Programmable address contract that receives tokens and executes cross-chain actions

The Deposit Contract is the programmable address smart contract that receives tokens and executes the programmed action. Each contract is bound to a specific destination address and handles the conversion of deposits into Routes intents.

## Purpose

Each programmable address contract serves a single destination:

* **Token reception**: Receives tokens from users
* **Action execution**: Converts deposits into cross-chain intents via Portal
* **Refund handling**: Returns funds for expired/unfulfilled intents

## Functions

### initialize

Called by the factory immediately after deployment.

```solidity theme={null}
function initialize(
    bytes32 _destinationAddress,
    address _depositor
) external
```

**Parameters:**

* `_destinationAddress`: Destination wallet that will receive funds
* `_depositor`: Address authorized to trigger refunds

### createIntent

Creates a cross-chain intent for the specified amount.

```solidity theme={null}
function createIntent(uint256 amount)
    external returns (bytes32 intentHash)
```

**Parameters:**

* `amount`: Amount of tokens to include in the intent

**Returns:**

* `intentHash`: Unique identifier for the created intent

### refund

Triggers a refund for an expired intent.

```solidity theme={null}
function refund(
    bytes32 routeHash,
    Reward calldata reward
) external
```

**Parameters:**

* `routeHash`: Hash of the route parameters
* `reward`: Reward structure for the intent

### View Functions

```solidity theme={null}
function destinationAddress() external view returns (bytes32)
function depositor() external view returns (address)
```

## Reward Structure

The refund function requires a Reward struct:

```solidity theme={null}
struct Reward {
    uint64 deadline;
    address creator;
    address prover;
    uint256 nativeAmount;
    TokenAmount[] tokens;
}

struct TokenAmount {
    address token;
    uint256 amount;
}
```

| Field          | Type           | Description                    |
| -------------- | -------------- | ------------------------------ |
| `deadline`     | uint64         | Intent expiry timestamp        |
| `creator`      | address        | Intent creator (this contract) |
| `prover`       | address        | Prover contract address        |
| `nativeAmount` | uint256        | Native token amount            |
| `tokens`       | TokenAmount\[] | Token amounts in reward        |

## Events

### IntentCreated

```solidity theme={null}
event IntentCreated(
    bytes32 indexed intentHash,
    uint256 amount,
    address indexed caller
)
```

Emitted when a new intent is created from a deposit.

| Field        | Type    | Indexed | Description                            |
| ------------ | ------- | ------- | -------------------------------------- |
| `intentHash` | bytes32 | Yes     | Unique intent identifier               |
| `amount`     | uint256 | No      | Token amount in the intent             |
| `caller`     | address | Yes     | Address that triggered intent creation |

### IntentRefunded

```solidity theme={null}
event IntentRefunded(
    bytes32 indexed routeHash,
    address indexed refundee
)
```

Emitted when funds are refunded for an expired intent.

| Field       | Type    | Indexed | Description                       |
| ----------- | ------- | ------- | --------------------------------- |
| `routeHash` | bytes32 | Yes     | Route hash of the refunded intent |
| `refundee`  | address | Yes     | Address receiving the refund      |

## Errors

### AlreadyInitialized

```solidity theme={null}
error AlreadyInitialized()
```

Thrown when `initialize()` is called more than once.

### NotInitialized

```solidity theme={null}
error NotInitialized()
```

Thrown when calling functions before initialization.

### OnlyFactory

```solidity theme={null}
error OnlyFactory()
```

Thrown when non-factory address calls `initialize()`.

### InvalidDepositor

```solidity theme={null}
error InvalidDepositor()
```

Thrown when non-depositor attempts to trigger refund.

### NoDepositorSet

```solidity theme={null}
error NoDepositorSet()
```

Thrown when depositor address is zero during initialization.

### InsufficientBalance

```solidity theme={null}
error InsufficientBalance(uint256 requested, uint256 available)
```

Thrown when intent amount exceeds contract's token balance.

### ZeroAmount

```solidity theme={null}
error ZeroAmount()
```

Thrown when attempting to create intent with zero amount.

### ReentrancyGuardReentrantCall

```solidity theme={null}
error ReentrancyGuardReentrantCall()
```

Thrown on reentrancy attempt (security protection).
