> For the complete documentation index, see [llms.txt](https://neovestor.gitbook.io/neovestor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neovestor.gitbook.io/neovestor/technology-stack/smart-contract-architecture.md).

# Smart Contract Architecture

## **Neovestor Smart Contract Architecture**

*Tokenizing Real-World Assets (RWAs) on Solana*

***

### **Core Programs**

#### **`neovestor_token` (SPL Token-2022 Extension)**

**Purpose**: Mint and manage tokenized RWAs (e.g., real estate, private credit).\
**Key Features**:

* **Transfer Hooks**: Enforce compliance checks (e.g., KYC/AML) before transfers.
* **Metadata**: Store RWA details (e.g., asset type, valuation, legal docs) using Token-2022 metadata extensions.
* **Mint Freeze Authority**: Pause token transfers during emergencies via DAO governance.

```rust
// Pseudocode (Anchor Framework)  
#[derive(Accounts)]  
pub struct MintRwa<'info> {  
    #[account(init, payer = authority, space = 8 + 64)]  
    pub rwa_mint: Account<'info, Mint>,  
    #[account(mut)]  
    pub authority: Signer<'info>,  
    pub token_program: Program<'info, Token2022>,  
    pub system_program: Program<'info, System>,  
}  
```

***

#### **`neovestor_compliance` (Custom Program)**

**Purpose**: Validate investor eligibility and enforce regulatory rules.\
**Key Features**:

* **KYC/AML Checks**: Integrate with Fractal ID or Circle’s API to verify identities.
* **Geoblocking**: Restrict transfers to/from OFAC-sanctioned regions.
* **Whitelists**: Allow only approved wallets to hold tokenized RWAs.

```rust
#[instruction(allowed_countries: Vec<String>)]  
pub fn enforce_kyc(ctx: Context<EnforceKyc>) -> Result<()> {  
    let country = get_investor_country(&ctx.accounts.investor.key())?;  
    require!(allowed_countries.contains(&country), NeovestorError::BlockedRegion);  
    Ok(())  
}  
```

***

#### **`neovestor_governance` (Custom DAO Program)**

**Purpose**: Manage protocol upgrades, fees, and asset onboarding via decentralized governance.\
**Key Features**:

* **Proposal System**: Stake $NEO tokens to propose changes (e.g., adjust reserve ratios).
* **Quadratic Voting**: Prevent whale dominance using vote weighting.
* **Time Locks**: Delay execution of critical proposals (e.g., 72 hours).

```rust
#[account]  
pub struct Proposal {  
    pub id: u64,  
    pub description: String,  
    pub votes_for: u64,  
    pub votes_against: u64,  
    pub executed: bool,  
}  
```

***

#### **`neovestor_liquidity` (SPL Token + Custom Logic)**

**Purpose**: Manage liquidity reserves and redemptions.\
**Key Features**:

* **Reserve Pool**: Automatically hold 10% of deposits in USDC for instant withdrawals.
* **Staking Vaults**: Allow users to stake RWA tokens for yield (e.g., 5% APY in USDC).
* **Oracle Pricing**: Fetch real-time RWA valuations via Pyth Network.

```rust
pub fn calculate_redemption(ctx: Context<CalculateRedemption>, amount: u64) -> Result<()> {  
    let nav = PythOracle::get_price(&ctx.accounts.rwa_mint)?;  
    let usdc_value = amount.checked_mul(nav).ok_or(NeovestorError::MathError)?;  
    ctx.accounts.investor.usdc_balance += usdc_value;  
    Ok(())  
}  
```

***

#### **`neovestor_vault` (Squads Multi-Sig Integration)**

**Purpose**: Securely manage treasury and asset collateral.\
**Key Features**:

* **Multi-Sig Approvals**: Require 3/5 signers for withdrawals (via Squads Protocol).
* **Collateralization**: Over-collateralize loans (125% LTV) to mitigate defaults.

```rust
// Squads-compatible instruction  
pub fn withdraw_from_vault(ctx: Context<WithdrawVault>, amount: u64) -> Result<()> {  
    require!(ctx.accounts.squad.has_quorum(3), NeovestorError::InsufficientApprovals);  
    // Transfer funds  
    Ok(())  
}  
```

***

### **Key Solana Native Integrations**

* **SPL Token-2022**:
  * Use [Token-2022](https://spl.solana.com/token-2022) for transfer hooks, metadata, and interest-bearing tokens.
* **BPF Loader**:
  * Deploy upgradeable programs using Solana’s [BPF loader](https://docs.solana.com/developing/on-chain-programs/overview#berkeley-packet-filter-bpf).
* **Cross-Program Invocation (CPI)**:
  * Securely call SPL Token, Pyth Oracle, and Squads programs via CPI.

***

### **Security Practices**

* **Audits**:
  * Third-party audits for custom programs.
* **Anchor Framework**:
  * Use [Anchor](https://www.anchor-lang.com/) for Rust-based safety (type-safe accounts, input validation).
* **Transfer Hooks**:
  * Enforce compliance checks via Token-2022’s [transfer-hook interface](https://spl.solana.com/token-2022/extensions#transfer-hook).

***

### **Example Workflow: Tokenizing Real Estate**

1. **Asset Onboarding**:
   * DAO approves a new real estate asset via `neovestor_governance`.
2. **Mint Tokens**:
   * `neovestor_token` mints 1M tokens representing 10% ownership of a $50M property.
3. **Investor Purchase**:
   * User deposits USDC, passes `neovestor_compliance` checks, and receives tokens.
4. **Income Distribution**:
   * Rental income converted to USDC and distributed via `neovestor_liquidity`.
5. **Redemption**:
   * Investor burns tokens to redeem USDC from `neovestor_vault`.

***

### **Future Upgrades**

* **Cross-Chain RWAs**:
  * Use [Wormhole](https://wormhole.com/) to bridge assets to Ethereum/Polygon.
* **Dynamic NFTs**:
  * Represent asset ownership tiers via [Metaplex](https://www.metaplex.com/).

***

This architecture leverages Solana’s speed, low costs, and native token standards to deliver a compliant, scalable platform for institutional RWAs. For implementation guidance, refer to the [Solana Program Library](https://spl.solana.com/) and [Anchor Documentation](https://www.anchor-lang.com/docs).


---

# 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://neovestor.gitbook.io/neovestor/technology-stack/smart-contract-architecture.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.
