web3go-xyz / web3go.xyz

Discovery data value of Web3
Apache License 2.0
10 stars 4 forks source link

unstake function #119

Closed happyJ2024 closed 1 year ago

happyJ2024 commented 1 year ago

https://www.notion.so/web3builders/Web3Go-Moonbeam-staking-pallet-Unstaking-Scheduled-unstaking-doc-8713a31bf27c4978a284e8991cd69931 unstaking文档

imqipan commented 1 year ago

The UI and the interaction design can be viewed at https://www.figma.com/file/UHdJBdCbMUCDoJ7GdcE9Cr/moombeam?node-id=25%3A8190&t=GIn4sJz0bj43E8jE-0

happyJ2024 commented 1 year ago

target_seconds_per_block : apr.utils.js getBlockTargetSeconds, default is 12s

blocks_per_round: chain constant, 当前页面已有该值roundInfo.length Image

happyJ2024 commented 1 year ago
  1. 当执行了api.tx.parachainStaking.scheduleRevokeDelegation(collator) 操作后, 会在链上生成一个schedule记录。

  2. 已知当前用户参与的collator列表

  3. 通过 api.query.parachainStaking.delegationScheduledRequests(collator) 查找得到 某个 collator下的 schedule记录 结构如下:

    [
    [
    [
      jcSQcu5RXtWXKPN78zJogNyqsff1j4ffgoJ2njNcDbZ3qNEh5   // collator
    ]
    [
      {
        delegator: jcS3Mpk2s3UdoBTW6QaniZnhn7xbMtfYX7ZZQJGg1DVNcNkk9   //delegator
        whenExecutable: 62,948                                     // 真正能执行确认动作的roundIndex
        action: {
          Revoke: 3,100,000,000,000,000                        // 动作, token数量
        }
      }
    ]
    ]
    ]
  4. 匹配当前用户地址和 schedule记录, 如果没有关联, 说明用户没有等待中的revoke操作 如果有关联, 得到 whenExecutable_roundIndex

  5. 已知参数: current_roundIndex, current_blockNumber, whenExecutable_roundIndex, target_seconds_per_block , blocks_per_round

*est_blocks_v1= (whenExecutable_roundIndex - current_roundIndex ) blocks_per_round **

est_blocks_v2= est_blocks_v1 - ( blocks_finished_in_current_round )

Image

*est_seconds = est_blocks_v2 target_seconds_per_block**

happyJ2024 commented 1 year ago

api.constants. parachainStaking.leaveDelegatorsDelay

Image

happyJ2024 commented 1 year ago

当 whenExecutable_roundIndex <= current_roundIndex , 此时 execute按钮出现了, 可以执行确认动作

api.tx.xxxx

Image

happyJ2024 commented 1 year ago

取消

Image

happyJ2024 commented 1 year ago

比如: 用户 U, Collator A,B U stake 给 A,B => 显示两条记录, 此时两条都有 revoke按钮

  1. U revoke A => 此时 A 显示倒计时, B 仍然是 revoke按钮
  2. 过了一段时间, U revoke B => 此时 A 保持显示倒计时, B 显示倒计时, 注意AB 倒计时 不同
  3. 过了一段时间,A倒计时终结了, 显示 Execute , B 仍然显示倒计时
  4. A 执行 Execute , 完成后A记录应该消失了。
  5. B倒计时终结了, 显示 Execute
  6. B 执行 Execute , 完成后B记录应该消失了。
happyJ2024 commented 1 year ago

execute 为什么有 delegator参数, 而 cancel 没有这个参数? execute 可以由别人代为执行 cancel 只能自己执行,默认是针对当前caller

imqipan commented 1 year ago

finished and ready to test on the test env.