# Oracle

## Initialization

### constructor

<pre class="language-solidity"><code class="lang-solidity"><strong>constructor(address to)
</strong></code></pre>

#### Description

The constructor initializes the smart contract and sets the default roles. It also transfers ownership to the specified address and calculates the domain separator for EIP-712 signatures.

#### Parameters

| Name | Type      | Description                                                                               |
| ---- | --------- | ----------------------------------------------------------------------------------------- |
| to   | `address` | The address to which ownership of the contract will be transferred during initialization. |

## Write Methods

### updateObservation

```solidity
function updateObservation(
    uint144 value, 
    address[] calldata signers, 
    uint256[] calldata deadline,
    uint8[] calldata v, 
    bytes32[] calldata r, 
    bytes32[] calldata s
) external
```

#### **Description**

The `updateObservation` function is used to update the Oracle price if the following conditions are satisfied

* All signers must reach a consensus and produce a signed message containing the same price observation
* Each signed message must be created by a different signer
* Each signed message must have a deadline not already passed
* The number of signers is equal to or greater than the signer threshold
* The cooldown period has elapsed since the last update
* The percentage change between the old and new price observation is within an allowed delta

#### **Parameters**

| Name     | Type        | Description                                                           |
| -------- | ----------- | --------------------------------------------------------------------- |
| value    | `uint144`   | The new observation value to be updated                               |
| signers  | `address[]` | An array of addresses representing the signers involved in the update |
| deadline | `uint256[]` | An array of deadlines corresponding to each signatures                |
| v        | uint8\[]    | An array of the 'v' components of the ECDSA signatures                |
| r        | bytes32\[]  | An array of the 'r' components of the ECDSA signatures                |
| s        | bytes32\[]  | An array of the s' components of the ECDSA signatures                 |

#### **Emits**

[LogUpdateObservation](#logupdateobservation)

### freeze

```solidity
function freeze() external onlyOperators
```

#### **Description**

The `freeze` function is an external function that allows designated operators to freeze the contract in case of emergency.

#### **Emits**

[LogFrozenChanged](#logfrozenchanged)

### unfreeze

```solidity
function unfreeze() external onlyOwner
```

#### **Description**

The `unfreeze`function is an external function that allows the contract owner operators to unfreeze the contract to resume normal operativity.

#### Emits

[LogFrozenChanged](#logfrozenchanged)

### setMaximumDeltaPercentage

<pre class="language-solidity"><code class="lang-solidity">function setMaximumDeltaPercentage(
<strong>    uint32 maximumDeltaPercentage
</strong>) external onlyOwner
</code></pre>

#### Description

The `setMaximumDeltaPercentage` function is an external function that allows the owner of the contract to set the maximum allowed delta percentage for updates to the price observation.

#### Parameters

<table><thead><tr><th width="262">Name</th><th width="213">Type</th><th>Description</th></tr></thead><tbody><tr><td>maximumDeltaPercentage</td><td><code>uint32</code></td><td>The new maximum allowed delta percentage for updates</td></tr></tbody></table>

#### Emits

[LogMaxDeltaPercentageChanged](#logmaxdeltapercentagechanged)

### setThreshold

```solidity
function setThreshold(uint8 threshold) external onlyOwner
```

#### Description

The `setThreshold` function is an external function that allows the owner of the contract to set the minimum required number of signers for updates to the observation state.

#### Parameters

<table><thead><tr><th width="262">Name</th><th width="213">Type</th><th>Description</th></tr></thead><tbody><tr><td>theshold</td><td><code>uint8</code></td><td>The new minimum required number of signers</td></tr></tbody></table>

#### Emit

[LogSignerThresholdChanged](#logsignerthresholdchanged)

## View Methods

### PRECISION

```solidity
uint256 public constant PRECISION
```

#### Description

The precision used by the contract to handle the observation value

### HEARTBEAT

```solidity
uint256 public constant HEARTBEAT
```

#### Description

The number of seconds the latest price observation is considered valid and up to date

### get

```solidity
function get(bytes memory) public view override returns (bool, uint256)
```

#### Description

The `get` function is a public view function that allows external callers to retrieve information about the current observation state stored in the contract. It returns a boolean indicating the validity of the observation and the actual observation value.

#### Parameters

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Description</th></tr></thead><tbody><tr><td>*</td><td><code>bytes</code></td><td>The function does not take any input parameters</td></tr></tbody></table>

#### Returns

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Description</th></tr></thead><tbody><tr><td>isValid</td><td><code>bool</code></td><td>If true the observation has been updated within <a href="#heartbeat">HEARTBEAT </a>seconds</td></tr><tr><td>observation</td><td><code>uint256</code></td><td>Latest price observation</td></tr></tbody></table>

## Events

### LogUpdateObservation

<pre class="language-solidity"><code class="lang-solidity"><strong>event LogUpdateObservation(
</strong>    uint256 timestamp,
    uint144 observation
)
</code></pre>

#### Parameters

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Index?</th></tr></thead><tbody><tr><td>timestamp</td><td><code>uint256</code></td><td>No</td></tr><tr><td>observation</td><td><code>uint144</code></td><td>No</td></tr></tbody></table>

### LogFrozenChanged

```solidity
event LogFrozenChanged(
    uint256 timestamp,
    uint8 frozen
)
```

#### Parameters

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Index?</th></tr></thead><tbody><tr><td>timestamp</td><td><code>uint256</code></td><td>No</td></tr><tr><td>frozen</td><td><code>uint8</code></td><td>No</td></tr></tbody></table>

### LogMaxDeltaPercentageChanged

```solidity
event LogMaxDeltaPercentageChanged(
  uint256 timestamp,
  uint32 maxDeltaPercentage
)
```

#### Parameters

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Index?</th></tr></thead><tbody><tr><td>timestamp</td><td><code>uint256</code></td><td>No</td></tr><tr><td>maxDeltaPercentage</td><td><code>uint32</code></td><td>No</td></tr></tbody></table>

### LogSignerThresholdChanged

<pre class="language-solidity"><code class="lang-solidity"><strong>event LogSignerThresholdChanged(
</strong>    uint256 timestamp, 
    uint8 signerThreshold
)
</code></pre>

#### Parameters

<table><thead><tr><th>Name</th><th width="306">Type</th><th>Index?</th></tr></thead><tbody><tr><td>timestamp</td><td><code>uint256</code></td><td>No</td></tr><tr><td>signerThreshold</td><td><code>uint8</code></td><td>No</td></tr></tbody></table>
