Skip to content

Commit 9d8bbdd

Browse files
authored
Merge pull request #589 from gleb498/single-nominator
Single nominator pool clarification
2 parents 33ffcc8 + 096e71e commit 9d8bbdd

File tree

12 files changed

+277
-15
lines changed

12 files changed

+277
-15
lines changed

docs/participate/network-maintenance/single-nominator.mdx

Lines changed: 257 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import Tabs from '@theme/Tabs';
2+
import TabItem from '@theme/TabItem';
3+
14
# Single Nominator Pool
25

3-
## Using mytonctrl
6+
[Single Nominator](https://github.com/orbs-network/single-nominator) is a TON smart contract that enables secure validation for TON blockchain. The contract is designed for TON validators that have enough self stake to validate by themselves without relying on third-party nominators stakes. The contract provides an alternative simplified implementation for the Nominator Pool smart contract that supports a Single Nominator only.
7+
8+
## Start using mytonctrl
49

510
Currently [mytonctrl](https://github.com/ton-blockchain/mytonctrl) supports `single_nominator` contracts, but firstly you need to install mytonctrl 2.0.
611

7-
### mytonctrl 2.0
12+
### Launch mytonctrl 2.0
813

914
If you already have installed mytonctrl just use command `update mytonctrl2`. If you have no mytonctrl installed, follow these steps:
1015

@@ -22,31 +27,63 @@ sudo bash ./install.sh -b mytonctrl2
2227

2328
### Set up single-nominator
2429

25-
After you have created and activated validator's wallet, follow these steps:
30+
After you have [created](/participate/run-nodes/full-node#import-existed-account) and [activated](/participate/run-nodes/full-node#activate-the-wallets) the validator's wallet, follow these steps:
2631

2732
1. Enable single nominator mode
2833

2934
```bash
3035
MyTonCtrl> enable_mode single-nominator
3136
```
3237

33-
2. Create pool
38+
2. Check if single-nominator mode is enabled.
39+
40+
```bash
41+
MyTonCtrl> status_modes
42+
Name Status Description
43+
single-nominator enabled Orbs's single nominator pools.
44+
```
45+
46+
3. Create pool
3447
3548
```bash
3649
MyTonCtrl> new_single_pool <pool-name> <owner_address>
3750
```
3851
39-
3. Type `pools_list` to display pool addresses
52+
If you have already created pool it's possible to import it:
4053

41-
4. Send 1 TON to the pool and activate it
54+
```bash
55+
MyTonCtrl> import_pool <pool-name> <pool-addr>
56+
```
57+
58+
4. Type `pools_list` to display pool addresses
59+
60+
```bash
61+
MyTonCtrl> pools_list
62+
Name Status Balance Version Address
63+
test-pool empty 0.0 spool_r2 kf_JcC5pn3etTAdwOnc16_tyMmKE8-ftNUnf0OnUjAIdDJpX
64+
```
65+
66+
5. Send 1 TON to the pool and activate it
4267

4368
```bash
4469
MyTonCtrl> activate_single_pool <pool-name>
4570
```
4671

72+
After successfully activated wallet:
73+
74+
```bash
75+
MyTonCtrl> pools_list
76+
Name Status Balance Version Address
77+
test-pool active 0.99389 spool_r2 kf_JcC5pn3etTAdwOnc16_tyMmKE8-ftNUnf0OnUjAIdDJpX
78+
```
79+
4780
Now you can work with this pool via mytonctrl like with a standard nominator pool.
4881

49-
## Without mytonctrl
82+
:::info
83+
If the pool's balance is enough to participate in both rounds (`balance > min_stake_amount * 2`) then MyTonCtrl will automatically participate in both rounds using `stake = balance / 2`, unless user sets stake manually using command `set stake`. This behaviour is different from using a nominator pool but similar to staking using validator wallet.
84+
:::
85+
86+
## Start without mytonctrl
5087
5188
#### Prepare launched Validator
5289
@@ -60,19 +97,19 @@ Now you can work with this pool via mytonctrl like with a standard nominator poo
6097
2. Stop validation and withdraw all funds.
6198

6299

63-
## Prepare single_nominator
100+
### Prepare Single Nominator
64101

65102

66103
1. Install [nodejs](https://nodejs.org/en) v.16 and later and npm ([detailed instructions](https://github.com/nodesource/distributions#debian-and-ubuntu-based-distributions))
104+
67105
2. Install `ts-node` and `arg` module
68106

69107
```bash
70108
$ sudo apt install ts-node
71109
$ sudo npm i arg -g
72110
```
73111

74-
75-
4. Create symlinks:
112+
4. Create symlinks for compilers:
76113

77114
```bash
78115
$ sudo ln -s /usr/bin/ton/crypto/fift /usr/local/bin/fift
@@ -87,9 +124,7 @@ $ npm run test
87124

88125
6. Replace mytonctrl nominator-pool scripts: https://raw.githubusercontent.com/orbs-network/single-nominator/main/mytonctrl-scripts/install-pool-scripts.sh
89126

90-
91-
92-
## Create single_nominator Pool
127+
### Create Single Nominator Pool
93128

94129
1. Get Toncenter API key from a Telegram [@tonapibot](https://t.me/tonapibot)
95130
2. Set env variables:
@@ -127,9 +162,9 @@ $ fift -s ./scripts/fift/str-to-addr.fif Ef-kC0..._WLqgs
127162
7. Copy "single-nominator.addr" to "mytoncore/pools/single-nominator-1.addr"
128163
8. Send stake from owner address to single nominator address
129164
130-
## Withdrawals from Single Nominator
165+
### Withdrawals from Single Nominator
131166
132-
Using wallets to withdraw from single_nominator
167+
Using wallets to withdraw from Single Nominator
133168
Fift:
134169
135170
1. Create "withdraw.boc" request with amount:
@@ -180,6 +215,213 @@ npx ts-node scripts/ts/withdraw-deeplink.ts <single-nominator-addr> <withdraw-am
180215

181216
d. Open deeplink on the owner's phone
182217

218+
## Deposit pool
219+
220+
You can make a deposit using **MyTonCtrl**, using the following commands:
221+
222+
```sh
223+
MyTonCtrl> mg <from-wallet-name> <pool-account-addr> <amount>
224+
```
225+
226+
or
227+
228+
```sh
229+
MyTonCtrl> deposit_to_pool <pool-addr> <amount>
230+
```
231+
232+
which deposits pool from validator wallet.
233+
234+
Or use the following steps:
235+
236+
1. Go to the pool’s page https://tonscan.org/nominator/<pool_address>.
237+
238+
2. Make sure that the information about the pool is fully displayed, if the pool has the wrong smart contract, there will be no information.
239+
240+
3. Press the `ADD STAKE` button or scan the QR-code using Tonkeeper or any other TON Wallet.
241+
242+
4. After you are transferred to the wallet, please, enter the amount of TON and then send the transaction. After that TON coins will be added to staking.
243+
244+
If the wallet does not open automatically, you can send the transaction manually by copying the pool address. Send it through any TON wallet. From the sent transaction, 1 TON will be debited as a commission for processing the deposit.
245+
246+
247+
## Withdraw funds
248+
249+
To get coins back after staking, send 1 TON to the pool’s address, add a comment **w** (small letter) to the transaction. This 1 TON minus commission will be returned, and a smart-contract will understand that you want to bring the coins back and it will send them back right after the end of the validator’s work cycle. It usually takes up to 18 hours on Mainnet and 2 hours on Testnet.
250+
251+
You can also withdraw funds using the following command:
252+
253+
```sh
254+
MyTonCtrl> withdraw_from_pool <pool-addr> <amount>
255+
```
256+
257+
Or you can create and send transaction manually:
258+
259+
<Tabs groupId="code-examples">
260+
<TabItem value="toncore" label="JS (@ton)">
261+
262+
```js
263+
import { Address, beginCell, internal, storeMessageRelaxed, toNano } from "@ton/core";
264+
265+
async function main() {
266+
const single_nominator_address = Address.parse('single nominator address');
267+
const WITHDRAW_OP = 0x1000
268+
const amount = 50000
269+
270+
const messageBody = beginCell()
271+
.storeUint(WITHDRAW_OP, 32) // op code for withdrawal
272+
.storeUint(0, 64) // query_id
273+
.storeCoins(amount) // amount to withdraw
274+
.endCell();
275+
276+
const internalMessage = internal({
277+
to: single_nominator_address,
278+
value: toNano('1'),
279+
bounce: true,
280+
body: messageBody
281+
});
282+
}
283+
```
284+
285+
</TabItem>
286+
287+
<TabItem value="tonconnect" label="Golang">
288+
289+
```go
290+
func WithdrawSingleNominatorMessage(single_nominator_address string, query_id, amount uint64) (*tonconnect.Message, error) {
291+
292+
const WITHDRAW_OP = 0x1000
293+
294+
payload, _ := cell.BeginCell().
295+
MustStoreUInt(WITHDRAW_OP, 32). // op code for withdrawal
296+
MustStoreUInt(query_id, 64). // query_id
297+
MustStoreCoins(amount). // amount to withdraw
298+
EndCell().MarshalJSON()
299+
300+
msg, err := tonconnect.NewMessage(
301+
single_nominator_address,
302+
tlb.MustFromTON("1").Nano().String(), // nanocoins to transfer/compute message
303+
tonconnect.WithPayload(payload))
304+
305+
if err != nil {
306+
return nil, err
307+
}
308+
309+
return msg, nil
310+
}
311+
```
312+
313+
</TabItem>
314+
315+
</Tabs>
316+
317+
318+
## Election process
319+
320+
### Set up a Single Nominator Pool
321+
322+
Configure the Single Nominator Pool contract using the [following]((/participate/network-maintenance/single-nominator#set-up-single-nominator)) instructions.
323+
324+
### Join the elections
325+
326+
[Deposit](/participate/network-maintenance/single-nominator#deposit-pool) minimum stake amount to the Single Nominator Pool.
327+
328+
**MyTonCtrl** will automatically join the elections. You can set the stake amount that mytonctrl sends to the [Elector contract](/develop/smart-contracts/governance#elector) ~ every 18 hours on Mainnet and 2 hours on Testnet.
329+
330+
```sh
331+
MyTonCtrl> set stake 90000
332+
```
333+
334+
**Minimum stake** amount could be found using `status` command.
335+
336+
![](/img/docs/single-nominator/tetsnet-conf.png)
337+
338+
You can set `stake` as `null` and it will be calculated according to the `stakePercent` value (could be checked with `status_settings` command).
339+
340+
It's possible to check is election has already been started:
341+
342+
```bash
343+
MyTonCtrl> status
344+
```
345+
346+
and for Testnet:
347+
348+
```bash
349+
MyTonCtrl> status fast
350+
```
351+
352+
As example:
353+
354+
![](/img/docs/single-nominator/election-status.png)
355+
356+
357+
If the election has been started and Single Nominator Pool is activated, validator should **automatically** send **ElectorNewStake** message to the Elector contract at the beginning of the next round.
358+
359+
Check validator wallet:
360+
361+
```sh
362+
MyTonCtrl> wl
363+
Name Status Balance Ver Wch Address
364+
validator_wallet_001 active 995.828585374 v1 -1 kf_dctjwS4tqWdeG4GcCLJ53rkgxZOGGrdDzHJ_mxPkm_Xct
365+
```
366+
367+
Then check it transaction history:
368+
369+
```sh
370+
MyTonCtrl> vas kf_dctjwS4tqWdeG4GcCLJ53rkgxZOGGrdDzHJ_mxPkm_Xct
371+
Address Status Balance Version
372+
kf_dctjwS4tqWdeG4GcCLJ53rkgxZOGGrdDzHJ_mxPkm_Xct active 995.828585374 v1r3
373+
374+
Code hash
375+
c3b9bb03936742cfbb9dcdd3a5e1f3204837f613ef141f273952aa41235d289e
376+
377+
Time Coins From/To
378+
39 minutes ago >>> 1.3 kf_hz3BIXrn5npis1cPX5gE9msp1nMTYKZ3l4obzc8phrBfF
379+
```
380+
381+
This **ElectorNewStake** transaction in Single Nominator contract history in Tonviewer:
382+
383+
![](/img/docs/single-nominator/new-stake.png)
384+
385+
On the above example **MyTonCtrl** automatically stake `90000` Toncoins on the Elector contract.
386+
387+
### Checking Validator Status
388+
389+
At the beginning of the next round check **MyTonCtrl** validator status with `status` command (`status fast` on Testnet).
390+
391+
![](/img/docs/single-nominator/status-validator.png)
392+
393+
You can confirm if your node has become a full validator by checking the following conditions:
394+
395+
1. **Validator Efficiency** - An efficiency of the local validator should be green and not `n/a`.
396+
2. **Validator Index** - The validator index should be greater than -1.
397+
398+
399+
### Checking profit
400+
401+
At the end of the round **MyTonCtrl** sends **ElectorRecoverStakeRequest** message to the Elector contract. It responses with `stake + profit` amount of Toncoins to your Single Nominator Pool.
402+
403+
![](/img/docs/single-nominator/validator-profit.png)
404+
405+
You can also check transactions history of your pool with `vas` command:
406+
407+
![](/img/docs/single-nominator/validator-profit-vas.png)
408+
409+
### Stop participating
410+
411+
If user doesn't want to take part in validating anymore:
412+
413+
1. Disable validator mode:
414+
415+
```bash
416+
MyTonCtrl> disable_mode validator
417+
2. [Withdraw](/participate/network-maintenance/single-nominator#withdraw-funds) all funds from the Single Nominator contract to the owner wallet.
418+
419+
## Transitioning a Regular Validator to Nominator Pool Mode
420+
421+
1. Disable `validator` mode to discontinue election participation.
422+
2. Await the return of both your stakes from the elector.
423+
3. Proceed with the following [steps](/participate/network-maintenance/single-nominator#set-up-single-nominator).
424+
183425

184426
## See Also
185427

docs/participate/run-nodes/full-node.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ Wait until `Local validator out of sync` becomes less than 20 seconds.
224224

225225
## Become a Validator
226226

227+
### Import existed account
228+
229+
It is possible to import existed account to **MyTonCtrl** using `iw` command:
230+
231+
```sh
232+
iw <wallet-addr> <wallet-secret-key>
233+
```
234+
235+
During the execution, the wallet_001 wallet is created:
236+
237+
![](\img\docs\full-node\import-acc.png)
227238

228239
### View the List of Wallets
229240

@@ -689,6 +700,15 @@ If validatorWalletName is null then execute the following:
689700
mytonctrl> set validatorWalletName validator_wallet_001
690701
```
691702

703+
### Status error on Testnet
704+
705+
![](\img\docs\full-node\status-error.jpg)
706+
707+
This error could be seen on Testnet network on `status` command. Use the following instead:
708+
709+
```bash
710+
mytonctrl> status fast
711+
```
692712

693713
### Transfer a Validator on the new Server
694714

47.1 KB
Loading
159 KB
Loading
Loading
74.2 KB
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)