@kaleidorg/wallet-engine 1.0.0-beta.35 → 1.0.0-beta.37
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/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/adapters/spark.d.ts +1 -0
- package/dist/adapters/spark.d.ts.map +1 -1
- package/dist/adapters/spark.js +3 -0
- package/dist/adapters/spark.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/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/package.json +5 -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,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC9E,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC;QACjC,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC;QAC5B,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;QACnD,gBAAgB,EAAE,YAAY,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,E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C,OAAO,CAAC,CAAC;IACzC,MAAM,WAAW,GAAI,OAAO,CAAC,YAA0C,IAAI,IAAI,CAAC;IAChF,MAAM,OAAO,GAAI,OAAO,CAAC,QAAsC,IAAI,IAAI,CAAC;IACxE,MAAM,MAAM,GAAG,WAAW,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,MAAM,SAAS,GAAI,OAAO,CAAC,UAAiC;QAC1D,CAAC,CAAE,OAAO,CAAC,UAAqB,GAAG,IAAI;QACvC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACf,OAAO;QACL,EAAE,EAAG,OAAO,CAAC,YAAuB,IAAI,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE;QAC3D,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;QAClC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAA4B,CAAC;QAC9D,SAAS;QACT,MAAM;QACN,aAAa,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QACtC,GAAG,EAAE,CAAC;QACN,UAAU,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9B,KAAK,EAAE,EAAkB;QACzB,EAAE,EAAE,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;;;;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AChE,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/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.37",
|
|
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,10 @@
|
|
|
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
|
+
},
|
|
25
29
|
"./adapters/wdk": {
|
|
26
30
|
"types": "./dist/adapters/wdk/index.d.ts",
|
|
27
31
|
"default": "./dist/adapters/wdk/index.js"
|