@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
|
@@ -0,0 +1,179 @@
|
|
|
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 { formatAmount, mapPaymentStatus, mapSwapStatus, mapTransferStatus, mapTransferType, } from "./rgb-helpers.js";
|
|
12
|
+
// ── Balance shape converters ──────────────────────────────────────────────
|
|
13
|
+
// Three slightly different upstream shapes; the unified `UnifiedAsset["balance"]`
|
|
14
|
+
// is the projection we render. Each converter is the *only* place that
|
|
15
|
+
// knows the field names of its specific SDK response — anything downstream
|
|
16
|
+
// reads the unified shape.
|
|
17
|
+
/**
|
|
18
|
+
* `wallet.getBtcBalance()` returns BTC split into "vanilla" (regular) and
|
|
19
|
+
* "colored" (RGB-allocated) sub-balances. The wallet UI only surfaces the
|
|
20
|
+
* vanilla portion as the BTC asset's balance — colored sats are accounted
|
|
21
|
+
* for under each RGB asset's own balance. Locks the policy: don't show
|
|
22
|
+
* colored sats as spendable BTC.
|
|
23
|
+
*/
|
|
24
|
+
export function convertBtcBalance(btcBalance) {
|
|
25
|
+
const vanilla = btcBalance.vanilla ?? { settled: 0, future: 0, spendable: 0 };
|
|
26
|
+
return {
|
|
27
|
+
total: vanilla.settled || 0,
|
|
28
|
+
available: vanilla.spendable || 0,
|
|
29
|
+
pending: vanilla.future || 0,
|
|
30
|
+
totalDisplay: formatAmount(vanilla.settled || 0, 8),
|
|
31
|
+
availableDisplay: formatAmount(vanilla.spendable || 0, 8),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `wallet.getAssetBalance(assetId)` returns the per-asset SDK balance.
|
|
36
|
+
* Exposes the off-chain inbound/outbound capacities — both shown in the
|
|
37
|
+
* channel-aware balance breakdown — and treats `offchain_outbound` as
|
|
38
|
+
* `locked` for legacy callers that don't know about the off-chain split.
|
|
39
|
+
*/
|
|
40
|
+
export function convertSdkBalance(balance, precision = 8) {
|
|
41
|
+
return {
|
|
42
|
+
total: balance.settled || 0,
|
|
43
|
+
available: balance.spendable || 0,
|
|
44
|
+
pending: balance.future || 0,
|
|
45
|
+
locked: balance.offchain_outbound || 0,
|
|
46
|
+
offchain_outbound: balance.offchain_outbound || 0,
|
|
47
|
+
offchain_inbound: balance.offchain_inbound || 0,
|
|
48
|
+
totalDisplay: formatAmount(balance.settled || 0, precision),
|
|
49
|
+
availableDisplay: formatAmount(balance.spendable || 0, precision),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `client.rln.listAssets()` returns balance as a plain `Record<string, number>`
|
|
54
|
+
* — same field names as the SDK shape but flatter and `undefined`-safe.
|
|
55
|
+
* Same projection as `convertSdkBalance` but no required-field assumptions.
|
|
56
|
+
*/
|
|
57
|
+
export function convertNodeBalance(balance, precision = 8) {
|
|
58
|
+
const total = balance?.settled || 0;
|
|
59
|
+
const available = balance?.spendable || 0;
|
|
60
|
+
const pending = balance?.future || 0;
|
|
61
|
+
return {
|
|
62
|
+
total,
|
|
63
|
+
available,
|
|
64
|
+
pending,
|
|
65
|
+
locked: balance?.offchain_outbound || 0,
|
|
66
|
+
offchain_outbound: balance?.offchain_outbound || 0,
|
|
67
|
+
offchain_inbound: balance?.offchain_inbound || 0,
|
|
68
|
+
totalDisplay: formatAmount(total, precision),
|
|
69
|
+
availableDisplay: formatAmount(available, precision),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// ── Asset converter ──────────────────────────────────────────────────────
|
|
73
|
+
/**
|
|
74
|
+
* Build a `UnifiedAsset` from the raw `client.rln.listAssets()` payload.
|
|
75
|
+
* Precision defaults to 8 (BTC convention) when the node omits it —
|
|
76
|
+
* legacy assets pre-RGB20 sometimes don't carry an explicit precision.
|
|
77
|
+
*/
|
|
78
|
+
export function convertNodeAssetToUnified(asset) {
|
|
79
|
+
const precision = asset.precision ?? 8;
|
|
80
|
+
return {
|
|
81
|
+
id: asset.asset_id,
|
|
82
|
+
name: asset.name,
|
|
83
|
+
ticker: asset.ticker,
|
|
84
|
+
precision,
|
|
85
|
+
protocol: "RGB_LN",
|
|
86
|
+
layer: "RGB_LN",
|
|
87
|
+
balance: convertNodeBalance(asset.balance, precision),
|
|
88
|
+
capabilities: {
|
|
89
|
+
canSend: true,
|
|
90
|
+
canReceive: true,
|
|
91
|
+
canSwap: false,
|
|
92
|
+
supportsLightning: true,
|
|
93
|
+
supportsOnchain: true,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// ── Transaction converters ───────────────────────────────────────────────
|
|
98
|
+
// Three sources of RGB activity — on-chain transfers, lightning payments,
|
|
99
|
+
// and maker/taker swaps — project into the same `UnifiedTransaction` shape
|
|
100
|
+
// so the activity view doesn't have to render-switch on protocol details.
|
|
101
|
+
/**
|
|
102
|
+
* On-chain RGB transfer from `client.rln.listTransfers()`. `asset` is left
|
|
103
|
+
* as an empty placeholder; the caller (Activity view) joins on `asset_id`
|
|
104
|
+
* to populate it via the asset inventory.
|
|
105
|
+
*/
|
|
106
|
+
export function convertTransferToTransaction(transfer) {
|
|
107
|
+
return {
|
|
108
|
+
id: transfer.txid || `tx_${Date.now()}`,
|
|
109
|
+
type: mapTransferType(transfer.kind),
|
|
110
|
+
status: mapTransferStatus(transfer.status),
|
|
111
|
+
timestamp: transfer.created_at || Date.now(),
|
|
112
|
+
amount: transfer.amount || 0,
|
|
113
|
+
amountDisplay: formatAmount(transfer.amount || 0, 8),
|
|
114
|
+
fee: transfer.fee,
|
|
115
|
+
feeDisplay: formatAmount(transfer.fee || 0, 8),
|
|
116
|
+
asset: {}, // Would need to be populated
|
|
117
|
+
from: transfer.sender,
|
|
118
|
+
to: transfer.recipient,
|
|
119
|
+
protocolData: transfer,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Maker/taker swap entry from `client.rln.listSwaps()`. The same swap
|
|
124
|
+
* appears once per side — `side` distinguishes them in the rendered id
|
|
125
|
+
* so a maker and taker view of the same swap don't collide.
|
|
126
|
+
*
|
|
127
|
+
* Timestamp resolution: prefer `completed_at`, then `initiated_at`, then
|
|
128
|
+
* `requested_at` (all in seconds — converted to ms here).
|
|
129
|
+
*/
|
|
130
|
+
export function convertSwapToTransaction(swap, side) {
|
|
131
|
+
const paymentHash = swap.payment_hash || `swap_${Date.now()}`;
|
|
132
|
+
const requestedAt = swap.requested_at ?? 0;
|
|
133
|
+
const completedAt = swap.completed_at ?? null;
|
|
134
|
+
const initiatedAt = swap.initiated_at ?? null;
|
|
135
|
+
const tsSec = completedAt ?? initiatedAt ?? requestedAt;
|
|
136
|
+
const timestamp = tsSec ? tsSec * 1000 : Date.now();
|
|
137
|
+
const qtyFrom = Number(swap.qty_from ?? 0);
|
|
138
|
+
return {
|
|
139
|
+
id: `swap_${side}_${paymentHash}`,
|
|
140
|
+
type: "swap",
|
|
141
|
+
status: mapSwapStatus(swap.status),
|
|
142
|
+
timestamp,
|
|
143
|
+
amount: qtyFrom,
|
|
144
|
+
amountDisplay: formatAmount(qtyFrom, 8),
|
|
145
|
+
fee: 0,
|
|
146
|
+
feeDisplay: formatAmount(0, 8),
|
|
147
|
+
asset: {},
|
|
148
|
+
protocolData: { ...swap, side },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Lightning payment entry from `client.rln.listPayments()`. Inbound vs
|
|
153
|
+
* outbound is determined by the `inbound` flag (we render as receive vs
|
|
154
|
+
* send). Amount resolution prefers `asset_amount` (for RGB-asset payments)
|
|
155
|
+
* then falls back to converting the BTC msat figure to sats.
|
|
156
|
+
*/
|
|
157
|
+
export function convertPaymentToTransaction(payment) {
|
|
158
|
+
const inbound = Boolean(payment.inbound);
|
|
159
|
+
const assetAmount = payment.asset_amount ?? null;
|
|
160
|
+
const amtMsat = payment.amt_msat ?? null;
|
|
161
|
+
const amount = assetAmount ?? (amtMsat ? Math.floor(amtMsat / 1000) : 0);
|
|
162
|
+
const timestamp = payment.created_at
|
|
163
|
+
? payment.created_at * 1000
|
|
164
|
+
: Date.now();
|
|
165
|
+
return {
|
|
166
|
+
id: payment.payment_hash || `pmt_${Date.now()}`,
|
|
167
|
+
type: inbound ? "receive" : "send",
|
|
168
|
+
status: mapPaymentStatus(payment.status),
|
|
169
|
+
timestamp,
|
|
170
|
+
amount,
|
|
171
|
+
amountDisplay: formatAmount(amount, 8),
|
|
172
|
+
fee: 0,
|
|
173
|
+
feeDisplay: formatAmount(0, 8),
|
|
174
|
+
asset: {},
|
|
175
|
+
to: payment.payee_pubkey,
|
|
176
|
+
protocolData: payment,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=rgb-converters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-converters.js","sourceRoot":"","sources":["../../src/lib/rgb-converters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,6EAA6E;AAC7E,kFAAkF;AAClF,uEAAuE;AACvE,2EAA2E;AAC3E,2BAA2B;AAE3B;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAA8B;IAC9D,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,IAAI,EAAE,O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OAAO,CAAC,YAAkC;QAC9C,YAAY,EAAE,OAAO;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure fee-rate policy for RGB on-chain operations.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `RgbAdapter#resolveFeeRate` so the priority order +
|
|
5
|
+
* mainnet floors are unit-testable without a live RGB client.
|
|
6
|
+
*
|
|
7
|
+
* The policy ([GL #26]):
|
|
8
|
+
* 1. If the caller passed a positive `provided` rate, honour it. The
|
|
9
|
+
* advanced UI can override the floor when the user knows what they
|
|
10
|
+
* want.
|
|
11
|
+
* 2. Non-mainnet networks (regtest/signet/testnet/null/unknown):
|
|
12
|
+
* return `1 sat/vB`. Cheap, always confirms locally.
|
|
13
|
+
* 3. Mainnet: ask the node for an estimate at the urgency-mapped block
|
|
14
|
+
* target, floor at `MAINNET_FEE_FLOOR[urgency]` so a cold-started
|
|
15
|
+
* node returning `1 sat/vB` doesn't strand mainnet transactions.
|
|
16
|
+
* 4. Mainnet + estimate failure: return the floor.
|
|
17
|
+
*/
|
|
18
|
+
export type FeeUrgency = "low" | "normal" | "high";
|
|
19
|
+
/**
|
|
20
|
+
* Conservative mainnet floors (sat/vB). Well above the dust-attack rate
|
|
21
|
+
* but still cheap relative to any user-facing payment. Tuned for a
|
|
22
|
+
* typical 10-min-block target at "normal" urgency. Adjust here if
|
|
23
|
+
* mainnet conditions shift — every call site reads from this table.
|
|
24
|
+
*/
|
|
25
|
+
export declare const MAINNET_FEE_FLOOR: Record<FeeUrgency, number>;
|
|
26
|
+
export interface ResolveRgbFeeRateInput {
|
|
27
|
+
/** Caller-provided rate (advanced UI override). Wins when > 0. */
|
|
28
|
+
provided: number | undefined;
|
|
29
|
+
/** Urgency tier; maps to a block target + floor. */
|
|
30
|
+
urgency: FeeUrgency;
|
|
31
|
+
/** Active network from the adapter config. `null` = unknown / not connected. */
|
|
32
|
+
network: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Async estimator. Receives the urgency-mapped block target. Should return
|
|
35
|
+
* the node's `fee_rate` in sat/vB, or `null` on failure. Failures must
|
|
36
|
+
* not throw — the policy needs a value to fall back on.
|
|
37
|
+
*/
|
|
38
|
+
estimateFn: (blocks: number) => Promise<number | null>;
|
|
39
|
+
}
|
|
40
|
+
export declare function resolveRgbFeeRatePolicy(input: ResolveRgbFeeRateInput): Promise<number>;
|
|
41
|
+
//# sourceMappingURL=rgb-fee-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-fee-policy.d.ts","sourceRoot":"","sources":["../../src/lib/rgb-fee-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AASnD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAIxD,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,oDAAoD;IACpD,OAAO,EAAE,UAAU,CAAC;IACpB,gFAAgF;IAChF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;;OAIG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACxD;AAED,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB5F"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure fee-rate policy for RGB on-chain operations.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `RgbAdapter#resolveFeeRate` so the priority order +
|
|
5
|
+
* mainnet floors are unit-testable without a live RGB client.
|
|
6
|
+
*
|
|
7
|
+
* The policy ([GL #26]):
|
|
8
|
+
* 1. If the caller passed a positive `provided` rate, honour it. The
|
|
9
|
+
* advanced UI can override the floor when the user knows what they
|
|
10
|
+
* want.
|
|
11
|
+
* 2. Non-mainnet networks (regtest/signet/testnet/null/unknown):
|
|
12
|
+
* return `1 sat/vB`. Cheap, always confirms locally.
|
|
13
|
+
* 3. Mainnet: ask the node for an estimate at the urgency-mapped block
|
|
14
|
+
* target, floor at `MAINNET_FEE_FLOOR[urgency]` so a cold-started
|
|
15
|
+
* node returning `1 sat/vB` doesn't strand mainnet transactions.
|
|
16
|
+
* 4. Mainnet + estimate failure: return the floor.
|
|
17
|
+
*/
|
|
18
|
+
/** Block-target mapping per urgency. high = next block, low = ~2 hours. */
|
|
19
|
+
const URGENCY_BLOCKS = {
|
|
20
|
+
high: 1,
|
|
21
|
+
normal: 6,
|
|
22
|
+
low: 12,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Conservative mainnet floors (sat/vB). Well above the dust-attack rate
|
|
26
|
+
* but still cheap relative to any user-facing payment. Tuned for a
|
|
27
|
+
* typical 10-min-block target at "normal" urgency. Adjust here if
|
|
28
|
+
* mainnet conditions shift — every call site reads from this table.
|
|
29
|
+
*/
|
|
30
|
+
export const MAINNET_FEE_FLOOR = {
|
|
31
|
+
low: 5,
|
|
32
|
+
normal: 10,
|
|
33
|
+
high: 25,
|
|
34
|
+
};
|
|
35
|
+
export async function resolveRgbFeeRatePolicy(input) {
|
|
36
|
+
const { provided, urgency, network, estimateFn } = input;
|
|
37
|
+
if (typeof provided === "number" && Number.isFinite(provided) && provided > 0) {
|
|
38
|
+
return provided;
|
|
39
|
+
}
|
|
40
|
+
const isMainnet = network === "mainnet";
|
|
41
|
+
if (!isMainnet) {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
const floor = MAINNET_FEE_FLOOR[urgency];
|
|
45
|
+
const blocks = URGENCY_BLOCKS[urgency];
|
|
46
|
+
const estimate = await estimateFn(blocks);
|
|
47
|
+
if (estimate == null || !Number.isFinite(estimate) || estimate <= 0) {
|
|
48
|
+
return floor;
|
|
49
|
+
}
|
|
50
|
+
return Math.max(Math.floor(estimate), floor);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=rgb-fee-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-fee-policy.js","sourceRoot":"","sources":["../../src/lib/rgb-fee-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,2EAA2E;AAC3E,MAAM,cAAc,GAA+B;IACjD,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,EAAE;CACR,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA+B;IAC3D,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;CACT,CAAC;AAiBF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAA6B;IACzE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IACzD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QAC9E,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the RGB adapter.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from src/protocols/rgb/adapter.ts so the adapter file can stay
|
|
5
|
+
* focused on the IProtocolAdapter surface + SDK orchestration. Everything in
|
|
6
|
+
* this module is side-effect free, has no `this` dependencies, and is
|
|
7
|
+
* covered by tests/unit/rgb-helpers.test.ts.
|
|
8
|
+
*
|
|
9
|
+
* Adding to this module: keep helpers pure (no class state, no SDK calls).
|
|
10
|
+
* Anything that needs the kaleido SDK client or the adapter's own config
|
|
11
|
+
* belongs in adapter.ts.
|
|
12
|
+
*/
|
|
13
|
+
import type { TransactionStatus, TransactionType } from "../types/base.js";
|
|
14
|
+
/**
|
|
15
|
+
* Render a raw integer amount in the asset's display precision.
|
|
16
|
+
* Always emits `precision` fractional digits — the caller can trim trailing
|
|
17
|
+
* zeros if it wants a tighter rendering.
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatAmount(amount: number, precision: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Map the SDK's transfer `kind` field to our unified TransactionType.
|
|
22
|
+
*
|
|
23
|
+
* The SDK is inconsistent about case + naming — both raw lowercase strings
|
|
24
|
+
* and PascalCase ("ReceiveAsset", "SendAsset") have been observed. Defaults
|
|
25
|
+
* to "send" for unknown / undefined input so legacy entries don't display
|
|
26
|
+
* as a confusing third state.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mapTransferType(kind?: string): TransactionType;
|
|
29
|
+
/**
|
|
30
|
+
* Map the SDK's transfer status string to our unified TransactionStatus.
|
|
31
|
+
*
|
|
32
|
+
* SDK casing has drifted between releases; we accept both. "WaitingCounterparty"
|
|
33
|
+
* is RGB-specific (lightning transfer waiting on the receiver) and maps to
|
|
34
|
+
* pending so the UI keeps showing the spinner rather than green-checking too
|
|
35
|
+
* early.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mapTransferStatus(status?: string): TransactionStatus;
|
|
38
|
+
/**
|
|
39
|
+
* Map a Lightning-payment status string to our unified TransactionStatus.
|
|
40
|
+
*
|
|
41
|
+
* Three variants of "succeeded" have shown up in the SDK across versions —
|
|
42
|
+
* we accept all three to insulate the wallet UI from upstream churn.
|
|
43
|
+
*/
|
|
44
|
+
export declare function mapPaymentStatus(status?: string): TransactionStatus;
|
|
45
|
+
/**
|
|
46
|
+
* Map a maker/taker swap status string to our unified TransactionStatus.
|
|
47
|
+
*
|
|
48
|
+
* The SDK historically returned PascalCase ("Completed") and lowercase
|
|
49
|
+
* ("completed", "success", "error") interchangeably depending on whether
|
|
50
|
+
* the response came from the maker or taker side. The mapper accepts both
|
|
51
|
+
* so a refactor of the SDK doesn't quietly flip swaps to "pending".
|
|
52
|
+
*/
|
|
53
|
+
export declare function mapSwapStatus(status?: string): TransactionStatus;
|
|
54
|
+
//# sourceMappingURL=rgb-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/rgb-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAK9D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAMpE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAKnE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAKhE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the RGB adapter.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from src/protocols/rgb/adapter.ts so the adapter file can stay
|
|
5
|
+
* focused on the IProtocolAdapter surface + SDK orchestration. Everything in
|
|
6
|
+
* this module is side-effect free, has no `this` dependencies, and is
|
|
7
|
+
* covered by tests/unit/rgb-helpers.test.ts.
|
|
8
|
+
*
|
|
9
|
+
* Adding to this module: keep helpers pure (no class state, no SDK calls).
|
|
10
|
+
* Anything that needs the kaleido SDK client or the adapter's own config
|
|
11
|
+
* belongs in adapter.ts.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Render a raw integer amount in the asset's display precision.
|
|
15
|
+
* Always emits `precision` fractional digits — the caller can trim trailing
|
|
16
|
+
* zeros if it wants a tighter rendering.
|
|
17
|
+
*/
|
|
18
|
+
export function formatAmount(amount, precision) {
|
|
19
|
+
return (amount / Math.pow(10, precision)).toFixed(precision);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Map the SDK's transfer `kind` field to our unified TransactionType.
|
|
23
|
+
*
|
|
24
|
+
* The SDK is inconsistent about case + naming — both raw lowercase strings
|
|
25
|
+
* and PascalCase ("ReceiveAsset", "SendAsset") have been observed. Defaults
|
|
26
|
+
* to "send" for unknown / undefined input so legacy entries don't display
|
|
27
|
+
* as a confusing third state.
|
|
28
|
+
*/
|
|
29
|
+
export function mapTransferType(kind) {
|
|
30
|
+
if (!kind)
|
|
31
|
+
return "send";
|
|
32
|
+
if (kind.includes("receive") || kind.includes("ReceiveAsset"))
|
|
33
|
+
return "receive";
|
|
34
|
+
if (kind.includes("send") || kind.includes("SendAsset"))
|
|
35
|
+
return "send";
|
|
36
|
+
return "send";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Map the SDK's transfer status string to our unified TransactionStatus.
|
|
40
|
+
*
|
|
41
|
+
* SDK casing has drifted between releases; we accept both. "WaitingCounterparty"
|
|
42
|
+
* is RGB-specific (lightning transfer waiting on the receiver) and maps to
|
|
43
|
+
* pending so the UI keeps showing the spinner rather than green-checking too
|
|
44
|
+
* early.
|
|
45
|
+
*/
|
|
46
|
+
export function mapTransferStatus(status) {
|
|
47
|
+
if (!status)
|
|
48
|
+
return "pending";
|
|
49
|
+
if (status === "Settled" || status === "settled")
|
|
50
|
+
return "confirmed";
|
|
51
|
+
if (status === "Failed" || status === "failed")
|
|
52
|
+
return "failed";
|
|
53
|
+
if (status === "WaitingCounterparty")
|
|
54
|
+
return "pending";
|
|
55
|
+
return "pending";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Map a Lightning-payment status string to our unified TransactionStatus.
|
|
59
|
+
*
|
|
60
|
+
* Three variants of "succeeded" have shown up in the SDK across versions —
|
|
61
|
+
* we accept all three to insulate the wallet UI from upstream churn.
|
|
62
|
+
*/
|
|
63
|
+
export function mapPaymentStatus(status) {
|
|
64
|
+
if (!status)
|
|
65
|
+
return "pending";
|
|
66
|
+
if (status === "succeeded" || status === "success" || status === "Succeeded")
|
|
67
|
+
return "confirmed";
|
|
68
|
+
if (status === "failed" || status === "Failed")
|
|
69
|
+
return "failed";
|
|
70
|
+
return "pending";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Map a maker/taker swap status string to our unified TransactionStatus.
|
|
74
|
+
*
|
|
75
|
+
* The SDK historically returned PascalCase ("Completed") and lowercase
|
|
76
|
+
* ("completed", "success", "error") interchangeably depending on whether
|
|
77
|
+
* the response came from the maker or taker side. The mapper accepts both
|
|
78
|
+
* so a refactor of the SDK doesn't quietly flip swaps to "pending".
|
|
79
|
+
*/
|
|
80
|
+
export function mapSwapStatus(status) {
|
|
81
|
+
if (!status)
|
|
82
|
+
return "pending";
|
|
83
|
+
if (status === "completed" || status === "success" || status === "Completed")
|
|
84
|
+
return "confirmed";
|
|
85
|
+
if (status === "failed" || status === "error" || status === "Failed")
|
|
86
|
+
return "failed";
|
|
87
|
+
return "pending";
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=rgb-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb-helpers.js","sourceRoot":"","sources":["../../src/lib/rgb-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,SAAiB;IAC5D,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;QAAE,OAAO,SAAS,CAAC;IAChF,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,MAAM,CAAC;IACvE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAC/C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IACrE,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAChE,IAAI,MAAM,KAAK,qBAAqB;QAAE,OAAO,SAAS,CAAC;IACvD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAe;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACjG,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAChE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACjG,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACtF,OAAO,SAAS,CAAC;AACnB,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,CAAA;AAED,eAAO,MAAM,gBAAgB,uEACyC,CAAA;AAEtE,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,YAAY,IAAI,CAAA;AAE7B,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,SAAS,GAAG,SAAS,EAAE,MAAM,CAGlE,CAAA;AAED,eAAO,MAAM,wBAAwB,iCAAiC,CAAA;AACtE,eAAO,MAAM,6BAA6B,2CAA2C,CAAA;AACrF,eAAO,MAAM,sBAAsB,8CAA8C,CAAA;AAEjF,eAAO,MAAM,oBAAoB,MAAM,CAAA;AAEvC,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAI7C,CAAA;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,eAAe,GAAG,IAAI,CAKxB;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAE5E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAI5E;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,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,0BAA0B,GAAG;IACxC,kBAAkB,CAAC,OAAO;IAC1B,mEAAmE;CACpE,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAC3B,oEAAoE,CAAA;AAEtE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA;AAC9B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAA;AAE7B,MAAM,CAAC,MAAM,gBAAgB,GAA0C;IACrE,OAAO,EAAE,0BAA0B;IACnC,OAAO,EAAE,2CAA2C;CACrD,CAAA;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,8BAA8B,CAAA;AACtE,MAAM,CAAC,MAAM,6BAA6B,GAAG,wCAAwC,CAAA;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG,2CAA2C,CAAA;AAEjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,G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
|
@@ -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",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"types": "./dist/adapters/spark.d.ts",
|
|
23
23
|
"default": "./dist/adapters/spark.js"
|
|
24
24
|
},
|
|
25
|
+
"./adapters/rgb": {
|
|
26
|
+
"types": "./dist/adapters/rgb.d.ts",
|
|
27
|
+
"default": "./dist/adapters/rgb.js"
|
|
28
|
+
},
|
|
29
|
+
"./adapters/flashnet": {
|
|
30
|
+
"types": "./dist/adapters/flashnet.d.ts",
|
|
31
|
+
"default": "./dist/adapters/flashnet.js"
|
|
32
|
+
},
|
|
25
33
|
"./adapters/wdk": {
|
|
26
34
|
"types": "./dist/adapters/wdk/index.d.ts",
|
|
27
35
|
"default": "./dist/adapters/wdk/index.js"
|