---
# System prepended metadata

title: Injective Oracle Script

---

# Injective Oracle Script

## Objective

New Oracle Script specifications to:
- Return partial values for transactions that contain partial failures

## Oracle Script Input/Output
Example input
```rust 
struct Input {
    symbols: Vec<String>,
    minimum_source_count: u8,  // We can also hardcode this instead 
}
```

Example output
```rust
struct Response {
    symbol: String,    // Where symbol is the asset ticker/symbol
    response_code: u8,  // As shown in the response code section
    rate: u64,        // Where value is either the rate or 0 (for non-zero responses)
}

struct Output {
    responses: Vec<Response>
}
```

## Response Codes
```
0 = SUCCESS
1 = SYMBOL_NOT_SUPPORTED
2 = NOT_ENOUGH_SOURCES --> Too many data source returns non-zero exit codes
3 = TOO_MANY_OUTLIERS --> Too many outliers found
127 = UNKNOWN_ERROR
```

<!-- ## Outlier Detection

### Detection Method
Sample retrieved from the data sources are not known to be normally distributed, have a low observation and from experience, outliers tended to be extreme. As such, the modified Z-score method is a suitable method of obtaining outliers given from the data source results.

The modified Z-score can be calculated using:

$$M_i=\dfrac{0.6745(x_i-\widetilde{x})}{MAD}$$

Where $\widetilde{x}$ is the sample medium and $MAD$ is the **medium absolute deviation** which is defined by the formula:

$$MAD = median_i\{|x_i-\widetilde{x}|\}$$

Observations can be labeled as an outlier when $|M_i|>D$ where $D=3.5$ is recommended. This value, however, can be changed depending on how sensitive we'd like the outlier to be detected.

## Parameter Selection

To ensure the validity of the given results, the `minimum_source_count` should be determined based on the table below:

| n  | breakdown_point  | maximum_outliers  |
| -- | ---------------- | ----------------- |
| 1  | 0.00%            | 0                 |
| 2  | 0.00%            | 0                 |
| 3  | 33.33%           | 1                 |
| 4  | 25.00%           | 1                 |
| 5  | 40.00%           | 2                 |
| 6  | 33.33%           | 2                 |
| 7  | 42.86%           | 3                 |
| 8  | 37.50%           | 3                 |
| 9  | 44.44%           | 4                 |
| 10 | 40.00%           | 4                 |
| 11 | 45.45%           | 5                 |
| 12 | 41.67%           | 5                 |
| 13 | 46.15%           | 6                 |
| 14 | 42.86%           | 6                 |
| 15 | 46.67%           | 7                 |
| 16 | 43.75%           | 7                 |

Where $n$ is the minimum_source_count.

As the prior detection method for outliers only work below the breakdown point, it is recommended to use $outlier_{max}-1$ as the threshold to trigger `response_code=3` as pass that point, determining whether or not the median has been influenced by the outliers will not be possible. However, doing this means that the minimum amount of sources required for a specific asset must be $n\geq5$. This will improve significantly improve the reliability of the feed, however, at the possible cost of the amount of assets that can be listed. -->