Module: OpenReceive::Server::Swap::Assets

Defined in:
lib/openreceive/server/swap/assets.rb

Overview

Ruby port of packages/js/node/src/swap/assets.ts: the OpenReceive pay-in asset catalog (labels, network labels, provider matching) and the network helpers the FixedFloat provider uses to map /ccies rows.

Constant Summary collapse

PAY_IN_ASSETS =
%w[
  SOL_SOL USDT_TRON USDT_SOL USDC_SOL ETH_ETH USDT_ETH USDC_ETH
].freeze
ASSET_INFO =
{
  "SOL_SOL" => {
    "pay_in_asset" => "SOL_SOL", "label" => "SOL", "network_label" => "Solana",
    "coin" => "SOL", "network" => "SOL"
  }.freeze,
  "USDT_TRON" => {
    "pay_in_asset" => "USDT_TRON", "label" => "USDT", "network_label" => "Tron",
    "coin" => "USDT", "network" => "TRX"
  }.freeze,
  "USDT_SOL" => {
    "pay_in_asset" => "USDT_SOL", "label" => "USDT", "network_label" => "Solana",
    "coin" => "USDT", "network" => "SOL"
  }.freeze,
  "USDC_SOL" => {
    "pay_in_asset" => "USDC_SOL", "label" => "USDC", "network_label" => "Solana",
    "coin" => "USDC", "network" => "SOL"
  }.freeze,
  "ETH_ETH" => {
    "pay_in_asset" => "ETH_ETH", "label" => "ETH", "network_label" => "Ethereum",
    "coin" => "ETH", "network" => "ETH"
  }.freeze,
  "USDT_ETH" => {
    "pay_in_asset" => "USDT_ETH", "label" => "USDT", "network_label" => "Ethereum",
    "coin" => "USDT", "network" => "ETH"
  }.freeze,
  "USDC_ETH" => {
    "pay_in_asset" => "USDC_ETH", "label" => "USDC", "network_label" => "Ethereum",
    "coin" => "USDC", "network" => "ETH"
  }.freeze
}.freeze

Class Method Summary collapse

Class Method Details

.info(pay_in_asset) ⇒ Object



53
54
55
# File 'lib/openreceive/server/swap/assets.rb', line 53

def info(pay_in_asset)
  ASSET_INFO.fetch(pay_in_asset)
end

.lightning_network?(value) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/openreceive/server/swap/assets.rb', line 82

def lightning_network?(value)
  %w[LN LIGHTNING LIGHTNINGNETWORK BTCLN BTCBOLT11].include?(normalize_network(value))
end

.list_infoObject



57
58
59
# File 'lib/openreceive/server/swap/assets.rb', line 57

def list_info
  PAY_IN_ASSETS.map { |asset| ASSET_INFO.fetch(asset) }
end

.network_matches?(expected, actual) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/openreceive/server/swap/assets.rb', line 65

def network_matches?(expected, actual)
  normalized_expected = normalize_network(expected)
  normalized_actual = normalize_network(actual)
  return true if normalized_actual == normalized_expected

  case normalized_expected
  when "TRX"
    %w[TRON TRC20 TRC].include?(normalized_actual)
  when "ETH"
    %w[ETHEREUM ERC20 ERC].include?(normalized_actual)
  when "SOL"
    normalized_actual == "SOLANA"
  else
    false
  end
end

.normalize_network(value) ⇒ Object



61
62
63
# File 'lib/openreceive/server/swap/assets.rb', line 61

def normalize_network(value)
  value.to_s.upcase.gsub(/[^A-Z0-9]+/, "")
end

.pay_in_asset?(value) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/openreceive/server/swap/assets.rb', line 49

def pay_in_asset?(value)
  value.is_a?(String) && PAY_IN_ASSETS.include?(value)
end