openreceive-server 0.2.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 +7 -0
- data/CHANGELOG.md +24 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/lib/openreceive/server/client_ip.rb +73 -0
- data/lib/openreceive/server/config.rb +46 -0
- data/lib/openreceive/server/errors.rb +221 -0
- data/lib/openreceive/server/lsc_uri.rb +104 -0
- data/lib/openreceive/server/rack_app.rb +92 -0
- data/lib/openreceive/server/reconciliation.rb +55 -0
- data/lib/openreceive/server/request_handler.rb +598 -0
- data/lib/openreceive/server/service.rb +775 -0
- data/lib/openreceive/server/swap/assets.rb +88 -0
- data/lib/openreceive/server/swap/fixedfloat.rb +831 -0
- data/lib/openreceive/server/swap/rates_feed.rb +311 -0
- data/lib/openreceive/server/swap/transient_cache.rb +106 -0
- data/lib/openreceive/server/swap/weight_budget.rb +115 -0
- data/lib/openreceive/server/swap.rb +141 -0
- data/lib/openreceive/server/version.rb +7 -0
- data/lib/openreceive/server/wallet_info.rb +69 -0
- data/lib/openreceive/server.rb +39 -0
- metadata +83 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "openreceive"
|
|
4
|
+
|
|
5
|
+
module OpenReceive
|
|
6
|
+
module Server
|
|
7
|
+
module Swap
|
|
8
|
+
# Ruby port of packages/js/node/src/swap/assets.ts: the OpenReceive
|
|
9
|
+
# pay-in asset catalog (labels, network labels, provider matching) and
|
|
10
|
+
# the network helpers the FixedFloat provider uses to map /ccies rows.
|
|
11
|
+
module Assets
|
|
12
|
+
PAY_IN_ASSETS = %w[
|
|
13
|
+
SOL_SOL USDT_TRON USDT_SOL USDC_SOL ETH_ETH USDT_ETH USDC_ETH
|
|
14
|
+
].freeze
|
|
15
|
+
|
|
16
|
+
ASSET_INFO = {
|
|
17
|
+
"SOL_SOL" => {
|
|
18
|
+
"pay_in_asset" => "SOL_SOL", "label" => "SOL", "network_label" => "Solana",
|
|
19
|
+
"coin" => "SOL", "network" => "SOL"
|
|
20
|
+
}.freeze,
|
|
21
|
+
"USDT_TRON" => {
|
|
22
|
+
"pay_in_asset" => "USDT_TRON", "label" => "USDT", "network_label" => "Tron",
|
|
23
|
+
"coin" => "USDT", "network" => "TRX"
|
|
24
|
+
}.freeze,
|
|
25
|
+
"USDT_SOL" => {
|
|
26
|
+
"pay_in_asset" => "USDT_SOL", "label" => "USDT", "network_label" => "Solana",
|
|
27
|
+
"coin" => "USDT", "network" => "SOL"
|
|
28
|
+
}.freeze,
|
|
29
|
+
"USDC_SOL" => {
|
|
30
|
+
"pay_in_asset" => "USDC_SOL", "label" => "USDC", "network_label" => "Solana",
|
|
31
|
+
"coin" => "USDC", "network" => "SOL"
|
|
32
|
+
}.freeze,
|
|
33
|
+
"ETH_ETH" => {
|
|
34
|
+
"pay_in_asset" => "ETH_ETH", "label" => "ETH", "network_label" => "Ethereum",
|
|
35
|
+
"coin" => "ETH", "network" => "ETH"
|
|
36
|
+
}.freeze,
|
|
37
|
+
"USDT_ETH" => {
|
|
38
|
+
"pay_in_asset" => "USDT_ETH", "label" => "USDT", "network_label" => "Ethereum",
|
|
39
|
+
"coin" => "USDT", "network" => "ETH"
|
|
40
|
+
}.freeze,
|
|
41
|
+
"USDC_ETH" => {
|
|
42
|
+
"pay_in_asset" => "USDC_ETH", "label" => "USDC", "network_label" => "Ethereum",
|
|
43
|
+
"coin" => "USDC", "network" => "ETH"
|
|
44
|
+
}.freeze
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
module_function
|
|
48
|
+
|
|
49
|
+
def pay_in_asset?(value)
|
|
50
|
+
value.is_a?(String) && PAY_IN_ASSETS.include?(value)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def info(pay_in_asset)
|
|
54
|
+
ASSET_INFO.fetch(pay_in_asset)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def list_info
|
|
58
|
+
PAY_IN_ASSETS.map { |asset| ASSET_INFO.fetch(asset) }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def normalize_network(value)
|
|
62
|
+
value.to_s.upcase.gsub(/[^A-Z0-9]+/, "")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def network_matches?(expected, actual)
|
|
66
|
+
normalized_expected = normalize_network(expected)
|
|
67
|
+
normalized_actual = normalize_network(actual)
|
|
68
|
+
return true if normalized_actual == normalized_expected
|
|
69
|
+
|
|
70
|
+
case normalized_expected
|
|
71
|
+
when "TRX"
|
|
72
|
+
%w[TRON TRC20 TRC].include?(normalized_actual)
|
|
73
|
+
when "ETH"
|
|
74
|
+
%w[ETHEREUM ERC20 ERC].include?(normalized_actual)
|
|
75
|
+
when "SOL"
|
|
76
|
+
normalized_actual == "SOLANA"
|
|
77
|
+
else
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def lightning_network?(value)
|
|
83
|
+
%w[LN LIGHTNING LIGHTNINGNETWORK BTCLN BTCBOLT11].include?(normalize_network(value))
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|