istox 0.1.81.pre.test8 → 0.1.81.pre.test9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/istox/helpers/blockchain_service.rb +0 -2
- data/lib/istox/helpers/order_book.rb +68 -40
- data/lib/istox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709e450a6f5c8ae8a44d8c52eb7cedaece6a4cafde0761e198dad80308b3af01
|
4
|
+
data.tar.gz: b6db801e20945d448e1b90fb8aa32d073b39c5fed7e97e9095cecaaca1958d48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69491f982e218c130936029d47601d330f25e8103020b358f53712edcbf76653a4b341669065c24a6a162d14a0ef9bf32adff5f45de9e0267c53e50151a3fd67
|
7
|
+
data.tar.gz: 06b3580527d154aae956e09102e19bb4db4b9473e32c9be4b60e6892b903dfa817c7b264f4f7d7b2507d1333499a97128c6f0194c5bfa011e4ad1b81fd615312
|
data/Gemfile.lock
CHANGED
@@ -34,8 +34,6 @@ module Istox
|
|
34
34
|
# execute before proc, and get the model that blockchain receipt should bind to
|
35
35
|
model = before.call(uuid)
|
36
36
|
|
37
|
-
puts model
|
38
|
-
|
39
37
|
# delete the previous existing blockchain receipts
|
40
38
|
klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
|
41
39
|
|
@@ -2,7 +2,6 @@ module Istox
|
|
2
2
|
class OrderBook
|
3
3
|
class << self
|
4
4
|
def allocation(soft_cap, total_supply, investments)
|
5
|
-
|
6
5
|
# sort by token price desc, and id asc
|
7
6
|
investments = investments.sort do |a, b|
|
8
7
|
[b[:token_price], a[:id]] <=> [a[:token_price], b[:id]]
|
@@ -11,50 +10,79 @@ module Istox
|
|
11
10
|
total_supply = ::BigDecimal.new(total_supply.to_s)
|
12
11
|
|
13
12
|
interests = investments
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
is_cutoff = false
|
13
|
+
cutoff_price = 0.0
|
14
|
+
total_bid_token = 0.0
|
15
|
+
total_allocated = 0.0
|
16
|
+
total_unallocated = 0.0
|
17
|
+
total_investment = 0.0
|
18
|
+
cutoff_price = ::Istox::FMath.div(soft_cap, total_supply)
|
19
|
+
is_cutoff = false
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
# return result immediately if no interest
|
22
|
+
unless interests.count.positive?
|
23
|
+
return { total_supply: total_supply.to_s, total_investment: '0',
|
24
|
+
cutoff_price: cutoff_price, total_bid_token: '0',
|
25
|
+
total_allocated: '0', total_unallocated: total_supply.to_s,
|
26
|
+
interests: [] }
|
27
|
+
end
|
28
|
+
|
29
|
+
interests = interests.map do |item|
|
30
|
+
bid_token = ::Istox::FMath.div(item[:fiat_amount], item[:token_price])
|
31
|
+
total_bid_token = ::Istox::FMath.add(total_bid_token, bid_token)
|
32
|
+
allocated = 0.0
|
33
|
+
unallocated = bid_token
|
34
|
+
unless is_cutoff
|
35
|
+
allocated = bid_token
|
36
|
+
unallocated = 0.0
|
37
|
+
if ::BigDecimal.new(::Istox::FMath.add(total_allocated, bid_token)) >= total_supply
|
38
|
+
unallocated = ::Istox::FMath.sub(::Istox::FMath.add(total_allocated, bid_token), total_supply)
|
39
|
+
allocated = ::Istox::FMath.sub(bid_token, unallocated)
|
40
|
+
cutoff_price = item[:token_price]
|
41
|
+
is_cutoff = true
|
39
42
|
end
|
40
|
-
|
41
|
-
|
43
|
+
total_allocated = ::Istox::FMath.add(total_allocated, allocated)
|
44
|
+
total_unallocated = ::Istox::FMath.add(total_unallocated, unallocated)
|
42
45
|
end
|
46
|
+
{
|
47
|
+
id: item[:id],
|
48
|
+
# user bidding total fiat amount
|
49
|
+
fiat_amount: item[:fiat_amount],
|
50
|
+
# user bidding price
|
51
|
+
bid_price: item[:token_price],
|
52
|
+
# total user bidding token derived from fiat_amount / token_price
|
53
|
+
bid_token: bid_token,
|
54
|
+
# round down allocated token to whole number
|
55
|
+
allocated: ::Istox::FMath.round_down(allocated, 0),
|
56
|
+
# round up unallocated token to whole number
|
57
|
+
unallocated: ::Istox::FMath.round_up(unallocated, 0)
|
58
|
+
}
|
59
|
+
end
|
43
60
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return { total_supply: total_supply, total_investment: total_investment,
|
51
|
-
cutoff_price: cutoff_price, total_bid_token: total_bid_token,
|
52
|
-
total_allocated: total_allocated, total_unallocated: total_unallocated,
|
53
|
-
interests: interests }
|
54
|
-
else
|
55
|
-
raise 'Registration interest is empty'
|
61
|
+
interests = interests.map do |item|
|
62
|
+
investment = ::Istox::FMath.mul(item[:allocated], cutoff_price)
|
63
|
+
total_investment = ::Istox::FMath.add(total_investment, investment)
|
64
|
+
|
65
|
+
# each user maximum total investment amount in fiat
|
66
|
+
item.merge!(investment: investment)
|
56
67
|
end
|
68
|
+
|
69
|
+
{
|
70
|
+
# total token supply
|
71
|
+
total_supply: total_supply.to_s,
|
72
|
+
# total investment in fiat
|
73
|
+
total_investment: total_investment,
|
74
|
+
# cut off price
|
75
|
+
cutoff_price: cutoff_price.to_s,
|
76
|
+
# total bid tokens, more than total supply for oversubscribe case
|
77
|
+
total_bid_token: total_bid_token,
|
78
|
+
# total allocated tokens
|
79
|
+
total_allocated: total_allocated,
|
80
|
+
# total unallocated tokens
|
81
|
+
total_unallocated: total_unallocated,
|
82
|
+
# all investor interest results
|
83
|
+
interests: interests
|
84
|
+
}
|
57
85
|
end
|
58
86
|
end
|
59
87
|
end
|
60
|
-
end
|
88
|
+
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.1.81.pre.
|
4
|
+
version: 0.1.81.pre.test9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|