The NNS dapp displays the USD value of the total amount of ICP locked in neurons.
It gets this information from the TVL canister but we want to move this functionality to the nns-dapp canister and remove the TVL canister.
There are 2 inputs to this data:
The amount of ICP locked in neurons
The price of ICP in USD.
We plan to periodically load both values and cache them in the canister state. When the user requests the TVL, it will be computed from the currently cached state.
In this PR we only add a function which can load the current price of ICP in USD into the nns-dapp state.
The function is not yet called, and the state is not yet persisted in this PR.
Changes
Add usd_per_icp_e8s and exchange_rate_timestamp_sec fields to the TvlState type. The timestamp is necessary to offer the same interface from the nns-dapp that the TVL canister offers.
Add code to call the get_exchange_rate method on the exchange rate canister, including an implementation which can be controlled for testing.
Add a test implementation of the time function which gives the current time.
Add update_exchange_rate which calls the exchange rate canister to ask for the ICP price of 5 minutes ago and stores it in the nns-dapp canister state, together with the time at which exchange rate was valid.
Tests
Added unit tests for the success and error cases.
Manually tested the feature end to end in a branch which has all the other changes.
Todos
[ ] Add entry to changelog (if necessary).
Will add when the code is functional.
Motivation
The NNS dapp displays the USD value of the total amount of ICP locked in neurons. It gets this information from the TVL canister but we want to move this functionality to the nns-dapp canister and remove the TVL canister.
There are 2 inputs to this data:
The amount of ICP locked in neurons The price of ICP in USD. We plan to periodically load both values and cache them in the canister state. When the user requests the TVL, it will be computed from the currently cached state.
In this PR we only add a function which can load the current price of ICP in USD into the nns-dapp state. The function is not yet called, and the state is not yet persisted in this PR.
Changes
usd_per_icp_e8s
andexchange_rate_timestamp_sec
fields to theTvlState
type. The timestamp is necessary to offer the same interface from the nns-dapp that the TVL canister offers.get_exchange_rate
method on the exchange rate canister, including an implementation which can be controlled for testing.time
function which gives the current time.update_exchange_rate
which calls the exchange rate canister to ask for the ICP price of 5 minutes ago and stores it in the nns-dapp canister state, together with the time at which exchange rate was valid.Tests
Todos