gitcoinco / skunkworks

experimental laboratory
63 stars 35 forks source link

open source decentralized exchange. #28

Open owocki opened 6 years ago

owocki commented 6 years ago

so anyone can host a DEX

kamescg commented 6 years ago

Been thinking about this a lot recently.

What do you think is the best place to start? Begin with some preliminary mockups and designs? Or start with the smart contract code?

owocki commented 6 years ago

seems like two diff skillsets to me. i think we'd start with building a team

kamescg commented 6 years ago

You might be right :) Good plan.

I'll help put out the signals. Team

kamescg commented 6 years ago

Just in case we want to pick up the conversation again in the future, I setup a React Dashboard Application with the Ethers library connected to Infura.

https://github.com/KamesCG/dex

The Ethers library is wrapped in Redux Saga's and components can import smart contract ABI directly.

An example of React component, which wraps blockchain functionality can be found at https://github.com/KamesCG/locateth/blob/master/src/core/assimilation/fetching/ethers/EthersEnsBlockScanFormTransition/index.js

It's a little messy...

A similar approach could probably be used to deploy decentralized exchange smart contracts via a modular approach. In this particular instance the Ethereum Name System ABI is being passed to the component, but it primarily just uses core ethers functionality to make blockchain requests.

The ethers integration can be found at:

src/core/assimilation/fetching/ethers

The Smart Contacts (including the ABI) can be stored in contracts and Webpack will bundle them together with custom Ether's components that wraps the smart contract functionality with the appropriate React component UI.

The PSD can be found in resources/skeleton.psd

PSD Prototype

Demo

Current Code

Demo

owocki commented 6 years ago

this is awesome.... lets try to find someone to do the smart contract development and kick off the bounty / build for this..

heyellieday commented 6 years ago

@KamesCG, this looks awesome! As someone who has used react for many projects, but has more recently gotten into dapps, it’s great to see the two worlds meet.

@owocki, I don’t have a ton of Solidity experience compared to many in this space, but I know enough to be dangerous :) I’ve been searching for a project like this for a bit so I’d love to help out with the Solidity part of this project while being available to help with the JS/React side as well.

kamescg commented 6 years ago

@heyellieday React (maybe in the future WebComponents) and dApps are totally amazing together. Component based design and decentralized systems just seem so perfect for each other :) I've been playing around the idea of auto-generating React components using the smart contract ABI and have those auto-populate a drag and drop editor.

It might lend itself to creating a more customizable interface for anyone interested in launching a decentralized exchange.

Demo

owocki commented 6 years ago

I don’t have a ton of Solidity experience compared to many in this space, but I know enough to be dangerous :)

working on OSS is a great way to learn. im really bad at RTFM programming myself!

@jclancy93 might be interested in pairing with you on the solidity :)

jclancy93 commented 6 years ago

I don’t have a ton of Solidity experience compared to many in this space, but I know enough to be dangerous :)

I'm in the same boat :). I'm far from a Solidity pro but I think I have a decent grasp of the language now. All of EtherDelta's contracts are open source though, so we definitely have a good place to start.

cpurta commented 6 years ago

Have a fair amount of experience in solidity. I have thought quite a bit about how you could implement an exchange via smart contracts. Definitely interested in scoping out what the contracts would look like in order to achieve this.

mkosowsk commented 6 years ago

Yet another person chiming in with not a ton of Solidity experience but will be watching this closely and looking to contribute where I can... great idea!

jclancy93 commented 6 years ago

The EtherDelta smart contracts can be found here if anyone is curious @cpurta. I personally have used EtherDelta pretty extensively pre it getting bought, then hacked, then having an ICO, needless to say I wont touch it anymore.

It is worth noting that EtherDelta has always done order-matching off chain, on a private server. So does 0x, for performance/cost reasons.

Overall, from a UX perspective its a solid platform. One of the major flaws of ED is that the smart contract also stores accounts. Basically, you have to deposit money to the EtherDelta contract before you can trade. I think ED was designed this way so that once a user deposits tokens to the platform, they can trade for free, since signing a message with your private key is all that is necessary to post an order to the order books.

Ideally, it would be great if the only ETH/tokens the DEX contract held was on the order books. Currently, the EtherDelta contract holds $100MM+, making it a highly lucrative target. This could help mitigate that somewhat. Maybe we could offer users the options to do both trade with or without an account (meaning they would have to create a TX for each trade)?

kamescg commented 6 years ago

Seeing as we have the starting support for a Decentralized Exchange now it might be worthwhile to ask @owocki once he's back from a ski trip (as mentioned in Slack - https://gitcoin.co/slack), to see if we can setup a new repository, and organize ideas/issues under a primary repo.

Personal Tasks To Be Completed

  1. Prepare repository for contributions (comments, notes, cleanup, etc...)
  2. Continued PSD Mockups + UX/UI Design
  3. Better Blockchain Development Workflow - Ganache (http://truffleframework.com/ganache)
  4. Add Storybook (https://github.com/storybooks/storybook) and UI Testing for React Components

Question?

Should Gitcoin (or ancillary DAO) maintain a Decentralized Exchange to serve as a community owned asset?

The fees, instead of profits for centralized company, can be used to support the Bounty program 100%. Both for tasks related to the DEX, and perhaps other less "sexy" Open Source projects that don't get immediate investment, because of a more distant value proposition... compared to software that supports "To the moooon!"

Seeing as we could potentially have a byzantine battalion (10s, maybe 100s) of developers/designers/engineers, using the Gitcoin model, it begs the question "Aren't we the ones most suited to deploy and maintain a decentralized exchange for the increasing market demand?"

The market has some obvious expectations...

Imgur

But if we meet those expectations, in addition to the value proposition of complete transparency for funding Open Source projects (that benefit the larger ecosystem), I imagine that might be interesting to some people?

0xean commented 6 years ago

definitely will keep an eye on this

heyellieday commented 6 years ago

@jclancy93, thanks for sharing the information about the Etherdelta smart contract. I spent time yesterday familiarizing myself with it and it does a lot of things right. This reddit post by the maintainer was helpful as they explained parts of the contract in more detail. Like you mentioned, the contract architecture makes a lot of sense, but holding large sums of money in one contract could make the contract a target. I agree that keeping funds in the contract only during an open trade could minimize that risk, but is likely to degrade UX.

I also came across two existing DEX projects, IDEX and LocalEthereum. They both run off of smart contracts but are not fully decentralized. IDEX (https://idex.market) is currently semi-decentralized with a smart-contract to execute the trades, but a centralized trading engine. Their whitepaper claims that they want to eventually become fully decentralized.

LocalEthereum (https://localethereum.com/) also runs in a similar semi-decentralized way, but differs in that it is a fiat to ethereum exchange, so it can't be truly trustless. I found this post detailing their smart contract interesting though, so I'm mentioning them here.

While the two exchanges above and EtherDelta are not fully decentralized, the off-chain aspects such as order books do make them easier to use. Sadly, their order books are centralized. Can we make an off-chain order book, but keep it decentralized? IPFS and something like orbit-db, a p2p database that runs on IPFS, might make that possible. I have to do more testing, but it seems like it could work to use orbit-db as an off-chain order book in a similar way to how EtherDelta uses their centralized server to manage orders. Roughly, it could work like so:

  1. For discovery, list of active orbit-db addresses are maintained in mapping in main DEX contract
  2. dex front-end clients (the end users) can view and submit cryptographically signed orders by connecting to the active orbit-db(s) listed in the smart contract.
  3. End users can then execute a trade transaction via the on-chain contract, passing in the signed order data retrieved from the p2p orbit-db where the contract would execute the trade if valid. Check out how EtherDelta verifies the order is valid in their contract source code.
  4. Clients listening to a "trade completed" event emitted from smart contract update orbit-db to reflect completed trade

While the above is a simplification, I think it illustrates a fully decentralized, yet off-chain order book is possible. Again, I have to research this more, but I think using orbit-db's append-only log mode with a merge function that reduces like-logs to the current state of a given order may be a viable option to keep state up to date. However, I need to verify that the contract's trading function could produce an event signature that would be provably from the smart contract so that the merge function could successfully reduce the state of a given order.

Ok, enough technical talk for now though :)

@KamesCG, I love the idea of the revenue from the DEX being used to fund bounties to make the DEX (and supporting infrastructure) better! I think building such a mechanism into the smart contract could be very powerful. At the very least, the smart contract could send the generated fees to another smart contract DAO that is responsible for managing the funds to improve the DEX. One idea could be to put the funds into Gitcoin, but find a way to "earmark" funds to be used for specific types of tasks.

I'm liking how this is shaping up!

kamescg commented 6 years ago

Another interesting approach to off-chain computation could potentially be using the iExec platform (https://iex.ec/) as an interface into a cloud computing marketplace where "As a Provider, you can lend your machine power and monetize it by executing developer applications."

owocki commented 6 years ago

hey all... glad to see all the action on this thread.

i dont have the time to get super organized about specifying this... but if one of you want sto take the lead on building a spec and some wireframes, im happy to put some ETH towards design and development

@KamesCG @heyellieday @pelsasser @jclancy93 etc

kamescg commented 6 years ago

I would love to contribute. What about an active working group? Maybe someone(s) wants to join forces for the initial specification, wireframes and general design/development strategy?

Also, a grant is available by iExec, to create distributed applications using their decentralized computing platform. The grant request is due January 19th. We could write a grant request, specifically discussing this project and apply for a $5,000+ grant to fund initial bounties.

Should we create a Gitcoin specific decentralized exchange repo?

owocki commented 6 years ago

Should we create a Gitcoin specific decentralized exchange repo?

im happy to create a repo for this..

not entirely sure it needs to be gitcoin branded... but it'd be nice to tie it back to the gitcoin community if thats where the funding / talent comes from.

it might be worth having a kickoff call with people who have the time / cycles to work together on this... from there we can figure out funding (i can help with this, as can iExec, as you mentioned)

kamescg commented 6 years ago

Perhaps a name like Gitmint?

Personally, I think it's important to push for the possibility for community owned/governed assets, which can create closed-loop value systems for the Open Source Software ecosystem - like permaculture, but for code. Would be exciting to see a decentralized exchange specifically built with the intention of replenishing value back into an active community.

Might be an interesting time to think about a decentralized, but shared calendar system?

kamescg commented 6 years ago

Gitmint Setup the Gitmint Organization - https://github.com/GitmintCore/gitmintcore

kamescg commented 6 years ago

Making some progress on the developer boilerplate.

Can checkout screenshot - https://twitter.com/KamesCG/status/952043200033603584- system booting up, compiling EtherDelta smart contracts, pushing them to local blockchain, and finally showing the block/transactions in the dashboard.

  1. Bootup Ganache
  2. Compile DEX Smart Contracts
  3. Deploy Smart Contracts
  4. Start React Hot Loading Server
  5. Initialize React Components w/ ABI

Gitmint Gitmint