Skip to content

Commit

Permalink
Add guide
Browse files Browse the repository at this point in the history
  • Loading branch information
welldan97 committed Nov 27, 2024
1 parent cecb9ea commit e96853e
Show file tree
Hide file tree
Showing 13 changed files with 542 additions and 194 deletions.
12 changes: 7 additions & 5 deletions book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ console.log(status) // 'success'
// Configuration
// -------------

import { TonStaker } from '@chorus-one/ton'
import { TonPoolStaker } from '@chorus-one/ton'

const staker = new TonStaker({
const staker = new TonPoolStaker({
rpcUrl: 'https://toncenter.com/api/v2/jsonRPC'
})

Expand All @@ -351,11 +351,13 @@ await staker.init()
const delegatorAddress = '0QDsF87nkTYgkvu1z5xveCEGTRnZmEVaVT0gdxoeyaNvmoCr'

// You can use the Chorus One validator address or specify your own
const validatorAddress = '<validator-contract-address>'
const validatorAddressPair = [
'kQAHBakDk_E7qLlNQZxJDsqj_ruyAFpqarw85tO-c03fK26F',
'kQCltujow9Sq3ZVPPU6CYGfqwDxYwjlmFGZ1Wt0bAYebio4o'
]

const { tx } = await staker.buildStakeTx({
delegatorAddress,
validatorAddress,
validatorAddressPair,
amount: '1' // 1 TON
})

Expand Down
16 changes: 13 additions & 3 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
- [Methods](build-your-staking-dapp/solana/methods.md)
- [TON](build-your-staking-dapp/ton/README.md)
- [Overview](build-your-staking-dapp/ton/overview.md)
- [Methods](build-your-staking-dapp/ton/methods.md)
- [TON Pool](build-your-staking-dapp/ton/ton-pool/README.md)
- [Overview](build-your-staking-dapp/ton/ton-pool/overview.md)
- [Methods](build-your-staking-dapp/ton/ton-pool/methods.md)
- [Nominator](build-your-staking-dapp/ton/nominator/README.md)
- [Overview](build-your-staking-dapp/ton/nominator/overview.md)
- [Methods](build-your-staking-dapp/ton/nominator/methods.md)
- [Single Nominator](build-your-staking-dapp/ton/single-nominator/README.md)
- [Overview](build-your-staking-dapp/ton/single-nominator/overview.md)
- [Methods](build-your-staking-dapp/ton/single-nominator/methods.md)

## Ethereum Tutorial

Expand Down Expand Up @@ -57,7 +65,9 @@
- [NearStaker](docs/classes/near_src.NearStaker.md)
- [SolanaStaker](docs/classes/solana_src.SolanaStaker.md)
- [SubstrateStaker](docs/classes/substrate_src.SubstrateStaker.md)
- [TonStaker](docs/classes/ton_src.TonStaker.md)
- [TonPoolStaker](docs/classes/ton_src.TonPoolStaker.md)
- [TonNominatorPoolStaker](docs/classes/ton_src.TonNominatorPoolStaker.md)
- [TonSingleNominatorPoolStaker](docs/classes/ton_src.TonSingleNominatorPoolStaker.md)
- [Signers](api-reference/signers/README.md)
- [FireblocksSigner](docs/classes/signer_fireblocks_src.FireblocksSigner.md)
- [LocalSigner](docs/classes/signer_local_src.LocalSigner.md)
Expand All @@ -67,7 +77,7 @@
- [Transaction](docs/interfaces/ethereum_src.Transaction.md)
- [Polkadot (Substrate)](api-reference/types/polkadot-substrate/README.md)
- [RewardDestination](docs/enums/substrate_src.RewardDestination.md)
- [Ton](api-reference/types/ton/README.md)
- [TON](api-reference/types/ton/README.md)
- [AddressDerivationConfig](docs/interfaces/ton_src.AddressDerivationConfig.md)
- [NominatorInfo](docs/interfaces/ton_src.NominatorInfo.md)
- [PoolData](docs/interfaces/ton_src.PoolData.md)
Expand Down
2 changes: 2 additions & 0 deletions book/build-your-staking-dapp/ton/nominator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Nominator Pool

2 changes: 1 addition & 1 deletion book/build-your-staking-dapp/ton/nominator/methods.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Methods
# Nominator Pool: Methods

This section provides an overview of the key methods available in the **Chorus One SDK** for staking on the TON Network via the **Nominator Pool** contract.

Expand Down
154 changes: 154 additions & 0 deletions book/build-your-staking-dapp/ton/nominator/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Nominator Pool: Overview

The **Nominator Pool** is ideal for groups looking to pool resources and stake collectively. It allows up to 40 users to combine their holdings, with a collective minimum of 400,000 TON (at least 10,000 TON per user). Rewards are automatically distributed proportionally, making it a convenient and efficient option for shared staking.

The **Chorus One SDK** simplifies this process by providing developers with the tools needed to build, sign, and broadcast staking transactions.

{% hint style="info" %}

**Compatibility Notice**

The methods provided in this documentation are compatible with popular TON libraries such as `@ton/ton`. This compatibility ensures that you can seamlessly integrate these methods into your existing TON projects.

{% endhint %}

## Setting Up the Staker

To get started with staking on TON using the Chorus One SDK, you will first need to initialize the SDK.

- **Note:** For testing purposes we will be using the TON testnet.

First, create an instance of `TonNominatorPoolStaker` with the following configuration:

```javascript
import { TonNominatorPoolStaker } from '@chorus-one/ton'

const staker = new TonNominatorPoolStaker({
rpcUrl: 'https://testnet.toncenter.com/api/v2/jsonRPC'
})
```

**Configuration Parameters**:

- **rpcUrl**: The URL of the TON RPC endpoint. This is where the SDK will connect to interact with the network. In this example, we are using a public endpoint for the testnet.

---

## Initializing the Staker

After configuring the `TonNominatorPoolStaker`, you can initialize it to prepare for staking operations.

This can be done via the following input:

```javascript
await staker.init()
```

The `init` method establishes a connection with the configured RPC endpoint and prepares the staker for operations such as building and broadcasting transactions.

---

## Building Transactions

Once the staker and signer are set up, you can start building transactions for staking operations.

The `TonNominatorPoolStaker` class provides methods to build transactions for staking, unstaking, and wallet deployment.

- You can learn more about these methods in the [Methods](methods.md) section.

**Example of building a nominator pool staking transaction:**

```javascript
const { tx } = await staker.buildStakeTx({
delegatorAddress: '0QDsF87nkTYgkvu1z5xveCEGTRnZmEVaVT0gdxoeyaNvmoCr',
validatorAddress: 'Ef9rkkVM0xr4rKZZMAfBkXU0U8qMnkTmqbUhYRNBvRt5knxP',
amount: '1', // 1 TON
})
```

---

## Getting the Validator Address provided by Chorus One

To be eligible for the validator election process, validators need a minimum stake of 400,000 TON locked in the validator contract:

Due to above requirements we deploy the TON Validator contract upon client request. If you'd like to stake TON with Chorus One, please contact us at [[email protected]](mailto:[email protected])

---

## Signing the Transaction

Once the transaction is built, you can sign that transaction using your own signing solution e.g.:

```js
const signedTx = await yourWallet.signTransaction(tx)
```

Additionally, you can use the Chorus One SDK to sign transactions using Fireblocks, mnemonic or other methods.

- For detailed information on setting up and configuring these options, please refer to the [What is a Signer?](../../signers-explained/what-is-a-signer.md) section.

{% tabs %}
{% tab title="Using Fireblocks for Signing" %}
By integrating Fireblocks you can leverage its robust security features to sign transactions on the TON network. To set up Fireblocks, you must provide the necessary API key, secret key, and vault ID.

Example shown below:

```javascript
import { TonNominatorPoolStaker } from '@chorus-one/TON'
import { FireblocksSigner } from '@chorus-one/signer-fireblocks'

const signer = new FireblocksSigner({
apiSecretKey: 'your-api-secret-key',
apiKey: 'your-api-key',
vaultName: 'your-vault-name',
assetId: 'TON_TEST',
addressDerivationFn: TonNominatorPoolStaker.getAddressDerivationFn()
})

await signer.init()

const { signedTx } = await staker.sign({
signer,
signerAddress: '0QDsF87nkTYgkvu1z5xveCEGTRnZmEVaVT0gdxoeyaNvmoCr',
tx
})
```

For more information please refer to the [Signing with Fireblocks](../../signers-explained/fireblocks.md)
{% endtab %}
{% endtabs %}

---

## Broadcasting the Transaction

After signing the transaction, you will need to broadcast it to the network. You can do this using the `broadcast` method:

```javascript
const txHash = await staker.broadcast({ signedTx })
```

And now you can track the transaction status:

```javascript
const { status, receipt } = await staker.getTxStatus({
address: '0QDsF87nkTYgkvu1z5xveCEGTRnZmEVaVT0gdxoeyaNvmoCr',
txHash
})

console.log(status) // 'success'
```

---

## Next Steps

In this section you learned how to set up the Chorus One SDK for the TON network using the TON testnet, which included how to build staking transactions, sign, broadcast, and track them.

- To learn more about the available methods on `TonNominatorPoolStaker`, continue to the [Methods](methods.md) section.

## Further Reading

- [TonNominatorPoolStaker API Reference](../../../docs/classes/ton_src.TonNominatorPoolStaker.md)
- [What is a Signer?](../../signers-explained/what-is-a-signer.md)
Loading

0 comments on commit e96853e

Please sign in to comment.