Skip to content

Commit 689d3c7

Browse files
authored
Replace some native token with bridge in docs (#1017)
1 parent c2abc57 commit 689d3c7

File tree

5 files changed

+139
-48
lines changed

5 files changed

+139
-48
lines changed

changelog.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,22 @@ This changelog is based on [Keep A Changelog](https://keepachangelog.com/en/1.1.
1010
Possibility to interact with smart-contracts used by earlier versions is lost.
1111
Governance authority will have to establish new partner chain on Cardano.
1212
All initialization and candidates registrations have to be repeated.
13-
* Switched from `polkadot-stable2503-07` to `polkadot-stable2506`. `type RuntimeEvent` became deprecated in polkadot-sdk. It has been removed from the toolkit crates. To update to this version of PC toolkit, please remove definition of `type RuntimeEvent` when wiring in runtime.
13+
* Updated from `polkadot-stable2503-07` to `polkadot-stable2506-2`. `type RuntimeEvent` became deprecated in polkadot-sdk. It has been removed from the toolkit crates. To update to this version of PC toolkit, please remove definition of `type RuntimeEvent` when wiring in runtime.
1414
* Added extra constant burn fee in `pallet-address-association` to discourage attacks on pallet storage.
15-
* Fixed panic when running `ariadne-parameters`, `registration-status` and `sidechain-params` subcommands when chain spec without initial authorities is used.
1615
* Wizards don't require `generate-keys` for `prepare-configuration`. Altered recommended order of `create-chain-spec` and `setup-main-chain-state`.
1716
* `MainchainAddress` is now serialized as plain String instead of hexstring of its bytes
1817
* Wizards use optional env vars: PC_CHAIN_CONFIG_FILE and PC_RESOURCES_CONFIG_FILE env variables to
1918
locate the chain config and resources config files
2019
* `pallet-block-producer-metadata` is updated with a configurable fee for inserting the metadata, to make attacks on unbounded storage economically infeasible
21-
* Removed redundant `RawPermissionedCandidateData` type.
2220
* Added `valid_before` argument to the signed message and all extrinsics in `pallet_block_producer_metadata`. This is to
2321
prevent unauthorized re-submission of metadata updates. The `sign-block-producer-metadata` command was updated to
2422
match this change.
25-
* `partner-chain-cli` (wizards) does not execute `<pc-node> build-spec` but creates the chain-spec.json file directly with a code injected into the command.
23+
* Removed redundant `RawPermissionedCandidateData` type.
2624
* Debug strings generated by `byte-string-derive` crate now fully pad output hex with zeros
2725
* `authority-selection-inherents` crate now exports all its public members from the crate root
2826
* `select_authorities` in `authority-selection-inherents` crate now returns a `BoundedVec` of `CommitteeMembers`. Projects that used the old version no longer
2927
need to transform the data in their own runtime code
30-
* Updates Rust dependency to v1.88, changes WASM target to 'wasm32v1-none'
31-
* Backward compatible Encode and Decode for legacy chains that operate with AURA and Grandpa keys as session keys.
28+
* Updated Rust toolchain to v1.90, changed WASM target to 'wasm32v1-none'
3229
* Macro `observed_async_trait` in `partner-chains-db-sync-data-sources` crate has been made non-public.
3330

3431
## Added
@@ -47,11 +44,11 @@ In SCALE encoding of inherent data custom implementations of `Encode` and `Decod
4744

4845
`getAriadneParameters` and `getRegistrations` RPC results format has changed, `auraPubKey` and `grandpaPubKey` are replaced by `"keys": {"aura": "...", "gran": "..."}`.
4946

50-
### Unidirectional Token Bridge (Work-in-progress)
47+
### Unidirectional Token Bridge
5148

5249
A set of modules implementing observability layer, runtime pallet and offchain commands for a trustless token bridge moving tokens from Cardano to the Partner Chain.
5350

54-
This bridge feature works by monitoring an *illiquid supply validator address* on Cardano for new UTXOs. These UTXOs are interpreted as being either user-initiated
51+
This bridge feature works by monitoring an *illiquid circulation supply validator address* on Cardano for new UTXOs. These UTXOs are interpreted as being either user-initiated
5552
transfers sent to a specified address on the Partner Chain, or reserve transfers made as part of the chain's operations for the purposes of distributing them as
5653
block producer rewards on-chain. Handling of the transfers is left to the chain builders themselves to implement according to their business needs and ledger structure.
5754

@@ -67,6 +64,7 @@ The data sources will automatically detect this option on startup and adjust the
6764

6865
* `smart-contracts` governance actions were failing due too redundant signature when initiated by non-governance wallet
6966
* Wizards using 'sidechain' in command line parameters are changed to use 'partner-chain' instead
67+
* Fixed panic when running `ariadne-parameters`, `registration-status` and `sidechain-params` subcommands when chain spec without initial authorities is used.
7068

7169
## Removed
7270

docs/developer-guides/native-token-reserve-management.md renamed to docs/developer-guides/bridge-and-reserve.md

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
# Native token reserve management
1+
# Native token bridge and reserve management
22

33
## Overview
44

5+
The bridge functionality allows to register movement of designated native token (minting policy of it is controlled by users) to the bridge (also called Illiquid Circulation Supply Validator).
6+
The Illiquid Circulation Supply Validator locks native tokens and prevents moving them out of the bridge.
7+
For operational reasons (coin selection problem), the system allows setting a minimum number of UTXOs that should always be present at the bridge address, by creating UTXOs that contain a special token. The validator ensures that this token can not be moved out of the address and any UTXOs there can only contain one token each.
8+
9+
Additionally to the bridge there is the Reserve mechanism.
10+
Reserve is set up by the governance authority with some amount of designated native tokens.
11+
More tokens can be deposited to the reserve later.
12+
Any user can release tokens from the reserve to the bridge - conceptually this should be observed at partner chain and some kind of rewards pool should be increased there.
13+
Release can be done only with the amount that is bounded by so-called `V-function` (release schedule function).
14+
515
This guide covers the following tasks:
616

717
1. **On Cardano:**
818

9-
- Creating your new token and setting up rules for how tokens are released over time
10-
- This involves setting up and managing a token management contract on the Cardano blockchain, enabling proper observability on your partner chain.
19+
- Creating your new token, and optionally setting up rules for how tokens can be released from the reserve over time
20+
- This involves setting up and managing a bridge and reserve contracts on the Cardano blockchain, enabling proper observability on your partner chain.
1121

1222
2. **On your partner chain:**
1323

1424
- Connecting your partner chain to track the token and enable token operations across both chains
1525
- This involves following a step-by-step process for interacting with both the Cardano blockchain and your partner chain.
1626

17-
After you complete the steps in this guide, you will have a fully functioning token system that works across Cardano and your partner chain.
27+
After you complete the steps in this guide, you will have fully functioning bridge and reserve systems that work across Cardano and your Partner Chain.
1828

1929
![Native token management contract](native-token-mgt-contract.png "Native token management contract")
2030

@@ -34,7 +44,7 @@ Please note that rewards schemes for token release is the responsibility of the
3444

3545
# Initialization
3646

37-
Initialization includes creating the native token on Cardano, writing the `VFunction`, running the commands `smart-contracts reserve init` and `smart-contracts reserve create` at the `partner-chains-node` side.
47+
Initialization includes creating the native token on Cardano, writing the `VFunction`, running the commands `smart-contracts bridge init` and `smart-contracts reserve create-utxos`, `smart-contracts reserve init`, and `smart-contracts reserve create` at the `partner-chains-node` side.
3848

3949
## 1. Setting up your token on Cardano
4050

@@ -60,26 +70,17 @@ Generally speaking, however, the process includes these steps:
6070

6171
### 1.2 Configuring the token release schedule
6272

73+
The release schedule is only required if the reserve feature is used.
74+
6375
#### 1.2.1 Implementing V(t) release function
6476

6577
**Understanding the `VFunction`:**
6678

6779
- The `VFunction` policy defines the schedule of allowed reserve token movement from the reserve supply to the circulating supply over time
6880

69-
- `VFunction` is a minting policy that has to accept 2 parameters (or more if you like)
70-
71-
- The first parameter is the `VFunction` Redeemer (which can be anything)
72-
- The second parameter is the `ScriptContext` (every smart contract takes this as parameter)
73-
74-
- The Validity interval is to be present and equal to `[T, infinity]`, where `T` is time in the recent past, close to the current time
81+
- `VFunction` is a minting policy. Offchain code will apply `ScriptContext` with the validity interval start of `T`, where `T` is the timestamp of currently observed chain tip.
7582

76-
- The Transaction input with ReserveAuthPolicy token is to be present
77-
78-
- The `VFunction` should be able to mint X tokens and be invoked repeatedly, each time minting X new tokens. The value of X should grow in time and represent the total number of tokens to be released from the reserve to IlliquidCirculationSupply up to the current moment in time
79-
80-
- Smart contracts do not pass anything to each other directly. However, each smart contract in a given single transaction has access to the context of the whole transaction, including input UTXOs, datums, etc
81-
82-
- Implementers of the `VFunction` should expect the validity interval to be correctly set up by the offchain release command.
83+
- The `VFunction` should allow to mint at most the maximum number of tokens that are allowed to be released from the reserve until `T`.
8384

8485
**User responsibility:**
8586

@@ -129,6 +130,38 @@ cardano-cli conway transaction submit --tx-file tx.signed --testnet-magic 2
129130

130131
5. Find and note the hash#id for the transaction that has the `VFunction` script attached.
131132

133+
### 1.3 Initializing bridge scripts
134+
135+
Objective: Initialize the bridge scripts for your partner chain.
136+
137+
#### 1.3.1 Run the `bridge init` command
138+
139+
Command template:
140+
141+
```bash
142+
./partner-chains-node smart-contracts bridge init \
143+
--genesis-utxo <GENESIS_UTXO> \
144+
--ogmios-url <OGMIOS_URL> \
145+
--payment-key-file <PAYMENT_KEY_FILE>
146+
```
147+
148+
The command is idempotent. If it fails at first attempt it is safe to repeat execution.
149+
The command is a governance action, so it might not submit transactions but instead output the transactions to sign.
150+
151+
#### 1.3.2 Run the `bridge create-utxos` command
152+
153+
Command template:
154+
155+
```bash
156+
./partner-chains-node smart-contracts bridge create-utxos \
157+
--genesis-utxo <GENESIS_UTXO> \
158+
--ogmios-url <OGMIOS_URL> \
159+
--payment-key-file <PAYMENT_KEY_FILE> \
160+
--amount <AMOUNT>
161+
```
162+
163+
The command is a governance action, so it might not submit transactions but instead output the transactions to sign.
164+
132165
### 1.3 Initializing token reserve controls
133166

134167
Objective: Initialize the reserve management system for your token.
@@ -207,9 +240,9 @@ Usage includes the `reserve release` and `reserve handover` commands.
207240
- `reserve handover` &ndash; a command for finishing the flow (either there is nothing to release or the governance authority user wants to finish the flow)
208241
- `reserve release` &ndash; a command to "move" the flow until the end.
209242

210-
## 2. Releasing tokens from reserve to circulation
243+
## 2. Releasing tokens from Cardano Reserve to bridge
211244

212-
Objective: Release available reserve tokens (defined by the `VFunction`).
245+
Objective: Release available reserve tokens (maximum amount is bounded by `VFunction`)
213246

214247
### 2.1 Run the `reserve release` command
215248

@@ -301,23 +334,27 @@ Objective: increase the pool of reserve tokens.
301334

302335
# Configuration
303336

304-
Configuration includes `reserve update-settings` commands used to either change token in reserve or `VFunction`.
337+
Configuration includes `reserve update-settings` commands used to change the `VFunction`.
305338

306339
<!-- Only "initialize", "create" and "update settings" are related to configuration. -->
307340

308341
## 4. Connecting your token to your partner chain
309342

310343
### 4.1 Gathering required token parameters
311344

312-
Objective: Collect the essential parameters needed to configure the native token management contract on the partner chain.
345+
Objective: Collect the essential parameters needed to configure the bridge pallet on the partner chain.
313346

314347
#### Required parameters
315348

316-
- NATIVE_TOKEN_POLICY_ID - the policy ID from Step 1.1
349+
- tokenPolicyId - the policy ID from Step 1.1
350+
351+
- tokenAssetName - the asset name from Step 1.1
352+
353+
- IlliquidCirculationSupplyValidatorAddress - can be obtained from the output of the `get-scripts` command (see below).
317354

318-
- NATIVE_TOKEN_ASSET_NAME - the asset name from Step 1.1
355+
- dataCheckpoint - it is the lower bound of observability. Chain Genesis UTXO is a good candidate,
356+
but it can be any UTXO on Cardano, created before the first bridge transfer that should be registered by the Partner Chain
319357

320-
- ILLIQUID_SUPPLY_VALIDATOR_ADDRESS - can be obtained from the output of the `get-scripts` command (see below).
321358

322359
#### 4.1.1 Retrieving the validator address
323360

@@ -341,13 +378,13 @@ Locate the validator address in the command output:
341378
}
342379
```
343380

344-
### 4.2 Following the native token migration guide
381+
### 4.2 Following the bridge migration guide
345382

346383
Objective: Migrate and synchronize the token state between Cardano and the partner chain.
347384

348385
#### Steps
349386

350-
1. Open the [native token migration guide](https://github.com/input-output-hk/partner-chains/blob/master/docs/developer-guides/native-token-migration-guide.md).
387+
1. Open the [bridge migration guide](https://github.com/input-output-hk/partner-chains/blob/master/docs/developer-guides/bridge-migration-guide.md).
351388

352389
2. Follow each step outlined in the guide.
353390

@@ -361,13 +398,13 @@ Objective: Update native token configuration if migration has already happened.
361398

362399
**Warning:** The following steps need to be executed by the governance authority from the sudo account in the Polkadot UI.
363400

364-
1. Run `set_main_chain_scripts` extrinsic on the nativeTokenManagement pallet via the Polkadot UI portal to set the native token `policy ID`, `asset name`, and `illiquid supply validator address`.
401+
1. Run `set_main_chain_scripts` extrinsic on the bridge pallet via the Polkadot UI portal to set the native token `tokenPolicyId`, `tokenAssetName`, `IlliquidCirculationSupplyValidatorAddress`, and `dataCheckpoint`.
365402

366403
![Polkadot UI portal](Polkadot-UI-portal-native-token-mgt.png)
367404

368405
2. After submitting a transaction, the native token configuration can be checked via the Polkadot UI portal: developer → chain state
369406

370-
- `selected state query`: nativeTokenManagement → mainchainScriptsConfiguration
407+
- `selected state query`: bridge → mainchainScriptsConfiguration
371408

372409
Example native token configuration:
373410

docs/developer-guides/native-token-migration-guide.md renamed to docs/developer-guides/bridge-migration-guide.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Native Token Management - Migration Guide
1+
# Bridge - Migration Guide
22

33
## About
44

5-
This document describes how to add the Native Token Management features to an already running
5+
This document describes how to add the Bridge features to an already running
66
partner chain and how to remove it.
77

88
## Context
99

10-
The Native Token Management feature in the Partner Chain Toolkit consists of the pallet,
10+
The Bridge feature in the Partner Chain Toolkit consists of the pallet,
1111
the primitives crate, and the supporting DB-Sync data source. It complements the main chain component by providing its observability.
1212

1313
Care must be taken when adding this feature to a running chain, because the data source and inherent
1414
data provider require runtime data for operation.
1515

1616
## Obtaining the main chain scripts
1717

18-
The native token management observability is configured using the following parameters:
19-
* `illiquid supply validator address` - this is the address to which the native tokens are sent on the
18+
The bridge observability is configured using the following parameters:
19+
* `illiquid supply validator address` - this is the address to which the native tokens are sent on the
2020
main chain to lock them so that they can be unlocked on the partner chain. This address is derived
2121
from the sidechain params and is present in the output of the `addresses` command of the
2222
`partner-chains-smart-contracts` CLI under `addresses/IlliquidCirculationSupplyValidator`.
@@ -26,16 +26,18 @@ used to represent the partner chain's token on the main chain. Because each nati
2626
different logic in its minting policy, development and creation of the asset is left for each
2727
partner chain builder.
2828
When using the `partner-chains-cli` wizard, these can be set up in the `prepare-configuration` step.
29+
* `data checkpoint` - this is the UTXO that determines the oldest transaction that observability will take into account,
30+
chain genesis UTXO is a safe value to use.
2931

3032
## Migration Steps - adding the feature
3133

3234
```mermaid
3335
flowchart TB
34-
id1["Obtain native token parameters from configuration"] --> id2["Update partner chain source code"] --> id3["Build new partner chain version"] --> id4["Deploy new partner chain version"] --> id5["Upgrade runtime"] --> id6["Set native token parameters"]
36+
id1["Obtain native token parameters from configuration"] --> id2["Update partner chain source code"] --> id3["Build new partner chain version"] --> id4["Deploy new partner chain version"] --> id5["Upgrade runtime"] --> id6["Set native token and data checkpoint parameters"]
3537
```
3638

3739
### Preparing changes
38-
1. Add the `native-token-management` pallet into the runtime. This requires implementing the trait `TokenTransferHandler`, which
40+
1. Add the `bridge` pallet into the runtime. This requires implementing the trait `TransferHandler`, which
3941
is left for the developers of each particular partner chain to implement according to their needs and
4042
ledger structure. Consult the implementation in `runtime/src/lib.rs` for an example with a mocked handler.
4143
2. Wire the data source into the node.
@@ -51,13 +53,13 @@ The following steps need to be performed in order:
5153
1. Upgrade the nodes running the chain to the new node version containing the inherent data provider.
5254
2. Perform a [runtime upgrade](https://docs.substrate.io/maintain/runtime-upgrades/) (using `sudo` or other governance feature) to the new runtime version containing the pallet.
5355
3. Invoke the `set_main_chain_scripts` extrinsic on the newly added pallet, using the governance mechanism,
54-
to set the native token `policy ID` and `asset name`, and the `illiquid supply validator address`. After
56+
to set the `tokenPolicyId`, `tokenAssetName`, `IlliquidCirculationSupplyValidatorAddress`, and `dataCheckpoint`. After
5557
this step all information necessary is present, and the native token data provider will start producing
56-
the inherent data based on observed native token transfers, triggering the pallet's inherent when necessary.
58+
the inherent data based on observed native token transfers, triggering the pallet's inherent when necessary.
5759

5860
## Migration Steps - removing the feature
5961

60-
1. Remove the pallet completely from the runtime. The `TokenTransferHandler` can be removed as well. To support syncing and validating historical blocks, the data source and inherent data provider *must* not be removed from the node.
62+
1. Remove the pallet completely from the runtime. The `TransferHandler` can be removed as well. To support syncing and validating historical blocks, the data source and inherent data provider *must* not be removed from the node.
6163
2. Perform [runtime upgrade](https://docs.substrate.io/maintain/runtime-upgrades/).
6264

6365
After this step _no further native token movement will be observed, even if performed on the main chain_.

docs/developer-guides/sdk-update-v1.7-to-v1.8.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ fn current_time() -> u64 {
6060
pallet_timestamp::Now::<Runtime>::get() / 1000
6161
}
6262
```
63+
64+
## Bridge
65+
66+
For the bridge please read documents specific to this feature: [operational guide](./bridge-and-reserve.md) and [migration guide](./bridge-migration-guide.md)

0 commit comments

Comments
 (0)