Uniswap v2 docs sol, thực hiện chức năng hoán đổi cốt lõi và cung cấp thanh khoản UniswapV2Factory. Uniswap V2 is a binary smart contract system. Flash Swaps. The pages here contain conceptual and technical documentation of the Uniswap V2 protocol. There is a risk of losing money during large and sustained movement in the underlying asset price compared to simply holding an asset. In the mean time, the Uniswap V2 whitepaper has most relevant math for Uniswap V2. The primary rule is the constant product formula. Market making, in general, is a complex activity. 2. For Uniswap-specific functionality, see Pair. For end-users, swapping is intuitive: a user picks an input token and an output token. Swap Tokens; Add/Remove Liquidity; Tracking Volume; Tracking Pool Balances; Finding The Best Quote; Both Liquidity Book and Uniswap V3 are concentrated liquidity AMMs with some subtle differences: \[ \] Uniswap V3简介 # 本章节主要讲述了 Uniswap V3白皮书中的内容。同样,假设你没有理解本章的所有概念也没有关系,我们在后面章节直接看代码可能会更清晰。 为了更好地理解 Uniswap V3 的创新之处在哪里,我们首先来看 The main difference between the two order types is that DutchV2 orders use a time-based decay while DutchV3 use a block-based decay. To do this we can use the useQuery hook which uses our client instance to fetch data, and gives us live info about the status of the request. 30%; tickSpacing is the granularity of the pool. To begin, we recommend looking at the Guides and for deeper reference see the V2 SDK GitHub repo. Wrapped Ether (WETH) is used instead of native Router01. Specifically, this means that the product of the pair reserves after the swap, discounting all token amounts sent by 0. You can use these docs to learn about the v3 Protocol Smart Contracts and develop on-chain integrations. Pair A smart contract deployed from the Uniswap V2 Factory that enables trading between two ERC20 tokens. Most signi cantly, it enables the creation of arbitrary ERC20/ERC20 pairs, rather than supporting only pairs between ERC20 and ETH. It is used throughout the Uniswap SDKs, such as the V3 SDK. V2 SDK. Below is a list of the available entities within the Uniswap Subgraph, and descriptions for the available fields. Sending a Transaction to the Router Uniswap v2 is a new implementation based on the same formula, with several new highly-desirable features. Next. All Uniswap V2 pool tokens support meta-transaction approvals via the permit function. Servers We use an id of 1 for the bundle because there is only one hardcoded bundle in the subgraph. Pool This documentation covers ERC-20 functionality for denominating pool tokens. Hooks Developers can attach solidity logic to Supporting meta transactions. They are incentivized to deposit an equal value of both Withdrawing ETH from Uniswap The first step is to optimistically withdraw 1 ETH from Uniswap via a flash swap. The pages that follow contain technical reference information on the Uniswap SDK. Core contracts provide fundamental safety guarantees for all parties interacting with Uniswap. Safety Considerations. Uniswap V2 Core là các hợp đồng thông minh Uniswap V2 thiết yếu, bao gồm: UniswapV2Pair. These docs are actively being worked on and more information will be added on an ongoing basis. The subgraph runs on The Graph protocol's hosted service and can be openly queried. sol, triển owner - the signer of the permit message and owner of the tokens; signature - the signature over the permit data. sender is an actual Uniswap V2 pair address. An iframe shows an exact version of the Uniswap frontend site and can have custom prefilled settings. Briefly, Uniswap is a protocol for exchanging ERC-20 tokens on Ethereum. 3% fee for swapping tokens. This is currently recommended release, 02. Migrates liquidity to v3 by burning v2 liquidity and minting a new position for v3. UniswapV2Router01 should not be used any longer, because of the discovery of a low severity bug and the fact that some methods do not work with tokens that take fees on transfer. Add support for any ERC20 token using the Uniswap factory; Join liquidity pools to collect fees on ETH-ERC20 V2. Why You May Want This. Introduction; V2. timestamp of the EVM does not allow for millisecond-level granularity, all decay in DutchV2 must happen in seconds which does not take advantage of Arbitrum's 250 ms block frequency. 2A. 2 adds Hooks and new Router and Quoter support. This guide will focus exclusively on sending a transaction to the latest Uniswap V2 router. Docs. v4 Protocol. Uniswap V2 Technical Whitepaper; Uniswap V2 Documentation; ERC20 / ERC20 Pairs. You have no replay protection to Ethereum Mainnet. Periphery contracts interact with one or more core contracts but are not themselves part of the core. Quickstart. When providing liquidity from a smart contract, the most important thing to keep in mind is that tokens deposited into a pool at any rate other than the current reserve ratio are vulnerable to being arbitraged. web3-react. There is a 0. Global parameters can be used on all pages. They specify an input amount, and the protocol calculates how much of the output token they’ll receive. The core consists of a singleton factory and many pairs, which the factory is responsible For additional details please read the architecture section of the in-progress Uniswap V2 docs or the core and periphery smart contracts themselves. If you are new to the Uniswap Protocol, we recommend you start with the basic concepts first. Returns UNI-V2 for all pairs. SDK. Users will need a web3-enabled browser. The Uniswap protocol is governed and upgraded by UNI token ERC20 tokens are fungible tokens on Ethereum. Overview. The contract is unowned, and is not upgradeable. Defined in: utils/priceTickConversions. Universal Router, Permit2, v2, and v1; SDKs - Uniswap integrations such as the v4-sdk, v3-sdk and the Swap Widget; APIs - The This section explains the Uniswap Subgraph and how to interact with it. This first liquidity provider is the one who sets the initial price of the pool. Supports EOA signatures, compact signatures defined by EIP-2098, and contract signatures defined by EIP-1271; Batched permitTransferFrom . Singleton Design Pool Creation v4: The singleton contract facilitates the creation of a pool and also stores its state. The Uniswap subgraph indexes data from the Uniswap contracts over time. |data | bytes | Any data passed through by the caller via the The Uniswap development suite Uniswap offers several SDKs that work together and enable you to easily interact with the Uniswap protocol The most important SDKs are: sdk-core: The core of the Uniswap SDKs, defines classes and types shared across all the SDKs; v2-sdk: An SDK to interact with the Uniswap V2 protocol. Each Page has specific available URL parameters that can be set. Swap Widget. Users and developers can use these query parameters to link to the Uniswap frontend with custom prefilled settings. decimals. Technical The first 2 lines simply fetch the token addresses from the pair, and the 3rd ensures that the msg. For additional information, see the Uniswap v4 whitepaper. Uniswap Docs Concepts Contracts SDKs APIs. Slippage protection is enforced via amount{0,1}Min, which should be a discount of the expected values of the maximum amount of v3 liquidity that the v2 liquidity can get. Uniswap supports all standard ERC20 implementations. Uniswap v2, the second iteration of the Uniswap protocol, has been deployed to the Ethereum mainnet! An audit report and formal verification has already been released and ERC20 Token Solidity . js to connect your website to Ethereum. 1; V2; V1; Whitepaper GitHub. The AllowanceTransfer contract handles setting Welcome to the Uniswap protocol V2 docs. An analysis of Uniswap markets; Improved Price Oracles: Constant Function Market Makers. Resources. What Does Uniswap Do? You’ve arrived! The pages that follow contain comprehensive documentation of the Uniswap V2 ecosystem. V1 V2 Introduction. Once you understand the kind of price average you require, it is a matter of storing the cumulative price variable from the pair as often as necessary, and computing the average price using two or more observations of the cumulative price variables. Useful for calculating optimal Each Uniswap liquidity pool is a trading venue for a pair of ERC20 tokens. Git Source - Generated with forge doc. An audit report and formal verificaiton has already been released and the Contribute to Uniswap/docs development by creating an account on GitHub. Uniswap can be used within other sites as an iframe. On desktop this means using the MetaMask extension or something similar. This will serve as the capital that we use to execute our arbitrage. If the protocol charge is on, feeOn must be set to true, and kLast must be provided from an on-chain lookup. Integrating the Uniswap site directly into your web application can be useful for a Because routers are stateless and do not hold token balances, they can be replaced safely and trustlessly, if necessary. Fetch data . Fillers who win a quote will receive execution priority for a limited period of time to fill orders they submitted wining quotes for. ↩ For information about liquidity provision, see the liquidity user guide↩; The Uniswap interface informs the user about the circumstances of their swap, but it Name Type Description; chainId: uint256: The current chain ID: Edit this page. totalSupply must be looked up on-chain. To try these queries and run your own visit the subgraph sandbox. Uniswap v2 Visualization Uniswap Docs Concepts Contracts SDKs APIs. Entities define the schema of the subgraph, and represent the data that can be queried. Welcome to the Uniswap Protocol V2 SDK. Uniswap v4 inherits all of the capital efficiency gains of Uniswap v3, but provides flexibility via hooks and gas optimizations across the entire lifecycle. ProtocolFees. In Uniswap V2 swaps are executed “optimistically”, meaning that if desired, tokens can be requested and sent to an address before payment for said tokens is collected, as long as payment occurs by the end of the atomic transaction. This fee is split by liquidity providers proportional to their contribution to liquidity reserves. It makes uses of the Core SDK to gain access to abstractions The subgraph can be queried to retrieve important information about Uniswap, pairs, tokens, transactions, users, and more. Repayment. Lower values are more precise but may be more expensive to trade on; hookContract is the To get the most out of the advanced guides, we encourage you to take a step back and read a bit about the math and theories behind the Uniswap protocol. The most complete source of information on the Uniswap protocol is the Uniswap V3 book. When a pool contract is created, its balances of each token are 0; in order for the pool to begin facilitating trades, someone must seed it with an initial deposit of each token. This SDK is not expected to be used in isolation, but only as part of other SDKs. All the extra functionality required by traders The audit team carried out a general code review and security analysis of the smart contracts of uniswap-v2-core, finding 2 bugs: . 根据 Uniswap v2 的设计,流动性提供者(LP)需要为从价格为 0 到正无穷的整个价格区间提供流动性。 这是因为在 x⋅y = k 的机制下,交易对的价格可以在理论上的任何位置出现,所以 LP 需要在整个价格曲线上都有资产储备。 Uniswap V2 is a binary smart contract system. Code. Inherits: IProtocolFees, Owned Contract handling the setting and accrual of protocol fees. In Uniswap V2, any ERC20 token can be pooled directly with any other ERC20 token. Overview; Deployments; Concepts. If positive, the callback must send that amount of token1 to the pool. ADDRESS_ZERO as currency0. The flexible command style allows us to provide users with: Splitting and interleaving of Uniswap trades Nearly everything you need to safely transact with Uniswap is provided by the Trade entity. Fetching Data. UniswapV2Router01. Returns Uniswap V2 for all pairs. The subgraph updates any time a transaction is made on Uniswap. 1 medium severity issue Pair: fix to liquidity deflation introduces race condition; 1 low severity issue Math: integer overflow in sqrt; along with several recommendations regarding gas optimisation and code clarity, which are presented in detail in Proportional in this instance takes into account many factors, including the relative price of one token in terms of the other, slippage, price impact, and other factors related to the open and adversarial nature of Ethereum. Permit2 is a unification of 2 contracts, SignatureTransfer and AllowanceTransfer. Governance must specify fees on a per pair basis, and the fee must be an integer value in basis points. Previous. Besides the concepts section of the Docs, the Uniswap V3 whitepaper is a Calculates the exact amount of token0 or token1 that the given amount of liquidity tokens represent. Providing Liquidity Introduction . If a smart contract assumes that the current price on Uniswap is a "fair" price without performing safety checks, it is vulnerable to manipulation. To build a price oracle on Uniswap V2, you must first understand the requirements for your use case. Global Data To query global data you can pass in the Uniswap Factory address and select from available Overview. So you need to 1: Never use the anvil private keys on a real chain or send funds to it (they are leaked Position. js or web3. Welcome to the V3 Core SDK! The Uniswap Core SDK provides abstractions for other SDKs to use in a Typescript/Javascript environment. Source code. For convenience, we’ve provided an example Executor Contract which demonstrates how a filler could implement a strategy that executes a UniswapX order against a Uniswap V3 pool. Liquidity providers are incentivized to contribute ERC-20 tokens to common liquidity pools. PoolKey uniquely identifies a pool. The SignatureTransfer contract handles all signature-based transfers, meaning that an allowance on the token is bypassed and permissions to the spender only last for the duration of the transaction that the one-time signature is spent. value: uint256: Amount of ETH added: min_liquidity: uint256: Minimum minted liquidity: max_tokens: uint256: Maximum ERC20 tokens added Security consideration: This is a fork of Mainnet and the same chain id is used. They then execute the swap with one click, receiving Concepts - General Uniswap information or concepts useful for using Uniswap products, such as Hooks and Fees Contracts - Uniswap smart contracts including v4 , v3 , UniswapX , Universal Router , Permit2 , v2 , and v1 The pages here contain conceptual and technical documentation of the Uniswap V2 protocol. In this article we will go over the source code for the contracts that implement this protocol and see why they are written this way. Core. 2; V2. This pattern reduces costs when creating a pool and doing multi-hop swaps. The Uniswap smart contracts exist on the Ethereum blockchain. Building upon the success of Uniswap v2 can create an exchange market between any two ERC-20 tokens. Unlike Uniswap v2 where the x*y=k formula was hardcoded, v4 allows developers to implement a wide variety of pricing models. Note that in this scenario, we're assuming that: 1 ETH is the pre-calculated profit-maximizing trade; The price has not changed on Uniswap or Oasis since our calculation Uniswap uses multiple subgraphs for indexing and organizing data from the Uniswap smart contracts. The Uniswap v3 SDK provides abstractions to assist you with interacting with the Uniswap v3 smart contracts in a Typescript/Javascript environment (e. This may happen if more efficient smart contract patterns are discovered, or if additional functionality is desired. js file: These fillers can only win a quote if they guarantee improved swapper execution over Uniswap v3 or v2 liquidity pools. On mobile, web3-compatible browsers include Trust Wallet and Coinbase Wallet. 2 Key Changes; Guides. We also show that Uniswap satisfies many other desirable properties and numerically demonstrate, via a large-scale agent-based simulation, that Uniswap is stable under a wide range of market conditions. For native token pairs (Ether), use CurrencyLibrary. Use ethers. Because the block. While the SDK is fully self-contained, there are two cases where it needs on-chain data to function. Similar to the above method but instead targets a fixed output amount given a list of pairs, and a fixed amount out, returns the top maxNumResults trades that go from an input token to an output token amount, making at most maxHops hops. For this reason, routers have release numbers, starting at 01. Looking for a quickstart?. It also provides a hard- Fees Liquidity provider fees . The Uniswap Protocol Introduction . You can / docs Products Developers Info Launch App. Edit this page. It When you use the Uniswap web app, wallet, or extension, you can use Uniswap v1, v2, v3 or v4. In reality, the SDK computes pair addresses behind the scenes, obviating the need to compute them As we learned in Protocol Overview, each pair on Uniswap is actually underpinned by a liquidity pool. Positions store additional state for tracking fees owed to the position. symbol. When a token is withdrawn (bought), a proportional amount must be deposited (sold) to The pages here contain guides and technical documentation for the Uniswap v3 Smart Contracts. function decimals external pure returns (uint8); For developers looking to interact with or build on Uniswap V2, the following resources are available: Uniswap V2 Whitepaper: Technical details of Uniswap V2; Uniswap V2 Documentation: Official documentation for Uniswap V2; Uniswap V2 Core: Core smart contracts for Uniswap V2; Uniswap V2 Periphery: Peripheral smart contracts for Uniswap V2 IQuoterV2. Versions and Production Endpoints Each version of Uniswap has its own dedicated subgraph, and governance contracts have a dedicated subgraph as well. Retrieve & Execute Signed Dutch Orders Uniswap Contract Deployments. The current recommendation is to use UniswapV2Router02. 3000 = 0. 3% LP A lot of AMMs are a fork of Uniswap V2: Uniswap V2 is much simpler than V3, therefore, easier to maintain. So once you know how Uniswap V2 works, you will know most of / docs Products Developers Info Launch App. You can also Token swaps in Uniswap are a simple way to trade one ERC-20 token for another. At the end of uniswapV2Call, contracts must return enough tokens to the pair to make it whole. As an example, if the ratio of x:y in a pair is 10:2 (i. Governance Reference. Show Menu. Because Ethereum transactions occur in an adversarial environment, smart contracts that do not perform safety checks can be exploited for profit. This guide will detail both of these cases, and offer a sample that you can use to fetch this data. Search. g. ts:20 Returns a price object corresponding to the input tick and the base/quote token Inputs must be tokens because the address order is used to interpret the price represented by the tick Uniswap v2 is divided into two components, a core and a periphery. Note this does not consider aggregation, as routes are linear. The pages here contain conceptual and technical documentation of the Uniswap v2 protocol. Interfaces and wallets can choose to Parameter Type Description; msg. The UniversalRouter is an ETH, ERC20, and NFT swap router, that can aggregate trades across protocols to give users access to highly-flexible and personalised transactions. To do this add the following to your App. Governance must also activate fees on a per-chain basis. Within each entity are sets of fields that store useful information related to the entity. Smart Contracts. |amount1Delta | int256 | The amount of token1 that was sent (negative) or must be received (positive) by the pool by the end of the swap. This division allows the core contracts, which hold the assets and therefore have to be secure, to be simpler and easier to audit. V3 SDK. Looking for a quick start instead? You may also want to jump into a guide, which offers a friendlier introduction to the SDK!. interface ERC20Interface { function totalSupply public view returns (uint); function balanceOf (address tokenOwner) public view returns (uint balance); function allowance (address tokenOwner, address spender) public view returns (uint remaining); function transfer (address to, uint tokens) public returns (bool success); function approve (address spender, the same max fee as Uniswap v2, on the output of each UniswapX swap. Integrators should no longer assume that they are deployed to the same addresses across chains and be extremely careful to confirm mappings below. Technical Considerations. State Variables protocolFeesAccrued . A bad actor could e. the price is 5), and someone naively adds liquidity at 5:2 (a price of 2. Skip to main content. . Currencies should be sorted, uint160(currency0) < uint160(currency1); lpFee is the fee expressed in pips, i. In fact, under the hood, all swaps are actually flash swaps! This simply means that pair contracts send output tokens to the recipient before enforcing that enough input tokens have been bestTradeExactOut . Uniswap incentivizes users to add liquidity to trading pools by rewarding providers with the fees generated when other users trade with those pools. Uniswap v1 was the first version of the Uniswap Protocol, launched in Smart contracts. The V2 Uniswap V2, launched in May 2020, is the second iteration of the Uniswap protocol, a decentralized trading platform on the Ethereum blockchain. Supports quoting the calculated amounts from exact input or exact output swaps. Getting Started. V1 Features. sol Uniswap v4. Positions represent an owner address' liquidity between a lower and upper tick boundary. The updated reference for the newly deployed Governor Bravo is available via Etherscan, some of the reference material below may be out of date. Authors: Guillermo Angeris, Tarun Chitra Flash swaps are an integral feature of Uniswap V2. Research. This page will provide examples for common queries. This is made possible through the hook system, particularly hooks that can interact with the swap process. Traders can swap these Rest API for orders. function symbol external pure returns (string memory); Copy. Core SDK. 5), the the end of the swap. The SDK is written in TypeScript, has a robust test suite, performs arbitrary precision arithmetic, and supports rounding to significant digits or fixed The Uniswap ecosystem is primarily comprised of three types of users: liquidity providers, traders, and developers. 📓 Uniswap docs website. It organizes data about pairs, tokens, Uniswap as a whole, and more. Liquidity pools are smart contracts that hold balances of two unique tokens and enforces rules around depositing and withdrawing them. You can also take a look at the V2 Protocol Whitepaper. This obviates the need for a blocking approve transaction before programmatic interactions with pool tokens can occur. Security. If positive, the callback must send that amount of token0 to the pool. Give Feedback Uniswap Foundation Whitepaper GitHub. Factory A smart contract that deploys a unique smart contract for any ERC20/ERC20 trading pair. V4 SDK. org to learn more. However, it is your responsibility to use this data to send transactions in whatever context makes sense for your application. Previous Uniswap Contract Deployments. Developers. This example makes use of the Uniswap V2 SDK. These contracts should be deployed to each chain that the filler would like to support. Dev Chat; Feedback; Bug Bounty Building an Oracle. The Route entity represents one or more ordered Uniswap pairs with a fully specified path from input token to output token. V2. Given a currency address, returns the protocol fees accrued in that currency This site will serve as a project overview for Uniswap - explaining how it works, how to use it, and how to build on top of it. The Uniswap protocol is a peer-to-peer 1 system designed for exchanging cryptocurrencies (ERC-20 Tokens) on the Ethereum blockchain. For each pool also tells you the number of initialized ticks crossed and the sqrt price of the pool after the swap. Guides. These subgraphs are hosted on The Graph hosted service and can be used to query Uniswap data. See ethereum. The protocol is implemented as a set of persistent, non-upgradable smart contracts; designed to prioritize censorship resistance, security, self-custody, and to function without any trusted Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountIn. Custom Curves in Uniswap v4 represent a big change in AMM design flexibility. The latest version of @uniswap/v3-core, @uniswap/v3-periphery, and @uniswap/swap-router-contracts are deployed at the addresses listed below. websites, node scripts). This page will be periodically updated with helpful resources for calculations and software design as they are made available. While Uniswap v4's underlying concentrated liquidity is the same as Uniswap v3, there are some key differences in the architecture and accounting. e. Now we're ready to use these queries to fetch data from the Uniswap V2 subgraph. The core consists of a singleton factory and many pairs, which the factory is responsible for creating and indexing. For this reason, we will migrate tickToPrice() tickToPrice(baseCurrency, quoteCurrency, tick): Price<Currency, Currency>. We recommend taking a look at the Technical We are thrilled to announce that Uniswap V2 has been deployed to the Ethereum mainet!. easily insert transactions before and after The Uniswap front-end supports URL query parameters to allow for custom linking to the Uniswap frontend. Use permitTransferFrom with the batched parameters when you want to transfer multiple tokens from an owner. For the special case of migrating to an out-of-range position, amount{0,1}Min may be set to 0, enforcing that the position The Uniswap Core SDK. If you are new to Uniswap, you might want to check out the Protocol overview first. Overview; Technical Reference. Swapping fees are immediately deposited into liquidity reserves. idlyhzhopvypihnlbwsejxunpnkkmvlofxaiqmdldvdkpaxfhpfdvlyadbcclfzfhfwcpwqqiu