bancor 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -4
- data/lib/bancor.rb +20 -21
- data/lib/bancor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4f4f1ce7a6d3f6cf58091747194671a82e6b5308cfb792f38329b09f5632059
|
4
|
+
data.tar.gz: efa191249b8a22d435e47754a00b71aa0c18daba5c6f2377781eef69452b46c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf0e032a266365c037ec1af5cd03b64f20e5bdb0db8d21d23fce0655e829dbc0b0c0277ec8358041590f3441a8c7f9b0058ca8ae37d27588e48e78fdda68312
|
7
|
+
data.tar.gz: db09f303715542076e46633fb3b28bc4cd13372bd729206d367d081094ee88342b5a7ce89c9576c61892b249955bbb5b0160adf85874f7e529a45ecb58937991
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
-
|
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
|
|
data/lib/bancor.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
require "bancor/version"
|
2
2
|
|
3
3
|
module Bancor
|
4
|
-
|
4
|
+
class Protocol
|
5
|
+
attr_reader :total_supply, :reserved_token, :price
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
data/lib/bancor/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|