Skip to content

Instantly share code, notes, and snippets.

@szerintedmi
Created January 15, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szerintedmi/55ee9e6a59492e4e92dd68b9644483cc to your computer and use it in GitHub Desktop.
Save szerintedmi/55ee9e6a59492e4e92dd68b9644483cc to your computer and use it in GitHub Desktop.
/* Augmint's internal Exchange
TODO: emmit events
TODO: deduct fee
TODO: minOrderAmount setter
*/
pragma solidity 0.4.18;
import "./interfaces/ExchangeInterface.sol";
contract Exchange is ExchangeInterface {
uint public minOrderAmount;
event NewSellEthOrder(uint sellEthOrderId, address maker, uint price, uint weiAmount);
event NewBuyEthOrder(uint buyEthOrderId, address maker, uint price, uint tokenAmount);
function Exchange(address augmintTokenAddress, address ratesAddress, uint _minOrderAmount) public {
augmintToken = AugmintTokenInterface(augmintTokenAddress);
rates = Rates(ratesAddress);
minOrderAmount = _minOrderAmount;
}
function placeSellEthOrder(uint price) external payable returns (uint sellEthOrderId) {
require(price > 0);
uint tokenAmount = rates.convertFromWei(augmintToken.peggedSymbol(), msg.value);
require(tokenAmount >= minOrderAmount);
sellEthOrderId = sellEthOrders.push(
Order(msg.sender, now, price, msg.value)
) - 1;
mSellEthOrders[msg.sender].push(sellEthOrderId);
NewSellEthOrder(sellEthOrderId, msg.sender, price, msg.value);
}
function placeBuyEthOrder(uint price, uint tokenAmount) external returns (uint buyEthOrderId) {
require(price > 0);
require(tokenAmount >= minOrderAmount);
augmintToken.transferFromNoFee(msg.sender, this, tokenAmount, "Sell token order placed");
buyEthOrderId = buyEthOrders.push(
Order(msg.sender, now, price, tokenAmount)
) - 1;
mBuyEthOrders[msg.sender].push(buyEthOrderId);
NewBuyEthOrder(buyEthOrderId, msg.sender, price, tokenAmount);
}
function cancelSellEthOrder(uint sellEthOrderId) external {
/* FIXME: to be implemented */
require(sellEthOrderId < sellEthOrders.length);
revert();
}
function cancelBuyEthOrder(uint buyEthOrderId) external {
/* FIXME: to be implemented */
require(buyEthOrderId < buyEthOrders.length);
revert();
}
function matchOrders(uint sellEthOrderId, uint buyEthOrderId) external {
/* FIXME: to be implemented */
require(sellEthOrderId != buyEthOrderId);
revert();
}
function matchMultipleOrders(uint[] sellEthOrderIds, uint[] buyEthOrderIds) external {
/* FIXME: to be implemented */
require(sellEthOrderIds.length == buyEthOrderIds.length);
revert();
}
function getOrderCounts() external view returns(uint sellEthOrderCount, uint buyEthOrderCount) {
return(sellEthOrders.length, buyEthOrders.length);
}
function getAccountOrders(address maker) external view returns (uint[] sellEthOrderIds, uint[] buyEthOrderIds) {
return (mSellEthOrders[maker], mBuyEthOrders[maker]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment