Skip to content

Commit 4ac6f46

Browse files
finishing polish on #64
1 parent 0d6d239 commit 4ac6f46

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

docs/evm-tutorials/staking-precompile.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ btcli subnet register --network ws://127.0.0.1:9944
3939
- Click on **Submit Transaction** at the bottom right. This will open the **authorize transaction** window.
4040
- On this **authorize transaction** window, make sure the **sign and submit** toggle is ON and click on the **Sign and Submit** on the bottom right.
4141

42-
## Staking V1 and V2.
42+
## Staking V1 and V2
4343

44-
There are two versions of staking precompile implemenation, V1 and V2. The contract address for V1 is `0x0000000000000000000000000000000000000801`. The address for V2 is `0x0000000000000000000000000000000000000805`. The V1 is deprecated, just being kept for compatiable with old interface. The major difference between V1 and V2 is, the staking amount is fetched from the msg.value in V1. Then precompile transfer the token back to caller. It is misleading and confuses the solidity developers. In V2 implementation, all amount parameters are defined as parameter of transaction.
44+
There are two versions of staking precompile implemenation, V1 and V2. The contract address for V1 is `0x0000000000000000000000000000000000000801`. The address for V2 is `0x0000000000000000000000000000000000000805`. V1 is deprecated, but is kept for backwards-compatibility. The major difference between V1 and V2 is that the staking amount is fetched from the `msg.value` in V1. Then precompile transfers the token back to the caller. It is misleading and confuses solidity developers. In the V2 implementation, all amount parameters are defined as parameter of transaction.
4545

4646
## Call the staking precompile from another smart contract (staking pool use case)
4747

48-
In this interaction you will compile [`stakeV2.sol`](https://github.com/opentensor/evm-bittensor/blob/main/solidity/stakeV2.sol), a smart contract Solidity code and execute it on the subtensor EVM. This `stakeV2.sol` will, in turn, call the staking precompile that is already deployed in the subtensor EVM.
48+
In this interaction you will compile [`stakeV2.sol`](https://github.com/opentensor/evm-bittensor/blob/main/solidity/stakeV2.sol), a Solidity smart contract code, and execute it on the Subtensor EVM. This `stakeV2.sol` will, in turn, call the staking precompile that is already deployed on the Subtensor EVM.
4949

5050
Before you proceed, familiarize yourself with the Solidity code of the [`stakeV2.sol`](https://github.com/opentensor/evm-bittensor/blob/main/solidity/stakeV2.sol) smart contract.
5151

@@ -67,7 +67,7 @@ Before you proceed, familiarize yourself with the Solidity code of the [`stakeV2
6767

6868
In this tutorial, you will interact directly with the staking precompile by using its ABI, and use your Metamask wallet as the source of TAO to stake.
6969

70-
1. Copy this below ABI from https://github.com/opentensor/subtensor/blob/main/precompiles/src/solidity/stakingV2.abi into Remix IDE as a new file.
70+
1. Copy the ABI from https://github.com/opentensor/subtensor/blob/main/precompiles/src/solidity/stakingV2.abi into Remix IDE as a new file.
7171

7272
2. Copy staking precompile address `0x0000000000000000000000000000000000000805` to the **At Address** field in Remix IDE, and click **At Address** button.
7373

@@ -80,16 +80,11 @@ In this tutorial, you will interact directly with the staking precompile by usin
8080
3. Toggle **include option** OFF for the second parameter.
8181
4. Click the **+** button and find the new stake record.
8282

83-
## Questions about Call the staking precompile from another smart contract.
84-
85-
1. which one is the coldkey?
86-
Since the precompile can't get the orginal caller, the precompile takes the contract's address as coldkey.
87-
2. is the token subtracted from contract or original caller if calling the addStake
88-
The contract need to pay the token. so must guarantee the balance of contract is enough to call addStake.
89-
3. any security issue for the contract
90-
Because the token for addStake is subtracted from contract. We must set the transaction as priviledged one.
91-
like the example in [the link will be available after a PR merged in subtensor side]
92-
4. the unit of amount in addStake, removeStake
93-
As the function parameter indicates, all these are aligned with the decimal of TAO
94-
5. If transfer token to contract in msg.value, and trigger the contract to call precompile. should the function in contract do the decimal convert.
95-
Yes. the decimal in msg.value is 18. need conversion like `uint256 amount = msg.value / 1e9`
83+
## Notes: Calling the staking precompile from another smart contract
84+
85+
- The precompile takes the contract's address as the **coldkey**, since the precompile can't get the original caller.
86+
- The **contract** (not the caller's coldkey) must have sufficient liquidity or the transaction will fail.
87+
- The transaction must be *privileged* because the liquidity for `addStake` is subtracted from contract.
88+
<!-- example in link will be available after a PR merged in subtensor side -->
89+
- As the function parameter indicates, `amount` in `addStake` and `removeStake` are specified in TAO $\tau$.
90+
- That when transferring liquidity to the contract, `msg.value` is in denominations of 1/1e18 TAO $\tau$ . The staking precompile, however, expects RAO, 1/1e9 TAO $\tau$. You must convert before calling it: **uint256 amount = msg.value / 1e9**.

0 commit comments

Comments
 (0)