# How it works

### Introduction

NewEra Finance provides a non-custodial investment platform that allows users to automatically invest in a diversified portfolio of Real World Assets (RWAs). The platform leverages Uniswap V4 Hooks, TWAMM (Time-Weighted Average Market Making) and price oracle to enable seamless, automated investments with Dollar Cost Averaging (DCA) and oracle-based limit orders.

### Key Features

* **Automated DCA**: Schedule regular investments into RWA tokens
* **Smart Limit Orders**: Optimize trade execution using oracle-based prices
* **Multi-Token Selection**: Invest in multiple RWAs simultaneously
* **Full Asset Control**: Non-custodial ownership
* **Global Access**: Fractionalized RWAs available worldwide

### How It Works: Technical Deep Dive

#### TWAMM Implementation for DCA

NewEra Finance implements Dollar Cost Averaging (DCA) through TWAMM (Time-Weighted Average Market Making) technology built on Uniswap v4 hooks. This system breaks down large orders into smaller pieces that execute over time, reducing price impact and protecting against frontrunning MEV (Miner Extractable Value).

**Core TWAMM Mechanics**

The TWAMM implementation in NewEra Finance operates at the protocol level through the following mechanism:

1. **Order Initialization**:
   * When a user creates a DCA order, they specify:
     * Total amount to invest
     * Target RWA tokens
     * Expiry Period (time period for the order to execute)
   * The system calculates the per-block execution amount by dividing the total investment by the number of blocks in the specified expiry period.
2. **Block-Level Execution**:
   * TWAMM orders are guaranteed to be the first pool action in each block
   * The system maintains an internal accounting of all active orders
   * For each block where TWAMM orders exist:
     * The hook checks for pending orders
     * Executes proportional swaps based on time elapsed
     * Updates order balances
3. **Execution Priority**:
   * TWAMM executions happen before any other pool actions (swaps or LP adjustments)
   * This priority placement provides protection against frontrunning
   * The sequential execution follows this pattern:

     ```
     For each block:  1. Execute all pending TWAMM orders  2. Process regular user swaps  3. Process LP position adjustments
     ```
4. **Order Settlement**:
   * Orders continue executing until:
     * The specified duration expires
     * All allocated funds are exhausted
   * Users can claim their tokens at any time after execution
   * The hook manages virtual orders that are settled on-chain when interacted with

#### Auto-Limit Order Engine with Oracle Integration

The Auto-Limit Order functionality in NewEra Finance integrates with oracle-based pricing to ensure optimal execution even in low-liquidity RWA markets.

**Price Determination Logic**

```
If pool_price ≤ oracle_price + user_tolerance:
    Execute swap immediately at market price
Else if pool_price > oracle_price + user_tolerance:
    Create limit order at price = oracle_price + user_tolerance
```

**Oracle Integration**

The system connects to a price oracle to retrieve trusted RWA pricing, which represents the actual issuance/redemption price of the underlying asset. The Tolerance parameter defines the premium the user is prepared to pay over the underlying asset value. This concept is similar to slippage. Users can set their tolerance level prior to the trade execution. The higher the tolerance, the faster the order is filled, as the position becomes more attractive for arbitrage.&#x20;

Arbitrageurs can:

1. Issue new RWA tokens at the redemption price
2. Fill the limit orders at oracle\_price + tolerance
3. Capture the spread between issuance cost and limit order price

This mechanism ensures liquidity even in thin markets by aligning with the real economic value of the RWAs.

#### Execution Flow

The complete execution flow combines both TWAMM and Auto-Limit Order functionality:

1. User submits order parameters (amount, tokens, expiration period, tolerance)
2. System evaluates market conditions:
   * If immediate execution is favorable (within tolerance):
     * Order is converted to a TWAMM order
     * Execution begins on the next block
   * If prices exceed tolerance:
     * Limit orders are placed at oracle price + tolerance
     * Filled by arbitrageurs
3. TWAMM execution continues until duration completes
4. User claims resulting tokens

#### Order Lifecycle Management

NewEra's Smart Hook manages the complete lifecycle of orders through specialized functions:

**TWAMM Order Functions**

* `submitOrder()`: Creates a new TWAMM order with specified parameters
* `updateOrder()`: Modifies an existing order's parameters (amount, duration)
* `executeTWAMMOrders()`: Processes all active orders since last execution
* `claimTokens()`: Allows users to retrieve proceeds from executed orders

**Limit Order Functions**

* `place()`: Creates new limit orders with oracle price + tolerance
* `kill()`: Cancels existing orders and returns funds
* `withdraw()`: Claims proceeds from filled orders
* `_fillEpoch()`: Internal function to process orders when conditions are met

### Use Cases

#### Individual Investors

* Regular investments into diversified RWA portfolios
* Setting up "set and forget" investment strategies with DCA
* Optimizing entry points with Auto-Limit Order's tolerance

#### DAOs and Treasury Management

* Converting large treasury holdings gradually
* Diversifying into RWAs with minimal price impact
* Automated treasury balancing

#### For Low-Liquidity Trading

* Ensuring execution at fair prices
* Creating liquidity through the oracle-based limit orders
* Enabling investment in assets that would otherwise be difficult to acquire

<figure><img src="/files/lQgugINArOlmPQtPGjiI" alt=""><figcaption></figcaption></figure>


---

# 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.newera.finance/newera-products/how-it-works.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.
