We designed a modular DEX that leverages TON's sharding to distribute load during congestion, ensuring smooth and uninterrupted transactions.
The Asset structure enables the protocol to handle different types of assets with the same logic, including Jetton, TON, XC, and potentially new token standards in the future.
We use a 4-bit prefix to distinguish asset types, which can be checked using preload_uint(4)
.
Additional token information may be stored after the 4-bit prefix.
$0000
), represents TON.
begin_cell().store_uint(0, 4).end_cell()
$0001
), represents Jetton v1.
begin_cell().store_uint(1, 4).store_slice(jetton master address, must not be empty).end_cell()
$0010
), represents extra currency.
begin_cell().store_uint(2, 4).store_int(token id, 32).end_cell()
The Factory is responsible for deploying all Torch contracts, including Vaults, Pools, and LP Accounts.
In addition to handling contract deployment, the Factory stores admin-related information for Pools and plays a key role in the deposit process. Based on user deposits, the Factory deploys dedicated LP Account contracts for each user.
This design keeps the Torch system running smoothly and everything working together seamlessly.
Torch currently supports TON Vault and Jetton Vault (with future plans for Extra-Currency Vault). These Vault contracts manage user assets, storing them directly within the Vault.
Simplified Pool Logic
Optimized for Different Assets
Efficient Transactions
Easy Cross-Pool Operations
Torch’s Vault system ensures efficient asset management, scalability, and seamless growth in the evolving DeFi landscape.
As mentioned earlier, pool contract handles mathematical logic and does not manage assets. This allows us to expand and implement various Pool types with different formulas (such as Weighted Pools). Currently, Torch has two types of Pools:
This structure provides flexibility and scalability, supporting diverse liquidity needs across the Torch ecosystem.
The LP Account waits until all assets from the user's deposit have been received. Once the assets are confirmed, the LP Account sends an op::deposit_all
message to notify the Pool of the liquidity provided by the user.
If the user deposits only one asset, an LP Account contract is not created. Instead, the Vault directly notifies the Pool upon receiving the asset.
To provide liquidity to Torch Finance's N-asset pool, users can choose to deposit between 1 to N assets. Since TON operates as an asynchronous system, the deposit process follows these steps:
Asset Deposit into Vault
Vault Notifies Factory
op::deposit_internal
message to the Factory.Factory Deploys LP Account
All Assets Deposited
op::deposit_all
message to the Pool with deposit details.Pool Calculates and Notifies Lp Vault
op::payout
to the Pool’s LP Vault, instructing it to transfer LP tokens to the user’s designated recipient.Cross-Pool Deposits Operations
op::deposit_between
or op::swap_between
message to the next pool for further processing.You might wonder:
When does the LP Vault come into play, and why does it already hold LP tokens for transfer?
This is because, during Pool creation, Torch automatically performs the following:
Simplified Pool Logic
Efficient Cross-Pool Operations
This design enhances system efficiency, lowers costs during high-frequency trades or cross-pool operations, and streamlines asset management across the Torch ecosystem.
When depositing to Torch Finance, users are advised to deposit assets in balanced proportions to minimize fees during the deposit process. The more balanced the deposit, the lower the fees, improving the efficiency and cost-effectiveness of liquidity provision.
Depositing assets in highly unbalanced proportions may result in higher fees. While this typically only occurs when depositing large amounts, maintaining balanced deposits can significantly reduce costs and avoid unnecessary fees.
Suppose the price of stTON is 1.0428 TON and tsTON is 1.036 TON. Users are encouraged to deposit assets according to the following ratio:
Depositing in this proportion helps minimize fees and ensures optimal asset balance.
For example, in the triTON Pool, if a user deposits assets in severely unbalanced amounts:
Such highly disproportionate deposits will result in significant fees and are strongly discouraged.
By maintaining balanced asset ratios, users can optimize deposit costs, enhance the deposit experience, and avoid unnecessary fee expenses.
Torch’s Stable Swap mechanism effectively reduces slippage during swaps, providing a more cost-efficient trading experience. Below is a detailed breakdown of the swap process:
Asset Transfer to Vault
Vault Notifies Pool
op::swap_internal
message to the Pool contract, initiating the swap calculation.Pool Calculates and Notifies Vault
op::payout
message to the Vault responsible for the swap out asset.Cross-Pool Swap Operations
op::swap_between
or op::withdraw_between
message to the next Pool to continue the swap process.Torch supports multiple withdrawal methods to meet different liquidity needs. Below is a detailed breakdown of the withdrawal process:
Transfer LP Tokens to LP Vault
LP Vault Notifies Pool
op::withdraw_internal
message to the Pool, notifying it of the withdrawal request and relevant details.Pool Calculates and Notifies Vault
op::payout
message to the Vault.Cross-Pool Withdrawal Operations
op::withdraw_between
message to the next Pool to continue the process.Torch currently supports two types of withdrawals:
Withdraw All
Withdraw One
Let's assume there are two pools:
Suppose you currently hold stTON and hTON and want to maximize your rewards. You can achieve this through a deposit and deposit process.
Here’s how it works:
op::deposit_all
message to the triTON Pool to process the stTON deposit.op::deposit_between
message to the quaTON Pool.For a complete view of the process, please refer to the diagram.
This process can also be performed using only the assets within the triTON Pool, without the need for hTON. In such cases, users can still achieve the deposit and deposit operation by utilizing assets directly from the Base Pool.
In the following example, the scenario typically involves users swapping Token A for Token B, a process that may involve multiple pools.
Continuing from the previous example, suppose you currently hold stTON and want to swap it for hTON. This can be achieved through a deposit and swap process.
Here’s how it works:
op::payout
to the LP Vault.op::swap_between
message to the quaTON Pool to initiate the swap.op::payout
message to the hTON vault, transferring hTON to the user’s designated address.Continuing from the previous Deposit and Swap example, this time we perform the reverse operation through Swap and Withdraw to convert assets from hTON to stTON.
Suppose you currently hold hTON and want to swap it for stTON. This can be done through the following steps:
op::payout
to the stTON Vault directly.op::withdraw_between
message to the triTON Pool to initiate the withdrawal process.op::payout
message to the stTON Vault, transferring the assets to the user’s designated address.Continuing from the previous Deposit and Deposit example, this time we perform the reverse operation through Withdraw and Withdraw to convert assets from quaTON LP to stTON in the triTON Pool.
Suppose you currently hold quaTON LP and want to convert it to stTON in the triTON Pool. This can be achieved through the following steps:
op::payout
to the triTON LP Vault.op::withdraw_between
message to the triTON Pool to initiate the next withdrawal process.op::payout
message to the stTON Vault, transferring the assets to the user’s designated address.Since Torch supports two withdrawal modes – Withdraw All and Withdraw One – there are four possible combinations during the Withdraw and Withdraw process:
Users can choose the appropriate combination based on their specific needs and desired outcomes.