-
Making EthX An Accessible Crypto Exchange
06/19/2019 at 23:21 • 1 commentThis exchange is useless if it cannot be accessed.
Since this exchange aims to be entirely decentralized, there should not be a central server hosting EthExchange. Then how are users going to be able to get the client side files for it? Almost every webpage is hosted on a server. Almost.
I discovered this interesting protocol called IPFS (InterPlanetary File System) which allows files (and webpages to be hosted in a decentralized way, on a peer-to-peer network. More info about IPFS on their site: https://ipfs.io/. Anyway, I am hosting EthExchange there. I will post more when it is properly hosted - it takes some time for a file to propagate across the network.
When propagated, EthExchange will be available here.
So that's super cool - I just made a decentralized Ethereum exchange! It works too (although there isn't much there yet... YET)
A programming "whoops": using parseInt instead of parseDouble
I was trying to trade fractions of tokens on EthExchange, but my transactions indicated that I had requested to buy exactly zero tokens. Long story short, I used the wrong parse function. Whoops! Fixed now, latest code is on the repo.
[A quick note about EthX market cap indications: they are wrong. Another thing for me to fix.]
-
Latching to a token that isn't mine
06/19/2019 at 01:43 • 0 commentsAt some point it would be nice to trade a token with actual value, right? None of these tokens (as of right now) were created by me. If you remember from the last log, the trading contract will need to 'latch' to an ERC20 token contract.
So I decided to try to latch to the OmiseGo token on the Ethereum Mainnet.
Did it work? Nope. I tried to place a sell order for the .16 OMG tokens I somehow have, but the transaction reverted. So I found the OMG token source code and copied it into Remix to try to figure out why this revert was occuring.
At first I thought that maybe my contract was reverting the transaction, misreading the 'allowance' values from the OMG contract, thinking it couldn't transfer. I tried to debug but Remix wouldn't let me for some odd reason, very unhelpful. Anyway, I started messing with the contract to try to find the issue. It seems that my trading contract can indeed read the OMG contract values properly, but it's still reverting. But only for sells - I can place a buy order. Although, that order will never be executed, simply because sell orders are broken. I have narrowed it down to these few lines:
function placeSellOrder(uint tokens, uint64 price10000) public{ require(ERC20(latched_contract).allowance(msg.sender, address(this))>=tokens); // handle fee and any extra funds ERC20(latched_contract).transferFrom(msg.sender,address(this),tokens); // get info needed for trading uint left = tokens; ... function continues
What's odd is that this works fine on my test token: LOL Coin (source: here), but breaks for OmiseGo. It's as if OMG's smart contract is causing the revert in:
ERC20(latched_contract).transferFrom(msg.sender,address(this),tokens);
- but really I have no clue.
If you're curious, OMG's source code is here, and my trading contract code can be found here. You bet I'll keep looking into it. If it doesn't work, then I'll test with the 300 or so Xenon tokens I also somehow have, although I think that coin is dead.
-
Order-Fulfilling Smart Contract
06/18/2019 at 17:25 • 0 commentsMarket prices change when people trade at new prices. People trade at new prices when orders at the old price are no longer fulfilled.
Before my new smart contract, any token would be fixed to a certain price unless that price was manually changed. My new contract allows the price to change by automatically matching buy and sell orders together.
Let's say Alice places a buy order for 100 tokens at a price of 1.2 dollars, but no previous sell orders have been placed at or below this price. The smart contract takes Alice's money, but lists her buy order.
Now let's say Bob places a sell order for 250 tokens at a price of 1.05 dollars. The smart contract now completes Alice's order, sending her 100 of Bob's sold tokens, and gives Bob his money. But Bob is still selling 150 more tokens, so the contract takes these and lists a sell order.
This is what all exchanges do every day, what the stock market does, etc. But those systems are centralized. This smart contract exists on the Ethereum blockchain, and it is decentralized.
My current smart contract can be viewed on Etherscan here (along with source code):
https://ropsten.etherscan.io/address/0x2400b7c684f1ddc738b7dcc4527c3b9af45cdac5#contracts
The contract is not perfect (and this one has at least one minor bug), but as a proof of concept, it does seem to work. Note that it is on the testnet - DO NOT SEND IT REAL ETHEREUM - you will be VERY SAD if you do.
Next I need to weed out the bugs and add two more functions: placeBuyOrder() and placeSellOrder(). These functions will allow orders to be placed at any price.
-
Where I am so far
06/15/2019 at 22:05 • 0 commentsI've been working on this already for a week or two, so this log is to update on where this project is right now
Essentially, trading is working, and the UI isn't beautiful but it is user-friendly. Everything is still on the Ropsten Testnet. All the tokens are using a fixed price system right now, so it wouldn't work for any non-stable tokens yet.
Currently I am working on an Ethereum smart contract capable of processing orders, thus allowing the token price to fluctuate.
Important thing: "latching contracts"
This is a term I created for contracts that 'latch' to a certain token to enable trading.
Trading protocols for smart contracts
There are several trading protocols right now:
- "legacy"
- "Tr100"
- "Tr100b"
- "Tr100b-compat"
"legacy" and "Tr100" are considered obsolete - not going over them.Tr100b and Tr100b-compat
Contracts that use either of these protocols can:
- tell you if a certain amount of tokens can be traded
- tell you what the fee is, or zero if none
- trade (obviously)
- tell you what the cost of a buy or revenue of a sale would be
- tell you the total token supply
- tell you the token balance of an address
The difference between them is that Tr100-compat is designed for latching contracts, and can also tell you which contract has been latched.
That is the state of the project thus far!