Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIN-1549 MIN-1548: LBE V2 and Expired Order Monitor #44

Merged
merged 43 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
415d914
config+schema+constant
m1n999999 Oct 24, 2024
2640f6c
wip
m1n999999 Oct 24, 2024
a3b6c16
use custom schema
m1n999999 Oct 25, 2024
e045810
type
m1n999999 Oct 25, 2024
4c4b468
wip
m1n999999 Oct 28, 2024
ab163cb
finish deposit/withdraw order
m1n999999 Oct 29, 2024
f4d48fe
close event and add more seller
m1n999999 Oct 29, 2024
3260eb8
add type ProjectDetails+remove Dummy type
m1n999999 Oct 29, 2024
7cfdd85
create event example
m1n999999 Oct 30, 2024
8236737
lbe v2 adapter
m1n999999 Oct 30, 2024
59bca26
close lbe v2
m1n999999 Oct 30, 2024
e16020b
fix deposit
m1n999999 Oct 30, 2024
60bdb2c
example for deposit and withdraw
m1n999999 Oct 31, 2024
2ac00de
example for cancel event
m1n999999 Oct 31, 2024
ac55fec
example+wip of counting seller
m1n999999 Oct 31, 2024
bd4da1b
wip
m1n999999 Nov 5, 2024
375f37e
update pnpm-lock
m1n999999 Nov 5, 2024
abc0e5c
counting seller
m1n999999 Nov 6, 2024
6d42c86
collect manager
m1n999999 Nov 6, 2024
6df1fbe
Merge branch 'main' into lbe-v2
m1n999999 Nov 6, 2024
eef0461
collect order
m1n999999 Nov 6, 2024
8dc57b1
redeem orders
m1n999999 Nov 7, 2024
923feae
refund
m1n999999 Nov 7, 2024
460fa4e
validate create amm
m1n999999 Nov 7, 2024
8183a3d
create amm pool
m1n999999 Nov 8, 2024
924c4f6
wip
m1n999999 Nov 11, 2024
9ce8417
wip 1
m1n999999 Nov 12, 2024
2b01f37
finish implement worker
m1n999999 Nov 12, 2024
d67ba87
fix build
m1n999999 Nov 12, 2024
030673d
fix worker
m1n999999 Nov 13, 2024
a39b946
seperate lbe-v2 file
m1n999999 Nov 19, 2024
c211411
fix worker
m1n999999 Nov 21, 2024
b22a0c8
udpate order and example for it
m1n999999 Nov 22, 2024
501287b
remove redudant
m1n999999 Nov 22, 2024
4259587
update mainnet config
m1n999999 Nov 22, 2024
6f6a941
new version of lucid
m1n999999 Nov 25, 2024
322945b
lbe v2 specification
m1n999999 Nov 26, 2024
a4861df
move compareUTxO to calculate file
m1n999999 Nov 26, 2024
76664d4
update docs
m1n999999 Nov 26, 2024
b8b730b
remove personal info
m1n999999 Nov 26, 2024
cab955b
add check field length action in fromPlutusData+add dcos
m1n999999 Nov 26, 2024
829b973
docs
m1n999999 Nov 26, 2024
6898dfd
MIN-1548: Auto cancel expired orders worker (#47)
m1n999999 Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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