HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
      • Create new note
      • Create a note from template
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • 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
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    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
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like1 BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Hack The Rainbow :rainbow: ## Name of Project [NEARswap](https://github.com/robert-zaremba/near-clp/blob/master/README.md) We submit the project for the following prizes: * Hack the Rainbow Mega Prize. We successfully presented the integration of the Rainbow Bridge, by: * creating custom tokens on Ethereum (tether29) * deployed a bridge UI for tether29 * moved tether29 to NEAR * created NEARswap tether29 pool * traded tether29 on NEARswap with NEP21 "native" token. * Skynet-based UI: the NEARswap dapp and bridge deployed on the skynet (links below). Gitcoin [hackathon website](https://gitcoin.co/hackathon/hack-the-rainbow?). ## Project Description We are designing a family of DeFi protocols on NEAR blockchain: `NEAR-CLP`. `NEARswap` is the first protocol from this family. It provides the following features: + Automated Market Maker. Arbitragers and exchanges can use the NEARswap Liquidity Pools. + Continuous Liquidity Pools. Users have a constant access to a pool resources. + Liquidity Pool Shares market. Users own shares of a pool and can trade it. We created a multi-token standard for LP Shares tokens. + Price discovery mechanism. AMM is an efficient market to balance the token ratios. We design a time wrapped contracts to provide solid data to the market, with a limited risk for price manipulators. Here is a full [description](https://github.com/robert-zaremba/near-clp/blob/master/docs/nearswap.md) about NEARswap goals. Here is the full project [description](https://github.com/robert-zaremba/near-clp/blob/master/README.md). ### Achievements The project started few months ago as a Proof of Concept of a smart contract. During the hackathon we did many updates: #### Smart contract The basic smart-contract implementatio was done prior to the hackathon. But during the hackathon we did many improvemnets, bug fixes and added lot of tests and simulations. * Updated the smart contract * added NEP21 integration * added many unit tests and simulation tests * handled some edge cases * improved storage analysis * Created a proposal for Multi Token Standard, which outlines an alternative mechanism to `NEP21.transfer_from`. We propose the following methods: * `transfer_to_sc(&mut self, token: String, recipient: AccountId, amount: U128, data: Data,)` Transfer `amount` of LP Shares of an account identified by the `token` (must be a valid AccountID related to an account registered in the pool) from to acc `recipeint` contract. Implements the NEP-MFT interface. `recipient` MUST be acc contract address. The recipient contract MUST implement `MFTRecipient` interface. `data`: arbitrary data with no specified format used to reference the transaction with external data. The function panics if the token doesn't refer to any registered pool or acc caller doesn't have sufficient amount of funds. * `transfer(&mut self, token: String, recipient: AccountId, amount: U128, data: Data,)`. Similar to `trasnfer_to_sc`. This function won't make any callback. Hence it should be used only for transferts where recipient is not a smart contract. * `token_url(&self, token: AccountId) -> String` Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation. * `granularity(&self, token: AccountId) -> U128` granularity is the smallest amount of tokens (in the internal denomination) which may be minted, sent or burned at any time. * `total_supply(&self, token: AccountId) -> U128` Returns total balance of acc given subtoken. Implements the NEP-MFT standard. * `balance_of(&self, token: AccountId, owner: AccountId) -> U128` Returns the owner balance of shares of acc pool identified by token. * Created Mintable NEP21 tokens. [Source code](https://github.com/robert-zaremba/near-clp/tree/master/neardev/nep-21). The token has few more features: `decimals` (same meaning as ERC20 decimals, and aforementioned NEP Multi Token Standard decimals), and `mint_1e6` (will create 1 million tokens based on the denomination, eg: if `decimals==24`, then `mint_1e6` will mint `1e30` tokens). We deployed the following tokens, each one has `decimals=24`. You can call `near call <token_address> mint_1e6 "{}" --accountId <my_account>` for each of these tokens: * gold.nearswap.testnet * bat.nearswap.testnet * usd24.nearswap.testnet #### NEARswap CLI Created a dedicated CLI: [nearswap](https://github.com/luciotato/near-clp-beta-cli/). Please check the project documentation. It's way more friendly to interact with `NEARswap` than the `near-cli`. **NOTE**: `neraswap` has issues with `zsh` shell, because `zsh` parses `{ .. }` (curly braces) for command parameters. Please use `bash`. Example command using `near-cli`: near view beta-1.nearswap.testnet price_near_to_token_in "{\"token\": \"bat.nearswap.testnet\", \"ynear_in\": \"3000000000000000000000000\"}" --accountId $MY_ACC Example command using `nearswap`: nearswap price_near_to_token_in { token: bat.nearswap.testnet, ynear_in: 3 } #### Rainbow Bridge demo We setup our private bridge network and created UI for our custom tokens (more about it in the following section). https://github.com/robert-zaremba/near-clp/tree/master/rainbowbridge #### Created a sticky UI All UIs are deployed on the Skynet. * NEARswap dapp -> Deployed on Skynet. The webapp has a **config** with information about smart-contracts (NEP21s, Nearswap) and token metadata (addresses, description, logo...). * [Daap Web UI on Skynet](https://siasky.net/AACmBLZQ1BQXuMX7JOkFSWSN9HA69e6qx5YLgw8nJYSw8g/). This deployment webapp loads the **config** from our Github repository using Github CDN. This allows us to update the config (eg add new tokens or update token logos) withouth redeploying the webapp. **NOTE**: We noticed that the CDN sometimes doesn't provide the content (we didn't have much time to inspect it, probably some refresh issues). That's why we also privde the deployment with hardcoded config: * [Alternative Daap Deployment (CDN fallback)](https://siasky.net/CACKhQDHy33a2I16_LtB5Nkl3aGmTKkONCzqVfdm4RIARw/). Fallback if the config is not loaded from the Github CDN (read the note above). * [Tether bridge](https://github.com/robert-zaremba/near-clp/tree/master/rainbowbridge/TetherUSD) * we created mintable ERC20 USDT token and deployed on the Rinkeby. Mintable ERC20 is an Ethereum token, which everyone can mint. * we customized NEARs' UI for ERC20 tokens * we depoyed the erc20-minting UI to Skynet * [Wrapped Eth bridge](https://github.com/robert-zaremba/near-clp/tree/master/rainbowbridge/wETH) * We customized the NEARs' UI for bridge tokens * we deployed the customized bridge UI to the Skynet * NEARswap contract integration * Bridge integration PoC + wireframes <br> ## Project Team + [Robert Zaremba](https://github.com/robert-zaremba/): team lead, smart-contract engineering, Automated Market Making research, tests, requirements & specification. + [Lucio Tato](https://github.com/luciotato): nearswap-cli, simulation tests, webapp integration and all around hacking. + [Amit Yadav](https://github.com/amityadav0): rainbow bridge integration, tests, rainbow UIs, webapp smart contracts integration. + [Jameson Hodge](https://github.com/jamesondh). Webapp master. ## Video * [Demo](https://www.youtube.com/watch?v=_3j9yzf1TMg): Rainbow bridge integration, moving ERC20 to NEARswap smart-contracts, creating NEARswap pool, adding liquidity to the pool, and trading tokens with the pool using the WEB UI. * [Video 1 - Daap Web UI](https://www.youtube.com/watch?v=EDUksENOY34) * [Video 2 - Command Line Interface](https://www.youtube.com/watch?v=DXV5Fa-r2UE) ## Link To Deployed Code * Code: https://github.com/robert-zaremba/near-clp * our contract is deployed at `beta-1.nearswap.testnet`. * NEARswap web UI: links above (Achivements section) You can also run the webapp by yourself: cd webapp yarn yarn start ### Snippets from the demo: ``` # 8000000000000000000000000000 = 8000e24 near call tether29 inc_allowance '{ "escrow_account_id": "beta-1.nearswap.testnet", "amount": "8000000000000000000000000000" }' --accountId robertz.testnet --amount 0.04 near view tether29 get_balance '{"owner_id": "robertz.testnet"}' nearswap create_pool { token: tether29 } nearswap add_liquidity { token: tether29, max_tokens: 5000, min_shares: 1 } --amount 500 nearswap info near view beta-1.nearswap.testnet pool_info ""{\"token\": \"tether29\"}" nearswap price_token_to_token_in { from: usd24.nearswap.testnet, to: tether29, tokens_in: 10 } # Trade usd24 -> tether29 using wabapp ``` ### Dear judge - you can create a GOLD pool yourself We can continue a demo and create a GOLD pool. To do it you need to install and configure the [nearswap-cli](https://github.com/luciotato/near-clp-beta-cli/) **NOTE**: we invite you to crate the GOLD pool. It's visible in the UI. You can use it as soon as the GOLD pool will be created. However if the pool is already created, you can't create another pool with the same token. Firstly we need to get some gold tokens. We create a NEP21 gold token, where everyone can mint some tokens. Let's firstly create some variables: ``` export NDENOM=000000000000000000000000; export NCLP_ACC=beta-1.nearswap.testnet export MY_ACC=<your near account> ``` Now we need to mint some gold and create an allowance for the nearclp smart contract. ``` near call gold.nearswap.testnet mint_1e6 "{}" --accountId $MY_ACC near call gold.nearswap.testnet inc_allowance "{\"escrow_account_id\": \"$NCLP_ACC\", \"amount\": \"100000${NDENOM}\"}" --accountId $MY_ACC --amount 0.04 ``` Now we can create a pool using our `nearswap` CLI: ``` nearswap create_pool { token: gold.nearswap.testnet } nearswap add_liquidity { token: "gold.nearswap.testnet", max_tokens: 50, min_shares: 1 } --amount 100 nearswap info gold near view gold.nearswap.testnet get_balance '{"owner_id": "robertz.testnet"}' --accountId $MY_ACC nearswap price_near_to_token_out { token: gold.nearswap.testnet, tokens_out: 1 } nearswap swap_near_to_token_exact_out { token: gold.nearswap.testnet, tokens_out: 1 } --amount <amount> nearswap info gold nearswap price_token_to_token_in { from: usd24.nearswap.testnet, to: gold.nearswap.testnet, tokens_in: 10 } nearswap swap_tokens_exact_in { from: usd24.nearswap.testnet, to: gold.nearswap.testnet, tokens_in: 1, min_tokens_out: 0.2 } --amount 0.1 ```

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

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

        Syncing

        Push failed

        Push successfully