@gardenfi/orderbook 3.1.2 → 3.1.3
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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +35 -33
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +29 -186
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +138 -157
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +203 -27
- package/dist/index13.cjs +1 -0
- package/dist/index13.js +31 -0
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +1 -1
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +54 -28
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/ExplorerUrlBuilder/ExplorerUrlBuilder.d.ts +13 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index2.cjs"),n=require("./index3.cjs"),e=require("./index4.cjs"),t=require("./index5.cjs"),o=require("./index6.cjs"),s=require("./index7.cjs"),a=require("./index8.cjs"),l=require("./index9.cjs"),r=require("./index10.cjs"),c=require("./index11.cjs"),d=require("./index12.cjs");exports.Orderbook=i.Orderbook;exports.BlockchainType=n.BlockchainType;exports.Assets=e.Assets;exports.Chains=e.Chains;exports.Config=e.Config;exports.NATIVE_TOKENS=e.NATIVE_TOKENS;exports.OrderLifecycle=e.OrderLifecycle;exports.OrderStatus=e.OrderStatus;exports.getBlockchainType=e.getBlockchainType;exports.is=e.is;exports.isAlpenSignet=e.isAlpenSignet;exports.isBitcoin=e.isBitcoin;exports.isEVM=e.isEVM;exports.isEvmNativeToken=e.isEvmNativeToken;exports.isLitecoin=e.isLitecoin;exports.isMainnet=e.isMainnet;exports.isNativeToken=e.isNativeToken;exports.isSolana=e.isSolana;exports.isSolanaNativeToken=e.isSolanaNativeToken;exports.isSpark=e.isSpark;exports.isStarknet=e.isStarknet;exports.isSui=e.isSui;exports.isSuiNativeToken=e.isSuiNativeToken;exports.isTron=e.isTron;exports.isXrpl=e.isXrpl;exports.ArbitrumLocalnet=t.ArbitrumLocalnet;exports.ETHStarknetLocalnetAsset=t.ETHStarknetLocalnetAsset;exports.EthereumLocalnet=t.EthereumLocalnet;exports.SOLSolanaLocalnetAsset=t.SOLSolanaLocalnetAsset;exports.STRKStarknetLocalnetAsset=t.STRKStarknetLocalnetAsset;exports.StarknetLocalnet=t.StarknetLocalnet;exports.WBTCArbitrumLocalnetAsset=t.WBTCArbitrumLocalnetAsset;exports.WBTCEthereumLocalnetAsset=t.WBTCEthereumLocalnetAsset;exports.bitcoinRegtestAsset=t.bitcoinRegtestAsset;exports.buildAssetsWithChain=o.buildAssetsWithChain;exports.ConstructUrl=s.ConstructUrl;exports.discriminateOrderResponse=s.discriminateOrderResponse;exports.getOrderResponseType=s.getOrderResponseType;exports.isBitcoinOrderResponse=s.isBitcoinOrderResponse;exports.isEvmOrderResponse=s.isEvmOrderResponse;exports.isOrder=s.isOrder;exports.isSolanaOrderResponse=s.isSolanaOrderResponse;exports.isStarknetOrderResponse=s.isStarknetOrderResponse;exports.isSuiOrderResponse=s.isSuiOrderResponse;exports.isXrplOrderResponse=s.isXrplOrderResponse;exports.ChainAsset=a.ChainAsset;exports.ExplorerUrlBuilder=l.ExplorerUrlBuilder;exports.OrderAction=r.OrderAction;exports.ParseOrderStatus=r.ParseOrderStatus;exports.isCompleted=r.isCompleted;exports.isDeadlinePassed=r.isDeadlinePassed;exports.parseAction=r.parseAction;exports.AssetManager=c.AssetManager;exports.RouteValidator=d.RouteValidator;
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { BlockchainType as
|
|
3
|
-
import { Assets as n, Chains as a, Config as p, NATIVE_TOKENS as l, OrderLifecycle as c, OrderStatus as d, getBlockchainType as
|
|
4
|
-
import { ArbitrumLocalnet as b, ETHStarknetLocalnetAsset as y, EthereumLocalnet as M, SOLSolanaLocalnetAsset as V, STRKStarknetLocalnetAsset as W, StarknetLocalnet as K, WBTCArbitrumLocalnetAsset as P, WBTCEthereumLocalnetAsset as
|
|
5
|
-
import { buildAssetsWithChain as
|
|
1
|
+
import { Orderbook as s } from "./index2.js";
|
|
2
|
+
import { BlockchainType as o } from "./index3.js";
|
|
3
|
+
import { Assets as n, Chains as a, Config as p, NATIVE_TOKENS as l, OrderLifecycle as c, OrderStatus as d, getBlockchainType as m, is as S, isAlpenSignet as A, isBitcoin as O, isEVM as T, isEvmNativeToken as f, isLitecoin as k, isMainnet as u, isNativeToken as x, isSolana as L, isSolanaNativeToken as R, isSpark as E, isStarknet as h, isSui as C, isSuiNativeToken as B, isTron as g, isXrpl as v } from "./index4.js";
|
|
4
|
+
import { ArbitrumLocalnet as b, ETHStarknetLocalnetAsset as y, EthereumLocalnet as M, SOLSolanaLocalnetAsset as V, STRKStarknetLocalnetAsset as W, StarknetLocalnet as K, WBTCArbitrumLocalnetAsset as P, WBTCEthereumLocalnetAsset as U, bitcoinRegtestAsset as X } from "./index5.js";
|
|
5
|
+
import { buildAssetsWithChain as H } from "./index6.js";
|
|
6
6
|
import { ConstructUrl as _, discriminateOrderResponse as j, getOrderResponseType as q, isBitcoinOrderResponse as w, isEvmOrderResponse as z, isOrder as F, isSolanaOrderResponse as G, isStarknetOrderResponse as J, isSuiOrderResponse as Q, isXrplOrderResponse as Y } from "./index7.js";
|
|
7
7
|
import { ChainAsset as $ } from "./index8.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { ExplorerUrlBuilder as re } from "./index9.js";
|
|
9
|
+
import { OrderAction as te, ParseOrderStatus as oe, isCompleted as ie, isDeadlinePassed as ne, parseAction as ae } from "./index10.js";
|
|
10
|
+
import { AssetManager as le } from "./index11.js";
|
|
11
|
+
import { RouteValidator as de } from "./index12.js";
|
|
11
12
|
export {
|
|
12
13
|
b as ArbitrumLocalnet,
|
|
13
|
-
|
|
14
|
+
le as AssetManager,
|
|
14
15
|
n as Assets,
|
|
15
|
-
|
|
16
|
+
o as BlockchainType,
|
|
16
17
|
$ as ChainAsset,
|
|
17
18
|
a as Chains,
|
|
18
19
|
p as Config,
|
|
19
20
|
_ as ConstructUrl,
|
|
20
21
|
y as ETHStarknetLocalnetAsset,
|
|
21
22
|
M as EthereumLocalnet,
|
|
23
|
+
re as ExplorerUrlBuilder,
|
|
22
24
|
l as NATIVE_TOKENS,
|
|
23
|
-
|
|
25
|
+
te as OrderAction,
|
|
24
26
|
c as OrderLifecycle,
|
|
25
27
|
d as OrderStatus,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
s as Orderbook,
|
|
29
|
+
oe as ParseOrderStatus,
|
|
30
|
+
de as RouteValidator,
|
|
29
31
|
V as SOLSolanaLocalnetAsset,
|
|
30
32
|
W as STRKStarknetLocalnetAsset,
|
|
31
33
|
K as StarknetLocalnet,
|
|
32
34
|
P as WBTCArbitrumLocalnetAsset,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
U as WBTCEthereumLocalnetAsset,
|
|
36
|
+
X as bitcoinRegtestAsset,
|
|
37
|
+
H as buildAssetsWithChain,
|
|
36
38
|
j as discriminateOrderResponse,
|
|
37
|
-
|
|
39
|
+
m as getBlockchainType,
|
|
38
40
|
q as getOrderResponseType,
|
|
39
|
-
|
|
41
|
+
S as is,
|
|
40
42
|
A as isAlpenSignet,
|
|
41
43
|
O as isBitcoin,
|
|
42
44
|
w as isBitcoinOrderResponse,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
ie as isCompleted,
|
|
46
|
+
ne as isDeadlinePassed,
|
|
45
47
|
T as isEVM,
|
|
46
|
-
|
|
48
|
+
f as isEvmNativeToken,
|
|
47
49
|
z as isEvmOrderResponse,
|
|
48
|
-
|
|
50
|
+
k as isLitecoin,
|
|
49
51
|
u as isMainnet,
|
|
50
|
-
|
|
52
|
+
x as isNativeToken,
|
|
51
53
|
F as isOrder,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
L as isSolana,
|
|
55
|
+
R as isSolanaNativeToken,
|
|
54
56
|
G as isSolanaOrderResponse,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
E as isSpark,
|
|
58
|
+
h as isStarknet,
|
|
57
59
|
J as isStarknetOrderResponse,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
C as isSui,
|
|
61
|
+
B as isSuiNativeToken,
|
|
60
62
|
Q as isSuiOrderResponse,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
g as isTron,
|
|
64
|
+
v as isXrpl,
|
|
63
65
|
Y as isXrplOrderResponse,
|
|
64
|
-
|
|
66
|
+
ae as parseAction
|
|
65
67
|
};
|
package/dist/index10.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index4.cjs"),u=t=>{const{created_at:n,source_swap:r,destination_swap:d}=t;if(d.redeem_tx_hash)return Number(d.redeem_block_number)||e.isBitcoin(d.chain)?e.OrderStatus.Redeemed:e.OrderStatus.RedeemDetected;if(e.isBitcoin(d.chain)&&r.redeem_tx_hash&&!d.redeem_tx_hash)return e.OrderStatus.Redeemed;if(r.refund_tx_hash)return Number(r.refund_block_number)?e.OrderStatus.Refunded:e.OrderStatus.RefundDetected;if(d.refund_tx_hash)return e.OrderStatus.AwaitingRefund;const a=e.isBitcoin(r.chain)?s(new Date(n),6):s(new Date(n),1);return d.initiate_tx_hash?e.OrderStatus.AwaitingRedeem:r.initiate_tx_hash?a?e.OrderStatus.AwaitingRefund:Number(r.initiate_block_number)?e.OrderStatus.Initiated:e.OrderStatus.InitiateDetected:a?e.OrderStatus.Expired:e.OrderStatus.Created},s=(t,n=1)=>{const r=new Date,d=new Date(t);return d.setHours(d.getHours()+n),r>d},_=t=>{const n=u(t);return n===e.OrderStatus.Redeemed||n===e.OrderStatus.Refunded||n===e.OrderStatus.Expired};var i=(t=>(t.Initiate="Initiate",t.PostRefundSACP="PostRefundSACP",t.Redeem="Redeem",t.Refund="Refund",t.Idle="Idle",t))(i||{});const o=t=>{const{source_swap:n,destination_swap:r}=t;return r.redeem_tx_hash&&Number(r.redeem_block_number)||n.refund_tx_hash&&Number(n.refund_block_number)?"Idle":!r.refund_tx_hash&&r.initiate_tx_hash?"Redeem":"Idle"};exports.OrderAction=i;exports.ParseOrderStatus=u;exports.isCompleted=_;exports.isDeadlinePassed=s;exports.parseAction=o;
|
package/dist/index10.js
CHANGED
|
@@ -1,188 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
async initialize() {
|
|
27
|
-
await this.fetchAndSetAssetsAndChains(), await this.routeValidator.loadPolicy();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fetch and cache asset and chain data from API
|
|
31
|
-
*/
|
|
32
|
-
async fetchAndSetAssetsAndChains() {
|
|
33
|
-
try {
|
|
34
|
-
this.isLoading = !0, this.error = null;
|
|
35
|
-
const t = await this.auth.getAuthHeaders();
|
|
36
|
-
if (!t.ok) return o("Failed to get auth headers");
|
|
37
|
-
const s = await y.get(
|
|
38
|
-
this.urls.assets,
|
|
39
|
-
{
|
|
40
|
-
headers: {
|
|
41
|
-
...t.val
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
if (!s.result) return o(`Failed to fetch chains data: ${s.error}`);
|
|
46
|
-
const { assets: e, chains: a } = this.processApiData(s.result);
|
|
47
|
-
return this.assets = e, this.chains = a, await this.buildRouteMatrix(), g("AssetManager initialized successfully");
|
|
48
|
-
} catch (t) {
|
|
49
|
-
return o(`Failed to fetch assets data: ${t}`);
|
|
50
|
-
} finally {
|
|
51
|
-
this.isLoading = !1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// ============================================
|
|
55
|
-
// Route Validation Methods
|
|
56
|
-
// ============================================
|
|
57
|
-
/**
|
|
58
|
-
* Check if a swap route from one asset to another is valid
|
|
59
|
-
*/
|
|
60
|
-
async isRouteValid(t, s) {
|
|
61
|
-
return await this.routeValidator.isValidRoute(
|
|
62
|
-
r.from(t.id),
|
|
63
|
-
r.from(s.id)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get all valid destination assets for a given source asset
|
|
68
|
-
*/
|
|
69
|
-
getValidDestinations(t) {
|
|
70
|
-
if (!this.routeMatrix || !this.assets || !t.id)
|
|
71
|
-
return console.warn(
|
|
72
|
-
"Missing routeMatrix, assets, or asset. Returning all assets."
|
|
73
|
-
), [];
|
|
74
|
-
const s = this.routeMatrix[t.id.toString().toLowerCase()];
|
|
75
|
-
return s ? s.map((e) => {
|
|
76
|
-
const a = e.toString();
|
|
77
|
-
return Object.values(this.assets).find((i) => r.from(i).toString() === a);
|
|
78
|
-
}).filter(Boolean) : [];
|
|
79
|
-
}
|
|
80
|
-
// ============================================
|
|
81
|
-
// Asset Query Methods
|
|
82
|
-
// ============================================
|
|
83
|
-
/**
|
|
84
|
-
* Get asset by chain and token address
|
|
85
|
-
*/
|
|
86
|
-
getAsset(t) {
|
|
87
|
-
if (!this.assets) return;
|
|
88
|
-
const s = r.from(t).toString();
|
|
89
|
-
return this.assets[s];
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get all assets for a specific chain
|
|
93
|
-
*/
|
|
94
|
-
getAssetsByChain(t) {
|
|
95
|
-
return this.assets ? Object.values(this.assets).filter((s) => s.chain === t) : [];
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Search assets by symbol or name
|
|
99
|
-
*/
|
|
100
|
-
searchAssets(t) {
|
|
101
|
-
if (!this.assets) return [];
|
|
102
|
-
const s = t.toLowerCase();
|
|
103
|
-
return Object.values(this.assets).filter(
|
|
104
|
-
(e) => e.symbol.toLowerCase().includes(s) || e.name.toLowerCase().includes(s)
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get chain data by chain identifier
|
|
109
|
-
*/
|
|
110
|
-
getChain(t) {
|
|
111
|
-
if (this.chains)
|
|
112
|
-
return this.chains[t];
|
|
113
|
-
}
|
|
114
|
-
// ============================================
|
|
115
|
-
// Private Helper Methods
|
|
116
|
-
// ============================================
|
|
117
|
-
/**
|
|
118
|
-
* Build route matrix for fast O(1) route lookups
|
|
119
|
-
*/
|
|
120
|
-
async buildRouteMatrix() {
|
|
121
|
-
if (!this.assets || !this.routeValidator) return;
|
|
122
|
-
const t = Object.values(this.assets).map((s) => {
|
|
123
|
-
if (!s.id) return null;
|
|
124
|
-
try {
|
|
125
|
-
return r.from(s.id);
|
|
126
|
-
} catch {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}).filter((s) => s !== null);
|
|
130
|
-
this.routeMatrix = await this.routeValidator.buildRouteMatrix(
|
|
131
|
-
t
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Process raw API data into structured format
|
|
136
|
-
*/
|
|
137
|
-
processApiData(t) {
|
|
138
|
-
const s = {}, e = {};
|
|
139
|
-
for (const a of t) {
|
|
140
|
-
const i = this.parseChainIdentifier(a.chain);
|
|
141
|
-
if (!i || !c.includes(i))
|
|
142
|
-
continue;
|
|
143
|
-
const h = {
|
|
144
|
-
...a,
|
|
145
|
-
name: a.name || this.formatChainName(i),
|
|
146
|
-
chain: i
|
|
147
|
-
};
|
|
148
|
-
for (const n of a.assets) {
|
|
149
|
-
const d = r.from(n.id).toString(), { name: f, symbol: m } = w(
|
|
150
|
-
n.name,
|
|
151
|
-
n.id
|
|
152
|
-
), p = {
|
|
153
|
-
...n,
|
|
154
|
-
id: r.from(n.id),
|
|
155
|
-
chain: i,
|
|
156
|
-
name: f,
|
|
157
|
-
symbol: m
|
|
158
|
-
};
|
|
159
|
-
s[d] = p, e[i] || (e[i] = h);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return { assets: s, chains: e };
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Parse chain identifier from string
|
|
166
|
-
*/
|
|
167
|
-
parseChainIdentifier(t) {
|
|
168
|
-
return c.includes(t) ? t : null;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Format chain name for display
|
|
172
|
-
*/
|
|
173
|
-
formatChainName(t) {
|
|
174
|
-
return t.split("_").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
|
|
175
|
-
}
|
|
176
|
-
// ============================================
|
|
177
|
-
// Data Refresh Methods
|
|
178
|
-
// ============================================
|
|
179
|
-
/**
|
|
180
|
-
* Refresh all data
|
|
181
|
-
*/
|
|
182
|
-
async refresh() {
|
|
183
|
-
await this.initialize();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
1
|
+
import { OrderStatus as e, isBitcoin as d } from "./index4.js";
|
|
2
|
+
const s = (t) => {
|
|
3
|
+
const { created_at: r, source_swap: n, destination_swap: i } = t;
|
|
4
|
+
if (i.redeem_tx_hash)
|
|
5
|
+
return Number(i.redeem_block_number) ? e.Redeemed : d(i.chain) ? e.Redeemed : e.RedeemDetected;
|
|
6
|
+
if (d(i.chain) && n.redeem_tx_hash && !i.redeem_tx_hash)
|
|
7
|
+
return e.Redeemed;
|
|
8
|
+
if (n.refund_tx_hash)
|
|
9
|
+
return Number(n.refund_block_number) ? e.Refunded : e.RefundDetected;
|
|
10
|
+
if (i.refund_tx_hash) return e.AwaitingRefund;
|
|
11
|
+
const u = d(n.chain) ? a(new Date(r), 6) : a(new Date(r), 1);
|
|
12
|
+
return i.initiate_tx_hash ? e.AwaitingRedeem : n.initiate_tx_hash ? u ? e.AwaitingRefund : Number(n.initiate_block_number) ? e.Initiated : e.InitiateDetected : u ? e.Expired : e.Created;
|
|
13
|
+
}, a = (t, r = 1) => {
|
|
14
|
+
const n = /* @__PURE__ */ new Date(), i = new Date(t);
|
|
15
|
+
return i.setHours(i.getHours() + r), n > i;
|
|
16
|
+
}, m = (t) => {
|
|
17
|
+
const r = s(t);
|
|
18
|
+
return r === e.Redeemed || r === e.Refunded || r === e.Expired;
|
|
19
|
+
};
|
|
20
|
+
var _ = /* @__PURE__ */ ((t) => (t.Initiate = "Initiate", t.PostRefundSACP = "PostRefundSACP", t.Redeem = "Redeem", t.Refund = "Refund", t.Idle = "Idle", t))(_ || {});
|
|
21
|
+
const o = (t) => {
|
|
22
|
+
const { source_swap: r, destination_swap: n } = t;
|
|
23
|
+
return n.redeem_tx_hash && Number(n.redeem_block_number) || r.refund_tx_hash && Number(r.refund_block_number) ? "Idle" : !n.refund_tx_hash && n.initiate_tx_hash ? "Redeem" : "Idle";
|
|
24
|
+
};
|
|
186
25
|
export {
|
|
187
|
-
|
|
26
|
+
_ as OrderAction,
|
|
27
|
+
s as ParseOrderStatus,
|
|
28
|
+
m as isCompleted,
|
|
29
|
+
a as isDeadlinePassed,
|
|
30
|
+
o as parseAction
|
|
188
31
|
};
|
package/dist/index11.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@gardenfi/utils"),y=require("./index12.cjs"),p=require("./index4.cjs"),r=require("./index8.cjs"),o=require("./index13.cjs"),h=Object.keys(p.Config);class g{constructor(t,s){this.assets=null,this.chains=null,this.routeMatrix=null,this.isLoading=!1,this.error=null,typeof s=="string"?this.auth=new n.ApiKey(s):this.auth=s;const e=o.ensureUrl(t.baseUrl),a=o.buildDefaultEndpoint(e,"/v2/chains"),i=o.buildDefaultEndpoint(e,"/v2/policy");this.urls={base:e,assets:o.ensureUrl(t.assetsUrl??a),policy:o.ensureUrl(t.policyUrl??i)},this.routeValidator=new y.RouteValidator(this.urls.policy.toString(),this.auth)}async initialize(){await this.fetchAndSetAssetsAndChains(),await this.routeValidator.loadPolicy()}async fetchAndSetAssetsAndChains(){try{this.isLoading=!0,this.error=null;const t=await this.auth.getAuthHeaders();if(!t.ok)return n.Err("Failed to get auth headers");const s=await n.Fetcher.get(this.urls.assets,{headers:{...t.val}});if(!s.result)return n.Err(`Failed to fetch chains data: ${s.error}`);const{assets:e,chains:a}=this.processApiData(s.result);return this.assets=e,this.chains=a,await this.buildRouteMatrix(),n.Ok("AssetManager initialized successfully")}catch(t){return n.Err(`Failed to fetch assets data: ${t}`)}finally{this.isLoading=!1}}async isRouteValid(t,s){return await this.routeValidator.isValidRoute(r.ChainAsset.from(t.id),r.ChainAsset.from(s.id))}getValidDestinations(t){if(!this.routeMatrix||!this.assets||!t.id)return console.warn("Missing routeMatrix, assets, or asset. Returning all assets."),[];const s=this.routeMatrix[t.id.toString().toLowerCase()];return s?s.map(e=>{const a=e.toString();return Object.values(this.assets).find(i=>r.ChainAsset.from(i).toString()===a)}).filter(Boolean):[]}getAsset(t){if(!this.assets)return;const s=r.ChainAsset.from(t).toString();return this.assets[s]}getAssetsByChain(t){return this.assets?Object.values(this.assets).filter(s=>s.chain===t):[]}searchAssets(t){if(!this.assets)return[];const s=t.toLowerCase();return Object.values(this.assets).filter(e=>e.symbol.toLowerCase().includes(s)||e.name.toLowerCase().includes(s))}getChain(t){if(this.chains)return this.chains[t]}async buildRouteMatrix(){if(!this.assets||!this.routeValidator)return;const t=Object.values(this.assets).map(s=>{if(!s.id)return null;try{return r.ChainAsset.from(s.id)}catch{return null}}).filter(s=>s!==null);this.routeMatrix=await this.routeValidator.buildRouteMatrix(t)}processApiData(t){const s={},e={};for(const a of t){const i=this.parseChainIdentifier(a.chain);if(!i||!h.includes(i))continue;const u={...a,name:a.name||this.formatChainName(i),chain:i};for(const l of a.assets){const c=r.ChainAsset.from(l.id).toString(),{name:d,symbol:f}=o.parseAssetNameSymbol(l.name,l.id),A={...l,id:r.ChainAsset.from(l.id),chain:i,name:d,symbol:f};s[c]=A,e[i]||(e[i]=u)}}return{assets:s,chains:e}}parseChainIdentifier(t){return h.includes(t)?t:null}formatChainName(t){return t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}async refresh(){await this.initialize()}}exports.AssetManager=g;
|
package/dist/index11.js
CHANGED
|
@@ -1,207 +1,188 @@
|
|
|
1
|
-
import { ApiKey as
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ApiKey as A, Err as o, Fetcher as y, Ok as g } from "@gardenfi/utils";
|
|
2
|
+
import { RouteValidator as C } from "./index12.js";
|
|
3
|
+
import { Config as b } from "./index4.js";
|
|
4
|
+
import { ChainAsset as r } from "./index8.js";
|
|
5
|
+
import { ensureUrl as l, buildDefaultEndpoint as u, parseAssetNameSymbol as w } from "./index13.js";
|
|
6
|
+
const c = Object.keys(b);
|
|
7
|
+
class I {
|
|
8
|
+
constructor(t, s) {
|
|
9
|
+
this.assets = null, this.chains = null, this.routeMatrix = null, this.isLoading = !1, this.error = null, typeof s == "string" ? this.auth = new A(s) : this.auth = s;
|
|
10
|
+
const e = l(t.baseUrl), a = u(e, "/v2/chains"), i = u(e, "/v2/policy");
|
|
11
|
+
this.urls = {
|
|
12
|
+
base: e,
|
|
13
|
+
assets: l(t.assetsUrl ?? a),
|
|
14
|
+
policy: l(t.policyUrl ?? i)
|
|
15
|
+
}, this.routeValidator = new C(
|
|
16
|
+
this.urls.policy.toString(),
|
|
17
|
+
this.auth
|
|
18
|
+
);
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
],
|
|
24
|
-
blacklist_pairs: [
|
|
25
|
-
.../* @__PURE__ */ new Set([
|
|
26
|
-
...(t == null ? void 0 : t.blacklist_pairs) || [],
|
|
27
|
-
...e.blacklist_pairs
|
|
28
|
-
])
|
|
29
|
-
],
|
|
30
|
-
whitelist_overrides: [
|
|
31
|
-
.../* @__PURE__ */ new Set([
|
|
32
|
-
...(t == null ? void 0 : t.whitelist_overrides) || [],
|
|
33
|
-
...e.whitelist_overrides
|
|
34
|
-
])
|
|
35
|
-
]
|
|
36
|
-
};
|
|
37
|
-
return this.policy.set(a.POLICY_CACHE_KEY, s), s;
|
|
20
|
+
// ============================================
|
|
21
|
+
// Initialization Methods
|
|
22
|
+
// ============================================
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the AssetManager by fetching all required data
|
|
25
|
+
*/
|
|
26
|
+
async initialize() {
|
|
27
|
+
await this.fetchAndSetAssetsAndChains(), await this.routeValidator.loadPolicy();
|
|
38
28
|
}
|
|
39
29
|
/**
|
|
40
|
-
*
|
|
30
|
+
* Fetch and cache asset and chain data from API
|
|
41
31
|
*/
|
|
42
|
-
async
|
|
43
|
-
const e = this.getPolicy();
|
|
44
|
-
if (e) return u(e);
|
|
32
|
+
async fetchAndSetAssetsAndChains() {
|
|
45
33
|
try {
|
|
34
|
+
this.isLoading = !0, this.error = null;
|
|
46
35
|
const t = await this.auth.getAuthHeaders();
|
|
47
|
-
if (!t.ok)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.apiBaseUrl,
|
|
36
|
+
if (!t.ok) return o("Failed to get auth headers");
|
|
37
|
+
const s = await y.get(
|
|
38
|
+
this.urls.assets,
|
|
51
39
|
{
|
|
52
40
|
headers: {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
41
|
...t.val
|
|
55
42
|
}
|
|
56
43
|
}
|
|
57
44
|
);
|
|
58
|
-
|
|
45
|
+
if (!s.result) return o(`Failed to fetch chains data: ${s.error}`);
|
|
46
|
+
const { assets: e, chains: a } = this.processApiData(s.result);
|
|
47
|
+
return this.assets = e, this.chains = a, await this.buildRouteMatrix(), g("AssetManager initialized successfully");
|
|
59
48
|
} catch (t) {
|
|
60
|
-
return
|
|
49
|
+
return o(`Failed to fetch assets data: ${t}`);
|
|
50
|
+
} finally {
|
|
51
|
+
this.isLoading = !1;
|
|
61
52
|
}
|
|
62
53
|
}
|
|
54
|
+
// ============================================
|
|
55
|
+
// Route Validation Methods
|
|
56
|
+
// ============================================
|
|
63
57
|
/**
|
|
64
|
-
*
|
|
58
|
+
* Check if a swap route from one asset to another is valid
|
|
65
59
|
*/
|
|
66
|
-
async
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
e,
|
|
71
|
-
r
|
|
72
|
-
);
|
|
73
|
-
if (o && !this.matchesRuleDestination(t, o))
|
|
74
|
-
return !1;
|
|
75
|
-
const c = this.findMatchingRule(
|
|
76
|
-
t,
|
|
77
|
-
r
|
|
60
|
+
async isRouteValid(t, s) {
|
|
61
|
+
return await this.routeValidator.isValidRoute(
|
|
62
|
+
r.from(t.id),
|
|
63
|
+
r.from(s.id)
|
|
78
64
|
);
|
|
79
|
-
return c && c.rule.direction === "<->" && !this.matchesRuleSource(e, c) ? !1 : this.matchesRuleList(e, t, i) ? !!this.matchesRuleList(e, t, n) : s.val.default === "open";
|
|
80
65
|
}
|
|
81
66
|
/**
|
|
82
|
-
*
|
|
67
|
+
* Get all valid destination assets for a given source asset
|
|
83
68
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
69
|
+
getValidDestinations(t) {
|
|
70
|
+
if (!this.routeMatrix || !this.assets || !t.id)
|
|
71
|
+
return console.warn(
|
|
72
|
+
"Missing routeMatrix, assets, or asset. Returning all assets."
|
|
73
|
+
), [];
|
|
74
|
+
const s = this.routeMatrix[t.id.toString().toLowerCase()];
|
|
75
|
+
return s ? s.map((e) => {
|
|
76
|
+
const a = e.toString();
|
|
77
|
+
return Object.values(this.assets).find((i) => r.from(i).toString() === a);
|
|
78
|
+
}).filter(Boolean) : [];
|
|
79
|
+
}
|
|
80
|
+
// ============================================
|
|
81
|
+
// Asset Query Methods
|
|
82
|
+
// ============================================
|
|
90
83
|
/**
|
|
91
|
-
*
|
|
84
|
+
* Get asset by chain and token address
|
|
92
85
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await this.isValidRoute(s, r) && t.push({ from: s, to: r });
|
|
98
|
-
return t;
|
|
86
|
+
getAsset(t) {
|
|
87
|
+
if (!this.assets) return;
|
|
88
|
+
const s = r.from(t).toString();
|
|
89
|
+
return this.assets[s];
|
|
99
90
|
}
|
|
100
91
|
/**
|
|
101
|
-
*
|
|
92
|
+
* Get all assets for a specific chain
|
|
102
93
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return { sortedIsolationRules: t, sortedBlacklistRules: s, sortedWhitelistRules: r };
|
|
94
|
+
getAssetsByChain(t) {
|
|
95
|
+
return this.assets ? Object.values(this.assets).filter((s) => s.chain === t) : [];
|
|
106
96
|
}
|
|
107
97
|
/**
|
|
108
|
-
*
|
|
98
|
+
* Search assets by symbol or name
|
|
109
99
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
pattern: e,
|
|
117
|
-
fromPattern: r,
|
|
118
|
-
toPattern: i,
|
|
119
|
-
direction: s,
|
|
120
|
-
specificity: this.calculateSpecificity(r, i)
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Gives a specificity score to a rule pattern for prioritizing.
|
|
125
|
-
*/
|
|
126
|
-
calculateSpecificity(e, t) {
|
|
127
|
-
const s = (r) => {
|
|
128
|
-
const i = r.toLowerCase();
|
|
129
|
-
return i === "*" ? 0 : i.includes(
|
|
130
|
-
"*"
|
|
131
|
-
/* Any */
|
|
132
|
-
) ? 1 : 2;
|
|
133
|
-
};
|
|
134
|
-
return s(e) * 10 + s(t);
|
|
100
|
+
searchAssets(t) {
|
|
101
|
+
if (!this.assets) return [];
|
|
102
|
+
const s = t.toLowerCase();
|
|
103
|
+
return Object.values(this.assets).filter(
|
|
104
|
+
(e) => e.symbol.toLowerCase().includes(s) || e.name.toLowerCase().includes(s)
|
|
105
|
+
);
|
|
135
106
|
}
|
|
136
107
|
/**
|
|
137
|
-
*
|
|
108
|
+
* Get chain data by chain identifier
|
|
138
109
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
rule: s,
|
|
144
|
-
matchedAs: "from"
|
|
145
|
-
/* From */
|
|
146
|
-
};
|
|
147
|
-
if (s.direction === "<->" && this.matchesAssetPattern(e, s.toPattern))
|
|
148
|
-
return {
|
|
149
|
-
rule: s,
|
|
150
|
-
matchedAs: "to"
|
|
151
|
-
/* To */
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
110
|
+
getChain(t) {
|
|
111
|
+
if (this.chains)
|
|
112
|
+
return this.chains[t];
|
|
155
113
|
}
|
|
114
|
+
// ============================================
|
|
115
|
+
// Private Helper Methods
|
|
116
|
+
// ============================================
|
|
156
117
|
/**
|
|
157
|
-
*
|
|
118
|
+
* Build route matrix for fast O(1) route lookups
|
|
158
119
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
120
|
+
async buildRouteMatrix() {
|
|
121
|
+
if (!this.assets || !this.routeValidator) return;
|
|
122
|
+
const t = Object.values(this.assets).map((s) => {
|
|
123
|
+
if (!s.id) return null;
|
|
124
|
+
try {
|
|
125
|
+
return r.from(s.id);
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}).filter((s) => s !== null);
|
|
130
|
+
this.routeMatrix = await this.routeValidator.buildRouteMatrix(
|
|
131
|
+
t
|
|
132
|
+
);
|
|
161
133
|
}
|
|
162
134
|
/**
|
|
163
|
-
*
|
|
135
|
+
* Process raw API data into structured format
|
|
164
136
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
137
|
+
processApiData(t) {
|
|
138
|
+
const s = {}, e = {};
|
|
139
|
+
for (const a of t) {
|
|
140
|
+
const i = this.parseChainIdentifier(a.chain);
|
|
141
|
+
if (!i || !c.includes(i))
|
|
142
|
+
continue;
|
|
143
|
+
const h = {
|
|
144
|
+
...a,
|
|
145
|
+
name: a.name || this.formatChainName(i),
|
|
146
|
+
chain: i
|
|
147
|
+
};
|
|
148
|
+
for (const n of a.assets) {
|
|
149
|
+
const d = r.from(n.id).toString(), { name: f, symbol: m } = w(
|
|
150
|
+
n.name,
|
|
151
|
+
n.id
|
|
152
|
+
), p = {
|
|
153
|
+
...n,
|
|
154
|
+
id: r.from(n.id),
|
|
155
|
+
chain: i,
|
|
156
|
+
name: f,
|
|
157
|
+
symbol: m
|
|
158
|
+
};
|
|
159
|
+
s[d] = p, e[i] || (e[i] = h);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { assets: s, chains: e };
|
|
167
163
|
}
|
|
168
164
|
/**
|
|
169
|
-
*
|
|
165
|
+
* Parse chain identifier from string
|
|
170
166
|
*/
|
|
171
|
-
|
|
172
|
-
return
|
|
167
|
+
parseChainIdentifier(t) {
|
|
168
|
+
return c.includes(t) ? t : null;
|
|
173
169
|
}
|
|
174
170
|
/**
|
|
175
|
-
*
|
|
171
|
+
* Format chain name for display
|
|
176
172
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (s.direction === "<->") {
|
|
180
|
-
const i = this.matchesAssetPattern(e, s.toPattern) && this.matchesAssetPattern(t, s.fromPattern);
|
|
181
|
-
return r || i;
|
|
182
|
-
}
|
|
183
|
-
return r;
|
|
173
|
+
formatChainName(t) {
|
|
174
|
+
return t.split("_").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
|
|
184
175
|
}
|
|
176
|
+
// ============================================
|
|
177
|
+
// Data Refresh Methods
|
|
178
|
+
// ============================================
|
|
185
179
|
/**
|
|
186
|
-
*
|
|
180
|
+
* Refresh all data
|
|
187
181
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return i && n;
|
|
182
|
+
async refresh() {
|
|
183
|
+
await this.initialize();
|
|
191
184
|
}
|
|
192
|
-
|
|
193
|
-
const t = {};
|
|
194
|
-
for (const s of e) {
|
|
195
|
-
const r = [];
|
|
196
|
-
for (const i of e)
|
|
197
|
-
await this.isValidRoute(s, i) && r.push(i);
|
|
198
|
-
t[s.toString()] = r;
|
|
199
|
-
}
|
|
200
|
-
return t;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
a.POLICY_CACHE_KEY = "route_policy";
|
|
204
|
-
let h = a;
|
|
185
|
+
}
|
|
205
186
|
export {
|
|
206
|
-
|
|
187
|
+
I as AssetManager
|
|
207
188
|
};
|
package/dist/index12.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@gardenfi/utils"),h=require("node-cache"),o=class o{constructor(e,t){this.policy=new h({stdTTL:36e3,checkperiod:3600}),typeof t=="string"?this.auth=new a.ApiKey(t):this.auth=t,typeof e=="string"?this.apiBaseUrl=new a.Url(e):this.apiBaseUrl=e}getPolicy(){return this.policy.get(o.POLICY_CACHE_KEY)}setPolicy(e){const t=this.getPolicy(),s={default:e.default||(t==null?void 0:t.default)||"open",isolation_groups:[...new Set([...(t==null?void 0:t.isolation_groups)||[],...e.isolation_groups])],blacklist_pairs:[...new Set([...(t==null?void 0:t.blacklist_pairs)||[],...e.blacklist_pairs])],whitelist_overrides:[...new Set([...(t==null?void 0:t.whitelist_overrides)||[],...e.whitelist_overrides])]};return this.policy.set(o.POLICY_CACHE_KEY,s),s}async loadPolicy(){const e=this.getPolicy();if(e)return a.Ok(e);try{const t=await this.auth.getAuthHeaders();if(!t.ok)return a.Err(`Failed to get auth headers: ${t.error}`);const s=await a.Fetcher.get(this.apiBaseUrl,{headers:{"Content-Type":"application/json",...t.val}});return s.result?a.Ok(this.setPolicy(s.result)):a.Err(`API Error: ${s.error}`)}catch(t){return a.Err(`Failed to load policy: ${t}`)}}async isValidRoute(e,t){const s=await this.loadPolicy();if(!s.ok||e.toString()===t.toString())return!1;const{sortedIsolationRules:r,sortedBlacklistRules:i,sortedWhitelistRules:n}=this.preprocessRules(s.val),c=this.findMatchingRule(e,r);if(c&&!this.matchesRuleDestination(t,c))return!1;const l=this.findMatchingRule(t,r);return l&&l.rule.direction==="<->"&&!this.matchesRuleSource(e,l)?!1:this.matchesRuleList(e,t,i)?!!this.matchesRuleList(e,t,n):s.val.default==="open"}async getValidDestinations(e,t){const s=[];for(const r of t)await this.isValidRoute(e,r)&&s.push(r);return s}async getAllValidRoutes(e){const t=[];for(const s of e)for(const r of e)await this.isValidRoute(s,r)&&t.push({from:s,to:r});return t}preprocessRules(e){const t=e.isolation_groups.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),s=e.blacklist_pairs.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),r=e.whitelist_overrides.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity);return{sortedIsolationRules:t,sortedBlacklistRules:s,sortedWhitelistRules:r}}parseRule(e){const s=e.includes("<->")?"<->":"->",[r,i]=e.split(s).map(n=>n.trim());return{pattern:e,fromPattern:r,toPattern:i,direction:s,specificity:this.calculateSpecificity(r,i)}}calculateSpecificity(e,t){const s=r=>{const i=r.toLowerCase();return i==="*"?0:i.includes("*")?1:2};return s(e)*10+s(t)}findMatchingRule(e,t){for(const s of t){if(this.matchesAssetPattern(e,s.fromPattern))return{rule:s,matchedAs:"from"};if(s.direction==="<->"&&this.matchesAssetPattern(e,s.toPattern))return{rule:s,matchedAs:"to"}}return null}matchesRuleDestination(e,t){return t.matchedAs==="from"?this.matchesAssetPattern(e,t.rule.toPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.fromPattern)}matchesRuleSource(e,t){return t.matchedAs==="to"?this.matchesAssetPattern(e,t.rule.fromPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.toPattern)}matchesRuleList(e,t,s){return s.some(r=>this.matchesRule(e,t,r))}matchesRule(e,t,s){const r=this.matchesAssetPattern(e,s.fromPattern)&&this.matchesAssetPattern(t,s.toPattern);if(s.direction==="<->"){const i=this.matchesAssetPattern(e,s.toPattern)&&this.matchesAssetPattern(t,s.fromPattern);return r||i}return r}matchesAssetPattern(e,t){const[s="",r=""]=t.split(":").map(c=>c.trim().toLowerCase()),i=s===""||s==="*"||s===e.chain.toLowerCase(),n=r===""||r==="*"||r===e.symbol.toLowerCase();return i&&n}async buildRouteMatrix(e){const t={};for(const s of e){const r=[];for(const i of e)await this.isValidRoute(s,i)&&r.push(i);t[s.toString()]=r}return t}};o.POLICY_CACHE_KEY="route_policy";let u=o;exports.RouteValidator=u;
|
package/dist/index12.js
CHANGED
|
@@ -1,31 +1,207 @@
|
|
|
1
|
-
import { Url as p } from "@gardenfi/utils";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ApiKey as f, Url as p, Ok as u, Err as l, Fetcher as d } from "@gardenfi/utils";
|
|
2
|
+
import m from "node-cache";
|
|
3
|
+
const a = class a {
|
|
4
|
+
constructor(e, t) {
|
|
5
|
+
this.policy = new m({
|
|
6
|
+
stdTTL: 36e3,
|
|
7
|
+
// 10 hours in seconds
|
|
8
|
+
checkperiod: 3600
|
|
9
|
+
// Check for expired keys every hour
|
|
10
|
+
}), typeof t == "string" ? this.auth = new f(t) : this.auth = t, typeof e == "string" ? this.apiBaseUrl = new p(e) : this.apiBaseUrl = e;
|
|
11
|
+
}
|
|
12
|
+
getPolicy() {
|
|
13
|
+
return this.policy.get(a.POLICY_CACHE_KEY);
|
|
14
|
+
}
|
|
15
|
+
setPolicy(e) {
|
|
16
|
+
const t = this.getPolicy(), s = {
|
|
17
|
+
default: e.default || (t == null ? void 0 : t.default) || "open",
|
|
18
|
+
isolation_groups: [
|
|
19
|
+
.../* @__PURE__ */ new Set([
|
|
20
|
+
...(t == null ? void 0 : t.isolation_groups) || [],
|
|
21
|
+
...e.isolation_groups
|
|
22
|
+
])
|
|
23
|
+
],
|
|
24
|
+
blacklist_pairs: [
|
|
25
|
+
.../* @__PURE__ */ new Set([
|
|
26
|
+
...(t == null ? void 0 : t.blacklist_pairs) || [],
|
|
27
|
+
...e.blacklist_pairs
|
|
28
|
+
])
|
|
29
|
+
],
|
|
30
|
+
whitelist_overrides: [
|
|
31
|
+
.../* @__PURE__ */ new Set([
|
|
32
|
+
...(t == null ? void 0 : t.whitelist_overrides) || [],
|
|
33
|
+
...e.whitelist_overrides
|
|
34
|
+
])
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
return this.policy.set(a.POLICY_CACHE_KEY, s), s;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Loads the current route policy, cached or via API.
|
|
41
|
+
*/
|
|
42
|
+
async loadPolicy() {
|
|
43
|
+
const e = this.getPolicy();
|
|
44
|
+
if (e) return u(e);
|
|
14
45
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
46
|
+
const t = await this.auth.getAuthHeaders();
|
|
47
|
+
if (!t.ok)
|
|
48
|
+
return l(`Failed to get auth headers: ${t.error}`);
|
|
49
|
+
const s = await d.get(
|
|
50
|
+
this.apiBaseUrl,
|
|
51
|
+
{
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
...t.val
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
return s.result ? u(this.setPolicy(s.result)) : l(`API Error: ${s.error}`);
|
|
59
|
+
} catch (t) {
|
|
60
|
+
return l(`Failed to load policy: ${t}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a given route is valid based on all route rules.
|
|
65
|
+
*/
|
|
66
|
+
async isValidRoute(e, t) {
|
|
67
|
+
const s = await this.loadPolicy();
|
|
68
|
+
if (!s.ok || e.toString() === t.toString()) return !1;
|
|
69
|
+
const { sortedIsolationRules: r, sortedBlacklistRules: i, sortedWhitelistRules: n } = this.preprocessRules(s.val), o = this.findMatchingRule(
|
|
70
|
+
e,
|
|
71
|
+
r
|
|
72
|
+
);
|
|
73
|
+
if (o && !this.matchesRuleDestination(t, o))
|
|
74
|
+
return !1;
|
|
75
|
+
const c = this.findMatchingRule(
|
|
76
|
+
t,
|
|
77
|
+
r
|
|
78
|
+
);
|
|
79
|
+
return c && c.rule.direction === "<->" && !this.matchesRuleSource(e, c) ? !1 : this.matchesRuleList(e, t, i) ? !!this.matchesRuleList(e, t, n) : s.val.default === "open";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns all valid destinations for a given source asset.
|
|
83
|
+
*/
|
|
84
|
+
async getValidDestinations(e, t) {
|
|
85
|
+
const s = [];
|
|
86
|
+
for (const r of t)
|
|
87
|
+
await this.isValidRoute(e, r) && s.push(r);
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns every valid route (from-to pair) among the provided assets.
|
|
92
|
+
*/
|
|
93
|
+
async getAllValidRoutes(e) {
|
|
94
|
+
const t = [];
|
|
95
|
+
for (const s of e)
|
|
96
|
+
for (const r of e)
|
|
97
|
+
await this.isValidRoute(s, r) && t.push({ from: s, to: r });
|
|
98
|
+
return t;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Turns policy string rules into sorted ParsedRule objects.
|
|
102
|
+
*/
|
|
103
|
+
preprocessRules(e) {
|
|
104
|
+
const t = e.isolation_groups.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity), s = e.blacklist_pairs.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity), r = e.whitelist_overrides.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity);
|
|
105
|
+
return { sortedIsolationRules: t, sortedBlacklistRules: s, sortedWhitelistRules: r };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parses a rule string (e.g. "ethereum:usdc -> base:usdt") into parts.
|
|
109
|
+
*/
|
|
110
|
+
parseRule(e) {
|
|
111
|
+
const s = e.includes(
|
|
112
|
+
"<->"
|
|
113
|
+
/* Bidirectional */
|
|
114
|
+
) ? "<->" : "->", [r, i] = e.split(s).map((n) => n.trim());
|
|
115
|
+
return {
|
|
116
|
+
pattern: e,
|
|
117
|
+
fromPattern: r,
|
|
118
|
+
toPattern: i,
|
|
119
|
+
direction: s,
|
|
120
|
+
specificity: this.calculateSpecificity(r, i)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Gives a specificity score to a rule pattern for prioritizing.
|
|
125
|
+
*/
|
|
126
|
+
calculateSpecificity(e, t) {
|
|
127
|
+
const s = (r) => {
|
|
128
|
+
const i = r.toLowerCase();
|
|
129
|
+
return i === "*" ? 0 : i.includes(
|
|
130
|
+
"*"
|
|
131
|
+
/* Any */
|
|
132
|
+
) ? 1 : 2;
|
|
133
|
+
};
|
|
134
|
+
return s(e) * 10 + s(t);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Finds the first matching rule for an asset given the rule "side".
|
|
138
|
+
*/
|
|
139
|
+
findMatchingRule(e, t) {
|
|
140
|
+
for (const s of t) {
|
|
141
|
+
if (this.matchesAssetPattern(e, s.fromPattern))
|
|
142
|
+
return {
|
|
143
|
+
rule: s,
|
|
144
|
+
matchedAs: "from"
|
|
145
|
+
/* From */
|
|
146
|
+
};
|
|
147
|
+
if (s.direction === "<->" && this.matchesAssetPattern(e, s.toPattern))
|
|
148
|
+
return {
|
|
149
|
+
rule: s,
|
|
150
|
+
matchedAs: "to"
|
|
151
|
+
/* To */
|
|
152
|
+
};
|
|
17
153
|
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Checks if a given toAsset matches the rule's destination side.
|
|
158
|
+
*/
|
|
159
|
+
matchesRuleDestination(e, t) {
|
|
160
|
+
return t.matchedAs === "from" ? this.matchesAssetPattern(e, t.rule.toPattern) : t.rule.direction !== "<->" ? !1 : this.matchesAssetPattern(e, t.rule.fromPattern);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a given fromAsset matches the rule's source side.
|
|
164
|
+
*/
|
|
165
|
+
matchesRuleSource(e, t) {
|
|
166
|
+
return t.matchedAs === "to" ? this.matchesAssetPattern(e, t.rule.fromPattern) : t.rule.direction !== "<->" ? !1 : this.matchesAssetPattern(e, t.rule.toPattern);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Checks if any rule in a list matches fromAsset and toAsset.
|
|
170
|
+
*/
|
|
171
|
+
matchesRuleList(e, t, s) {
|
|
172
|
+
return s.some((r) => this.matchesRule(e, t, r));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Checks if a rule matches fromAsset and toAsset (forward or backward if bidirectional).
|
|
176
|
+
*/
|
|
177
|
+
matchesRule(e, t, s) {
|
|
178
|
+
const r = this.matchesAssetPattern(e, s.fromPattern) && this.matchesAssetPattern(t, s.toPattern);
|
|
179
|
+
if (s.direction === "<->") {
|
|
180
|
+
const i = this.matchesAssetPattern(e, s.toPattern) && this.matchesAssetPattern(t, s.fromPattern);
|
|
181
|
+
return r || i;
|
|
182
|
+
}
|
|
183
|
+
return r;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Checks if an asset string matches a rule's pattern (wildcards supported).
|
|
187
|
+
*/
|
|
188
|
+
matchesAssetPattern(e, t) {
|
|
189
|
+
const [s = "", r = ""] = t.split(":").map((o) => o.trim().toLowerCase()), i = s === "" || s === "*" || s === e.chain.toLowerCase(), n = r === "" || r === "*" || r === e.symbol.toLowerCase();
|
|
190
|
+
return i && n;
|
|
191
|
+
}
|
|
192
|
+
async buildRouteMatrix(e) {
|
|
193
|
+
const t = {};
|
|
194
|
+
for (const s of e) {
|
|
195
|
+
const r = [];
|
|
196
|
+
for (const i of e)
|
|
197
|
+
await this.isValidRoute(s, i) && r.push(i);
|
|
198
|
+
t[s.toString()] = r;
|
|
199
|
+
}
|
|
200
|
+
return t;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
a.POLICY_CACHE_KEY = "route_policy";
|
|
204
|
+
let h = a;
|
|
27
205
|
export {
|
|
28
|
-
|
|
29
|
-
d as ensureUrl,
|
|
30
|
-
$ as parseAssetNameSymbol
|
|
206
|
+
h as RouteValidator
|
|
31
207
|
};
|
package/dist/index13.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@gardenfi/utils"),p=require("./index8.cjs");function d(n,t,e){var o;const r=(n??"").trim();if(!r)return{name:"",symbol:""};const i=r.split(":");if(i.length>=2){const u=((o=i[0])==null?void 0:o.trim())||"",m=i.slice(1).join(":").trim()||(e==null?void 0:e.trim())||"";return{name:u,symbol:m}}let s="";if(t)try{s=(typeof t=="string"?p.ChainAsset.from(t):t).symbol.toUpperCase()}catch{}return{name:r,symbol:s||(e==null?void 0:e.trim())||""}}function h(n){return n instanceof c.Url?n:new c.Url(n)}function A(n,t){const e=n.toString().replace(/\/+$/,""),r=t.startsWith("/")?t:`/${t}`;return`${e}${r}`}exports.buildDefaultEndpoint=A;exports.ensureUrl=h;exports.parseAssetNameSymbol=d;
|
package/dist/index13.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Url as p } from "@gardenfi/utils";
|
|
2
|
+
import { ChainAsset as c } from "./index8.js";
|
|
3
|
+
function $(r, t, n) {
|
|
4
|
+
var o;
|
|
5
|
+
const e = (r ?? "").trim();
|
|
6
|
+
if (!e) return { name: "", symbol: "" };
|
|
7
|
+
const i = e.split(":");
|
|
8
|
+
if (i.length >= 2) {
|
|
9
|
+
const m = ((o = i[0]) == null ? void 0 : o.trim()) || "", u = i.slice(1).join(":").trim() || (n == null ? void 0 : n.trim()) || "";
|
|
10
|
+
return { name: m, symbol: u };
|
|
11
|
+
}
|
|
12
|
+
let s = "";
|
|
13
|
+
if (t)
|
|
14
|
+
try {
|
|
15
|
+
s = (typeof t == "string" ? c.from(t) : t).symbol.toUpperCase();
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
return { name: e, symbol: s || (n == null ? void 0 : n.trim()) || "" };
|
|
19
|
+
}
|
|
20
|
+
function d(r) {
|
|
21
|
+
return r instanceof p ? r : new p(r);
|
|
22
|
+
}
|
|
23
|
+
function f(r, t) {
|
|
24
|
+
const n = r.toString().replace(/\/+$/, ""), e = t.startsWith("/") ? t : `/${t}`;
|
|
25
|
+
return `${n}${e}`;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
f as buildDefaultEndpoint,
|
|
29
|
+
d as ensureUrl,
|
|
30
|
+
$ as parseAssetNameSymbol
|
|
31
|
+
};
|
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),c=require("./index7.cjs"),d=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),c=require("./index7.cjs"),d=require("./index10.cjs");class l{constructor(o,s){this.url=o,this.auth=s}async createOrder(o){try{const s=await this.auth.getAuthHeaders();if(s.error)return r.Err(s.error);const e=await r.Fetcher.post(this.url.endpoint("/v2/orders"),{body:JSON.stringify(o),headers:{...s.val,"Content-Type":"application/json"}});if(e.error)return r.Err(e.error);if(!e.result)return r.Err("CreateOrder: Unexpected error, result is undefined");const i=c.discriminateOrderResponse(e.result);return i?r.Ok(i):r.Err("CreateOrder: Unable to determine order type from response")}catch(s){return r.Err("CreateOrder Err:",String(s))}}async getOrder(o,s){try{const e=await this.auth.getAuthHeaders();if(e.error)return r.Err(e.error);const i=this.url.endpoint("/v2/orders").endpoint(o),n=await r.Fetcher.get(i,{...s,headers:{...e.val,"Content-Type":"application/json"}});if(n.error)return r.Err(n.error);if(!n.result)return r.Err("GetOrder: Unexpected error, result is undefined");const t=d.ParseOrderStatus(n.result);return r.Ok({...n.result,status:t})}catch(e){return r.Err(`GetOrder: ${e instanceof Error?e.message:String(e)}`)}}async getOrders(o,s){const e=await this.auth.getAuthHeaders();if(e.error)return r.Err(e.error);const n=c.ConstructUrl(this.url,"/v2/orders",o);try{const t=await r.Fetcher.get(n,{...s,headers:{...e.val,"Content-Type":"application/json"}});if(t.error)return r.Err(t.error);if(!t.result)return r.Err("GetAllOrders: Unexpected error, result is undefined");const u=t.result.data.map(a=>({...a,status:d.ParseOrderStatus(a)}));return r.Ok({...t.result,data:u})}catch(t){return r.Err(`GetAllOrders: ${t instanceof Error?t.message:String(t)}`)}}async subscribeOrders(o,s,e,i){let n=!1;const t=async()=>{if(!n){n=!0;try{const a=await this.getOrders(o,i);a.ok?await s(a.val):console.error("Error fetching orders:",a.error)}catch(a){console.error("Error fetching orders:",a)}finally{n=!1}}};await t();const u=setInterval(t,e);return()=>{clearInterval(u)}}}exports.Orderbook=l;
|
package/dist/index2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Err as s, Fetcher as d, Ok as c } from "@gardenfi/utils";
|
|
2
2
|
import { discriminateOrderResponse as h, ConstructUrl as f } from "./index7.js";
|
|
3
|
-
import { ParseOrderStatus as l } from "./
|
|
3
|
+
import { ParseOrderStatus as l } from "./index10.js";
|
|
4
4
|
class m {
|
|
5
5
|
constructor(o, t) {
|
|
6
6
|
this.url = o, this.auth = t;
|
package/dist/index9.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@gardenfi/utils"),d=require("./index4.cjs"),i=require("./index3.cjs"),o={[i.BlockchainType.bitcoin]:{address:()=>"",tx:(e,t)=>new s.Url("tx",e).endpoint(t).toString()},[i.BlockchainType.tron]:{address:(e,t)=>`${e}/#/address/${t}`,tx:(e,t)=>`${e}/#/transaction/${t.slice(2)}`},[i.BlockchainType.starknet]:{address:(e,t)=>new s.Url("contract",e).endpoint(t).toString(),tx:(e,t)=>new s.Url("tx",e).endpoint(t).toString()},[i.BlockchainType.xrpl]:{address:(e,t)=>new s.Url("accounts",e).endpoint(t).toString(),tx:(e,t)=>new s.Url("transactions",e).endpoint(t).toString()},[i.BlockchainType.solana]:{address:(e,t,n)=>{let r=new s.Url("address",e).endpoint(t);return n===s.Network.TESTNET&&(r=r.addSearchParams({cluster:"devnet"})),r.toString()},tx:(e,t,n)=>{let r=new s.Url("tx",e).endpoint(t);return n===s.Network.TESTNET&&(r=r.addSearchParams({cluster:"devnet"})),r.toString()}},default:{address:(e,t)=>new s.Url("address",e).endpoint(t).toString(),tx:(e,t)=>new s.Url("tx",e).endpoint(t).toString()}};class a{constructor(t,n,r){this.explorerUrl=n,this.network=r,this.chainType=d.getBlockchainType(t)}static from(t,n,r){return new a(t,n,r)}getAddressLink(t){return(o[this.chainType]??o.default).address(this.explorerUrl,t,this.network)}getTxLink(t){const n=this.extractTxHash(t);return(o[this.chainType]??o.default).tx(this.explorerUrl,n,this.network)}extractTxHash(t){var n,r;return((r=(n=t.split(",").at(-1))==null?void 0:n.split(":").at(0))==null?void 0:r.trim())??""}}exports.ExplorerUrlBuilder=a;
|
package/dist/index9.js
CHANGED
|
@@ -1,31 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { Url as s, Network as a } from "@gardenfi/utils";
|
|
2
|
+
import { getBlockchainType as c } from "./index4.js";
|
|
3
|
+
import { BlockchainType as i } from "./index3.js";
|
|
4
|
+
const o = {
|
|
5
|
+
[i.bitcoin]: {
|
|
6
|
+
address: () => "",
|
|
7
|
+
tx: (r, t) => new s("tx", r).endpoint(t).toString()
|
|
8
|
+
},
|
|
9
|
+
[i.tron]: {
|
|
10
|
+
address: (r, t) => `${r}/#/address/${t}`,
|
|
11
|
+
tx: (r, t) => `${r}/#/transaction/${t.slice(2)}`
|
|
12
|
+
},
|
|
13
|
+
[i.starknet]: {
|
|
14
|
+
address: (r, t) => new s("contract", r).endpoint(t).toString(),
|
|
15
|
+
tx: (r, t) => new s("tx", r).endpoint(t).toString()
|
|
16
|
+
},
|
|
17
|
+
[i.xrpl]: {
|
|
18
|
+
address: (r, t) => new s("accounts", r).endpoint(t).toString(),
|
|
19
|
+
tx: (r, t) => new s("transactions", r).endpoint(t).toString()
|
|
20
|
+
},
|
|
21
|
+
[i.solana]: {
|
|
22
|
+
address: (r, t, n) => {
|
|
23
|
+
let e = new s("address", r).endpoint(t);
|
|
24
|
+
return n === a.TESTNET && (e = e.addSearchParams({ cluster: "devnet" })), e.toString();
|
|
25
|
+
},
|
|
26
|
+
tx: (r, t, n) => {
|
|
27
|
+
let e = new s("tx", r).endpoint(t);
|
|
28
|
+
return n === a.TESTNET && (e = e.addSearchParams({ cluster: "devnet" })), e.toString();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
default: {
|
|
32
|
+
address: (r, t) => new s("address", r).endpoint(t).toString(),
|
|
33
|
+
tx: (r, t) => new s("tx", r).endpoint(t).toString()
|
|
34
|
+
}
|
|
24
35
|
};
|
|
36
|
+
class d {
|
|
37
|
+
constructor(t, n, e) {
|
|
38
|
+
this.explorerUrl = n, this.network = e, this.chainType = c(t);
|
|
39
|
+
}
|
|
40
|
+
static from(t, n, e) {
|
|
41
|
+
return new d(t, n, e);
|
|
42
|
+
}
|
|
43
|
+
getAddressLink(t) {
|
|
44
|
+
return (o[this.chainType] ?? o.default).address(this.explorerUrl, t, this.network);
|
|
45
|
+
}
|
|
46
|
+
getTxLink(t) {
|
|
47
|
+
const n = this.extractTxHash(t);
|
|
48
|
+
return (o[this.chainType] ?? o.default).tx(this.explorerUrl, n, this.network);
|
|
49
|
+
}
|
|
50
|
+
extractTxHash(t) {
|
|
51
|
+
var n, e;
|
|
52
|
+
return ((e = (n = t.split(",").at(-1)) == null ? void 0 : n.split(":").at(0)) == null ? void 0 : e.trim()) ?? "";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
25
55
|
export {
|
|
26
|
-
|
|
27
|
-
s as ParseOrderStatus,
|
|
28
|
-
m as isCompleted,
|
|
29
|
-
a as isDeadlinePassed,
|
|
30
|
-
o as parseAction
|
|
56
|
+
d as ExplorerUrlBuilder
|
|
31
57
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './lib/constants/utils';
|
|
|
8
8
|
export { isSuiOrderResponse, ConstructUrl, discriminateOrderResponse, getOrderResponseType, isBitcoinOrderResponse, isEvmOrderResponse, isOrder, isSolanaOrderResponse, isStarknetOrderResponse, isXrplOrderResponse, } from './lib/utils';
|
|
9
9
|
export { ChainAsset } from './lib/chainAsset/chainAsset';
|
|
10
10
|
export type { ChainAssetString, AssetLike } from './lib/chainAsset/chainAsset';
|
|
11
|
+
export { ExplorerUrlBuilder } from './lib/ExplorerUrlBuilder/ExplorerUrlBuilder';
|
|
11
12
|
export { OrderAction, ParseOrderStatus, isCompleted, isDeadlinePassed, parseAction, } from './lib/orderStatus/orderStatus';
|
|
12
13
|
export { AssetManager } from './lib/assetManager/AssetManager';
|
|
13
14
|
export type { ApiChainData, ApiChainsResponse, AssetManagerState, BaseChainData, ChainData, FiatResponse, } from './lib/assetManager/types';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Network } from '@gardenfi/utils';
|
|
2
|
+
import { Chain } from '../constants/asset.types';
|
|
3
|
+
|
|
4
|
+
export declare class ExplorerUrlBuilder {
|
|
5
|
+
private readonly explorerUrl;
|
|
6
|
+
private readonly network;
|
|
7
|
+
private readonly chainType;
|
|
8
|
+
constructor(chain: Chain, explorerUrl: string, network: Network);
|
|
9
|
+
static from(chain: Chain, explorerUrl: string, network: Network): ExplorerUrlBuilder;
|
|
10
|
+
getAddressLink(address: string): string;
|
|
11
|
+
getTxLink(tx: string): string;
|
|
12
|
+
private extractTxHash;
|
|
13
|
+
}
|