istox 0.2.6.pre.4 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -19
- data/lib/istox/helpers/blockchain_service.rb +7 -5
- data/lib/istox/helpers/messaging.rb +19 -0
- data/lib/istox/helpers/order_book_prorate.rb +64 -24
- data/lib/istox/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2099515f9703dcadd1f99da2d05be06e062c624638ae9c3646880497c7d192d
|
4
|
+
data.tar.gz: 1ceba372de27ec21beb41acde07f601f138cf116d1aad19f50034af3f7cb2d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
4
|
+
istox (0.2.9)
|
5
5
|
amazing_print
|
6
6
|
awesome_print
|
7
7
|
aws-sdk-sns (~> 1)
|
@@ -66,7 +66,7 @@ GEM
|
|
66
66
|
amazing_print (1.3.0)
|
67
67
|
amq-protocol (2.3.2)
|
68
68
|
arel (9.0.0)
|
69
|
-
awesome_print (1.
|
69
|
+
awesome_print (1.9.2)
|
70
70
|
aws-eventstream (1.1.0)
|
71
71
|
aws-partitions (1.318.0)
|
72
72
|
aws-sdk-core (3.96.1)
|
@@ -91,8 +91,9 @@ GEM
|
|
91
91
|
bullet (5.7.6)
|
92
92
|
activesupport (>= 3.0.0)
|
93
93
|
uniform_notifier (~> 1.11.0)
|
94
|
-
bunny (2.
|
94
|
+
bunny (2.18.0)
|
95
95
|
amq-protocol (~> 2.3, >= 2.3.1)
|
96
|
+
sorted_set (~> 1, >= 1.0.2)
|
96
97
|
byebug (11.1.3)
|
97
98
|
coderay (1.1.2)
|
98
99
|
concurrent-ruby (1.1.6)
|
@@ -111,31 +112,35 @@ GEM
|
|
111
112
|
i18n (~> 0.5)
|
112
113
|
fakeredis (0.7.0)
|
113
114
|
redis (>= 3.2, < 5.0)
|
114
|
-
faraday (1.
|
115
|
+
faraday (1.4.1)
|
116
|
+
faraday-excon (~> 1.1)
|
115
117
|
faraday-net_http (~> 1.0)
|
118
|
+
faraday-net_http_persistent (~> 1.1)
|
116
119
|
multipart-post (>= 1.2, < 3)
|
117
|
-
ruby2_keywords
|
120
|
+
ruby2_keywords (>= 0.0.4)
|
121
|
+
faraday-excon (1.1.0)
|
118
122
|
faraday-net_http (1.0.1)
|
123
|
+
faraday-net_http_persistent (1.1.0)
|
119
124
|
faraday_middleware (1.0.0)
|
120
125
|
faraday (~> 1.0)
|
121
|
-
ffi (1.15.
|
126
|
+
ffi (1.15.1)
|
122
127
|
globalid (0.4.2)
|
123
128
|
activesupport (>= 4.2.0)
|
124
|
-
google-protobuf (3.
|
125
|
-
googleapis-common-protos-types (1.0.
|
126
|
-
google-protobuf (~> 3.
|
129
|
+
google-protobuf (3.15.8-universal-darwin)
|
130
|
+
googleapis-common-protos-types (1.0.6)
|
131
|
+
google-protobuf (~> 3.14)
|
127
132
|
graphlient (0.5.0)
|
128
133
|
faraday (>= 1.0)
|
129
134
|
faraday_middleware
|
130
135
|
graphql-client
|
131
|
-
graphql (1.
|
136
|
+
graphql (1.12.8)
|
132
137
|
graphql-client (0.16.0)
|
133
138
|
activesupport (>= 3.0)
|
134
139
|
graphql (~> 1.8)
|
135
|
-
grpc (1.
|
136
|
-
google-protobuf (~> 3.
|
140
|
+
grpc (1.37.0-universal-darwin)
|
141
|
+
google-protobuf (~> 3.15)
|
137
142
|
googleapis-common-protos-types (~> 1.0)
|
138
|
-
grpc-tools (1.
|
143
|
+
grpc-tools (1.37.0)
|
139
144
|
hashie (3.5.7)
|
140
145
|
i18n (0.9.5)
|
141
146
|
concurrent-ruby (~> 1.0)
|
@@ -166,8 +171,8 @@ GEM
|
|
166
171
|
nio4r (2.3.1)
|
167
172
|
nokogiri (1.10.9)
|
168
173
|
mini_portile2 (~> 2.4.0)
|
169
|
-
oj (3.
|
170
|
-
ougai (
|
174
|
+
oj (3.11.5)
|
175
|
+
ougai (2.0.0)
|
171
176
|
oj (~> 3.10)
|
172
177
|
paranoia (2.4.3)
|
173
178
|
activerecord (>= 4.0, < 6.2)
|
@@ -207,9 +212,10 @@ GEM
|
|
207
212
|
rake (>= 0.8.7)
|
208
213
|
thor (>= 0.19.0, < 2.0)
|
209
214
|
rake (10.5.0)
|
210
|
-
rb-fsevent (0.
|
215
|
+
rb-fsevent (0.11.0)
|
211
216
|
rb-inotify (0.10.1)
|
212
217
|
ffi (~> 1.0)
|
218
|
+
rbtree (0.4.4)
|
213
219
|
redis (4.1.3)
|
214
220
|
redis-actionpack (5.2.0)
|
215
221
|
actionpack (>= 5, < 7)
|
@@ -218,7 +224,7 @@ GEM
|
|
218
224
|
redis-activesupport (5.2.0)
|
219
225
|
activesupport (>= 3, < 7)
|
220
226
|
redis-store (>= 1.3, < 2)
|
221
|
-
redis-namespace (1.8.
|
227
|
+
redis-namespace (1.8.1)
|
222
228
|
redis (>= 3.0.4)
|
223
229
|
redis-rack (2.1.3)
|
224
230
|
rack (>= 2.0.8, < 3)
|
@@ -250,8 +256,12 @@ GEM
|
|
250
256
|
rspec-mocks (~> 3.8.0)
|
251
257
|
rspec-support (~> 3.8.0)
|
252
258
|
rspec-support (3.8.0)
|
253
|
-
ruby2_keywords (0.0.
|
254
|
-
|
259
|
+
ruby2_keywords (0.0.4)
|
260
|
+
set (1.0.1)
|
261
|
+
slop (4.9.1)
|
262
|
+
sorted_set (1.0.3)
|
263
|
+
rbtree
|
264
|
+
set (~> 1.0)
|
255
265
|
sprockets (3.7.2)
|
256
266
|
concurrent-ruby (~> 1.0)
|
257
267
|
rack (> 1, < 3)
|
@@ -8,18 +8,18 @@ module Istox
|
|
8
8
|
@@blockchain_receipt_klass
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.request(sid:, action:, before:,
|
12
|
-
start(sid: sid, action: action, before: before, execute: execute, is_request: true, request_reason: request_reason)
|
11
|
+
def self.request(sid:, action:, before:, execute:, before_start: nil, request_reason: nil)
|
12
|
+
start(sid: sid, action: action, before: before, before_start: before_start, execute: execute, is_request: true, request_reason: request_reason)
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.run(sid:, action:, before:, execute:)
|
16
|
-
start(sid: sid, action: action, before: before, execute: execute)
|
15
|
+
def self.run(sid:, action:, before:, execute:, before_start: nil)
|
16
|
+
start(sid: sid, action: action, before: before, before_start: before_start, execute: execute)
|
17
17
|
end
|
18
18
|
class << self
|
19
19
|
private
|
20
20
|
|
21
21
|
# before is the proc that will be executed before, must return the main model blockchain receipt will bind to
|
22
|
-
def start(sid:, action:, before:, execute:, is_request: false, request_reason: nil)
|
22
|
+
def start(sid:, action:, before:, execute:, before_start: nil, is_request: false, request_reason: nil)
|
23
23
|
# create blockchain receipt first
|
24
24
|
klass = blockchain_receipt_class
|
25
25
|
uuid = ::SecureRandom.uuid
|
@@ -33,6 +33,8 @@ module Istox
|
|
33
33
|
|
34
34
|
chainhub_processing = true
|
35
35
|
|
36
|
+
before_start.call(uuid) if before_start.present?
|
37
|
+
|
36
38
|
::ActiveRecord::Base.transaction do
|
37
39
|
# execute before proc, and get the model that blockchain receipt should bind to
|
38
40
|
model = before.call(uuid)
|
@@ -161,6 +161,25 @@ module Istox
|
|
161
161
|
end
|
162
162
|
template_data_arr.concat(copy_email_data_arr)
|
163
163
|
end
|
164
|
+
|
165
|
+
def push_notification(template_name, template_data_arr)
|
166
|
+
raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil?
|
167
|
+
|
168
|
+
return log.info 'Template data is empty, skipping this request' if template_data_arr.empty?
|
169
|
+
|
170
|
+
::Istox::Publisher.manual_publish(
|
171
|
+
exchange: 'message',
|
172
|
+
exchange_type: 'direct',
|
173
|
+
routing_key: 'push_notification.message',
|
174
|
+
message: {
|
175
|
+
type: 'SEND_PUSH_NOTIFICATION',
|
176
|
+
data: {
|
177
|
+
template_name: template_name,
|
178
|
+
template_data_arr_json: template_data_arr.to_json
|
179
|
+
}
|
180
|
+
}
|
181
|
+
)
|
182
|
+
end
|
164
183
|
end
|
165
184
|
end
|
166
185
|
end
|
@@ -2,42 +2,75 @@ module Istox
|
|
2
2
|
class OrderBookProrate
|
3
3
|
class << self
|
4
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
|
5
|
+
invest_step:, hard_cap:, investments:, whitelists: [], include_refund_amount: false,
|
6
|
+
rollover_investments: [])
|
6
7
|
|
7
8
|
# make sure is hashes
|
8
9
|
original_investments = investments.as_json.map(&:symbolize_keys)
|
9
10
|
whitelists = whitelists.as_json.map(&:symbolize_keys)
|
10
11
|
investments = investments.as_json.map(&:symbolize_keys)
|
12
|
+
rollover_investments = rollover_investments.as_json.map(&:symbolize_keys)
|
13
|
+
|
14
|
+
## rollover investment is guaranteed, so it should decrease the hard cap
|
15
|
+
rollover_investments.map do |rollover_investment|
|
16
|
+
hard_cap = ::Istox::FMath.sub(hard_cap, rollover_investment[:fiat_amount])
|
17
|
+
end
|
11
18
|
|
12
19
|
# process whitelist
|
13
20
|
whitelists.each do |whitelist|
|
14
|
-
|
21
|
+
whitelisted_investments = investments.select { |investment1| investment1[:account_id] == whitelist[:account_id] }
|
22
|
+
|
23
|
+
next unless whitelisted_investments.length.positive?
|
15
24
|
|
16
|
-
|
25
|
+
current_guarenteed_amount = ::BigDecimal.new(whitelist[:guaranteed_allocation].to_s)
|
17
26
|
|
18
|
-
|
27
|
+
whitelisted_investments.each do |whitelisted_investment|
|
28
|
+
granted_amount = [::BigDecimal.new(whitelisted_investment[:fiat_amount].to_s), current_guarenteed_amount].min
|
19
29
|
|
20
|
-
|
30
|
+
next unless granted_amount.positive?
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
26
39
|
end
|
27
40
|
|
28
41
|
# sort by id asc
|
29
42
|
interests = investments.sort do |a, b|
|
30
43
|
a[:id] <=> b[:id]
|
31
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
|
+
|
32
58
|
total_interests = 0
|
33
59
|
|
34
60
|
max_allowed_investor = Istox::FMath.round_down(::Istox::FMath.div(hard_cap, min_investment), 0).to_i
|
35
61
|
|
36
|
-
|
62
|
+
allowed_investor_ids = []
|
37
63
|
interests.each_with_index.map do |interest|
|
38
|
-
if interest[:
|
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
|
39
68
|
total_interests = ::Istox::FMath.add(total_interests, interest[:fiat_amount])
|
40
|
-
|
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
|
41
74
|
end
|
42
75
|
end
|
43
76
|
|
@@ -45,18 +78,18 @@ module Istox
|
|
45
78
|
if total_interests.to_d > hard_cap.to_s.to_d
|
46
79
|
|
47
80
|
# prorate the interests
|
48
|
-
i = 0
|
49
81
|
interests = interests.each_with_index.map do |interest|
|
50
|
-
investment = if
|
82
|
+
investment = if interest[:fiat_amount].to_d.positive? && !interest[:to_be_set_zero]
|
51
83
|
result = ::Istox::FMath.round_down(::Istox::FMath.mul(::Istox::FMath.div(interest[:fiat_amount], total_interests),
|
52
84
|
hard_cap), 0)
|
53
85
|
|
54
86
|
result = result.to_d - result.to_d.modulo(invest_step.to_s.to_d)
|
55
87
|
|
56
88
|
# only set to min investment if is not vip
|
57
|
-
|
89
|
+
if result < min_investment.to_d && interest[:is_vip].blank? && !interest[:has_earlier_interest]
|
90
|
+
result = min_investment.to_d
|
91
|
+
end
|
58
92
|
|
59
|
-
i += 1
|
60
93
|
result
|
61
94
|
else
|
62
95
|
::BigDecimal.new('0').to_s
|
@@ -66,6 +99,7 @@ module Istox
|
|
66
99
|
id: interest[:id],
|
67
100
|
is_vip: interest[:is_vip],
|
68
101
|
granted_amount: interest[:granted_amount],
|
102
|
+
has_earlier_interest: interest[:has_earlier_interest],
|
69
103
|
investment: investment.to_s
|
70
104
|
}
|
71
105
|
end
|
@@ -79,10 +113,10 @@ module Istox
|
|
79
113
|
if new_total_interests.to_d > hard_cap.to_s.to_d
|
80
114
|
total_deducting = ::Istox::FMath.sub(new_total_interests, hard_cap)
|
81
115
|
interests.reverse_each do |interest|
|
82
|
-
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]
|
83
117
|
|
84
118
|
# allow to deduct to zero if is vip
|
85
|
-
deductable = if interest[:is_vip]
|
119
|
+
deductable = if interest[:is_vip] || interest[:has_earlier_interest]
|
86
120
|
interest[:investment]
|
87
121
|
else
|
88
122
|
::Istox::FMath.sub(interest[:investment], min_investment)
|
@@ -103,10 +137,11 @@ module Istox
|
|
103
137
|
interest[:granted_amount].to_d.positive?
|
104
138
|
interest.delete(:is_vip)
|
105
139
|
interest.delete(:granted_amount)
|
140
|
+
interest.delete(:has_earlier_interest)
|
106
141
|
|
107
142
|
if include_refund_amount
|
108
143
|
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])
|
144
|
+
interest[:refund_amount] = original_investment.present? ? ::Istox::FMath.sub(original_investment[:fiat_amount], interest[:investment]) : '0'
|
110
145
|
end
|
111
146
|
interest
|
112
147
|
end
|
@@ -115,14 +150,12 @@ module Istox
|
|
115
150
|
|
116
151
|
final_interests = interests.each_with_index.map do |interest|
|
117
152
|
final_amount = if interest[:is_vip]
|
118
|
-
vip_fiat_amount =
|
153
|
+
vip_fiat_amount = !interest[:to_be_set_zero] ? interest[:fiat_amount] : '0'
|
119
154
|
::Istox::FMath.add(vip_fiat_amount, interest[:granted_amount])
|
120
155
|
else
|
121
|
-
|
156
|
+
!interest[:to_be_set_zero] ? interest[:fiat_amount] : '0'
|
122
157
|
end
|
123
158
|
|
124
|
-
max_allowed_investor -= 1 if interest[:fiat_amount].to_d.positive?
|
125
|
-
|
126
159
|
result = {
|
127
160
|
id: interest[:id],
|
128
161
|
investment: ::BigDecimal.new(final_amount.to_s).to_s
|
@@ -139,9 +172,16 @@ module Istox
|
|
139
172
|
end
|
140
173
|
end
|
141
174
|
|
175
|
+
transform_rollover_investments = rollover_investments.map do |rollover_investment|
|
176
|
+
rollover_investment[:investment] = ::BigDecimal.new(rollover_investment[:fiat_amount].to_s).to_s
|
177
|
+
rollover_investment[:refund_amount] = ::BigDecimal.new(0).to_s if include_refund_amount
|
178
|
+
|
179
|
+
rollover_investment.select { |k, _v| %i[id investment refund_amount].include?(k) }
|
180
|
+
end
|
181
|
+
|
142
182
|
{
|
143
183
|
cutoff_price: token_price.to_s,
|
144
|
-
interests: final_interests
|
184
|
+
interests: final_interests.concat(transform_rollover_investments)
|
145
185
|
}
|
146
186
|
end
|
147
187
|
end
|
data/lib/istox/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -517,7 +517,7 @@ files:
|
|
517
517
|
homepage: http://www.abc.com
|
518
518
|
licenses: []
|
519
519
|
metadata: {}
|
520
|
-
post_install_message:
|
520
|
+
post_install_message:
|
521
521
|
rdoc_options: []
|
522
522
|
require_paths:
|
523
523
|
- lib
|
@@ -528,12 +528,12 @@ 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:
|
533
|
+
version: '0'
|
534
534
|
requirements: []
|
535
|
-
rubygems_version: 3.0.
|
536
|
-
signing_key:
|
535
|
+
rubygems_version: 3.0.6
|
536
|
+
signing_key:
|
537
537
|
specification_version: 4
|
538
538
|
summary: istox backend shared gem
|
539
539
|
test_files: []
|