Skip to content

Instantly share code, notes, and snippets.

View killerstorm's full-sized avatar

Alex Mizrahi killerstorm

View GitHub Profile
alex=# begin transaction;
BEGIN
alex=# select 20000000000::integer + 1000000000::integer;
ERROR: integer out of range
alex=# select 1;
ERROR: current transaction is aborted, commands ignored until end of transaction block

Interest tokens

Token sales are associated with a number of problems, such as high risk, lack of fairness, network disruptions, etc. A good overview of problems as well as possible mitigating strategies are described in V. Buterin's Analyzing Token Sale Models.

In this article I'm going to describe a very simple mechanism which can potentially mitigate some of ICO problems. It has following properties:

  1. Incentive to invest early (without it it is usually better to wait until the last minute)
  2. No network disruptions
  3. Almost no risk for investors
  4. Can be used at very early stages
pragma solidity ^0.4.8;
contract PredictionClub {
struct OutcomeState {
uint nOutcomeTokens;
uint nBetTokens;
uint cumBetTokens;
uint withdrawQueueBetTokens;
mapping (address => uint) balances;
@killerstorm
killerstorm / gtb.md
Last active September 7, 2018 11:01

Bancor vs Growth Tokens

About a year ago I described a concept which I called Growth Tokens (hereinafter GT). As I recently found out, Bancor is very similar to GT. In fact GT can be seen as a generalization of Bancor as it gives you more parameters to play with. Also Bancor and GT assign different interpretation to virtually the same mathematical formula, so it might be interesting to compare that.

Let's start with going through Bancor model. First, recall the basic formulat for price:

Price = Cost / Quantity

This can be used to calculate price within one transaction, but the formula also works when you aggregate results of multiple transactions:

contract EthGrowthToken {
uint256 ethBalance = 0;
uint constant depositFeePc = 1;
uint constant withdrawFeePc = 1;
// Following function implement growth logic:
// ether can be converted to and from tokens according to a current price which
// is calculated as (ethBalance / totalTokens), however we charge deposit
Doesn't work:
2016-11-21 23:08:38 TRACE rpc Request: {"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0x00a329c0648769A73afAc7F9381E08FB43dBEA72","gas":"0x1e8480","gasPrice":"0x174876e800","to":"0xa5bd94e55604de62e9b562f484da5eb20d7b7f70","data":"0xfdacd5760000000000000000000000000000000000000000000000000000000000000001"}],"id":7}
2016-11-21 23:08:38 TRACE miner send_transaction: dispatching tx: f88c8310002585174876e800831e848094a5bd94e55604de62e9b562f484da5eb20d7b7f7080a4fdacd57600000000000000000000000000000000000000000000000000000000000000011ca0af65128bb14d8e1fc4c6e67bb4f99127c27079811516d1f8f6cd2d5dcc7cf71da05a48101f784d1271fed0dfe955ef937bc953039ec6e979b7eceff062d1de9485 for network ID None
2016-11-21 23:08:38 TRACE rpc AsyncResponse: Some(AsyncStringResponse { response: Single(Sync(Success(Success { jsonrpc: V2, result: "0x50046748f220859070a665f9e468ff78962bfffc98fca5931efba4a65a11aeda", id: Num(7) }))) })
2016-11-21 23:08:38 DEBUG rpc Response: "{\"jsonrpc\":\"2.0\",\"res
$ parity --chain dev --jsonrpc-apis web3,eth,net,rpc,personal -l rpc,miner=trace | tee out.log
2016-11-21 17:00:34 main INFO parity::run Starting Parity/v1.5.0-unstable-60922b6-20161118/x86_64-macos/rustc1.13.0
2016-11-21 17:00:34 main INFO parity::run State DB configuation: fast
2016-11-21 17:00:34 main INFO parity::run Operating mode: active
2016-11-21 17:00:34 main INFO ethcore::service Configured for DevelopmentChain using InstantSeal engine
2016-11-21 17:00:35 IO Worker #2 INFO network Public node URL: enode://83f5b965c78153ec99ee57139383f0ef8d30d0d2fba9256b5a1a236e9d9d13b660bbc91c6da0bc46f7ddb6385e37a9b0bc1560c1644044bba9375916f94c1935@192.168.0.102:30303
2016-11-21 17:00:38 TRACE rpc Request: {"jsonrpc":"2.0","method":"personal_unlockAccount","params":["0x00a329c0648769A73afAc7F9381E08FB43dBEA72", "password", 99999],"id":76}
2016-11-21 17:00:38 TRACE rpc AsyncResponse: Some(AsyncStringResponse { response: Single(Sync(Success(Success { jsonrpc: V2, result: true, id: Num(76) }))) })
2016-
$ truffle migrate --reset --network live
Running migration: 1_initial_migration.js
Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
at Object.callback (/Users/macbook/.nvm/versions/node/v4.6.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/contract.js:147:46)
at /Users/macbook/.nvm/versions/node/v4.6.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/method.js:142:25
at /Users/macbook/.nvm/versions/node/v4.6.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/requestmanager.js:89:9
at null.request.onreadystatechange (/Users/macbook/.nvm/versions/node/v4.6.1/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:114:13)
at null.dispatchEvent (/Users/macbook/.nvm/versions/node/v4.6.1/lib/node_modules/truffle/node_modules/web3/node_modules/xmlhttpre
(defvar *locks* ())
(defmacro with-read (table index variable &body body)
`(let ((,variable (gethash ,index ,table))
(old-locks *locks*)
(*locks* (list* (cons ,table ,index) *locks*)))
(flet ((update (table index value)
(let ((*locks* old-locks))
(%update table index value))))
,@body)))
;setup environment: module is submitted with keyset definition ...
(env-data { "keyset": { "keys": ["ABCD"] , "pred": "keys-all" } })
;... and is signed by ABCD key
(env-keys "ABCD")
;define keyset to guard module
(define-keyset 'module-keyset (read-keyset "keyset"))
;define smart-contract code
(module payments 'module-keyset