Close

Latching to a token that isn't mine

A project log for EthExchange

Open source, decentralized exchange on the Ethereum blockchain

dylan-brophyDylan Brophy 06/19/2019 at 01:430 Comments

At 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.

Discussions