@arkade-os/sdk 0.4.30 → 0.4.32

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.
Files changed (53) hide show
  1. package/dist/adapters/expo.d.cts +2 -2
  2. package/dist/adapters/expo.d.ts +2 -2
  3. package/dist/adapters/indexedDB.cjs +2 -2
  4. package/dist/adapters/indexedDB.js +1 -1
  5. package/dist/{ark-C0TMXvwO.d.cts → ark-ibLW4Hte.d.cts} +1 -1
  6. package/dist/{ark-C0TMXvwO.d.ts → ark-ibLW4Hte.d.ts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-Iip3xMF_.d.ts → asyncStorageTaskQueue-BEOFPNc0.d.ts} +1 -1
  8. package/dist/{asyncStorageTaskQueue-DHOoNvRy.d.cts → asyncStorageTaskQueue-VGHXWR9F.d.cts} +1 -1
  9. package/dist/{chunk-PCEE6DRL.cjs → chunk-I2UIKZM5.cjs} +7 -7
  10. package/dist/{chunk-PCEE6DRL.cjs.map → chunk-I2UIKZM5.cjs.map} +1 -1
  11. package/dist/{chunk-XWJFOP5G.cjs → chunk-KQK4PP6L.cjs} +77 -22
  12. package/dist/chunk-KQK4PP6L.cjs.map +1 -0
  13. package/dist/{chunk-GRJKJNBO.js → chunk-SHEBNWOQ.js} +3 -3
  14. package/dist/{chunk-GRJKJNBO.js.map → chunk-SHEBNWOQ.js.map} +1 -1
  15. package/dist/{chunk-6NY27WL6.js → chunk-XROGFOPX.js} +77 -22
  16. package/dist/chunk-XROGFOPX.js.map +1 -0
  17. package/dist/contracts/handlers/index.d.cts +3 -3
  18. package/dist/contracts/handlers/index.d.ts +3 -3
  19. package/dist/{delegate-Ds4Hi7Xy.d.ts → delegate-BXaR1RNG.d.ts} +1 -1
  20. package/dist/{delegate-CEk9RHVj.d.cts → delegate-BvNTw44a.d.cts} +1 -1
  21. package/dist/{index-DA9r_7Vg.d.ts → index-BusKawmy.d.ts} +2 -2
  22. package/dist/{index-WIAY0DDn.d.cts → index-C-5Tw7VA.d.cts} +2 -2
  23. package/dist/index.cjs +86 -86
  24. package/dist/index.d.cts +6 -6
  25. package/dist/index.d.ts +6 -6
  26. package/dist/index.js +1 -1
  27. package/dist/repositories/realm/index.cjs +10 -10
  28. package/dist/repositories/realm/index.d.cts +1 -1
  29. package/dist/repositories/realm/index.d.ts +1 -1
  30. package/dist/repositories/realm/index.js +1 -1
  31. package/dist/repositories/sqlite/index.cjs +10 -10
  32. package/dist/repositories/sqlite/index.d.cts +1 -1
  33. package/dist/repositories/sqlite/index.d.ts +1 -1
  34. package/dist/repositories/sqlite/index.js +1 -1
  35. package/dist/{taskRunner-JNjIWWJi.d.ts → taskRunner-B1igKGAo.d.ts} +1 -1
  36. package/dist/{taskRunner-CdEVYgoP.d.cts → taskRunner-By92TQ1m.d.cts} +1 -1
  37. package/dist/wallet/expo/background.cjs +8 -8
  38. package/dist/wallet/expo/background.d.cts +3 -3
  39. package/dist/wallet/expo/background.d.ts +3 -3
  40. package/dist/wallet/expo/background.js +2 -2
  41. package/dist/wallet/expo/index.cjs +9 -9
  42. package/dist/wallet/expo/index.d.cts +4 -4
  43. package/dist/wallet/expo/index.d.ts +4 -4
  44. package/dist/wallet/expo/index.js +2 -2
  45. package/dist/{wallet-CMgzKP0o.d.cts → wallet-B_rxgQTu.d.cts} +2 -2
  46. package/dist/{wallet-BGL6SzKQ.d.ts → wallet-CyM4F7Bs.d.ts} +2 -2
  47. package/dist/worker/expo/index.cjs +6 -6
  48. package/dist/worker/expo/index.d.cts +4 -4
  49. package/dist/worker/expo/index.d.ts +4 -4
  50. package/dist/worker/expo/index.js +2 -2
  51. package/package.json +1 -1
  52. package/dist/chunk-6NY27WL6.js.map +0 -1
  53. package/dist/chunk-XWJFOP5G.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { getRandomId, extendVirtualCoinForContract, warnAndFilterVtxosForScript, saveVtxosForContract } from './chunk-6NY27WL6.js';
1
+ import { getRandomId, extendVirtualCoinForContract, warnAndFilterVtxosForScript, saveVtxosForContract } from './chunk-XROGFOPX.js';
2
2
 
3
3
  // src/worker/expo/taskRunner.ts
4
4
  async function runTasks(queue, processors, deps) {
@@ -91,5 +91,5 @@ var contractPollProcessor = {
91
91
  };
92
92
 
93
93
  export { CONTRACT_POLL_TASK_TYPE, contractPollProcessor, createTaskDependencies, runTasks };
94
- //# sourceMappingURL=chunk-GRJKJNBO.js.map
95
- //# sourceMappingURL=chunk-GRJKJNBO.js.map
94
+ //# sourceMappingURL=chunk-SHEBNWOQ.js.map
95
+ //# sourceMappingURL=chunk-SHEBNWOQ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":[],"mappings":";;;AAkDA,eAAsB,QAAA,CAClB,KAAA,EACA,UAAA,EACA,IAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,EAAS;AACnC,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,QAAA,EAAU,CAAC,CAAC,CAAC,CAAA;AACnE,EAAA,MAAM,UAAwB,EAAC;AAE/B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,IAAA,MAAM,SAAA,GAAY,YAAA,CAAa,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA;AAE5C,IAAA,IAAI,OAAA;AAEJ,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,OAAA,GAAU;AAAA,QACN,YAAY,IAAA,CAAK,EAAA;AAAA,QACjB,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,MAAA,EAAQ;AAAA,OACZ;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,IAAI;AACA,QAAA,OAAA,GAAU,MAAM,SAAA,CAAU,OAAA,CAAQ,IAAA,EAAM,IAAI,CAAA;AAAA,MAChD,SAAS,KAAA,EAAO;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A,IAAI,SAAA,GAAY,CAAA;AAChB,MAAA,IAAI,OAAA,GAAU,IAAA;AACd,MAAA,MAAM,WAAkC,EAAC;AAEzC,MAAA,OAAO,OAAA,EAAS;AACZ,QAAA,MAAM,EAAE,KAAA,EAAO,IAAA,EAAK,GAAI,MAAM,gBAAgB,QAAA,CAAS;AAAA,UACnD,OAAA,EAAS,CAAC,QAAA,CAAS,MAAM,CAAA;AAAA,UACzB,SAAA;AAAA,UACA;AAAA,SACH,CAAA;AAED,QAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,UAAA,QAAA,CAAS,IAAA,CAAK,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAC,CAAA;AAAA,QAC5C;AAEA,QAAA,OAAA,GAAU,IAAA,GAAO,KAAA,CAAM,MAAA,KAAW,QAAA,GAAW,KAAA;AAC7C,QAAA,SAAA,EAAA;AAAA,MACJ;AAKA,MAAA,MAAM,QAAA,GAAW,2BAAA;AAAA,QACb,QAAA;AAAA,QACA,QAAA,CAAS,MAAA;AAAA,QACT;AAAA,OACJ;AACA,MAAA,MAAM,oBAAA,CAAqB,gBAAA,EAAkB,QAAA,EAAU,QAAQ,CAAA;AAC/D,MAAA,UAAA,IAAc,QAAA,CAAS,MAAA;AACvB,MAAA,kBAAA,EAAA;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,YAAY,IAAA,CAAK,EAAA;AAAA,MACjB,IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-GRJKJNBO.js","sourcesContent":["import type { TaskItem, TaskResult, TaskQueue } from \"./taskQueue\";\nimport type { WalletRepository } from \"../../repositories/walletRepository\";\nimport type { ContractRepository } from \"../../repositories/contractRepository\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport type { ArkProvider } from \"../../providers/ark\";\nimport type { ExtendedVirtualCoin, VirtualCoin } from \"../../wallet\";\nimport type { Contract } from \"../../contracts/types\";\nimport { getRandomId, extendVirtualCoinForContract } from \"../../wallet/utils\";\n\n/**\n * Shared dependencies injected into every processor at runtime.\n *\n * `extendVtxo` requires the owning contract — processors must resolve each\n * vtxo's `script` to a known contract (via the contract repository) before\n * calling this. The strict signature prevents the footgun where a missing\n * contract silently falls back to the wallet's default tapscript.\n */\nexport interface TaskDependencies {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) => ExtendedVirtualCoin;\n}\n\n/**\n * A stateless unit that handles one type of task item.\n *\n * Processors must not keep in-memory state across invocations —\n * all coordination lives in the @see TaskQueue and repositories.\n *\n * The `TDeps` parameter defaults to @see TaskDependencies but\n * can be overridden for domain-specific processors (e.g. swap processing).\n */\nexport interface TaskProcessor<TDeps = TaskDependencies> {\n readonly taskType: string;\n execute(item: TaskItem, deps: TDeps): Promise<Omit<TaskResult, \"id\" | \"executedAt\">>;\n}\n\n/**\n * Run all pending tasks from the queue through matching processors.\n *\n * For each task in the inbox:\n * 1. Find the processor whose `taskType` matches `task.type`.\n * 2. Execute it, producing a @see TaskResult.\n * 3. Push the result to the outbox and remove the task from the inbox.\n *\n * Tasks with no matching processor produce a `\"noop\"` result.\n * Processor errors produce a `\"failed\"` result with the error message.\n */\nexport async function runTasks<TDeps = TaskDependencies>(\n queue: TaskQueue,\n processors: TaskProcessor<TDeps>[],\n deps: TDeps,\n): Promise<TaskResult[]> {\n const tasks = await queue.getTasks();\n const processorMap = new Map(processors.map((p) => [p.taskType, p]));\n const results: TaskResult[] = [];\n\n for (const task of tasks) {\n const processor = processorMap.get(task.type);\n\n let partial: Omit<TaskResult, \"id\" | \"executedAt\">;\n\n if (!processor) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"noop\",\n };\n } else {\n try {\n partial = await processor.execute(task, deps);\n } catch (error) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"failed\",\n data: {\n error: error instanceof Error ? error.message : String(error),\n },\n };\n }\n }\n\n const result: TaskResult = {\n ...partial,\n id: getRandomId(),\n executedAt: Date.now(),\n };\n\n await queue.pushResult(result);\n await queue.removeTask(task.id);\n results.push(result);\n }\n\n return results;\n}\n\n/**\n * Options for @see createTaskDependencies.\n */\nexport interface CreateTaskDependenciesOptions {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n}\n\n/**\n * Build the @see TaskDependencies needed by task processors\n * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)\n *\n * This is the same construction that `defineExpoBackgroundTask` does\n * internally, extracted so that consumers with custom schedulers\n * (e.g. bare React Native with `react-native-background-fetch`)\n * can build deps without depending on Expo.\n */\nexport function createTaskDependencies(options: CreateTaskDependenciesOptions): TaskDependencies {\n return {\n ...options,\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) =>\n extendVirtualCoinForContract(vtxo, contract),\n };\n}\n","import type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport {\n warnAndFilterVtxosForScript,\n saveVtxosForContract,\n} from \"../../../contracts/vtxoOwnership\";\n\nexport const CONTRACT_POLL_TASK_TYPE = \"contract-poll\";\n\n/**\n * Polls the indexer for the latest VTXO state of every contract and\n * persists the results to the wallet repository.\n *\n * Replicates the polling subset of @see ContractManager.initialize:\n * 1. Load all contracts from the contract repository.\n * 2. Paginated fetch of every VTXO (including spent) from the indexer.\n * 3. Extend each VTXO with tapscript data.\n * 4. Save to the wallet repository.\n *\n * NOTE: the indexer query deliberately omits `spendableOnly`. Every\n * repository implements `saveVtxos` as an upsert with no batch delete,\n * so filtering to spendable-only would leave VTXOs that became spent\n * between polls marked as spendable forever. Fetching the full set lets\n * the upsert overwrite stale records with their latest state.\n */\nexport const contractPollProcessor: TaskProcessor = {\n taskType: CONTRACT_POLL_TASK_TYPE,\n\n async execute(\n item: TaskItem,\n deps: TaskDependencies,\n ): Promise<Omit<TaskResult, \"id\" | \"executedAt\">> {\n const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;\n\n const contracts = await contractRepository.getContracts();\n let contractsProcessed = 0;\n let vtxosSaved = 0;\n\n for (const contract of contracts) {\n // Paginated fetch of spendable virtual outputs\n const pageSize = 100;\n let pageIndex = 0;\n let hasMore = true;\n const allVtxos: ExtendedVirtualCoin[] = [];\n\n while (hasMore) {\n const { vtxos, page } = await indexerProvider.getVtxos({\n scripts: [contract.script],\n pageIndex,\n pageSize,\n });\n\n for (const vtxo of vtxos) {\n allVtxos.push(extendVtxo(vtxo, contract));\n }\n\n hasMore = page ? vtxos.length === pageSize : false;\n pageIndex++;\n }\n\n // Skip wrong-script rows (legacy duplicates or indexer drift)\n // before persisting; the loop must keep going for the remaining\n // contracts even when one row is rejected.\n const filtered = warnAndFilterVtxosForScript(\n allVtxos,\n contract.script,\n \"contractPollProcessor\",\n );\n await saveVtxosForContract(walletRepository, contract, filtered);\n vtxosSaved += filtered.length;\n contractsProcessed++;\n }\n\n return {\n taskItemId: item.id,\n type: CONTRACT_POLL_TASK_TYPE,\n status: \"success\",\n data: { contractsProcessed, vtxosSaved },\n };\n },\n};\n"]}
1
+ {"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":[],"mappings":";;;AAkDA,eAAsB,QAAA,CAClB,KAAA,EACA,UAAA,EACA,IAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,EAAS;AACnC,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,QAAA,EAAU,CAAC,CAAC,CAAC,CAAA;AACnE,EAAA,MAAM,UAAwB,EAAC;AAE/B,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;AACvB,MAAA,kBAAA,EAAA;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,YAAY,IAAA,CAAK,EAAA;AAAA,MACjB,IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-SHEBNWOQ.js","sourcesContent":["import type { TaskItem, TaskResult, TaskQueue } from \"./taskQueue\";\nimport type { WalletRepository } from \"../../repositories/walletRepository\";\nimport type { ContractRepository } from \"../../repositories/contractRepository\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport type { ArkProvider } from \"../../providers/ark\";\nimport type { ExtendedVirtualCoin, VirtualCoin } from \"../../wallet\";\nimport type { Contract } from \"../../contracts/types\";\nimport { getRandomId, extendVirtualCoinForContract } from \"../../wallet/utils\";\n\n/**\n * Shared dependencies injected into every processor at runtime.\n *\n * `extendVtxo` requires the owning contract — processors must resolve each\n * vtxo's `script` to a known contract (via the contract repository) before\n * calling this. The strict signature prevents the footgun where a missing\n * contract silently falls back to the wallet's default tapscript.\n */\nexport interface TaskDependencies {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) => ExtendedVirtualCoin;\n}\n\n/**\n * A stateless unit that handles one type of task item.\n *\n * Processors must not keep in-memory state across invocations —\n * all coordination lives in the @see TaskQueue and repositories.\n *\n * The `TDeps` parameter defaults to @see TaskDependencies but\n * can be overridden for domain-specific processors (e.g. swap processing).\n */\nexport interface TaskProcessor<TDeps = TaskDependencies> {\n readonly taskType: string;\n execute(item: TaskItem, deps: TDeps): Promise<Omit<TaskResult, \"id\" | \"executedAt\">>;\n}\n\n/**\n * Run all pending tasks from the queue through matching processors.\n *\n * For each task in the inbox:\n * 1. Find the processor whose `taskType` matches `task.type`.\n * 2. Execute it, producing a @see TaskResult.\n * 3. Push the result to the outbox and remove the task from the inbox.\n *\n * Tasks with no matching processor produce a `\"noop\"` result.\n * Processor errors produce a `\"failed\"` result with the error message.\n */\nexport async function runTasks<TDeps = TaskDependencies>(\n queue: TaskQueue,\n processors: TaskProcessor<TDeps>[],\n deps: TDeps,\n): Promise<TaskResult[]> {\n const tasks = await queue.getTasks();\n const processorMap = new Map(processors.map((p) => [p.taskType, p]));\n const results: TaskResult[] = [];\n\n for (const task of tasks) {\n const processor = processorMap.get(task.type);\n\n let partial: Omit<TaskResult, \"id\" | \"executedAt\">;\n\n if (!processor) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"noop\",\n };\n } else {\n try {\n partial = await processor.execute(task, deps);\n } catch (error) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"failed\",\n data: {\n error: error instanceof Error ? error.message : String(error),\n },\n };\n }\n }\n\n const result: TaskResult = {\n ...partial,\n id: getRandomId(),\n executedAt: Date.now(),\n };\n\n await queue.pushResult(result);\n await queue.removeTask(task.id);\n results.push(result);\n }\n\n return results;\n}\n\n/**\n * Options for @see createTaskDependencies.\n */\nexport interface CreateTaskDependenciesOptions {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n}\n\n/**\n * Build the @see TaskDependencies needed by task processors\n * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)\n *\n * This is the same construction that `defineExpoBackgroundTask` does\n * internally, extracted so that consumers with custom schedulers\n * (e.g. bare React Native with `react-native-background-fetch`)\n * can build deps without depending on Expo.\n */\nexport function createTaskDependencies(options: CreateTaskDependenciesOptions): TaskDependencies {\n return {\n ...options,\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) =>\n extendVirtualCoinForContract(vtxo, contract),\n };\n}\n","import type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport {\n warnAndFilterVtxosForScript,\n saveVtxosForContract,\n} from \"../../../contracts/vtxoOwnership\";\n\nexport const CONTRACT_POLL_TASK_TYPE = \"contract-poll\";\n\n/**\n * Polls the indexer for the latest VTXO state of every contract and\n * persists the results to the wallet repository.\n *\n * Replicates the polling subset of @see ContractManager.initialize:\n * 1. Load all contracts from the contract repository.\n * 2. Paginated fetch of every VTXO (including spent) from the indexer.\n * 3. Extend each VTXO with tapscript data.\n * 4. Save to the wallet repository.\n *\n * NOTE: the indexer query deliberately omits `spendableOnly`. Every\n * repository implements `saveVtxos` as an upsert with no batch delete,\n * so filtering to spendable-only would leave VTXOs that became spent\n * between polls marked as spendable forever. Fetching the full set lets\n * the upsert overwrite stale records with their latest state.\n */\nexport const contractPollProcessor: TaskProcessor = {\n taskType: CONTRACT_POLL_TASK_TYPE,\n\n async execute(\n item: TaskItem,\n deps: TaskDependencies,\n ): Promise<Omit<TaskResult, \"id\" | \"executedAt\">> {\n const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;\n\n const contracts = await contractRepository.getContracts();\n let contractsProcessed = 0;\n let vtxosSaved = 0;\n\n for (const contract of contracts) {\n // Paginated fetch of spendable virtual outputs\n const pageSize = 100;\n let pageIndex = 0;\n let hasMore = true;\n const allVtxos: ExtendedVirtualCoin[] = [];\n\n while (hasMore) {\n const { vtxos, page } = await indexerProvider.getVtxos({\n scripts: [contract.script],\n pageIndex,\n pageSize,\n });\n\n for (const vtxo of vtxos) {\n allVtxos.push(extendVtxo(vtxo, contract));\n }\n\n hasMore = page ? vtxos.length === pageSize : false;\n pageIndex++;\n }\n\n // Skip wrong-script rows (legacy duplicates or indexer drift)\n // before persisting; the loop must keep going for the remaining\n // contracts even when one row is rejected.\n const filtered = warnAndFilterVtxosForScript(\n allVtxos,\n contract.script,\n \"contractPollProcessor\",\n );\n await saveVtxosForContract(walletRepository, contract, filtered);\n vtxosSaved += filtered.length;\n contractsProcessed++;\n }\n\n return {\n taskItemId: item.id,\n type: CONTRACT_POLL_TASK_TYPE,\n status: \"success\",\n data: { contractsProcessed, vtxosSaved },\n };\n },\n};\n"]}
@@ -2256,27 +2256,57 @@ function extendCoin(wallet, utxo) {
2256
2256
  tapTree: wallet.boardingTapscript.encode()
2257
2257
  };
2258
2258
  }
2259
- function extendVtxoFromContract(vtxo, contract) {
2259
+ function deriveContractTapscripts(contract) {
2260
2260
  const handler = contractHandlers.get(contract.type);
2261
2261
  if (!handler) {
2262
2262
  throw new Error(`No handler for contract type '${contract.type}'`);
2263
2263
  }
2264
2264
  const script = handler.createScript(contract.params);
2265
2265
  return {
2266
- ...vtxo,
2267
2266
  forfeitTapLeafScript: script.forfeit(),
2268
2267
  intentTapLeafScript: script.forfeit(),
2269
2268
  tapTree: script.encode()
2270
2269
  };
2271
2270
  }
2272
- function extendVirtualCoinForContract(vtxo, contractOrMap) {
2271
+ function cloneTapLeafScript([
2272
+ controlBlock,
2273
+ script
2274
+ ]) {
2275
+ return [
2276
+ {
2277
+ version: controlBlock.version,
2278
+ internalKey: new Uint8Array(controlBlock.internalKey),
2279
+ merklePath: controlBlock.merklePath.map((hash) => new Uint8Array(hash))
2280
+ },
2281
+ new Uint8Array(script)
2282
+ ];
2283
+ }
2284
+ function cloneContractTapscripts(tapscripts) {
2285
+ return {
2286
+ forfeitTapLeafScript: cloneTapLeafScript(tapscripts.forfeitTapLeafScript),
2287
+ intentTapLeafScript: cloneTapLeafScript(tapscripts.intentTapLeafScript),
2288
+ tapTree: new Uint8Array(tapscripts.tapTree)
2289
+ };
2290
+ }
2291
+ function extendVtxoFromContract(vtxo, contract, cache) {
2292
+ if (!cache) {
2293
+ return { ...vtxo, ...deriveContractTapscripts(contract) };
2294
+ }
2295
+ let tapscripts = cache.get(contract.script);
2296
+ if (!tapscripts) {
2297
+ tapscripts = deriveContractTapscripts(contract);
2298
+ cache.set(contract.script, tapscripts);
2299
+ }
2300
+ return { ...vtxo, ...cloneContractTapscripts(tapscripts) };
2301
+ }
2302
+ function extendVirtualCoinForContract(vtxo, contractOrMap, cache) {
2273
2303
  const contract = resolveContract(vtxo, contractOrMap);
2274
2304
  if (!contract) {
2275
2305
  throw new Error(
2276
2306
  "extendVirtualCoinForContract: no contract matched vtxo.script \u2014 callers must resolve the owning contract before annotating"
2277
2307
  );
2278
2308
  }
2279
- return extendVtxoFromContract(vtxo, contract);
2309
+ return extendVtxoFromContract(vtxo, contract, cache);
2280
2310
  }
2281
2311
  function isContractMap(value) {
2282
2312
  return typeof value.get === "function";
@@ -3627,6 +3657,15 @@ var txKey = {
3627
3657
  boardingTxid: "",
3628
3658
  arkTxid: ""
3629
3659
  };
3660
+ function consumeBoardingReceive(boardingTxs, predicate) {
3661
+ const index = boardingTxs.findIndex(predicate);
3662
+ if (index === -1) return false;
3663
+ boardingTxs.splice(index, 1);
3664
+ return true;
3665
+ }
3666
+ function isSettledBoardingReceive(tx) {
3667
+ return tx.type === "RECEIVED" /* TxReceived */ && tx.settled && tx.key.boardingTxid !== "";
3668
+ }
3630
3669
  function collectAssets(vtxos) {
3631
3670
  const map = /* @__PURE__ */ new Map();
3632
3671
  for (const vtxo of vtxos) {
@@ -3666,24 +3705,39 @@ function subtractAssets(spent, change) {
3666
3705
  }
3667
3706
  async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, getTxCreatedAt) {
3668
3707
  const fromOldestVtxo = [...vtxos].sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
3708
+ const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
3669
3709
  const sent = [];
3670
3710
  let received = [];
3671
3711
  for (const vtxo of fromOldestVtxo) {
3672
3712
  if (vtxo.status.isLeaf) {
3673
- if (!commitmentsToIgnore.has(vtxo.virtualStatus.commitmentTxIds[0]) && fromOldestVtxo.filter((v) => v.settledBy === vtxo.virtualStatus.commitmentTxIds[0]).length === 0) {
3674
- const assets = collectAssets([vtxo]);
3675
- received.push({
3676
- key: {
3677
- ...txKey,
3678
- commitmentTxid: vtxo.virtualStatus.commitmentTxIds[0]
3679
- },
3680
- tag: "batch",
3681
- type: "RECEIVED" /* TxReceived */,
3682
- amount: vtxo.value,
3683
- settled: vtxo.status.isLeaf || vtxo.isSpent,
3684
- createdAt: vtxo.createdAt.getTime(),
3685
- ...assets && { assets }
3686
- });
3713
+ const commitmentTxid = vtxo.virtualStatus.commitmentTxIds[0];
3714
+ const vtxoCreatedAt = vtxo.createdAt.getTime();
3715
+ const ignoredCommitment = commitmentsToIgnore.has(commitmentTxid) || !!vtxo.settledBy && commitmentsToIgnore.has(vtxo.settledBy);
3716
+ if (ignoredCommitment) {
3717
+ consumeBoardingReceive(
3718
+ unmatchedSettledBoardingTxs,
3719
+ (tx) => tx.createdAt <= vtxoCreatedAt && (tx.key.commitmentTxid === commitmentTxid || tx.key.commitmentTxid === vtxo.settledBy)
3720
+ );
3721
+ } else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.virtualStatus.commitmentTxIds[0]).length === 0) {
3722
+ const duplicateBoardingReceive = consumeBoardingReceive(
3723
+ unmatchedSettledBoardingTxs,
3724
+ (tx) => tx.amount === vtxo.value && tx.createdAt <= vtxoCreatedAt
3725
+ );
3726
+ if (!duplicateBoardingReceive) {
3727
+ const assets = collectAssets([vtxo]);
3728
+ received.push({
3729
+ key: {
3730
+ ...txKey,
3731
+ commitmentTxid
3732
+ },
3733
+ tag: "batch",
3734
+ type: "RECEIVED" /* TxReceived */,
3735
+ amount: vtxo.value,
3736
+ settled: vtxo.status.isLeaf || vtxo.isSpent,
3737
+ createdAt: vtxoCreatedAt,
3738
+ ...assets && { assets }
3739
+ });
3740
+ }
3687
3741
  }
3688
3742
  } else if (fromOldestVtxo.filter((v) => v.arkTxId === vtxo.txid).length === 0) {
3689
3743
  const assets = collectAssets([vtxo]);
@@ -6689,7 +6743,8 @@ var ContractManager = class _ContractManager {
6689
6743
  for (const contract of contracts) {
6690
6744
  byScript.set(contract.script, contract);
6691
6745
  }
6692
- return vtxos.map((vtxo) => extendVirtualCoinForContract(vtxo, byScript));
6746
+ const tapscriptCache = /* @__PURE__ */ new Map();
6747
+ return vtxos.map((vtxo) => extendVirtualCoinForContract(vtxo, byScript, tapscriptCache));
6693
6748
  }
6694
6749
  buildContractsDbFilter(filter) {
6695
6750
  return {
@@ -8089,7 +8144,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
8089
8144
  const tx = {
8090
8145
  key: {
8091
8146
  boardingTxid: utxo.txid,
8092
- commitmentTxid: "",
8147
+ commitmentTxid: utxo.virtualStatus.commitmentTxIds?.[0] ?? "",
8093
8148
  arkTxid: ""
8094
8149
  },
8095
8150
  amount: utxo.value,
@@ -13959,5 +14014,5 @@ function isArkContract(str) {
13959
14014
  }
13960
14015
 
13961
14016
  export { ArkNote, AssetManager, BIP322, Batch, ContractManager, ContractRepositoryImpl, ContractWatcher, DB_VERSION, DEFAULT_MESSAGE_TIMEOUTS, DelegateManagerImpl, DelegateNotConfiguredError, DelegatorManagerImpl, DelegatorNotConfiguredError, DescriptorSigningProviderMissingError, DustChangeError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EsploraProvider, Estimator, HDDescriptorProvider, InMemoryContractRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBWalletRepository, MESSAGE_BUS_NOT_INITIALIZED, MIGRATION_KEY, MessageBus, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, P2A, Ramps, ReadonlyAssetManager, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegateProvider, RestDelegatorProvider, SeedIdentity, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, TxTree, TxType, TxWeightEstimator, Unroll, VtxoManager, Wallet2 as Wallet, WalletMessageHandler, WalletNotInitializedError, WalletRepositoryImpl, WsElectrumChainSource, buildForfeitTx, buildOffchainTx, closeDatabase, combineTapscriptSigs, contractFromArkContract, contractFromArkContractWithAddress, decodeArkContract, deserializeAssets, deserializeUtxo, deserializeVtxo, encodeArkContract, extendVirtualCoinForContract, getMigrationStatus, getRandomId, hasBoardingTxExpired, isArkContract, isBatchSignable, isDiscoverable, isExpired, isRecoverable, isSpendable, isSubdust, isValidArkAddress, isVtxoExpiringSoon, isVtxoForScript, migrateWalletRepository, openDatabase, requiresMigration, rollbackMigration, saveVtxosForContract, scriptFromArkAddress, serializeAssets, serializeUtxo, serializeVtxo, setupServiceWorker, validateConnectorsTxGraph, validateVtxoTxGraph, verifyTapscriptSignatures, waitForIncomingFunds, warnAndFilterVtxosForScript };
13962
- //# sourceMappingURL=chunk-6NY27WL6.js.map
13963
- //# sourceMappingURL=chunk-6NY27WL6.js.map
14017
+ //# sourceMappingURL=chunk-XROGFOPX.js.map
14018
+ //# sourceMappingURL=chunk-XROGFOPX.js.map