A contract that bought back BNT for ETH at the 0.01 ETH crowdsale price, deployed 2017-06-25.
Historical Significance
A fixed buyback price for BNT set up shortly after the Bancor crowdsale.
Key Facts
Description
Lets BNT holders sell tokens to the contract for ETH at a fixed price of 0.01 ETH per BNT, the crowdsale price. A seller approves the contract and calls sell(), which takes the full approved amount and sends back the ETH. The owner can withdraw ETH from it.
Source Verified
Historian Categories
Spurious Dragon Era
Continued DoS protection. State trie clearing.
Bytecode Overview
Verified Source Available
Source verified on Etherscan.
Show source code (Solidity)
pragma solidity ^0.4.11;
/*
Overflow protected math functions
*/
contract SafeMath {
/**
constructor
*/
function SafeMath() {
}
/**
@dev returns the sum of _x and _y, asserts if the calculation overflows
@param _x value 1
@param _y value 2
@return sum
*/
function safeAdd(uint256 _x, uint256 _y) internal returns (uint256) {
uint256 z = _x + _y;
assert(z >= _x);
return z;
}
/**
@dev returns the difference of _x minus _y, asserts if the subtraction results in a negative number
@param _x minuend
@param _y subtrahend
@return difference
*/
function safeSub(uint256 _x, uint256 _y) internal returns (uint256) {
assert(_x >= _y);
return _x - _y;
}
/**
@dev returns the product of multiplying _x by _y, asserts if the calculation overflows
@param _x factor 1
@param _y factor 2
@return product
*/
function safeMul(uint256 _x, uint256 _y) internal returns (uint256) {
uint256 z = _x * _y;
assert(_x == 0 || z / _x == _y);
return z;
}
}
/*
Owned contract interface
*/
contract IOwned {
// this function isn't abstract since the compiler emits automatically generated getter functions as external
function owner() public constant returns (address owner) { owner; }
function transferOwnership(address _newOwner) public;
function acceptOwnership() public;
}
/*
Provides support and utilities for contract ownership
*/
contract Owned is IOwned {
address public owner;
address public newOwner;
event OwnerUpdate(address _prevOwner, address _newOwner);
/**
@dev constructor
*/
function Owned() {
owner = msg.sender;
}
// allows execution by the owner only
modifier ownerOnly {
assert(msg.sender == owner);
_;
}
/**
@dev allows transferring the contract ownership
the new owner still need to accept the transfer
can only be called by the contract owner
@param _newOwner new contract owner
*/
function transferOwnership(address _newOwner) public ownerOnly {
require(_newOwner != owner);
newOwner = _newOwner;
}
/**
@dev used by a new owner to accept an ownership transfer
*/
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnerUpdate(owner, newOwner);
owner = newOwner;
newOwner = 0x0;
}
}
/*
ERC20 Standard Token interface
*/
contract IERC20Token {
// these functions aren't abstract since the compiler emits automatically generated getter functions as external
function name() public constant returns (string name) { name; }
function symbol() public constant returns (string symbol) { symbol; }
function decimals() public constant returns (uint8 decimals) { decimals; }
function totalSupply() public constant returns (uint256 totalSupply) { totalSupply; }
function balanceOf(address _owner) public constant returns (uint256 balance) { _owner; balance; }
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { _owner; _spender; remaining; }
function transfer(address _to, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function approve(address _spender, uint256 _value) public returns (bool success);
}
/*
Token Holder interface
*/
contract ITokenHolder is IOwned {
function withdrawTokens(IERC20Token _token, address _to, uint256 _amount) public;
}
/*
We consider every contract to be a 'token holder' since it's currently not possible
for a contract to deny receiving tokens.
The TokenHolder's contract sole purpose is to provide a safety mechanism that allows
the owner to send tokens that were sent to the contract by mistake back to their sender.
*/
contract TokenHolder is ITokenHolder, Owned {
/**
@dev constructor
*/
function TokenHolder() {
}
// validates an address - currently only checks that it isn't null
modifier validAddress(address _address) {
require(_address != 0x0);
_;
}
// verifies that the address is different than this contract address
modifier notThis(address _address) {
require(_address != address(this));
_;
}
/**
@dev withdraws tokens held by the contract and sends them to an account
can only be called by the owner
@param _token ERC20 token contract address
@param _to account to receive the new amount
@param _amount amount to withdraw
*/
function withdrawTokens(IERC20Token _token, address _to, uint256 _amount)
public
ownerOnly
validAddress(_token)
validAddress(_to)
notThis(_to)
{
assert(_token.transfer(_to, _amount));
}
}
/*
Smart Token interface
*/
contract ISmartToken is ITokenHolder, IERC20Token {
function disableTransfers(bool _disable) public;
function issue(address _to, uint256 _amount) public;
function destroy(address _from, uint256 _amount) public;
}
/*
BancorPriceFloor v0.1
The bancor price floor contract is a simple contract that allows selling smart tokens for a constant ETH price
'Owned' is specified here for readability reasons
*/
contract BancorPriceFloor is Owned, TokenHolder, SafeMath {
uint256 public constant TOKEN_PRICE_N = 1; // crowdsale price in wei (numerator)
uint256 public constant TOKEN_PRICE_D = 100; // crowdsale price in wei (denominator)
string public version = '0.1';
ISmartToken public token; // smart token the contract allows selling
/**
@dev constructor
@param _token smart token the contract allows selling
*/
function BancorPriceFloor(ISmartToken _token)
validAddress(_token)
{
token = _token;
}
/**
@dev sells the smart token for ETH
note that the function will sell the full allowance amount
@return ETH sent in return
*/
function sell() public returns (uint256 amount) {
uint256 allowance = token.allowance(msg.sender, this); // get the full allowance amount
assert(token.transferFrom(msg.sender, this, allowance)); // transfer all tokens from the sender to the contract
uint256 etherValue = safeMul(allowance, TOKEN_PRICE_N) / TOKEN_PRICE_D; // calculate ETH value of the tokens
msg.sender.transfer(etherValue); // send the ETH amount to the seller
return etherValue;
}
/**
@dev withdraws ETH from the contract
@param _amount amount of ETH to withdraw
*/
function withdraw(uint256 _amount) public ownerOnly {
assert(msg.sender.send(_amount)); // send the amount
}
/**
@dev deposits ETH in the contract
*/
function() public payable {
}
}External Links
Related contracts
Bancor
Same deployerBancor Network Token (BNT), the first Bancor Smart Token, deployed 2017-06-10 ahead of the Bancor crowdsale.
0x1f573d...a7ff1cJune 10, 2017CrowdsaleController
Same deployerThe Bancor crowdsale contract. Opened 2017-06-12 and collected 396,619.89 ETH, about $153M at the time.
0xbbc797...f89710June 10, 2017BancorFormula
Same deployerThe original Bancor pricing formula, computing purchase and sale returns for Smart Tokens from supply, reserve and reserve ratio.
0x8d10c0...395b98June 22, 2017Ether Token
Same deployerBancor's ETH wrapper token, used as the ETH reserve of the original BNT converter.
0xd76b5c...b746aeJune 22, 2017BancorChanger
Same deployerThe original Bancor converter for BNT, deployed 2017-06-22 with an ETH reserve held as EtherToken.
0xca83bd...629ff4June 22, 2017BancorGasPriceLimit
Same deployerHolds the maximum gas price allowed for Bancor conversions, set to 20 gwei at deployment on 2017-10-19.
0xafb06c...b99590October 19, 2017