> For the complete documentation index, see [llms.txt](https://docs.mavenfinance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mavenfinance.io/smart-contracts/smart-contracts-overview/delegation-contract.md).

# Delegation Contract

Maven Finance's Delegation Contract: Powering Decentralized Representation

Functioning as the Satellites contract within the ecosystem, the Delegation contract plays a pivotal role in the execution of governance and oracle responsibilities.

The Delegation contract controls the management of Satellites, facilitating their registration and tracking their overall activities. Moreover, it handles the delegation of sMVN tokens from stakeholders to Satellites, establishing a direct link between the token holders and their chosen representative.&#x20;

By managing the delegation and actions of Satellites, the Delegation contract contributes to the transparent, democratic, and efficient operations within Maven Finance's decentralized platform.

### Delegation Entrypoints

#### delegateToSatellite

`function delegateToSatellite(address userAddress, address satelliteAddress)`

Delegates the staked MVN of a given user address to the satellite address

| Param Name       | Type    | Description                                              |
| ---------------- | ------- | -------------------------------------------------------- |
| userAddress      | address | The user address to be delegated                         |
| satelliteAddress | address | The satellite address that the user will be delegated to |

#### undelegateFromSatellite

`function undelegateFromSatellite(address userAddress)`

Undelegates the user from his satellite

| Param Name  | Type    | Description                                               |
| ----------- | ------- | --------------------------------------------------------- |
| userAddress | address | The user address to be undelegated from his/her satellite |

### Satellite Entrypoints

#### registerAsSatellite

`function registerAsSatellite(string name, string description, string image, string website, nat satelliteFee, option(key) oraclePublicKey, option(string) oraclePeerId)`

Registers the sender as a satellite with the given parameters

| Param Name      | Type           | Description                                                                                                                                                                      |
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name            | string         | The name of the satellite                                                                                                                                                        |
| description     | string         | The description of the satellite                                                                                                                                                 |
| image           | string         | The link to the image url of the satellite                                                                                                                                       |
| website         | string         | The link to the website of the satellite                                                                                                                                         |
| satelliteFee    | nat            | The fee which the satellite will collect from delegates when rewards are distributed                                                                                             |
| oraclePublicKey | option(key)    | An optional key if the satellite wishes to serve as an oracle providing data                                                                                                     |
| oraclePeerId    | option(string) | An optional string if the satellite wishes to serve as an oracle providing data - this string will serve as a reference to the satellite within the overall peer-to-peer network |

#### unregisterAsSatellite

`function unregisterAsSatellite(address satelliteAddress)`

Unregisters the sender as a satellite

| Param Name       | Type    | Description                                     |
| ---------------- | ------- | ----------------------------------------------- |
| satelliteAddress | address | The satellite address that wishes to unregister |

#### updateSatelliteRecord

`function registerAsSatellite(string name, string description, string image, string website, nat satelliteFee, option(key) oraclePublicKey, option(string) oraclePeerId)`

Updates a satellite's record with the given parameters

| Param Name      | Type           | Description                                                                                                                                                                      |
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name            | string         | The name of the satellite                                                                                                                                                        |
| description     | string         | The description of the satellite                                                                                                                                                 |
| image           | string         | The link to the image url of the satellite                                                                                                                                       |
| website         | string         | The link to the website of the satellite                                                                                                                                         |
| satelliteFee    | nat            | The fee which the satellite will collect from delegates when rewards are distributed                                                                                             |
| oraclePublicKey | option(key)    | An optional key if the satellite wishes to serve as an oracle providing data                                                                                                     |
| oraclePeerId    | option(string) | An optional string if the satellite wishes to serve as an oracle providing data - this string will serve as a reference to the satellite within the overall peer-to-peer network |

#### distributeReward

`function distributeReward(set(address) eligibleSatellites, nat totalStakedMvnReward)`

Distributes the given staked MVN reward equally among all the eligible satellites

{% hint style="info" %}
Can be called only by whitelisted addresses, specified by Maven Governance
{% endhint %}

| Param Name           | Type         | Description                                                                          |
| -------------------- | ------------ | ------------------------------------------------------------------------------------ |
| eligibleSatellites   | set(address) | The set of satellite addresses which will receive the staked MVN reward in this call |
| totalStakedMvnReward | nat          | The total staked MVN reward to be distributed                                        |

### 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 |

#### 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, delegationConfigActionType delegationConfigAction)`

Updates the config variables on the Delegation Contract

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

<table><thead><tr><th width="232">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>delegationConfigAction</td><td>delegationConfigActionType: <br>| unit ConfigMinimumStakedMvnBalance <br>| unit ConfigDelegationRatio<br>| unit ConfigMaxSatellites<br>| unit ConfigSatNameMaxLength<br>| unit ConfigSatDescMaxLength<br>| unit ConfigSatImageMaxLength<br>| unit ConfigSatWebsiteMaxLength</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="196.33333333333331">Param Name</th><th width="331">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) MRC-10 <br>| (address tokenContractAddress, nat tokenId)  MRC-20</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(delegationPausableEntrypointType 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="184.33333333333331">Param Name</th><th width="313">Type</th><th>Description</th></tr></thead><tbody><tr><td>targetEntrypoint</td><td>delegationPausableEntrypointType: <br>| bool DelegateToSatellite <br>| bool UndelegateFromSatellite <br>| bool RegisterAsSatellite <br>| bool UnregisterAsSatellite <br>| bool UpdateSatelliteRecord <br>| bool DistributeReward </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>

### Protected **Entrypoints**

#### onStakeChange

`function onStakeChange(set(address userAddress, nat referenceSMvnBalance) onStakeChangeSet)`

Registers a stake change event for the given users in the onStakeChange set

{% hint style="info" %}
Can be called only by the Doorman Contract
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>onStakeChangeSet</td><td>set(address userAddress, nat referenceSMvnBalance)</td><td>The set of user addresses and their reference staked MVN balance</td></tr><tr><td>userAddress</td><td>address</td><td>The address of a user whose staked balance has changed</td></tr><tr><td>referenceSMvnBalance</td><td>nat</td><td>The initial staked MVN balance of the user before any actions has been applied to it, which will be used as a reference</td></tr></tbody></table>

#### updateSatelliteStatus

`function updateSatelliteStatus(address satelliteAddress, string newStatus)`

Updates the given satellite with a new status

{% hint style="info" %}
Can be called only by the admin or by whitelisted addresses
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>satelliteAddress</td><td>address</td><td>The address of a satellite whose status has changed</td></tr><tr><td>newStatus</td><td>string</td><td>The updated status of a satellite. Valid strings are "ACTIVE", "BANNED", or "SUSPENDED"</td></tr></tbody></table>

### View Methods

#### getAdmin

`function getAdmin()`

Returns the contract admin

#### getGovernanceAddress

`function getGovernanceAddress()`

Returns the contract governance address

#### getConfig

`function getConfig()`

Returns the contract configuration parameters

#### 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

#### getBreakGlassConfig

`function getBreakGlassConfig()`

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

#### getDelegateOpt

`function getDelegateOpt(address delegateAddress)`

Returns the delegate record if it exists, else returns none

#### getSatelliteOpt

`function getSatelliteOpt(address satelliteAddress)`

Returns the satellite record if it exists, else returns none

#### getSatelliteRewardsOpt

`function getSatelliteRewardsOpt(address userAddress)`

Returns the satellite rewards record if it exists, else returns none

#### getLambdaOpt

`function getLambdaOpt(string lambdaName)`

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