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

# Rebalancing

> How rebalancing proposals are created, approved and executed

<Warning>
  Draft: specification in progress. Endpoints and fields may change.
</Warning>

Rebalancing means adjusting the proportion between USDY and BUIDL in the yielding balance. At TESA, every rebalancing starts as a proposal and only happens with the company's approval.

## Where proposals come from

* **Suggested by TESA** (`origem: tesa`): when the rate spread between the assets exceeds the policy threshold. The `alocacao.proposta` event notifies the integration.
* **Created by the integration** (`origem: cliente`): with `POST /propostas`, specifying the target allocation.

```mermaid theme={null}
stateDiagram-v2
  [*] --> pendente
  pendente --> aprovada: approve
  pendente --> rejeitada: reject
  aprovada --> executada: signed by the custodian and confirmed on-chain
```

## Flow

<Steps>
  <Step title="Receive or create the proposal">
    ```bash theme={null}
    curl -X POST https://api.t3sa.com/v1/propostas \
      -H "Authorization: Bearer tesa_live_..." \
      -H "Idempotency-Key: 3c9a0d52-1e7b-4f28-8d6a-5b2e7f0c9a14" \
      -H "Content-Type: application/json" \
      -d '{"alocacao_alvo":[{"ativo":"USDY","percentual":55},{"ativo":"BUIDL","percentual":45}],"motivo":"Revisão trimestral"}'
    ```
  </Step>

  <Step title="Review the movements">
    `GET /propostas/{id}` shows `movimentos` and `alocacao_resultante`. Check them before approving.
  </Step>

  <Step title="Approve or reject">
    With an `admin` key, call `POST /propostas/{id}/aprovar` or `POST /propostas/{id}/rejeitar`. Approval requires an `Idempotency-Key` and, in the current proposal, can be signed with HMAC.
  </Step>

  <Step title="Sign with the custodian">
    The approved proposal includes `transacoes[].payload_nao_assinado`. The custodian signs and broadcasts.
  </Step>

  <Step title="Track execution">
    After on-chain confirmation, the proposal moves to `executada` and records of type `rebalanceamento` appear in `GET /registros`.
  </Step>
</Steps>

## Changing the policy

To change the proportion permanently, not just once, use `PUT /politica-de-alocacao`. The new version applies to future deposits and becomes the reference for upcoming proposals. The percentages must add up to 100, otherwise the API returns `422` with `politica_invalida`.

<Note>
  Approving does not move funds. Funds move only after signing by the company's custodian.
</Note>
