Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.11;
- contract proxyRecipient {
- function proxyTransfer(address caller) payable;
- }
- contract proxyAddress {
- function() payable {
- proxyRecipient(0xfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed).proxyTransfer.value(msg.value)(msg.sender);
- }
- }
- contract ERC20 {
- event Transfer(address indexed from, address indexed to, uint value);
- event Approval( address indexed owner, address indexed spender, uint value);
- function totalSupply() constant returns (uint supply);
- function balanceOf( address who ) constant returns (uint value);
- function allowance(address owner, address spender) constant returns (uint _allowance);
- function transfer( address to, uint value) returns (bool ok);
- function transferFrom( address from, address to, uint value) returns (bool ok);
- function approve(address spender, uint value) returns (bool ok);
- }
- contract SafeMath {
- function safeMul(uint a, uint b) internal returns (uint) {
- uint c = a * b;
- assert(a == 0 || c / a == b);
- return c;
- }
- function safeDiv(uint a, uint b) internal returns (uint) {
- assert(b > 0);
- uint c = a / b;
- assert(a == b * c + a % b);
- return c;
- }
- function safeSub(uint a, uint b) internal returns (uint) {
- assert(b <= a);
- return a - b;
- }
- function safeAdd(uint a, uint b) internal returns (uint) {
- uint c = a + b;
- assert(c>=a && c>=b);
- return c;
- }
- function max64(uint64 a, uint64 b) internal constant returns (uint64) {
- return a >= b ? a : b;
- }
- function min64(uint64 a, uint64 b) internal constant returns (uint64) {
- return a < b ? a : b;
- }
- function max256(uint256 a, uint256 b) internal constant returns (uint256) {
- return a >= b ? a : b;
- }
- function min256(uint256 a, uint256 b) internal constant returns (uint256) {
- return a < b ? a : b;
- }
- function assert(bool assertion) internal {
- if (!assertion) {
- throw;
- }
- }
- }
- contract owned {
- address public owner;
- function owned() {
- owner = msg.sender;
- }
- modifier onlyOwner {
- if (msg.sender != owner) throw;
- _;
- }
- function transferOwnership(address newOwner) onlyOwner {
- owner = newOwner;
- }
- }
- contract tradeWallet is SafeMath, owned {
- struct SELLOFFER
- {
- ERC20 token;
- uint price;
- uint units;
- uint allowance;
- address proxy;
- }
- struct BUYOFFER
- {
- ERC20 token;
- uint price;
- uint units;
- uint allowance;
- }
- uint public nextOffer = 1;
- mapping(address => uint) public proxyMap;
- mapping(uint => SELLOFFER) public sellOffers;
- mapping(uint => BUYOFFER) public buyOffers;
- /* soldity: 0.4.11+commit.68ef5810.Emscripten.clang
- contract proxyAddress {
- function() payable {
- proxyRecipient(0xfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed).proxyTransfer.value(msg.value)(msg.sender);
- }
- }
- */
- bytes proxyCode = hex"6060604052341561000c57fe5b5b60c98061001b6000396000f30060606040525b609b5b604080517f833ec7200000000000000000000000000000000000000000000000000000000081523373ffffffffffffffffffffffffffffffffffffffff166004820152905173feedfeedfeedfeedfeedfeedfeedfeedfeedfeed9163833ec72091349160248082019260009290919082900301818588803b1515608757fe5b6125ee5a03f11515609457fe5b505050505b565b0000a165627a7a723058201205452475b8ac3fdba319cceb71647d6ac16a0d19aa9b33c601a616aef1c1060029";
- function tradeWallet() {
- // set the proxy tearget to this contract:
- for (uint i = 0; i < 20; i++) {
- proxyCode[125-i] = byte(uint8(uint(this) >> (8*i)));
- }
- }
- function deployCode(bytes _code) internal returns (address deployedAddress) {
- assembly {
- deployedAddress := create(0, add(_code, 0x20), mload(_code))
- jumpi(invalidJumpLabel, iszero(extcodesize(deployedAddress))) // jumps if no code at addresses
- }
- _code;
- deployedAddress;
- }
- function makeSellOffer(ERC20 token, uint price, uint units, uint allowance) onlyOwner
- {
- sellOffers[nextOffer] = SELLOFFER(token,price,units,allowance,deployCode(proxyCode));
- proxyMap[sellOffers[nextOffer].proxy] = nextOffer;
- nextOffer++;
- }
- function makeBuyOffer(ERC20 token, uint price, uint units, uint allowance) onlyOwner
- {
- buyOffers[nextOffer] = BUYOFFER(token,price,units,allowance);
- nextOffer++;
- }
- function setSellAllowance(uint id, uint allowance) onlyOwner {
- sellOffers[id].allowance = allowance;
- }
- function min(uint a, uint b) internal returns (uint) {
- if(a < b) return a;
- return b;
- }
- function takerBuys(address taker, uint id) internal
- {
- var availableTokens = min(sellOffers[id].token.balanceOf(this),sellOffers[id].allowance);
- var unitLots = min( availableTokens / sellOffers[id].units , msg.value / sellOffers[id].price);
- var takerPayment = unitLots * sellOffers[id].price;
- var makerPayment = unitLots * sellOffers[id].units;
- var change = msg.value - takerPayment;
- sellOffers[id].allowance = safeSub(sellOffers[id].allowance,makerPayment);
- if(!sellOffers[id].token.transfer(taker,makerPayment)) throw;
- if(change > 0) taker.transfer(change);
- }
- function takerSells(uint id, uint unitLots)
- {
- var availableEther = min(this.balance, buyOffers[id].allowance);
- unitLots = min(unitLots, availableEther / buyOffers[id].units);
- var takerPayment = unitLots * buyOffers[id].units;
- var makerPayment = unitLots * buyOffers[id].price;
- buyOffers[id].allowance = safeSub(buyOffers[id].allowance,makerPayment);
- if(!buyOffers[id].token.transferFrom(msg.sender,this,takerPayment)) throw;
- msg.sender.transfer(makerPayment);
- }
- function takerBuys(uint id) payable {
- takerBuys(msg.sender,id);
- }
- function proxyTransfer(address caller) payable
- {
- takerBuys(caller,proxyMap[msg.sender]);
- }
- function makerWithdrawEther(uint256 etherValueSmallestUnits) onlyOwner
- {
- if(etherValueSmallestUnits > this.balance) etherValueSmallestUnits = this.balance;
- msg.sender.transfer(etherValueSmallestUnits);
- }
- function makerDepositEther() payable {
- }
- function makerWidtdrawToken(ERC20 token, uint tokenSmallestUnits) onlyOwner {
- if(tokenSmallestUnits > token.balanceOf(this)) tokenSmallestUnits = token.balanceOf(this);
- token.transfer(msg.sender,tokenSmallestUnits);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement