2021-09-11 18:23:17 -07:00
2021-09-23 16:21:10 -07:00
2021-09-11 18:23:17 -07:00
2021-11-13 20:08:56 -08:00
2021-11-26 09:59:39 -08:00
2021-09-11 18:23:17 -07:00
2021-09-15 15:48:38 -06:00

sudoswap AMM

An implementation of the AMM idea described here.

Liquidity providers use LSSVMPairFactory to deploy a minimal proxy LSSVMPair for a specific NFT collection. From there, the deployed pool maintains its own ETH/NFT inventory. Users can then call the various swap functions on the pool to trade ETH/NFTs.

LSSVMPairs are either LSSVMPairEnumerable or LSSVMPairMissingEnumerable depending on whether or not the pair's ERC721 contract supports Enumerable or not. If it doesn't, we implement our own ID set to allow for easy access to NFT IDs in the pool.

The LSSVMRouter allows splitting swaps across multiple LSSVMPairs.

An LSSVMPair can be ETH, NFT, or TRADE. The type refers to what the pool holds--an ETH pool has ETH that it is willing to give to traders in exchange for NFTs, an NFT pool has NFTs that it is willing to give to traders in exchange for ETH, and TRADE pools allow for both ETH-->NFT and NFT-->ETH.

The LSSVMPair swap functions are named from the perspective of the end user. EX: swapETHForAnyNFTs means the caller is sending ETH and receiving NFTs.

In order to determine how many NFTs or ETH to give or receive, each LSSVMPair calls a discrete bonding curve contract that conforms to the ICurve interface. Bonding curve contracts are pure; it is up to the LSSVMPair to update its state and perform input/output validation.

See inline comments for more on swap/bonding curve logic.

Built with DappTools Template

Template repository for getting started quickly with DappTools

Github Actions

Building and testing

make
make test

Deploying

Contracts can be deployed via the make deploy command. Addresses are automatically written in a name-address json file stored under out/addresses.json.

We recommend testing your deployments and provide an example under scripts/test-deploy.sh which will launch a local testnet, deploy the contracts, and do some sanity checks.

Environment variables under the .env file are automatically loaded (see .env.example). Be careful of the precedence in which env vars are read.

We assume ETH_FROM is an address you own and is part of your keystore. If not, use ethsign import to import your private key.

See the Makefile for more context on how this works under the hood

We use Alchemy as a remote node provider for the Mainnet & Rinkeby network deployments. You must have set your API key as the ALCHEMY_API_KEY enviroment variable in order to deploy to these networks

Mainnet

ETH_FROM=0x3538b6eF447f244268BCb2A0E1796fEE7c45002D make deploy-mainnet

Rinkeby

ETH_FROM=0x3538b6eF447f244268BCb2A0E1796fEE7c45002D make deploy-rinkeby

Custom Network

ETH_RPC_URL=<your network> make deploy

Local Testnet

# on one terminal
dapp testnet
# get the printed account address from the testnet, and set it as ETH_FROM. Then:
make deploy

Installing the toolkit

If you do not have DappTools already installed, you'll need to run the below commands

Install Nix

# User must be in sudoers
curl -L https://nixos.org/nix/install | sh

# Run this or login again to use Nix
. "$HOME/.nix-profile/etc/profile.d/nix.sh"

Install DappTools

curl https://dapp.tools/install | sh

DappTools Resources

S
Description
Internal copy of sudoAMM.
Readme AGPL-3.0
854 KiB
Languages
Solidity 97.6%
Shell 1.8%
Python 0.3%
Makefile 0.2%