Created
June 20, 2017 11:36
-
-
Save johnzweng/df855c573c40ce50b721c8a9f3d40869 to your computer and use it in GitHub Desktop.
Status script for watching the status.im smartcontract crowdsale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Johannes Zweng <[email protected]>, 2017 | |
* | |
* This simple script just loads the Status.im contracts (Crowdsale and Tokens) | |
* into the web3 Script API and then provides a single status function which you | |
* can call on the console to query the current status of the crowdsale. | |
* | |
* Usage: | |
* 1) Store this gist locally on your computer. | |
* 2) make sure you have "web3" and "bignumber.js" node modules installed. For example like this: | |
* npm install web3 | |
* npm install bignumber.js | |
* 3) Load this script for interactive use into node: | |
* | |
* # node -e "eval(require('fs').readFileSync('web3-status-im-tokensale.js').toString())" -i | |
* | |
* This will open an interactive node shell, from where you can enter | |
* the folowing 2 commands: | |
* | |
* > status() | |
* or: | |
* > ceilingInfos() | |
* | |
* (Note: you can use the cursor-up key to easily repeat the last command.) | |
* | |
* The first will show you general infos about the current ICO state. The second one will | |
* display infos about the current dynamicceiling status. | |
*/ | |
var BigNumber = require('bignumber.js'); | |
var Web3 = require("web3"); | |
// TODO: change port 8545 if you have running geth or parity on a different JSON-RPC port: | |
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
// Taken from https://contribute.status.im/ at June 20, 2017, 06:59 CEST | |
var statusIcoAddress = '0x55d34b686aa8C04921397c5807DB9ECEdba00a4c'; | |
// prevent autoformatting for these long lines, these are just the interface definitions for the contracts | |
// (nothing hand written) | |
// @formatter:off | |
var statusIcoABI = [{"constant":true,"inputs":[],"name":"destEthDevs","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"endBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"maxSGTSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalGuaranteedCollected","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalNormalCollected","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"maxCallFrequency","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"sntController","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"failSafeLimit","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"exchangeRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"maxGasPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"finalizedBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"startBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"onTransfer","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"pauseContribution","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"finalize","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"maxGuaranteedLimit","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"lastCallBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"dynamicCeiling","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"destTokensDevs","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"guaranteedBuyersBought","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokensIssued","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_snt","type":"address"},{"name":"_sntController","type":"address"},{"name":"_startBlock","type":"uint256"},{"name":"_endBlock","type":"uint256"},{"name":"_dynamicCeiling","type":"address"},{"name":"_destEthDevs","type":"address"},{"name":"_destTokensReserve","type":"address"},{"name":"_destTokensSgt","type":"address"},{"name":"_destTokensDevs","type":"address"},{"name":"_sgt","type":"address"},{"name":"_maxSGTSupply","type":"uint256"}],"name":"initialize","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"SGT","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"guaranteedBuyersLimit","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"destTokensSgt","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"changeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"resumeContribution","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"SNT","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_th","type":"address"},{"name":"_limit","type":"uint256"}],"name":"setGuaranteedAddress","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"destTokensReserve","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"onApprove","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"claimTokens","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalCollected","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_th","type":"address"}],"name":"proxyPayment","outputs":[{"name":"","type":"bool"}],"payable":true,"type":"function"},{"constant":true,"inputs":[],"name":"finalizedTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_token","type":"address"},{"indexed":true,"name":"_controller","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"ClaimedTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_th","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"},{"indexed":false,"name":"_tokens","type":"uint256"},{"indexed":false,"name":"_guaranteed","type":"bool"}],"name":"NewSale","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_th","type":"address"},{"indexed":false,"name":"_limit","type":"uint256"}],"name":"GuaranteedAddress","type":"event"},{"anonymous":false,"inputs":[],"name":"Finalized","type":"event"}]; | |
var dynamicCeilingABI = [{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"curves","outputs":[{"name":"hash","type":"bytes32"},{"name":"limit","type":"uint256"},{"name":"slopeFactor","type":"uint256"},{"name":"collectMinimum","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"currentIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"nCurves","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"allRevealed","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"contribution","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_curveHashes","type":"bytes32[]"}],"name":"setHiddenCurves","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_limits","type":"uint256[]"},{"name":"_slopeFactors","type":"uint256[]"},{"name":"_collectMinimums","type":"uint256[]"},{"name":"_lasts","type":"bool[]"},{"name":"_salts","type":"bytes32[]"}],"name":"revealMulti","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_limit","type":"uint256"},{"name":"_slopeFactor","type":"uint256"},{"name":"_collectMinimum","type":"uint256"},{"name":"_last","type":"bool"},{"name":"_salt","type":"bytes32"}],"name":"revealCurve","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"revealedCurves","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_limit","type":"uint256"},{"name":"_slopeFactor","type":"uint256"},{"name":"_collectMinimum","type":"uint256"},{"name":"_last","type":"bool"},{"name":"_salt","type":"bytes32"}],"name":"calculateHash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"collected","type":"uint256"}],"name":"toCollect","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"changeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_index","type":"uint256"}],"name":"moveTo","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_owner","type":"address"},{"name":"_contribution","type":"address"}],"payable":false,"type":"constructor"}]; | |
var sgtABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"creationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newController","type":"address"}],"name":"changeController","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_blockNumber","type":"uint256"}],"name":"balanceOfAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_cloneTokenName","type":"string"},{"name":"_cloneDecimalUnits","type":"uint8"},{"name":"_cloneTokenSymbol","type":"string"},{"name":"_snapshotBlock","type":"uint256"},{"name":"_transfersEnabled","type":"bool"}],"name":"createCloneToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"generateTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_blockNumber","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"data","type":"uint256[]"}],"name":"multiMint","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"transfersEnabled","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentSnapShotBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"destroyTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokenFactory","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_transfersEnabled","type":"bool"}],"name":"enableTransfers","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"controller","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_tokenFactory","type":"address"}],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_cloneToken","type":"address"},{"indexed":false,"name":"_snapshotBlock","type":"uint256"}],"name":"NewCloneToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Approval","type":"event"}]; | |
var sntABI =[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"creationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newController","type":"address"}],"name":"changeController","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_blockNumber","type":"uint256"}],"name":"balanceOfAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_cloneTokenName","type":"string"},{"name":"_cloneDecimalUnits","type":"uint8"},{"name":"_cloneTokenSymbol","type":"string"},{"name":"_snapshotBlock","type":"uint256"},{"name":"_transfersEnabled","type":"bool"}],"name":"createCloneToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"generateTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_blockNumber","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"transfersEnabled","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentSnapShotBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"destroyTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"claimTokens","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokenFactory","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_transfersEnabled","type":"bool"}],"name":"enableTransfers","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"controller","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_tokenFactory","type":"address"}],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_token","type":"address"},{"indexed":true,"name":"_controller","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"ClaimedTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_cloneToken","type":"address"},{"indexed":false,"name":"_snapshotBlock","type":"uint256"}],"name":"NewCloneToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Approval","type":"event"}]; | |
// @formatter:on | |
// Initialice ICO contract and all helper contracts on ethereum mainnet: | |
var statusIco = web3.eth.contract(statusIcoABI).at(statusIcoAddress); | |
var dynamicCeiling = web3.eth.contract(dynamicCeilingABI).at(statusIco.dynamicCeiling()); | |
var tokenSgt = web3.eth.contract(sgtABI).at(statusIco.SGT()); | |
var tokenSnt = web3.eth.contract(sntABI).at(statusIco.SNT()); | |
/** | |
* Display statistics during status-im ICO: | |
*/ | |
function status() { | |
// startBlock is uint256 --> uses BigNumber! | |
var blocksUntilStart = statusIco.startBlock().sub(web3.eth.blockNumber).toString(); | |
var startBlockReached = statusIco.startBlock().sub(web3.eth.blockNumber).lte(new BigNumber(0)); | |
var totalCollectedEth = web3.fromWei(statusIco.totalCollected(), 'ether'); | |
var totalNormalCollectedEth = web3.fromWei(statusIco.totalNormalCollected(), 'ether'); | |
var totalGuaranteedCollectedEth = web3.fromWei(statusIco.totalGuaranteedCollected(), 'ether'); | |
var totalSgtTokens = tokenSgt.totalSupply().div(new BigNumber(10)); | |
var totalSntTokens = web3.fromWei(tokenSnt.totalSupply(), 'ether'); // SNT has also 18 decimals like ETH | |
// as long as finalizedBlock equals 0, the ICO is not finalized: | |
var isIcoFinalized = !(statusIco.finalizedBlock().equals(new BigNumber(0))); | |
// | |
// START OUTPUT: | |
// | |
console.log('-------------------------------------------------------------------------------'); | |
console.log(' Status of the STATUS.IM crowdsale:'); | |
console.log('-------------------------------------------------------------------------------'); | |
console.log(' * ICO starts at block #: ' + statusIco.startBlock().toString()); | |
if (!startBlockReached) { | |
console.log(' * Blocks remaining until start: ' + blocksUntilStart); | |
} else { | |
console.log(' * ICO start block has been reached!'); | |
} | |
console.log(' * Total ETH collected (total): ' + totalCollectedEth); | |
console.log(' + from whitlisted (guaranteed): ' + totalGuaranteedCollectedEth); | |
console.log(' + from normal buyers: ' + totalNormalCollectedEth); | |
console.log(' * Total existing SNT Tokens: ' + totalSntTokens + ' SNT'); | |
console.log(' * Total existing SGT Tokens: ' + totalSgtTokens + ' SGT'); | |
console.log(' * ICO finalized: ' + isIcoFinalized); | |
// console.log(' -- Infos about the dynamic ceilings:'); | |
console.log(' * OPEN TO BUY UNDER CURRENT CEILING: ' + web3.fromWei(dynamicCeilingToCollect(statusIco.totalNormalCollected()), 'ether').toString() + ' ETH'); | |
console.log('-------------------------------------------------------------------------------'); | |
} | |
/** | |
* I try here to calculate the currently active cap in the same way the ICO | |
* contract does it with the DynamicCeiling helper contract. | |
* This should represent the same calculation as done in the contract here in line 132: | |
* https://github.com/status-im/status-network-token/blob/master/contracts/DynamicCeiling.sol#L132 | |
* | |
* @return BigNumber current active cap | |
*/ | |
function dynamicCeilingToCollect(totalNormalCollected) { | |
var revealedCurves = dynamicCeiling.revealedCurves().toNumber(); | |
var currentIndex = dynamicCeiling.currentIndex().toNumber(); | |
if (revealedCurves === 0) { | |
return 0; | |
} | |
var difference, collect, currCurve, currLimit, currSlopeFactor, currCollectMinimum; | |
currCurve = dynamicCeiling.curves(currentIndex); | |
// index 1 is "limit" in struct Curve: | |
currLimit = currCurve[1]; | |
// index 2 is "slopeFactor" in struct Curve: | |
currSlopeFactor = currCurve[2]; | |
// index 3 is "collectMinimum" in struct Curve: | |
currCollectMinimum = currCurve[3]; | |
difference = currLimit.sub(totalNormalCollected); | |
collect = difference.div(currSlopeFactor); | |
if (collect.lte(currCollectMinimum)) { | |
if (difference.gt(currCollectMinimum)) { | |
return currCollectMinimum; | |
} else { | |
return difference; | |
} | |
} else { | |
return collect; | |
} | |
} | |
/** | |
* Display statistics during status-im ICO: | |
*/ | |
function ceilingInfos() { | |
// dynamic ceiling infos: | |
var numberOfRevealedCeilings = dynamicCeiling.revealedCurves().toNumber(); | |
var maxPossibleCeilings = dynamicCeiling.nCurves().toNumber(); | |
var currentIndex = dynamicCeiling.currentIndex().toNumber(); | |
var allCeilingsRevealed = dynamicCeiling.allRevealed(); | |
var currentCurve = dynamicCeiling.curves(currentIndex); | |
var nextCurve; | |
// only true if: | |
// - not the last ceiling | |
// - next ceiling limit != 0 | |
var isNextCeilingRevealed = ((currentIndex + 1) < maxPossibleCeilings) | |
&& !dynamicCeiling.curves(currentIndex + 1)[1].equals(new BigNumber(0)) | |
if (isNextCeilingRevealed) { | |
nextCurve = dynamicCeiling.curves(currentIndex + 1); | |
} | |
// | |
// START OUTPUT: | |
// | |
console.log('-------------------------------------------------------------------------------'); | |
console.log(' STATUS.IM DynamicCeiling infos:'); | |
console.log('-------------------------------------------------------------------------------'); | |
console.log(' * Max possible number of ceilings: ' + maxPossibleCeilings); | |
console.log(' * Number of already reveiled ceilings: ' + numberOfRevealedCeilings); | |
console.log(' * Are already ALL ceilings revealed: ' + allCeilingsRevealed); | |
console.log(' * Index of current ceiling (0 is first): ' + currentIndex); | |
console.log(' --------'); | |
console.log(' * Current Ceiling limit: ' + web3.fromWei(currentCurve[1], 'ether').toString() + ' ETH'); | |
console.log(' * Current Ceiling slopeFactor: ' + currentCurve[2].toString()); | |
console.log(' * Current Ceiling collectMinimum: ' + web3.fromWei(currentCurve[3], 'ether').toString() + ' ETH'); | |
console.log(' * OPEN TO BUY UNDER CURRENT CEILING: ' + web3.fromWei(dynamicCeilingToCollect(statusIco.totalNormalCollected()), 'ether').toString() + ' ETH'); | |
if (isNextCeilingRevealed) { | |
console.log(' --------'); | |
console.log(' * Next Ceiling limit: ' + web3.fromWei(nextCurve[1], 'ether').toString() + ' ETH'); | |
console.log(' * Next Ceiling slopeFactor: ' + nextCurve[2].toString()); | |
console.log(' * Next Ceiling collectMinimum: ' + web3.fromWei(nextCurve[3], 'ether').toString() + ' ETH'); | |
} | |
console.log('-------------------------------------------------------------------------------'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment