> For the complete documentation index, see [llms.txt](https://docs.uxd.fi/uxdprogram-solana/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uxd.fi/uxdprogram-solana/instructions/initialize_controller.md).

# initialize\_controller

### Flow

* Checks
  * Anchor IDL accounts checks
  * Validates: check decimal input parameter
* Handler
  * Initialises the `controller` PDA
  * Initialises the `redeemable_mint` PDA
  * Writes initial `controller` data
  * Emits Anchor `InitializeControllerEvent` event

### Specificities

There can ever only be a single `Controller` for a given deployed program due to the seed derivation being a function of a static string and the programID

This instruction is preferably called right after program deployment. In the very unlikely event that  someone front run you, nothing at stake yet so wipe and redeploy and call it faster.

This instruction is preferably called by a multisig/DAO instead of a specific user account, for safety.

### Parameters

`redeemable_mint_decimals` the number of decimal the `redeemable mint` (UXD in our case) should be created with

### Accounts input

{% code title="programs/uxd/src/instructions/initialize\_controller.rs" %}

```rust
// ...

/// Takes 7 accounts - 4 used locally - 0 for CPI - 2 Programs - 1 Sysvar
#[derive(Accounts)]
#[instruction(
    redeemable_mint_decimals: u8,
)]
pub struct InitializeController<'info> {
    /// #1 Authored call accessible only to the signer matching Controller.authority
    pub authority: Signer<'info>,

    /// #2
    #[account(mut)]
    pub payer: Signer<'info>,

    /// #3 The top level UXDProgram on chain account managing the redeemable mint
    #[account(
        init,
        seeds = [CONTROLLER_NAMESPACE],
        bump,
        payer = payer,
        space = CONTROLLER_SPACE
    )]
    pub controller: AccountLoader<'info, Controller>,

    /// #4 The redeemable mint managed by the `controller` instance
    #[account(
        init,
        seeds = [REDEEMABLE_MINT_NAMESPACE],
        bump,
        mint::authority = controller,
        mint::decimals = redeemable_mint_decimals,
        payer = payer,
        constraint = redeemable_mint_decimals <= SOLANA_MAX_MINT_DECIMALS
    )]
    pub redeemable_mint: Account<'info, Mint>,

    /// #5 System Program
    pub system_program: Program<'info, System>,

    /// #6 Token Program
    pub token_program: Program<'info, Token>,

    /// #7 Rent Sysvar
    pub rent: Sysvar<'info, Rent>,
}

// ...
```

{% endcode %}


---

# 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:

```
GET https://docs.uxd.fi/uxdprogram-solana/instructions/initialize_controller.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.
