Skip to content

Commit

Permalink
Merge pull request #2936 from dfinity/add-rosetta-refs
Browse files Browse the repository at this point in the history
Add Rosetta references
  • Loading branch information
jessiemongeon1 authored May 17, 2024
2 parents c6d67ed + d68bb2a commit 29e064b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
26 changes: 20 additions & 6 deletions docs/developer-docs/daos/nns/neuron-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To keep up to date with new NNS release proposals from DFINITY, you can subscrib

## Neuron attributes
Before explaining how to modify a neuron, it is important to understand the most important parts of a neuron.
Every user can stake ICP utility tokens into a neuron and pariticipate in the NNS DAO with this neuron.
Every user can stake ICP utility tokens into a neuron and participate in the NNS DAO with this neuron.

* **Neuron ID**: Each neuron has an identity selected by NNS governance at neuron creation.
* **Account**: Each neuron has an associated account on the ICP ledger where the locked ICP balance resides. This account is owned by the NNS governance canister and therefore a user cannot move staked tokens.
Expand All @@ -30,7 +30,7 @@ Every user can stake ICP utility tokens into a neuron and pariticipate in the NN
* A neuron can be _dissolving_ which means that the timer is decreasing the neuron's dissolve delay as time passes.
* Once the timer has counted down, a neuron is _dissolved_ and the ICP tokens can be unstaked again.
* **Age**: Every non-dissolving neuron has an age, which denotes how long it has been in the non-dissolving state.
A neuron's voting power increases as its age increases. A neuron's voting power also increases if its controller increases its dissolv delay.
A neuron's voting power increases as its age increases. A neuron's voting power also increases if its controller increases its dissolve delay.

* **Maturity**: When neurons vote, over time the NNS increases their maturity to reward them. Maturity can be converted into ICP by spawning (see below).

Expand All @@ -52,6 +52,7 @@ type ListNeuronsResponse = record {
};
```
By using this API, a user can request information about a list of neurons.

The user can define which neurons to get information from by defining a list of neuron IDs in the argument `neuron_ids`.
In addition, if the argument `include_neurons_readable_by_caller` is set to true, the neurons who the user is authorized to read are also included (i.e., the neurons for which the user is a controller or hot key).

Expand All @@ -68,6 +69,8 @@ type ManageNeuron = record {
};
```

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/staking/) for this workflow.

### Creating a neuron and topping it up
Staking ICP utility tokens in a neuron involves three steps:
1. Compute the neuron's address on the ledger, where the staked tokens will be held. This corresponds to a subaccount of the NNS governance canister.
Expand All @@ -87,7 +90,7 @@ b) Computed the subaccount based on the two inputs from (a). View for example th
c) Compute the final account identifier on the ledger (that gives you the address) using the computed subaccount from (b) and the principal ID of the NNS governance canister. View for example the method [`neuron_subaccount`](https://github.com/dfinity/ic/blob/master/rs/nns/governance/src/governance.rs) which computes the account based on a given subaccount and with the NNS governance principal ID `GOVERNANCE_CANISTER_ID`.


For the above steps, make sure you are using an up-to-date version of this code in your application.
For the above steps, make sure you are using an up-to-date version of this code in your application.

:::info
It is of utmost importance to ensure that the address is computed correctly in the first step and remembered so that it can be reused in the second step.
Expand Down Expand Up @@ -148,6 +151,7 @@ When `ClaimOrRefreshNeuronFromAccount` is used, the NNS governance canister will

_Required permissions:_ Anyone can make this call and top up a neuron, even if they do not have any permissions on the neuron. No matter who makes the call to the governance canister, its controller is set by the arguments as mentioned above.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/staking/) for this workflow.

### Managing permissions of a neuron
Every neuron has a controller that cannot be changed and may have hot keys. Hot keys are defined by a list of principal ID and can be used to perform actions with limited privileges, namely voting and following.
Expand All @@ -172,6 +176,8 @@ For adding a hot key, the principal `new_hot_key` to add needs to be provided an
_Required permissions:_
Only a neuron's controller can add and remove hot keys.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/staking/) for this workflow.


### Modifying a neuron's state
Recall from the section _Neuron attributes_, that a neuron has a dissolve delay and can be non-dissolving, dissolving, or dissolved.
Expand All @@ -192,7 +198,7 @@ type IncreaseDissolveDelay = record {
type SetDissolveTimestamp = record { dissolve_timestamp_seconds : nat64 };
```

To move a neuron from non-dissovling into dissovling state, and start the timer, use `StartDissolving`. No additional argument are required.
To move a neuron from non-dissolving into dissolving state, and start the timer, use `StartDissolving`. No additional argument are required.

To move a neuron from dissolving into non-dissolving state, and stop the timer at the dissolve state that the neuron has, use `StopDissolving`.

Expand All @@ -207,6 +213,8 @@ In both cases, the dissolve delay can only be increased but never decreased.
_Required permissions:_
Only a neuron's controller can start or stop dissolving a neuron or increase its dissolve delay.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/staking/) for this workflow.


### Spawning a neuron's rewards
When a neuron's maturity has risen above a threshold, one can spawn a portion of the maturity. In a first step, this creates a new neuron in a special spawning state containing the spawned maturity. After 7 days, the maturity is replaced with newly minted ICP, taking some [maturity modulation function](https://wiki.internetcomputer.org/wiki/Maturity_modulation#:~:text=The%20maturity%20modulation%20function%20introduces,NNS%20neurons%20and%20SNS%20neurons.) into account. In the end, the new neuron will be dissolved and have these ICP as stake - which can then be disbursed to any account.
Expand All @@ -220,7 +228,7 @@ type Spawn = record {
nonce : opt nat64;
};
```
Specify by `perpercentage_to_spawn` the portion of the maturity that should be spawn into a neuron in percentage. This should be a value between 1 and 100 (inclusive).
Specify by `percentage_to_spawn` the portion of the maturity that should be spawn into a neuron in percentage. This should be a value between 1 and 100 (inclusive).
If the spawned neurons should have a different controller than the parent neuron (from which you spawn the maturity), you can optionally define a different controlling principal by `new_controller`. Otherwise, the spawned neuron will have the same controller as the parent neuron.
Similarly to claiming a neuron (see above), you need to specify the new neuron's ledger address and choose a nonce for this in the last argument `nonce`.
Based on this nonce and the controlling principal, the neuron's address is uniquely defined (see section _Compute the neuron's address_).
Expand All @@ -229,6 +237,7 @@ If no nonce is provided, the governance canister chooses a random one.
_Required permissions:_
Only a neuron's controller can spawn maturity from a neuron.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/staking/) for this workflow.



Expand Down Expand Up @@ -278,14 +287,16 @@ The `vote` represents if the neuron should adopt or reject the proposal.
As can be found [here](https://github.com/dfinity/ic/blob/720c78843f20246bf4e5c15f703923bd316c19de/rs/nns/governance/proto/ic_nns_governance/pb/v1/governance.proto#L427), 1 corresponds to a yes-vote and hence to adopt the proposal and 2 corresponds to a no-vote and thus to reject the proposal.
`proposal` is the proposal ID of the proposal that the neuron votes on.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/voting/) for this workflow.

**Set a neuron's following**

In case that a neuron's owner lacks the time or expertise to vote on some proposals, a neuron can be configured to vote automatically by following other neurons on a topic-by-topic basis.
For any valid topic, a list of followees can be specified, and the neuron will follow the vote of a majority of the followers on a proposal with a type belonging to that topic. If a null topic is specified, this acts as a catch-all that enables the neuron to follow the vote of followees for all topics where no explicit rule has been specified.
There are two topics that are excluded from the catch-all: `Governance` and `SNS & Neuron's Fund`.

:::info
It is important to understand that a neuron's vote is only cast if the majority of the follwed neurons agree on a decision. Find [here](/docs/current/developer-docs/daos/nns/nns-app-quickstart#neuron-following) more information and examples regarding the following-rules.
It is important to understand that a neuron's vote is only cast if the majority of the followed neurons agree on a decision. Find [here](/docs/current/developer-docs/daos/nns/nns-app-quickstart#neuron-following) more information and examples regarding the following-rules.

:::

Expand All @@ -304,6 +315,9 @@ The second argument `followees` defines a list of neuron IDs whose decision will
_Required permissions:_
Voting and setting following can be done by a neuron's controller or a neuron's hot key.

You can also use the [ICP Rosetta API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/voting/) for this workflow.


### Splitting a neuron
A neuron can be split in two neurons, for example to set different dissolve delays.
A user can choose how much of the neuron's stake should be split into a new neuron.
Expand Down
6 changes: 6 additions & 0 deletions docs/developer-docs/defi/icp-tokens/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ The ICP token differs from Bitcoin in the following ways:
- Rather than using proof of work, staked participant nodes use a variant of threshold BLS signatures to agree on a valid state of the chain.

- Any transaction can store an 8-byte memo — this memo field is used by the Rosetta API to store the nonce that distinguishes between transactions. However, other uses for the field are possible.

## ICP Rosetta implementation

- [ICP Rosetta data API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/data_api/)

- [ICP Rosetta construction API](/docs/current/developer-docs/defi/rosetta/icp_rosetta/construction_api/)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
keywords: [rosetta, icp, data api, rosetta api, defi]
---
Expand Down

0 comments on commit 29e064b

Please sign in to comment.