Coder Social home page Coder Social logo

caviar's Introduction

Caviar

Caviar is a fully on-chain NFT AMM that allows you to trade every NFT in a collection (from floors to superrares). You can also trade fractional amounts of each NFT too. It's designed with a heavy emphasis on composability, flexibility and usability. Docs are available here.

Getting started

yarn
forge install
forge test --gas-report

Example

forge install outdoteth/caviar transmissions11/solmate
pragma solidity ^0.8.17;

import "caviar/Caviar.sol";
import "caviar/Pair.sol";
import "solmate/tokens/ERC721.sol";

contract ExampleSwapper {
    Pair pair;
    ERC721 nft;

    constructor(address _nft, address _caviar) {
        nft = ERC721(_nft);
        pair = Pair(Caviar(_caviar).pairs(_nft, address(0), bytes32(0)));
    }

    function buyAndSell(uint256[] memory tokenIds, uint256 maxInput, uint256 minOutput) public payable {
        // buy nfts
        pair.nftBuy{value: maxInput}(tokenIds, maxInput);

        // sell nfts
        bytes32[][] memory proofs  = new bytes32[][](0);
        nft.setApprovalForAll(address(pair), true);
        pair.nftSell(tokenIds, minOutput, proofs);
    }
}

Contracts overview

Contract LOC Description
Caviar.sol 36 Factory contract that creates pairs and maintains a registry
Pair.sol 294 Pair contract that contains ERC20 AMM, NFT wrapping and NFT AMM logic
LpToken.sol 15 ERC20 token which represents liquidity ownership in pair contracts
SafeERC20Namer.sol 65 Helper contract that fetches the name and symbol of an ERC20/ERC721
CaviarEthRoyaltyRouter.sol 89 Router contract that swaps NFTs and pays royalties

Goerli: (demo app)

caviar's People

Contributors

0xmichalis avatar outdoteth 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

Watchers

 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.