istox 0.1.125 → 0.1.126
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/istox-gem.iml +2 -1691
- data/Gemfile.lock +4 -4
- data/lib/istox/helpers/order_book_prorate.rb +79 -13
- data/lib/istox/version.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -97,7 +97,7 @@ GEM
|
|
97
97
|
ffi (1.12.2)
|
98
98
|
globalid (0.4.2)
|
99
99
|
activesupport (>= 4.2.0)
|
100
|
-
google-protobuf (3.11.4
|
100
|
+
google-protobuf (3.11.4)
|
101
101
|
googleapis-common-protos-types (1.0.4)
|
102
102
|
google-protobuf (~> 3.0)
|
103
103
|
graphlient (0.3.7)
|
@@ -108,7 +108,7 @@ GEM
|
|
108
108
|
graphql-client (0.16.0)
|
109
109
|
activesupport (>= 3.0)
|
110
110
|
graphql (~> 1.8)
|
111
|
-
grpc (1.27.0
|
111
|
+
grpc (1.27.0)
|
112
112
|
google-protobuf (~> 3.11)
|
113
113
|
googleapis-common-protos-types (~> 1.0)
|
114
114
|
grpc-tools (1.27.0)
|
@@ -144,9 +144,9 @@ GEM
|
|
144
144
|
minitest (5.14.0)
|
145
145
|
multipart-post (2.1.1)
|
146
146
|
nio4r (2.3.1)
|
147
|
-
nokogiri (1.10.
|
147
|
+
nokogiri (1.10.9)
|
148
148
|
mini_portile2 (~> 2.4.0)
|
149
|
-
oj (3.10.
|
149
|
+
oj (3.10.3)
|
150
150
|
ougai (1.8.2)
|
151
151
|
oj (~> 3.4)
|
152
152
|
paranoia (2.4.2)
|
@@ -1,8 +1,29 @@
|
|
1
1
|
module Istox
|
2
2
|
class OrderBookProrate
|
3
3
|
class << self
|
4
|
-
def allocation(token_price:, min_investment:, bid_block:,
|
5
|
-
invest_step:, hard_cap:, investments:)
|
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
|
6
27
|
|
7
28
|
# sort by id asc
|
8
29
|
interests = investments.sort do |a, b|
|
@@ -12,22 +33,30 @@ module Istox
|
|
12
33
|
|
13
34
|
max_allowed_investor = Istox::FMath.round_down(::Istox::FMath.div(hard_cap, min_investment), 0).to_i
|
14
35
|
|
15
|
-
|
16
|
-
|
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
|
17
42
|
end
|
18
43
|
|
19
44
|
# only need to handle when oversubscribe
|
20
45
|
if total_interests.to_d > hard_cap.to_s.to_d
|
21
46
|
|
22
47
|
# prorate the interests
|
23
|
-
|
24
|
-
|
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?
|
25
51
|
result = ::Istox::FMath.round_down(::Istox::FMath.mul(::Istox::FMath.div(interest[:fiat_amount], total_interests),
|
26
52
|
hard_cap), 0)
|
53
|
+
|
27
54
|
result = result.to_d - result.to_d.modulo(invest_step.to_s.to_d)
|
28
55
|
|
29
|
-
|
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?
|
30
58
|
|
59
|
+
i += 1
|
31
60
|
result
|
32
61
|
else
|
33
62
|
::BigDecimal.new('0').to_s
|
@@ -35,6 +64,8 @@ module Istox
|
|
35
64
|
|
36
65
|
{
|
37
66
|
id: interest[:id],
|
67
|
+
is_vip: interest[:is_vip],
|
68
|
+
granted_amount: interest[:granted_amount],
|
38
69
|
investment: investment.to_s
|
39
70
|
}
|
40
71
|
end
|
@@ -48,9 +79,14 @@ module Istox
|
|
48
79
|
if new_total_interests.to_d > hard_cap.to_s.to_d
|
49
80
|
total_deducting = ::Istox::FMath.sub(new_total_interests, hard_cap)
|
50
81
|
interests.reverse_each do |interest|
|
51
|
-
next unless interest[:investment].to_d > min_investment.to_d
|
82
|
+
next unless interest[:investment].to_d > min_investment.to_d || interest[:is_vip]
|
52
83
|
|
53
|
-
|
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
|
54
90
|
|
55
91
|
if deductable.to_d > total_deducting.to_d
|
56
92
|
interest[:investment] = ::Istox::FMath.sub(interest[:investment], total_deducting)
|
@@ -62,14 +98,44 @@ module Istox
|
|
62
98
|
end
|
63
99
|
end
|
64
100
|
|
65
|
-
final_interests = interests
|
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
|
66
113
|
|
67
114
|
else
|
68
|
-
|
69
|
-
|
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 = {
|
70
127
|
id: interest[:id],
|
71
|
-
investment:
|
128
|
+
investment: ::BigDecimal.new(final_amount.to_s).to_s
|
129
|
+
|
72
130
|
}
|
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
|
73
139
|
end
|
74
140
|
end
|
75
141
|
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.126
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
445
445
|
- !ruby/object:Gem::Version
|
446
446
|
version: '0'
|
447
447
|
requirements: []
|
448
|
-
rubygems_version: 3.0.
|
448
|
+
rubygems_version: 3.0.6
|
449
449
|
signing_key:
|
450
450
|
specification_version: 4
|
451
451
|
summary: istox backend shared gem
|