Introduction
This page describes overall architecture and possible interactions with staking protocol developed by swap.coffee. User-friendly interface is available at https://swap.coffee/stake, but this document is aiming at providing readers with technical insights, TL-B schemes and others associated complexities. At the time of writing this article, we only support staking protocol for our own product, but we also have plans and are in the process of implementation (by the time you read this, it’s likely already implemented) to support staking protocol for partner products as well.Architecture
Staking protocol consists of 2 on-chain contracts: Master and Vault; integral off-chain backend that is responsible for rewards calciulation; and also interacts with swap.coffee’s rewards distribution system.Master Contract
Master Contract is used both for storing crucial data about protocol itself and keeping funds that are being distributed as a rewards. It is also fully compatible with NFT standard by supporting all related methods of NFT Collection. You may retrieve staking-related information by calling contract’s get methodget_stored_data
, which returns:
1. int initialized
1 for true, 0 for false.
2. slice admin_address
3. slice distributor_address
Technical wallet that is a part of swap.coffee’s rewards distribution system
and which serves as a proxy point for users which want to claim their staking rewards.
4. slice vault_address
Address of a staking Vault Contract associated with this Master Contract.
5. cell state
Cell of the following format:
6. cell rewards
Contains information about the rewards that were (or being) distributed across all the users that
participate(d) in staking.
Cell is being represented as a cell-referencing dictionary, which can be read as follows:
reward_rate
is being calculated in one of the following ways:
7. cell jettons
Unlike many other staking protocols, ours supports staking of not only one specific token, but of any
(pre-defined by the protocol administrator) set of them. One of the purposes of the Master Contract is to be
an entry point to retrieve list of such supported tokens, and this exact cell contains them.
Cell is being represented as a cell-referencing dictionary, which can be read as follows:
8. cell periods
Investment of funds is possible only for one of the predetermined periods, which are stored in this exact cell.
Cell is being represented as a cell-referencing dictionary, which can be read as follows:
Vault Contract
This contract serves both as a storage for users’ staked assets and as a proxy for users’ interactions with the Master Contract.Deposit
New staking position may be created by sending jettons to the Vault Contract with specificforward_payload
: