> For the complete documentation index, see [llms.txt](https://docs.gnoswap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gnoswap.io/contracts/gov/staker/delegation_manager.gno.md).

# delegation\_manager.gno

{% embed url="<https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno>" %}

## Types

### DelegationManager

```go
type DelegationManager struct
```

DelegationManager manages the mapping between users and their delegation IDs. It provides efficient lookup and management of user delegations organized by delegator and delegatee addresses.

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L9)

#### Methods

**AddDelegationID**

```go
func (dm *DelegationManager) AddDelegationID(
	delegator string,
	delegatee string,
	delegationID int64
)
```

AddDelegationID appends a delegation ID to the delegator-delegatee pair, skipping duplicates. The whole get-modify-set runs inside this domain method so the nested BPTree mutation never escapes the owning realm. Performing the lookup in one realm and the write in another (e.g. re-fetching the inner tree across a realm boundary and mutating it) would hit the cross-realm write guard for the persisted leaf slot.

#### Parameters

| Name           | Type   | Description                                              |
| -------------- | ------ | -------------------------------------------------------- |
| `delegator`    | string | delegator address string used to select the nested tree. |
| `delegatee`    | string | delegatee address string used as the nested-tree key.    |
| `delegationID` | int64  | delegation ID to append when it is not already present.  |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L114)

**GetDelegationIDs**

```go
func (dm *DelegationManager) GetDelegationIDs(
	delegator string,
	delegatee string
) ([]int64, bool)
```

GetDelegationIDs returns IDs recorded for one delegator/delegatee pair.

#### Parameters

| Name        | Type   | Description                                              |
| ----------- | ------ | -------------------------------------------------------- |
| `delegator` | string | delegator address string used to select the nested tree. |
| `delegatee` | string | delegatee address string used as the nested-tree key.    |

#### Return Values

| Name      | Type     | Description                                      |
| --------- | -------- | ------------------------------------------------ |
| `[]int64` | \[]int64 | delegation IDs stored for the pair.              |
| `bool`    | bool     | true when the pair exists with a valid ID slice. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L71)

**GetDelegatorDelegations**

```go
func (dm *DelegationManager) GetDelegatorDelegations(
	delegator string
) (*bptree.BPTree, bool)
```

GetDelegatorDelegations returns the delegatee tree for one delegator.

#### Parameters

| Name        | Type   | Description                                         |
| ----------- | ------ | --------------------------------------------------- |
| `delegator` | string | delegator address string used as the root-tree key. |

#### Return Values

| Name             | Type            | Description                                                       |
| ---------------- | --------------- | ----------------------------------------------------------------- |
| `*bptree.BPTree` | \*bptree.BPTree | delegatee-to-delegation-ID tree when present and correctly typed. |
| `bool`           | bool            | true when the delegator entry exists with the expected tree type. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L50)

**GetUserDelegations**

```go
func (dm *DelegationManager) GetUserDelegations() *bptree.BPTree
```

GetUserDelegations returns the entire user delegations tree.

#### Return Values

| Name             | Type            | Description                             |
| ---------------- | --------------- | --------------------------------------- |
| `*bptree.BPTree` | \*bptree.BPTree | tree keyed by delegator address string. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L30)

**RemoveDelegationID**

```go
func (dm *DelegationManager) RemoveDelegationID(
	delegator string,
	delegatee string,
	delegationID int64
)
```

RemoveDelegationID removes a delegation ID from the delegator-delegatee pair. Like AddDelegationID, the read-modify-write is kept inside this domain method. RemoveDelegationID removes one ID from a delegator/delegatee pair. Missing pairs and IDs are left unchanged.

#### Parameters

| Name           | Type   | Description                                              |
| -------------- | ------ | -------------------------------------------------------- |
| `delegator`    | string | delegator address string used to select the nested tree. |
| `delegatee`    | string | delegatee address string used as the nested-tree key.    |
| `delegationID` | int64  | delegation ID to remove when it is present.              |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L134)

**SetDelegationIDs**

```go
func (dm *DelegationManager) SetDelegationIDs(
	delegator string,
	delegatee string,
	ids []int64
)
```

SetDelegationIDs stores the complete ID slice for a delegator/delegatee pair. A missing delegator entry is initialized with a new nested tree.

#### Parameters

| Name        | Type     | Description                                                        |
| ----------- | -------- | ------------------------------------------------------------------ |
| `delegator` | string   | delegator address string used to select or create the nested tree. |
| `delegatee` | string   | delegatee address string used as the nested-tree key.              |
| `ids`       | \[]int64 | delegation IDs to store for the pair.                              |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L94)

**SetUserDelegations**

```go
func (dm *DelegationManager) SetUserDelegations(
	userDelegations *bptree.BPTree
)
```

SetUserDelegations replaces the root delegator-to-delegations tree.

#### Parameters

| Name              | Type            | Description                                                            |
| ----------------- | --------------- | ---------------------------------------------------------------------- |
| `userDelegations` | \*bptree.BPTree | tree keyed by delegator address string and containing delegatee trees. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L38)

#### Constructors

* `func NewDelegationManager() *DelegationManager` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/delegation_manager.gno#L20))
