# Instrument Return Oracles

Oracles that feed in returns data of the underlying instrument serve a pivotal role in determining the [redemption](https://limitless.gitbook.io/ramm/prediction-market-and-amm-technical/redemption-and-valuing-longzcb-tokens)/issuance price of **`longZCB`** tokens. It is important that these data feeds are resistant to manipulations within a block (i.e flash loans to increase/decrease the price of **`longZCB`**) to prevent attacks and drainage.&#x20;

## Perpetual Instruments

### Last Oracle Rate

`lastRate` is the last recorded exchange rate between an instrument's underlying(i.e USDC) vs its shares. For perpetual instruments, the exchange rate between the instrument's shares and its underlying reflects the socialized profit & loss of the instrument.`lastOracleRate` could be manipulated over short time frames (such as via flash loans) to display a rate that does not reflect the true returns generated by the instrument at a particular time.&#x20;

These limitations make the `lastRate` insecure as a price oracle by which to [value](https://limitless.gitbook.io/ramm/prediction-market-and-amm-technical/redemption-and-valuing-longzcb-tokens) longZCB tokens. Given that RAMM allows users to issue/redeem longZCB at this valued price, we need to ensure that the exchange rate oracle used to value can't be manipulated.

As such, RAMM uses the lastOracleRate, a time linear interpolation of the lastRate and the lastOracleRate, to value longZCB tokens.&#x20;

```cpp
// How to compute lastOracleRate, which is the key input to the 
// longZCB valuations

timeDiff = block.timestamp - lastTime // time difference between 
timeDivWindow = timeDiff/(TIME_WINDOW)

// If time elapsed from last record is less than the constant parameter TIME_WINDOW,
// then lastOracleRate is an interpolation between last recorded exchange rate 
// and lastOracle rate
if(TIME_WINDOW>= timeDiff){
  lastOracleRate = lastRate * min(timeDivWindow , 1)
    + lastOracleRate * (TIME_WINDOW - timeDivWindow)/TIME_WINDOW
} 

// If time elapsed from last record is greater than the constant parameter TIME_WINDOW,
// then lastOracleRate is simply the last recorded exchange rate
else{
  lastOracleRate = lastRate;
}

```

## Fixed Instruments

For fixed term fixed rate instruments, **the balance of the instrument contract when they are resolved at maturity** determines the redemption price of **`longZCB`**/**`shortZCB`** tokens. These can't be manipulated via flash loans as the written logic requires the redemption price to be computed at least a block after the instrument has been resolved.&#x20;
