> For the complete documentation index, see [llms.txt](https://gabriel-j-shapiro.gitbook.io/metalex-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gabriel-j-shapiro.gitbook.io/metalex-docs/protocol-how-to-guides/run-a-secondary-trade.md).

# Run a secondary trade

Secondary trades settle through a cyberCORP's **`DealManager`**. A deal is built from an agreement template and identified by a `bytes32 agreementId`.

## 1. Propose the deal

```solidity
bytes32 agreementId = IDealManager(dealManager).proposeDeal(
    certPrinters,     // address[] — cert printers involved
    USDC,             // paymentToken
    200_000e6,        // paymentAmount
    templateId,       // bytes32 agreement template
    salt,             // uint256
    globalValues,     // string[]
    parties,          // address[] — the counterparties
    certDetails,      // CertificateDetails[]
    partyValues,      // string[][]
    conditions,       // address[] — ICondition gates
    secretHash,       // bytes32
    expiry            // uint256
);
```

Use `proposeAndSignDeal` to propose and sign in one call.

## 2. Counterparties sign (and pay)

Each party signs the agreement (EIP-712). `signDealAndPay` combines a party's signature with their payment:

```solidity
IDealManager(dealManager).signDealAndPay(
    signer,
    agreementId,
    signature,        // bytes (EIP-712)
    partyValues,      // string[]
    fillUnallocated,  // bool
    name,             // string
    secret            // string — if the deal is secret-gated
);
```

## 3. Finalise

When all parties have signed and the deal's conditions are satisfied:

```solidity
IDealManager(dealManager).finalizeDeal(agreementId);
```

Finalisation applies the deal's certificate effects (mint / assign / endorse) through the IssuanceManager. `signAndFinalizeDeal` does the final signature and finalisation together.

## Cancelling

* `voidExpiredDeal(agreementId, signer, signature)` — clear an expired deal.
* `revokeDeal(agreementId, signer, signature)` — revoke before completion.
* `signToVoid(agreementId, signer, signature)` — sign to void a deal.

## Note on escrow

The escrow of payment and assets is part of this deal flow — there is no separate escrow contract to call. See [LeXscroWLite](/metalex-docs/protocol-reference/contracts/lexscrowlite.md).

## Related

* [DealManager](/metalex-docs/protocol-reference/contracts/dealmanager.md), [CyberAgreementRegistry](/metalex-docs/protocol-reference/contracts/cyberagreementregistry.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://gabriel-j-shapiro.gitbook.io/metalex-docs/protocol-how-to-guides/run-a-secondary-trade.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
