Skip to content
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@
"zerostate",
"ensurepip",
"Buildx",
"underperforming"
"underperforming",
"blackhole"
],
"ignoreRegExpList": [
"\\(#.*\\)",
Expand Down
190 changes: 99 additions & 91 deletions docs/v3/documentation/infra/crosschain/bridge-addresses.md

Large diffs are not rendered by default.

35 changes: 16 additions & 19 deletions docs/v3/documentation/infra/crosschain/overview.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
# Cross-chain bridges

Decentralized cross-chain bridges operate on TON Blockchain, allowing you to transfer assets from TON Blockchain to other blockchains and vice versa.
Decentralized cross-chain bridges function on the TON Blockchain, allowing asset transfers between this blockchain and the others.

## Toncoin Bridge
## Toncoin bridge

The Toncoin bridge allows you to transfer Toncoin between TON Blockchain and the Ethereum blockchain, as well as between TON Blockchain and the BNB Smart Chain.
The Toncoin bridge enables transfers of Toncoin between the TON and Ethereum Blockchain and between the TON and the BSC (BNB Smart Chain).

The bridge is managed by [decentralized oracles](/v3/documentation/infra/crosschain/bridge-addresses).
This bridge is managed by [decentralized oracles](/v3/documentation/infra/crosschain/bridge-addresses).

### How to use it:
### How to use it

The bridge frontend is hosted on https://ton.org/bridge.
The bridge frontend is hosted [here](https://ton.org/bridge).

:::info
[Bridge frontend source code](https://github.com/ton-blockchain/bridge)
:::

### TON-Ethereum smart contracts source codes
### Smart Contract source codes

#### TON-Ethereum

* [FunC (TON side)](https://github.com/ton-blockchain/bridge-func)
* [Solidity (Ethereum side)](https://github.com/ton-blockchain/bridge-solidity/tree/eth_mainnet)


### TON-BNB Smart Chain smart contracts source codes
#### TON-BSC (BNB Smart Chain)

* [FunC (TON side)](https://github.com/ton-blockchain/bridge-func/tree/bsc)
* [Solidity (BSC side)](https://github.com/ton-blockchain/bridge-solidity/tree/bsc_mainnet)

### Blockchain configurations

### Blockchain Configs

You can get the actual bridge smart contract addresses and oracle addresses by inspecting the corresponding config:

TON-Ethereum: [#71](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L738).

TON-BSC: [#72](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L739).

TON-Polygon: [#73](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L740).
You can find the current bridge smart contract addresses and oracle addresses by checking the corresponding configuration:

* TON-Ethereum: [#71](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L738)
* TON-BSC: [#72](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L739)
* TON-Polygon: [#73](https://github.com/ton-blockchain/ton/blob/35d17249e6b54d67a5781ebf26e4ee98e56c1e50/crypto/block/block.tlb#L740)

### Documentation

* [How the bridge works](https://github.com/ton-blockchain/TIPs/issues/24)

### Cross-chain roadmap

* https://t.me/tonblockchain/146
* [@The Open Network](https://t.me/tonblockchain/146)
59 changes: 33 additions & 26 deletions docs/v3/documentation/infra/minter-flow.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
# Extra Currency Minting
# Extra currency minting

## Extracurrency
According to [Ton Blockchain Whitepaper 3.1.6](https://ton-blockchain.github.io/docs/tblkch.pdf#page=55), TON Blockchain allows its users to define arbitrary cryptocurrencies or tokens apart from the Toncoin, provided some conditions are met. Such additional cryptocurrencies are identified by 32-bit _currency\_ids_. The list of defined additional cryptocurrencies is a part of the blockchain configuration,
stored in the masterchain. Each internal message as well as account balance contains a special field for `ExtraCurrencyCollection` (set of extracurrencies attached to a message or kept on balance):

According to [TON Blockchain Whitepaper 3.1.6](https://ton-blockchain.github.io/docs/tblkch.pdf#page=55), the TON Blockchain allows users to create arbitrary cryptocurrencies or tokens, in addition to the Toncoin, provided certain conditions are met. These additional cryptocurrencies are identified by 32-bit **currency\_ids**. The list of these defined cryptocurrencies is a part of the blockchain configuration stored in the MasterChain. Each internal message and account balance includes a special field for `ExtraCurrencyCollection`, which is a set of extracurrencies attached to a message or maintained in a balance:

```tlb
extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32)) = ExtraCurrencyCollection;
currencies$_ grams:Grams other:ExtraCurrencyCollection = CurrencyCollection;
```

## Extracurrency config
A dictionary, or to be precise `ExtraCurrencyCollection`, of all currencies that should be minted is stored in `ConfigParam7`:

A dictionary, specifically `ExtraCurrencyCollection`, containing all currencies to be minted is stored in `ConfigParam7`:

```tlb
_ to_mint:ExtraCurrencyCollection = ConfigParam 7;
```

`ConfigParam 6` contains data related to minting:
`ConfigParam 6` contains data related to the minting:

```tlb
_ mint_new_price:Grams mint_add_price:Grams = ConfigParam 6;
```

`ConfigParam2` contains address of _Minter_.


`ConfigParam2` contains the address of **Minter**.

## Low-level minting flow
In each block, the collator compares the old global balance (global balance of all currencies at the end of prev block) with `ConfigParam7`. If any amount for any currency in `ConfigParam7` is less than it is in the global balance - the config is invalid. If any amount of any currency in `ConfigParam7` is higher than it is in the global balance a minting message will be created.

This minting message has source `-1:0000000000000000000000000000000000000000000000000000000000000000` and _Minter_ from `ConfigParam2` as destination and contains excesses of extracurrencies in `ConfigParam7` over old global balance.
In each block, the collator compares the old global balance (the global balance of all currencies at the end of the previous block) with `ConfigParam7`. If any amount for any currency in `ConfigParam7` is less than it is in the global balance, the config is invalid. If any amount of any currency in `ConfigParam7` is higher than it is in the global balance, a minting message will be created.

This minting message has source `-1:0000000000000000000000000000000000000000000000000000000000000000` and **Minter** from `ConfigParam2` as destination and contains excesses of extracurrencies in `ConfigParam7` over the old global balance.

The issue here is that the minting message contains extra currencies only and no TON coins. That means that even if _Minter_ is set as a fundamental smart contract (presented in `ConfigParam31`), a minting message will cause the aborted transaction: `compute_ph:(tr_phase_compute_skipped reason:cskip_no_gas)`.
The problem here is that the minting message includes only additional currencies and no Toncoins. As a result, even if the **Minter** is designated as a fundamental smart contract (as indicated in `ConfigParam31`), a minting message will lead to an aborted transaction with the error: `compute_ph:(tr_phase_compute_skipped reason:cskip_no_gas)`.

## High-level minting flow
One of possible high-level minting flows implemented [here](https://github.com/ton-blockchain/governance-contract/tree/50ed2ecacc9e3cff4c77cbcc69aa07b39f5c46a2) (check `*.tolk` files) is as following:

1. There is `ExtraCurrencyAuthorizationConfig`: it is config that contains information which contracts (addresses) has authorization to request minter to mint new extracurrencies. This config has the following scheme:
One possible high-level minting flow, which is implemented [here](https://github.com/ton-blockchain/governance-contract/tree/50ed2ecacc9e3cff4c77cbcc69aa07b39f5c46a2) (check `*.tolk` files) is as follows:

1. There is `ExtraCurrencyAuthorizationConfig`: the config contains information on which contracts (addresses) have authorization to request minter to mint new extracurrencies. This config has the following scheme:

```tlb
_ (Hashmap 32 std_addr) = ExtraCurrencyAuthorizationConfig;
```
where key - `currency_id` and `std_addr` is _admin_ of this currency (can be in any workchain).
2. Minter accepts mint requests from _admins_, forwards request for mint to Config, Config updates `ConfigParam 7` and responses to Minter. Since extracurrencies would be minted to Minter only on next masterchain block, withdrawing extracurrencies to _admin_ should be delayed. It is done via _Echo_ smart-contract not in masterchain. When response from _Echo_ came to Minter it sends extracurrencies to _admin_. So the scheme is as follows `Admin -> Minter -> Config -> Minter -> Echo (in other workchain to wait until the next masterchain block) -> Minter -> Admin`.

Example of such flow: [minting 2'000'000'000 units of `currency_id=100`](https://testnet.tonviewer.com/transaction/20fe328c04b4896acecb6e96aaebfe6fef90dcc1441e27049302f29770904ef0)
where key - `currency_id` and `std_addr` is _admin_ of this currency (can be in any WorkChain).

2. Minter accepts mint requests from **admins**, forwards requests for mint to **Config**, **Config** updates `ConfigParam 7`, and responds to **Minter**. Since extracurrencies would be minted to **Minter** only on the next MasterChain block, withdrawing extra currencies to **admin** should be delayed. It is done via **Echo** smart-contract, not in MasterChain. When a response from **Echo** comes to **Minter**, it sends extracurrencies to **admin**. So the scheme is as follows:

`Admin -> Minter -> Config -> Minter -> Echo (in other workchain to wait until the next masterchain block) -> Minter -> Admin`

An example of this flow is as follows: [minting 2'000'000'000 units of `currency_id=100`](https://testnet.tonviewer.com/transaction/20fe328c04b4896acecb6e96aaebfe6fef90dcc1441e27049302f29770904ef0)

:::danger
Each mint of new extracurrency or increasing supply of existing one requires change of ConfigParam 7, thus changing config and creation keyblock. Too frequent keyblocks slows down shards (each keyblock leads to rotation of validator groups) and lite-client sync. Thus contracts like swap.tolk should not be used in production. Instead schemes with reserves, that minimize minting events, need to be used.
Each minting of new extracurrency or an increase in the supply of existing currency necessitates a change to `ConfigParam7`, which in turn alters the configuration and creation of keyblocks. Frequent keyblock generation can slow down shard performance since each key block causes a rotation of validator groups and affects the synchronization of liteclients. Therefore, contracts like `swap.tolk` should not be utilized in production environments. Instead, it is advisable to use schemes that involve reserves to minimize minting events.
:::


:::Info
Sending of extracurrency to blackhole has the following effect: extracurrency amount is burnt, but since ConfigParam 7 is not changed, on next block Minter will receive burnt amount on it's balance.
:::info
Sending of extracurrency to blackhole has the following effect: extracurrency amount is burnt, but since `ConfigParam7` is not changed, on the next block, **Minter** will receive the burnt amount on its balance.
:::

## Bird-eye minting flow
How to mint your own extracurrency:
1. Ensure your network has Minter Contract and ConfigParam 2, ConfigParam 6 set.
2. Create Currency Admin contract that controls how extracurrency is minted.
3. Create proposal to validators to add your Currency Admin contract address to ExtraCurrencyAuthorizationConfig for some `currency_id`, and get it accepted.
4. Send `mint` request from Currency Admin contract to Minter. Wait till Minter send back extracurrency.

## How to mint your own extracurrency

1. Ensure that your network has the **Minter Contract** and that `ConfigParam2` and `ConfigParam6` are set correctly.

2. Create a **Currency Admin Contract** that will control how the extra currency is minted.

3. Submit a proposal to the validators to add your **Currency Admin** contract address to the `ExtraCurrencyAuthorizationConfig` for a specific `currency_id` and obtain their approval.

4. Send a `mint` request from the **Currency Admin Contract** to the **Minter**. Wait for the **Minter** to return the extra currency.
Loading
Loading