There are a couple of things that we need to consider before digging deeper into the layout of the application:
- An address on Ethereum has ERC20 tokens balances. To transfer these assets to the Injective Chain, they have to use our existing Peggy bridge.
- After transferring their assets from Ethereum to the Injective Chain, these balances are minted for the user on their Injective Chain address within the bank module. These balances are used for staking, participating in governance, insurance funds, etc.
- To trade on the Injective Chain, the user has to transfer their Injective Chain Balances to a subaccount. One injective address can have multiple subaccounts.
- The list of markets available for spot/perpetuals trading can be fetched using our public API endpoints. There are examples within the
injective-ts
repository that show you how to do this.
- To execute a trade there has to be enough liquidity in that particular market. Injective is orderbook based.
- For the market the user is trying to trade in we have to open a GRPC stream for the market's order book so we can calculate the
executionPrice
of the particular trade we are trying to make (based on the user's input amount).
The ideal application would be composed of three main components:
- Header - Where we are going to show the Injective logo, a way for the user to connect to their wallet and their address once they are connected.
- Main Content - Where we are going to have the simple trading interface,
- Footer - Where we should show a copyright copy and Injective's social media icons
Here are some guidelines about the simple trading interface:
- Market (asset) selection,
- Subaccount balances based on the selection,
- Approximate execution price and total cost of the trade,
- Validation of the user's input based on their current subaccount holdings and orderbook liquidity,
Here are the functionalities that we need to support:
- User wallet connection
- List of supported assets (markets) to trade
- Executing trades within the simple interface - both for spot and perpetual:
- Calculating the execution price based on the amount and market's current orderbook state,
- Composing the message, packing it into a transaction and broadcasting it to the Injective Chain
- Updating the user's subaccount balances based on the action they performed
- Showing the user's open position for perpetual trades
- [Bonus] List of subaccount balances
- [Bonus] Subaccount deposit modal
- [Bonus] Peggy Bridge transfer modal