istox 0.2.9 → 0.2.10

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: b906e9dbba05e70feaf86f32baac44406b99092e766673c68b6ea264db7a9ddc
4
- data.tar.gz: 1170ef8daccda9dceb671598f3ebb74e9071fc6e142ba4c0aa90c35aa21fc22f
3
+ metadata.gz: f2099515f9703dcadd1f99da2d05be06e062c624638ae9c3646880497c7d192d
4
+ data.tar.gz: 1ceba372de27ec21beb41acde07f601f138cf116d1aad19f50034af3f7cb2d18
5
5
  SHA512:
6
- metadata.gz: a1f9dc10064f5527c503564078a02a7a6a219e57a03f6c152653f66e79050005cc0404bd639b8f18f870184811e3c0c2e874b45e73723e89b19c9f1fc0bfa10c
7
- data.tar.gz: 6a604074785ecbcb31e10bbc37230f1ad7290aa7315c6b02b1c5ab14c4d0c8a572c441ae291c53e61ca31a87939fa12b4bfceb472f8bb08b38921d4c9aa15c66
6
+ metadata.gz: 9263b776b77849f00a25f08b99a2e753a5eabc03e929afeb3628b6c58d13dcf799e1c587418781b77c2c01e2bd0afd7bba9de88291569198a4d66f8354a8c8dc
7
+ data.tar.gz: 9d6034c961985ae0ea89c806ac44dd505074fabfe899f73765328b9ef00bc4b85a06a907d8203ea3ad9f35cac77841caf372fe518911184b1f808f68f0f6a682
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.2.5.3)
4
+ istox (0.2.9)
5
5
  amazing_print
6
6
  awesome_print
7
7
  aws-sdk-sns (~> 1)
@@ -9,7 +9,6 @@ PATH
9
9
  bunny (>= 2.12.0)
10
10
  exponential-backoff (= 0.0.4)
11
11
  graphlient
12
- gruf
13
12
  hashie (~> 3.5.7)
14
13
  istox_gruf (~> 2.7.3)
15
14
  listen (~> 3.0.5)
@@ -92,8 +91,9 @@ GEM
92
91
  bullet (5.7.6)
93
92
  activesupport (>= 3.0.0)
94
93
  uniform_notifier (~> 1.11.0)
95
- bunny (2.17.0)
94
+ bunny (2.18.0)
96
95
  amq-protocol (~> 2.3, >= 2.3.1)
96
+ sorted_set (~> 1, >= 1.0.2)
97
97
  byebug (11.1.3)
98
98
  coderay (1.1.2)
99
99
  concurrent-ruby (1.1.6)
@@ -101,7 +101,6 @@ GEM
101
101
  database_cleaner (1.6.2)
102
102
  debug_inspector (1.1.0)
103
103
  diff-lcs (1.3)
104
- e2mmap (0.1.0)
105
104
  erubi (1.9.0)
106
105
  exponential-backoff (0.0.4)
107
106
  factory_bot (4.8.2)
@@ -124,7 +123,7 @@ GEM
124
123
  faraday-net_http_persistent (1.1.0)
125
124
  faraday_middleware (1.0.0)
126
125
  faraday (~> 1.0)
127
- ffi (1.15.0)
126
+ ffi (1.15.1)
128
127
  globalid (0.4.2)
129
128
  activesupport (>= 4.2.0)
130
129
  google-protobuf (3.15.8-universal-darwin)
@@ -142,15 +141,6 @@ GEM
142
141
  google-protobuf (~> 3.15)
143
142
  googleapis-common-protos-types (~> 1.0)
144
143
  grpc-tools (1.37.0)
145
- gruf (2.9.1)
146
- activesupport (> 4)
147
- concurrent-ruby (> 1)
148
- e2mmap (~> 0.1)
149
- grpc (~> 1.10)
150
- grpc-tools (~> 1.10)
151
- json (>= 2.3)
152
- slop (~> 4.6)
153
- thwait (~> 0.1)
154
144
  hashie (3.5.7)
155
145
  i18n (0.9.5)
156
146
  concurrent-ruby (~> 1.0)
@@ -161,7 +151,6 @@ GEM
161
151
  grpc-tools (~> 1.10)
162
152
  slop (~> 4.6)
163
153
  jmespath (1.4.0)
164
- json (2.5.1)
165
154
  listen (3.0.8)
166
155
  rb-fsevent (~> 0.9, >= 0.9.4)
167
156
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -223,9 +212,10 @@ GEM
223
212
  rake (>= 0.8.7)
224
213
  thor (>= 0.19.0, < 2.0)
225
214
  rake (10.5.0)
226
- rb-fsevent (0.10.4)
215
+ rb-fsevent (0.11.0)
227
216
  rb-inotify (0.10.1)
228
217
  ffi (~> 1.0)
218
+ rbtree (0.4.4)
229
219
  redis (4.1.3)
230
220
  redis-actionpack (5.2.0)
231
221
  actionpack (>= 5, < 7)
@@ -267,7 +257,11 @@ GEM
267
257
  rspec-support (~> 3.8.0)
268
258
  rspec-support (3.8.0)
269
259
  ruby2_keywords (0.0.4)
270
- slop (4.8.2)
260
+ set (1.0.1)
261
+ slop (4.9.1)
262
+ sorted_set (1.0.3)
263
+ rbtree
264
+ set (~> 1.0)
271
265
  sprockets (3.7.2)
272
266
  concurrent-ruby (~> 1.0)
273
267
  rack (> 1, < 3)
@@ -278,8 +272,6 @@ GEM
278
272
  sqlite3 (1.3.13)
279
273
  thor (0.20.3)
280
274
  thread_safe (0.3.6)
281
- thwait (0.2.0)
282
- e2mmap
283
275
  timecop (0.9.1)
284
276
  tzinfo (1.2.6)
285
277
  thread_safe (~> 0.1)
@@ -18,33 +18,59 @@ module Istox
18
18
 
19
19
  # process whitelist
20
20
  whitelists.each do |whitelist|
21
- investment = investments.find { |investment1| investment1[:account_id] == whitelist[:account_id] }
21
+ whitelisted_investments = investments.select { |investment1| investment1[:account_id] == whitelist[:account_id] }
22
22
 
23
- next unless investment.present?
23
+ next unless whitelisted_investments.length.positive?
24
24
 
25
- granted_amount = [::BigDecimal.new(investment[:fiat_amount].to_s), ::BigDecimal.new(whitelist[:guaranteed_allocation].to_s)].min
25
+ current_guarenteed_amount = ::BigDecimal.new(whitelist[:guaranteed_allocation].to_s)
26
26
 
27
- next unless granted_amount.positive?
27
+ whitelisted_investments.each do |whitelisted_investment|
28
+ granted_amount = [::BigDecimal.new(whitelisted_investment[:fiat_amount].to_s), current_guarenteed_amount].min
28
29
 
29
- hard_cap = ::Istox::FMath.sub(hard_cap, granted_amount)
30
- investment[:fiat_amount] = Istox::FMath.sub(investment[:fiat_amount], granted_amount)
31
- investment[:is_vip] = true
32
- investment[:granted_amount] = granted_amount.to_s
30
+ next unless granted_amount.positive?
31
+
32
+ current_guarenteed_amount = ::Istox::FMath.sub(current_guarenteed_amount, granted_amount).to_d
33
+
34
+ hard_cap = ::Istox::FMath.sub(hard_cap, granted_amount)
35
+ whitelisted_investment[:fiat_amount] = Istox::FMath.sub(whitelisted_investment[:fiat_amount], granted_amount)
36
+ whitelisted_investment[:is_vip] = true
37
+ whitelisted_investment[:granted_amount] = granted_amount.to_s
38
+ end
33
39
  end
34
40
 
35
41
  # sort by id asc
36
42
  interests = investments.sort do |a, b|
37
43
  a[:id] <=> b[:id]
38
44
  end
45
+
46
+ ## check whether each investment already had earlier investment from the same investor
47
+ interests = interests.map do |interest|
48
+ earlier_interest = interests.find do |i|
49
+ i[:account_id] == interest[:account_id] &&
50
+ i[:id] != interest[:id] && i[:id].to_i < interest[:id].to_i
51
+ end
52
+
53
+ interest[:has_earlier_interest] = earlier_interest.present?
54
+
55
+ interest
56
+ end
57
+
39
58
  total_interests = 0
40
59
 
41
60
  max_allowed_investor = Istox::FMath.round_down(::Istox::FMath.div(hard_cap, min_investment), 0).to_i
42
61
 
43
- b = 0
62
+ allowed_investor_ids = []
44
63
  interests.each_with_index.map do |interest|
45
- if interest[:fiat_amount].to_d.positive? && b < max_allowed_investor
64
+ if !allowed_investor_ids.include?(interest[:account_id]) &&
65
+ interest[:fiat_amount].to_d.positive? && allowed_investor_ids.length < max_allowed_investor
66
+ allowed_investor_ids.push(interest[:account_id])
67
+ interest[:to_be_set_zero] = false
46
68
  total_interests = ::Istox::FMath.add(total_interests, interest[:fiat_amount])
47
- b += 1
69
+ elsif allowed_investor_ids.include?(interest[:account_id]) && interest[:fiat_amount].to_d.positive?
70
+ interest[:to_be_set_zero] = false
71
+ total_interests = ::Istox::FMath.add(total_interests, interest[:fiat_amount])
72
+ else
73
+ interest[:to_be_set_zero] = true
48
74
  end
49
75
  end
50
76
 
@@ -52,18 +78,18 @@ module Istox
52
78
  if total_interests.to_d > hard_cap.to_s.to_d
53
79
 
54
80
  # prorate the interests
55
- i = 0
56
81
  interests = interests.each_with_index.map do |interest|
57
- investment = if i < max_allowed_investor && interest[:fiat_amount].to_d.positive?
82
+ investment = if interest[:fiat_amount].to_d.positive? && !interest[:to_be_set_zero]
58
83
  result = ::Istox::FMath.round_down(::Istox::FMath.mul(::Istox::FMath.div(interest[:fiat_amount], total_interests),
59
84
  hard_cap), 0)
60
85
 
61
86
  result = result.to_d - result.to_d.modulo(invest_step.to_s.to_d)
62
87
 
63
88
  # only set to min investment if is not vip
64
- result = min_investment.to_d if result < min_investment.to_d && interest[:is_vip].blank?
89
+ if result < min_investment.to_d && interest[:is_vip].blank? && !interest[:has_earlier_interest]
90
+ result = min_investment.to_d
91
+ end
65
92
 
66
- i += 1
67
93
  result
68
94
  else
69
95
  ::BigDecimal.new('0').to_s
@@ -73,6 +99,7 @@ module Istox
73
99
  id: interest[:id],
74
100
  is_vip: interest[:is_vip],
75
101
  granted_amount: interest[:granted_amount],
102
+ has_earlier_interest: interest[:has_earlier_interest],
76
103
  investment: investment.to_s
77
104
  }
78
105
  end
@@ -86,10 +113,10 @@ module Istox
86
113
  if new_total_interests.to_d > hard_cap.to_s.to_d
87
114
  total_deducting = ::Istox::FMath.sub(new_total_interests, hard_cap)
88
115
  interests.reverse_each do |interest|
89
- next unless interest[:investment].to_d > min_investment.to_d || interest[:is_vip]
116
+ next unless interest[:investment].to_d > min_investment.to_d || interest[:is_vip] || interest[:has_earlier_interest]
90
117
 
91
118
  # allow to deduct to zero if is vip
92
- deductable = if interest[:is_vip]
119
+ deductable = if interest[:is_vip] || interest[:has_earlier_interest]
93
120
  interest[:investment]
94
121
  else
95
122
  ::Istox::FMath.sub(interest[:investment], min_investment)
@@ -110,6 +137,7 @@ module Istox
110
137
  interest[:granted_amount].to_d.positive?
111
138
  interest.delete(:is_vip)
112
139
  interest.delete(:granted_amount)
140
+ interest.delete(:has_earlier_interest)
113
141
 
114
142
  if include_refund_amount
115
143
  original_investment = original_investments.find { |original_investment1| original_investment1[:id] == interest[:id] }
@@ -122,14 +150,12 @@ module Istox
122
150
 
123
151
  final_interests = interests.each_with_index.map do |interest|
124
152
  final_amount = if interest[:is_vip]
125
- vip_fiat_amount = max_allowed_investor.positive? ? interest[:fiat_amount] : '0'
153
+ vip_fiat_amount = !interest[:to_be_set_zero] ? interest[:fiat_amount] : '0'
126
154
  ::Istox::FMath.add(vip_fiat_amount, interest[:granted_amount])
127
155
  else
128
- max_allowed_investor.positive? ? interest[:fiat_amount] : '0'
156
+ !interest[:to_be_set_zero] ? interest[:fiat_amount] : '0'
129
157
  end
130
158
 
131
- max_allowed_investor -= 1 if interest[:fiat_amount].to_d.positive?
132
-
133
159
  result = {
134
160
  id: interest[:id],
135
161
  investment: ::BigDecimal.new(final_amount.to_s).to_s
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.2.9'.freeze
2
+ VERSION = '0.2.10'.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.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print