This repo contains source code for Ton Dex contracts in Tolk and tests/infrastructure for them.
Tests, core logic and environment for this project are reused from the T-Dex, similar project written in Tact. Although, there are some semantic changes, to adapt existing interfaces to Tolk language patterns and idioms.
- Build a fully open-source decentralized exchange (DEX)
- Keep transaction costs low with efficient smart contract design
- Show how to build complex smart contracts using Tolk
- Demonstrate safe patterns for working with Jettons
- Explore Tolk language features in a real production system
This project aims to show core TON smart contract development principles and serve as a foundation for other Jetton-based protocols. We also want to explore how Tolk works for building complex multi-contract systems and what coding patterns and idioms work best.
We follow somewhat common Dex architecture and math - Constant Product Formula Market Maker compatible with Uniswap V2. There is no "protocol fee" implemented since the project is open source, only LP providers fee in pools (however it should be possible to add one).
Dex allows cross-pool and exact-out swaps and implements asset-abstraction model, meaning that the protocol could be extended to allow swaps between any kinds of assets.
Check these docs to learn about how Dex works, its semantics and how to integrate with it.
- How to swap on Dex
- How to manage liquidity
- How to work with Factory, TODO
- How to create new pool and vaults, TODO
To start working, install all dependencies:
yarn install
Build the contracts:
yarn build:tolk
Other useful commands:
Run tests:
yarn test
Lint the code:
yarn lint
Format the code:
yarn fmt
The project uses Jest for testing. Tests are located in the sources/tests
directory and cover various aspects of the T-Dex functionality:
amm-pool.spec.ts
- Tests for the AMM Pool functionalityliquidity-deposit.spec.ts
- Tests for liquidity deposit processliquidity-payloads.spec.ts
- Tests for payload handling in liquidity operationsswap-payloads.spec.ts
- Tests for payload handling in swap operations
To run all tests:
yarn test
TODO: describe Tolk pipeline