Class: Launchpad::IEO::Sale
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Launchpad::IEO::Sale
- Includes:
- AASM
- Defined in:
- app/models/launchpad/ieo/sale.rb
Overview
TODO: We need to validate that currency exists on peatio side on sale creation step.
Constant Summary collapse
- RESULTS =
%w[nothing listing].freeze
- PUBLIC_STATES =
%w[preparing cancelled ongoing refunding distributing finished].freeze
- EDITABLE_STATES =
{draft: %w[name description owner_uid currency_id supply low_goal commission min_amount max_amount min_unit result starts_at finishes_at], preparing: %w[name description starts_at finishes_at], ongoing: %w[finishes_at]}.freeze
- TYPES =
fcfs - First Come, First Served algorithm.
%w[fcfs proportional].freeze
- FEES_POLICY =
subtract - contribution * fees add - contribution + contribution * fees
%w[subtract add].freeze
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
- #fees_policy ⇒ Object
-
#full? ⇒ Boolean
Finish fcfs sale when all tokens + min possible amount will be greater than total sale supply\ since it means that user would not be able to buy anymore.
- #list_currency ⇒ Object
- #notify_ranger ⇒ Object
- #ratio ⇒ Object
- #result ⇒ Object
- #sales_to_json ⇒ Object
-
#tokens_ordered(ndigits: Launchpad::IEO::TOKENS_AMOUNT_PRECISION) ⇒ Object
(also: #collected_amount)
Instance Methods =====================================================.
- #type ⇒ Object
Instance Method Details
#as_json(_options = {}) ⇒ Object
273 274 275 |
# File 'app/models/launchpad/ieo/sale.rb', line 273 def as_json(={}) super(include: :pairs, methods: %i[collected_amount tokens_ordered ratio]) end |
#fees_policy ⇒ Object
269 270 271 |
# File 'app/models/launchpad/ieo/sale.rb', line 269 def fees_policy super&.inquiry end |
#full? ⇒ Boolean
Finish fcfs sale when all tokens + min possible amount will be greater than total sale supply\ since it means that user would not be able to buy anymore.
257 258 259 |
# File 'app/models/launchpad/ieo/sale.rb', line 257 def full? tokens_ordered + min_amount >= supply end |
#list_currency ⇒ Object
281 282 283 284 285 286 |
# File 'app/models/launchpad/ieo/sale.rb', line 281 def list_currency Peatio::ManagementAPIV2::Client.new.update_currency( id: currency_id, visible: true ) end |
#notify_ranger ⇒ Object
277 278 279 |
# File 'app/models/launchpad/ieo/sale.rb', line 277 def notify_ranger Peatio::MQ::Events.publish("public", "ieo", "tickers", sale: as_json) end |
#ratio ⇒ Object
251 252 253 |
# File 'app/models/launchpad/ieo/sale.rb', line 251 def ratio (collected_amount / supply).round(Launchpad::IEO::RATIO_PRECISION, BigDecimal::ROUND_DOWN) end |
#result ⇒ Object
265 266 267 |
# File 'app/models/launchpad/ieo/sale.rb', line 265 def result super&.inquiry end |
#sales_to_json ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'app/models/launchpad/ieo/sale.rb', line 288 def sales_to_json attributes.merge!( collected_amount: collected_amount, tokens_ordered: tokens_ordered, ratio: ratio, pairs: pairs.as_json ) end |
#tokens_ordered(ndigits: Launchpad::IEO::TOKENS_AMOUNT_PRECISION) ⇒ Object Also known as: collected_amount
Instance Methods =====================================================
240 241 242 243 244 245 246 |
# File 'app/models/launchpad/ieo/sale.rb', line 240 def tokens_ordered(ndigits: Launchpad::IEO::TOKENS_AMOUNT_PRECISION) if type.proportional? orders.executable.tokens_ordered(ndigits: ndigits) elsif type.fcfs? orders.active_and_prepared_and_completed.tokens_ordered(ndigits: ndigits) end end |
#type ⇒ Object
261 262 263 |
# File 'app/models/launchpad/ieo/sale.rb', line 261 def type super&.inquiry end |