Giter VIP home page Giter VIP logo

v3-core's Introduction

Uniswap V3

Lint Tests Fuzz Testing Mythx npm version

This repository contains the core smart contracts for the Uniswap V3 Protocol. For higher level contracts, see the uniswap-v3-periphery repository.

Bug bounty

This repository is subject to the Uniswap V3 bug bounty program, per the terms defined here.

Local deployment

In order to deploy this code to a local testnet, you should install the npm package @uniswap/v3-core and import the factory bytecode located at @uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json. For example:

import {
  abi as FACTORY_ABI,
  bytecode as FACTORY_BYTECODE,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

// deploy the bytecode

This will ensure that you are testing against the same bytecode that is deployed to mainnet and public testnets, and all Uniswap code will correctly interoperate with your local deployment.

Using solidity interfaces

The Uniswap v3 interfaces are available for import into solidity smart contracts via the npm artifact @uniswap/v3-core, e.g.:

import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';

contract MyContract {
  IUniswapV3Pool pool;

  function doSomethingWithPool() {
    // pool.swap(...);
  }
}

Licensing

The primary license for Uniswap V3 Core is the Business Source License 1.1 (BUSL-1.1), see LICENSE. However, some files are dual licensed under GPL-2.0-or-later:

  • All files in contracts/interfaces/ may also be licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/interfaces/LICENSE
  • Several files in contracts/libraries/ may also be licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/libraries/LICENSE

Other Exceptions

  • contracts/libraries/FullMath.sol is licensed under MIT (as indicated in its SPDX header), see contracts/libraries/LICENSE_MIT
  • All files in contracts/test remain unlicensed (as indicated in their SPDX headers).

v3-core's People

Contributors

danrobinson avatar ewilz avatar gakonst avatar haydenadams avatar hensha256 avatar k06a avatar lint-action avatar marktoda avatar moodysalem avatar noahzinsmeister avatar rmi7 avatar snreynolds avatar wilsoncusack avatar yorkemartin 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  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  avatar  avatar  avatar  avatar

Watchers

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

v3-core's Issues

investigate making `muluq` less lossy

as implemented, this function is lossy to the tune of 80 bits. this may be possible to reduce with some clever tricks. note that this also will work for divuq, which uses muluq under the hood

remove all ERC20 functionality from core

since only unbounded liquidity is fungible, it can be replaced by liquidity bounded to (min, max)

All ERC20 functionality can/should be implemented externally

Imo we should make a router that mints fungible liquidity at 1x, 2x, 10x, etc... for each pair (token namer can be moved here too)

Scale up the initial liquidity tokens for usability

Suggest scaling up initial liquidity tokens by 10^(18 - (min(token0Decimals, token1Decimals)) if token0Decimals < 18 or token1Decimals < 18

This will help us with a lot of wallet UX bugs and even uniswap frontend bugs (4 significant figures can be a very large string in our UI), in addition to computing useful token symbols and names

e.g.
image

minimize SLOADs and SSTOREs

Both setPosition and swap0for1 have many redundant writes and reads. Ideally these should be batched so each state variable is only read and written at most once.

This should likely be done last, since it may reduce the readability of the code (and since it may be obsoleted by further changes).

decide on tick size

until now, assuming 1%
must be greater than ~15 bips for tick index to fit in uint16

factors are:

  • gas cost of crossing ticks
  • representing all possible prices
  • maximum amount of leverage
  • the level of allowed granularity/leverage of limit orders we want
  • comparable projects allowed leverage

improve the precision of `divuq`

because divuq uses reciprocal under the hood, which can have precision issues because it uses floor division, divuq can also have precision issues

Move counterfactual logic for reading price0Cumulative and price1Cumulative to pair

When reading price*CumulativeLast variables, all oracle consumers actually want the cumulative price as of the current block, not the last liquidity event (e.g. mint/burn/swap)

We provided a library in uniswap v2 periphery for this
https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/libraries/UniswapV2OracleLibrary.sol#L16

However, we should just add the view method directly to the pair getCumulativePrices() returns (price0Cumulative, price1Cumulative) that returns the cumulative prices as of the current block, even if there was no liquidity event.

Also potentially consider marking the Last suffixed variables private, if we want to force others to use this other method.

Implement uqmul112 and uqdiv112 to multiply/divide two fixed-point numbers

This is needed to track the growth in sqrt(x*y)/shares, which is how we plan to account for fees when adding and removing liquidity within bounds. (It's possible we may eventually be able to make do with somewhat less precision than 112x112.)

// multiply a UQ112x112 by a UQ112x112, returning a UQ112x112
// reverts on overflow
function uqmul112(FixedPoint.uq112x112 memory self, FixedPoint.uq112x112 memory x) internal pure returns (FixedPoint.uq112x112 memory) {
        ...
}

// divide a UQ112x112 by a UQ112x112, returning a UQ112x112
function uqdiv112(FixedPoint.uq112x112 memory self, FixedPoint.uq112x112 memory x) internal pure returns (FixedPoint.uq112x112 memory) {
        ...
}

fix fee at the beginning of the block

in uniswap v2, oracle price accumulators were modified before the first action of every block that could potentially change the price. this prevented bad price manipulation behavior via flash loans, force-sending assets to the contract, etc.

similarly, in uniswap v3, we have to modify the current fee vote before the first action of every block that could potentially change it. this will prevent someone from flash loaning a bunch of liquidity, voting for the lowest fee, and obviating the vote of existing LPs.

the median fee vote can only change on calls to setPosition and tick crossings, so we have to figure out an elegant way to update the global fee before the first setPosition/tick crossing of every block. it's possible we can piggy-back on the timeElapsed check we use for the oracle (https://github.com/Uniswap/uniswap-v3-core/blob/05ee4361f34ec5e544f0843943844d8dbab1fe9a/contracts/UniswapV3Pair.sol#L214), or there may be more efficient ways to do this.

add helper function(s) to calculate useful values

in v2, it can be hard to calculate the value of some amount of LP shares because a) it uses reserves instead of balances, and b) when the fee is on there's some logic that needs to happen

we should make a view function to calculate the worth of LP shares, and also how many LP tokens a given amount of token0 and token1 entitle you to

Fix fee compounding math

w.r.t. fees not getting withdrawn when ticks are crossed (and still being exposed to price movements)

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.