bancor 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ba43330f2dbb71af71a5fcaef2456f7e3a40b65bf73f484f0a18b2ce7a78884
4
- data.tar.gz: c83b9adc9aa9c3e9b272ca8084c22e61692902e7bbb977f3a574128e5c58d08b
3
+ metadata.gz: e4f4f1ce7a6d3f6cf58091747194671a82e6b5308cfb792f38329b09f5632059
4
+ data.tar.gz: efa191249b8a22d435e47754a00b71aa0c18daba5c6f2377781eef69452b46c0
5
5
  SHA512:
6
- metadata.gz: eb234e6d8a9a197331061aed96d47d24f482ca620d901665b86e438b2ae905e135b172c682f0f5a8150b4bca354da8776fbec0cb0c1844d9b4f2e184f676fc90
7
- data.tar.gz: 1500d7fc6b1c376161328ed86e1902c8a56a60249c4019c00b4774f15eccdf7f6fb96d06b8a696a2cbad1c4c6ec4e3afe9fdfe139f91656502f7ffc766f30799
6
+ metadata.gz: fbf0e032a266365c037ec1af5cd03b64f20e5bdb0db8d21d23fce0655e829dbc0b0c0277ec8358041590f3441a8c7f9b0058ca8ae37d27588e48e78fdda68312
7
+ data.tar.gz: db09f303715542076e46633fb3b28bc4cd13372bd729206d367d081094ee88342b5a7ce89c9576c61892b249955bbb5b0160adf85874f7e529a45ecb58937991
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bancor (0.1.0)
4
+ bancor (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Bancor
2
+ [![Gem](https://img.shields.io/gem/v/bancor.svg?style=flat-square)](https://rubygems.org/gems/bancor)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bancor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
4
+ Implement the logic of Bancor protocol.
6
5
 
7
6
  ## Installation
8
7
 
@@ -22,7 +21,31 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ ```
25
+ irb(main):001:0> bp = Bancor::Protocol.new(eth: 300000, rate: 1, crr: 0.2)
26
+ => #<Bancor::Protocol:0x00007fabd8a37510 @total_supply=300000, @reserved_token=60000.0, @price=1.0, @crr=0.2>
27
+
28
+ irb(main):002:0> bp.buy 300
29
+ => 1.003998003989035
30
+
31
+ irb(main):003:0> bp.buy 700
32
+ => 1.0133112579155532
33
+
34
+ irb(main):004:0> bp.sell 1302
35
+ => 0.9958916677019946
36
+
37
+ irb(main):005:0> bp.buy 100
38
+ => 0.9972261505575943
39
+
40
+ irb(main):006:0> bp.total_supply
41
+ => 299791.7445404769
42
+
43
+ irb(main):007:0> bp.reserved_token
44
+ => 59792.033475409095
45
+
46
+ irb(main):008:0> bp.price
47
+ => 0.9972261505575943
48
+ ```
26
49
 
27
50
  ## Development
28
51
 
@@ -1,29 +1,28 @@
1
1
  require "bancor/version"
2
2
 
3
3
  module Bancor
4
- attr_accessor :total_supply, :price
4
+ class Protocol
5
+ attr_reader :total_supply, :reserved_token, :price
5
6
 
6
- ETH = 300000.freeze # 300000(ETH)
7
- CRR = 0.2.freeze # CRR = 20%
8
- RATE = 1.freeze # Rate 1ETH = 1BNT
7
+ def initialize(eth:, rate:, crr:)
8
+ @total_supply = eth * rate
9
+ @reserved_token = @total_supply * crr
10
+ @price = @reserved_token / (@total_supply * crr)
11
+ @crr = crr
12
+ end
9
13
 
10
- def initialize
11
- @total_supply = ETH
12
- @reserved_token = ETH * 0.2 # ETH 20% to reserve. CRR = 20%
13
- @price = @reserved_token / (@total_supply * CRR)
14
- end
15
-
16
- def buying(quantity)
17
- token = @total_supply * (((1 + (quantity / @reserved_token)) ** CRR) - 1)
18
- @reserved_token = @reserved_token + quantity
19
- @total_supply = @total_supply + token
20
- @price = @reserved_token / (@total_supply * CRR)
21
- end
14
+ def buy(quantity)
15
+ token = @total_supply * (((1 + (quantity / @reserved_token)) ** @crr) - 1)
16
+ @reserved_token = @reserved_token + quantity
17
+ @total_supply = @total_supply + token
18
+ @price = @reserved_token / (@total_supply * @crr)
19
+ end
22
20
 
23
- def selling(quantity)
24
- token = @reserved_token * (1 - ((1 - (quantity / @total_supply)) ** (1/CRR)))
25
- @reserved_token = @reserved_token - token
26
- @total_supply = @total_supply - quantity
27
- @price = @reserved_token / (@total_supply * CRR)
21
+ def sell(quantity)
22
+ token = @reserved_token * (1 - ((1 - (quantity / @total_supply)) ** (1/@crr)))
23
+ @reserved_token = @reserved_token - token
24
+ @total_supply = @total_supply - quantity
25
+ @price = @reserved_token / (@total_supply * @crr)
26
+ end
28
27
  end
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module Bancor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bancor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Kurotaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler