class Bancor::Protocol

Attributes

price[R]
reserved_token[R]
total_supply[R]
transaction_price[R]

Public Class Methods

new(eth:, rate:, crr:) click to toggle source
# 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

Public Instance Methods

destroy_by_reserve_token(amount) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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