@arkade-os/boltz-swap 0.3.29 → 0.3.31
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 +34 -3
- package/dist/{chunk-LWUXSE5N.js → chunk-B3Q4TFWT.js} +1 -1
- package/dist/chunk-NHBWNN6H.js +117 -0
- package/dist/expo/background.cjs +5407 -0
- package/dist/expo/background.d.cts +61 -0
- package/dist/expo/background.d.ts +61 -0
- package/dist/expo/background.js +127 -0
- package/dist/expo/index.cjs +4673 -5077
- package/dist/expo/index.d.cts +24 -140
- package/dist/expo/index.d.ts +24 -140
- package/dist/expo/index.js +23 -55
- package/dist/index.cjs +14 -3
- package/dist/index.js +14 -4
- package/dist/repositories/realm/index.js +0 -2
- package/dist/repositories/sqlite/index.js +0 -2
- package/dist/swapsPollProcessor-BF3uTFae.d.cts +93 -0
- package/dist/swapsPollProcessor-wYOMzldd.d.ts +93 -0
- package/package.json +25 -3
- package/dist/background-UQDFQCGM.js +0 -12
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-X3JNWDAR.js +0 -261
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-BF3uTFae.cjs';
|
|
2
|
+
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-BF3uTFae.cjs';
|
|
3
|
+
import '@arkade-os/sdk/worker/expo';
|
|
4
|
+
import '@arkade-os/sdk';
|
|
5
|
+
import '../types-BBI7-KJ0.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Define the Expo background task handler for swap polling.
|
|
9
|
+
*
|
|
10
|
+
* **Must be called at module/global scope** (before React mounts) so
|
|
11
|
+
* Expo's TaskManager can resume the task on cold start.
|
|
12
|
+
*
|
|
13
|
+
* Pair with {@link registerExpoSwapBackgroundTask} to activate the OS
|
|
14
|
+
* scheduler — `ExpoArkadeSwaps.setup()` no longer registers the task
|
|
15
|
+
* for you.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // App entry (e.g. _layout.tsx) — module scope
|
|
20
|
+
* import { defineExpoSwapBackgroundTask } from "@arkade-os/boltz-swap/expo/background";
|
|
21
|
+
* import { AsyncStorageTaskQueue } from "@arkade-os/sdk/worker/expo";
|
|
22
|
+
* import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
23
|
+
*
|
|
24
|
+
* const taskQueue = new AsyncStorageTaskQueue(AsyncStorage, "ark:swap-queue");
|
|
25
|
+
* defineExpoSwapBackgroundTask("ark-swap-poll", {
|
|
26
|
+
* taskQueue,
|
|
27
|
+
* swapRepository,
|
|
28
|
+
* identityFactory: async () => {
|
|
29
|
+
* const key = await SecureStore.getItemAsync("ark-private-key");
|
|
30
|
+
* return SingleKey.fromHex(key!);
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function defineExpoSwapBackgroundTask(taskName: string, options: DefineSwapBackgroundTaskOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Activate the OS-level background task scheduler.
|
|
38
|
+
*
|
|
39
|
+
* Call once after {@link defineExpoSwapBackgroundTask} — typically right
|
|
40
|
+
* after `ExpoArkadeSwaps.setup()`. Safe to call again to update the
|
|
41
|
+
* interval.
|
|
42
|
+
*
|
|
43
|
+
* @param taskName - The task name passed to {@link defineExpoSwapBackgroundTask}.
|
|
44
|
+
* @param options.minimumInterval - Minimum interval in **minutes** (default
|
|
45
|
+
* 15, the floor enforced by `expo-background-task`).
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.expo.dev/versions/latest/sdk/background-task/#backgroundtaskoptions
|
|
48
|
+
*/
|
|
49
|
+
declare function registerExpoSwapBackgroundTask(taskName: string, options?: {
|
|
50
|
+
minimumInterval?: number;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Unregister the swap background task from the OS scheduler.
|
|
54
|
+
*
|
|
55
|
+
* `ExpoArkadeSwaps.dispose()` does **not** call this — the OS-level
|
|
56
|
+
* task lifecycle is the consumer's responsibility, matching the explicit
|
|
57
|
+
* `register` step.
|
|
58
|
+
*/
|
|
59
|
+
declare function unregisterExpoSwapBackgroundTask(taskName: string): Promise<void>;
|
|
60
|
+
|
|
61
|
+
export { DefineSwapBackgroundTaskOptions, defineExpoSwapBackgroundTask, registerExpoSwapBackgroundTask, unregisterExpoSwapBackgroundTask };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-wYOMzldd.js';
|
|
2
|
+
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-wYOMzldd.js';
|
|
3
|
+
import '@arkade-os/sdk/worker/expo';
|
|
4
|
+
import '@arkade-os/sdk';
|
|
5
|
+
import '../types-BBI7-KJ0.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Define the Expo background task handler for swap polling.
|
|
9
|
+
*
|
|
10
|
+
* **Must be called at module/global scope** (before React mounts) so
|
|
11
|
+
* Expo's TaskManager can resume the task on cold start.
|
|
12
|
+
*
|
|
13
|
+
* Pair with {@link registerExpoSwapBackgroundTask} to activate the OS
|
|
14
|
+
* scheduler — `ExpoArkadeSwaps.setup()` no longer registers the task
|
|
15
|
+
* for you.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // App entry (e.g. _layout.tsx) — module scope
|
|
20
|
+
* import { defineExpoSwapBackgroundTask } from "@arkade-os/boltz-swap/expo/background";
|
|
21
|
+
* import { AsyncStorageTaskQueue } from "@arkade-os/sdk/worker/expo";
|
|
22
|
+
* import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
23
|
+
*
|
|
24
|
+
* const taskQueue = new AsyncStorageTaskQueue(AsyncStorage, "ark:swap-queue");
|
|
25
|
+
* defineExpoSwapBackgroundTask("ark-swap-poll", {
|
|
26
|
+
* taskQueue,
|
|
27
|
+
* swapRepository,
|
|
28
|
+
* identityFactory: async () => {
|
|
29
|
+
* const key = await SecureStore.getItemAsync("ark-private-key");
|
|
30
|
+
* return SingleKey.fromHex(key!);
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function defineExpoSwapBackgroundTask(taskName: string, options: DefineSwapBackgroundTaskOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Activate the OS-level background task scheduler.
|
|
38
|
+
*
|
|
39
|
+
* Call once after {@link defineExpoSwapBackgroundTask} — typically right
|
|
40
|
+
* after `ExpoArkadeSwaps.setup()`. Safe to call again to update the
|
|
41
|
+
* interval.
|
|
42
|
+
*
|
|
43
|
+
* @param taskName - The task name passed to {@link defineExpoSwapBackgroundTask}.
|
|
44
|
+
* @param options.minimumInterval - Minimum interval in **minutes** (default
|
|
45
|
+
* 15, the floor enforced by `expo-background-task`).
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.expo.dev/versions/latest/sdk/background-task/#backgroundtaskoptions
|
|
48
|
+
*/
|
|
49
|
+
declare function registerExpoSwapBackgroundTask(taskName: string, options?: {
|
|
50
|
+
minimumInterval?: number;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Unregister the swap background task from the OS scheduler.
|
|
54
|
+
*
|
|
55
|
+
* `ExpoArkadeSwaps.dispose()` does **not** call this — the OS-level
|
|
56
|
+
* task lifecycle is the consumer's responsibility, matching the explicit
|
|
57
|
+
* `register` step.
|
|
58
|
+
*/
|
|
59
|
+
declare function unregisterExpoSwapBackgroundTask(taskName: string): Promise<void>;
|
|
60
|
+
|
|
61
|
+
export { DefineSwapBackgroundTaskOptions, defineExpoSwapBackgroundTask, registerExpoSwapBackgroundTask, unregisterExpoSwapBackgroundTask };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SWAP_POLL_TASK_TYPE,
|
|
3
|
+
swapsPollProcessor
|
|
4
|
+
} from "../chunk-NHBWNN6H.js";
|
|
5
|
+
import {
|
|
6
|
+
BoltzSwapProvider
|
|
7
|
+
} from "../chunk-B3Q4TFWT.js";
|
|
8
|
+
|
|
9
|
+
// src/expo/background.ts
|
|
10
|
+
import * as TaskManager from "expo-task-manager";
|
|
11
|
+
import * as BackgroundTask from "expo-background-task";
|
|
12
|
+
import { runTasks } from "@arkade-os/sdk/worker/expo";
|
|
13
|
+
import {
|
|
14
|
+
ExpoArkProvider,
|
|
15
|
+
ExpoIndexerProvider
|
|
16
|
+
} from "@arkade-os/sdk/adapters/expo";
|
|
17
|
+
function getRandomId() {
|
|
18
|
+
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
19
|
+
}
|
|
20
|
+
function createBackgroundWalletShim(args) {
|
|
21
|
+
const notImplemented = (method) => {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`[boltz-swap] Background wallet shim: "${String(method)}" is not implemented`
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
identity: args.identity,
|
|
28
|
+
getAddress: args.getAddress,
|
|
29
|
+
getBoardingAddress: async () => notImplemented("getBoardingAddress"),
|
|
30
|
+
getBalance: async () => notImplemented("getBalance"),
|
|
31
|
+
getVtxos: async () => notImplemented("getVtxos"),
|
|
32
|
+
getBoardingUtxos: async () => notImplemented("getBoardingUtxos"),
|
|
33
|
+
getTransactionHistory: async () => notImplemented("getTransactionHistory"),
|
|
34
|
+
getContractManager: async () => notImplemented("getContractManager"),
|
|
35
|
+
getDelegatorManager: async () => notImplemented("getDelegatorManager"),
|
|
36
|
+
sendBitcoin: async () => notImplemented("sendBitcoin"),
|
|
37
|
+
send: async () => notImplemented("send"),
|
|
38
|
+
settle: async () => notImplemented("settle"),
|
|
39
|
+
assetManager: new Proxy({}, {
|
|
40
|
+
get: () => notImplemented("assetManager")
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function defineExpoSwapBackgroundTask(taskName, options) {
|
|
45
|
+
const { taskQueue, swapRepository, identityFactory } = options;
|
|
46
|
+
TaskManager.defineTask(taskName, async () => {
|
|
47
|
+
try {
|
|
48
|
+
const config = await taskQueue.loadConfig();
|
|
49
|
+
if (!config) {
|
|
50
|
+
return BackgroundTask.BackgroundTaskResult.Success;
|
|
51
|
+
}
|
|
52
|
+
const identity = await identityFactory();
|
|
53
|
+
const arkProvider = new ExpoArkProvider(config.arkServerUrl);
|
|
54
|
+
const indexerProvider = new ExpoIndexerProvider(
|
|
55
|
+
config.arkServerUrl
|
|
56
|
+
);
|
|
57
|
+
const swapProvider = new BoltzSwapProvider({
|
|
58
|
+
network: config.network,
|
|
59
|
+
apiUrl: config.boltzApiUrl
|
|
60
|
+
});
|
|
61
|
+
const wallet = createBackgroundWalletShim({
|
|
62
|
+
identity,
|
|
63
|
+
getAddress: async () => {
|
|
64
|
+
const { ArkAddress } = await import("@arkade-os/sdk");
|
|
65
|
+
const { hex } = await import("@scure/base");
|
|
66
|
+
const info = await arkProvider.getInfo();
|
|
67
|
+
const pubkey = await identity.xOnlyPublicKey();
|
|
68
|
+
const serverPubKey = hex.decode(info.signerPubkey);
|
|
69
|
+
const xOnlyServerPubKey = serverPubKey.length === 33 ? serverPubKey.slice(1) : serverPubKey;
|
|
70
|
+
const hrp = info.network === "bitcoin" ? "ark" : "tark";
|
|
71
|
+
return new ArkAddress(
|
|
72
|
+
xOnlyServerPubKey,
|
|
73
|
+
pubkey,
|
|
74
|
+
hrp
|
|
75
|
+
).encode();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const deps = {
|
|
79
|
+
swapRepository,
|
|
80
|
+
swapProvider,
|
|
81
|
+
arkProvider,
|
|
82
|
+
indexerProvider,
|
|
83
|
+
identity,
|
|
84
|
+
wallet
|
|
85
|
+
};
|
|
86
|
+
await runTasks(taskQueue, [swapsPollProcessor], deps);
|
|
87
|
+
const results = await taskQueue.getResults();
|
|
88
|
+
if (results.length > 0) {
|
|
89
|
+
await taskQueue.acknowledgeResults(
|
|
90
|
+
results.map((r) => r.id)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const existing = await taskQueue.getTasks(SWAP_POLL_TASK_TYPE);
|
|
94
|
+
if (existing.length === 0) {
|
|
95
|
+
const task = {
|
|
96
|
+
id: getRandomId(),
|
|
97
|
+
type: SWAP_POLL_TASK_TYPE,
|
|
98
|
+
data: {},
|
|
99
|
+
createdAt: Date.now()
|
|
100
|
+
};
|
|
101
|
+
await taskQueue.addTask(task);
|
|
102
|
+
}
|
|
103
|
+
return BackgroundTask.BackgroundTaskResult.Success;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(
|
|
106
|
+
"[boltz-swap] Background task failed:",
|
|
107
|
+
error instanceof Error ? error.message : error
|
|
108
|
+
);
|
|
109
|
+
return BackgroundTask.BackgroundTaskResult.Failed;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function registerExpoSwapBackgroundTask(taskName, options) {
|
|
114
|
+
await BackgroundTask.registerTaskAsync(taskName, {
|
|
115
|
+
minimumInterval: options?.minimumInterval ?? 15
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async function unregisterExpoSwapBackgroundTask(taskName) {
|
|
119
|
+
await BackgroundTask.unregisterTaskAsync(taskName);
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
SWAP_POLL_TASK_TYPE,
|
|
123
|
+
defineExpoSwapBackgroundTask,
|
|
124
|
+
registerExpoSwapBackgroundTask,
|
|
125
|
+
swapsPollProcessor,
|
|
126
|
+
unregisterExpoSwapBackgroundTask
|
|
127
|
+
};
|