@miradexio/client 0.1.0 → 0.1.2
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/README.md +57 -292
- package/dist/address/base58.d.ts.map +1 -1
- package/dist/address/base58.js +1 -2
- package/dist/address/base58.js.map +1 -1
- package/dist/address/bech32.d.ts +0 -8
- package/dist/address/bech32.d.ts.map +1 -1
- package/dist/address/bech32.js +3 -9
- package/dist/address/bech32.js.map +1 -1
- package/dist/address/evm.d.ts.map +1 -1
- package/dist/address/evm.js +1 -2
- package/dist/address/evm.js.map +1 -1
- package/dist/address/index.d.ts +0 -6
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +6 -9
- package/dist/address/index.js.map +1 -1
- package/dist/address/monero.d.ts +0 -10
- package/dist/address/monero.d.ts.map +1 -1
- package/dist/address/monero.js +4 -10
- package/dist/address/monero.js.map +1 -1
- package/dist/address/polkadot.d.ts +0 -5
- package/dist/address/polkadot.d.ts.map +1 -1
- package/dist/address/polkadot.js +2 -6
- package/dist/address/polkadot.js.map +1 -1
- package/dist/address/ton.d.ts +0 -6
- package/dist/address/ton.d.ts.map +1 -1
- package/dist/address/ton.js +3 -8
- package/dist/address/ton.js.map +1 -1
- package/dist/api/index.d.ts +0 -19
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +18 -37
- package/dist/api/index.js.map +1 -1
- package/dist/atomic-swap/drive.d.ts +0 -13
- package/dist/atomic-swap/drive.d.ts.map +1 -1
- package/dist/atomic-swap/drive.js +66 -111
- package/dist/atomic-swap/drive.js.map +1 -1
- package/dist/atomic-swap/extract.d.ts +0 -23
- package/dist/atomic-swap/extract.d.ts.map +1 -1
- package/dist/atomic-swap/extract.js +6 -16
- package/dist/atomic-swap/extract.js.map +1 -1
- package/dist/atomic-swap/index.d.ts +0 -7
- package/dist/atomic-swap/index.d.ts.map +1 -1
- package/dist/atomic-swap/index.js +1 -7
- package/dist/atomic-swap/index.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/errors.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/errors.js +5 -20
- package/dist/atomic-swap/monero-sweep/errors.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/index.d.ts +0 -13
- package/dist/atomic-swap/monero-sweep/index.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/index.js +30 -56
- package/dist/atomic-swap/monero-sweep/index.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/ring-select.d.ts +0 -4
- package/dist/atomic-swap/monero-sweep/ring-select.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/ring-select.js +9 -21
- package/dist/atomic-swap/monero-sweep/ring-select.js.map +1 -1
- package/dist/atomic-swap/presign.d.ts +0 -63
- package/dist/atomic-swap/presign.d.ts.map +1 -1
- package/dist/atomic-swap/presign.js +30 -90
- package/dist/atomic-swap/presign.js.map +1 -1
- package/dist/atomic-swap/refund.d.ts +0 -18
- package/dist/atomic-swap/refund.d.ts.map +1 -1
- package/dist/atomic-swap/refund.js +16 -32
- package/dist/atomic-swap/refund.js.map +1 -1
- package/dist/atomic-swap/run.d.ts +0 -17
- package/dist/atomic-swap/run.d.ts.map +1 -1
- package/dist/atomic-swap/run.js +11 -25
- package/dist/atomic-swap/run.js.map +1 -1
- package/dist/atomic-swap/snapshot.d.ts +0 -30
- package/dist/atomic-swap/snapshot.d.ts.map +1 -1
- package/dist/atomic-swap/snapshot.js +8 -23
- package/dist/atomic-swap/snapshot.js.map +1 -1
- package/dist/atomic-swap/submit-encsig.d.ts +0 -7
- package/dist/atomic-swap/submit-encsig.d.ts.map +1 -1
- package/dist/atomic-swap/submit-encsig.js +2 -11
- package/dist/atomic-swap/submit-encsig.js.map +1 -1
- package/dist/atomic-swap/types.d.ts +2 -55
- package/dist/atomic-swap/types.d.ts.map +1 -1
- package/dist/atomic-swap/types.js +2 -3
- package/dist/atomic-swap/types.js.map +1 -1
- package/dist/blockchain/quorum-provider.d.ts +0 -15
- package/dist/blockchain/quorum-provider.d.ts.map +1 -1
- package/dist/blockchain/quorum-provider.js +7 -9
- package/dist/blockchain/quorum-provider.js.map +1 -1
- package/dist/cooperative-redeem.d.ts +5 -14
- package/dist/cooperative-redeem.d.ts.map +1 -1
- package/dist/cooperative-redeem.js +3 -20
- package/dist/cooperative-redeem.js.map +1 -1
- package/dist/engine/blockchain-querier.d.ts +0 -22
- package/dist/engine/blockchain-querier.d.ts.map +1 -1
- package/dist/engine/engine-state.d.ts +0 -8
- package/dist/engine/engine-state.d.ts.map +1 -1
- package/dist/engine/engine-state.js.map +1 -1
- package/dist/engine/flow-context.d.ts +0 -20
- package/dist/engine/flow-context.d.ts.map +1 -1
- package/dist/engine/flow-context.js +17 -41
- package/dist/engine/flow-context.js.map +1 -1
- package/dist/engine/flows/atomic-flow.d.ts +0 -28
- package/dist/engine/flows/atomic-flow.d.ts.map +1 -1
- package/dist/engine/flows/atomic-flow.js +64 -121
- package/dist/engine/flows/atomic-flow.js.map +1 -1
- package/dist/engine/flows/swap-flow.d.ts +0 -19
- package/dist/engine/flows/swap-flow.d.ts.map +1 -1
- package/dist/engine/flows/swap-flow.js +41 -83
- package/dist/engine/flows/swap-flow.js.map +1 -1
- package/dist/engine/miradex-engine.d.ts +1 -62
- package/dist/engine/miradex-engine.d.ts.map +1 -1
- package/dist/engine/miradex-engine.js +18 -50
- package/dist/engine/miradex-engine.js.map +1 -1
- package/dist/engine/pipeline.d.ts +0 -11
- package/dist/engine/pipeline.d.ts.map +1 -1
- package/dist/engine/pipeline.js +9 -21
- package/dist/engine/pipeline.js.map +1 -1
- package/dist/engine/platform.d.ts +0 -160
- package/dist/engine/platform.d.ts.map +1 -1
- package/dist/engine/platform.js +2 -0
- package/dist/engine/platform.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -11
- package/dist/index.js.map +1 -1
- package/dist/interfaces/blockchain.d.ts +1 -13
- package/dist/interfaces/blockchain.d.ts.map +1 -1
- package/dist/interfaces/blockchain.js +1 -0
- package/dist/interfaces/blockchain.js.map +1 -1
- package/dist/interfaces/logger.d.ts +0 -6
- package/dist/interfaces/logger.d.ts.map +1 -1
- package/dist/interfaces/logger.js.map +1 -1
- package/dist/lib/bitcoin/deposit-watcher.d.ts +0 -23
- package/dist/lib/bitcoin/deposit-watcher.d.ts.map +1 -1
- package/dist/lib/bitcoin/deposit-watcher.js +7 -31
- package/dist/lib/bitcoin/deposit-watcher.js.map +1 -1
- package/dist/lib/bitcoin/script-hash.d.ts.map +1 -1
- package/dist/lib/bitcoin/script-hash.js +2 -6
- package/dist/lib/bitcoin/script-hash.js.map +1 -1
- package/dist/lib/bitcoin/sweep.d.ts +0 -30
- package/dist/lib/bitcoin/sweep.d.ts.map +1 -1
- package/dist/lib/bitcoin/sweep.js +11 -40
- package/dist/lib/bitcoin/sweep.js.map +1 -1
- package/dist/lib/bitcoin/tx-verify.d.ts +0 -28
- package/dist/lib/bitcoin/tx-verify.d.ts.map +1 -1
- package/dist/lib/bitcoin/tx-verify.js +20 -61
- package/dist/lib/bitcoin/tx-verify.js.map +1 -1
- package/dist/lib/bitcoin/wallet.d.ts +0 -38
- package/dist/lib/bitcoin/wallet.d.ts.map +1 -1
- package/dist/lib/bitcoin/wallet.js +13 -38
- package/dist/lib/bitcoin/wallet.js.map +1 -1
- package/dist/lib/crypto/bytes.d.ts +0 -14
- package/dist/lib/crypto/bytes.d.ts.map +1 -1
- package/dist/lib/crypto/bytes.js +5 -14
- package/dist/lib/crypto/bytes.js.map +1 -1
- package/dist/lib/crypto/errors.d.ts +0 -5
- package/dist/lib/crypto/errors.d.ts.map +1 -1
- package/dist/lib/crypto/errors.js +2 -5
- package/dist/lib/crypto/errors.js.map +1 -1
- package/dist/lib/crypto/libp2p-identity.d.ts +0 -15
- package/dist/lib/crypto/libp2p-identity.d.ts.map +1 -1
- package/dist/lib/crypto/libp2p-identity.js +16 -28
- package/dist/lib/crypto/libp2p-identity.js.map +1 -1
- package/dist/lib/crypto/mnemonic.d.ts +0 -9
- package/dist/lib/crypto/mnemonic.d.ts.map +1 -1
- package/dist/lib/crypto/mnemonic.js +11 -27
- package/dist/lib/crypto/mnemonic.js.map +1 -1
- package/dist/lib/crypto/platform.d.ts +0 -6
- package/dist/lib/crypto/platform.d.ts.map +1 -1
- package/dist/lib/crypto/platform.js +2 -6
- package/dist/lib/crypto/platform.js.map +1 -1
- package/dist/lib/crypto/scalars.d.ts +0 -23
- package/dist/lib/crypto/scalars.d.ts.map +1 -1
- package/dist/lib/crypto/scalars.js +10 -23
- package/dist/lib/crypto/scalars.js.map +1 -1
- package/dist/lib/crypto/types.d.ts +0 -4
- package/dist/lib/crypto/types.d.ts.map +1 -1
- package/dist/lib/crypto/wasm.d.ts +0 -23
- package/dist/lib/crypto/wasm.d.ts.map +1 -1
- package/dist/lib/crypto/wasm.js +10 -13
- package/dist/lib/crypto/wasm.js.map +1 -1
- package/dist/lib/default-config.d.ts +1 -59
- package/dist/lib/default-config.d.ts.map +1 -1
- package/dist/lib/default-config.js +22 -61
- package/dist/lib/default-config.js.map +1 -1
- package/dist/lib/errors.d.ts +0 -54
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +12 -35
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/keystore.d.ts +0 -24
- package/dist/lib/keystore.d.ts.map +1 -1
- package/dist/lib/keystore.js +3 -10
- package/dist/lib/keystore.js.map +1 -1
- package/dist/lib/monero/output-scanner.d.ts +0 -18
- package/dist/lib/monero/output-scanner.d.ts.map +1 -1
- package/dist/lib/monero/output-scanner.js +17 -40
- package/dist/lib/monero/output-scanner.js.map +1 -1
- package/dist/lib/monero/rpc.d.ts +0 -64
- package/dist/lib/monero/rpc.d.ts.map +1 -1
- package/dist/lib/monero/rpc.js +17 -59
- package/dist/lib/monero/rpc.js.map +1 -1
- package/dist/lib/monero/verify-lock.d.ts +0 -12
- package/dist/lib/monero/verify-lock.d.ts.map +1 -1
- package/dist/lib/monero/verify-lock.js +9 -24
- package/dist/lib/monero/verify-lock.js.map +1 -1
- package/dist/lib/monero/verify-sweep.d.ts +0 -20
- package/dist/lib/monero/verify-sweep.d.ts.map +1 -1
- package/dist/lib/monero/verify-sweep.js +7 -25
- package/dist/lib/monero/verify-sweep.js.map +1 -1
- package/dist/lib/pow-solver.d.ts.map +1 -1
- package/dist/lib/pow-solver.js +3 -8
- package/dist/lib/pow-solver.js.map +1 -1
- package/dist/lib/retry.d.ts +7 -64
- package/dist/lib/retry.d.ts.map +1 -1
- package/dist/lib/retry.js +13 -13
- package/dist/lib/retry.js.map +1 -1
- package/dist/portable.d.ts.map +1 -1
- package/dist/portable.js +3 -4
- package/dist/portable.js.map +1 -1
- package/dist/quote-binding.d.ts +0 -13
- package/dist/quote-binding.d.ts.map +1 -1
- package/dist/quote-binding.js +3 -18
- package/dist/quote-binding.js.map +1 -1
- package/dist/swap-executor.d.ts +1 -5
- package/dist/swap-executor.d.ts.map +1 -1
- package/dist/swap-executor.js +1 -1
- package/dist/swap-executor.js.map +1 -1
- package/dist/types/api.d.ts +0 -6
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js +6 -9
- package/dist/types/api.js.map +1 -1
- package/dist/types/errors.d.ts +0 -7
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -7
- package/dist/types/errors.js.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/keys.d.ts +0 -15
- package/dist/types/keys.d.ts.map +1 -1
- package/dist/types/protocol.d.ts +0 -51
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +3 -8
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/status.js +9 -14
- package/dist/types/status.js.map +1 -1
- package/dist/types/verification.d.ts +0 -10
- package/dist/types/verification.d.ts.map +1 -1
- package/dist/types/verification.js +7 -15
- package/dist/types/verification.js.map +1 -1
- package/dist/verification/chainflip-networks.d.ts +2 -35
- package/dist/verification/chainflip-networks.d.ts.map +1 -1
- package/dist/verification/chainflip-networks.js +12 -4
- package/dist/verification/chainflip-networks.js.map +1 -1
- package/dist/verification/chainflip.d.ts +0 -40
- package/dist/verification/chainflip.d.ts.map +1 -1
- package/dist/verification/chainflip.js +49 -129
- package/dist/verification/chainflip.js.map +1 -1
- package/dist/verification/constants.d.ts +0 -40
- package/dist/verification/constants.d.ts.map +1 -1
- package/dist/verification/constants.js +14 -40
- package/dist/verification/constants.js.map +1 -1
- package/dist/verification/index.d.ts +0 -26
- package/dist/verification/index.d.ts.map +1 -1
- package/dist/verification/index.js +8 -12
- package/dist/verification/index.js.map +1 -1
- package/dist/verification/memo.d.ts +0 -15
- package/dist/verification/memo.d.ts.map +1 -1
- package/dist/verification/memo.js +9 -27
- package/dist/verification/memo.js.map +1 -1
- package/dist/verification/near-intents.d.ts +0 -63
- package/dist/verification/near-intents.d.ts.map +1 -1
- package/dist/verification/near-intents.js +25 -67
- package/dist/verification/near-intents.js.map +1 -1
- package/dist/verification/rate-oracle.d.ts +0 -22
- package/dist/verification/rate-oracle.d.ts.map +1 -1
- package/dist/verification/rate-oracle.js +6 -11
- package/dist/verification/rate-oracle.js.map +1 -1
- package/dist/verification/thorchain-networks.d.ts +0 -27
- package/dist/verification/thorchain-networks.d.ts.map +1 -1
- package/dist/verification/thorchain-networks.js +13 -15
- package/dist/verification/thorchain-networks.js.map +1 -1
- package/dist/verification/thorchain.d.ts +0 -30
- package/dist/verification/thorchain.d.ts.map +1 -1
- package/dist/verification/thorchain.js +24 -47
- package/dist/verification/thorchain.js.map +1 -1
- package/dist/wasm-pins.d.ts +3 -3
- package/dist/wasm-pins.js +1 -1
- package/dist/wire/near-intents.zod.d.ts +0 -27
- package/dist/wire/near-intents.zod.d.ts.map +1 -1
- package/dist/wire/near-intents.zod.js +15 -23
- package/dist/wire/near-intents.zod.js.map +1 -1
- package/dist/wire/server/action.zod.d.ts +0 -10
- package/dist/wire/server/action.zod.d.ts.map +1 -1
- package/dist/wire/server/action.zod.js +8 -14
- package/dist/wire/server/action.zod.js.map +1 -1
- package/dist/wire/server/common.zod.d.ts +0 -13
- package/dist/wire/server/common.zod.d.ts.map +1 -1
- package/dist/wire/server/common.zod.js +6 -14
- package/dist/wire/server/common.zod.js.map +1 -1
- package/dist/wire/server/swap.zod.d.ts +0 -42
- package/dist/wire/server/swap.zod.d.ts.map +1 -1
- package/dist/wire/server/swap.zod.js +12 -26
- package/dist/wire/server/swap.zod.js.map +1 -1
- package/dist/wire/thorchain.zod.d.ts +0 -8
- package/dist/wire/thorchain.zod.d.ts.map +1 -1
- package/dist/wire/thorchain.zod.js +3 -8
- package/dist/wire/thorchain.zod.js.map +1 -1
- package/package.json +4 -5
- package/wasm/miradex-rust/README.md +3 -4
- package/wasm/miradex-rust/miradex_rust.d.ts +4 -6
- package/wasm/miradex-rust/miradex_rust.js +4 -6
- package/wasm/miradex-rust/miradex_rust_bg.wasm +0 -0
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Types are inferred from schemas — one source of truth, zero drift.
|
|
10
|
-
* Validation uses safeParse — never throws, returns structured errors.
|
|
11
|
-
*/
|
|
1
|
+
// Three strictness levels:
|
|
2
|
+
// FlowContext - base, nullable (keygen, creating-swap)
|
|
3
|
+
// PopulatedFlowContext - snapshot-critical fields non-empty
|
|
4
|
+
// (awaiting-deposit, deposit-detected)
|
|
5
|
+
// VerifiedFlowContext - populated + verification non-null
|
|
6
|
+
// (signing, funding, confirming, swapping)
|
|
7
|
+
// Types are inferred from the schemas; validation uses safeParse.
|
|
12
8
|
import { z } from 'zod';
|
|
13
9
|
const VerificationCheckSchema = z.object({
|
|
14
10
|
name: z.string(),
|
|
@@ -26,36 +22,29 @@ const FlowContextExtraSchema = z.object({
|
|
|
26
22
|
text: z.string().min(1, 'extra.text must not be empty'),
|
|
27
23
|
type: z.enum(EXTRA_TYPES),
|
|
28
24
|
});
|
|
29
|
-
//
|
|
30
|
-
// Every field is nullable — the engine builds it up progressively.
|
|
25
|
+
// Every field nullable; the engine builds it up progressively.
|
|
31
26
|
const FlowContextBaseSchema = z.object({
|
|
32
|
-
// Addresses
|
|
33
27
|
depositAddr: z.string().nullable(),
|
|
34
28
|
destAddress: z.string().nullable(),
|
|
35
29
|
refundAddress: z.string().nullable(),
|
|
36
30
|
keystoreId: z.string().nullable(),
|
|
37
|
-
// Amounts
|
|
38
31
|
depositAmount: z.string().nullable(),
|
|
39
32
|
fromToken: z.string().nullable(),
|
|
40
33
|
toToken: z.string().nullable(),
|
|
41
34
|
expectedOut: z.string().nullable(),
|
|
42
35
|
amountInUsd: z.string().nullable(),
|
|
43
36
|
expectedOutUsd: z.string().nullable(),
|
|
44
|
-
// Display
|
|
45
37
|
qr: z.string().nullable(),
|
|
46
38
|
verification: VerificationResultSchema.nullable(),
|
|
47
39
|
verificationSourceUrl: z.string().nullable(),
|
|
48
40
|
expiresAt: z.string().nullable(),
|
|
49
41
|
depositMemo: z.string().nullable(),
|
|
50
|
-
// Identity
|
|
51
42
|
provider: z.string().nullable(),
|
|
52
43
|
swapId: z.string().nullable(),
|
|
53
44
|
swapNumber: z.string().nullable(),
|
|
54
|
-
// Contextual
|
|
55
45
|
extra: FlowContextExtraSchema.nullable(),
|
|
56
46
|
});
|
|
57
|
-
//
|
|
58
|
-
// non-empty strings — Zod rejects "" and null at runtime.
|
|
47
|
+
// Critical snapshot fields must be non-empty for deposit-ready phases.
|
|
59
48
|
const PopulatedFlowContextSchema = FlowContextBaseSchema.extend({
|
|
60
49
|
depositAddr: z.string().min(1, 'depositAddr is required for this phase'),
|
|
61
50
|
destAddress: z.string().min(1, 'destAddress is required for this phase'),
|
|
@@ -63,24 +52,18 @@ const PopulatedFlowContextSchema = FlowContextBaseSchema.extend({
|
|
|
63
52
|
toToken: z.string().min(1, 'toToken is required for this phase'),
|
|
64
53
|
qr: z.string().min(1, 'qr is required for this phase'),
|
|
65
54
|
provider: z.string().min(1, 'provider is required for this phase'),
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// provider not in the quote set). The deposit, swap, and refund paths
|
|
70
|
-
// do not depend on knowing the exact expected output, so blocking
|
|
71
|
-
// `deposit-detected` on it would force the SDK to fail a swap that's
|
|
72
|
-
// otherwise progressing fine. UIs already handle null with a "—".
|
|
55
|
+
// expectedOut stays nullable: it's display-only, sourced from /quotes which
|
|
56
|
+
// can fail transiently. Deposit/swap/refund paths don't need it; blocking
|
|
57
|
+
// here would fail an otherwise-fine swap. UIs render null as "-".
|
|
73
58
|
expectedOut: z.string().nullable(),
|
|
74
59
|
});
|
|
75
|
-
//
|
|
76
|
-
// MUST be a valid VerificationResult (non-null).
|
|
60
|
+
// Post-verification: everything populated + verification non-null.
|
|
77
61
|
const VerifiedFlowContextSchema = PopulatedFlowContextSchema.extend({
|
|
78
62
|
verification: VerificationResultSchema,
|
|
79
63
|
});
|
|
80
|
-
// Re-
|
|
64
|
+
// Re-exported for tests and adapter implementations.
|
|
81
65
|
export { FlowContextBaseSchema, PopulatedFlowContextSchema, VerifiedFlowContextSchema, FlowContextExtraSchema, VerificationResultSchema, VerificationCheckSchema, };
|
|
82
|
-
//
|
|
83
|
-
// missing/invalid field. The engine calls these before emitting phases.
|
|
66
|
+
// Engine calls these before emitting phases; structured error per failure.
|
|
84
67
|
function buildValidationError(phase, zodError) {
|
|
85
68
|
const fields = zodError.issues.map((issue) => issue.path.join('.'));
|
|
86
69
|
const details = zodError.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`);
|
|
@@ -129,18 +112,11 @@ const EMPTY_FLOW_CONTEXT = {
|
|
|
129
112
|
swapNumber: null,
|
|
130
113
|
extra: null,
|
|
131
114
|
};
|
|
132
|
-
|
|
133
|
-
* Create a new FlowContext with defaults, overriding with provided values.
|
|
134
|
-
* Null values in partial are applied (they mean "not yet known").
|
|
135
|
-
*/
|
|
115
|
+
// null in `partial` is a valid override and means "not yet known".
|
|
136
116
|
export function createFlowContext(partial) {
|
|
137
117
|
return { ...EMPTY_FLOW_CONTEXT, ...partial };
|
|
138
118
|
}
|
|
139
|
-
|
|
140
|
-
* Merge an update into an existing FlowContext.
|
|
141
|
-
* Only non-undefined keys in partial overwrite. Null IS a valid value
|
|
142
|
-
* (it means "reset to unknown").
|
|
143
|
-
*/
|
|
119
|
+
// Only non-undefined keys overwrite. null means "reset to unknown".
|
|
144
120
|
export function mergeFlowContext(current, partial) {
|
|
145
121
|
return { ...current, ...partial };
|
|
146
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-context.js","sourceRoot":"","sources":["../../src/engine/flow-context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"flow-context.js","sourceRoot":"","sources":["../../src/engine/flow-context.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,kEAAkE;AAClE,8DAA8D;AAC9D,gEAAgE;AAChE,6DAA6D;AAC7D,oEAAoE;AACpE,kEAAkE;AAElE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE;IACnD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,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only pollMs;
|
|
22
|
-
/**
|
|
23
|
-
* True once the driver has emitted a terminal phase (`completed`,
|
|
24
|
-
* `failed`, `refunded`, etc.). Used to suppress the post-driver
|
|
25
|
-
* `requiredAction` re-check that would otherwise trigger a phantom
|
|
26
|
-
* second sweep — the server has no scanner for the on-chain XMR sweep,
|
|
27
|
-
* so a fresh `getSwapDetail` right after the driver completes still
|
|
28
|
-
* reports `requiredAction.type === 'sweep'`.
|
|
29
|
-
*/
|
|
30
22
|
private hasReachedTerminal;
|
|
31
|
-
/**
|
|
32
|
-
* Optional maker pin forwarded to `coreResumeAtomicSwap` via
|
|
33
|
-
* `params.variantId`. Set by `start()` from `StartAtomicSwapParams`;
|
|
34
|
-
* unused (and irrelevant) on the resume path because the maker is
|
|
35
|
-
* already chosen at that point.
|
|
36
|
-
*/
|
|
37
23
|
private variantId;
|
|
38
24
|
constructor(api: ApiClient, platform: PlatformAdapter, config: ResolvedEngineConfig, emitFn: (state: AtomicFlowState) => void, options?: AtomicFlowOptions);
|
|
39
25
|
private get signal();
|
|
40
26
|
private get logger();
|
|
41
27
|
private setFlowContext;
|
|
42
|
-
/**
|
|
43
|
-
* Validate FlowContext as PopulatedFlowContext.
|
|
44
|
-
* On failure, emits a 'failed' phase with structured error and returns null.
|
|
45
|
-
*/
|
|
46
28
|
private requirePopulated;
|
|
47
|
-
/**
|
|
48
|
-
* Validate FlowContext as VerifiedFlowContext.
|
|
49
|
-
* On failure, emits a 'failed' phase with structured error and returns null.
|
|
50
|
-
*/
|
|
51
29
|
private requireVerified;
|
|
52
30
|
private emitError;
|
|
53
31
|
private transition;
|
|
@@ -69,12 +47,6 @@ export declare class AtomicFlow {
|
|
|
69
47
|
private executeSweep;
|
|
70
48
|
private executeRefund;
|
|
71
49
|
private resolveLockAddress;
|
|
72
|
-
/**
|
|
73
|
-
* Read protocol params from the server response; fall back to the platform
|
|
74
|
-
* adapter's optional write-through cache when the server didn't return the
|
|
75
|
-
* refund encsig. On success from the server, populate the cache so later
|
|
76
|
-
* refunds survive a briefly-unreachable backend.
|
|
77
|
-
*/
|
|
78
50
|
private resolveProtocolParams;
|
|
79
51
|
private cacheProtocolParams;
|
|
80
52
|
private emitRefundAborted;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-flow.d.ts","sourceRoot":"","sources":["../../../src/engine/flows/atomic-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"atomic-flow.d.ts","sourceRoot":"","sources":["../../../src/engine/flows/atomic-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;AAyEnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,UAAU;IAqBnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAvBzB,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,kBAAkB,CAA6B;IACvD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,UAAU,CAAc;IAChC,OA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Z,qBAAqB;YAiCrB,mBAAmB;IAiBjC,OAAO,CAAC,iBAAiB;YAUX,iBAAiB;IAuC/B,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,6BAA6B;CAItC"}
|
|
@@ -27,16 +27,14 @@ function isTransientError(err) {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* until a separate TxReclaim phase (not yet implemented client-side).
|
|
39
|
-
*/
|
|
30
|
+
// True if the params carry enough material to refund without the sidecar.
|
|
31
|
+
// Two valid shapes:
|
|
32
|
+
// Legacy/Full: tx_full_refund_encsig alone (client builds + broadcasts
|
|
33
|
+
// TxFullRefund spending TxCancel).
|
|
34
|
+
// Partial: tx_partial_refund_encsig + amnesty triple
|
|
35
|
+
// (amnesty_amount_sats, tx_partial_refund_fee_sats). Amnesty
|
|
36
|
+
// output stays at multisig pending TxReclaim (not implemented
|
|
37
|
+
// client-side yet).
|
|
40
38
|
function hasRefundEscapeHatch(params) {
|
|
41
39
|
if (params.tx_full_refund_encsig)
|
|
42
40
|
return true;
|
|
@@ -60,21 +58,13 @@ export class AtomicFlow {
|
|
|
60
58
|
flowCtx = null;
|
|
61
59
|
lastProgressKey = null;
|
|
62
60
|
pollMs;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* second sweep — the server has no scanner for the on-chain XMR sweep,
|
|
68
|
-
* so a fresh `getSwapDetail` right after the driver completes still
|
|
69
|
-
* reports `requiredAction.type === 'sweep'`.
|
|
70
|
-
*/
|
|
61
|
+
// Set once the driver emits a terminal phase. Suppresses the post-driver
|
|
62
|
+
// requiredAction re-check that would otherwise trigger a phantom second
|
|
63
|
+
// sweep — the server has no scanner for the on-chain XMR sweep so a fresh
|
|
64
|
+
// getSwapDetail still reports requiredAction.type === 'sweep'.
|
|
71
65
|
hasReachedTerminal = false;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* `params.variantId`. Set by `start()` from `StartAtomicSwapParams`;
|
|
75
|
-
* unused (and irrelevant) on the resume path because the maker is
|
|
76
|
-
* already chosen at that point.
|
|
77
|
-
*/
|
|
66
|
+
// Forwarded to coreResumeAtomicSwap as params.variantId. Set by start();
|
|
67
|
+
// ignored on resume (maker already chosen).
|
|
78
68
|
variantId;
|
|
79
69
|
constructor(api, platform, config, emitFn, options) {
|
|
80
70
|
this.api = api;
|
|
@@ -94,10 +84,7 @@ export class AtomicFlow {
|
|
|
94
84
|
? mergeFlowContext(this.flowCtx, partial)
|
|
95
85
|
: createFlowContext(partial);
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
* Validate FlowContext as PopulatedFlowContext.
|
|
99
|
-
* On failure, emits a 'failed' phase with structured error and returns null.
|
|
100
|
-
*/
|
|
87
|
+
// On failure, emits 'failed' with a structured error and returns null.
|
|
101
88
|
requirePopulated(phase) {
|
|
102
89
|
if (!this.flowCtx) {
|
|
103
90
|
this.emitError(phase, 'FlowContext not initialized');
|
|
@@ -110,10 +97,7 @@ export class AtomicFlow {
|
|
|
110
97
|
this.emitError(phase, result.error.message);
|
|
111
98
|
return null;
|
|
112
99
|
}
|
|
113
|
-
|
|
114
|
-
* Validate FlowContext as VerifiedFlowContext.
|
|
115
|
-
* On failure, emits a 'failed' phase with structured error and returns null.
|
|
116
|
-
*/
|
|
100
|
+
// On failure, emits 'failed' with a structured error and returns null.
|
|
117
101
|
requireVerified(phase) {
|
|
118
102
|
if (!this.flowCtx) {
|
|
119
103
|
this.emitError(phase, 'FlowContext not initialized');
|
|
@@ -168,17 +152,14 @@ export class AtomicFlow {
|
|
|
168
152
|
this.transition({ phase: 'keygen', snapshot: this.flowCtx, message: 'Initializing keygen...' });
|
|
169
153
|
await ensureWasm();
|
|
170
154
|
const network = this.config.network;
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
// flow is identical from this point forward — same deposit polling,
|
|
174
|
-
// same swap creation, same drive loop.
|
|
155
|
+
// Reuse an existing keystore (re-quote-after-failure) or generate a
|
|
156
|
+
// fresh one. Flow is identical past this point.
|
|
175
157
|
let wallet;
|
|
176
158
|
if (params.existingKeystoreId !== undefined) {
|
|
177
159
|
this.setFlowContext({ extra: { text: 'Loading keystore...', type: 'message' } });
|
|
178
160
|
this.transition({ phase: 'keygen', snapshot: this.flowCtx, message: 'Loading keystore...' });
|
|
179
|
-
// Trust
|
|
180
|
-
//
|
|
181
|
-
// doubling the call's transient-failure surface for a no-op check.
|
|
161
|
+
// Trust the keystore: it was created here and its keys already
|
|
162
|
+
// passed verifyKeys. Re-checking adds a transient-failure surface.
|
|
182
163
|
this.keystore = await this.platform.loadKeystore(params.existingKeystoreId);
|
|
183
164
|
this.keystoreId = params.existingKeystoreId;
|
|
184
165
|
wallet = walletFromWif(this.keystore.btc.wif, network);
|
|
@@ -216,16 +197,10 @@ export class AtomicFlow {
|
|
|
216
197
|
this.keystoreId = saveResult.id;
|
|
217
198
|
this.logger.info({ keystoreId: this.keystoreId }, 'Keystore saved');
|
|
218
199
|
}
|
|
219
|
-
// Emit
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
// snapshot.keystoreId` to decide whether to keep this engine; if
|
|
224
|
-
// the slow chain below blows the budget the engine is destroyed
|
|
225
|
-
// mid-flight and the user has to retry. Emitting a placeholder
|
|
226
|
-
// keystore-saved transition here guarantees the registry binds
|
|
227
|
-
// the engine on first save, regardless of subsequent network
|
|
228
|
-
// latency.
|
|
200
|
+
// Emit keystoreId before the slow pre-deposit chain (estimateFee,
|
|
201
|
+
// getQuotes, generateQr). EngineRegistry races a 30s timeout against
|
|
202
|
+
// state.atomic.snapshot.keystoreId — without this early emit the
|
|
203
|
+
// engine gets destroyed mid-flight on slow networks.
|
|
229
204
|
this.setFlowContext({ keystoreId: this.keystoreId });
|
|
230
205
|
this.transition({
|
|
231
206
|
phase: 'keystore-saved',
|
|
@@ -244,12 +219,8 @@ export class AtomicFlow {
|
|
|
244
219
|
}
|
|
245
220
|
catch { /* non-fatal */ }
|
|
246
221
|
const qr = await this.platform.generateQr(wallet.address);
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
// QR. The first `keystore-saved` transition above was the bare-
|
|
250
|
-
// bones state emit needed to keep the registry from destroying
|
|
251
|
-
// this engine; this second `setFlowContext` enriches it before
|
|
252
|
-
// `awaiting-deposit` validates against `PopulatedFlowContext`.
|
|
222
|
+
// Slow chain done: enrich FlowContext before awaiting-deposit validates
|
|
223
|
+
// against PopulatedFlowContext.
|
|
253
224
|
this.setFlowContext({
|
|
254
225
|
depositAddr: wallet.address,
|
|
255
226
|
depositAmount: requiredBtc,
|
|
@@ -258,7 +229,6 @@ export class AtomicFlow {
|
|
|
258
229
|
extra: { text: `Send ${requiredBtc} BTC to the address above.`, type: 'message' },
|
|
259
230
|
});
|
|
260
231
|
this.checkAborted();
|
|
261
|
-
// Validate before emitting awaiting-deposit
|
|
262
232
|
const populated = this.requirePopulated('awaiting-deposit');
|
|
263
233
|
if (!populated)
|
|
264
234
|
return;
|
|
@@ -334,15 +304,10 @@ export class AtomicFlow {
|
|
|
334
304
|
this.emitTerminal(existingSwapId, detail.status, detail);
|
|
335
305
|
return;
|
|
336
306
|
}
|
|
337
|
-
// Funding-address UTXO is only meaningful pre-broadcast
|
|
338
|
-
// swap is
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
// testnet/stagenet electrs (cold TLS, multi-server fallback,
|
|
342
|
-
// flaky public endpoints) and the result feeds nothing
|
|
343
|
-
// downstream once the protocol is past funding. Skip it for
|
|
344
|
-
// post-funding statuses so resume settles immediately on the
|
|
345
|
-
// current state instead of stalling on a useless network probe.
|
|
307
|
+
// Funding-address UTXO is only meaningful pre-broadcast; once the
|
|
308
|
+
// swap is 'deposited' or past, BTC is in TxLock and the funding
|
|
309
|
+
// address is empty. Re-querying costs 2-15s on flaky public
|
|
310
|
+
// electrs and feeds nothing downstream — skip for post-funding.
|
|
346
311
|
const PRE_FUNDING_STATUSES = new Set([
|
|
347
312
|
'initializing',
|
|
348
313
|
'pending',
|
|
@@ -353,7 +318,6 @@ export class AtomicFlow {
|
|
|
353
318
|
: null;
|
|
354
319
|
if (deposit)
|
|
355
320
|
this.deposit = deposit;
|
|
356
|
-
// Verify the contract for the resumed swap
|
|
357
321
|
let verification = null;
|
|
358
322
|
if (detail.depositAddress && detail.verification) {
|
|
359
323
|
const { verifyDepositAddress } = await import('../../verification/index.js');
|
|
@@ -364,8 +328,7 @@ export class AtomicFlow {
|
|
|
364
328
|
refundAddress: this.keystore.swap.refundAddress,
|
|
365
329
|
toToken: 'XMR',
|
|
366
330
|
amount: '',
|
|
367
|
-
//
|
|
368
|
-
// blocks come from the typed atomicswap params when present.
|
|
331
|
+
// lock_address = SwapDetail.depositAddress; timelock from typed params.
|
|
369
332
|
protocol: detail.depositAddress &&
|
|
370
333
|
detail.protocolData?.type === 'atomicswap' &&
|
|
371
334
|
detail.protocolData.params
|
|
@@ -379,7 +342,7 @@ export class AtomicFlow {
|
|
|
379
342
|
fetchFn: this.config.fetchFn,
|
|
380
343
|
});
|
|
381
344
|
}
|
|
382
|
-
//
|
|
345
|
+
// Server is past the verification gate; trust it.
|
|
383
346
|
if (!verification) {
|
|
384
347
|
verification = { verified: true, provider: 'atomicswap', checks: [], timestamp: Date.now() };
|
|
385
348
|
}
|
|
@@ -390,8 +353,8 @@ export class AtomicFlow {
|
|
|
390
353
|
depositAmount: deposit ? (deposit.value / 1e8).toFixed(8) : this.flowCtx?.depositAmount ?? null,
|
|
391
354
|
extra: { text: `Resuming swap (${detail.status})...`, type: 'message' },
|
|
392
355
|
});
|
|
393
|
-
//
|
|
394
|
-
//
|
|
356
|
+
// Core supplies verification via progress callbacks on resume; base
|
|
357
|
+
// FlowContext is enough for the entry transition.
|
|
395
358
|
this.transition({
|
|
396
359
|
phase: 'creating-swap',
|
|
397
360
|
snapshot: this.flowCtx,
|
|
@@ -402,10 +365,9 @@ export class AtomicFlow {
|
|
|
402
365
|
}
|
|
403
366
|
this.logger.info({ btcAddress }, 'Resume Path B: local keystore');
|
|
404
367
|
const deposit = await this.platform.fetchUtxo(btcAddress, network);
|
|
405
|
-
//
|
|
406
|
-
//
|
|
407
|
-
//
|
|
408
|
-
// with from the keystore metadata (saved by saveKeystore as `label`).
|
|
368
|
+
// expectedOut is required for PopulatedFlowContext. Pre-funding resume
|
|
369
|
+
// has no on-chain deposit, so pull the original amount from the
|
|
370
|
+
// keystore metadata (saveKeystore stores it as `label`).
|
|
409
371
|
let amountForQuote;
|
|
410
372
|
if (deposit) {
|
|
411
373
|
amountForQuote = (deposit.value / 1e8).toFixed(8);
|
|
@@ -522,9 +484,8 @@ export class AtomicFlow {
|
|
|
522
484
|
throw new Error('keystore must be set before driving swap');
|
|
523
485
|
}
|
|
524
486
|
const network = (this.keystore.btc?.network ?? 'mainnet');
|
|
525
|
-
//
|
|
526
|
-
//
|
|
527
|
-
// on resume). The provider is shared across the driver's lifetime.
|
|
487
|
+
// AV-B.2 (resume): the driver reconstructs TxLock via this provider when
|
|
488
|
+
// recomputing the redeem digest. Shared across the driver's lifetime.
|
|
528
489
|
const blockchain = await this.platform.createBlockchainProvider(network);
|
|
529
490
|
const result = await coreResumeAtomicSwap({
|
|
530
491
|
api: this.api,
|
|
@@ -544,13 +505,10 @@ export class AtomicFlow {
|
|
|
544
505
|
saveProtocolSnapshot: this.platform.saveProtocolSnapshot,
|
|
545
506
|
loadProtocolSnapshot: this.platform.loadProtocolSnapshot,
|
|
546
507
|
});
|
|
547
|
-
//
|
|
548
|
-
//
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
// status=sending right after the client broadcast its sweep tx. Treating
|
|
552
|
-
// that as actionable triggers a phantom second executeSweep that emits a
|
|
553
|
-
// spurious `completed → sweeping` transition.
|
|
508
|
+
// Skip the server re-check if mapCoreProgress already emitted terminal:
|
|
509
|
+
// the server has no on-chain XMR scanner so it still reports
|
|
510
|
+
// requiredAction=sweep right after our broadcast, which would trigger a
|
|
511
|
+
// phantom second executeSweep and a spurious completed -> sweeping flicker.
|
|
554
512
|
if (this.hasReachedTerminal)
|
|
555
513
|
return;
|
|
556
514
|
let finalStatus = 'completed';
|
|
@@ -574,11 +532,9 @@ export class AtomicFlow {
|
|
|
574
532
|
this.emitTerminal(result.swapId, finalStatus, undefined);
|
|
575
533
|
return;
|
|
576
534
|
}
|
|
577
|
-
// Non-terminal
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
// needs to watch for the requiredAction to flip to 'refund' (or the
|
|
581
|
-
// swap to reach terminal). pollUntilTerminal does both.
|
|
535
|
+
// Non-terminal with no actionable requiredAction (e.g. server still
|
|
536
|
+
// broadcasting TxCancel). Sidecar handles cancel; we wait for the
|
|
537
|
+
// action to flip to 'refund' or the swap to reach terminal.
|
|
582
538
|
this.setFlowContext({
|
|
583
539
|
extra: { text: requiredAction?.message ?? 'Waiting for server...', type: 'message' },
|
|
584
540
|
});
|
|
@@ -671,10 +627,9 @@ export class AtomicFlow {
|
|
|
671
627
|
phase: 'completed',
|
|
672
628
|
snapshot: this.flowCtx,
|
|
673
629
|
outputTxHash: p.txHash ?? null,
|
|
674
|
-
// Atomic swaps have no slippage
|
|
675
|
-
//
|
|
676
|
-
//
|
|
677
|
-
// even when the in-flight progress event doesn't carry it.
|
|
630
|
+
// Atomic swaps have no slippage; buyer receives exactly rate * deposit.
|
|
631
|
+
// Fall back to expectedOut so the receipt shows the right number even
|
|
632
|
+
// when the progress event doesn't carry it.
|
|
678
633
|
actualOut: this.flowCtx?.expectedOut ?? '',
|
|
679
634
|
durationSec: null,
|
|
680
635
|
});
|
|
@@ -708,9 +663,8 @@ export class AtomicFlow {
|
|
|
708
663
|
});
|
|
709
664
|
break;
|
|
710
665
|
case 'cancelling':
|
|
711
|
-
//
|
|
712
|
-
//
|
|
713
|
-
// settles in `refunded` (or `failed` if the refund never lands).
|
|
666
|
+
// TxCancel in flight; refund follows. Stay watching until the row
|
|
667
|
+
// settles in 'refunded' (or 'failed' if the refund never lands).
|
|
714
668
|
this.setFlowContext({ extra: { text: p.message, type: 'warning' } });
|
|
715
669
|
this.transition({
|
|
716
670
|
phase: 'creating-swap',
|
|
@@ -720,11 +674,8 @@ export class AtomicFlow {
|
|
|
720
674
|
break;
|
|
721
675
|
case 'withheld':
|
|
722
676
|
case 'expired':
|
|
723
|
-
//
|
|
724
|
-
//
|
|
725
|
-
// terminal statuses in `TerminalStatus`. Emit a `failed` phase so
|
|
726
|
-
// poll consumers (engine driver, TUI exec state) observe a terminal
|
|
727
|
-
// transition and resolve.
|
|
677
|
+
// Both are terminal in TerminalStatus. Emit 'failed' so poll
|
|
678
|
+
// consumers see a terminal transition and resolve.
|
|
728
679
|
this.transition({
|
|
729
680
|
phase: 'failed',
|
|
730
681
|
snapshot: this.flowCtx,
|
|
@@ -733,12 +684,9 @@ export class AtomicFlow {
|
|
|
733
684
|
break;
|
|
734
685
|
case 'punished': {
|
|
735
686
|
// Not terminal. Alice published TxPunish (Bob missed the refund
|
|
736
|
-
// window), but the sidecar
|
|
737
|
-
//
|
|
738
|
-
//
|
|
739
|
-
// the driver finishes the swap with an XMR sweep that lands the row
|
|
740
|
-
// in `completed`. Stay in a watching phase so `drive.ts`'s existing
|
|
741
|
-
// sweep branch can pick up the action transition.
|
|
687
|
+
// window), but the sidecar runs cooperative_xmr_redeem_after_punish
|
|
688
|
+
// to recover s_a; the server then flips requiredAction to 'sweep'
|
|
689
|
+
// and drive.ts finishes via the sweep branch.
|
|
742
690
|
const reason = p.message ||
|
|
743
691
|
'BTC punished — recovering XMR via cooperative_xmr_redeem_after_punish...';
|
|
744
692
|
this.setFlowContext({ extra: { text: reason, type: 'warning' } });
|
|
@@ -1052,12 +1000,10 @@ export class AtomicFlow {
|
|
|
1052
1000
|
}
|
|
1053
1001
|
return '';
|
|
1054
1002
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
* refunds survive a briefly-unreachable backend.
|
|
1060
|
-
*/
|
|
1003
|
+
// Server response first; fall back to the platform adapter's optional
|
|
1004
|
+
// write-through cache when the server omitted the refund encsig. On a
|
|
1005
|
+
// good server response, prime the cache so later refunds survive a brief
|
|
1006
|
+
// backend outage.
|
|
1061
1007
|
async resolveProtocolParams(swapId, detail) {
|
|
1062
1008
|
const fromServer = extractProtocolData(detail).params;
|
|
1063
1009
|
if (fromServer && hasRefundEscapeHatch(fromServer)) {
|
|
@@ -1109,17 +1055,14 @@ export class AtomicFlow {
|
|
|
1109
1055
|
this.emitTerminal(swapId, detail.status, detail);
|
|
1110
1056
|
return;
|
|
1111
1057
|
}
|
|
1112
|
-
//
|
|
1113
|
-
//
|
|
1114
|
-
// briefly unreachable later.
|
|
1058
|
+
// Prime the protocol cache while the server is up; the refund path
|
|
1059
|
+
// falls back to it if the server goes down later.
|
|
1115
1060
|
const polledParams = extractProtocolData(detail).params;
|
|
1116
1061
|
if (polledParams?.tx_full_refund_encsig) {
|
|
1117
1062
|
await this.cacheProtocolParams(swapId, polledParams);
|
|
1118
1063
|
}
|
|
1119
|
-
//
|
|
1120
|
-
//
|
|
1121
|
-
// the client-side refund so we don't drift toward the punish
|
|
1122
|
-
// deadline while idly polling.
|
|
1064
|
+
// 'refund' flip means TxCancel confirmed and the refund window is
|
|
1065
|
+
// open. Auto-trigger so we don't drift toward the punish deadline.
|
|
1123
1066
|
const action = detail.requiredAction ?? null;
|
|
1124
1067
|
if (action?.type === 'refund') {
|
|
1125
1068
|
this.logger.info({ swapId, blocksRemaining: action.blocksRemaining ?? null }, 'Required action flipped to refund — auto-triggering client-side refund');
|