# Decentralised USD to xDai exchange
This project consists of two systems that can be developed independently -
1. Peer to peer USD xDai exchange
2. Dispute resolution DAO
Participants involved in system -
1. Buyer: someone receiving xDai and sending USD
2. Seller: someone receiving USD and sending xDai
## Peer to peer exchange
Basic exchange flow will be like following -
1. Seller puts an order to sell x amount of xDai for y amount of USD and taking z% as fee. Seller also need to specify a link where he accepts payments
2. Please note that the fee is not charged by our exchange it is charged by seller and is passed on to the seller
3. Seller's xDai are locked into our smart contract along with exchange rate, fee, and payment link
4. Buyer looks at the list of available sell orders and select one which suits her. Initiates a trade for a sell order by specifying amount of xDai she wants to buy
5. At this point buyer does not have any xDai to execute onchain transaction. So we have to implement gasless transaction mechanism
6. Buyer makes payment to the seller out of our platform and updates status of trade to "paid for"
7. Seller confirms USD payment and releases funds from escrow contract to the buyer
There are other non ideal user flows that we will discuss later
This system will have following components -
1. Decentralised escrow
2. And ofcourse dcentralised hosted web UI
3. Dispute resolution
### Decentralised escrow
It will be an onchain smart contract which will hold seller xDai verify availability of funds with seller
### Decentralised UI
Webapp can be deployed on ipfs
### Dispute resolution
In case buyer sends USD to the seller and seller does not release xDai then buyer can raise a dispute to our dicentralised court (yet to be figured out).On dispute resolution court can release funds to only buyer or seller, no other address
## Extensions
We can extend functionality of this basic exchange further
### Automatic order matching
Instead of asking buyer to look through sell order we can simply ask buyer to specify amount of xDai she wants to buy. We can then simply select sell orders that can fulfil her request with minimum fee and show to her. If her order can not be fulfilled in single sell order then she has to take trouble of buying it multiple time from multiple sellers.
### Seller pools
To resolve this issue of doing multiple trnasactions for buyers we can allow sellers to create a pool. This pool creation will be totally indepdent and trnsparent to our platform. Our platform won't know how pool works, a pool looks like a single seller on our platform for all purposes. Any one can create a pool and put xDai for sell on our platoform.
### Automatic payment verification
We can develop a simple service which a seller can ask to be deployed by us or deploy and run herself. This service listens events in escrow contract and calls payment receving service the seller is using to collect payment. When a buyer updates status of a trade to "paid for" this service can check payment service provider API to verify payment and then call escrow contract on behalf of seller to release xDai to buyer
### Trusted sellers with automatic verification
A trusted decentralised oracle to source payment verification status from seller's payment verification service could be used. Needs discussion. I suspect this oracle will add centralisation somwhere in stack. If feasible and done then we can develop fully decentralised trusted on/off ramp for USD to xDai
## Conclusion
This is just a high level idea of develping a decentralised USD xDai exchange. There are multiple points that needs to be explored and discussed further for feasibility. I am confident that we can pull together such a system and come up with a fully decentralised, secure, autonomous, unstoppable exchange