Code Monkey home page Code Monkey logo

switcheo's Introduction

Switcheo

An implementation of a NEO decentralized exchange

Manual Withdrawal from V2 Contract

Read wiki here

NOTE: The README below is outdated and refers to V1 Contract and will be updated soon to better reflect the V2 contract contents

Usage

There are 4 main operations for this DApp:

  • makeOffer

    This allows users to make a asset swap offer on the contract.

    The params required are:

    1. script hash of the offer maker (invoking user)
    2. script hash of the asset being offered
    3. amount of asset being offered
    4. script hash of the asset wanted in return
    5. amount of asset being wanted

    SystemAssets must be attached if they are part of the fill.

    Once invoked, the offered amount will be transferred to the smart contract, and the offer will be placed on the blockchain for anyone with the corresponding assets to fill.

    NEP-5 tokens and SystemAssets are the currently supported asset types.

  • fillOffer

    This allows users to fill an offer on the contract.

    The params required are:

    1. script hash of the offer filler (invoking user)
    2. offer hash of the offer to be filled
    3. the amount offered that should be filled

    SystemAssets must be attached if they are part of the fill.

    Once invoked, the offer corresponding to the second arg will be filled. Partial filling is possible.

    Amounts will be transferred to the maker and filler for withdrawal in a second transaction.

  • cancelOffer

    This allows a user to cancel a previous offer that has not been completely filled.

    The params required are:

    1. offer hash to be cancelled

    Once invoked, the offer will be cancelled and any remaining balance will be credited to the user balance for withdrawal in a second transaction.

  • withdrawAssets

    This allows users to withdraw their balance in the smart contract.

    The params required (NEP-5) are:

    1. script hash of the user to withdraw balance from
    2. script hash of the asset to withdraw
    3. amount of asset to withdraw

    For SystemAssets, params are not required, but the transaction must be invoked with a TransactionAttribute of Usage 0xd1 and Data 0x01. We chose an implementation which uses transaction attributes instead of "method arguments" to prevent double withdrawals before main net deployment.

    Our implementation currently does not allow a transfer trading of this balance and this operation must always be called to make use of the swapped asset.

Offer listing

In order to find offers on the blockchain, list traversal can be used. By querying the contract's storage with a concatenation of the offered and wanted asset script hashes, the head of the list can be obtained.

This will give the offerHash of the latest offer on the trading pair. This allows the offer information to be queried and deserialized. Each offer contains the offerHash of the next offer.

In this way, the list can be traversed entirely, and a order book can be displayed / cached.

Example

Test on beta client at V2 Testnet at the bottom right https://beta.switcheo.exchange Or trade on directly on mainnet https://www.switcheo.exchange

Future work

There remains certain TODOs that are incomplete in V2.

  • Usage of DynamicCall

    We hardcoded all known NEP-5 tokens in our contract as Appcall can only be done statically at the moment. We hope to push for the implementation of DynamicCall in the vm / compiler so that the contract does not need to be updated.

switcheo's People

Contributors

henrytimelessness avatar ravenxce avatar switchythecoder avatar

Watchers

 avatar  avatar

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.