> ## 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 Address Factory Works

> Factory contract that generates and deploys deterministic programmable addresses

The Address Factory is a smart contract that generates deterministic programmable addresses and deploys their contracts on demand. Each factory is configured for a specific source-destination token pair.

## Purpose

The factory serves as the entry point for the programmable address system:

* **Address generation**: Computes programmable addresses without onchain transactions
* **Contract deployment**: Deploys programmable address contracts when funds are received
* **Configuration storage**: Holds immutable settings for all programmable address contracts it creates

## Constructor

```solidity theme={null}
constructor(
    uint64 _destinationChain,
    address _sourceToken,
    bytes32 _targetToken,
    address _portalAddress,
    address _proverAddress,
    bytes32 _destinationPortal,
    uint64 _intentDeadlineDuration
)
```

| Parameter                 | Type    | Description                                 |
| ------------------------- | ------- | ------------------------------------------- |
| `_destinationChain`       | uint64  | Target chain ID                             |
| `_sourceToken`            | address | Token on source chain                       |
| `_targetToken`            | bytes32 | Token on destination (bytes32 for cross-VM) |
| `_portalAddress`          | address | Routes Portal contract                      |
| `_proverAddress`          | address | Cross-chain prover                          |
| `_destinationPortal`      | bytes32 | Portal on destination chain                 |
| `_intentDeadlineDuration` | uint64  | Intent validity period                      |

## Functions

### getDepositAddress

Computes the deterministic programmable address for a given destination.

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

**Parameters:**

* `destinationAddress`: destination wallet address as bytes32 (cross-VM compatible)

**Returns:**

* The EVM address where the user should send tokens

### isDeployed

Checks if a programmable address contract has been deployed for a destination.

```solidity theme={null}
function isDeployed(bytes32 destinationAddress)
    external view returns (bool)
```

### deploy

Deploys a new programmable address contract for the specified destination.

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

**Parameters:**

* `destinationAddress`: destination wallet address as bytes32 (cross-VM compatible)
* `depositor`: Address authorized to trigger refunds

**Returns:**

* Address of the deployed programmable address contract

### getConfiguration

Returns all factory configuration values.

```solidity theme={null}
function getConfiguration() external view returns (
    uint64 destinationChain,
    address sourceToken,
    bytes32 targetToken,
    address portalAddress,
    address proverAddress,
    bytes32 destinationPortal,
    uint64 intentDeadlineDuration
)
```

### Configuration Getters

Individual getters for each configuration value:

* `DESTINATION_CHAIN()` - Target chain ID
* `SOURCE_TOKEN()` - Source token address
* `TARGET_TOKEN()` - Target token (bytes32)
* `PORTAL_ADDRESS()` - Portal contract address
* `PROVER_ADDRESS()` - Prover contract address
* `DESTINATION_PORTAL()` - Destination portal (bytes32)
* `INTENT_DEADLINE_DURATION()` - Deadline duration
* `DEPOSIT_IMPLEMENTATION()` - Implementation contract address

## Events

### DepositContractDeployed

```solidity theme={null}
event DepositContractDeployed(
    bytes32 indexed destinationAddress,
    address indexed depositAddress
)
```

Emitted when a new programmable address contract is deployed.

| Field                | Type    | Indexed | Description                           |
| -------------------- | ------- | ------- | ------------------------------------- |
| `destinationAddress` | bytes32 | Yes     | Destination wallet address (cross-VM) |
| `depositAddress`     | address | Yes     | Deployed contract address             |

## Errors

### ContractAlreadyDeployed

```solidity theme={null}
error ContractAlreadyDeployed(address depositAddress)
```

Thrown when attempting to deploy a contract that already exists.

### InvalidDeadlineDuration

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

Thrown during construction if deadline duration is zero.

### InvalidPortalAddress

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

Thrown during construction if Portal address is zero.

### InvalidProverAddress

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

Thrown during construction if Prover address is zero.

### InvalidSourceToken

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

Thrown during construction if source token address is invalid.

### InvalidTargetToken

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

Thrown during construction if target token is invalid.

### InvalidDestinationPortal

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

Thrown during construction if destination Portal is zero bytes.
