Code Monkey home page Code Monkey logo

atomic-markets's Introduction

box-img-sm-template

Everything you need to quickly jump in and begin swapping non-fungible tokens for other tokens


Quick Start

truffle unbox nori-dot-eco/atomic-markets
truffle test

Key features

  • Boilerplate ERC-721 non-fungible token (NFT) contracts super-powered with some extended atomic logic

  • Boilerplate ERC-777 advanced token standard contracts super-powered with some atomic logic

  • Market contracts for price-based atomic swaps of NFT assets for token assets

  • Bring your own UI. Plug your own UI logic directly into the contracts. If UI examples would be helpful let me know. Keep a look out for an upcoming post on medium where Ill dive a bit deeper in to how exactly to do that

Prereqs

  1. Make sure you are using a unix flavor operating system for everything
  2. Install some stuff:

Market Contracts

Background

There are multiple types of markets: cen

  • Price Based: a market where buyers and sellers can choose which NFT they want to purchase with their tokens.

  • WIP First-in-first-out (FIFO): a market where NFTs are bought and sold in a first-in-first-out queue (similar to a spot market). In this market, buyers do not get to choose which NFTs they are purchasing.

Purpose

The Market contracts are used to buy and sell NFTs using tokens. They are the contracts by which sellers list NFTs and buyers purchase them with tokens.

The Market contracts are designed to never take custody of buyer or seller assets. Instead, they are a medium that is used to swap a NFT asset from a seller's own account to a buyer's account without ever taking custody of the seller's asset itself (nor the buyer's tokens).

At a high-level, the market accomplishes this form of an atomic swap by use of the (modified) ERC 721 and ERC 777 advanced token's approveAndCall function.

When a seller invokes this function, passing in the market address as the intended operator, the market is given authorization to transfer the NFT on behalf of the user as soon as the market receives a corresponding token authorization from a buyer.

When the market does receive this corresponding authorization (done in the same way as the NFT was done-- using the token's approveAndCall function), the Market automatically invokes (via contract introspection described in EIP820) a safeTransferFrom call on the NFT AND an transferFrom call on the token in the same transaction

The result?

An atomic swap of one asset for the other using a single transaction and without an intermediary custodying the assets.

Basically, the market "listens" for sellers who say "I want to sell this NFT", and "listens" for buyers who say "I want to buy some NFTs with my tokens", and when it can match these two conversations, it automatically swaps the token for the NFT.

In other words, you never have to deposit the tokens or the NFTs in an exchange.

Todo:

Documentation

  • write notes on how Nori uses these types of contracts

  • write a note about how it could be extended for updating prices without relisting (might already be possible by re-approving)

  • notes on how this box adds partial erc 820 support, but not full extension for 777 support (but that can be done). It also adds only one additional functions to call when authorizing operator, this call matches erc820 rather than the standard erc721 165 support (but should be backward compatible-- Ive chosen to use 820 support to match that of the token's erc777 support so as not be more ubiquitous and hopefully not to be confusing for readers/users)

Future

  • modify buy/sell to be a generic "create order" so that tokens/nft orders can be added in any order (currently the contracts require creating the NFT sale, and then buying it with a token-- we can instead generalize and just add an order book that checks if there is a matching order upon invoking a function called createOrder)
  • write implementation for FIFO market (for a preview, you can see an implementation of that logic in the Nori contracts github repository

atomic-markets's People

Contributors

dependabot[bot] avatar jaycenhorton 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

Watchers

 avatar  avatar  avatar  avatar  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.