# Delegable Actions

## Overview

Delegable Actions allow third-party contracts (plugins) to perform specific operations on behalf of users within the Curvance ecosystem. This delegation system offers a more flexible and powerful alternative to standard ERC20 approvals, enabling opportunities for automation, complex strategies, and improved user experiences.

Any Curvance contract that inherits from `PluginDelegable` can support delegate-triggered operations through functions that typically end with a for postfix (e.g., `borrowFor`, `withdrawFor`, `leverageFor`). This pattern ensures consistent delegate authorization checks across the protocol.

{% hint style="info" %}
For a full list of delegable actions, please check out our plugin guide here: [List of Delegable Actions](https://docs.curvance.com/cve/developer-docs/quick-start-guides/plugin-integration/list-of-delegable-actions)
{% endhint %}

The delegation system provides several security advantages over traditional approaches:

* **Granular control:** Users can grant and revoke specific action permissions to different addresses
* **Emergency revocation:** Users can revoke all delegations at once by incrementing their approval index
* **Time-lock protection:** Optional delegation lockdown with a cooldown period

Delegations exist across all Curvance contracts simultaneously, using the Central Registry to track and validate delegation permissions throughout the protocol.

***

## User Interaction Functions

### Delegation in PluginDelegable.sol

#### isDelegate()

**Description:** Determines whether a delegate address has permission to act on behalf of a specified user.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function isDelegate(address user, address delegate) public view returns (bool)
```

<table><thead><tr><th width="133.76669311523438">Type</th><th width="162.066650390625">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The address to check whether delegate has delegation permissions for.</td></tr><tr><td>address</td><td>delegate</td><td>The address to check delegation permissions of user.</td></tr></tbody></table>

**Return data:**

<table><thead><tr><th width="147.54998779296875">Type</th><th>Description</th></tr></thead><tbody><tr><td>bool</td><td>Returns true if delegate is authorized to act on behalf of user.</td></tr></tbody></table>

***

#### setDelegateApproval()

**Description**: Approves or restricts a delegate's authority to operate on the caller's behalf. This is the primary method for users to control their delegation permissions.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function setDelegateApproval(address delegate, bool isApproved) external
```

<table><thead><tr><th width="141.58334350585938">Type</th><th width="169.23333740234375">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>delegate</td><td>The address that will be approved or restricted from delegated actions.</td></tr><tr><td>bool</td><td>isApproved</td><td>Whether delegate is being approved (true) or restricted (false).</td></tr></tbody></table>

Events:

```solidity
event DelegateApproval(
    address indexed owner,
    address indexed delegate,
    uint256 approvalIndex,
    bool isApproved
);
```

***

#### getUserApprovalIndex()

**Description:** Retrieves a user's current approval index from the Central Registry. This index is incremented when a user wants to revoke all delegations.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function getUserApprovalIndex(address user) public view returns (uint256)
```

<table><thead><tr><th width="134.88336181640625">Type</th><th width="137.5">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The user to check delegated approval index for.</td></tr></tbody></table>

**Return data:**

<table><thead><tr><th width="130.41668701171875">Type</th><th width="148.433349609375">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The user to check delegated approval index for.</td></tr></tbody></table>

***

#### checkDelegationDisabled()

**Description:** Checks whether delegation is temporarily or permanently disabled for a specified user.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function checkDelegationDisabled(address user) public view returns (bool)
```

<table><thead><tr><th width="131.5333251953125">Type</th><th width="151.89996337890625">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The user to check delegation status for.</td></tr></tbody></table>

**Return data:**

<table><thead><tr><th width="143.08334350585938">Type</th><th>Description</th></tr></thead><tbody><tr><td>bool</td><td>Returns true if user has delegation disabled or if their cooldown period has not expired.</td></tr></tbody></table>

***

### Delegable Actions in ActionRegistry.sol

#### getUserApprovalIndex()

Description: Returns a user's approval index, which is used to authorize delegates across the entire protocol.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function getUserApprovalIndex(address user) external view returns (uint256)
```

<table><thead><tr><th width="131.5333251953125">Type</th><th width="121.75">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The user to check delegated approval index for.</td></tr></tbody></table>

**Return data:**

<table><thead><tr><th width="164.29998779296875">Type</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>Current approval index for the specified user.</td></tr></tbody></table>

***

#### incrementApprovalIndex()

**Description**: Increments a caller's approval index, immediately revoking all delegate permissions across all Curvance contracts.

**Contract:** CentralRegistry

**Function signature:**

```solidity
function incrementApprovalIndex() external
```

**Events:**

```solidity
event ApprovalIndexIncremented(address indexed user, uint256 newIndex);
```

***

#### checkDelegationDisabled()

**Description:** Determines whether a user has delegation disabled, either intentionally or due to a cooldown period.

**Function signature:**

```solidity
function checkDelegationDisabled(address user) external view returns (bool)
```

<table><thead><tr><th width="123.7166748046875">Type</th><th width="130.2166748046875">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>user</td><td>The user to check delegation status for.</td></tr></tbody></table>

**Return data:**

<table><thead><tr><th width="121.86666870117188">Type</th><th>Description</th></tr></thead><tbody><tr><td>bool</td><td>Returns true if user has delegation disabled or if their cooldown period has not expired.</td></tr></tbody></table>

***

#### setDelegable()

**Description:** Sets a caller's status for whether to allow new delegations or not. When re-enabling delegation, the user's configured cooldown period applies.

Function signature:

```solidity
function setDelegable(bool delegationDisabled) external
```

**Parameters:**

<table><thead><tr><th width="113.66665649414062">Type</th><th width="199.98333740234375">Name</th><th>Description</th></tr></thead><tbody><tr><td>bool</td><td>delegationDisabled</td><td>true to disable delegation, false to enable delegation (after cooldown).</td></tr></tbody></table>

**Events:**

```solidity
event DelegableStatusChanged(
    address indexed user,
    bool delegable,
    uint256 delegationEnabledTimestamp
);
```
