Contract Address: 0xE197529709D7cBaf31756C6d9B8742718E17FCA5
What follows is an experiment in a trustless smart contract
based buy order for tokens. The contract source code can be
used for any token contract that conforms to EIP20.
This contract has been configured for the recently live MKR token.
The contract deployed @ 0xE197529709D7cBaf31756C6d9B8742718E17FCA5
represents a buy order for MKR
tokens @ 6.9 ETH per MKR. The contract has been funded with 7 ETH, enough to purchase a bit
more than a single MKR token.
If you are interested in participating int his experiment by selling me MKR using this contract you can do so by following these steps.
Via the MKR Token contract @ 0xC66eA802717bFb9833400264Dd12c2bCeAa34a6d
make an approval for 0xE197529709D7cBaf31756C6d9B8742718E17FCA5
in the amount of MKR tokens you wish to sell.
Because MKR is divisible up to 18 decimal places, if you would like to sell
1.5
MKR then you would need to give an approval in the amount of
1500000000000000000 (1.5e18)
.
Once the token transfer has been approved you will need to tell the
order contract @ 0xE197529709D7cBaf31756C6d9B8742718E17FCA5
to fill the order. This will execute a transferFrom
call from the MKR token contract, transfering the tokens to my ethereum
address @ 0xd3CdA913deB6f67967B99D67aCDFa1712C293601
and tranfer the
coresponding amount of ETH to the ethereum address that the MKR tokens were
transferred from.
This can be done with any of the following 4 functions.
fillOrder(address _from, uint numTokens)
: pays ether to and transfersnumTokens
tokens from the_from
address.fillMyOrder(uint numTokens)
: pays ether to and transfersnumTokens
tokens from themsg.sender
address.fillTheirOrder(address who)
: queries the MKR token contract for the pre-authorized allowance and transfers that amount to thewho
address.fillOrderAuto()
: queries the MKR token contract for the pre-authorized allowance and transfers that amount to themsg.sender
address.
You can also trigger filling of the order by just sending an empty transaction
to the order contract, which will execute the fillOrderAuto
function by default.
I would recommend using the Ethereum Wallet application to execute the transactions as it provides a user friendly interface for executing these transactions.
I've attached the contract ABI, Runtime Bytecode, and Source. The source was compiled
using solc 0.3.0-1f9578ce
and I have verified that browser solidity
produces the same bytecode as my locally compiled version.
The constant getter function weiPerToken()
can be used to query
the amount that will be paid in WEI for each MKR token that is transferred. Note that this
amount is the amount for 1 whole MKR token, which is not the same as the smallest
divisible MKR unit.
The constant getter function numTokensAbleToPurchase()
can be used to query the number of
MKR tokens that the contract can currently affort to purchase in units of the smallest divisible
MKR unit. For example if the contract has exactly enough ether to purchase a single whole MKR
token then this function would return 1e18
.