# Aggregator Contract

The Aggregator contract acts as a central hub for the platform's oracle system, gathering and processing price feed data provided by the Satellites.

The Aggregator contract's role encompasses the collection of data from Satellites, calculation of the median value, and the final submission of these aggregated price feeds to the Maven Finance system.&#x20;

With a focus on accuracy and timeliness, the Aggregator contract plays a critical part in maintaining the reliability and stability of Maven Finance's DeFi ecosystem.

### Oracle **Entrypoints**

#### updateData

`function updateData(oracleObservationsType oracleObservations, signaturesType signatures)`

Updates the aggregator contract with new data. Called by a randomly designated oracle

{% hint style="info" %}
Can be called only by an active Oracle in the Aggregator Contract
{% endhint %}

<table><thead><tr><th width="220">Param Name</th><th width="295">Type</th><th>Description</th></tr></thead><tbody><tr><td>oracleObservations</td><td>oracleObservationsType: <br>map (address oracleAddress,  oracleObservationSingleType oracleObservation)</td><td>Map of oracle addresses to their observations</td></tr><tr><td>oracleObservation</td><td>oracleObservationSingleType: <br>(nat data, nat epoch, nat round, address aggregatorAddress)</td><td>Observation of a single oracle</td></tr><tr><td>data</td><td>nat</td><td>Observation data </td></tr><tr><td>epoch</td><td>nat</td><td>Current epoch</td></tr><tr><td>round</td><td>nat</td><td>Current round</td></tr><tr><td>aggregatorAddress</td><td>address</td><td>Address of the aggregator contract for the observation data</td></tr><tr><td>signatures</td><td>signaturesType: <br>map(address oracleAddress, signature oracleSignature)</td><td>Map of oracle addresses to their signatures</td></tr><tr><td>oracleAddress</td><td>address</td><td>Oracle (Satellite) address</td></tr><tr><td>oracleSignature</td><td>signature</td><td>Signature of the Oracle (Satellite)</td></tr></tbody></table>

#### withdrawRewardMvrk

`function withdrawRewardXvrk(address oracleAddress)`

Withdraws any MVRK rewards that the oracle has from the aggregator contract

{% hint style="info" %}
Can be called only by an active Oracle in the Aggregator Contract
{% endhint %}

| Param Name    | Type    | Description                                |
| ------------- | ------- | ------------------------------------------ |
| oracleAddress | address | The address of the oracle claiming rewards |

#### withdrawRewardStakedMvn

`function withdrawRewardStakedMvn(address oracleAddress)`

Withdraws any staked MVN rewards that the oracle has from the aggregator contract

{% hint style="info" %}
Can be called only by an active Oracle in the Aggregator Contract
{% endhint %}

| Param Name    | Type    | Description                                |
| ------------- | ------- | ------------------------------------------ |
| oracleAddress | address | The address of the oracle claiming rewards |

### Admin Oracle **Entrypoints**

#### addOracle

`function addOracle(address oracleAddress)`

Adds an oracle to the aggregator contract

{% hint style="info" %}
Can be called only by the admin or the governance satellite contract address
{% endhint %}

| Param Name    | Type    | Description                               |
| ------------- | ------- | ----------------------------------------- |
| oracleAddress | address | The address of the new oracle to be added |

#### updateOracle

`function updateOracle()`

Updates an oracle information such as the oraclePublicKey and oraclePeerId on the aggregator contract by fetching its data from the delegation contract

{% hint style="info" %}
Can be called only by a registered oracle on this aggregator contract
{% endhint %}

#### removeOracle

`function removeOracle(address oracleAddress)`

Removes an oracle from the aggregator contract

{% hint style="info" %}
Can be called only by the admin or the governance satellite contract address
{% endhint %}

| Param Name    | Type    | Description                             |
| ------------- | ------- | --------------------------------------- |
| oracleAddress | address | The address of the oracle to be removed |

### Housekeeping **Entrypoints**

#### setAdmin

`function setAdmin(address newAdminAddress)`

Sets a new admin address for the contract

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

| Param Name      | Type    | Description                  |
| --------------- | ------- | ---------------------------- |
| newAdminAddress | address | The address of the new admin |

#### setGovernance

`function setGovernance(address newGovernanceAddress)`

Sets a new governance contract address

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

| Param Name           | Type    | Description                                |
| -------------------- | ------- | ------------------------------------------ |
| newGovernanceAddress | address | The address of the new governance contract |

#### setName

`function setName(string updatedContractName)`

Sets a new name for the contract, and aggregator reference in the governance satellite contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="235.33333333333331">Param Name</th><th width="177">Type</th><th>Description</th></tr></thead><tbody><tr><td>updatedContractName</td><td>string</td><td>The new reference name for this aggregator contract, subject to the max length as specified in the aggregator factory config aggregatorNameMaxLength variable</td></tr></tbody></table>

#### updateMetadata

`function updateMetadata(string key, bytes hash)`

Replace the hash of the contract metadata based on the provided key

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name | Type   | Description                                  |
| ---------- | ------ | -------------------------------------------- |
| key        | string | The key in the metadata bigmap to be updated |
| hash       | bytes  | The hash of the metadata key                 |

#### updateConfig

`function updateConfig(nat newConfigValue, aggregatorConfigActionType aggregatorConfigAction)`

Updates the config variables on the Aggregator Contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="236">Param Name</th><th width="364.3333333333333">Type</th><th>Description</th></tr></thead><tbody><tr><td>newConfigValue</td><td>nat</td><td>The new value of the config parameter</td></tr><tr><td>aggregatorConfigAction</td><td>aggregatorConfigActionType: <br>| unit ConfigDecimals<br>| unit ConfigAlphaPercentPerThousand<br>| unit ConfigPercentOracleThreshold<br>| unit ConfigHeartbeatSeconds<br>| unit ConfigRewardAmountStakedMvn<br>| unit ConfigRewardAmountMvrk</td><td>The variant config variable to be updated</td></tr></tbody></table>

#### updateWhitelistContracts

`function updateWhitelistContracts(address whitelistContractAddress, updateType update)`

Add, update or remove a whitelist contract in the whitelistContracts map in the storage

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name               | Type                | Description                                                          |                 |                                                                                                                 |
| ------------------------ | ------------------- | -------------------------------------------------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------- |
| whitelistContractAddress | address             | The contract address to be updated in the whitelist contracts bigmap |                 |                                                                                                                 |
| updateType               | <p>updateType: <br> | unit Update  <br>                                                    | unit Remove</p> | Specifies whether the whitelistContractAddress should be updated or removed from the whitelist contracts bigmap |

#### updateGeneralContracts

`function updateGeneralContracts(string generalContractName, address generalContractAddress, updateType update)`

Add, update or remove a general contract in the generalContracts map in the storage

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name             | Type                | Description                                                                                                       |                 |                                                                                                             |
| ---------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------- |
| generalContractName    | string              | The identifier key to be set in the general contracts bigmap which will be the general contract name in camelcase |                 |                                                                                                             |
| generalContractAddress | address             | The contract address to be updated in the general contracts bigmap                                                |                 |                                                                                                             |
| updateType             | <p>updateType: <br> | unit Update <br>                                                                                                  | unit Remove</p> | Specifies whether the generalContractAddress should be updated or removed from the general contracts bigmap |

#### mistakenTransfer

`function mistakenTransfer(transferActionType transferList)`

Transfers any mav or token that may have mistakenly been sent to this contract

{% hint style="info" %}
Can be called only by the admin or the governance satellite contract
{% endhint %}

<table><thead><tr><th width="170.33333333333331">Param Name</th><th width="334">Type</th><th>Description</th></tr></thead><tbody><tr><td>transferList</td><td><p>transferActionType:</p><p>list(address to_, <br>nat tokenAmount, <br>token tokenType)</p></td><td>A list of transfers of tokens to recipients</td></tr><tr><td>to_</td><td>address</td><td>The recipient of the mistaken transfer</td></tr><tr><td>tokenAmount</td><td>nat</td><td>The amount of tokens to be transferred</td></tr><tr><td>token</td><td>tokenType: <br>| unit Mav <br>| (address tokenContractAddress) Fa12 | (address tokenContractAddress, nat tokenId)  Fa2</td><td>The token type of the token to be transferred, corresponding to either Mav, MRC-10, or MRC-20</td></tr></tbody></table>

#### setLambda

`function setLambda(string lambdaName, bytes func_bytes)`

Sets a lambda in the contract with the given bytes and name

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>lambdaName</td><td>string</td><td>The name of the lambda to be set</td></tr><tr><td>func_bytes</td><td>bytes</td><td>The data of the lambda in Michelson bytes format</td></tr></tbody></table>

### BreakGlass **Entrypoints**

#### pauseAll

`function pauseAll()`

Pauses all entrypoints in the contract.&#x20;

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

#### unpauseAll

`function unpauseAll()`

Unpauses all entrypoints in the contract.&#x20;

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

#### togglePauseEntrypoint

`function togglePauseEntrypoint(aggregatorPausableEntrypointType targetEntrypoint, unit empty)`

Toggles the pausing of a specific entrypoint in the contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="190.33333333333331">Param Name</th><th width="315">Type</th><th>Description</th></tr></thead><tbody><tr><td>targetEntrypoint</td><td>aggregatorPausableEntrypointType: <br>| bool UpdateData <br>| bool WithdrawRewardMvrk<br>| bool WithdrawRewardStakedMvn </td><td>The target entrypoint to be paused, and its corresponding pause boolean. If the boolean is set to True, the entrypoint will be paused. </td></tr><tr><td>empty</td><td>unit</td><td>A null param used to prettify interactions with this entrypoint on blockchain explorers such as better-call-dev</td></tr></tbody></table>

### View Methods

#### getAdmin

`function getAdmin()`

Returns the contract admin

#### getGovernanceAddress

`function getGovernanceAddress()`

Returns the contract governance address

#### getName

`function getName()`

Returns the contract name

#### getConfig

`function getConfig()`

Returns the contract configuration parameters

#### getBreakGlassConfig

`function getBreakGlassConfig()`

Returns the break glass config parameters (which shows the pause status of entrypoints)

#### getWhitelistContractOpt

`function getWhitelistContractOpt(address contractAddress)`

Returns unit if contract address is whitelisted, else returns none

#### getGeneralContractOpt

`function getGeneralContractOpt(string contractName)`

Returns the contract address if the contract name is found, else returns none

#### getOracleLedger

`function getOracleLedger()`

Returns the oracle ledger in the aggregator contract

#### getOracleOpt

`function getOracleOpt(address oracleAddress)`

Returns an oracle record if found, else returns none

#### getOracleRewardStakedMvnOpt

`function getOracleRewardStakedMvnOpt(address oracleAddress)`

Returns the staked MVN rewards of a given oracle address, else returns none

#### getOracleRewardMvrkOpt

`function getOracleRewardMvrkOpt(address oracleAddress)`

Returns the mvrk rewards of a given oracle address, else returns none

#### getLastCompletedData

`function getLastCompletedData()`

Returns the last completed data record on the aggregator contract

#### getDecimals

`function getDecimals()`

Returns the number of decimals used in the aggregator contract

#### getLambdaOpt

`function getLambdaOpt(string lambdaName)`

Returns a lambda in the contract for the given lambda name, else returns none


---

# 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.mavenfinance.io/smart-contracts/smart-contracts-overview/aggregator-contract.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.
