istox 0.2.9 → 0.2.10.pre.1

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: 5bb9f52ae8d2903dd9945db8f4f9cc35bba65476b38fab52facd2ee7af1a9be3
4
+ data.tar.gz: 3ea4da15fce4939aa97e1449029ae023b2f6292f320c1ff00c8d86b060a17647
5
5
  SHA512:
6
- metadata.gz: a1f9dc10064f5527c503564078a02a7a6a219e57a03f6c152653f66e79050005cc0404bd639b8f18f870184811e3c0c2e874b45e73723e89b19c9f1fc0bfa10c
7
- data.tar.gz: 6a604074785ecbcb31e10bbc37230f1ad7290aa7315c6b02b1c5ab14c4d0c8a572c441ae291c53e61ca31a87939fa12b4bfceb472f8bb08b38921d4c9aa15c66
6
+ metadata.gz: 83a8ec6ed983aff937d8a6732c451ac2f49e37ab5c325ecc2fe0ec0053ec3cc0de4f42e260d058117a5a16f583e5c708f49382a3065e956382ecb8bfcb15b0b7
7
+ data.tar.gz: dc287d41fea3dfbf61c1e6398c190bb67efefa45e879e8fa8271c7e50584c2e7ec91d6bfa95b897d0907a5e77a4c3356b524072ec56e85705ed1f9bb322ef32b
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.10)
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)
@@ -23,43 +22,43 @@ PATH
23
22
  GEM
24
23
  remote: https://rubygems.org/
25
24
  specs:
26
- actioncable (5.2.2)
27
- actionpack (= 5.2.2)
25
+ actioncable (5.2.6)
26
+ actionpack (= 5.2.6)
28
27
  nio4r (~> 2.0)
29
28
  websocket-driver (>= 0.6.1)
30
- actionmailer (5.2.2)
31
- actionpack (= 5.2.2)
32
- actionview (= 5.2.2)
33
- activejob (= 5.2.2)
29
+ actionmailer (5.2.6)
30
+ actionpack (= 5.2.6)
31
+ actionview (= 5.2.6)
32
+ activejob (= 5.2.6)
34
33
  mail (~> 2.5, >= 2.5.4)
35
34
  rails-dom-testing (~> 2.0)
36
- actionpack (5.2.2)
37
- actionview (= 5.2.2)
38
- activesupport (= 5.2.2)
39
- rack (~> 2.0)
35
+ actionpack (5.2.6)
36
+ actionview (= 5.2.6)
37
+ activesupport (= 5.2.6)
38
+ rack (~> 2.0, >= 2.0.8)
40
39
  rack-test (>= 0.6.3)
41
40
  rails-dom-testing (~> 2.0)
42
41
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
43
- actionview (5.2.2)
44
- activesupport (= 5.2.2)
42
+ actionview (5.2.6)
43
+ activesupport (= 5.2.6)
45
44
  builder (~> 3.1)
46
45
  erubi (~> 1.4)
47
46
  rails-dom-testing (~> 2.0)
48
47
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
49
- activejob (5.2.2)
50
- activesupport (= 5.2.2)
48
+ activejob (5.2.6)
49
+ activesupport (= 5.2.6)
51
50
  globalid (>= 0.3.6)
52
- activemodel (5.2.2)
53
- activesupport (= 5.2.2)
54
- activerecord (5.2.2)
55
- activemodel (= 5.2.2)
56
- activesupport (= 5.2.2)
51
+ activemodel (5.2.6)
52
+ activesupport (= 5.2.6)
53
+ activerecord (5.2.6)
54
+ activemodel (= 5.2.6)
55
+ activesupport (= 5.2.6)
57
56
  arel (>= 9.0)
58
- activestorage (5.2.2)
59
- actionpack (= 5.2.2)
60
- activerecord (= 5.2.2)
61
- marcel (~> 0.3.1)
62
- activesupport (5.2.2)
57
+ activestorage (5.2.6)
58
+ actionpack (= 5.2.6)
59
+ activerecord (= 5.2.6)
60
+ marcel (~> 1.0.0)
61
+ activesupport (5.2.6)
63
62
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
63
  i18n (>= 0.7, < 2)
65
64
  minitest (~> 5.1)
@@ -92,17 +91,17 @@ 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
- concurrent-ruby (1.1.6)
99
+ concurrent-ruby (1.1.9)
100
100
  crass (1.0.6)
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
- erubi (1.9.0)
104
+ erubi (1.10.0)
106
105
  exponential-backoff (0.0.4)
107
106
  factory_bot (4.8.2)
108
107
  activesupport (>= 3.0.0)
@@ -113,44 +112,39 @@ GEM
113
112
  i18n (~> 0.5)
114
113
  fakeredis (0.7.0)
115
114
  redis (>= 3.2, < 5.0)
116
- faraday (1.4.1)
115
+ faraday (1.4.2)
116
+ faraday-em_http (~> 1.0)
117
+ faraday-em_synchrony (~> 1.0)
117
118
  faraday-excon (~> 1.1)
118
119
  faraday-net_http (~> 1.0)
119
120
  faraday-net_http_persistent (~> 1.1)
120
121
  multipart-post (>= 1.2, < 3)
121
122
  ruby2_keywords (>= 0.0.4)
123
+ faraday-em_http (1.0.0)
124
+ faraday-em_synchrony (1.0.0)
122
125
  faraday-excon (1.1.0)
123
126
  faraday-net_http (1.0.1)
124
127
  faraday-net_http_persistent (1.1.0)
125
128
  faraday_middleware (1.0.0)
126
129
  faraday (~> 1.0)
127
- ffi (1.15.0)
130
+ ffi (1.15.3)
128
131
  globalid (0.4.2)
129
132
  activesupport (>= 4.2.0)
130
- google-protobuf (3.15.8-universal-darwin)
133
+ google-protobuf (3.17.3)
131
134
  googleapis-common-protos-types (1.0.6)
132
135
  google-protobuf (~> 3.14)
133
136
  graphlient (0.5.0)
134
137
  faraday (>= 1.0)
135
138
  faraday_middleware
136
139
  graphql-client
137
- graphql (1.12.8)
140
+ graphql (1.12.12)
138
141
  graphql-client (0.16.0)
139
142
  activesupport (>= 3.0)
140
143
  graphql (~> 1.8)
141
- grpc (1.37.0-universal-darwin)
144
+ grpc (1.38.0)
142
145
  google-protobuf (~> 3.15)
143
146
  googleapis-common-protos-types (~> 1.0)
144
- 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)
147
+ grpc-tools (1.38.0)
154
148
  hashie (3.5.7)
155
149
  i18n (0.9.5)
156
150
  concurrent-ruby (~> 1.0)
@@ -161,28 +155,26 @@ GEM
161
155
  grpc-tools (~> 1.10)
162
156
  slop (~> 4.6)
163
157
  jmespath (1.4.0)
164
- json (2.5.1)
165
158
  listen (3.0.8)
166
159
  rb-fsevent (~> 0.9, >= 0.9.4)
167
160
  rb-inotify (~> 0.9, >= 0.9.7)
168
- loofah (2.4.0)
161
+ loofah (2.10.0)
169
162
  crass (~> 1.0.2)
170
163
  nokogiri (>= 1.5.9)
171
164
  mail (2.7.1)
172
165
  mini_mime (>= 0.1.1)
173
- marcel (0.3.3)
174
- mimemagic (~> 0.3.2)
166
+ marcel (1.0.1)
175
167
  method_source (0.9.2)
176
- mimemagic (0.3.3)
177
- mini_mime (1.0.1)
178
- mini_portile2 (2.4.0)
179
- minitest (5.14.0)
168
+ mini_mime (1.1.0)
169
+ mini_portile2 (2.5.3)
170
+ minitest (5.14.4)
180
171
  multi_json (1.14.1)
181
172
  multipart-post (2.1.1)
182
- nio4r (2.3.1)
183
- nokogiri (1.10.9)
184
- mini_portile2 (~> 2.4.0)
185
- oj (3.11.5)
173
+ nio4r (2.5.7)
174
+ nokogiri (1.11.7)
175
+ mini_portile2 (~> 2.5.0)
176
+ racc (~> 1.4)
177
+ oj (3.11.6)
186
178
  ougai (2.0.0)
187
179
  oj (~> 3.10)
188
180
  paranoia (2.4.3)
@@ -195,43 +187,45 @@ GEM
195
187
  pry (~> 0.10)
196
188
  pry-rails (0.3.9)
197
189
  pry (>= 0.10.4)
198
- rack (2.2.2)
190
+ racc (1.5.2)
191
+ rack (2.2.3)
199
192
  rack-test (1.1.0)
200
193
  rack (>= 1.0, < 3)
201
- rails (5.2.2)
202
- actioncable (= 5.2.2)
203
- actionmailer (= 5.2.2)
204
- actionpack (= 5.2.2)
205
- actionview (= 5.2.2)
206
- activejob (= 5.2.2)
207
- activemodel (= 5.2.2)
208
- activerecord (= 5.2.2)
209
- activestorage (= 5.2.2)
210
- activesupport (= 5.2.2)
194
+ rails (5.2.6)
195
+ actioncable (= 5.2.6)
196
+ actionmailer (= 5.2.6)
197
+ actionpack (= 5.2.6)
198
+ actionview (= 5.2.6)
199
+ activejob (= 5.2.6)
200
+ activemodel (= 5.2.6)
201
+ activerecord (= 5.2.6)
202
+ activestorage (= 5.2.6)
203
+ activesupport (= 5.2.6)
211
204
  bundler (>= 1.3.0)
212
- railties (= 5.2.2)
205
+ railties (= 5.2.6)
213
206
  sprockets-rails (>= 2.0.0)
214
207
  rails-dom-testing (2.0.3)
215
208
  activesupport (>= 4.2.0)
216
209
  nokogiri (>= 1.6)
217
210
  rails-html-sanitizer (1.3.0)
218
211
  loofah (~> 2.3)
219
- railties (5.2.2)
220
- actionpack (= 5.2.2)
221
- activesupport (= 5.2.2)
212
+ railties (5.2.6)
213
+ actionpack (= 5.2.6)
214
+ activesupport (= 5.2.6)
222
215
  method_source
223
216
  rake (>= 0.8.7)
224
217
  thor (>= 0.19.0, < 2.0)
225
218
  rake (10.5.0)
226
- rb-fsevent (0.10.4)
219
+ rb-fsevent (0.11.0)
227
220
  rb-inotify (0.10.1)
228
221
  ffi (~> 1.0)
222
+ rbtree (0.4.4)
229
223
  redis (4.1.3)
230
224
  redis-actionpack (5.2.0)
231
225
  actionpack (>= 5, < 7)
232
226
  redis-rack (>= 2.1.0, < 3)
233
227
  redis-store (>= 1.1.0, < 2)
234
- redis-activesupport (5.2.0)
228
+ redis-activesupport (5.2.1)
235
229
  activesupport (>= 3, < 7)
236
230
  redis-store (>= 1.3, < 2)
237
231
  redis-namespace (1.8.1)
@@ -267,28 +261,30 @@ GEM
267
261
  rspec-support (~> 3.8.0)
268
262
  rspec-support (3.8.0)
269
263
  ruby2_keywords (0.0.4)
270
- slop (4.8.2)
271
- sprockets (3.7.2)
264
+ set (1.0.1)
265
+ slop (4.9.1)
266
+ sorted_set (1.0.3)
267
+ rbtree
268
+ set (~> 1.0)
269
+ sprockets (4.0.2)
272
270
  concurrent-ruby (~> 1.0)
273
271
  rack (> 1, < 3)
274
- sprockets-rails (3.2.1)
272
+ sprockets-rails (3.2.2)
275
273
  actionpack (>= 4.0)
276
274
  activesupport (>= 4.0)
277
275
  sprockets (>= 3.0.0)
278
276
  sqlite3 (1.3.13)
279
- thor (0.20.3)
277
+ thor (1.1.0)
280
278
  thread_safe (0.3.6)
281
- thwait (0.2.0)
282
- e2mmap
283
279
  timecop (0.9.1)
284
- tzinfo (1.2.6)
280
+ tzinfo (1.2.9)
285
281
  thread_safe (~> 0.1)
286
282
  uniform_notifier (1.11.0)
287
283
  vault (0.16.0)
288
284
  aws-sigv4
289
- websocket-driver (0.7.0)
285
+ websocket-driver (0.7.5)
290
286
  websocket-extensions (>= 0.1.0)
291
- websocket-extensions (0.1.3)
287
+ websocket-extensions (0.1.5)
292
288
 
293
289
  PLATFORMS
294
290
  ruby
@@ -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-1'.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.pre.1
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-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -528,9 +528,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
528
528
  version: '0'
529
529
  required_rubygems_version: !ruby/object:Gem::Requirement
530
530
  requirements:
531
- - - ">="
531
+ - - ">"
532
532
  - !ruby/object:Gem::Version
533
- version: '0'
533
+ version: 1.3.1
534
534
  requirements: []
535
535
  rubygems_version: 3.0.6
536
536
  signing_key: