istox 0.1.120.pre.2 → 0.1.120

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: 86efea88fe9b160bd80eed0b64af89e8be72b002b5164c45cb75fb7b62eece6c
4
- data.tar.gz: 19d1e8f79a6cda0ceaf2aa1c163d660c530becf138ae87218e1de21f14a5647d
3
+ metadata.gz: a6fdaa4c5337520660c3bfedcf47d63c7773092439e23c40265227c5284f467d
4
+ data.tar.gz: 42f695f32b11fd48cb08110ded342b581399a16b45e07da17cc4a9adadb11727
5
5
  SHA512:
6
- metadata.gz: 801854a5d2e6b2dff20ae204b774e7512a3acc8aa9a712903db1811fbc68841c236044dd0b980325143e3df56cc19cf40bf1c34e04d80a3b0008654afa2a61b9
7
- data.tar.gz: 5bf57d11d786ab8b36696b8497aa9befffd14c03f6275c092edeaaab7eadcd492c9d04405ffbd67c90d55932ecc635e9beac4da3726ad1e0e761f71e04d923d1
6
+ metadata.gz: 0b11f506154370f933fc191361959627ab87f0935fe6c89e55b09723219c3efeae156f1c7e0a7044ac29c7f34af8f4b59ccf99425d42168c7473ea8202e64179
7
+ data.tar.gz: c7f12ffb9707da6a8f78d504afa410175d93ef966e020aceafd7e4e11f6db6da7636cd85520aba306116747c2971b03a9ac7d4430490fbf9e3fd00d1cfed2413
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.120.pre.1)
4
+ istox (0.1.115)
5
5
  awesome_print
6
6
  binding_of_caller
7
7
  bunny (>= 2.12.0)
@@ -95,7 +95,7 @@ GEM
95
95
  ffi (1.11.3)
96
96
  globalid (0.4.2)
97
97
  activesupport (>= 4.2.0)
98
- google-protobuf (3.11.2-universal-darwin)
98
+ google-protobuf (3.11.2)
99
99
  googleapis-common-protos-types (1.0.4)
100
100
  google-protobuf (~> 3.0)
101
101
  graphlient (0.3.7)
@@ -106,7 +106,7 @@ GEM
106
106
  graphql-client (0.16.0)
107
107
  activesupport (>= 3.0)
108
108
  graphql (~> 1.8)
109
- grpc (1.26.0-universal-darwin)
109
+ grpc (1.26.0)
110
110
  google-protobuf (~> 3.8)
111
111
  googleapis-common-protos-types (~> 1.0)
112
112
  grpc-tools (1.26.0)
@@ -1,29 +1,8 @@
1
1
  module Istox
2
2
  class OrderBookProrate
3
3
  class << self
4
- def allocation(token_price:, min_investment:, bid_block:, # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity
5
- invest_step:, hard_cap:, investments:, whitelists: [], include_refund_amount: false)
6
-
7
- # make sure is hashes
8
- original_investments = investments.as_json.map(&:symbolize_keys)
9
- whitelists = whitelists.as_json.map(&:symbolize_keys)
10
- investments = investments.as_json.map(&:symbolize_keys)
11
-
12
- # process whitelist
13
- whitelists.each do |whitelist|
14
- investment = investments.find { |investment1| investment1[:account_id] == whitelist[:account_id] }
15
-
16
- next unless investment.present?
17
-
18
- granted_amount = [::BigDecimal.new(investment[:fiat_amount].to_s), ::BigDecimal.new(whitelist[:guaranteed_allocation].to_s)].min
19
-
20
- next unless granted_amount.positive?
21
-
22
- hard_cap = ::Istox::FMath.sub(hard_cap, granted_amount)
23
- investment[:fiat_amount] = Istox::FMath.sub(investment[:fiat_amount], granted_amount)
24
- investment[:is_vip] = true
25
- investment[:granted_amount] = granted_amount.to_s
26
- end
4
+ def allocation(token_price:, min_investment:, bid_block:,
5
+ invest_step:, hard_cap:, investments:)
27
6
 
28
7
  # sort by id asc
29
8
  interests = investments.sort do |a, b|
@@ -33,30 +12,22 @@ module Istox
33
12
 
34
13
  max_allowed_investor = Istox::FMath.round_down(::Istox::FMath.div(hard_cap, min_investment), 0).to_i
35
14
 
36
- b = 0
37
- interests.each_with_index.map do |interest|
38
- if interest[:fiat_amount].to_d.positive? && b < max_allowed_investor
39
- total_interests = ::Istox::FMath.add(total_interests, interest[:fiat_amount])
40
- b += 1
41
- end
15
+ interests.each_with_index.map do |interest, i|
16
+ total_interests = ::Istox::FMath.add(total_interests, interest[:fiat_amount]) if i < max_allowed_investor
42
17
  end
43
18
 
44
19
  # only need to handle when oversubscribe
45
20
  if total_interests.to_d > hard_cap.to_s.to_d
46
21
 
47
22
  # prorate the interests
48
- i = 0
49
- interests = interests.each_with_index.map do |interest|
50
- investment = if i < max_allowed_investor && interest[:fiat_amount].to_d.positive?
23
+ interests = interests.each_with_index.map do |interest, i|
24
+ investment = if i < max_allowed_investor
51
25
  result = ::Istox::FMath.round_down(::Istox::FMath.mul(::Istox::FMath.div(interest[:fiat_amount], total_interests),
52
26
  hard_cap), 0)
53
-
54
27
  result = result.to_d - result.to_d.modulo(invest_step.to_s.to_d)
55
28
 
56
- # only set to min investment if is not vip
57
- result = min_investment.to_d if result < min_investment.to_d && interest[:is_vip].blank?
29
+ result = min_investment.to_d if result < min_investment.to_d
58
30
 
59
- i += 1
60
31
  result
61
32
  else
62
33
  ::BigDecimal.new('0').to_s
@@ -64,8 +35,6 @@ module Istox
64
35
 
65
36
  {
66
37
  id: interest[:id],
67
- is_vip: interest[:is_vip],
68
- granted_amount: interest[:granted_amount],
69
38
  investment: investment.to_s
70
39
  }
71
40
  end
@@ -79,14 +48,9 @@ module Istox
79
48
  if new_total_interests.to_d > hard_cap.to_s.to_d
80
49
  total_deducting = ::Istox::FMath.sub(new_total_interests, hard_cap)
81
50
  interests.reverse_each do |interest|
82
- next unless interest[:investment].to_d > min_investment.to_d || interest[:is_vip]
51
+ next unless interest[:investment].to_d > min_investment.to_d
83
52
 
84
- # allow to deduct to zero if is vip
85
- deductable = if interest[:is_vip]
86
- interest[:investment]
87
- else
88
- ::Istox::FMath.sub(interest[:investment], min_investment)
89
- end
53
+ deductable = ::Istox::FMath.sub(interest[:investment], min_investment)
90
54
 
91
55
  if deductable.to_d > total_deducting.to_d
92
56
  interest[:investment] = ::Istox::FMath.sub(interest[:investment], total_deducting)
@@ -98,44 +62,14 @@ module Istox
98
62
  end
99
63
  end
100
64
 
101
- final_interests = interests.map do |interest|
102
- interest[:investment] = ::Istox::FMath.add(interest[:investment], interest[:granted_amount]) if interest[:granted_amount].present? &&
103
- interest[:granted_amount].to_d.positive?
104
- interest.delete(:is_vip)
105
- interest.delete(:granted_amount)
106
-
107
- if include_refund_amount
108
- original_investment = original_investments.find { |original_investment1| original_investment1[:id] == interest[:id] }
109
- interest[:refund_amount] = ::Istox::FMath.sub(original_investment[:fiat_amount], interest[:investment])
110
- end
111
- interest
112
- end
65
+ final_interests = interests
113
66
 
114
67
  else
115
-
116
- final_interests = interests.each_with_index.map do |interest|
117
- final_amount = if interest[:is_vip]
118
- vip_fiat_amount = max_allowed_investor.positive? ? interest[:fiat_amount] : '0'
119
- ::Istox::FMath.add(vip_fiat_amount, interest[:granted_amount])
120
- else
121
- max_allowed_investor.positive? ? interest[:fiat_amount] : '0'
122
- end
123
-
124
- max_allowed_investor -= 1 if interest[:fiat_amount].to_d.positive?
125
-
126
- result = {
68
+ final_interests = interests.each_with_index.map do |interest, i|
69
+ {
127
70
  id: interest[:id],
128
- investment: ::BigDecimal.new(final_amount.to_s).to_s
129
-
71
+ investment: i < max_allowed_investor ? ::BigDecimal.new(interest[:fiat_amount].to_s).to_s : ::BigDecimal.new('0').to_s
130
72
  }
131
-
132
- if include_refund_amount
133
- original_investment = original_investments.find { |original_investment1| original_investment1[:id] == interest[:id] }
134
- refund_amount = ::Istox::FMath.sub(original_investment[:fiat_amount], final_amount)
135
- result[:refund_amount] = refund_amount
136
- end
137
-
138
- result
139
73
  end
140
74
  end
141
75
 
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.120-2'.freeze
2
+ VERSION = '0.1.120'.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.120.pre.2
4
+ version: 0.1.120
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-21 00:00:00.000000000 Z
11
+ date: 2020-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -411,9 +411,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
411
411
  version: '0'
412
412
  required_rubygems_version: !ruby/object:Gem::Requirement
413
413
  requirements:
414
- - - ">"
414
+ - - ">="
415
415
  - !ruby/object:Gem::Version
416
- version: 1.3.1
416
+ version: '0'
417
417
  requirements: []
418
418
  rubygems_version: 3.0.6
419
419
  signing_key: