Position
Last updated
Last updated
In Dywe, position management is implemented through the interaction of Frontend, Backend and two main contracts: the Master Contract (Master Contract of positions) and User Contract (User Contract).
The process of opening a position involves several steps:
Transaction generation - the user initiates the opening of a position (Open Position) through the platform interface.
Sending data to Master Contract - Frontend forms the transaction and sends it to Master Contract.
Data processing - Master Contract deserialises input parameters and passes them to User Contract, which performs the functions of a database (storing and processing information about positions).
Transaction Status Check - Frontend passes the BOC (Bag of Cells) of the transaction to Backend and requests the status of the transaction.
If the position is successfully opened, the user receives a confirmation.
In case of an error, an appropriate notification is displayed.
Closing a position is performed as follows:
Initiating a close - the user sends the Close Position command through the interface.
Data exchange between contracts
The request is sent to User Contract.
User Contract sends a message to Master Contract containing the parameters of the position to be closed.
Master Contract sends a message to Liquidity Pool specifying the amount of X USDT to be credited to the user.
Liquidity Pool executes the transaction, sending the funds to the user's address.
The process of liquidating a position is similar to closing a position, but with one key difference:
Liquidity Pool makes no payment to the user, as liquidation means a complete loss of margin collateral.
Otherwise, the procedure of data transfer between contracts remains unchanged.
This mechanism ensures reliable trade execution and protects the liquidity of the system.