Skip to content

Commit

Permalink
MIN-1549 MIN-1548: LBE V2 and Expired Order Monitor (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1n999999 authored Nov 28, 2024
1 parent 0df20dd commit 3955648
Show file tree
Hide file tree
Showing 40 changed files with 7,115 additions and 1,088 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 20.17
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20
v20.17
91 changes: 68 additions & 23 deletions docs/transaction.md → docs/dex-transaction.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Minswap AMM V2 & Stableswap Classes Documentation
# Minswap DEX Classes documentation

## Overview

Expand All @@ -9,6 +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`.
- **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 @@ -54,7 +56,10 @@ const blockfrostAdapter = new BlockfrostAdapter(
const utxos = await lucid.utxosAt(address);

const lpAsset = Asset.fromString("<STABLE_POOL_LP_ASSET>");
const config = StableswapConstant.getConfigByLpAsset(lpAsset, NetworkId.TESTNET);
const config = StableswapConstant.getConfigByLpAsset(
lpAsset,
NetworkId.TESTNET
);

const pool = await blockfrostAdapter.getStablePoolByLpAsset(lpAsset);

Expand Down Expand Up @@ -92,7 +97,9 @@ const txComplete = await new Stableswap(lucid).createBulkOrdersTx({
],
});

const signedTx = await txComplete.signWithPrivateKey("<YOUR_PRIVATE_KEY>").complete();
const signedTx = await txComplete
.signWithPrivateKey("<YOUR_PRIVATE_KEY>")
.complete();
const txId = await signedTx.submit();
console.info(`Transaction submitted successfully: ${txId}`);
```
Expand Down Expand Up @@ -144,27 +151,30 @@ const acceptedAmountOut = Slippage.apply({
type: "down",
});

const txComplete = await new DexV2(lucid, blockfrostAdapter).createBulkOrdersTx({
sender: address,
availableUtxos: utxos,
orderOptions: [
{
type: OrderV2.StepType.SWAP_EXACT_IN,
amountIn: swapAmount,
assetIn: assetA,
direction: OrderV2.Direction.A_TO_B,
minimumAmountOut: acceptedAmountOut,
lpAsset: pool.lpAsset,
isLimitOrder: false,
killOnFailed: false,
},
],
});
const txComplete = await new DexV2(lucid, blockfrostAdapter).createBulkOrdersTx(
{
sender: address,
availableUtxos: utxos,
orderOptions: [
{
type: OrderV2.StepType.SWAP_EXACT_IN,
amountIn: swapAmount,
assetIn: assetA,
direction: OrderV2.Direction.A_TO_B,
minimumAmountOut: acceptedAmountOut,
lpAsset: pool.lpAsset,
isLimitOrder: false,
killOnFailed: false,
},
],
}
);

const signedTx = await txComplete.signWithPrivateKey("<YOUR_PRIVATE_KEY>").complete();
const signedTx = await txComplete
.signWithPrivateKey("<YOUR_PRIVATE_KEY>")
.complete();
const txId = await signedTx.submit();
console.info(`Transaction submitted successfully: ${txId}`);

```

### 3. Create the DEX V2 Liquiditiy Pool
Expand Down Expand Up @@ -204,19 +214,54 @@ const txComplete = await new DexV2(lucid, blockfrostAdapter).createPoolTx({
tradingFeeNumerator: 100n,
});

const signedTx = await txComplete.signWithPrivateKey("<YOUR_PRIVATE_KEY>").complete();
const signedTx = await txComplete
.signWithPrivateKey("<YOUR_PRIVATE_KEY>")
.complete();
const txId = await signedTx.submit();
console.info(`Transaction submitted successfully: ${txId}`);
```

### 4. Off-chain component to track and cancel the expired orders

```ts
const network: Network = "Preprod";
const blockfrostProjectId = "<YOUR_BLOCKFROST_API_KEY>";
const blockfrostUrl = "https://cardano-preprod.blockfrost.io/api/v0";

const address = "<YOUR_ADDRESS>";
const lucid = await getBackendLucidInstance(
network,
blockfrostProjectId,
blockfrostUrl,
address
);

const blockfrostAdapter = new BlockfrostAdapter(
NetworkId.TESTNET,
new BlockFrostAPI({
projectId: blockfrostProjectId,
network: "preprod",
})
);

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

await monitor.start();
```

## Additional Examples

You can explore more examples in the [Examples](../examples/example.ts) folder to learn how to integrate the Stableswap and DexV2 classes in more complex scenarios.

## Conclusion

The Stableswap and AMM V2 classes offer powerful tools for interacting with Minswap’s decentralized exchange. They allow users to easily manage liquidity pools and make swaps, with built-in support for Minswap Batcher Fee discounts. By utilizing these classes, users can create efficient transactions and leverage the utility of $MIN to reduce costs.

For more details, you can refer to the specific class files:

- [Stableswap class](../src/stableswap.ts)
- [AMM V2 class](../src/dex-v2.ts)
- [AMM V2 class](../src/dex-v2.ts)
Binary file added docs/lbe-v2/LBE Specification.pdf
Binary file not shown.
Loading

0 comments on commit 3955648

Please sign in to comment.