Git Product home page Git Product logo

erc721x's Introduction

ERC721x Contract

This standard allows contract that implement the ILock interface to lock/unlock assets in place to enable/disable them from being transferred.

Notorious project using such implementation:

How does this work?

The Lock Registry contains four mappings:

mapping(address => bool) public approvedContract;
mapping(uint256 => uint256) public lockCount;
mapping(uint256 => mapping(uint256 => address)) public lockMap;
mapping(uint256 => mapping(address => uint256)) public lockMapIndex;

The first, approvedContract, is a mapping that checks if an address is allowed to lock/unlock assets from the collection. This mapping is updated by the owner of the contract (EOA or multisig for example).

lockCount is a mapping that tracks how many locks a token possesses. As long as the lock count is > 0, the token cannot move. Once there are no more locks, the token is free to move once again.

lockMap and lockMapIndex work together.

lockMap is a double mapping that connects a token ID to the address that locked it.

lockMap[tokenId][lockIndex] => contract that locked

lockMapIndex is a double mapping that connects a token ID to the lockIndex of the adddress that locked it.

lockMapIndex[tokenId][lockingContract] => lock Index of locking contract

Those 2 mappings are necessary to easily track and delete lock when a contract unlocks a token.

Interface

The IERC721x interface is very simple:

interface IERC721x {

	/**
	* @dev Returns if the token is locked (non-transferrable) or not.
	*/
	function isUnlocked(uint256 _id) external view returns(bool);

	/**
	* @dev Returns the amount of locks on the token.
	*/
	function lockCount(uint256 _tokenId) external view returns(uint256);

	/**
	* @dev Returns if a contract is allowed to lock/unlock tokens.
	*/
	function approvedContract(address _contract) external view returns(bool);

	/**
	* @dev Returns the contract that locked a token at a specific index in the mapping.
	*/
	function lockMap(uint256 _tokenId, uint256 _index) external view returns(address);

	/**
	* @dev Returns the mapping index of a contract that locked a token.
	*/
	function lockMapIndex(uint256 _tokenId, address _contract) external view returns(uint256);

	/**
	* @dev Locks a token, preventing it from being transferrable
	*/
	function lockId(uint256 _id) external;

	/**
	* @dev Unlocks a token.
	*/
	function unlockId(uint256 _id) external;

	/**
	* @dev Unlocks a token from a given contract if the contract is no longer approved.
	*/
	function freeId(uint256 _id, address _contract) external;
}

An approved contract can lock or unlock an asset. Locking an asset twice will revert, same behaviour for double unlocking.

freeId is an emergency function that can only be called under a specific condition. It behaves similarly to the unlockId function. It can only be called if the previously approved contract that locked the asset is no longer approved. This means that you will be required to change approvedContract[badContract] => false by calling updateApprovedContracts and unset the initially approved contract. This should only happen if the locking contract has bad logic and prevents people from unlocking assets. By disapproving the defective contract, we allow users to remove the lock to enable transferring their asset if they choose to.

What can it do?

The lock registry is a vital tool in web3. It allows users to lock assets in place, which is the underlying condition of staking or securing assets. If assets cannot move, they cannot be stolen. The guarantee lock registry ensures is that assets cannot be transferred in staking mechanisms. A key example is Play and Kollect experience created by CyberKongz.

When locking an asset, the token does not move to a contract to interact with it and therefore does not have to leave the owner's wallet. In addition to reducing contract risks, asset holders are given the option to engage in an unlimited number of previously approved locking contracts simultaneously, while always retaining true ownership of the asset.

This allows for the creation of an onchain 2fa. Assets could reside on a hot wallet (metamask) but be secured by a guardian address that is a multisig or a HW wallet. This allows users to benefit from the flexibility of hot wallet interactions on metamask while also maintaining the high security of multisigs or HW wallets. Additionally, users would not longer need to click/sign endlessly. A twitter experiment by Owl can be found here.

An implementation has been created called the Guardian contract. Repo can be found here.

Checkout other similar implementations

The talented devs over at Samurise have implemented a similar tech for their contracts, Check here!

erc721x's People

Contributors

cygaar avatar lxxykong avatar owlofmoistness avatar sebssebssebs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.