istox 0.1.119 → 0.1.120.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: d369f69df949441ab14c3fac0c794b92d17d5fe3a6c5a54859fddecf530eb6c8
4
- data.tar.gz: 0c588144bc9be77609880360723f28e7db90764d46eb12063ad57c0d8c497649
3
+ metadata.gz: d7115c09fd48a24d96b6a7018f3cfc0cd1f83ea98ba6eae8515f935148fa39cb
4
+ data.tar.gz: 77b3be7bc1d761ba51141dabc8677793b001c4fedde9b1c7b11900aa724938ed
5
5
  SHA512:
6
- metadata.gz: f152ebf349268814c9a1dcd73fd9a59475b22d2f55d014afd3e5917c99ac59eb5346129c205ed9d2aecc315cd7ae897caf58a1dd4fa7bf81fbb1e565effda6e4
7
- data.tar.gz: 57d185c7104b0a6b7eebc2155c226e8ff3fcc786f19ce99c236b8417db76a9f77e8dd4b846a084b89676313f963661f30f560960c552d9efb75999b3e074c6a8
6
+ metadata.gz: fddbc0a6b9471fea4bd53ceb9ce9878e070fddd715b567bbde9e33e9661ce8b1763e9f4c6e75f7d031d784fb96938e6cc539d38a72e14193f8ec22cece7b5a22
7
+ data.tar.gz: 47afe434053f98ce27cea5088b15522df50ecdbbf12e230845b62d8d1ceda67fb52f1d24e9f86fa972d65cb52b00db6cf59b5e104fe4716d7357659434bc4fda
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)
@@ -37,8 +37,9 @@ module Istox
37
37
  # <more other sample template attributes>: <other sample template data>,
38
38
  # }]
39
39
  def sms_template(template_name, template_data_arr)
40
- raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil? ||
41
- template_data_arr.empty?
40
+ raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil?
41
+
42
+ return log.info 'Template data is empty, skipping this request' if template_data_arr.empty?
42
43
 
43
44
  ::Istox::Publisher.manual_publish(
44
45
  exchange: 'message',
@@ -101,8 +102,9 @@ module Istox
101
102
  # base64: "<Base64 of the file>"
102
103
  # }]
103
104
  def email_template(template_name, template_data_arr, attachments: nil)
104
- raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil? ||
105
- template_data_arr.empty?
105
+ raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil?
106
+
107
+ return log.info 'Template data is empty, skipping this request' if template_data_arr.empty?
106
108
 
107
109
  ::Istox::Publisher.manual_publish(
108
110
  exchange: 'message',
@@ -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
 
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.119'.freeze
2
+ VERSION = '0.1.120-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.119
4
+ version: 0.1.120.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-14 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: