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

feat: New command - staking #227

Merged
merged 54 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
54ef498
start
Jul 19, 2023
e2f3af7
added Withdraw, WithdrawAll
Jul 19, 2023
5d00339
added Unstake, UnstakeAll
Jul 19, 2023
7089c69
refactored Withdraw, WithdrawAll
Jul 22, 2023
538253c
added ViewBalance
Jul 22, 2023
2ac06dc
added ValidatorList
Jul 28, 2023
17fd266
refactored
Jul 28, 2023
5f5d1e2
fixed
Jul 28, 2023
39ccfb7
refactored
Jul 28, 2023
bca4e17
added delegated stake for view_account_summary
Jul 28, 2023
3f6b8ef
refactored get_validator_list()
Jul 29, 2023
e8fd341
refactored delegated_stake
Jul 29, 2023
9ddcb47
fixed
Jul 29, 2023
13f1b7b
added Stake, StakeAll
Aug 2, 2023
d94aade
added Deposit, DepositAndStake
Aug 2, 2023
9ad54aa
fixed <non-printable data (0 B)>
Aug 2, 2023
629d0d4
Merge branch 'master' into staking
FroVolod Aug 23, 2023
6acc1cb
Merge branch 'master' into staking
FroVolod Sep 3, 2023
b2646c8
updated to "order networks selection ..." #225
Sep 3, 2023
cc04fe1
added validators url
Sep 3, 2023
66d3b40
Merge branch 'master' into staking
FroVolod Sep 3, 2023
0d7e3b8
Merge branch 'master' into staking
FroVolod Sep 4, 2023
3591c95
Merge branch 'master' into staking
FroVolod Sep 9, 2023
d461b41
fixed unstake message
Sep 10, 2023
4e9af99
Merge branch 'master' into staking
FroVolod Sep 25, 2023
d93fedf
updated to "near-gas"
Sep 26, 2023
e8fbce9
clippy
Sep 26, 2023
70b7eaf
Merge branch 'master' into staking
FroVolod Sep 29, 2023
4fef7c4
updated: interactive-clap = "0.2.5"
Sep 30, 2023
3241e84
Merge branch 'master' into staking
FroVolod Oct 6, 2023
49809df
Merge remote-tracking branch 'origin/master' into staking
Oct 18, 2023
dbf79fc
refactor: optimized and simplified the delegated stake fetching
frol Oct 22, 2023
e6ba1ff
refactor: serde_json::to_vec() instead of .to_string().into_bytes()
Oct 22, 2023
cf8cfb6
Update src/commands/staking/delegate/unstake.rs
FroVolod Oct 22, 2023
4d92ff3
refactored get_validator_list()
Oct 23, 2023
1ebba51
refactored
Oct 24, 2023
1645264
updated input_account_id()
Oct 24, 2023
205d93a
refactored get_validator_list()
Oct 25, 2023
3038d61
added get_used_delegated_validator_list()
Oct 25, 2023
2e7a484
updated GUIDE
Oct 25, 2023
770796d
Update src/commands/staking/delegate/mod.rs
FroVolod Oct 26, 2023
2998e10
renamed Delegate to Delegation
Oct 26, 2023
fa9a653
fixed GUIDE
Oct 26, 2023
33abbb2
fixed GUIDE
Oct 26, 2023
d40363f
docs: Updated the GUIDE
frol Oct 26, 2023
7461a4f
updated StakeDelegationCommand
Oct 26, 2023
877098c
fixed GUIDE
Oct 26, 2023
8559cbc
updated view-balance
Oct 26, 2023
829144a
updated get_used_delegated_validator_list()
Oct 27, 2023
dde9cb8
updated cargo.lock
Oct 30, 2023
371bdf5
Merge remote-tracking branch 'origin/master' into staking
Oct 30, 2023
60f7e5c
fixed GUIDES
frol Oct 31, 2023
07960bb
refactor: common.rs
frol Oct 31, 2023
45c34d1
refactor: Refactored success messages and the `from_previous_context`
frol Oct 31, 2023
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
152 changes: 84 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

320 changes: 292 additions & 28 deletions docs/GUIDE.en.md

Large diffs are not rendered by default.

290 changes: 290 additions & 0 deletions docs/GUIDE.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ near --offline tokens \

- [account - Manage accounts](#account---Manage-accounts)
- [tokens - Manage token assets such as NEAR, FT, NFT](#tokens---Manage-token-assets-such-as-NEAR-FT-NFT)
- [staking - Manage staking: view, add and withdraw stake](#staking---Manage-staking-view-add-and-withdraw-stake)
- [contract - Manage smart-contracts: deploy code, call functions](#contract---Manage-smart-contracts-deploy-code-call-functions)
- [transaction - Operate transactions](#transaction---Operate-transactions)
- [config - Manage connections in a configuration file](#config---Manage-connections-in-a-configuration-file)
Expand Down Expand Up @@ -1329,6 +1330,295 @@ fro_volod.testnet account has NFT tokens:
</a>
</details>

### staking - Manage staking: view, add and withdraw stake

- [validator-list](#validator-list---View-the-list-of-validators-to-delegate)
- [delegation](#delegation---Delegation-management)

#### validator-list - View the list of validators to delegate

Для просмотра списка валидаторов необходимо ввести в командной строке терминала:
```txt
near staking \
validator-list \
network-config mainnet
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
+-----+----------------------------------------------+----------+------------+----------------------------------------+
| # | Validator Id | Fee | Delegators | Stake |
+-----+----------------------------------------------+----------+------------+----------------------------------------+
| 1 | staked.poolv1.near | 10 % | 3207 | 44135674.18356215181482959363448 NEAR |
| 2 | figment.poolv1.near | 10 % | 1911 | 43158696.364374348313201031661037 NEAR |
| 3 | astro-stakers.poolv1.near | 1 % | 11528 | 26760042.204197815051321354819805 NEAR |
| 4 | bzam6yjpnfnxsdmjf6pw.poolv1.near | 100 % | 772 | 23347900.996610021010359525969384 NEAR |
| 5 | zavodil.poolv1.near | 1 % | 7116 | 20700903.223980192761611953425855 NEAR |
| 6 | binancenode1.poolv1.near | 5 % | 1250 | 14209385.916611355199355410152982 NEAR |
| 7 | staking_yes_protocol1.poolv1.near | 100 % | 65 | 13590245.381034035922399111793022 NEAR |
| 8 | pinnacle1.poolv1.near | 100 % | 4 | 13509874.537453205747773186007329 NEAR |
| 9 | priory.poolv1.near | 100 % | 15 | 12727257.514716521676379711750814 NEAR |
| 10 | stake1.poolv1.near | 3 % | 754 | 12449700.095021989100340879377004 NEAR |
| 11 | mockingbird.poolv1.near | 100 % | 28 | 11501759.018634341466180769487983 NEAR |
| 12 | dqw9k3e4422cxt92masmy.poolv1.near | 100 % | 36 | 11122519.385245577197951932017032 NEAR |
| 13 | flipside.pool.near | 100 % | 9 | 11087540.718366137730589600283212 NEAR |
| 14 | sweat_validator.poolv1.near | 100 % | 112 | 10900424.272450229667472212076621 NEAR |
| 15 | epic.poolv1.near | 1 % | 5363 | 10769900.629411406438519703653828 NEAR |
| 16 | future_is_near.poolv1.near | 9 % | 355 | 10243082.132364573976720438585765 NEAR |
| 17 | cosmose.poolv1.near | 100 % | 10 | 10064982.806109296980776431396738 NEAR |
| 18 | aurora.pool.near | 99 % | 3301 | 9298278.181302142009939675438401 NEAR |
...
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/IYG8qgo3bdXHrgnyJL443gw6L?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/IYG8qgo3bdXHrgnyJL443gw6L.png" width="836"/>
</a>
</details>

#### delegation - Delegation management

- [view-balance](#View-the-total-balance-for-a-given-account)
- [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor)
- [deposit-and-stake](#deposit-and-stake---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor-and-stakes-it)
- [stake](#stake---Staking-the-given-amount-from-the-inner-account-of-the-predecessor)
- [stake-all](#stake-all---Staking-all-available-unstaked-balance-from-the-inner-account-of-the-predecessor)
- [unstake](#unstake---Unstaking-the-given-amount-from-the-inner-account-of-the-predecessor)
- [unstake-all](#unstake-all---Unstaking-all-staked-balance-from-the-inner-account-of-the-predecessor)
- [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account)
- [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account)

##### view-balance - View the total balance for a given account

Для просмотра баланса аккаунта у делегироанного валидатора необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
view-balance aurora.pool.f863973.m0 \
network-config testnet \
now
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Balance on validator <aurora.pool.f863973.m0> for <volodymyr.testnet>:
Staked balance: 38.021465232511349340052266 NEAR
Unstaked balance: 0.000000000000000000000001 NEAR
Total balance: 38.021465232511349340052267 NEAR
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/2ZFe7ILJOoJCHYPYSnv7JBBFy?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/2ZFe7ILJOoJCHYPYSnv7JBBFy.png" width="836"/>
</a>
</details>

##### deposit - Deposits the attached amount into the inner account of the predecessor

Чтобы разместить депозит Вашего аккаунта у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
deposit '10 NEAR' aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully deposited 10 NEAR on <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/acAvmEqNNhfK8f4Ggl2BcOPde?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/acAvmEqNNhfK8f4Ggl2BcOPde.png" width="836"/>
</a>
</details>

##### deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it

Чтобы разместить депозит и сделать ставку Вашего аккаунта у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
deposit-and-stake '15 NEAR' aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully deposited and staked 15 NEAR on <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/tTwzlj0FszzXEh36aP6ZaTdhG?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/tTwzlj0FszzXEh36aP6ZaTdhG.png" width="836"/>
</a>
</details>

##### stake - Staking the given amount from the inner account of the predecessor

Чтобы сделать ставку определенной суммы от внесенного ранее депозита у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
stake '5 NEAR' aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully stake 5 NEAR on <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/10T84aFMiJSYLv3shBEsql68L?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/10T84aFMiJSYLv3shBEsql68L.png" width="836"/>
</a>
</details>

##### stake-all - Staking all available unstaked balance from the inner account of the predecessor

Чтобы сделать ставку всего депозита у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
stake-all aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully stake the entire amount on <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/bhUAfnDCnt9U2XQLeY46sbTWR?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/bhUAfnDCnt9U2XQLeY46sbTWR.png" width="836"/>
</a>
</details>

##### unstake - Unstaking the given amount from the inner account of the predecessor

Чтобы снять ставку определенной суммы у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
unstake '7 NEAR' aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully unstake 7 NEAR from <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/vOJusmeGFwrofAKN6wd2Q3a5w?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/vOJusmeGFwrofAKN6wd2Q3a5w.png" width="836"/>
</a>
</details>

##### unstake-all - Unstaking all staked balance from the inner account of the predecessor

Чтобы снять всю ставку у делегироанного валидатора, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
unstake-all aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
<volodymyr.testnet> has successfully unstake the entire amount from <aurora.pool.f863973.m0>.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/FgEjwrSlSHjIXeUBZGyl1O6vG?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/FgEjwrSlSHjIXeUBZGyl1O6vG.png" width="836"/>
</a>
</details>

##### withdraw - Withdrawing the non staked balance for given account

Чтобы вывести определенную сумму из делегироанного валидатора на свой аккаунт, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
withdraw '3 NEAR' aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Error:
0: <volodymyr.testnet> can't withdraw tokens in the current epoch.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/U4V6CUJU0vG0dJhT4igXyrJpk?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/U4V6CUJU0vG0dJhT4igXyrJpk.png" width="836"/>
</a>
</details>

##### withdraw-all - Withdrawing the entire unstaked balance from the predecessor account

Чтобы вывести всю сумму из делегироанного валидатора на свой аккаунт, необходимо ввести в командной строке терминала:
```txt
near staking \
delegation volodymyr.testnet \
withdraw-all aurora.pool.f863973.m0 \
network-config testnet \
sign-with-legacy-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Error:
0: <volodymyr.testnet> can't withdraw tokens in the current epoch.
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/5ql7FP93TM2whN2kyVYxBCtYy?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/5ql7FP93TM2whN2kyVYxBCtYy.png" width="836"/>
</a>
</details>

### contract - Manage smart-contracts: deploy code, call functions

- [call-function](#call-function---Execute-function-contract-method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ impl From<SignerAccountIdContext> for crate::commands::ActionContext {
],
new_account_id.clone())
} else {
let args = json!({
let args = serde_json::to_vec(&json!({
"new_account_id": new_account_id.clone().to_string(),
"new_public_key": item.account_properties.public_key.to_string()
})
.to_string()
.into_bytes();
}))?;

if let Some(linkdrop_account_id) = &network_config.linkdrop_account_id {
if new_account_id.is_sub_account_of(linkdrop_account_id)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account/storage_management/storage_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ impl SignerAccountIdContext {
actions: vec![near_primitives::transaction::Action::FunctionCall(
near_primitives::transaction::FunctionCallAction {
method_name: "storage_deposit".to_string(),
args: serde_json::json!({ "account_id": &receiver_account_id })
.to_string()
.into_bytes(),
args: serde_json::to_vec(&serde_json::json!({
"account_id": &receiver_account_id
}))?,
gas: crate::common::NearGas::from_tgas(50).as_gas(),
deposit: deposit.to_yoctonear(),
},
Expand Down
6 changes: 2 additions & 4 deletions src/commands/account/storage_management/storage_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ impl SignerAccountIdContext {
actions: vec![near_primitives::transaction::Action::FunctionCall(
near_primitives::transaction::FunctionCallAction {
method_name: "storage_withdraw".to_string(),
args: serde_json::json!({
args: serde_json::to_vec(&serde_json::json!({
"amount": amount.clone().to_yoctonear().to_string()
})
.to_string()
.into_bytes(),
}))?,
gas: crate::common::NearGas::from_tgas(50).as_gas(),
deposit: crate::common::NearBalance::from_yoctonear(1)
.to_yoctonear(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ impl AccountContext {
.blocking_call_view_function(
&contract_account_id,
"storage_balance_of",
serde_json::json!({
serde_json::to_vec(&serde_json::json!({
"account_id": account_id.to_string(),
})
.to_string()
.into_bytes(),
}))?,
block_reference.clone(),
)
.wrap_err_with(|| {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/account/update_social_profile/sign_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ impl From<SignerContext> for crate::commands::ActionContext {
.blocking_call_view_function(
&contract_account_id,
"get",
serde_json::json!({
serde_json::to_vec(&serde_json::json!({
"keys": vec![format!("{account_id}/profile/**")],
})
.to_string()
.into_bytes(),
}))?,
near_primitives::types::Finality::Final.into(),
)
.wrap_err_with(|| {format!("Failed to fetch query for view method: 'get {account_id}/profile/**'")})?
Expand Down
Loading
Loading