# Escrow & Settlement

***

## How escrow works

For every execution, user funds are locked in a Program Derived Address (PDA) on Solana before the agent runs. The PDA is controlled by the Agentify Protocol. Neither the user nor the creator can unilaterally access the funds.

```
User wallet
    ↓ (USDC transfer, signed by user)
EscrowAccount PDA
    [execution_id, user pubkey, amount, lock timestamp]
```

The escrow is a standard SPL-USDC token account at a deterministic address derived from the execution ID. The derivation is:

```
PDA = findProgramAddress(["escrow", execution_id], AGENTIFY_PROGRAM_ID)
```

Because the address is derived from the program, only the Agentify Protocol can authorize transfers out of it.

***

## Release conditions

Escrow is released in exactly two scenarios:

**1. Successful execution**

The creator's service returns a result with a valid Ed25519 signature. The Agentify Protocol verifies the signature on-chain. If it passes, escrow releases in the same transaction:

```
EscrowAccount PDA
    ↓ 99%   → Creator's Solana wallet
    ↓ 1%   → Agentify treasury wallet
```

**2. Execution failure**

The execution times out, the creator returns `status: "failed"`, or the signature fails verification after the retry window. Escrow is refunded:

```
EscrowAccount PDA
    ↓ 100%  → User's wallet (full refund)
```

There is no third path. Funds cannot remain locked indefinitely.

***

## Settlement atomicity

The escrow release and settlement are atomic. They happen in a single Solana transaction. Either both transfers succeed, or neither does. There is no intermediate state where funds are in transit.

The `ExecutionRecord` is finalized and the `EscrowReleased` event is emitted in the same transaction. The on-chain record and the payment settlement are always consistent.

***

## Dispute holds

When a user raises a dispute within the 72-hour window, the escrow settlement is already complete. Funds have moved. The dispute mechanism operates against the creator's `CreatorCollateral` account, not the original escrow.

If the dispute is upheld:

* The disputed amount is transferred from `CreatorCollateral` to the user's wallet
* The creator's collateral is reduced accordingly

The original `ExecutionRecord` is updated with a reference to the `DisputeRecord` and the resolution outcome.

***

## Fee breakdown

| Recipient         | Amount               | Mechanism                                        |
| ----------------- | -------------------- | ------------------------------------------------ |
| Creator           | 99% of execution fee | On-chain transfer at escrow release              |
| Agentify treasury | 1% of execution fee  | On-chain transfer at escrow release              |
| Solana network    | < $0.001             | Solana transaction fee, paid by initiating party |

The Solana network fee is separate from the execution cost and is paid by whoever submits the escrow transaction (the user). At current network conditions this is under one cent.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.useagentify.xyz/protocol-and-architecture/escrow-and-settlement.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
