@kaleidorg/wallet-engine 1.0.0-beta.37 → 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/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/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/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/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 +5 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flashnet adapter entry — AMM (Flashnet) + cross-chain bridge (Orchestra).
|
|
3
|
+
*
|
|
4
|
+
* Opt-in sub-path export: `@kaleidorg/wallet-engine/adapters/flashnet`. Pulls
|
|
5
|
+
* `@flashnet/sdk` (via the Flashnet client manager) — not the Arkade/RGB SDKs.
|
|
6
|
+
* The Orchestra REST client carries no SDK; its API key is consumer-injected
|
|
7
|
+
* via `setOrchestraApiKey()` (kept out of the engine, which has no build-time env).
|
|
8
|
+
*
|
|
9
|
+
* `flashnetClientManager.initialize()` needs a `SparkWallet`, so this composes
|
|
10
|
+
* with `@kaleidorg/wallet-engine/adapters/spark`.
|
|
11
|
+
*/
|
|
12
|
+
export { flashnetClientManager } from '../lib/flashnet-client-manager.js';
|
|
13
|
+
export * from '../lib/orchestra-client.js';
|
|
14
|
+
//# sourceMappingURL=flashnet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashnet.d.ts","sourceRoot":"","sources":["../../src/adapters/flashnet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flashnet adapter entry — AMM (Flashnet) + cross-chain bridge (Orchestra).
|
|
3
|
+
*
|
|
4
|
+
* Opt-in sub-path export: `@kaleidorg/wallet-engine/adapters/flashnet`. Pulls
|
|
5
|
+
* `@flashnet/sdk` (via the Flashnet client manager) — not the Arkade/RGB SDKs.
|
|
6
|
+
* The Orchestra REST client carries no SDK; its API key is consumer-injected
|
|
7
|
+
* via `setOrchestraApiKey()` (kept out of the engine, which has no build-time env).
|
|
8
|
+
*
|
|
9
|
+
* `flashnetClientManager.initialize()` needs a `SparkWallet`, so this composes
|
|
10
|
+
* with `@kaleidorg/wallet-engine/adapters/spark`.
|
|
11
|
+
*/
|
|
12
|
+
export { flashnetClientManager } from '../lib/flashnet-client-manager.js';
|
|
13
|
+
export * from '../lib/orchestra-client.js';
|
|
14
|
+
//# sourceMappingURL=flashnet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashnet.js","sourceRoot":"","sources":["../../src/adapters/flashnet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,cAAc,yBAAyB,CAAA"}
|
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flashnet Client Manager
|
|
3
|
-
*
|
|
3
|
+
* Singleton managing the lifecycle of a FlashnetClient from `@flashnet/sdk`.
|
|
4
4
|
* Requires an initialized SparkWallet to function.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* Ported from rate-extension/src/protocols/spark/flashnet-client-manager.ts.
|
|
7
|
+
* The SDK is a value import (optional dependency) — consumers install
|
|
8
|
+
* `@flashnet/sdk` to use this manager, matching the Spark client-manager convention.
|
|
6
9
|
*/
|
|
10
|
+
import type { SparkWallet } from '@buildonspark/spark-sdk';
|
|
11
|
+
import { FlashnetClient, type WalletBalance } from '@flashnet/sdk';
|
|
7
12
|
import { type FlashnetNetwork } from '../types/flashnet.js';
|
|
13
|
+
import type { SparkConfig } from '../types/spark.js';
|
|
8
14
|
declare class FlashnetClientManager {
|
|
9
15
|
private client;
|
|
10
16
|
private initPromise;
|
|
11
17
|
private poolId;
|
|
12
18
|
private network;
|
|
19
|
+
initialize(wallet: SparkWallet, sparkNetwork?: SparkConfig['network']): Promise<void>;
|
|
20
|
+
private doInitialize;
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
22
|
+
* Fetch the wallet's AMM swap history and persist the outgoing (token-in)
|
|
23
|
+
* legs to the sent-token outbox.
|
|
24
|
+
*
|
|
25
|
+
* A swap moves a token to the pool via an internal SDK transfer that the
|
|
26
|
+
* Spark token-transaction query cannot classify as a send. Flashnet's
|
|
27
|
+
* `GET /v1/swaps/user/{pubkey}` returns every past swap with explicit
|
|
28
|
+
* direction (assetIn / amountIn / inboundTransferId), so this both fixes
|
|
29
|
+
* future swaps and recovers ones made before any recording existed.
|
|
30
|
+
*
|
|
31
|
+
* Idempotent — records are keyed by transfer hash, so re-running on each
|
|
32
|
+
* connect simply refreshes them.
|
|
17
33
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
private backfillSwapHistory;
|
|
35
|
+
getClient(): FlashnetClient;
|
|
36
|
+
/** Convenience pass-through so callers don't need to await client.getBalance() through a cast. */
|
|
37
|
+
getBalance(): Promise<WalletBalance>;
|
|
21
38
|
getPoolId(): string | null;
|
|
22
39
|
getNetwork(): FlashnetNetwork | null;
|
|
23
40
|
getUsdbTokenAddress(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flashnet-client-manager.d.ts","sourceRoot":"","sources":["../../src/lib/flashnet-client-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"flashnet-client-manager.d.ts","sourceRoot":"","sources":["../../src/lib/flashnet-client-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAkBjD,cAAM,qBAAqB;IACzB,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,OAAO,CAA+B;IAE9C,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAQvE,YAAY;IAqD1B;;;;;;;;;;;;OAYG;YACW,mBAAmB;IA4DjC,SAAS,IAAI,cAAc;IAO3B,kGAAkG;IAC5F,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC;IAI1C,SAAS,IAAI,MAAM,GAAG,IAAI;IAI1B,UAAU,IAAI,eAAe,GAAG,IAAI;IAIpC,mBAAmB,IAAI,MAAM;IAO7B,aAAa,IAAI,OAAO;IAIlB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAalC;AAED,eAAO,MAAM,qBAAqB,uBAA8B,CAAA"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flashnet Client Manager
|
|
3
|
-
*
|
|
3
|
+
* Singleton managing the lifecycle of a FlashnetClient from `@flashnet/sdk`.
|
|
4
4
|
* Requires an initialized SparkWallet to function.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* Ported from rate-extension/src/protocols/spark/flashnet-client-manager.ts.
|
|
7
|
+
* The SDK is a value import (optional dependency) — consumers install
|
|
8
|
+
* `@flashnet/sdk` to use this manager, matching the Spark client-manager convention.
|
|
6
9
|
*/
|
|
7
|
-
import {
|
|
10
|
+
import { FlashnetClient } from '@flashnet/sdk';
|
|
11
|
+
import { BTC_ASSET_PUBKEY, USDB_DECIMALS, getFlashnetNetworkForSpark, getFlashnetUsdbTokenAddress, isUsdbTokenAddress, } from '../types/flashnet.js';
|
|
12
|
+
import { log } from './log.js';
|
|
13
|
+
import { saveSentTokenRecord } from './spark-sent-token-records.js';
|
|
8
14
|
/**
|
|
9
15
|
* Normalize the SDK pools response to always return an array.
|
|
10
16
|
* The SDK may return `Pool[]` or `{ pools: Pool[] }`.
|
|
@@ -26,11 +32,6 @@ class FlashnetClientManager {
|
|
|
26
32
|
this.poolId = null;
|
|
27
33
|
this.network = null;
|
|
28
34
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Initialize with a SparkWallet instance.
|
|
31
|
-
* @param wallet - SparkWallet from @buildonspark/spark-sdk
|
|
32
|
-
* @param sparkNetwork - The Spark network ('mainnet' | 'regtest')
|
|
33
|
-
*/
|
|
34
35
|
initialize(wallet, sparkNetwork) {
|
|
35
36
|
if (this.initPromise)
|
|
36
37
|
return this.initPromise;
|
|
@@ -48,11 +49,12 @@ class FlashnetClientManager {
|
|
|
48
49
|
throw new Error('Flashnet is only available when Spark is on mainnet or regtest.');
|
|
49
50
|
}
|
|
50
51
|
try {
|
|
51
|
-
|
|
52
|
+
// The SDK accepts SparkWallet | IssuerSparkWallet but doesn't export a
|
|
53
|
+
// shared base — the cast keeps the call site honest while letting the
|
|
54
|
+
// rest of the file enjoy real types from the SDK.
|
|
52
55
|
this.client = new FlashnetClient(wallet);
|
|
53
56
|
await this.client.initialize();
|
|
54
57
|
this.network = network;
|
|
55
|
-
// Auto-discover the largest BTC/USDB pool
|
|
56
58
|
try {
|
|
57
59
|
const poolsResponse = await this.client.listPools({
|
|
58
60
|
assetAAddress: BTC_ASSET_PUBKEY,
|
|
@@ -61,12 +63,22 @@ class FlashnetClientManager {
|
|
|
61
63
|
});
|
|
62
64
|
const pools = normalizePoolsResponse(poolsResponse);
|
|
63
65
|
if (pools && pools.length > 0) {
|
|
64
|
-
|
|
66
|
+
// listPools returns LpPublicKey identifiers; we store the first
|
|
67
|
+
// (highest-TVL) BTC↔USDB pool as the default for swap UX.
|
|
68
|
+
const first = pools[0];
|
|
69
|
+
if (first?.lpPublicKey)
|
|
70
|
+
this.poolId = first.lpPublicKey;
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
catch (error) {
|
|
68
|
-
|
|
74
|
+
log.warn('[FlashnetClientManager] Pool discovery failed:', error);
|
|
69
75
|
}
|
|
76
|
+
// Backfill outgoing-swap history into the sent-token outbox so past
|
|
77
|
+
// token swaps (e.g. USDB → BTC) appear as sends in transaction history.
|
|
78
|
+
// Flashnet's AMM swap endpoint is the authoritative, retroactive source
|
|
79
|
+
// of direction — the Spark SDK exposes none for token transactions.
|
|
80
|
+
// Best-effort and async: never blocks or fails wallet init.
|
|
81
|
+
void this.backfillSwapHistory(wallet);
|
|
70
82
|
}
|
|
71
83
|
catch (error) {
|
|
72
84
|
this.client = null;
|
|
@@ -76,12 +88,84 @@ class FlashnetClientManager {
|
|
|
76
88
|
throw new Error(`Failed to initialize FlashnetClient: ${message}`);
|
|
77
89
|
}
|
|
78
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Fetch the wallet's AMM swap history and persist the outgoing (token-in)
|
|
93
|
+
* legs to the sent-token outbox.
|
|
94
|
+
*
|
|
95
|
+
* A swap moves a token to the pool via an internal SDK transfer that the
|
|
96
|
+
* Spark token-transaction query cannot classify as a send. Flashnet's
|
|
97
|
+
* `GET /v1/swaps/user/{pubkey}` returns every past swap with explicit
|
|
98
|
+
* direction (assetIn / amountIn / inboundTransferId), so this both fixes
|
|
99
|
+
* future swaps and recovers ones made before any recording existed.
|
|
100
|
+
*
|
|
101
|
+
* Idempotent — records are keyed by transfer hash, so re-running on each
|
|
102
|
+
* connect simply refreshes them.
|
|
103
|
+
*/
|
|
104
|
+
async backfillSwapHistory(wallet) {
|
|
105
|
+
const client = this.client;
|
|
106
|
+
if (!client)
|
|
107
|
+
return;
|
|
108
|
+
// `toHumanReadableTokenIdentifier` is private on FlashnetClient; the swap
|
|
109
|
+
// endpoint may return hex token ids, so normalize to the bech32 form the
|
|
110
|
+
// rest of the wallet uses when possible.
|
|
111
|
+
const toHumanReadable = (raw) => {
|
|
112
|
+
try {
|
|
113
|
+
const fn = client
|
|
114
|
+
.toHumanReadableTokenIdentifier;
|
|
115
|
+
return fn ? fn.call(client, raw) : raw;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return raw;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
const senderSparkAddress = (await wallet.getSparkAddress());
|
|
123
|
+
const { swaps } = await client.getUserSwaps(undefined, {
|
|
124
|
+
sort: 'timestampDesc',
|
|
125
|
+
limit: 200,
|
|
126
|
+
});
|
|
127
|
+
let recorded = 0;
|
|
128
|
+
for (const swap of swaps ?? []) {
|
|
129
|
+
// Only the token-in leg is an outflow that needs the outbox. The
|
|
130
|
+
// token-out leg of a swap is a receive, already returned by the
|
|
131
|
+
// Spark token-transaction query.
|
|
132
|
+
const assetIn = swap?.assetInAddress;
|
|
133
|
+
const inboundTransferId = swap?.inboundTransferId;
|
|
134
|
+
if (!assetIn || assetIn === BTC_ASSET_PUBKEY || !inboundTransferId)
|
|
135
|
+
continue;
|
|
136
|
+
const assetId = toHumanReadable(assetIn);
|
|
137
|
+
const isUsdb = isUsdbTokenAddress(assetId);
|
|
138
|
+
const parsedTs = Date.parse(swap?.timestamp ?? '');
|
|
139
|
+
await saveSentTokenRecord({
|
|
140
|
+
hash: inboundTransferId,
|
|
141
|
+
senderSparkAddress,
|
|
142
|
+
amount: Number(swap?.amountIn ?? 0) || 0,
|
|
143
|
+
assetId,
|
|
144
|
+
ticker: isUsdb ? 'USDB' : 'TOKEN',
|
|
145
|
+
name: isUsdb ? 'USDB' : assetId,
|
|
146
|
+
decimals: isUsdb ? USDB_DECIMALS : 0,
|
|
147
|
+
timestamp: Number.isFinite(parsedTs) ? parsedTs : Date.now(),
|
|
148
|
+
});
|
|
149
|
+
recorded += 1;
|
|
150
|
+
}
|
|
151
|
+
if (recorded > 0) {
|
|
152
|
+
log.info(`[FlashnetClientManager] Backfilled ${recorded} outgoing swap(s) into token history`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
log.warn('[FlashnetClientManager] Swap history backfill failed:', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
79
159
|
getClient() {
|
|
80
160
|
if (!this.client) {
|
|
81
161
|
throw new Error('FlashnetClient not initialized. Call initialize() first.');
|
|
82
162
|
}
|
|
83
163
|
return this.client;
|
|
84
164
|
}
|
|
165
|
+
/** Convenience pass-through so callers don't need to await client.getBalance() through a cast. */
|
|
166
|
+
async getBalance() {
|
|
167
|
+
return this.getClient().getBalance();
|
|
168
|
+
}
|
|
85
169
|
getPoolId() {
|
|
86
170
|
return this.poolId;
|
|
87
171
|
}
|
|
@@ -103,7 +187,7 @@ class FlashnetClientManager {
|
|
|
103
187
|
await this.client.cleanup();
|
|
104
188
|
}
|
|
105
189
|
catch (error) {
|
|
106
|
-
|
|
190
|
+
log.warn('[FlashnetClientManager] Disconnect error:', error);
|
|
107
191
|
}
|
|
108
192
|
}
|
|
109
193
|
this.client = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flashnet-client-manager.js","sourceRoot":"","sources":["../../src/lib/flashnet-client-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"flashnet-client-manager.js","sourceRoot":"","sources":["../../src/lib/flashnet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
+
*
|
|
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,MAAM,yBAAyB,0BAA0B,CAAA;AAEhE;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBACX,MAAM,EAAE,MAAM;CAQ3B;AAMD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;C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c,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;;;;;;;;;;;;;GA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IACxF,CAAC;IACD,OAAO,GAAqB,CAAA;AAC9B,CAAC"}
|
package/dist/types/flashnet.d.ts
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flashnet Protocol Types
|
|
3
3
|
* Ported from rate-extension/src/protocols/types/flashnet.ts
|
|
4
|
+
*
|
|
5
|
+
* Re-exports the @flashnet/sdk types we lean on so call sites have a single
|
|
6
|
+
* import surface. These are type-only re-exports — erased at compile time — so
|
|
7
|
+
* the SDK-free root barrel stays runtime-clean even though it does
|
|
8
|
+
* `export * from './types/flashnet'`.
|
|
4
9
|
*/
|
|
10
|
+
export type { FlashnetClient, WalletBalance, TokenBalance } from '@flashnet/sdk';
|
|
11
|
+
export type { SimulateSwapRequest, SimulateSwapResponse, SwapResponse, SimulateRouteSwapRequest, SimulateRouteSwapResponse, ExecuteRouteSwapResponse, ListPoolsQuery, ListPoolsResponse, PoolDetailsResponse, PoolLiquidityResponse, ListPoolSwapsQuery, ListPoolSwapsResponse, ListUserSwapsQuery, ListUserSwapsResponse, FlashnetErrorCode, FlashnetErrorResponseBody, } from '@flashnet/sdk';
|
|
5
12
|
export type FlashnetNetwork = 'mainnet' | 'regtest';
|
|
6
13
|
export declare const USDB_TOKEN_ADDRESS: Record<'mainnet' | 'regtest', string>;
|
|
14
|
+
export declare const USDB_TOKEN_ADDRESS_ALIASES: string[];
|
|
7
15
|
export declare const BTC_ASSET_PUBKEY = "020202020202020202020202020202020202020202020202020202020202020202";
|
|
8
16
|
export declare const USDB_DECIMALS = 6;
|
|
9
17
|
export declare const BTC_DECIMALS = 8;
|
|
18
|
+
export declare const FLASHNET_API_URL: Record<'mainnet' | 'regtest', string>;
|
|
19
|
+
export declare const FLASHNET_REWARDS_API_URL = "https://rewards.flashnet.xyz";
|
|
20
|
+
export declare const FLASHNET_USDB_REWARDS_DOC_URL = "https://docs.flashnet.xyz/usdb/rewards";
|
|
21
|
+
export declare const SPARK_BALANCES_DOC_URL = "https://docs.spark.money/wallets/balances";
|
|
10
22
|
export declare const DEFAULT_SLIPPAGE_BPS = 500;
|
|
23
|
+
export interface UsdbRewardTier {
|
|
24
|
+
minBalance: number;
|
|
25
|
+
rate: number;
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const USDB_REWARD_TIERS: UsdbRewardTier[];
|
|
11
29
|
export declare function getFlashnetNetworkForSpark(sparkNetwork: string | null | undefined): FlashnetNetwork | null;
|
|
12
30
|
export declare function getFlashnetUsdbTokenAddress(network: FlashnetNetwork): string;
|
|
31
|
+
export declare function isUsdbTokenAddress(value: string | null | undefined): boolean;
|
|
32
|
+
export declare function getUsdbRewardRate(usdbBalance: number): number;
|
|
13
33
|
export interface FlashnetSwapSimulation {
|
|
14
34
|
amountOut: bigint;
|
|
15
35
|
executionPrice: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flashnet.d.ts","sourceRoot":"","sources":["../../src/types/flashnet.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"flashnet.d.ts","sourceRoot":"","sources":["../../src/types/flashnet.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAChF,YAAY,EAEV,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EAEZ,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EAExB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EAErB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EAErB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,eAAe,CAAA;AAEtB,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,CAAA;AAGnD,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,SAAS,GAAG,SAAS,EAAE,MAAM,CAGpE,CAAA;AAED,eAAO,MAAM,0BAA0B,UAGtC,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AQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb"}
|
package/dist/types/flashnet.js
CHANGED
|
@@ -1,23 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
* Flashnet Protocol Types
|
|
3
|
-
* Ported from rate-extension/src/protocols/types/flashnet.ts
|
|
4
|
-
*/
|
|
1
|
+
// Mainnet and regtest share one canonical USDB token address.
|
|
5
2
|
export const USDB_TOKEN_ADDRESS = {
|
|
6
3
|
mainnet: 'btkn1xgrvjwey5ngcagvap2dzzvsy4uk8ua9x69k82dwvt5e7ef9drm9qztux87',
|
|
7
4
|
regtest: 'btkn1xgrvjwey5ngcagvap2dzzvsy4uk8ua9x69k82dwvt5e7ef9drm9qztux87',
|
|
8
5
|
};
|
|
6
|
+
export const USDB_TOKEN_ADDRESS_ALIASES = [
|
|
7
|
+
USDB_TOKEN_ADDRESS.mainnet,
|
|
8
|
+
'btknrt1xgrvjwey5ngcagvap2dzzvsy4uk8ua9x69k82dwvt5e7ef9drm9qp48s74',
|
|
9
|
+
];
|
|
9
10
|
export const BTC_ASSET_PUBKEY = '020202020202020202020202020202020202020202020202020202020202020202';
|
|
10
11
|
export const USDB_DECIMALS = 6;
|
|
11
12
|
export const BTC_DECIMALS = 8;
|
|
13
|
+
export const FLASHNET_API_URL = {
|
|
14
|
+
mainnet: 'https://api.flashnet.xyz',
|
|
15
|
+
regtest: 'https://api.amm.makebitcoingreatagain.dev',
|
|
16
|
+
};
|
|
17
|
+
export const FLASHNET_REWARDS_API_URL = 'https://rewards.flashnet.xyz';
|
|
18
|
+
export const FLASHNET_USDB_REWARDS_DOC_URL = 'https://docs.flashnet.xyz/usdb/rewards';
|
|
19
|
+
export const SPARK_BALANCES_DOC_URL = 'https://docs.spark.money/wallets/balances';
|
|
12
20
|
export const DEFAULT_SLIPPAGE_BPS = 500;
|
|
21
|
+
export const USDB_REWARD_TIERS = [
|
|
22
|
+
{ minBalance: 10, rate: 0.035, label: '3.5%' },
|
|
23
|
+
{ minBalance: 1000, rate: 0.045, label: '4.5%' },
|
|
24
|
+
{ minBalance: 10000, rate: 0.06, label: '6%' },
|
|
25
|
+
];
|
|
13
26
|
export function getFlashnetNetworkForSpark(sparkNetwork) {
|
|
14
|
-
|
|
27
|
+
const normalized = sparkNetwork?.trim().toLowerCase();
|
|
28
|
+
if (normalized === 'mainnet')
|
|
15
29
|
return 'mainnet';
|
|
16
|
-
if (
|
|
30
|
+
if (normalized === 'regtest')
|
|
17
31
|
return 'regtest';
|
|
18
32
|
return null;
|
|
19
33
|
}
|
|
20
34
|
export function getFlashnetUsdbTokenAddress(network) {
|
|
21
35
|
return USDB_TOKEN_ADDRESS[network];
|
|
22
36
|
}
|
|
37
|
+
export function isUsdbTokenAddress(value) {
|
|
38
|
+
if (!value)
|
|
39
|
+
return false;
|
|
40
|
+
const normalized = value.trim().toLowerCase();
|
|
41
|
+
return USDB_TOKEN_ADDRESS_ALIASES.some((alias) => alias.toLowerCase() === normalized);
|
|
42
|
+
}
|
|
43
|
+
export function getUsdbRewardRate(usdbBalance) {
|
|
44
|
+
let rate = 0;
|
|
45
|
+
for (const tier of USDB_REWARD_TIERS) {
|
|
46
|
+
if (usdbBalance >= tier.minBalance)
|
|
47
|
+
rate = tier.rate;
|
|
48
|
+
}
|
|
49
|
+
return rate;
|
|
50
|
+
}
|
|
23
51
|
//# sourceMappingURL=flashnet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flashnet.js","sourceRoot":"","sources":["../../src/types/flashnet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flashnet.js","sourceRoot":"","sources":["../../src/types/flashnet.ts"],"names":[],"mappings":"AAoCA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAA0C;IACvE,OAAO,EAAE,iEAAiE;IAC1E,OAAO,EAAE,iEAAiE;CAC3E,CAAA;AAED,MAAM,CAAC,MAAM,0BA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jE,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7C,OAAO,0BAA0B,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,CAAA;AACvF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACrC,IAAI,WAAW,IAAI,IAAI,CAAC,UAAU;YAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACtD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaleidorg/wallet-engine",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.38",
|
|
4
4
|
"description": "WDK-based multi-protocol wallet engine (Spark, RGB/RLN, Liquid, Arkade): IProtocolAdapter contract + WDK adapters, cross-protocol router, BIP321 unified receive, and lite/advanced disclosure.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"types": "./dist/adapters/rgb.d.ts",
|
|
27
27
|
"default": "./dist/adapters/rgb.js"
|
|
28
28
|
},
|
|
29
|
+
"./adapters/flashnet": {
|
|
30
|
+
"types": "./dist/adapters/flashnet.d.ts",
|
|
31
|
+
"default": "./dist/adapters/flashnet.js"
|
|
32
|
+
},
|
|
29
33
|
"./adapters/wdk": {
|
|
30
34
|
"types": "./dist/adapters/wdk/index.d.ts",
|
|
31
35
|
"default": "./dist/adapters/wdk/index.js"
|