Class: Bancor::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/bancor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(eth:, rate:, crr:) ⇒ Protocol

Returns a new instance of Protocol.



7
8
9
10
11
12
# File 'lib/bancor.rb', line 7

def initialize(eth:, rate:, crr:)
  @total_supply = eth * rate
  @reserved_token = @total_supply * crr
  @price = @reserved_token / (@total_supply * crr)
  @crr = crr
end

Instance Attribute Details

#priceObject (readonly)

Returns the value of attribute price.



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

def price
  @price
end

#reserved_tokenObject (readonly)

Returns the value of attribute reserved_token.



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

def reserved_token
  @reserved_token
end

#total_supplyObject (readonly)

Returns the value of attribute total_supply.



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

def total_supply
  @total_supply
end

#transaction_priceObject (readonly)

Returns the value of attribute transaction_price.



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

def transaction_price
  @transaction_price
end

Instance Method Details

#destroy_by_reserve_token(amount) ⇒ Object



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

def destroy_by_reserve_token(amount)
  smart_token_amount = @reserved_token * (1 - ((1 - (amount / @total_supply)) ** (1/@crr)))
  @reserved_token = @reserved_token - smart_token_amount
  @total_supply = @total_supply - amount
  @price = @reserved_token / (@total_supply * @crr)
  smart_token_amount
end

#destroy_by_smart_token(amount) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/bancor.rb', line 38

def destroy_by_smart_token(amount)
  transaction_price = @reserved_token * (1 - ((1 - (amount / @total_supply)) ** (1/@crr)))
  @total_supply = @total_supply - amount
  @reserved_token = @reserved_token - transaction_price
  @price = @reserved_token / (@total_supply * @crr)
  transaction_price
end

#issue_by_reserve_token(amount) ⇒ Object



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

def issue_by_reserve_token(amount)
  smart_token_amount = @total_supply * (((1 + (amount / @reserved_token)) ** @crr) - 1)
  @reserved_token = @reserved_token + amount
  @total_supply = @total_supply + smart_token_amount
  @price = @reserved_token / (@total_supply * @crr)
  smart_token_amount
end

#issue_by_smart_token(amount) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/bancor.rb', line 30

def issue_by_smart_token(amount)
  transaction_price = @reserved_token * ((((amount / @total_supply) + 1) ** (1/@crr)) - 1)
  @total_supply = @total_supply + amount
  @reserved_token = @reserved_token + transaction_price
  @price = @reserved_token / (@total_supply * @crr)
  transaction_price
end