Uniswap for ERC-1155.
We are incredibly thankful for the work done by the Uniswap team, without which Niftyswap wouldn't exists.
Niftyswap is a fork of Uniswap, a protocol for automated token exchange on Ethereum. While Uniswap is for trading ERC-20 tokens, Niftyswap is a protocol for ERC-1155 tokens. Both are designed to favor ease of use and provide guaranteed access to liquidity on-chain.
Most exchanges maintain an order book and facilitate matches between buyers and sellers. Niftyswap smart contracts hold liquidity reserves of various tokens, and trades are executed directly against these reserves. Prices are set automatically using the constant product
An important feature of Nitfyswap is the utilization of a factory/registry contract that deploys a separate exchange contract for each ERC-1155 token contract. These exchange contracts each hold independent reserves of a single fungible ERC-1155 currency and their associated ERC-1155 token id. This allows trades between the Currency and the ERC-1155 tokens based on the relative supplies.
For more details, see Specification.pdf
There are some differences compared to the original Uniswap that we would like to outline below:
- For ERC-1155 tokens, not ERC-20s
- Base currency is not ETH, but needs to be an ERC-1155
- Liquidity fee is 0.5% instead of 0.3%
- All fees are taken from base currency (Uniswap takes trading fees on both sides). This will lead to some small inneficiencies which will be corrected via arbitrage.
- Users do not need to set approvals before their first trade
- 100% native meta-tx friendly for ERC-1155 implementations with native meta-tx functionalities
- Front-end implementations can add arbitrary fee (in addition to the 0.5%) for tokens with native meta-transactions.
- Less functions than Uniswap
There are pros and cons to these differences and we welcome you to discuss these by openning issues in this repository.
NiftyswapExchange.sol: The exchange contract that handles the logic for exchanging assets for a given base token. NiftyswapFactory.sol: The exchange factory that allows the creation of nifyswap exchanges for the tokens of a given ERC-1155 token conract and an ERC-1155 base currency.
Niftyswap has been audited by two independant parties and all issues discovered were addressed.
** Agustín was hired as a full-time employee at Horizon after the audit was completed. Agustín did not take part in the writing of Niftyswap contracts.
- Install node v11,
- Install yarn :
npm install -g yarn
- Install Truffle npm package:
npm install truffle
oryarn add truffle
- Install the multi-token-standard npm package
npm install niftyswap
oryarn add niftyswap
yarn install
yarn build
yarn ganache
- in another terminal run,
yarn test
- executes test suite