diff --git a/docs/dex-transaction.md b/docs/dex-transaction.md index a9dc2fe..249b90e 100644 --- a/docs/dex-transaction.md +++ b/docs/dex-transaction.md @@ -9,8 +9,8 @@ This documentation provides details on how to interact with the **Stableswap** a - **Stableswap class**: Located in `src/stableswap.ts`. - **AMM V2 class**: Located in `src/dex-v2.ts`. - **Example file**: Demonstrates usage of both classes, located in `examples/example.ts`. -- **DexV2Worker Class**: Located in `src/dex-v2-worker.ts`. -- **DexV2Worker Example**: Located in `examples/dex-v2-worker-example.ts`. +- **ExpiredOrderMonitor Class**: Located in `src/expired-order-monitor.ts`. +- **ExpiredOrderMonitor Example**: Located in `examples/expired-order-monitor-example.ts`. ### Utility Functions @@ -221,7 +221,7 @@ const txId = await signedTx.submit(); console.info(`Transaction submitted successfully: ${txId}`); ``` -### 4. Run Dex V2 Worker +### 4. Off-chain component to track and cancel the expired orders ```ts const network: Network = "Preprod"; @@ -244,13 +244,13 @@ const blockfrostAdapter = new BlockfrostAdapter( }) ); -const worker = new DexV2Worker({ +const monitor = new ExpiredOrderMonitor({ lucid, blockfrostAdapter, privateKey: "", }); -await worker.start(); +await monitor.start(); ``` ## Additional Examples diff --git a/examples/dex-v2-worker-example.ts b/examples/expired-order-monitor-example.ts similarity index 87% rename from examples/dex-v2-worker-example.ts rename to examples/expired-order-monitor-example.ts index f9ba0f6..3b85155 100644 --- a/examples/dex-v2-worker-example.ts +++ b/examples/expired-order-monitor-example.ts @@ -2,7 +2,7 @@ import { BlockFrostAPI } from "@blockfrost/blockfrost-js"; import { Network } from "@minswap/lucid-cardano"; import { BlockfrostAdapter, NetworkId } from "../src"; -import { DexV2Worker } from "../src/dex-v2-worker"; +import { ExpiredOrderMonitor } from "../src/expired-order-monitor"; import { getBackendLucidInstance } from "../src/utils/lucid"; async function main(): Promise { @@ -27,13 +27,13 @@ async function main(): Promise { }) ); - const worker = new DexV2Worker({ + const monitor = new ExpiredOrderMonitor({ lucid, blockfrostAdapter, privateKey: "", }); - await worker.start(); + await monitor.start(); } void main(); diff --git a/src/dex-v2.ts b/src/dex-v2.ts index 24c3735..a94f05c 100644 --- a/src/dex-v2.ts +++ b/src/dex-v2.ts @@ -1069,13 +1069,11 @@ export class DexV2 { break; } case OrderV2.ExtraDatumType.DATUM_HASH: { - invariant( - refundDatum.hash in extraDatumMap, - `Can not find refund datum of order ${orderUtxo.txHash}#${orderUtxo.outputIndex}` - ); lucidTx.payToAddressWithData( datum.refundReceiver, - { asHash: extraDatumMap[refundDatum.hash] }, + refundDatum.hash in extraDatumMap + ? { asHash: extraDatumMap[refundDatum.hash] } + : { hash: refundDatum.hash }, outAssets ); break; diff --git a/src/dex-v2-worker.ts b/src/expired-order-monitor.ts similarity index 93% rename from src/dex-v2-worker.ts rename to src/expired-order-monitor.ts index 610922f..98ec277 100644 --- a/src/dex-v2-worker.ts +++ b/src/expired-order-monitor.ts @@ -9,7 +9,7 @@ type DexV2WorkerConstructor = { privateKey: string; }; -export class DexV2Worker { +export class ExpiredOrderMonitor { private readonly lucid: Lucid; private readonly blockfrostAdapter: BlockfrostAdapter; private readonly privateKey: string; @@ -66,7 +66,10 @@ export class DexV2Worker { mapDatum[receiverDatum.hash] = rawDatum; // eslint-disable-next-line unused-imports/no-unused-vars } catch (_err) { - continue; + if (receiverDatum.type === OrderV2.ExtraDatumType.INLINE_DATUM) { + // if receiver Datum type is INLINE_DATUM, skip this order. + continue; + } } } orders.push(order);