Technical Overview
Here we have Technical overview of the T3 system
T3 Technical Overview
An overview of T3 contracts and mechanics.
Software Architecture
The main components of the platform are:
Vault
Routers
Price Feeds
GMX
GLP
Molecule Integration
The Vault contract stores deposits and handles the main trading functions.
Deposits: Funds are deposited into the Vault through the minting of TLP tokens. e.g. if the price of TLP is $1.50, a user can mint 1 TLP by depositing 1.50 USDC tokens.
Withdrawals: Funds can be withdrawn from the vault through the burning of TLP tokens. e.g. if the price of TLP is $1.50, a user can burn 1 TLP to redeem 1.50 USDC tokens.
Swaps: The vault allows swapping of the tokens held in the vault. e.g. if the price of ETH is $5000 a user can swap 1 ETH for 5000 USDC through the swap function of the vault.
Longing: Users can open a long position using the vault. e.g. to open a long, a user can deposit 1 ETH into the vault and open a position of $25,000, if the price of ETH at the time of opening the position is $5000, then this would be a 5x long position. If the price of ETH increases by 10%, the user would make a profit of $25,000 * 10% = $2500. A snapshot of the collateral is taken when the position is opened, so in this example, the collateral would be recorded as $5000 and will not change even if the price of ETH changes. To ensure the vault has sufficient funds to pay out any profits, an amount of ETH equivalent to the position’s size is marked as reserved, for this position, 5 ETH in the vault would be reserved.
Shorting: Users can open a short position using the vault. e.g. to open a short, a user can deposit 5000 USDC into the vault and open a position of $25,000. Stablecoins are required as collateral for shorts and similar to longs, an amount of stablecoins equivalent to the size of the position would be reserved to pay out any profits.
Liquidations: A position can be liquidated by keepers if the losses of the position reduces the collateral to the point where
position size / remaining collateralis more than the max allowed leverage.
Router
The Router contracts provide convenience functions on top of the vault. e.g. the vault requires tokens to be sent to it then the swap function called to execute the swap, the router handles transferring the tokens to the vault as well as wrapping / unwrapping of native tokens if required.
The PositionRouter contract handles a two part transaction process for increasing or decreasing long / short positions, this process helps to reduce front-running issues:
A user sends the request to increase / decrease a position to the PositionRouter
A keeper requests the index price from an aggregate of exchanges
The keeper then executes the position at the current index price
If the position cannot be executed within the allowed slippage the request is cancelled and the funds are sent back to the user
A user can execute the position on their own if three minutes have passed between the request transaction and the execution transaction. The function of the position keepers is to provide convenience and the protocol can continue to operate even without these keepers.
For swaps, the base fee is 0.25%, while price feeds update within 0.12% price movements, this helps to reduce front-running issues.
Price Feeds
The PriceFeed contract accepts submissions from the chainlink price feed Aggregator contracts
The vault uses the price from Chainlink
For liquidations, these can only occur if the Chainlink price reaches the liquidation price for a position.
As the price feed contract may be updated to improve its security, the most reliable way to find the contract address for it would be to check the value of Vault.priceFeed.
TMX
TMX is the governance token of the platform, it is a regular ERC20 token that can be staked for rewards.
TLP
TLP is the liquidity provider token of the platform, it can be minted using any of the tokens within the liquidity pool such as ETH, BTC and USDC.
The token’s price is determined by the worth of all tokens within the pool and factoring in the profits and losses of all currently opened positions.
Access Control
Parameters that can be adjusted by a controller account currently controlled by the team
Setting of swap and margin trading fees up to a maximum of 5%
Setting of token weights for the TLP pool, token weights affect the dynamic fees of swaps, these fees are such that a swap which increases the balance towards the specified token weight will be lower, while a swap that moves the token weight away from the desired amounts will have higher fees, the details of the calculation can be found from
Vault.vaultUtils.getSwapFeeBasisPointsPausing of swaps or leverage trading for emergency use
Setting of the maximum allowed leverage
Setting of maximum total capacity for long and short positions
Parameters that can be adjusted by a Timelock controlled by team:
Listing of new tokens
Updating
Vault.priceFeedUpdating
Vault.vaultUtils, the VaultUtils contract validates the opening and closing of positions and also specifies how fees are calculatedUpdating of
govvalues
The Timelock works by requiring a 15 Minutes gap between when the full details of an action is signalled on-chain to when the action is executed. An example flow would be:
Timelock.signalSetPriceFeedis called, this specifies the Vault address and the address of the new price feedAt least 5 Minutes must pass
Timelock.setPriceFeedcan be called, this will update theVault.priceFeedvalue
15 Minutes was selected as it helps to be able to respond quickly to any issues that may occur.
In the event of a malicious transaction being sent, it is possible for all funds in the pool to be compromised. To mitigate this, all actions which can impact user funds must pass through the signal, time gap, execute process mentioned above. If a malicious transactions is detected through the monitoring process or Bug Bounty, a multi-sig consisting of advisors and team members can be used to override the Timelock.admin value, this would prevent the action from being executed. This also applies for actions such as pausing trading when there was no need to, in this case, the admin can be replaced by the multi-sig and trading can be re-activated.
Note that the multi-sig can only override the admin value, it cannot bypass the time gap required for Timelock actions.
Upgradeability
The core logic of the T3 contracts cannot be changed, but certain peripheral functions such as fee and pricing calculations can be updated. This update is done by implementing new fee / pricing contracts and updating the core contracts to use the new contracts. For example, the Vault contract has a priceFeed value that can be changed by the Timelock contract described in the Access Control section.
Front Running Attack Mitigations
Front running attacks are mitigated through the two step transaction process and swap fees.
Flash Loan Attack Mitigations
Opening and closing of positions as well as swaps, minting and redeeming of TLP are settled at the oracle price covered in the Price Feeds section since these prices are not dependent on pool composition or parameters like long / short ratios, so a flash loan would not have an impact on these functions. The dynamic fees for swaps are dependent on pool composition, however, this does not lead to positive slippage so the maximum benefit from a flash loan would be a zero fee swap which adjusts pool composition towards the desired token weights.
Molecule Integrations in T3 System
Overview of Integration
The integration of the Molecule Controller contract within the T3 system is a pivotal aspect, as it governs access across the platform. This integration is primarily embedded within three critical contracts of the T3 system: the Router, GLP Manager, and the OrderBook contract. The inclusion of the Molecule Controller Contract in these contracts is essential for regulating user access and ensuring compliance with defined protocols.
Access Control Mechanism
Each of these contracts - the Router, GLP Manager, and the OrderBook - is equipped with a setMoleculeController function. This function is a cornerstone in gating the T3 system, thereby controlling user access. It plays a crucial role in maintaining the integrity and security of the platform by ensuring that only users who comply with the Molecule Protocol's standards can interact with the core functionalities of the T3 system.
Compliance and User Accessibility
The compliance parameters are set based on the Chainalysis sanction list and an Access list, which is determined by user sign-up activities. This means that only users who are not flagged on the Chainalysis sanction list and who are recognized as legitimate through the sign-up process can engage with the T3 system’s fundamental operations. These operations include creating long/short positions, executing swaps, and managing liquidity (both adding and removing).
Last updated