SecondPriceAuction.sol
contract SecondPriceAuction
Simple modified second price auction contract. Price starts high and monotonically decreases until all tokens are sold at the current price with currently received funds. The price curve has been chosen to resemble a logarithmic curve and produce a reasonable auction timeline. Requires softcap to be met, before finalisation, and if finalisation is not met a refund will be available.Source: DutchAuction/SecondPriceAuction.solAuthor: Parity Technologies, 2017. Modifications made by Connor Howe - ConnorBlockchain.
Index
Reference
Events
Buyin
event
Buyin
(address who, uint accounted, uint received, uint price)
Someone bought in at a particular max-price.Parameters:
who
- addressaccounted
- uintreceived
- uintprice
- uintEnded
event
Ended
(uint price)
The sale just ended with the current price.Parameters:
price
- uintFinalised
event
Finalised
(address who, uint tokens)
Finalised the purchase for `who`, who has been given `tokens` tokens.Parameters:
who
- addresstokens
- uintInjected
event
Injected
(address who, uint accounted, uint received)
Admin injected a purchase.Parameters:
who
- addressaccounted
- uintreceived
- uintRetired
event
Retired
()
Auction is over. All accounts finalised.
SoftCapNotReached
event
SoftCapNotReached
(uint totalReceived, uint usdWEISoftCap, address _who)
Sale did not reach softcap.Parameters:
totalReceived
- uintusdWEISoftCap
- uint_who
- addressUninjected
event
Uninjected
(address who)
Admin uninjected a purchase.Parameters:
who
- address
Modifiers
beforeBeginning
modifier
beforeBeginning
()
Ensure the sale has not begun.
notPreSaleMember
modifier
notPreSaleMember
(address _who)
Ensure same address for pre-sale is not used for public, to ensure clear devide of vested tokens and non-vested tokens.Parameters:
_who
- addressonlyAdmin
modifier
onlyAdmin
()
Ensure sender is admin.
onlyBasic
modifier
onlyBasic
(address who)
Ensure sender is not a contract.Parameters:
who
- addressonlyBuyins
modifier
onlyBuyins
(address _who)
Ensure `_who` is a participant.Parameters:
_who
- addressonlyEligible
modifier
onlyEligible
(address who, uint8 v, bytes32 r, bytes32 s)
Ensure that the signature is valid, `who` is a certified, basic account, the gas price is sufficiently low and the value is sufficiently high.Parameters:
who
- addressv
- uint8r
- bytes32s
- bytes32whenActive
modifier
whenActive
()
Ensure the sale is ongoing.
whenEnded
modifier
whenEnded
()
Ensure the sale is ended.
whenNotHalted
modifier
whenNotHalted
()
Ensure we're not halted.
whenSoftMet
modifier
whenSoftMet
()
Ensure soft cap has been met.
whenSoftNotMet
modifier
whenSoftNotMet
()
Ensure soft cap has not been met.
Functions
allFinalised
function
allFinalised
() public view returns (bool)
Returns:True if all buyins have finalised.
bonus
function
bonus
(uint _value) public view returns (uint)
If bonus is still occuring, and if so what would the token amount be once bonus applied.Modifiers:whenActiveParameters:
_value
- Ether amount of potential purchase.Returns:Amount of tokens + bonus.buyin
function
buyin
(uint8 v, bytes32 r, bytes32 s) public payable
User buys in to auction, and throws if not active and when refund needed.Modifiers:whenNotHalted notPreSaleMember whenActive onlyEligibleParameters:
v
- uint8r
- bytes32s
- bytes32claimRefund
function
claimRefund
(address _who) public
Returns ether to participant if softcap is not met.Modifiers:whenNotHalted whenEnded whenSoftNotMet onlyBuyinsParameters:
_who
- Address of pre-sale member to refund tokens to.currentPrice
function
currentPrice
() public view returns (uint)
Modifiers:whenActiveReturns:The current price of 1 token in usdWEI.
currentTime
function
currentTime
() public view returns (uint)
Returns:The current time.
drain
function
drain
() public
Admin emergency function to drain the contract of any funds.Modifiers:onlyAdmin
eligibleCall
function
eligibleCall
(address who, uint8 v, bytes32 r, bytes32 s) public view returns (bool)
Check if who address can purchase via buyin function.Parameters:
who
- Address to check if signature has been signed b and KYC has passed.v
- uint8r
- bytes32s
- bytes32Returns:boolfallback
function (address _certifierContract, address _tokenContract, address _tokenVesting, address _treasury, address _admin, uint _beginTime, uint _tokenCap) public
Initializes instance of Token & Certifier contract, and assigns all values.Parameters:
_certifierContract
- Address of Certifier contract._tokenContract
- Address of ERC20 contract._tokenVesting
- Address of TokenVesting contract._treasury
- Address of treasury._admin
- Address of admin._beginTime
- Start time of dutch auction._tokenCap
- Token cap in whole tokens (decimals).finalise
function
finalise
(address _who) public
Calculates final token price, and transfers tokens to _who when softcap and time met. If presale member, approveAndCall will auto call TokenVesting contract.Modifiers:whenNotHalted whenEnded whenSoftMet onlyBuyinsParameters:
_who
- Address of pre-sale member to transfer tokenshoursPassed
function
hoursPassed
() public view returns (uint)
Returns:Amount of hours that the auction has passed.
inject
function
inject
(address _who, uint128 _received, uint128 _appliedBonus) public
Similar to buyin except no payment reqired and bonus automatically given, only callable by admin.Modifiers:onlyAdmin onlyBasic beforeBeginningParameters:
_who
- Address of pre-sale member._received
- Amount of ether that the pre-sale member contributed._appliedBonus
- Bonus agreed in pre-sale agreement.isActive
function
isActive
() public view returns (bool)
Returns:True if the sale is ongoing.
isSigned
function
isSigned
(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public pure returns (bool)
Check if signature has been signed by _addr.Parameters:
_addr
- Address to check if signature has been signed by.msgHash
- Hash of terms and conditions.v
- uint8r
- bytes32s
- bytes32Returns:boolmaxPurchase
function
maxPurchase
() public view returns (uint)
Modifiers:whenActiveReturns:The largest purchase that can be made at present, not including any discount.
recoverAddr
function
recoverAddr
(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public pure returns (address)
Recover address from msg signature.Parameters:
msgHash
- Hash of terms and conditions.v
- uint8r
- bytes32s
- bytes32Returns:addresssetHalted
function
setHalted
(bool _halted) public
Admin emergency function to pause buy-in and finalisation.Modifiers:onlyAdminParameters:
_halted
- Bool to transition contract to halted state or not.setUSDSoftCap
function
setUSDSoftCap
(uint _usdWEISoftCap) public
Admin can change softcap USDWEI value of 10m if bull run occurs.Modifiers:onlyAdmin whenActiveParameters:
_usdWEISoftCap
- Amount of WEI to 10m USD.setUSDWei
function
setUSDWei
(uint _usdWEI) public
Admin can change stored USDWEI value of ether if bull run occurs.Modifiers:onlyAdmin whenActiveParameters:
_usdWEI
- Amount of WEI to 1 USD.softCapMet
function
softCapMet
() public view returns (bool)
Returns:True if ether recieved greater than softcap.
theDeal
function
theDeal
(uint _value) public view returns (uint, bool, uint)
Amount of tokens that would be given to the sender if they were to spent _value now.Modifiers:whenActiveParameters:
_value
- Ether amount of potential purchase.Returns:Amount of tokens.tokensAvailable
function
tokensAvailable
() public view returns (uint)
Modifiers:whenActiveReturns:Total indivisible token parts available for purchase right now.
uninject
function
uninject
(address _who) public
Reverses previous injection function, only callable by admin.Modifiers:onlyAdmin beforeBeginningParameters:
_who
- Address of pre-sale member to reverse injection.
Last updated
Was this helpful?