marko
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # [DEX Integration] Ring V2 protocol ## :beginner: The goal Fully implementing the Ring V2 protocol in Tycho, which means providing solutions for: - Indexing - Execution - Simulation Across Mainnet, Base, and Unichain blockchain networks. ## :beginner: How does Ring V2 protocol work Ring V2 protocol is a UniswapV2 clone, with an exception, it uses wrapped tokens for all things swap related internally. The wrapper is called "Few protocol", and is represented by the `FewFactory` contract that deploys, and returns, respective wrapped tokens. The following contracts are shared between the two protocols: - `SwapV2Factory` - `SwapV2Pair` - note that Pairs are exclusively made up of wrapped tokens, not regular IERC20 ones `SwapV2Router` - this contract has a lot of changes compared to it's source, but the most notable one is that all wrapping is done inside of the methods respectfully. So the user doesn't have to wrap their own token at any time when interacting (altering liquidity). A swap starting and ending with unwrapped IERC20 tokens is executed trough the `SwapV2Router` contract. ## :beginner: Indexing `tycho-integration-sdk` The following events should be indexed in order to have full protocol state available at all times: - `SwapV2Factory.PairCreated` - Triggered upon a UniswapV2 style pool creation - store pools in a map - note that wrapped token addresses are emitted - `SwapV2Pair.PairEvents` - Triggered upon pool state change - should trigger price updates - note that wrapped token addresses are emitted - `FewFactory.WrappedTokenCreated` - store tokens in a `FewToken:Token` map This way we will have all needed data to fully represent the protocol. The starting blocks are determined by the `SwapV2Factory` deployment block on each chain respectfully. The indexing configs are going to be in the `<chain>-ring-v2.yaml` format. ## :beginner: Simulating `tycho-simulation` The Ring V2 protocol simulation is going to be natively integrated into the codebase. It's similar to the way Uniswap V2 exchanges are implemented. Including the `state` and `tycho_decoder` interfaces. As far as we know, there is no need to implement the `ISwapAdapter` interface. The implementation in `evm/protocol` will also include tests ensuring proper functionality. ## :beginner: Executing `tycho-exection` The `encode_swap` function will be implemented, for interacting with the `Executor` contract. A `RingV2Executor` will be created, in order to match the interface for swap execution. The contract itself will be similar to `UniswapV2Executor`. The contract will be an implementation of the `IExecutor` contract shown below: ```solidity / SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.26; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; pragma abicoder v2; interface IExecutor { /** * @notice Performs a swap on a liquidity pool. * @dev This method takes the amount of the input token and returns the amount of * the output token which has been swapped. * * Note Part of the informal interface is that the executor supports sending the received * tokens to a receiver address. If the underlying smart contract does not provide this * functionality consider adding an additional transfer in the implementation. * * @param givenAmount The amount of the input token to swap. * @param data Data that holds information necessary to perform the swap. * @return calculatedAmount The amount of the output token swapped, depending on * the givenAmount inputted. */ function swap( uint256 givenAmount, bytes calldata data ) external payable returns (uint256 calculatedAmount); } interface IExecutorErrors { error InvalidParameterLength(uint256); error UnknownPoolType(uint8); } ``` Also tests covering the new `RingV2Executor` contract will be included in the `foundry/test` directory, ensuring proper functionality. ## :beginner: Expected time goal It's expected the integration will last 4 weeks. About a week per repo, plus a week of various unknowns that will certainly be unveiled. ## :beginner: Mainnet - Contract addreses `Ring Swap Factory` `0xeb2A625B704d73e82946D8d026E1F588Eed06416` `Few Factory` `0x7D86394139bf1122E82FDF45Bb4e3b038A4464DD` `Ring Swap Router` `0x39d1d8fcC5E6EEAf567Bce4e29B94fec956D3519` `UniversalRouter` `0xEff87A51f5Abd015F1AFCD5737BBab450eA15A24` `Permit2` `0x000000000022D473030F116dDEE9F6B43aC78BA3` `FewETHWrapper` `0xAda6059b4F6244Acd8934095Ed0162C5Df6B5ebB` ## :beginner: Base - Contract addreses `Ring Swap Factory` `0x9BfFC3B30D6659e3D84754cc38865B3D60B4980E` `Few Factory` `0xb3Ad7754f363af676dC1C5be40423FE538a47920` `Ring Swap Router` `0x224749CDd5791480ECEBE452e5FFAEfEf94Cd254` `UniversalRouter` `0x9a8C67C02250EC50f16b6143D139CbDB131f1e07` `Permit2` `0x000000000022D473030F116dDEE9F6B43aC78BA3` `FewETHWrapper` `0x20E6B1260d12910C0Ab13c1AbEBCFe24AE9c4fe7` ## :beginner: Unichain - Contract addreses `Ring Swap Factory` `0xEeE400Eabfba8F60f4e6B351D8577394BeB972CD` `Few Factory` `0x974Cc3F3468cd9C12731108148C4DABFB5eE556F` `Ring Swap Router` `0xf9d7ff2f6A0c3631A807199276a493Af8097916F` `UniversalRouter` `0xE17e4e8A43c1A0a1844BDe72ACA86Be3B81b28aF` `Permit2` `0x000000000022D473030F116dDEE9F6B43aC78BA3` `FewETHWrapper` `0xc43a3Dd1b16168e00297315d679840e30A89df42`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully