Position as NFTs

Redefining how trading data is stored
In LEXER, aiming to offer the feature of cross-margin to users, we reimagined how the trading data are stored and processed, thus creating the concept of position as a token. This is one of the many innovations made by LEXER to offer a better trading experience to the user in the DeFi space.
Position as a token means that all positions in LEXER are NFTs, with all of its trading metadata fully stored on-chain. As the position is the NFT itself, The owner can freely transfer the position to any other address with adding benefits like adding collateral with any address, etc. This creates the flexibility of treating the position itself as an asset.
With position as a token, we can build cross-margin on top of the tech, and open a new sector of DeFi. More on that in Cross Margin​


Mechanism - ERC721L

To enable position as a token, we have created an extension of ERC721, into what we called ERC721L. This extension focuses on modifying the existing ERC721 standard to accommodate storing position as a token. A few modifications included
There are two states of a position, active or closed. When a position is closed, the position NFT should be burned, and the ownership of the token would be transferred to zero address or 0x0. ERC721, however, does not recognize the zero address as a valid holder of an NFT, which is not true in LEXER. If an NFT is owned by the zero address, it automatically implies that the position is already closed. As each position has a unique token ID, anyone can query the blockchain events according to the token ID to query every event that the position has emitted throughout its lifespan. This creates the most accessible and transparent data source in the history of DeFi.
To cope with the computation, such as fetching all the active positions of the platform, ERC721L is also enumerable by default. The enumeration of the tokens are
function tokenOfOwnerByIndex(address owner, uint256 index)
returns (uint256)
require(index < ERC721T.balanceOf(owner), "ERC721T: index out of bounds");
return _ownedTokens[owner][index];
function tokenByIndex(uint256 index) external view returns (uint256) {
require(index < _totalSupply, "ERC721T: index out of bounds");
return _allTokens[index];
ERC721L is based on ERC721 and ERC721Enumerable contracts written by OpenZeppelin and further modified by the LEXER team, we are thankful for their work.


Close position

Since the ownership of a position can be changed, we respect the final ownership of the position at the exit, i.e. the liquidity of the position at close will be transferred to the address that owns the token at the close, regardless of whether it's a wallet address or a contact address.
If you are planning to create custom contracts that allow the deposit of the position tokens, you should also create logic to access the ERC20 funds in the contracts so that they do not get locked up forever.



By restructuring how we store positions, we can achieve the goal of offering cross-margin easily. Since we mitigate the work of handling the mapping of the positions to the users and opened a new sector in using positions as an asset, much like how PFP NFTs would work.
Since every position is an NFT now, users can freely transfer
Tokenizing the positions also allows users to transfer their positions, this enabled us to build our cross-margin mechanism on top of it, read more about it in the section onCross Margin​