@kaleidorg/wallet-engine 1.0.0-beta.36 → 1.0.0-beta.38
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/adapters/RgbAdapter.d.ts +70 -28
- package/dist/adapters/RgbAdapter.d.ts.map +1 -1
- package/dist/adapters/RgbAdapter.js +463 -371
- package/dist/adapters/RgbAdapter.js.map +1 -1
- package/dist/adapters/flashnet.d.ts +14 -0
- package/dist/adapters/flashnet.d.ts.map +1 -0
- package/dist/adapters/flashnet.js +14 -0
- package/dist/adapters/flashnet.js.map +1 -0
- package/dist/adapters/rgb.d.ts +11 -0
- package/dist/adapters/rgb.d.ts.map +1 -0
- package/dist/adapters/rgb.js +11 -0
- package/dist/adapters/rgb.js.map +1 -0
- package/dist/lib/flashnet-client-manager.d.ts +25 -8
- package/dist/lib/flashnet-client-manager.d.ts.map +1 -1
- package/dist/lib/flashnet-client-manager.js +97 -13
- package/dist/lib/flashnet-client-manager.js.map +1 -1
- package/dist/lib/kaleido-client-manager.d.ts +38 -3
- package/dist/lib/kaleido-client-manager.d.ts.map +1 -1
- package/dist/lib/kaleido-client-manager.js +79 -10
- package/dist/lib/kaleido-client-manager.js.map +1 -1
- package/dist/lib/orchestra-client.d.ts +149 -0
- package/dist/lib/orchestra-client.d.ts.map +1 -0
- package/dist/lib/orchestra-client.js +178 -0
- package/dist/lib/orchestra-client.js.map +1 -0
- package/dist/lib/rgb-converters.d.ts +62 -0
- package/dist/lib/rgb-converters.d.ts.map +1 -0
- package/dist/lib/rgb-converters.js +179 -0
- package/dist/lib/rgb-converters.js.map +1 -0
- package/dist/lib/rgb-fee-policy.d.ts +41 -0
- package/dist/lib/rgb-fee-policy.d.ts.map +1 -0
- package/dist/lib/rgb-fee-policy.js +52 -0
- package/dist/lib/rgb-fee-policy.js.map +1 -0
- package/dist/lib/rgb-helpers.d.ts +54 -0
- package/dist/lib/rgb-helpers.d.ts.map +1 -0
- package/dist/lib/rgb-helpers.js +89 -0
- package/dist/lib/rgb-helpers.js.map +1 -0
- package/dist/types/flashnet.d.ts +20 -0
- package/dist/types/flashnet.d.ts.map +1 -1
- package/dist/types/flashnet.js +34 -6
- package/dist/types/flashnet.js.map +1 -1
- package/package.json +9 -1
|
@@ -1,54 +1,123 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* KaleidoClient Manager
|
|
3
|
-
* Singleton manager for KaleidoClient lifecycle.
|
|
4
|
-
*
|
|
3
|
+
* Singleton manager for KaleidoClient lifecycle (RGB Lightning node + Kaleidoswap maker).
|
|
4
|
+
*
|
|
5
|
+
* Transport is either "http" (kaleido-sdk's HTTP RlnClient) or "nwc" (an
|
|
6
|
+
* RLN-shaped client over Nostr Wallet Connect). The NWC implementation carries
|
|
7
|
+
* a nostr/relay dependency, so it is NOT bundled here — the consumer injects a
|
|
8
|
+
* factory via `setNwcRlnClientFactory()` (the extension supplies its NwcRlnClient;
|
|
9
|
+
* React Native / node hosts that don't use NWC never register one).
|
|
5
10
|
*/
|
|
6
|
-
import { KaleidoClient } from
|
|
11
|
+
import { KaleidoClient } from "kaleido-sdk";
|
|
12
|
+
import { log } from "./log.js";
|
|
13
|
+
import { ProtocolError } from "../types/base.js";
|
|
14
|
+
let nwcRlnClientFactory = null;
|
|
15
|
+
/**
|
|
16
|
+
* Register the NWC-backed RLN client factory. The extension calls this once at
|
|
17
|
+
* startup with `(uri) => new NwcRlnClient(uri)`. Without it, transport "nwc" throws.
|
|
18
|
+
*/
|
|
19
|
+
export function setNwcRlnClientFactory(factory) {
|
|
20
|
+
nwcRlnClientFactory = factory;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A MakerClient stand-in used in NWC mode when no maker URL is configured.
|
|
24
|
+
* Every access rejects with MAKER_NOT_CONFIGURED so swap flows fail loudly
|
|
25
|
+
* instead of silently hitting the wrong endpoint.
|
|
26
|
+
*/
|
|
27
|
+
function createMakerStub() {
|
|
28
|
+
return new Proxy({}, {
|
|
29
|
+
get() {
|
|
30
|
+
return () => Promise.reject(new ProtocolError("Maker API not configured. Set a maker URL to enable swaps.", "RGB_LN", "MAKER_NOT_CONFIGURED"));
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
7
34
|
class KaleidoClientManager {
|
|
8
35
|
constructor() {
|
|
9
36
|
this.client = null;
|
|
10
37
|
this.config = null;
|
|
38
|
+
/** Held only in NWC mode so reset() can tear down the relay pool. */
|
|
39
|
+
this.nwcRln = null;
|
|
11
40
|
}
|
|
41
|
+
/** Initialize the KaleidoClient with configuration. */
|
|
12
42
|
initialize(config) {
|
|
43
|
+
// Tear down any prior NWC relay pool before replacing the client.
|
|
44
|
+
this.nwcRln?.close();
|
|
45
|
+
this.nwcRln = null;
|
|
13
46
|
this.config = config;
|
|
47
|
+
if (config.transport === "nwc") {
|
|
48
|
+
if (!config.nwcUri) {
|
|
49
|
+
throw new ProtocolError("NWC connection string is required for transport 'nwc'", "RGB_LN", "NODE_NOT_CONFIGURED");
|
|
50
|
+
}
|
|
51
|
+
if (!nwcRlnClientFactory) {
|
|
52
|
+
throw new ProtocolError("NWC transport is not available: no NwcRlnClient factory registered. Call setNwcRlnClientFactory() at startup.", "RGB_LN", "NODE_NOT_CONFIGURED");
|
|
53
|
+
}
|
|
54
|
+
// Compose a KaleidoClient-shaped object: NWC-backed `.rln`, plus an
|
|
55
|
+
// optional HTTP `.maker` (a separate, transport-independent concern).
|
|
56
|
+
const rln = nwcRlnClientFactory(config.nwcUri);
|
|
57
|
+
this.nwcRln = rln;
|
|
58
|
+
const hasMaker = !!config.baseUrl;
|
|
59
|
+
const maker = hasMaker
|
|
60
|
+
? KaleidoClient.create({ baseUrl: config.baseUrl, timeout: config.timeout }).maker
|
|
61
|
+
: createMakerStub();
|
|
62
|
+
this.client = {
|
|
63
|
+
rln,
|
|
64
|
+
maker,
|
|
65
|
+
hasNode: () => true,
|
|
66
|
+
hasMaker: () => hasMaker,
|
|
67
|
+
close: async () => rln.close(),
|
|
68
|
+
};
|
|
69
|
+
log.info("[KaleidoClientManager] Initialized NWC transport:", { hasMakerUrl: hasMaker });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
14
72
|
this.client = KaleidoClient.create({
|
|
15
73
|
baseUrl: config.baseUrl,
|
|
16
74
|
nodeUrl: config.nodeUrl,
|
|
17
75
|
apiKey: config.apiKey,
|
|
18
76
|
timeout: config.timeout,
|
|
19
77
|
});
|
|
20
|
-
|
|
78
|
+
log.info("[KaleidoClientManager] Initialized with config:", {
|
|
21
79
|
baseUrl: config.baseUrl,
|
|
22
80
|
hasNodeUrl: !!config.nodeUrl,
|
|
23
81
|
hasApiKey: !!config.apiKey,
|
|
24
82
|
});
|
|
25
83
|
}
|
|
84
|
+
/** @throws if not initialized */
|
|
26
85
|
getClient() {
|
|
27
86
|
if (!this.client) {
|
|
28
|
-
throw new Error(
|
|
87
|
+
throw new Error("KaleidoClient not initialized. Call initialize() first.");
|
|
29
88
|
}
|
|
30
89
|
return this.client;
|
|
31
90
|
}
|
|
32
91
|
isInitialized() {
|
|
33
92
|
return this.client !== null;
|
|
34
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if a node is reachable — either an HTTP node URL or an NWC link.
|
|
96
|
+
* Gates almost every RLN operation in the adapter.
|
|
97
|
+
*/
|
|
35
98
|
hasNode() {
|
|
36
|
-
return !!this.config?.nodeUrl;
|
|
99
|
+
return !!this.config?.nodeUrl || this.config?.transport === "nwc";
|
|
37
100
|
}
|
|
38
101
|
getConfig() {
|
|
39
102
|
return this.config;
|
|
40
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Reset the client (disconnect and clear). Tears down the NWC relay pool
|
|
106
|
+
* when running the NWC transport so we don't leak sockets on reconnect.
|
|
107
|
+
*/
|
|
41
108
|
reset() {
|
|
109
|
+
this.nwcRln?.close();
|
|
110
|
+
this.nwcRln = null;
|
|
42
111
|
this.client = null;
|
|
43
112
|
this.config = null;
|
|
44
|
-
|
|
113
|
+
log.info("[KaleidoClientManager] Reset complete");
|
|
45
114
|
}
|
|
115
|
+
/** Update configuration (re-initializes the client). */
|
|
46
116
|
updateConfig(config) {
|
|
47
117
|
if (!this.config) {
|
|
48
|
-
throw new Error(
|
|
118
|
+
throw new Error("Cannot update config: client not initialized");
|
|
49
119
|
}
|
|
50
|
-
|
|
51
|
-
this.initialize(newConfig);
|
|
120
|
+
this.initialize({ ...this.config, ...config });
|
|
52
121
|
}
|
|
53
122
|
}
|
|
54
123
|
export const kaleidoClientManager = new KaleidoClientManager();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kaleido-client-manager.js","sourceRoot":"","sources":["../../src/lib/kaleido-client-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"kaleido-client-manager.js","sourceRoot":"","sources":["../../src/lib/kaleido-client-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAuB9C,IAAI,mBAAmB,GAA+B,IAAI,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA4B;IACjE,mBAAmB,GAAG,OAAO,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe;IACtB,OAAO,IAAI,KAAK,CACd,EAAE,EACF;QACE,GAAG;YACD,OAAO,GAAG,EAAE,CACV,OAAO,CAAC,MAAM,CACZ,IAAI,aAAa,CACf,4DAA4D,EAC5D,QAAQ,EACR,sBAAsB,CACvB,CACF,CAAC;QACN,CAAC;KACF,CACwB,CAAC;AAC9B,CAAC;AAED,MAAM,oBAAoB;IAA1B;QACU,WAAM,GAAyB,IAAI,CAAC;QACpC,WAAM,GAA+B,IAAI,CAAC;QAClD,qEAAqE;QAC7D,WAAM,GAA4B,IAAI,CAAC;IAqGjD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AAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flashnet Orchestra REST API Client
|
|
3
|
+
*
|
|
4
|
+
* Cross-chain swap orchestration: stablecoins (USDC/USDT) and native assets
|
|
5
|
+
* (ETH/SOL/TRX) on EVM/Solana/Tron ↔ BTC/USDB on Spark.
|
|
6
|
+
*
|
|
7
|
+
* API docs: https://docs.flashnet.xyz/products/orchestration/overview
|
|
8
|
+
* Base URL: https://orchestration.flashnet.xyz
|
|
9
|
+
*
|
|
10
|
+
* Ported from rate-extension/src/protocols/spark/orchestra-client.ts. The API
|
|
11
|
+
* key is NOT read from a build-time env var here — the engine is platform-
|
|
12
|
+
* agnostic, so the consumer injects it once at startup via `setOrchestraApiKey()`
|
|
13
|
+
* (the extension supplies its inlined `VITE_FLASHNET_ORCHESTRA_KEY`).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Register the Orchestra API key. Call once at startup. Warns if given an
|
|
17
|
+
* empty value so a misconfigured build is obvious instead of surfacing as a
|
|
18
|
+
* runtime 401 that looks like a network failure.
|
|
19
|
+
*/
|
|
20
|
+
export declare function setOrchestraApiKey(key: string | null | undefined): void;
|
|
21
|
+
/**
|
|
22
|
+
* Stable marker embedded in the auth-error message. Only `Error.message`
|
|
23
|
+
* survives the background-SW → UI message boundary (see background-protocol.ts:
|
|
24
|
+
* `sendResponse({ error: error?.message })`), so the UI matches on this token
|
|
25
|
+
* rather than `instanceof OrchestraAuthError`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const ORCHESTRA_AUTH_ERROR_CODE = "ORCHESTRA_AUTH_FAILED";
|
|
28
|
+
/**
|
|
29
|
+
* Thrown when an authed Orchestra call fails due to a missing/invalid API key
|
|
30
|
+
* (HTTP 401/403). Callers can detect this to show a "Bridge unavailable /
|
|
31
|
+
* not configured" message instead of a generic "Quote failed".
|
|
32
|
+
*/
|
|
33
|
+
export declare class OrchestraAuthError extends Error {
|
|
34
|
+
readonly status: number;
|
|
35
|
+
constructor(status: number);
|
|
36
|
+
}
|
|
37
|
+
export interface OrchestraRouteAsset {
|
|
38
|
+
chain: string;
|
|
39
|
+
asset: string;
|
|
40
|
+
contractAddress?: string;
|
|
41
|
+
decimals: number;
|
|
42
|
+
chainId?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface OrchestraRoute {
|
|
45
|
+
sourceChain: string;
|
|
46
|
+
sourceAsset: string;
|
|
47
|
+
destinationChain: string;
|
|
48
|
+
destinationAsset: string;
|
|
49
|
+
source?: OrchestraRouteAsset;
|
|
50
|
+
destination?: OrchestraRouteAsset;
|
|
51
|
+
}
|
|
52
|
+
export interface OrchestraEstimate {
|
|
53
|
+
estimatedOut: string;
|
|
54
|
+
feeAmount: string;
|
|
55
|
+
feeBps: number;
|
|
56
|
+
totalFeeAmount: string;
|
|
57
|
+
feeAsset: string;
|
|
58
|
+
route: OrchestraRoute;
|
|
59
|
+
}
|
|
60
|
+
export interface OrchestraQuote {
|
|
61
|
+
quoteId: string;
|
|
62
|
+
depositAddress: string;
|
|
63
|
+
amountIn: string;
|
|
64
|
+
estimatedOut: string;
|
|
65
|
+
feeAmount: string;
|
|
66
|
+
feeBps: number;
|
|
67
|
+
totalFeeAmount: string;
|
|
68
|
+
feeAsset: string;
|
|
69
|
+
route: OrchestraRoute;
|
|
70
|
+
expiresAt: string;
|
|
71
|
+
}
|
|
72
|
+
export type OrchestraOrderStatus = 'processing' | 'confirming' | 'bridging' | 'swapping' | 'awaiting_approval' | 'refunding' | 'delivering' | 'completed' | 'failed' | 'refunded';
|
|
73
|
+
export interface OrchestraOrderStage {
|
|
74
|
+
stage: string;
|
|
75
|
+
timestamp: string;
|
|
76
|
+
}
|
|
77
|
+
export interface OrchestraOrder {
|
|
78
|
+
id: string;
|
|
79
|
+
quoteId: string;
|
|
80
|
+
status: OrchestraOrderStatus;
|
|
81
|
+
amountIn?: string;
|
|
82
|
+
amountOut?: string;
|
|
83
|
+
depositAddress?: string;
|
|
84
|
+
recipientAddress?: string;
|
|
85
|
+
route?: OrchestraRoute;
|
|
86
|
+
stages?: OrchestraOrderStage[];
|
|
87
|
+
createdAt?: string;
|
|
88
|
+
updatedAt?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface OrchestraOrderLookup {
|
|
91
|
+
quote: OrchestraQuote | null;
|
|
92
|
+
order: OrchestraOrder | null;
|
|
93
|
+
stages?: OrchestraOrderStage[];
|
|
94
|
+
}
|
|
95
|
+
export interface CreateQuoteParams {
|
|
96
|
+
sourceChain: string;
|
|
97
|
+
sourceAsset: string;
|
|
98
|
+
destinationChain: string;
|
|
99
|
+
destinationAsset: string;
|
|
100
|
+
amount: string;
|
|
101
|
+
recipientAddress: string;
|
|
102
|
+
slippageBps?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface SubmitOrderParams {
|
|
105
|
+
quoteId: string;
|
|
106
|
+
txHash?: string;
|
|
107
|
+
sourceAddress?: string;
|
|
108
|
+
sparkTxHash?: string;
|
|
109
|
+
sourceSparkAddress?: string;
|
|
110
|
+
bitcoinTxid?: string;
|
|
111
|
+
bitcoinVout?: number;
|
|
112
|
+
}
|
|
113
|
+
export interface EstimateParams {
|
|
114
|
+
sourceChain: string;
|
|
115
|
+
sourceAsset: string;
|
|
116
|
+
destinationChain: string;
|
|
117
|
+
destinationAsset: string;
|
|
118
|
+
amount: string;
|
|
119
|
+
}
|
|
120
|
+
/** List all available cross-chain routes. No auth required. */
|
|
121
|
+
export declare function getRoutes(): Promise<OrchestraRoute[]>;
|
|
122
|
+
/** Get a lightweight price estimate. No auth required. */
|
|
123
|
+
export declare function getEstimate(params: EstimateParams): Promise<OrchestraEstimate>;
|
|
124
|
+
/** Create a durable quote with deposit address. Auth required. TTL ~30 min. */
|
|
125
|
+
export declare function createQuote(params: CreateQuoteParams): Promise<OrchestraQuote>;
|
|
126
|
+
/** Look up a quote and its associated order (if any). Auth required. */
|
|
127
|
+
export declare function getOrder(quoteId: string): Promise<OrchestraOrderLookup>;
|
|
128
|
+
/** Submit deposit proof to create an order from a quote. Auth required. */
|
|
129
|
+
export declare function submitOrder(params: SubmitOrderParams): Promise<{
|
|
130
|
+
orderId: string;
|
|
131
|
+
status: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Check order status by ID, quoteId, or txHash.
|
|
135
|
+
*
|
|
136
|
+
* The Flashnet orchestration `/v1/orchestration/status` endpoint historically
|
|
137
|
+
* returned a flat `OrchestraOrder`, but the live API now wraps the response
|
|
138
|
+
* as `{ order: OrchestraOrder, stages?: OrchestraOrderStage[] }` (same shape
|
|
139
|
+
* as `/order`). Both forms have been observed in the wild — we unwrap defensively
|
|
140
|
+
* so the bridge tracking poller sees a real `status` field either way.
|
|
141
|
+
* Without this, `status` is `undefined`, the poller silently keeps showing
|
|
142
|
+
* the stale local status (e.g. "swapping") even after the order completes.
|
|
143
|
+
*/
|
|
144
|
+
export declare function getStatus(query: {
|
|
145
|
+
id?: string;
|
|
146
|
+
quoteId?: string;
|
|
147
|
+
txHash?: string;
|
|
148
|
+
}): Promise<OrchestraOrder>;
|
|
149
|
+
//# sourceMappingURL=orchestra-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestra-client.d.ts","sourceRoot":"","sources":["../../src/lib/orchestra-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAQvE;AAED;;;;;GAKG;AACH,eAAO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,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;CACf;AAuDD,+DAA+D;AAC/D,wBAAsB,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAO3D;AAED,0DAA0D;AAC1D,wBAAsB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUpF;AAED,+EAA+E;AAC/E,wBAAsB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAcpF;AAED,wEAAwE;AACxE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAK7E;AAED,2EAA2E;AAC3E,wBAAsB,WAAW,CAC/B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE;IACrC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiB1B"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flashnet Orchestra REST API Client
|
|
3
|
+
*
|
|
4
|
+
* Cross-chain swap orchestration: stablecoins (USDC/USDT) and native assets
|
|
5
|
+
* (ETH/SOL/TRX) on EVM/Solana/Tron ↔ BTC/USDB on Spark.
|
|
6
|
+
*
|
|
7
|
+
* API docs: https://docs.flashnet.xyz/products/orchestration/overview
|
|
8
|
+
* Base URL: https://orchestration.flashnet.xyz
|
|
9
|
+
*
|
|
10
|
+
* Ported from rate-extension/src/protocols/spark/orchestra-client.ts. The API
|
|
11
|
+
* key is NOT read from a build-time env var here — the engine is platform-
|
|
12
|
+
* agnostic, so the consumer injects it once at startup via `setOrchestraApiKey()`
|
|
13
|
+
* (the extension supplies its inlined `VITE_FLASHNET_ORCHESTRA_KEY`).
|
|
14
|
+
*/
|
|
15
|
+
import { log } from './log.js';
|
|
16
|
+
const BASE_URL = 'https://orchestration.flashnet.xyz';
|
|
17
|
+
/**
|
|
18
|
+
* Orchestra API key, injected by the consumer. PUBLIC-by-design in the
|
|
19
|
+
* extension (shipped in the bundle) — the seam simply keeps the build-time
|
|
20
|
+
* env-var read out of the engine. Empty until `setOrchestraApiKey()` runs;
|
|
21
|
+
* every authed endpoint (createQuote/getOrder/submitOrder/getStatus) 401s
|
|
22
|
+
* without it.
|
|
23
|
+
*/
|
|
24
|
+
let apiKey = '';
|
|
25
|
+
/**
|
|
26
|
+
* Register the Orchestra API key. Call once at startup. Warns if given an
|
|
27
|
+
* empty value so a misconfigured build is obvious instead of surfacing as a
|
|
28
|
+
* runtime 401 that looks like a network failure.
|
|
29
|
+
*/
|
|
30
|
+
export function setOrchestraApiKey(key) {
|
|
31
|
+
apiKey = key ?? '';
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
log.warn('[Orchestra] API key is empty — Bridge quote/submit calls will fail with HTTP 401. ' +
|
|
34
|
+
'Pass a key to setOrchestraApiKey() at startup.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stable marker embedded in the auth-error message. Only `Error.message`
|
|
39
|
+
* survives the background-SW → UI message boundary (see background-protocol.ts:
|
|
40
|
+
* `sendResponse({ error: error?.message })`), so the UI matches on this token
|
|
41
|
+
* rather than `instanceof OrchestraAuthError`.
|
|
42
|
+
*/
|
|
43
|
+
export const ORCHESTRA_AUTH_ERROR_CODE = 'ORCHESTRA_AUTH_FAILED';
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when an authed Orchestra call fails due to a missing/invalid API key
|
|
46
|
+
* (HTTP 401/403). Callers can detect this to show a "Bridge unavailable /
|
|
47
|
+
* not configured" message instead of a generic "Quote failed".
|
|
48
|
+
*/
|
|
49
|
+
export class OrchestraAuthError extends Error {
|
|
50
|
+
constructor(status) {
|
|
51
|
+
super(`${ORCHESTRA_AUTH_ERROR_CODE}: Bridge is not configured or unavailable. ` +
|
|
52
|
+
'The cross-chain service rejected the request (authentication failed).');
|
|
53
|
+
this.name = 'OrchestraAuthError';
|
|
54
|
+
this.status = status;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Client
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
function authHeaders() {
|
|
61
|
+
if (!apiKey)
|
|
62
|
+
return {};
|
|
63
|
+
return { Authorization: `Bearer ${apiKey}` };
|
|
64
|
+
}
|
|
65
|
+
function idempotencyHeader(prefix) {
|
|
66
|
+
return { 'X-Idempotency-Key': `${prefix}:${crypto.randomUUID()}` };
|
|
67
|
+
}
|
|
68
|
+
async function request(method, path, opts) {
|
|
69
|
+
const url = new URL(path, BASE_URL);
|
|
70
|
+
if (opts?.params) {
|
|
71
|
+
for (const [k, v] of Object.entries(opts.params)) {
|
|
72
|
+
if (v !== undefined)
|
|
73
|
+
url.searchParams.set(k, v);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
77
|
+
if (opts?.auth)
|
|
78
|
+
Object.assign(headers, authHeaders());
|
|
79
|
+
if (opts?.idempotency)
|
|
80
|
+
Object.assign(headers, idempotencyHeader(opts.idempotency));
|
|
81
|
+
const res = await fetch(url.toString(), {
|
|
82
|
+
method,
|
|
83
|
+
headers,
|
|
84
|
+
body: opts?.body ? JSON.stringify(opts.body) : undefined,
|
|
85
|
+
});
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
const text = await res.text().catch(() => '');
|
|
88
|
+
// An auth failure on an authed call almost always means the API key was
|
|
89
|
+
// not injected (or is invalid). Throw a specific error so the UI can
|
|
90
|
+
// distinguish "Bridge not configured" from a transient quote error.
|
|
91
|
+
if (opts?.auth && (res.status === 401 || res.status === 403)) {
|
|
92
|
+
throw new OrchestraAuthError(res.status);
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Orchestra API ${method} ${path} failed (${res.status}): ${text}`);
|
|
95
|
+
}
|
|
96
|
+
return res.json();
|
|
97
|
+
}
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Public API
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
/** List all available cross-chain routes. No auth required. */
|
|
102
|
+
export async function getRoutes() {
|
|
103
|
+
const res = await request('GET', '/v1/orchestration/routes');
|
|
104
|
+
// API wraps in { routes: [...] }
|
|
105
|
+
return Array.isArray(res) ? res : res.routes;
|
|
106
|
+
}
|
|
107
|
+
/** Get a lightweight price estimate. No auth required. */
|
|
108
|
+
export async function getEstimate(params) {
|
|
109
|
+
return request('GET', '/v1/orchestration/estimate', {
|
|
110
|
+
params: {
|
|
111
|
+
sourceChain: params.sourceChain,
|
|
112
|
+
sourceAsset: params.sourceAsset,
|
|
113
|
+
destinationChain: params.destinationChain,
|
|
114
|
+
destinationAsset: params.destinationAsset,
|
|
115
|
+
amount: params.amount,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** Create a durable quote with deposit address. Auth required. TTL ~30 min. */
|
|
120
|
+
export async function createQuote(params) {
|
|
121
|
+
return request('POST', '/v1/orchestration/quote', {
|
|
122
|
+
body: {
|
|
123
|
+
sourceChain: params.sourceChain,
|
|
124
|
+
sourceAsset: params.sourceAsset,
|
|
125
|
+
destinationChain: params.destinationChain,
|
|
126
|
+
destinationAsset: params.destinationAsset,
|
|
127
|
+
amount: params.amount,
|
|
128
|
+
recipientAddress: params.recipientAddress,
|
|
129
|
+
slippageBps: params.slippageBps ?? 100,
|
|
130
|
+
},
|
|
131
|
+
auth: true,
|
|
132
|
+
idempotency: 'quote:create',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/** Look up a quote and its associated order (if any). Auth required. */
|
|
136
|
+
export async function getOrder(quoteId) {
|
|
137
|
+
return request('GET', '/v1/orchestration/order', {
|
|
138
|
+
params: { quoteId },
|
|
139
|
+
auth: true,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/** Submit deposit proof to create an order from a quote. Auth required. */
|
|
143
|
+
export async function submitOrder(params) {
|
|
144
|
+
return request('POST', '/v1/orchestration/submit', {
|
|
145
|
+
body: params,
|
|
146
|
+
auth: true,
|
|
147
|
+
idempotency: 'submit',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check order status by ID, quoteId, or txHash.
|
|
152
|
+
*
|
|
153
|
+
* The Flashnet orchestration `/v1/orchestration/status` endpoint historically
|
|
154
|
+
* returned a flat `OrchestraOrder`, but the live API now wraps the response
|
|
155
|
+
* as `{ order: OrchestraOrder, stages?: OrchestraOrderStage[] }` (same shape
|
|
156
|
+
* as `/order`). Both forms have been observed in the wild — we unwrap defensively
|
|
157
|
+
* so the bridge tracking poller sees a real `status` field either way.
|
|
158
|
+
* Without this, `status` is `undefined`, the poller silently keeps showing
|
|
159
|
+
* the stale local status (e.g. "swapping") even after the order completes.
|
|
160
|
+
*/
|
|
161
|
+
export async function getStatus(query) {
|
|
162
|
+
const params = {};
|
|
163
|
+
if (query.id)
|
|
164
|
+
params.id = query.id;
|
|
165
|
+
else if (query.quoteId)
|
|
166
|
+
params.quoteId = query.quoteId;
|
|
167
|
+
else if (query.txHash)
|
|
168
|
+
params.txHash = query.txHash;
|
|
169
|
+
const raw = await request('GET', '/v1/orchestration/status', { params, auth: true });
|
|
170
|
+
// Wrapped shape: pull the order, attach stages so callers can use them
|
|
171
|
+
// for finer-grained progress UI without a second request.
|
|
172
|
+
if (raw && typeof raw === 'object' && 'order' in raw && raw.order) {
|
|
173
|
+
const wrapped = raw;
|
|
174
|
+
return wrapped.stages ? { ...wrapped.order, stages: wrapped.stages } : wrapped.order;
|
|
175
|
+
}
|
|
176
|
+
return raw;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=orchestra-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestra-client.js","sourceRoot":"","sources":["../../src/lib/orchestra-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,MAAM,QAAQ,GAAG,oCAAoC,CAAA;AAErD;;;;;;GAMG;AACH,IAAI,MAAM,GAAG,EAAE,CAAA;AAEf;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAA8B;IAC/D,MAAM,GAAG,GAAG,IAAI,EAAE,CAAA;IAClB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,GAAG,CAAC,IAAI,CACN,oFAAoF;YAClF,gDAAgD,CACnD,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAA;AAEhE;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAE3C,YAAY,MAAc;QACxB,KAAK,CACH,GAAG,yBAAyB,6CAA6C;YACvE,uEAAuE,CAC1E,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AA8GD,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,SAAS,WAAW;IAClB,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAA;IACtB,OAAO,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE,CAAA;AAC9C,CAAC;AAED,SAAS,iBAAiB,CAAC,M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,CAAA;IACD,uEAAuE;IACvE,0DAA0D;IAC1D,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAClE,MAAM,OAAO,GAAG,GAA2B,CAAA;QAC3C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,KAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAM,CAAA;IACxF,CAAC;IACD,OAAO,GAAqB,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK ↔ unified-shape converters for the RGB adapter.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from src/protocols/rgb/adapter.ts so the conversion logic lives
|
|
5
|
+
* in one place and the adapter is closer to "what RPCs do I call". Every
|
|
6
|
+
* function here is side-effect free, has no `this` dependencies, and only
|
|
7
|
+
* imports types — no SDK client, no module state.
|
|
8
|
+
*
|
|
9
|
+
* Covered by tests/unit/rgb-converters.test.ts.
|
|
10
|
+
*/
|
|
11
|
+
import type { AssetBalanceResponse, BtcBalanceResponse } from "kaleido-sdk/rln";
|
|
12
|
+
import type { UnifiedAsset, UnifiedTransaction } from "../types/base.js";
|
|
13
|
+
/**
|
|
14
|
+
* `wallet.getBtcBalance()` returns BTC split into "vanilla" (regular) and
|
|
15
|
+
* "colored" (RGB-allocated) sub-balances. The wallet UI only surfaces the
|
|
16
|
+
* vanilla portion as the BTC asset's balance — colored sats are accounted
|
|
17
|
+
* for under each RGB asset's own balance. Locks the policy: don't show
|
|
18
|
+
* colored sats as spendable BTC.
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertBtcBalance(btcBalance: BtcBalanceResponse): UnifiedAsset["balance"];
|
|
21
|
+
/**
|
|
22
|
+
* `wallet.getAssetBalance(assetId)` returns the per-asset SDK balance.
|
|
23
|
+
* Exposes the off-chain inbound/outbound capacities — both shown in the
|
|
24
|
+
* channel-aware balance breakdown — and treats `offchain_outbound` as
|
|
25
|
+
* `locked` for legacy callers that don't know about the off-chain split.
|
|
26
|
+
*/
|
|
27
|
+
export declare function convertSdkBalance(balance: AssetBalanceResponse, precision?: number): UnifiedAsset["balance"];
|
|
28
|
+
/**
|
|
29
|
+
* `client.rln.listAssets()` returns balance as a plain `Record<string, number>`
|
|
30
|
+
* — same field names as the SDK shape but flatter and `undefined`-safe.
|
|
31
|
+
* Same projection as `convertSdkBalance` but no required-field assumptions.
|
|
32
|
+
*/
|
|
33
|
+
export declare function convertNodeBalance(balance: Record<string, number> | undefined, precision?: number): UnifiedAsset["balance"];
|
|
34
|
+
/**
|
|
35
|
+
* Build a `UnifiedAsset` from the raw `client.rln.listAssets()` payload.
|
|
36
|
+
* Precision defaults to 8 (BTC convention) when the node omits it —
|
|
37
|
+
* legacy assets pre-RGB20 sometimes don't carry an explicit precision.
|
|
38
|
+
*/
|
|
39
|
+
export declare function convertNodeAssetToUnified(asset: Record<string, unknown>): UnifiedAsset;
|
|
40
|
+
/**
|
|
41
|
+
* On-chain RGB transfer from `client.rln.listTransfers()`. `asset` is left
|
|
42
|
+
* as an empty placeholder; the caller (Activity view) joins on `asset_id`
|
|
43
|
+
* to populate it via the asset inventory.
|
|
44
|
+
*/
|
|
45
|
+
export declare function convertTransferToTransaction(transfer: Record<string, unknown>): UnifiedTransaction;
|
|
46
|
+
/**
|
|
47
|
+
* Maker/taker swap entry from `client.rln.listSwaps()`. The same swap
|
|
48
|
+
* appears once per side — `side` distinguishes them in the rendered id
|
|
49
|
+
* so a maker and taker view of the same swap don't collide.
|
|
50
|
+
*
|
|
51
|
+
* Timestamp resolution: prefer `completed_at`, then `initiated_at`, then
|
|
52
|
+
* `requested_at` (all in seconds — converted to ms here).
|
|
53
|
+
*/
|
|
54
|
+
export declare function convertSwapToTransaction(swap: Record<string, unknown>, side: "maker" | "taker"): UnifiedTransaction;
|
|
55
|
+
/**
|
|
56
|
+
* Lightning payment entry from `client.rln.listPayments()`. Inbound vs
|
|
57
|
+
* outbound is determined by the `inbound` flag (we render as receive vs
|
|
58
|
+
* send). Amount resolution prefers `asset_amount` (for RGB-asset payments)
|
|
59
|
+
* then falls back to converting the BTC msat figure to sats.
|
|
60
|
+
*/
|
|
61
|
+
export declare function convertPaymentToTransaction(payment: Record<string, unknown>): UnifiedTransaction;
|
|
62
|
+
//# sourceMappingURL=rgb-converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-converters.d.ts","sourceRoot":"","sources":["../../src/lib/rgb-converters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAetE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,YAAY,CAAC,SAAS,CAAC,CASzF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,oBAAoB,EAC7B,SAAS,GAAE,MAAU,GACpB,YAAY,CAAC,SAAS,CAAC,CAWzB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,SAAS,GAAE,MAAU,GACpB,YAAY,CAAC,SAAS,CAAC,CAezB;AAID;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAkBtF;AAOD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,kBAAkB,CAepB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,OAAO,GAAG,OAAO,GACtB,kBAAkB,CAoBpB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,CAqBhG"}
|