@gardenfi/orderbook 3.1.2 → 3.1.3-beta.10
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 +55 -49
- 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 +14 -0
- package/dist/index14.cjs +1 -0
- package/dist/index14.js +31 -0
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +56 -57
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +1 -1
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +67 -31
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +21 -7
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +18 -14
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +54 -28
- package/dist/src/index.d.ts +3 -2
- package/dist/src/lib/ExplorerUrlBuilder/ExplorerUrlBuilder.d.ts +13 -0
- package/dist/src/lib/api.d.ts +1 -0
- package/dist/src/lib/constants/asset.d.ts +86 -3
- package/dist/src/lib/constants/asset.types.d.ts +3 -1
- package/dist/src/lib/constants/localnetConstants.d.ts +14 -0
- package/dist/src/lib/errors.d.ts +1 -0
- package/dist/src/lib/orderStatus/orderStatus.d.ts +1 -1
- package/dist/src/lib/orderbook/orderbook.types.d.ts +6 -0
- package/dist/src/lib/utils.d.ts +6 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index2.cjs"),n=require("./index3.cjs"),e=require("./index4.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index2.cjs"),n=require("./index3.cjs"),e=require("./index4.cjs"),s=require("./index5.cjs"),o=require("./index6.cjs"),t=require("./index7.cjs"),a=require("./index8.cjs"),l=require("./index9.cjs"),i=require("./index10.cjs"),c=require("./index11.cjs"),d=require("./index12.cjs");exports.Orderbook=r.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.isLightning=e.isLightning;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=s.ArbitrumLocalnet;exports.ETHStarknetLocalnetAsset=s.ETHStarknetLocalnetAsset;exports.EthereumLocalnet=s.EthereumLocalnet;exports.SOLSolanaLocalnetAsset=s.SOLSolanaLocalnetAsset;exports.STRKStarknetLocalnetAsset=s.STRKStarknetLocalnetAsset;exports.StarknetLocalnet=s.StarknetLocalnet;exports.USDCArbitrumLocalnetAsset=s.USDCArbitrumLocalnetAsset;exports.USDCEthereumLocalnetAsset=s.USDCEthereumLocalnetAsset;exports.WBTCArbitrumLocalnetAsset=s.WBTCArbitrumLocalnetAsset;exports.WBTCEthereumLocalnetAsset=s.WBTCEthereumLocalnetAsset;exports.bitcoinRegtestAsset=s.bitcoinRegtestAsset;exports.buildAssetsWithChain=o.buildAssetsWithChain;exports.ConstructUrl=t.ConstructUrl;exports.discriminateOrderResponse=t.discriminateOrderResponse;exports.getOrderResponseType=t.getOrderResponseType;exports.isBitcoinOrderResponse=t.isBitcoinOrderResponse;exports.isEvmOrderResponse=t.isEvmOrderResponse;exports.isLightningOrderResponse=t.isLightningOrderResponse;exports.isOrder=t.isOrder;exports.isSolanaOrderResponse=t.isSolanaOrderResponse;exports.isStarknetOrderResponse=t.isStarknetOrderResponse;exports.isSuiOrderResponse=t.isSuiOrderResponse;exports.isXrplOrderResponse=t.isXrplOrderResponse;exports.ChainAsset=a.ChainAsset;exports.ExplorerUrlBuilder=l.ExplorerUrlBuilder;exports.OrderAction=i.OrderAction;exports.ParseOrderStatus=i.ParseOrderStatus;exports.isCompleted=i.isCompleted;exports.isDeadlinePassed=i.isDeadlinePassed;exports.parseAction=i.parseAction;exports.AssetManager=c.AssetManager;exports.RouteValidator=d.RouteValidator;
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
import { Orderbook as
|
|
1
|
+
import { Orderbook as s } from "./index2.js";
|
|
2
2
|
import { BlockchainType as i } 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
|
|
4
|
-
import { ArbitrumLocalnet as
|
|
5
|
-
import { buildAssetsWithChain as
|
|
6
|
-
import { ConstructUrl as
|
|
7
|
-
import { ChainAsset as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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 u, isEvmNativeToken as L, isLightning as T, isLitecoin as f, isMainnet as k, isNativeToken as x, isSolana as R, isSolanaNativeToken as h, isSpark as g, isStarknet as C, isSui as E, isSuiNativeToken as B, isTron as b, isXrpl as v } from "./index4.js";
|
|
4
|
+
import { ArbitrumLocalnet as y, ETHStarknetLocalnetAsset as U, EthereumLocalnet as D, SOLSolanaLocalnetAsset as M, STRKStarknetLocalnetAsset as V, StarknetLocalnet as W, USDCArbitrumLocalnetAsset as K, USDCEthereumLocalnetAsset as P, WBTCArbitrumLocalnetAsset as X, WBTCEthereumLocalnetAsset as H, bitcoinRegtestAsset as I } from "./index5.js";
|
|
5
|
+
import { buildAssetsWithChain as j } from "./index6.js";
|
|
6
|
+
import { ConstructUrl as w, discriminateOrderResponse as z, getOrderResponseType as F, isBitcoinOrderResponse as G, isEvmOrderResponse as J, isLightningOrderResponse as Q, isOrder as Y, isSolanaOrderResponse as Z, isStarknetOrderResponse as $, isSuiOrderResponse as ee, isXrplOrderResponse as re } from "./index7.js";
|
|
7
|
+
import { ChainAsset as te } from "./index8.js";
|
|
8
|
+
import { ExplorerUrlBuilder as oe } from "./index9.js";
|
|
9
|
+
import { OrderAction as ae, ParseOrderStatus as pe, isCompleted as le, isDeadlinePassed as ce, parseAction as de } from "./index10.js";
|
|
10
|
+
import { AssetManager as Se } from "./index11.js";
|
|
11
|
+
import { RouteValidator as Oe } from "./index12.js";
|
|
11
12
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
y as ArbitrumLocalnet,
|
|
14
|
+
Se as AssetManager,
|
|
14
15
|
n as Assets,
|
|
15
16
|
i as BlockchainType,
|
|
16
|
-
|
|
17
|
+
te as ChainAsset,
|
|
17
18
|
a as Chains,
|
|
18
19
|
p as Config,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
w as ConstructUrl,
|
|
21
|
+
U as ETHStarknetLocalnetAsset,
|
|
22
|
+
D as EthereumLocalnet,
|
|
23
|
+
oe as ExplorerUrlBuilder,
|
|
22
24
|
l as NATIVE_TOKENS,
|
|
23
|
-
|
|
25
|
+
ae as OrderAction,
|
|
24
26
|
c as OrderLifecycle,
|
|
25
27
|
d as OrderStatus,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
m as
|
|
28
|
+
s as Orderbook,
|
|
29
|
+
pe as ParseOrderStatus,
|
|
30
|
+
Oe as RouteValidator,
|
|
31
|
+
M as SOLSolanaLocalnetAsset,
|
|
32
|
+
V as STRKStarknetLocalnetAsset,
|
|
33
|
+
W as StarknetLocalnet,
|
|
34
|
+
K as USDCArbitrumLocalnetAsset,
|
|
35
|
+
P as USDCEthereumLocalnetAsset,
|
|
36
|
+
X as WBTCArbitrumLocalnetAsset,
|
|
37
|
+
H as WBTCEthereumLocalnetAsset,
|
|
38
|
+
I as bitcoinRegtestAsset,
|
|
39
|
+
j as buildAssetsWithChain,
|
|
40
|
+
z as discriminateOrderResponse,
|
|
41
|
+
m as getBlockchainType,
|
|
42
|
+
F as getOrderResponseType,
|
|
43
|
+
S as is,
|
|
40
44
|
A as isAlpenSignet,
|
|
41
45
|
O as isBitcoin,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
G as isBitcoinOrderResponse,
|
|
47
|
+
le as isCompleted,
|
|
48
|
+
ce as isDeadlinePassed,
|
|
49
|
+
u as isEVM,
|
|
50
|
+
L as isEvmNativeToken,
|
|
51
|
+
J as isEvmOrderResponse,
|
|
52
|
+
T as isLightning,
|
|
53
|
+
Q as isLightningOrderResponse,
|
|
48
54
|
f as isLitecoin,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
k as isMainnet,
|
|
56
|
+
x as isNativeToken,
|
|
57
|
+
Y as isOrder,
|
|
52
58
|
R as isSolana,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
h as isSolanaNativeToken,
|
|
60
|
+
Z as isSolanaOrderResponse,
|
|
61
|
+
g as isSpark,
|
|
56
62
|
C as isStarknet,
|
|
57
|
-
|
|
63
|
+
$ as isStarknetOrderResponse,
|
|
58
64
|
E as isSui,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
B as isSuiNativeToken,
|
|
66
|
+
ee as isSuiOrderResponse,
|
|
67
|
+
b as isTron,
|
|
68
|
+
v as isXrpl,
|
|
69
|
+
re as isXrplOrderResponse,
|
|
70
|
+
de as parseAction
|
|
65
71
|
};
|
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"),s=t=>{const{source_swap:r,destination_swap:n}=t;if(n.redeem_tx_hash)return Number(n.redeem_block_number)||e.isBitcoin(n.chain)?e.OrderStatus.Redeemed:e.OrderStatus.RedeemDetected;if(e.isBitcoin(n.chain)&&r.redeem_tx_hash&&!n.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(n.refund_tx_hash)return e.OrderStatus.AwaitingRefund;const d=u(t.deadline);return n.initiate_tx_hash?e.OrderStatus.AwaitingRedeem:r.initiate_tx_hash?d?e.OrderStatus.AwaitingRefund:Number(r.initiate_block_number)?e.OrderStatus.Initiated:e.OrderStatus.InitiateDetected:d?e.OrderStatus.Expired:e.OrderStatus.Created},u=t=>{const r=Math.round(Date.now()/1e3);return console.log("now:",r),r>t},i=t=>{const r=s(t);return r===e.OrderStatus.Redeemed||r===e.OrderStatus.Refunded||r===e.OrderStatus.Expired};var a=(t=>(t.Initiate="Initiate",t.PostRefundSACP="PostRefundSACP",t.Redeem="Redeem",t.Refund="Refund",t.Idle="Idle",t))(a||{});const _=t=>{const{source_swap:r,destination_swap:n}=t;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"};exports.OrderAction=a;exports.ParseOrderStatus=s;exports.isCompleted=i;exports.isDeadlinePassed=u;exports.parseAction=_;
|
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 u = (t) => {
|
|
3
|
+
const { source_swap: n, destination_swap: r } = t;
|
|
4
|
+
if (r.redeem_tx_hash)
|
|
5
|
+
return Number(r.redeem_block_number) ? e.Redeemed : d(r.chain) ? e.Redeemed : e.RedeemDetected;
|
|
6
|
+
if (d(r.chain) && n.redeem_tx_hash && !r.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 (r.refund_tx_hash) return e.AwaitingRefund;
|
|
11
|
+
const i = s(t.deadline);
|
|
12
|
+
return r.initiate_tx_hash ? e.AwaitingRedeem : n.initiate_tx_hash ? i ? e.AwaitingRefund : Number(n.initiate_block_number) ? e.Initiated : e.InitiateDetected : i ? e.Expired : e.Created;
|
|
13
|
+
}, s = (t) => {
|
|
14
|
+
const n = Math.round(Date.now() / 1e3);
|
|
15
|
+
return console.log("now:", n), n > t;
|
|
16
|
+
}, f = (t) => {
|
|
17
|
+
const n = u(t);
|
|
18
|
+
return n === e.Redeemed || n === e.Refunded || n === e.Expired;
|
|
19
|
+
};
|
|
20
|
+
var a = /* @__PURE__ */ ((t) => (t.Initiate = "Initiate", t.PostRefundSACP = "PostRefundSACP", t.Redeem = "Redeem", t.Refund = "Refund", t.Idle = "Idle", t))(a || {});
|
|
21
|
+
const m = (t) => {
|
|
22
|
+
const { source_swap: n, destination_swap: r } = t;
|
|
23
|
+
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";
|
|
24
|
+
};
|
|
186
25
|
export {
|
|
187
|
-
|
|
26
|
+
a as OrderAction,
|
|
27
|
+
u as ParseOrderStatus,
|
|
28
|
+
f as isCompleted,
|
|
29
|
+
s as isDeadlinePassed,
|
|
30
|
+
m 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("./index14.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;
|