From 67c651567b734bb3b72719d63c31e1acf559d378 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 7 Aug 2024 13:57:14 +0800 Subject: [PATCH 1/3] Issue 759 (#2122) * feat: handle single use lock tag Signed-off-by: Miles Zhang * feat: token collection suspicious tag not include chinese Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/models/ckb_sync/api.rb | 4 ++++ app/models/token_collection.rb | 2 +- app/workers/token_collection_tag_worker.rb | 11 +++++++++-- app/workers/xudt_tag_worker.rb | 7 +++++++ config/settings.mainnet.yml | 2 ++ config/settings.testnet.yml | 2 ++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/models/ckb_sync/api.rb b/app/models/ckb_sync/api.rb index 1cf7674dd..ecbe2aa26 100644 --- a/app/models/ckb_sync/api.rb +++ b/app/models/ckb_sync/api.rb @@ -119,6 +119,10 @@ def btc_time_code_hash Settings.btc_time_code_hash end + def single_use_lock_code_hash + Settings.single_use_lock_code_hash + end + METHOD_NAMES.each do |name| define_method name do |*params| call_rpc(name, params:) diff --git a/app/models/token_collection.rb b/app/models/token_collection.rb index 3bff9f90e..331bb4ae5 100644 --- a/app/models/token_collection.rb +++ b/app/models/token_collection.rb @@ -1,5 +1,5 @@ class TokenCollection < ApplicationRecord - VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "layer-2-asset"] + VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "layer-2-asset", "supply-limited"] enum standard: { cota: "cota", spore: "spore", m_nft: "m_nft", nrc721: "nrc721" } diff --git a/app/workers/token_collection_tag_worker.rb b/app/workers/token_collection_tag_worker.rb index e30b00525..7d05e86d8 100644 --- a/app/workers/token_collection_tag_worker.rb +++ b/app/workers/token_collection_tag_worker.rb @@ -21,6 +21,8 @@ def mark_tags(token_collection) ["suspicious"] elsif out_of_length?(token_collection.name) ["out-of-length-range"] + elsif single_use_lock?(token_collection.creator.address_hash) + ["supply-limited"] elsif rgbpp_lock?(token_collection.creator.address_hash) ["rgb++", "layer-1-asset"] else @@ -29,11 +31,11 @@ def mark_tags(token_collection) end def invalid_char?(name) - !name.ascii_only? + !name.ascii_only? && (name =~ /^[\u4E00-\u9FFF]+$/).nil? end def invisible_char?(name) - (name =~ /^[\x21-\x7E]+(?:\s[\x21-\x7E]+)?$/).nil? + (name =~ /^[\x21-\x7E\u4E00-\u9FFF]+(?:\s[\x21-\x7E\u4E00-\u9FFF]+)?$/).nil? end def out_of_length?(name) @@ -48,4 +50,9 @@ def rgbpp_lock?(issuer_address) address_code_hash = CkbUtils.parse_address(issuer_address).script.code_hash issuer_address.present? && CkbSync::Api.instance.rgbpp_code_hash.include?(address_code_hash) end + + def single_use_lock?(issuer_address) + address_script = CkbUtils.parse_address(issuer_address).script + issuer_address.present? && CkbSync::Api.instance.single_use_lock_code_hash == address_script.code_hash && address_script.hash_type == "data1" + end end diff --git a/app/workers/xudt_tag_worker.rb b/app/workers/xudt_tag_worker.rb index cb0b25bd2..be35c1be8 100644 --- a/app/workers/xudt_tag_worker.rb +++ b/app/workers/xudt_tag_worker.rb @@ -28,6 +28,8 @@ def mark_tags(udt) ["utility"] elsif !first_xudt?(udt.symbol, udt.block_timestamp) ["suspicious"] + elsif single_use_lock?(udt.issuer_address) + ["supply-limited"] elsif rgbpp_lock?(udt.issuer_address) ["rgb++", "layer-1-asset", "supply-limited"] else @@ -56,6 +58,11 @@ def rgbpp_lock?(issuer_address) issuer_address.present? && CkbSync::Api.instance.rgbpp_code_hash.include?(address_code_hash) end + def single_use_lock?(issuer_address) + address_script = CkbUtils.parse_address(issuer_address).script + issuer_address.present? && CkbSync::Api.instance.single_use_lock_code_hash == address_script.code_hash && address_script.hash_type == "data1" + end + def utility_lp_token?(args) args.length == 74 end diff --git a/config/settings.mainnet.yml b/config/settings.mainnet.yml index 52583dd77..1e47acde2 100644 --- a/config/settings.mainnet.yml +++ b/config/settings.mainnet.yml @@ -86,3 +86,5 @@ rgbpp_code_hash: # btc time code hash btc_time_code_hash: - "0x70d64497a075bd651e98ac030455ea200637ee325a12ad08aff03f1a117e5a62" + +single_use_lock_code_hash: "0x8290467a512e5b9a6b816469b0edabba1f4ac474e28ffdd604c2a7c76446bbaf" diff --git a/config/settings.testnet.yml b/config/settings.testnet.yml index 8cfbd8363..7126e4b5b 100644 --- a/config/settings.testnet.yml +++ b/config/settings.testnet.yml @@ -92,3 +92,5 @@ rgbpp_code_hash: btc_time_code_hash: - "0x00cdf8fab0f8ac638758ebf5ea5e4052b1d71e8a77b9f43139718621f6849326" - "0x80a09eca26d77cea1f5a69471c59481be7404febf40ee90f886c36a948385b55" + +single_use_lock_code_hash: "0x8290467a512e5b9a6b816469b0edabba1f4ac474e28ffdd604c2a7c76446bbaf" From fd8cfd98160e9f248f68b9792d5dc0bebb8dcc4e Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 8 Aug 2024 15:38:37 +0800 Subject: [PATCH 2/3] fix: yesterday_treasury_amount may be 0 when it generated by schedule (#2125) Signed-off-by: Miles Zhang --- app/models/market_data.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/models/market_data.rb b/app/models/market_data.rb index 338b8bf68..5d71baf9e 100644 --- a/app/models/market_data.rb +++ b/app/models/market_data.rb @@ -86,11 +86,11 @@ def parsed_dao end def total_supply - if current_timestamp > first_released_timestamp_may - result = parsed_dao.c_i - BURN_QUOTA - yesterday_treasury_amount.to_i - else - result = parsed_dao.c_i - BURN_QUOTA - end + result = if current_timestamp > first_released_timestamp_may + parsed_dao.c_i - BURN_QUOTA - yesterday_treasury_amount.to_i + else + parsed_dao.c_i - BURN_QUOTA + end unit == "ckb" ? (result / 10**8).truncate(8) : result end @@ -104,11 +104,9 @@ def circulating_supply # 2020-05-01 def first_released_timestamp_may @first_released_timestamp_may ||= - begin - Rails.cache.realize("first_released_timestamp_may") do - lock_address = Address.find_by_address_hash("ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn323t90gna20lusyshreg32qee4fhkt9jj2t6qrqzzqxzq8yqt8kmd9") - lock_address.present? ? lock_address.lock_script.lock_info[:estimated_unlock_time].to_i : CkbUtils.time_in_milliseconds(Time.find_zone("UTC").parse("2020-05-01")) - end + Rails.cache.realize("first_released_timestamp_may") do + lock_address = Address.find_by_address_hash("ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn323t90gna20lusyshreg32qee4fhkt9jj2t6qrqzzqxzq8yqt8kmd9") + lock_address.present? ? lock_address.lock_script.lock_info[:estimated_unlock_time].to_i : CkbUtils.time_in_milliseconds(Time.find_zone("UTC").parse("2020-05-01")) end end @@ -133,11 +131,9 @@ def third_released_timestamp_may # 2020-07-01 def first_released_timestamp_other @first_released_timestamp_other ||= - begin - Rails.cache.realize("first_released_timestamp_may") do - lock_address = Address.find_by_address_hash("ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32s3y29vjv73cfm8qax220dwwmpdccl4upy4s9qzzqxzq8yqyd09am") - lock_address.present? ? lock_address.lock_script.lock_info[:estimated_unlock_time].to_i : CkbUtils.time_in_milliseconds(Time.find_zone("UTC").parse("2020-07-01")) - end + Rails.cache.realize("first_released_timestamp_may") do + lock_address = Address.find_by_address_hash("ckb1q3w9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32s3y29vjv73cfm8qax220dwwmpdccl4upy4s9qzzqxzq8yqyd09am") + lock_address.present? ? lock_address.lock_script.lock_info[:estimated_unlock_time].to_i : CkbUtils.time_in_milliseconds(Time.find_zone("UTC").parse("2020-07-01")) end end @@ -160,6 +156,7 @@ def third_released_timestamp_other end def yesterday_treasury_amount - DailyStatistic.order(:created_at_unixtimestamp).last.treasury_amount + treasury_amounts = DailyStatistic.order(created_at_unixtimestamp: :desc).first(2).pluck(:treasury_amount) + treasury_amounts[0] == "0" ? treasury_amounts[1] : treasury_amounts[0] end end From 754bd3d9181ac10001c85d19d960d7b0966d94e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:40:09 +0800 Subject: [PATCH 3/3] chore(deps-dev): bump rexml from 3.2.8 to 3.3.3 (#2110) Bumps [rexml](https://github.com/ruby/rexml) from 3.2.8 to 3.3.3. - [Release notes](https://github.com/ruby/rexml/releases) - [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md) - [Commits](https://github.com/ruby/rexml/compare/v3.2.8...v3.3.3) --- updated-dependencies: - dependency-name: rexml dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a4d79ce5f..7cad15742 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -403,8 +403,8 @@ GEM redis-objects (2.0.0.beta) redis (~> 5.0) regexp_parser (2.7.0) - rexml (3.2.8) - strscan (>= 3.0.9) + rexml (3.3.3) + strscan rubocop (1.50.1) json (~> 2.3) parallel (~> 1.10)