Class: Bancor::Protocol
- Inherits:
-
Object
- Object
- Bancor::Protocol
- Defined in:
- lib/bancor.rb
Instance Attribute Summary collapse
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#reserved_token ⇒ Object
readonly
Returns the value of attribute reserved_token.
-
#total_supply ⇒ Object
readonly
Returns the value of attribute total_supply.
-
#transaction_price ⇒ Object
readonly
Returns the value of attribute transaction_price.
Instance Method Summary collapse
- #destroy_by_reserve_token(amount) ⇒ Object
- #destroy_by_smart_token(amount) ⇒ Object
-
#initialize(eth:, rate:, crr:) ⇒ Protocol
constructor
A new instance of Protocol.
- #issue_by_reserve_token(amount) ⇒ Object
- #issue_by_smart_token(amount) ⇒ Object
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
#price ⇒ Object (readonly)
Returns the value of attribute price.
5 6 7 |
# File 'lib/bancor.rb', line 5 def price @price end |
#reserved_token ⇒ Object (readonly)
Returns the value of attribute reserved_token.
5 6 7 |
# File 'lib/bancor.rb', line 5 def reserved_token @reserved_token end |
#total_supply ⇒ Object (readonly)
Returns the value of attribute total_supply.
5 6 7 |
# File 'lib/bancor.rb', line 5 def total_supply @total_supply end |
#transaction_price ⇒ Object (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 |