A one-day offer to sell DigixDAO's DGD at 0.75 ether a token, with the price and the expiry compiled in and an owner who can close it.
Historical Significance
A fixed-price offer to sell one token, expiring on a timestamp compiled into the contract. In 2016 there was no automated market maker and no order book on chain, so selling a holding meant a centralised exchange or a purpose-built contract like this one quoting a price and waiting. The expiry is what makes it an offer rather than a standing market: the seller commits to a price and to how long they will honour it, and both commitments are enforced by the contract rather than by their word.
Context
Deployed a week after the DGD token itself, in the weeks when DigixDAO's crowdsale had just closed and holders were looking for somewhere to trade. Homestead was two months old, ERC-20 had settled the interface, and the infrastructure for exchanging tokens onchain did not yet exist.
Key Facts
Description
A single-asset swap offer. It holds the address of the token it trades, 0xe0b7927c4af23765cb51314a0e0521a9645f0e2a, which is DigixDAO's DGD, a price of 0.75 ether per token, and an expiry timestamp, all readable through tokenObj(), price_token() and expiryDate(). checkExpiry() closes the offer once that moment has passed.
Privileged calls are restricted to the owner recorded at construction. The contract also exposes the two scaling constants it does its arithmetic with, a billion and the number of wei in a finney, which is how a contract of this period kept unit conversions honest without a maths library.
Its expiry is 8 May 2016 at 03:45 UTC, less than a day after it was deployed. The offer was written to stand for hours rather than to sit on chain as a market.
Source Verified
Historian Categories
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
Source verified through compiler archaeology and exact bytecode matching.
View Verification ProofShow source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
// Version 0.1
// This swap contract was created by Attores and released under a GPL license
// Visit attores.com for more contracts and Smart contract as a Service
// This is the standard token interface
contract TokenInterface {
struct User {
bool locked;
uint256 balance;
uint256 badges;
mapping (address => uint256) allowed;
}
mapping (address => User) users;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
mapping (address => bool) seller;
address config;
address owner;
address dao;
bool locked;
/// @return total amount of tokens
uint256 public totalSupply;
uint256 public totalBadges;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @param _owner The address from which the badge count will be retrieved
/// @return The badges count
function badgesOf(address _owner) constant returns (uint256 badge);
/// @notice send `_value` tokens to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of tokens to be transfered
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` badges to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of tokens to be transfered
/// @return Whether the transfer was successful or not
function sendBadge(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` tokens to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of tokens to be transfered
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens on its behalf
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens of _owner that _spender is allowed to spend
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
/// @notice mint `_amount` of tokens to `_owner`
/// @param _owner The address of the account receiving the tokens
/// @param _amount The amount of tokens to mint
/// @return Whether or not minting was successful
function mint(address _owner, uint256 _amount) returns (bool success);
/// @notice mintBadge Mint `_amount` badges to `_owner`
/// @param _owner The address of the account receiving the tokens
/// @param _amount The amount of tokens to mint
/// @return Whether or not minting was successful
function mintBadge(address _owner, uint256 _amount) returns (bool success);
function registerDao(address _dao) returns (bool success);
function registerSeller(address _tokensales) returns (bool success);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event SendBadge(address indexed _from, address indexed _to, uint256 _amount);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
// Actual swap contract written by Attores
contract swap{
address public beneficiary;
TokenInterface public tokenObj;
uint public price_token;
uint256 public WEI_PER_FINNEY = 1000000000000000;
uint public BILLION = 1000000000;
uint public expiryDate;
// Constructor function for this contract. Called during contract creation
function swap(address sendEtherTo, address adddressOfToken, uint tokenPriceInFinney_1000FinneyIs_1Ether, uint durationInDays){
beneficiary = sendEtherTo;
tokenObj = TokenInterface(adddressOfToken);
price_token = tokenPriceInFinney_1000FinneyIs_1Ether * WEI_PER_FINNEY;
expiryDate = now + durationInDays * 1 days;
}
// This function is called every time some one sends ether to this contract
function(){
if (now >= expiryDate) throw;
// Dividing by Billion here to cater for the decimal places
var tokens_to_send = (msg.value * BILLION) / price_token;
uint balance = tokenObj.balanceOf(this);
address payee = msg.sender;
if (balance >= tokens_to_send){
tokenObj.transfer(msg.sender, tokens_to_send);
beneficiary.send(msg.value);
} else {
tokenObj.transfer(msg.sender, balance);
uint amountReturned = ((tokens_to_send - balance) * price_token) / BILLION;
payee.send(amountReturned);
beneficiary.send(msg.value - amountReturned);
}
}
modifier afterExpiry() { if (now >= expiryDate) _ }
//This function checks if the expiry date has passed and if it has, then returns the tokens to the beneficiary
function checkExpiry() afterExpiry{
uint balance = tokenObj.balanceOf(this);
tokenObj.transfer(beneficiary, balance);
}
}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, 2016Association
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