AAVE Uniswap: Create & Unwind Leveraged Positions on Aave & Uniswap

AAVE-Uniswap

a simple contract that lets you create and unwind leveraged positions on Aave 👻 by integrating with Uniswap 🦄, plus some testing courtesy of Hardhat👷. The Aave Ape combines two Defi protocols, Aave (for lending) and Uniswap (for swapping).

AAVE Interacting with Aave starts with the Lending Pool Addresses Provider — this is the source of truth for Aave V2’s latest contract addresses:

  • LendingPool: where the depositing & borrowing happens 🏦
  • ProtocolDataProvider: provides easy-to-access information about reserves & users 📊
  • PriceOracle: provides secure price feeds 💱

uniswapv2 Interacting with Uniswap V2 all happens through the Uniswap Router02.

key point

We can create a constructor that lets us set the two addresses we need (the AddressesProvider and the Router). Once we then have the addresses and the interfaces, we can create helper functions to instantiate contracts so that we can interact with them, and fetch Aave reserve data from the ProtocolDataProvider.

Assuming you have an apeAsset you want to go long and a borrowAsset you want to go short this ape function lets a user carry out the following steps in one transaction

  • Calculate the maximum amount the user is able to borrow in the borrowAsset, based on their collateral (this relies on getAvailableBorrowInAsset)
  • Borrow that amount of borrowAsset from Aave V2 on behalf of the user

This requires the user to have delegated credit to the Aave Ape contract, so that it can borrow from Aave on the user’s behalf — see more about Credit Delegation

  • Approve the borrowAsset for trading on Uniswap
  • Swap the borrowAsset for the maximum available amount of the apeAsset via Uniswap V2
  • Deposit the apeAsset back into Aave on behalf of the user

unwindApe Borrow the amount needed to repay their borrowAsset debt via a flashloan from Aave V2.
For more detail , please visit aave-ape

operating steps

// depoly aaveape
hardhat run --network matic scripts/deploy.js   

// contract verify
npx hardhat verify --network matic 0xddb2d92d5a0EDcb03c013322c7BAe92734AA4597 "0xd05e3E715d945B59290df0ae8eF85c1BdB684744" "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506"

// open maxposition on aave
hardhat run --network matic scripts/loan.js   

Link: https://github.com/Dapp-Learning-DAO/Dapp-Learning/tree/main/basic/21-aave-uni-loan

#solidity #smartcontract #dapp #blockchain #dao #uniswap #aave

AAVE Uniswap: Create & Unwind Leveraged Positions on Aave & Uniswap
Best of Crypto

Best of Crypto

1660238820

Uniswap Protocol for Exchanging ERC-20 tokens on Fantom Opera

Fantom Uniswap Deployment

Uniswap is an automated liquidity protocol powered by a constant product formula and implemented in a system of non-upgradeable smart contracts on a block chain. It obviates the need for trusted intermediaries, prioritizing decentralization, censorship resistance, and security. Uniswap is open-source software licensed under the GPL.

We've deployed the Uniswap protocol, originally developed on the Ethereum network, on our unique Fantom Opera block chain technology. This brings the benefits of having decentralized and secure environment for liquidity pool based trading into the Fantom ecosystem and its growing user base.

Modules and Tools Deployed

Here is the list of references to Uniswap ecosystem projects we utilize to get the protocol live on Fantom Opera block chain network. We would like to express our appreciation to the great work these projects did to create such an excellent set of secure trading tools.

We deployed following contracts from the Uniswap protocol ecosystem:

  • Uniswap Core V2 contract
  • Uniswap V2 Pair
  • Uniswap Periphery updated to use WFTM tokens instead of original WETH.

We also use our own implementations of following modules:

  • Wrapped Fantom native tokens to ERC20

Download details:

Author: Fantom-foundation
Source code: https://github.com/Fantom-foundation/Fantom-Uniswap
License: GPL-3.0 license

#fantom #blockchain #uniswap #solidity #typescript

Uniswap Protocol for Exchanging ERC-20 tokens on Fantom Opera
Best of Crypto

Best of Crypto

1657316040

Uniswap V3 Optimism | Optimism fork Of The V3 Core Contracts

Uniswap V3 Optimism

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

Licensing

The primary license for Uniswap V3 Core is the Business Source License 1.1 (BUSL-1.1), see LICENSE.

Exceptions

  • All files in contracts/interfaces/ are licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/interfaces/LICENSE
  • Several files in contracts/libraries/ are licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/libraries/LICENSE_GPL
  • 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.

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v3-core-optimism
License: View license

#uniswap #blockchain #ethereum #defi #smartcontract #typescript #solidity

Uniswap V3 Optimism | Optimism fork Of The V3 Core Contracts
Best of Crypto

Best of Crypto

1657308720

Optimism fork Of The Uniswap V3 Periphery Contracts

Uniswap V3 Periphery Optimism

This repository contains the Optimism fork of the periphery smart contracts for the Uniswap V3 Protocol. For the lower level core contracts, see the uniswap-v3-core-optimism repository.

Testing

Because these contracts and tests are modified for OVM support, there are some changes that mean we can no longer simply run yarn test and yarn test:ovm and expect all tests to pass for both the EVM and OVM. There are a few reasons for this:

  1. EVM vs. OVM contracts will use different amounts of gas, so the gas tests will fail
  2. PoolAddress.sol has a hardcoded bytecode hash, but this hash will be different for EVM vs. OVM bytecode
  3. In Uniswap V3 Core and Periphery contracts some logic was pulled out into library contracts to reduce contract size. The original EVM contracts had deterministic bytecode, so a bytecode hash can be easily hardcoded in PoolAddress.sol, but this is no longer true. The contracts now require linking libraries, and therefore the bytecode and bytecode hash is dependent on the library addresses, which are dependent on the deployer account and nonce

Therefore, we must follow the steps below to run EVM tests in this repo:

  1. Run UPDATE_SNAPSHOT=1 yarn test which will ensure gas costs snapshots are updated (i.e. tests will not fail for gas cost reasons)

And to run OVM tests:

  1. Run yarn postinstall to apply a patch that adds OVM mock contract support to Waffle
  2. Run UPDATE_SNAPSHOT=1 yarn test:ovm which will ensure gas costs snapshots are updated (i.e. tests will not fail for gas cost reasons)
  3. On subsequent test runs, run yarn optimism-down && yarn optimism-up && UPDATE_SNAPSHOT=1 yarn test:ovm. This is required so the deployer account nonce is reset to zero, which is necessary to get the above bytecode hash when deploying contracts

Both test commands (yarn test and yarn test:ovm) will automatically update the POOL_INIT_CODE_HASH in PoolAddress.sol as needed for testing.

Note that the _Setup.spec.ts test file must always be run first. This ensures library addresses (which are dependent on account nonce) are always the same, which ensures the bytecode hash is the same on each test run.

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v3-periphery-optimism
License: GPL-2.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #typescript #solidity

Optimism fork Of The Uniswap V3 Periphery Contracts
Best of Crypto

Best of Crypto

1657301340

Solidity Libraries That Are Shared Across Uniswap Contracts

uniswap lib

Solidity libraries that are shared across Uniswap contracts. This package focuses on safety and execution gas efficiency.

Install

Run yarn to install dependencies.

Test

Run yarn test to execute the test suite.

Usage

Install this in another project via yarn add @uniswap/lib

Then import the contracts via:

import '@uniswap/lib/contracts/libraries/Babylonian.sol';

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/solidity-lib
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #solidity

Solidity Libraries That Are Shared Across Uniswap Contracts
Best of Crypto

Best of Crypto

1657294020

The Utility Package for Snapshotting Gas Costs for Uniswap

snapshot gas cost

Tiny utility function for snapshotting gas costs in unit tests.

Objective

This function is useful for smart contract testing against hardhat networks. Use it to produce snapshot diffs that you commit to your repository.

Usage

import snapshotGasCost from '@uniswap/snapshot-gas-cost'
import {Contract} from "@ethersproject/contracts";

describe('gas tests', () => {
    let myContract: Contract
    beforeEach('initialize contract', () => {
        /// initialize myContract
    })
    
    it('gas snapshot for a mutable function', async () => {
        await snapshotGasCost(myContract.someMutableFunction())
    })
    
    it('gas snapshot for a view function', async () => {
        await snapshotGasCost(myContract.estimateGas.someViewFunction())
    })
})

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/snapshot-gas-cost
License: GPL-2.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #typescript

The Utility Package for Snapshotting Gas Costs for Uniswap
Best of Crypto

Best of Crypto

1657286640

Deploy Uniswap V3 Script to any Ethereum Compatible Network

Deploy Uniswap V3 Script

This package includes a CLI script for deploying the latest Uniswap V3 smart contracts to any EVM (Ethereum Virtual Machine) compatible network.

Licensing

Please note that Uniswap V3 is under BUSL license until the Change Date, currently 2023-04-01. Exceptions to the license may be specified by Uniswap Governance via Additional Use Grants, which can, for example, allow V3 to be deployed on new chains. Please follow the Uniswap Governance process to request a DAO vote for exceptions to the license, or to move up the Change Date.

License changes must be enacted via the ENS domain uniswap.eth, which is controlled by Uniswap Governance. This means (among other things) that Governance has the power to associate arbitrary text with any subdomain of the form X.uniswap.eth. Modifications of the Change Date should be specified at v3-core-license-date.uniswap.eth, and Additional Use Grants should be specified at v3-core-license-grants.uniswap.eth. The process for associating text with a subdomain is detailed below:

  1. If the subdomain does not already exist (which can be checked at this URL), the setSubnodeRecord function of the ENS registry should be called with the following arguments:
  • node: namehash('uniswap.eth') (0xa2a03459171c76bff45817330c10ef9f8af07011a33005b73b50189bbc7e7132)
  • label: keccak256('v3-core-license-date') (0xee55740591b0fd5d7a28a6edc49567f6ff3febbe942ec0e2fa49ee536595085b) or keccak256('v3-core-license-grants') (0x15ff9b5bd7642701a10e5ea8fb29c957ffda4854cd028e9f6218506e6b509af2)
  • owner: 0x1a9C8182C09F50C8318d769245beA52c32BE35BC, the Uniswap Governance Timelock
  • resolver: 0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41, the public ENS resolver.
  • ttl: 0
  1. Then, the setText function of the public resolver should be called with the following arguments:
  • node: namehash('v3-core-license-date.uniswap.eth') (0x0505ec7822d61b4cfb294f137d1a7f0ceedf162f555a4bf2f4be58a07cf266c5) or namehash('v3-core-license-grants.uniswap.eth') (0xa35d592ec6e5289a387cba1d5f82be794f495bd5a361a1fb314687c6aefea1f4)
  • key: A suitable label, such as notice.
  • value: The text of the change. Note that text may already be associated with the subdomain in question. If it does, it can be reviewed at the following URLs for either v3-core-license-date or v3-core-license-grants, and appended to as desired.

Note: setContentHash may also be used to associate text with a subdomain, but setText is presented above for simplicity.

These contract function calls should ultimately be encoded into a governance proposal, about which more details are available here.

Usage

This package vends a CLI for executing a deployment script that results in a full deployment of Uniswap Protocol v3. Get the arguments for running the latest version of the script via npx @uniswap/deploy-v3 --help.

As of v1.0.3 the arguments are:

> npx @uniswap/deploy-v3 --help
Usage: npx @uniswap/deploy-v3 [options]

Options:
  -pk, --private-key <string>               Private key used to deploy all contracts
  -j, --json-rpc <url>                      JSON RPC URL where the program should be deployed
  -w9, --weth9-address <address>            Address of the WETH9 contract on this chain
  -ncl, --native-currency-label <string>    Native currency label, e.g. ETH
  -o, --owner-address <address>             Contract address that will own the deployed artifacts after the script runs
  -s, --state <path>                        Path to the JSON file containing the migrations state (optional) (default: "./state.json")
  -v2, --v2-core-factory-address <address>  The V2 core factory address used in the swap router (optional)
  -g, --gas-price <number>                  The gas price to pay in GWEI for each transaction (optional)
  -c, --confirmations <number>              How many confirmations to wait for after each transaction (optional) (default: "2")
  -V, --version                             output the version number
  -h, --help                                display help for command

The script runs a set of migrations, each migration deploying a contract or executing a transaction. Migration state is saved in a JSON file at the supplied path (by default ./state.json).

To use the script, you must fund an address, and pass the private key of that address to the script so that it can construct and broadcast the deployment transactions.

The block explorer verification process (e.g. Etherscan) is specific to the network. For the existing deployments, we have used the @nomiclabs/hardhat-etherscan hardhat plugin in the individual repositories to verify the deployment addresses.

Note that in between deployment steps, the script waits for confirmations. By default, this is set to 2. If the network only mines blocks when the transactions is queued (e.g. a local testnet), you must set confirmations to 0.

Development

To run unit tests, run yarn test.

For testing the script, run yarn start.

To publish the script, first create a version: npm version <version identifier>, then publish via npm publish. Don't forget to push your tagged commit!

FAQs

How much gas should I expect to use for full completion?

We estimate 30M - 40M gas needed to run the full deploy script.

When I run the script, it says "Contract was already deployed..."

Delete state.json before a fresh deploy. state.json tracks which steps have already occurred. If there are any entries, the deploy script will attempt to pick up from the last step in state.json.

Where can I see all the addresses where each contract is deployed?

Check out state.json. It'll show you the final deployed addresses.

How long will the script take?

Depends on the confirmation times and gas parameter. The deploy script sends up to a total of 14 transactions.

Where should I ask questions or report issues?

You can file them in issues on this repo and we'll try our best to respond.

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/deploy-v3
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #typesctipt

Deploy Uniswap V3 Script to any Ethereum Compatible Network
Best of Crypto

Best of Crypto

1657279200

Uniswap V3 Staker | Canonical Liquidity Mining Contract for Uniswap V3

uniswap-v3-staker

This is the canonical staking contract designed for Uniswap V3.

Deployments

Note that the v1.0.0 release is susceptible to a high-difficulty, never-exploited vulnerability. For this reason, please use the v1.0.2 release, deployed and verified on Etherscan on all networks at the address: 0xe34139463bA50bD61336E0c446Bd8C0867c6fE65:

NetworkExplorer
Mainnethttps://etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Rinkebyhttps://rinkeby.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Kovanhttps://kovan.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Ropstenhttps://ropsten.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Goerlihttps://goerli.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Arbitrum Rinkebyhttps://testnet.arbiscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Arbitrum Onehttps://arbiscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Optimismhttps://optimistic.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65
Optimism Kovanhttps://kovan-optimistic.etherscan.io/address/0xe34139463bA50bD61336E0c446Bd8C0867c6fE65

⚠️DEPRECATED⚠️: For historical verification purposes only, the staker at tag v1.0.0 was deployed at the address: 0x1f98407aaB862CdDeF78Ed252D6f557aA5b0f00d

Links:

Development and Testing

$ yarn
$ yarn test

Gas Snapshots

# if gas snapshots need to be updated
$ UPDATE_SNAPSHOT=1 yarn test

Contract Sizing

$ yarn size-contracts

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v3-staker
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #typescript #solidity

Uniswap V3 Staker | Canonical Liquidity Mining Contract for Uniswap V3
Best of Crypto

Best of Crypto

1657271640

Uniswap V2 Periphery | Smart Contracts for interacting with Uniswap V2

Uniswap V2

In-depth documentation on Uniswap V2 is available at uniswap.org.

The built contract artifacts can be browsed via unpkg.com.

Local Development

The following assumes the use of node@>=10.

Install Dependencies

yarn

Compile Contracts

yarn compile

Run Tests

yarn test

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v2-periphery
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #solidity #typescript

Uniswap V2 Periphery | Smart Contracts for interacting with Uniswap V2
Best of Crypto

Best of Crypto

1657264260

Market Depth Calculation for Uniswap V3

This project calculates current and historical market depth from Uniswap V3 liquidity pools and preform comparison against centralized exchange market depths.

Data requirement:

  • Bigquery/Dune Analytics: to obtain all mint and burn events for each pool
    • Run bigquery_mintburn.sql on GCP
  • Subgraph: to obtain block-level price data for pools (alternatively use Bigquery)
  • Coinpaprika API (optional): to get historical price externally
  • Kaiko API (optional): to obtain centralized exchange market depth

Files:

  • depthutil.py Functions used to construct liquidity distribution retrospectively and generate market depth at each historical date and level
  • depthutil2.py V2 version (more efficient) of constructing liquidity distribution and calculating market depth
  • example.py Simple example of market depth calculation
  • genbulkMarketDepth.py for bulk calculation and upload to GCP

To run example: ./run.sh

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v3-market-depth-study
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #python

Market Depth Calculation for Uniswap V3
Best of Crypto

Best of Crypto

1657256880

Uniswap V2 Subgraph | Subgraph Dynamically Tracks any Pair By Uniswap

Uniswap V2 Subgraph

Uniswap is a decentralized protocol for automated token exchange on Ethereum.

This subgraph dynamically tracks any pair created by the uniswap factory. It tracks of the current state of Uniswap contracts, and contains derived stats for things like historical data and USD prices.

  • aggregated data across pairs and tokens,
  • data on individual pairs and tokens,
  • data on transactions
  • data on liquidity providers
  • historical data on Uniswap, pairs or tokens, aggregated by day

Running Locally

Make sure to update package.json settings to point to your own graph account.

Queries

Below are a few ways to show how to query the uniswap-subgraph for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the querying api. These queries can be used locally or in The Graph Explorer playground.

Key Entity Overviews

UniswapFactory

Contains data across all of Uniswap V2. This entity tracks important things like total liquidity (in ETH and USD, see below), all time volume, transaction count, number of pairs and more.

Token

Contains data on a specific token. This token specific data is aggregated across all pairs, and is updated whenever there is a transaction involving that token.

Pair

Contains data on a specific pair.

Transaction

Every transaction on Uniswap is stored. Each transaction contains an array of mints, burns, and swaps that occured within it.

Mint, Burn, Swap

These contain specifc information about a transaction. Things like which pair triggered the transaction, amounts, sender, recipient, and more. Each is linked to a parent Transaction entity.

Example Queries

Querying Aggregated Uniswap Data

This query fetches aggredated data from all uniswap pairs and tokens, to give a view into how much activity is happening within the whole protocol.

{
  uniswapFactories(first: 1) {
    pairCount
    totalVolumeUSD
    totalLiquidityUSD
  }
}

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v2-subgraph
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract

Uniswap V2 Subgraph | Subgraph Dynamically Tracks any Pair By Uniswap
Best of Crypto

Best of Crypto

1657249500

Sybil Interface | A Governance Tool for Discovering Delegates

Sybil Interface

Sybil is a governance tool for discovering delegates. Sybil maps on-chain addresses to digital identities to maintain a list of delegates. This interface displays governance data for supported protocols, and also allows users to link social profiles with their Ethereum addresses.

Mainnet support only.

Social Verification

Sybil is a tool that connects wallet addresses to digital identities. Users sign messages with their Ethereum keys, and post signatures on their social profiles. Verifiers can then check these signatures and verify truthful address -> profile mappings.

This interface allows users to connect their Ethereum addresses to social profiles using the Sybil verification flow. For more detailed documentation on the Sybil verification process, see here: https://github.com/Uniswap/sybil-list

Supported Social Platforms

This interface supports social verification through Twitter only. However, more platforms can be added in the future (Github, etc).

Governance

The interface allows users to view data about delegates and proposals for multiple Ethereum governance. Users can also delegate votes and vote on active proposals.

Supported protocols

Currently Uniswap and Compound governance are supported in the interface.

Adding protocol support

Forks of Compound or Uniswap governance can easily be integrated into the interface. There are two data sources the interface uses: data directly pulled from Governance contracts and data from governance subgraphs.

Steps to add new protocol support:

Add relevant information to list of supported protocols in reducer.js

Make sure to have a subgraph that can return data that matches the stuctures in queries.js. See subgraph code for governance here: https://github.com/protofire/compound-governance-subgraph. This subgraph can easily be forked and pointed towards other governance systems.

Add subgraph client support by adding relevant information in client.js and in hook useSubgraphClient in hooks.ts

PR's for additional protocol support are welcome.

Development

Install Dependencies

yarn

Run

yarn start

Configuring the environment (optional)

To have the interface default to a different network when a wallet is not connected:

  1. Make a copy of .env named .env.local
  2. Change REACT_APP_NETWORK_ID to "{YOUR_NETWORK_ID}"
  3. Change REACT_APP_NETWORK_URL to e.g. "https://{YOUR_NETWORK_ID}.infura.io/v3/{YOUR_INFURA_KEY}"

Note that the interface only works on mainnet to limit the amount of required data sources for governance systems.

Contributions

Please open all pull requests against the master branch. CI checks will run against all PRs.

Learn More

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/sybil-interface
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract

Sybil Interface | A Governance Tool for Discovering Delegates
Best of Crypto

Best of Crypto

1657242180

Hardhat V3 Deploy | Hardhat Plugin for Uniswap V3 Deployment

hardhat-v3-deploy

Deploy Uniswap V3 contracts in development.

Installation

$ npm install @uniswap/hardhat-v3-deploy

Import the plugin in your hardhat.config.js:

require("@uniswap/hardhat-v3-deploy");

Or if you are using TypeScript, in your hardhat.config.ts:

import "@uniswap/hardhat-v3-deploy";

Now, run npm run hardhat and you should see:

AVAILABLE TASKS:

  accounts          Prints the list of accounts
  ...
  deploy-uniswap    Deploys Uniswap V3 contracts
  ...
  test              Runs mocha tests

Great! Now, to deploy the contracts:

$ npm run hardhat deploy-uniswap

And you're done. Time to build something great.

Plugin Development

TODO

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/hardhat-v3-deploy
License: MIT license

#uniswap #blockchain #ethereum #defi #smartcontract #hardhat #typescript

Hardhat V3 Deploy | Hardhat Plugin for Uniswap V3 Deployment
Best of Crypto

Best of Crypto

1657238340

The Token Lists Specification for Uniswap Protocol

token lists

This package includes a JSON schema for token lists, and TypeScript utilities for working with token lists.

The JSON schema represents the technical specification for a token list which can be used in a dApp interface, such as the Uniswap Interface.

What are token lists?

Uniswap Token Lists is a specification for lists of token metadata (e.g. address, decimals, ...) that can be used by any dApp interfaces that needs one or more lists of tokens.

Anyone can create and maintain a token list, as long as they follow the specification.

Specifically an instance of a token list is a JSON blob that contains a list of ERC20 token metadata for use in dApp user interfaces. Token list JSON must validate against the JSON schema in order to be used in the Uniswap Interface. Tokens on token lists, and token lists themselves, are tagged so that users can easily find tokens.

JSON Schema $id

The JSON schema ID is https://uniswap.org/tokenlist.schema.json

Validating token lists

This package does not include code for token list validation. You can easily do this by including a library such as ajv to perform the validation against the JSON schema. The schema is exported from the package for ease of use.


import { schema } from '@uniswap/token-lists'
import Ajv from 'ajv'
import addFormats from 'ajv-formats'
import fetch from 'node-fetch'

const ARBITRUM_LIST = 'https://bridge.arbitrum.io/token-list-42161.json'

async function validate() {
  const ajv = new Ajv({ allErrors: true, verbose: true })
  addFormats(ajv)
  const validator = ajv.compile(schema);
  const response = await fetch(ARBITRUM_LIST)
  const data = await response.json()
  const valid = validator(data)
  if (valid) {
    return valid
  }
  if (validator.errors) {
    throw validator.errors.map(error => {
      delete error.data
      return error
    })
  }
}

validate()
  .then(console.log("Valid List."))
  .catch(console.error)

Authoring token lists

Manual

The best way to manually author token lists is to use an editor that supports JSON schema validation. Most popular code editors do, such as IntelliJ or VSCode. Other editors can be found here.

The schema is registered in the SchemaStore, and any file that matches the pattern *.tokenlist.json should automatically utilize the JSON schema for the supported text editors.

In order for your token list to be able to be used, it must pass all JSON schema validation.

Automated

If you want to automate token listing, e.g. by pulling from a smart contract, or other sources, you can use this npm package to take advantage of the JSON schema for validation and the TypeScript types. Otherwise, you are simply working with JSON. All the usual tools apply, e.g.:

import { TokenList, schema } from '@uniswap/token-lists'

// generate your token list however you like.
const myList: TokenList = generateMyTokenList();

// use a tool like `ajv` to validate your generated token list
validateMyTokenList(myList, schema);

// print the resulting JSON to stdout
process.stdout.write(JSON.stringify(myList));

Semantic versioning

Lists include a version field, which follows semantic versioning.

List versions must follow the rules:

  • Increment major version when tokens are removed
  • Increment minor version when tokens are added
  • Increment patch version when tokens already on the list have minor details changed (name, symbol, logo URL, decimals)

Changing a token address or chain ID is considered both a remove and an add, and should be a major version update.

Note that list versioning is used to improve the user experience, but not for security, i.e. list versions are not meant to provide protection against malicious updates to a token list; i.e. the list semver is used as a lossy compression of the diff of list updates. List updates may still be diffed in the client dApp.

Deploying your list

Once you have authored the list, you can make it available at any URI. Prefer pinning your list to IPFS (e.g. via pinata.cloud) and referencing the list by an ENS name that resolves to the contenthash.

If hosted on HTTPS, make sure the endpoint is configured to send an access-control-allow-origin header to avoid CORS errors.

Linking an ENS name to the list

An ENS name can be assigned to an IPFS hash via the contenthash text record. This is the preferred way of referencing your list.

Examples

You can find a simple example of a token list in test/schema/example.tokenlist.json.

A snapshot of the Uniswap default list encoded as a token list is found in test/schema/bigexample.tokenlist.json.

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/token-lists
License: MIT license

#uniswap #blockchain #ethereum #defi #smartcontract

The Token Lists Specification for Uniswap Protocol
Best of Crypto

Best of Crypto

1657231020

Uniswap V2 Core | Core Smart Contracts Of Uniswap V2

Uniswap V2

In-depth documentation on Uniswap V2 is available at uniswap.org.

The built contract artifacts can be browsed via unpkg.com.

Local Development

The following assumes the use of node@>=10.

Install Dependencies

yarn

Compile Contracts

yarn compile

Run Tests

yarn test

Download Details:
Author: Uniswap
Source Code: https://github.com/Uniswap/v2-core
License: GPL-3.0 license

#uniswap #blockchain #ethereum #defi #smartcontract #typescript #solidity

Uniswap V2 Core | Core Smart Contracts Of Uniswap V2