Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning message to use DAppStaking v3 interface for precompile calls #726

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions docs/build/EVM/precompiles/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,41 @@ The Addresses can be checked in the [Astar repo](https://github.com/AstarNetwork

## Usage Example

Here we'll demonstrate how to interact with the dApp staking precompile using Remix IDE. Other precompiles can be accessed in a similar manner.
This section demonstrates how to interact with the dApp Staking precompile from your contract or using Remix IDE. Other precompiles can be accessed in a similar manner.

### From contract

`DappsStakingV3.sol` contains functions that _mimic_ the interface of the latest version of `dApp Staking`. The interface can be found in the [Astar repository](https://github.com/AstarNetwork/Astar/blob/master/precompiles/dapp-staking/DappsStakingV3.sol).
Developers are encouraged to use this interface to fully utilize dApp staking functionality.

```solidity
import "./DappsStaking.sol";
import "./DappsStakingV3.sol";

contract A {
DappsStaking public constant DAPPS_STAKING = DappsStaking(0x0000000000000000000000000000000000005001);
DAppStaking public constant DAPPS_STAKING = DAppStaking(0x0000000000000000000000000000000000005001);

/// @notice Check current era
function checkCurrentEra() public view {
uint256 currentEra = DAPPS_STAKING.read_current_era();
/// @notice Check protocol state
/// @return ProtocolState: The current protocol state.
function checkProtocolState() public view returns (DAppStaking.ProtocolState memory) {
DAppStaking.ProtocolState memory protocolState = DAPPS_STAKING.protocol_state();
return protocolState;
}
}
```

### Using Remix IDE

:::caution

The example below uses a soft-deprecated interface from the older dApp Staking v2.
While it is still supported by the network, it does not reflect the recommended usage for dApp Staking v3.
Please use the `v3` interface in a similar way for the latest version of the dApp Staking precompile.

:::

Example use: check `current era` and `total staked amount` in the `pallet-dapps-staking` for Shiden Network. For this example we will use Remix.

1. Copy `DappsStaking.sol` from [Astar repo](https://github.com/AstarNetwork/Astar/) and create new contract in Remix:
1. Copy `DappsStakingV2.sol` from [Astar repo](https://github.com/AstarNetwork/Astar/blob/master/precompiles/dapp-staking/DappsStakingV2.sol) and create new contract in Remix:

![](https://i.imgur.com/mr0TcLq.png)

Expand Down
Loading