Module: Bancor

Defined in:
lib/bancor.rb,
lib/bancor/version.rb

Constant Summary collapse

ETH =

300000(ETH)

300000.freeze
CRR =

CRR = 20%

0.2.freeze
RATE =

Rate 1ETH = 1BNT

1.freeze
VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/bancor.rb', line 4

def price
  @price
end

#total_supplyObject

Returns the value of attribute total_supply.



4
5
6
# File 'lib/bancor.rb', line 4

def total_supply
  @total_supply
end

Instance Method Details

#buying(quantity) ⇒ Object



16
17
18
19
20
21
# File 'lib/bancor.rb', line 16

def buying(quantity)
  token = @total_supply * (((1 + (quantity / @reserved_token)) ** CRR) - 1)
  @reserved_token = @reserved_token + quantity
  @total_supply = @total_supply + token
  @price = @reserved_token / (@total_supply * CRR)
end

#initializeObject



10
11
12
13
14
# File 'lib/bancor.rb', line 10

def initialize
  @total_supply = ETH
  @reserved_token = ETH * 0.2 # ETH 20% to reserve. CRR = 20%
  @price = @reserved_token / (@total_supply * CRR)
end

#selling(quantity) ⇒ Object



23
24
25
26
27
28
# File 'lib/bancor.rb', line 23

def selling(quantity)
  token = @reserved_token * (1 - ((1 - (quantity / @total_supply)) ** (1/CRR)))
  @reserved_token = @reserved_token - token
  @total_supply = @total_supply - quantity
  @price = @reserved_token / (@total_supply * CRR)
end