Skip to content

Commit

Permalink
rename function+title+file and handle refund datum hash without raw d…
Browse files Browse the repository at this point in the history
…atum
  • Loading branch information
m1n999999 committed Nov 27, 2024
1 parent 408860e commit a78e34f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions docs/dex-transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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";
Expand All @@ -244,13 +244,13 @@ const blockfrostAdapter = new BlockfrostAdapter(
})
);

const worker = new DexV2Worker({
const monitor = new ExpiredOrderMonitor({
lucid,
blockfrostAdapter,
privateKey: "<YOUR_PRIVATE_KEY>",
});

await worker.start();
await monitor.start();
```

## Additional Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -27,13 +27,13 @@ async function main(): Promise<void> {
})
);

const worker = new DexV2Worker({
const monitor = new ExpiredOrderMonitor({
lucid,
blockfrostAdapter,
privateKey: "<YOUR_PRIVATE_KEY>",
});

await worker.start();
await monitor.start();
}

void main();
8 changes: 3 additions & 5 deletions src/dex-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/dex-v2-worker.ts → src/expired-order-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a78e34f

Please sign in to comment.