*Stake NFTs to use assets in-game, with an escape hatch (tracked via address mappings) to allow withdraws trustlessly.*
## Overview
Supremacy is a game that is a hybrid of web2 and web3 technologies. The NFTs were giant mechs, in-game assets used to do battle against other players. The NFTs were also able to be traded across secondary markets. To enable actual use in-game, we have to 'lock' the NFTs when they are being used in the game, otherwise a player might transfer an NFT outside of the game's knowledge.
At the same time, there needs to be the ability to withdraw NFTs out of the game directly via the contract in the event of a rugpull or other catastrophic event. A trustless withdrawal mechanism, which allows players to maintain control of their assets forevermore.
We introduce two concepts:
- Go ***off-world***: Take your mech out of the game, off the planet and into the blockchain
- Go ***on-world***: Enter your mech into the game, onto the planet and off the blockchain
This helps players understand the moving of assets back and forth and hopefully stomach the gas fees required to do so.
## Approach
An ERC721 compatible contract was deployed by extending OpenZeppelin's ERC721 library to manage and mint NFTs.
A separate contract was deployed to implement Staking. We add a mapping of addresses to staked NFTs which is used to track the state of staked assets.
```solidity
mapping(address => mapping(uint256 => stakingStatus)) public records;
```
It requires the following admin functions:
```solidity
function remap(address collection, uint256 tokenId, address newAddr) public onlyOwner
function lock(address collection, uint256 tokenId) public onlyOwner
function unlock(address collection, uint256 tokenId) public onlyOwner
```
And the following user functions:
```solidity
function stake(address collection, uint256 tokenId) public
function unstake(address collection, uint256 tokenId) public
```
## Benefits
Staking NFTs allow gamers to use their assets in-game, because the server knows that they have 'deployed' their mechs and can not move them on a secondary market.
A trustless "escape hatch" allows players to have full control over their assets, increasing trust and decreasing the risk of centralisation.
## Challenges
The existence of secondary (and primary) markets makes it difficult to track ownership of NFTs in a centralised system.
Ideally you don't have the need for staking at all, and the game just 'knows' at any one time who owns what. The problem is that ownership tracking is eventually consistent as the indexer needs to run, scrape, collate, calculate who is owning the NFT.
## References
- [ERC721 non-fungible token standard](https://eips.ethereum.org/EIPS/eip-721)
- [Deployed contract (ETH)](https://etherscan.io/address/0x651D4424F34e6e918D8e4D2Da4dF3DEbDAe83D0C)
- [Supremacy](https://supremacy.game/)
- [OpenZeppelin's ERC721 library](https://docs.openzeppelin.com/contracts/4.x/api/token/erc721)