A vending machine for DigixDAO's DGD: send ether to it and it sends back tokens at 1.03 ether each, until its stock runs out.
Historical Significance
A token sale reduced to a contract holding stock at a fixed price, with no deadline, no goal and no refund logic: the seller commits the inventory and the price, and the buyer either gets tokens or gets thrown. In 2016 there was no automated market maker and no onchain order book, so a contract like this was the whole of what selling a holding without an exchange looked like. The cap and refund on a partial fill is the detail that makes it safe to send more than the remaining stock is worth.
Context
Deployed in May 2016, weeks after DigixDAO's crowdsale closed and while DGD was one of the few tokens with real demand behind it. Homestead was two months old, and the infrastructure for exchanging tokens onchain amounted to contracts people wrote for themselves.
Key Facts
Description
A one-sided sale contract for a single asset. The token address, 0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A, which is DigixDAO's DGD, and the price of 1.03 ether per token are both written into the constructor and cannot be changed afterwards.
Sending ether to the contract is the purchase: it divides the payment by the price, throws if that comes to nothing or if it holds no tokens, caps the order at what it actually has and refunds the difference, then transfers the tokens out. The owner can withdraw ether and move tokens out through two restricted functions, and can hand ownership on.
There is no buy side and no way for the contract to acquire more stock on its own. When the balance is gone every further payment is rejected.
Heuristic Analysis
The following characteristics were detected through bytecode analysis and may not be accurate.
Homestead Era
The first planned hard fork. Removed the canary contract, adjusted gas costs.
Bytecode Overview
Verified Source Available
This contract has verified source code on Etherscan.
Show source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
contract Token {
event Transfer(address indexed from, address indexed to, uint256 value);
function transfer(address _to, uint256 _value);
function balanceOf(address) returns (uint256);
}
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 TokenSale is owned {
address public asset;
uint256 public price;
function TokenSale()
{
asset = 0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A; // DGD
price = 1030000000; // 1.03 ETH
}
function transfer_token(address _token, address _to, uint256 _value)
onlyOwner()
{
Token(_token).transfer(_to,_value);
}
function transfer_eth(address _to, uint256 _value)
onlyOwner()
{
if(this.balance >= _value) {
_to.send(_value);
}
}
function () {
uint order = msg.value / price;
if(order == 0) throw;
uint256 balance = Token(asset).balanceOf(address(this));
if(balance == 0) throw;
if(order > balance )
{
order = balance;
uint256 change = msg.value - order * price;
msg.sender.send(change);
}
Token(asset).transfer(msg.sender,order);
}
}External Links
Related contracts
Association
Same eraThe ethereum.org democracy tutorial: token holders propose a transaction, vote on it for a fixed period, and the contract sends it if it passes.
0x8bfd7f...2aea40March 16, 2016Crowdsale
Same eraThe ethereum.org crowdsale tutorial: contributions run to a deadline against a goal, pay out a separate reward token, and are refunded if the goal is missed.
0x9af2b1...3a4858March 17, 2016Crowdsale
Same eraThe ethereum.org crowdsale tutorial: contributions run to a deadline against a goal, pay out a separate reward token, and are refunded if the goal is missed.
0xb83820...872c31March 24, 2016token
Same eraA shares contract that reports every balance as zero until three rounds of delegation have run, then answers with the delegated weight.
0xe81537...03263bMarch 26, 2016Contract 0x6960a6...8464a1
Same eraThe ethereum.org democracy tutorial: token holders propose a transaction, vote on it for a fixed period, and the contract sends it if it passes.
0x6960a6...8464a1March 26, 2016Contract 0xdbbf29...30cace
Same eraBlock-height timelock (Homestead, Apr 2016) that releases its full ETH balance to a fixed beneficiary at releaseBlock, self-scheduling a wake-up via Piper Merri
0xdbbf29...30caceApril 4, 2016