istox 0.1.118 → 0.1.119.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6780e67873de895958f545a604e4f07d7c6156bd4500f1b0cdf26a2775c81de7
4
- data.tar.gz: 3426b0f8747328d4aa0c459336ec8dc883f3f71390dffcd9a02acae61b16c7be
3
+ metadata.gz: 6c7c060b93bd6ba62c8e7ff847a70eede8b1f0b1a1c36c8a257d7d87bb6bb6f9
4
+ data.tar.gz: adff8860c2353f3e1661d08ff862b3ff073212999d292eb6223c3a22b249b9d2
5
5
  SHA512:
6
- metadata.gz: 286711adcd8fa252fc18f1004b9d93f7b0341f6fac1f55e2a23e8130813d248e710ae51f118089710a0dc180d24cd587900df1bf918f0f398819c201c5b4191d
7
- data.tar.gz: 448e197b8bce37fc7191da99cdcdbb06cb953aeaf5d118392b655b9df6b427ebdf986f905b09c863a4aaba0ab8485753940e494b54ef493cda5877a9d91f3812
6
+ metadata.gz: 6cc8c47eb70effb080b17c0bc6a5da962374fb7a666138a9d9a0e164e663d245b99a289268887b653487b193085848442de49320555be44534030d1556ae891b
7
+ data.tar.gz: 0b4e36e282273f5dc580312383e3ec491202e453da319dc0af4f314d12227c9997d74cef8cddf0e4cc7f8988f65ce286436292c825a2c33857e9dc4efb46b4c5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.115)
4
+ istox (0.1.119)
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)
98
+ google-protobuf (3.11.2-universal-darwin)
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)
109
+ grpc (1.26.0-universal-darwin)
110
110
  google-protobuf (~> 3.8)
111
111
  googleapis-common-protos-types (~> 1.0)
112
112
  grpc-tools (1.26.0)
@@ -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|
@@ -26,7 +47,8 @@ module Istox
26
47
  hard_cap), 0)
27
48
  result = result.to_d - result.to_d.modulo(invest_step.to_s.to_d)
28
49
 
29
- result = min_investment.to_d if result < min_investment.to_d
50
+ # only set to min investment if is not vip
51
+ result = min_investment.to_d if result < min_investment.to_d && interest[:is_vip].blank?
30
52
 
31
53
  result
32
54
  else
@@ -35,6 +57,8 @@ module Istox
35
57
 
36
58
  {
37
59
  id: interest[:id],
60
+ is_vip: interest[:is_vip],
61
+ granted_amount: interest[:granted_amount],
38
62
  investment: investment.to_s
39
63
  }
40
64
  end
@@ -48,9 +72,14 @@ module Istox
48
72
  if new_total_interests.to_d > hard_cap.to_s.to_d
49
73
  total_deducting = ::Istox::FMath.sub(new_total_interests, hard_cap)
50
74
  interests.reverse_each do |interest|
51
- next unless interest[:investment].to_d > min_investment.to_d
75
+ next unless interest[:investment].to_d > min_investment.to_d || interest[:is_vip]
52
76
 
53
- deductable = ::Istox::FMath.sub(interest[:investment], min_investment)
77
+ # allow to deduct to zero if is vip
78
+ deductable = if interest[:is_vip]
79
+ interest[:investment]
80
+ else
81
+ ::Istox::FMath.sub(interest[:investment], min_investment)
82
+ end
54
83
 
55
84
  if deductable.to_d > total_deducting.to_d
56
85
  interest[:investment] = ::Istox::FMath.sub(interest[:investment], total_deducting)
@@ -62,14 +91,41 @@ module Istox
62
91
  end
63
92
  end
64
93
 
65
- final_interests = interests
94
+ final_interests = interests.map do |interest|
95
+ interest[:investment] = ::Istox::FMath.add(interest[:investment], interest[:granted_amount]) if interest[:granted_amount].present? &&
96
+ interest[:granted_amount].to_d.positive?
97
+ interest.delete(:is_vip)
98
+ interest.delete(:granted_amount)
99
+
100
+ if include_refund_amount
101
+ original_investment = original_investments.find { |original_investment1| original_investment1[:id] == interest[:id] }
102
+ interest[:refund_amount] = ::Istox::FMath.sub(original_investment[:fiat_amount], interest[:investment])
103
+ end
104
+ interest
105
+ end
66
106
 
67
107
  else
68
- final_interests = interests.each_with_index.map do |interest, i|
69
- {
108
+ final_interests = interests.each_with_index.map do |interest|
109
+ final_amount = if interest[:is_vip]
110
+ ::Istox::FMath.add(interest[:fiat_amount], interest[:granted_amount])
111
+ else
112
+ max_allowed_investor.positive? ? interest[:fiat_amount] : '0'
113
+ end
114
+
115
+ max_allowed_investor -= 1
116
+ result = {
70
117
  id: interest[:id],
71
- investment: i < max_allowed_investor ? ::BigDecimal.new(interest[:fiat_amount].to_s).to_s : ::BigDecimal.new('0').to_s
118
+ investment: ::BigDecimal.new(final_amount.to_s).to_s
119
+
72
120
  }
121
+
122
+ if include_refund_amount
123
+ original_investment = original_investments.find { |original_investment1| original_investment1[:id] == interest[:id] }
124
+ refund_amount = ::Istox::FMath.sub(original_investment[:fiat_amount], final_amount)
125
+ result[:refund_amount] = refund_amount
126
+ end
127
+
128
+ result
73
129
  end
74
130
  end
75
131
 
@@ -59,14 +59,14 @@ module Istox
59
59
  raise "Exchange type #{exchange_config.type} is not valid/supported."
60
60
  end
61
61
 
62
- publish_confirm = options[:publish_confirm].nil? ? true : options[:publish_confirm]
62
+ # publish_confirm = options[:publish_confirm].nil? ? true : options[:publish_confirm]
63
63
 
64
- if publish_confirm
65
- log.info 'Waiting for RABBITMQ publisher acknowledgement'
64
+ # if publish_confirm
65
+ # log.info 'Waiting for RABBITMQ publisher acknowledgement'
66
66
 
67
- success = channel.wait_for_confirms
68
- raise 'RABBITMQ publish acknowlegement failed' unless success
69
- end
67
+ # success = channel.wait_for_confirms
68
+ # raise 'RABBITMQ publish acknowlegement failed' unless success
69
+ # end
70
70
 
71
71
  log.info 'Publish RABBITMQ message success'
72
72
  end
@@ -80,7 +80,7 @@ module Istox
80
80
 
81
81
  @channel = ::Istox::BunnyBoot.channel
82
82
 
83
- @channel.confirm_select
83
+ # @channel.confirm_select
84
84
 
85
85
  @channel
86
86
  end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.118'.freeze
2
+ VERSION = '0.1.119-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.1.118
4
+ version: 0.1.119.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: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-02-14 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: '0'
416
+ version: 1.3.1
417
417
  requirements: []
418
418
  rubygems_version: 3.0.6
419
419
  signing_key: