istox 0.1.81.pre.test8 → 0.1.81.pre.test9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6914180beb5936e43d978d38460627b21ea6ea1d5d7673fd30626cf8450e6208
4
- data.tar.gz: 4685dd98e263b7fc0e0365747d80db3aee98bd729135203077eba4089e97848c
3
+ metadata.gz: 709e450a6f5c8ae8a44d8c52eb7cedaece6a4cafde0761e198dad80308b3af01
4
+ data.tar.gz: b6db801e20945d448e1b90fb8aa32d073b39c5fed7e97e9095cecaaca1958d48
5
5
  SHA512:
6
- metadata.gz: cd3cf29e6a37c6c2d6d89d33becdd9e425b9133f97b2c4600bf29b4ac14829759e006ae0d9e9deb385de57d296492c801683a6dd943494dc7dc0eb8a13faba15
7
- data.tar.gz: d74fff382c493301cde5d299fa925483f1b38823fe2df151f53f1a9607f7c485dc38b578d6a72c9c2a0e09ac2f3baa95661edfa7c7489edd6e9bcd283c1bbca0
6
+ metadata.gz: 69491f982e218c130936029d47601d330f25e8103020b358f53712edcbf76653a4b341669065c24a6a162d14a0ef9bf32adff5f45de9e0267c53e50151a3fd67
7
+ data.tar.gz: 06b3580527d154aae956e09102e19bb4db4b9473e32c9be4b60e6892b903dfa817c7b264f4f7d7b2507d1333499a97128c6f0194c5bfa011e4ad1b81fd615312
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.81.pre.test7)
4
+ istox (0.1.81.pre.test8)
5
5
  binding_of_caller
6
6
  bunny (>= 2.12.0)
7
7
  graphlient
@@ -34,8 +34,6 @@ module Istox
34
34
  # execute before proc, and get the model that blockchain receipt should bind to
35
35
  model = before.call(uuid)
36
36
 
37
- puts model
38
-
39
37
  # delete the previous existing blockchain receipts
40
38
  klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
41
39
 
@@ -2,7 +2,6 @@ module Istox
2
2
  class OrderBook
3
3
  class << self
4
4
  def allocation(soft_cap, total_supply, investments)
5
-
6
5
  # sort by token price desc, and id asc
7
6
  investments = investments.sort do |a, b|
8
7
  [b[:token_price], a[:id]] <=> [a[:token_price], b[:id]]
@@ -11,50 +10,79 @@ module Istox
11
10
  total_supply = ::BigDecimal.new(total_supply.to_s)
12
11
 
13
12
  interests = investments
14
- if interests.count > 0
15
- cutoff_price = 0.0
16
- total_bid_token = 0.0
17
- total_allocated = 0.0
18
- total_unallocated = 0.0
19
- total_investment = 0.0
20
- cutoff_price = ::Istox::FMath.div(soft_cap, total_supply)
21
- is_cutoff = false
13
+ cutoff_price = 0.0
14
+ total_bid_token = 0.0
15
+ total_allocated = 0.0
16
+ total_unallocated = 0.0
17
+ total_investment = 0.0
18
+ cutoff_price = ::Istox::FMath.div(soft_cap, total_supply)
19
+ is_cutoff = false
22
20
 
23
- interests = interests.map do |item|
24
- bid_token = ::Istox::FMath.div(item[:fiat_amount], item[:token_price])
25
- total_bid_token = ::Istox::FMath.add(total_bid_token, bid_token)
26
- allocated = 0.0
27
- unallocated = bid_token
28
- unless is_cutoff
29
- allocated = bid_token
30
- unallocated = 0.0
31
- if ::BigDecimal.new(::Istox::FMath.add(total_allocated, bid_token)) >= total_supply
32
- unallocated = ::Istox::FMath.sub(::Istox::FMath.add(total_allocated, bid_token), total_supply)
33
- allocated = ::Istox::FMath.sub(bid_token, unallocated)
34
- cutoff_price = item[:token_price]
35
- is_cutoff = true
36
- end
37
- total_allocated = ::Istox::FMath.add(total_allocated, allocated)
38
- total_unallocated = ::Istox::FMath.add(total_unallocated, unallocated)
21
+ # return result immediately if no interest
22
+ unless interests.count.positive?
23
+ return { total_supply: total_supply.to_s, total_investment: '0',
24
+ cutoff_price: cutoff_price, total_bid_token: '0',
25
+ total_allocated: '0', total_unallocated: total_supply.to_s,
26
+ interests: [] }
27
+ end
28
+
29
+ interests = interests.map do |item|
30
+ bid_token = ::Istox::FMath.div(item[:fiat_amount], item[:token_price])
31
+ total_bid_token = ::Istox::FMath.add(total_bid_token, bid_token)
32
+ allocated = 0.0
33
+ unallocated = bid_token
34
+ unless is_cutoff
35
+ allocated = bid_token
36
+ unallocated = 0.0
37
+ if ::BigDecimal.new(::Istox::FMath.add(total_allocated, bid_token)) >= total_supply
38
+ unallocated = ::Istox::FMath.sub(::Istox::FMath.add(total_allocated, bid_token), total_supply)
39
+ allocated = ::Istox::FMath.sub(bid_token, unallocated)
40
+ cutoff_price = item[:token_price]
41
+ is_cutoff = true
39
42
  end
40
- { id: item[:id], fiat_amount: item[:fiat_amount], bid_price: item[:token_price], bid_token: bid_token,
41
- allocated: allocated, unallocated: unallocated }
43
+ total_allocated = ::Istox::FMath.add(total_allocated, allocated)
44
+ total_unallocated = ::Istox::FMath.add(total_unallocated, unallocated)
42
45
  end
46
+ {
47
+ id: item[:id],
48
+ # user bidding total fiat amount
49
+ fiat_amount: item[:fiat_amount],
50
+ # user bidding price
51
+ bid_price: item[:token_price],
52
+ # total user bidding token derived from fiat_amount / token_price
53
+ bid_token: bid_token,
54
+ # round down allocated token to whole number
55
+ allocated: ::Istox::FMath.round_down(allocated, 0),
56
+ # round up unallocated token to whole number
57
+ unallocated: ::Istox::FMath.round_up(unallocated, 0)
58
+ }
59
+ end
43
60
 
44
- interests = interests.map do |item|
45
- investment = ::Istox::FMath.mul(item[:allocated], cutoff_price)
46
- total_investment = ::Istox::FMath.add(total_investment, investment)
47
- item.merge!(investment: investment)
48
- end
49
-
50
- return { total_supply: total_supply, total_investment: total_investment,
51
- cutoff_price: cutoff_price, total_bid_token: total_bid_token,
52
- total_allocated: total_allocated, total_unallocated: total_unallocated,
53
- interests: interests }
54
- else
55
- raise 'Registration interest is empty'
61
+ interests = interests.map do |item|
62
+ investment = ::Istox::FMath.mul(item[:allocated], cutoff_price)
63
+ total_investment = ::Istox::FMath.add(total_investment, investment)
64
+
65
+ # each user maximum total investment amount in fiat
66
+ item.merge!(investment: investment)
56
67
  end
68
+
69
+ {
70
+ # total token supply
71
+ total_supply: total_supply.to_s,
72
+ # total investment in fiat
73
+ total_investment: total_investment,
74
+ # cut off price
75
+ cutoff_price: cutoff_price.to_s,
76
+ # total bid tokens, more than total supply for oversubscribe case
77
+ total_bid_token: total_bid_token,
78
+ # total allocated tokens
79
+ total_allocated: total_allocated,
80
+ # total unallocated tokens
81
+ total_unallocated: total_unallocated,
82
+ # all investor interest results
83
+ interests: interests
84
+ }
57
85
  end
58
86
  end
59
87
  end
60
- end
88
+ end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.81-test8'.freeze
2
+ VERSION = '0.1.81-test9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.81.pre.test8
4
+ version: 0.1.81.pre.test9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny