From 088f6577938310256251f7299cca8664197b9ba9 Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 14:58:35 +0700 Subject: [PATCH 1/6] zero batcher fee --- examples/build-tx-example.ts | 28 +- src/batcher-fee-reduction/calculate.ts | 114 ------ src/batcher-fee-reduction/configs.internal.ts | 374 ++---------------- src/dex-v2.ts | 17 +- src/dex.ts | 55 +-- src/stableswap.ts | 21 +- test/adapter.test.ts | 13 +- test/batcher-fee.test.ts | 201 ---------- test/order.test.ts | 92 +++-- 9 files changed, 112 insertions(+), 803 deletions(-) delete mode 100644 src/batcher-fee-reduction/calculate.ts delete mode 100644 test/batcher-fee.test.ts diff --git a/examples/build-tx-example.ts b/examples/build-tx-example.ts index 0d767e8..3a048bf 100644 --- a/examples/build-tx-example.ts +++ b/examples/build-tx-example.ts @@ -328,8 +328,8 @@ export async function _createPoolV2( assetA: ADA, assetB: { // Replace with your asset - policyId: "997322483e052b1c2e42447fca9261427c6214bb14288a0ac4651fa7", - tokenName: "6c7031", + policyId: "a99569ec232f6b5ce2d81045417af541addca3c44de01be882b394ee", + tokenName: "4c505f544f4b454e", }, amountA: 10_000000n, amountB: 30_000n, @@ -343,7 +343,6 @@ export async function _swapExactInV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -368,7 +367,6 @@ export async function _swapExactInV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos: availableUtxos, orderOptions: [ { type: OrderV2.StepType.SWAP_EXACT_IN, @@ -388,7 +386,6 @@ export async function _swapExactOutV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -413,7 +410,6 @@ export async function _swapExactOutV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos: availableUtxos, orderOptions: [ { type: OrderV2.StepType.SWAP_EXACT_OUT, @@ -432,7 +428,6 @@ export async function _depositV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -457,7 +452,6 @@ export async function _depositV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.DEPOSIT, @@ -477,7 +471,6 @@ export async function _withdrawV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { // ADA-MIN Lp Asset const lpAsset = { @@ -510,7 +503,6 @@ export async function _withdrawV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.WITHDRAW, @@ -528,7 +520,6 @@ export async function _stopV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -552,7 +543,6 @@ export async function _stopV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.STOP, @@ -570,7 +560,6 @@ export async function _ocoV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -611,7 +600,6 @@ export async function _ocoV2TxExample( direction: OrderV2.Direction.A_TO_B, }, ], - availableUtxos, }); } @@ -619,7 +607,6 @@ export async function _zapOutV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { // ADA-MIN Lp Asset const lpAsset = { @@ -644,7 +631,6 @@ export async function _zapOutV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.ZAP_OUT, @@ -662,7 +648,6 @@ export async function _partialSwapV2TxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = ADA; const assetB = MIN; @@ -689,7 +674,6 @@ export async function _partialSwapV2TxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.PARTIAL_SWAP, @@ -714,7 +698,6 @@ export async function _multiRoutingTxExample( lucid: Lucid, adapter: Adapter, address: string, - availableUtxos: Utxo[] ): Promise { const assetA = MIN; const amountA = 10_000n; @@ -771,7 +754,6 @@ export async function _multiRoutingTxExample( return new DexV2(lucid, adapter).createBulkOrdersTx({ sender: address, - availableUtxos, orderOptions: [ { type: OrderV2.StepType.SWAP_ROUTING, @@ -882,7 +864,7 @@ export async function _depositStableExample( // This pool has 2 assets in its config. They are [tDJED, tiUSD]. // This order deposits 100_000n tDJED and 1_000n tiUSD into the pool. - const amountIns = [20_000n, 20_000n]; + const amountIns = [1_000n, 1_000n]; const lpAmount = StableswapCalculation.calculateDeposit({ amountIns: amountIns, @@ -903,8 +885,8 @@ export async function _depositStableExample( lpAsset: lpAsset, type: StableOrder.StepType.DEPOSIT, assetsAmount: [ - [Asset.fromString(pool.assets[0]), 20_000n], - [Asset.fromString(pool.assets[1]), 20_000n], + [Asset.fromString(pool.assets[0]), 1_000n], + [Asset.fromString(pool.assets[1]), 1_000n], ], minimumLPReceived: lpAmount, totalLiquidity: pool.totalLiquidity, diff --git a/src/batcher-fee-reduction/calculate.ts b/src/batcher-fee-reduction/calculate.ts deleted file mode 100644 index 86a1e71..0000000 --- a/src/batcher-fee-reduction/calculate.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { Assets, Utxos } from "@spacebudz/lucid"; -import BigNumber from "bignumber.js"; - -import { NetworkEnvironment } from "../types/network"; -import { - BatcherFeeConfig, - BatcherFeeReductionConfig, - DexVersion, -} from "./configs.internal"; - -export namespace BatcherFee { - export function getFinalFee({ - config, - reductionAssets, - }: { - config: BatcherFeeReductionConfig; - reductionAssets: Assets; - }): bigint { - if (Object.keys(reductionAssets).length === 0) { - return config.maxFee; - } - const { assets, minFee } = config; - // Calculate total amount ratio through each reduction asset - // The ratio is: current amount in wallet / maximum amount - let totalReductionAmountRatio = new BigNumber(0); - for (const { asset, maximumAmount } of assets) { - if (asset in reductionAssets) { - const reductionAmount = new BigNumber(reductionAssets[asset].toString()) - .div(maximumAmount.toString()); - totalReductionAmountRatio = - totalReductionAmountRatio.plus(reductionAmount); - } - } - - // Maximum ratio is 1 - const maximumReductionAmountRatio = totalReductionAmountRatio.isGreaterThanOrEqualTo(new BigNumber(1)) - ? new BigNumber(1) - : totalReductionAmountRatio; - - const maximumReduction = new BigNumber(config.maxFee.toString()) - .minus(minFee.toString()) - .div(config.maxFee.toString()) - .multipliedBy(100); - - // Apply the ratio to calculate batcher fee reduction - const totalReduction = new BigNumber(maximumReduction).multipliedBy(maximumReductionAmountRatio).div(100); - - // New batcher fee = (1 - reduction) * DEFAULT BATCHER FEE - const finalFee = new BigNumber(1) - .minus(totalReduction) - .multipliedBy(new BigNumber(config.maxFee.toString())) - .toFixed(0); - - return BigInt(finalFee); - } - - export function finalizeFee({ - networkEnv, - currentDate, - dexVersion, - utxos, - orderAssets - }: { - networkEnv: NetworkEnvironment; - currentDate: Date, - dexVersion: DexVersion; - utxos: Utxos; - orderAssets: Assets; - }): { - batcherFee: bigint; - reductionAssets: Assets; - } { - const defaultFee = BatcherFeeConfig.CONFIG[networkEnv][dexVersion].defaultFee; - const activeReductionConfig = BatcherFeeConfig.getActiveConfig({ - networkEnv, - dexVersion, - currentDate - }); - - if (activeReductionConfig === undefined) { - return { - batcherFee: defaultFee, - reductionAssets: {} - } - } - - const reductionAssets: Assets = {}; - const totalAssets: Assets = {}; - for (const u of utxos) { - for (const [asset, amount] of Object.entries(u.assets)) { - if (asset in totalAssets) { - totalAssets[asset] += amount; - } else { - totalAssets[asset] = amount; - } - } - } - for (const { asset } of activeReductionConfig.assets) { - if (asset in totalAssets) { - reductionAssets[asset] = totalAssets[asset]; - if (asset in orderAssets) { - reductionAssets[asset] -= orderAssets[asset]; - } - } - } - return { - batcherFee: getFinalFee({ - config: activeReductionConfig, - reductionAssets: reductionAssets - }), - reductionAssets: reductionAssets, - }; - } -} \ No newline at end of file diff --git a/src/batcher-fee-reduction/configs.internal.ts b/src/batcher-fee-reduction/configs.internal.ts index 05abcf1..f909146 100644 --- a/src/batcher-fee-reduction/configs.internal.ts +++ b/src/batcher-fee-reduction/configs.internal.ts @@ -1,9 +1,4 @@ -import { NetworkEnvironment } from "../types/network"; - -export type BatcherFeeAssetConfig = { - asset: string; - maximumAmount: bigint; -}; +import { OrderV1, OrderV2, StableOrder } from "../types/order"; export enum DexVersion { DEX_V1 = "DEX_V1", @@ -11,345 +6,38 @@ export enum DexVersion { STABLESWAP = "STABLESWAP", } -export type BatcherFeeReductionConfig = { - // Maximum Fee users have to pay for Batcher - maxFee: bigint; - // Minimum Fee users have to pay for Batcher - minFee: bigint; - // The time that the system starts applying the reduction - startTime: Date; - // The condition that the system stops applying the reduction - endCondition?: { - // The time that the system stops applying the reduction - endTime: Date; - }; - assets: BatcherFeeAssetConfig[]; +export const BATCHER_FEE_DEX_V1: Record = { + [OrderV1.StepType.SWAP_EXACT_IN]: 900_000n, // + [OrderV1.StepType.SWAP_EXACT_OUT]: 900_000n, // + [OrderV1.StepType.DEPOSIT]: 1_000_000n, // + [OrderV1.StepType.WITHDRAW]: 1_000_000n, // + [OrderV1.StepType.ZAP_IN]: 1_050_000n, // }; -export type BatcherFeeConfig = { - /** - * The Fee that the system will choose if there is no active reduction configurations - * It's 2 ADA in almost cases until now - */ - defaultFee: bigint; - reduction: BatcherFeeReductionConfig[]; +export const BATCHER_FEE_STABLESWAP: Record = { + [StableOrder.StepType.SWAP]: 600_000n, // + [StableOrder.StepType.DEPOSIT]: 600_000n, // + [StableOrder.StepType.WITHDRAW]: 600_000n, // + [StableOrder.StepType.WITHDRAW_IMBALANCE]: 600_000n, // + [StableOrder.StepType.ZAP_OUT]: 600_000n, }; -export const FIXED_BATCHER_FEE = 2_000_000n; - -const MIN_TESTNET = - "e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed724d494e"; -const ADA_MIN_LP_V1_TESTNET = - "e4214b7cce62ac6fbba385d164df48e157eae5863521b4b67ca71d863bb0079303c57812462dec9de8fb867cef8fd3768de7f12c77f6f0dd80381d0d"; -const ADA_MIN_LP_V2_TESTNET = - "d6aae2059baee188f74917493cf7637e679cd219bdfbbf4dcbeb1d0b6c3ea488e6ff940bb6fb1b18fd605b5931d9fefde6440117015ba484cf321200"; - -const MIN_MAINNET = - "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"; -const ADA_MIN_LP_V1_MAINNET = - "e4214b7cce62ac6fbba385d164df48e157eae5863521b4b67ca71d866aa2153e1ae896a95539c9d62f76cedcdabdcdf144e564b8955f609d660cf6a2"; -const ADA_MIN_LP_V2_MAINNET = - "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c82e2b1fd27a7712a1a9cf750dfbea1a5778611b20e06dd6a611df7a643f8cb75"; - -export namespace BatcherFeeConfig { - export const CONFIG: Record< - NetworkEnvironment, - Record - > = { - [NetworkEnvironment.MAINNET]: { - [DexVersion.DEX_V1]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2022-09-14T07:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_MAINNET, // MIN - maximumAmount: 50_000_000_000n, // 50K MIN - }, - { - asset: ADA_MIN_LP_V1_MAINNET, // ADA-MIN LP - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP - }, - ], - }, - ], - }, - [DexVersion.STABLESWAP]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2022-09-14T07:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_MAINNET, // MIN - maximumAmount: 50_000_000_000n, // 50K MIN - }, - { - asset: ADA_MIN_LP_V1_MAINNET, // ADA-MIN LP - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP - }, - ], - }, - ], - }, - [DexVersion.DEX_V2]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 1_000_000n, - minFee: 750_000n, - startTime: new Date("2024-07-01T05:00:00.000Z"), - endCondition: { - endTime: new Date("2024-10-10T08:00:00.000Z"), - }, - assets: [ - { - asset: MIN_MAINNET, // MIN - maximumAmount: 50_000_000_000n, // 50K MIN - }, - { - asset: ADA_MIN_LP_V1_MAINNET, // ADA-MIN LP V1 - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP - }, - { - asset: ADA_MIN_LP_V2_MAINNET, // ADA-MIN LP V2 - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP V2 - }, - ], - }, - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2024-10-10T08:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_MAINNET, // MIN - maximumAmount: 50_000_000_000n, // 50K MIN - }, - { - asset: ADA_MIN_LP_V1_MAINNET, // ADA-MIN LP V1 - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP - }, - { - asset: ADA_MIN_LP_V2_MAINNET, // ADA-MIN LP V2 - maximumAmount: 5_000_000_000n, // 5B ADA-MIN LP V2 - }, - ], - }, - ], - }, - }, - [NetworkEnvironment.TESTNET_PREPROD]: { - [DexVersion.DEX_V1]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2022-09-01T00:00:00.000Z"), - endCondition: { - endTime: new Date("2024-06-24T00:00:00.000Z"), - }, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - ], - }, - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2024-06-24T00:00:00.000Z"), - endCondition: { endTime: new Date("2024-11-04T11:00:00.000Z") }, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - { - asset: ADA_MIN_LP_V2_TESTNET, // ADA-MIN LP V2 - maximumAmount: 100_000_000n, - }, - ], - }, - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2024-11-04T11:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - ], - }, - ], - }, - [DexVersion.STABLESWAP]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2022-09-01T00:00:00.000Z"), - endCondition: { - endTime: new Date("2024-06-24T00:00:00.000Z"), - }, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP - maximumAmount: 100_000_000n, - }, - ], - }, - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2024-06-24T00:00:00.000Z"), - endCondition: { endTime: new Date("2024-11-04T11:00:00.000Z") }, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - { - asset: ADA_MIN_LP_V2_TESTNET, // ADA-MIN LP V2 - maximumAmount: 100_000_000n, - }, - ], - }, - { - maxFee: 2_000_000n, - minFee: 1_500_000n, - startTime: new Date("2024-11-04T11:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - ], - }, - ], - }, - [DexVersion.DEX_V2]: { - defaultFee: 2_000_000n, - reduction: [ - { - maxFee: 1_300_000n, - minFee: 1_000_000n, - startTime: new Date("2024-04-23T00:00:00.000Z"), - endCondition: { - endTime: new Date("2024-06-24T00:00:00.000Z"), - }, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - ], - }, - { - maxFee: 1_300_000n, - minFee: 1_000_000n, - startTime: new Date("2024-06-24T00:00:00.000Z"), - endCondition: undefined, - assets: [ - { - asset: MIN_TESTNET, // MIN - maximumAmount: 10_000_000n, - }, - { - asset: ADA_MIN_LP_V1_TESTNET, // ADA-MIN LP V1 - maximumAmount: 100_000_000n, - }, - { - asset: ADA_MIN_LP_V2_TESTNET, // ADA-MIN LP V2 - maximumAmount: 100_000_000n, - }, - ], - }, - ], - }, - }, - [NetworkEnvironment.TESTNET_PREVIEW]: { - [DexVersion.DEX_V1]: { - defaultFee: 2_000_000n, - reduction: [], - }, - [DexVersion.STABLESWAP]: { - defaultFee: 2_000_000n, - reduction: [], - }, - [DexVersion.DEX_V2]: { - defaultFee: 2_000_000n, - reduction: [], - }, - }, - }; +export const BATCHER_FEE_DEX_V2: Record = { + [OrderV2.StepType.SWAP_EXACT_IN]: 700_000n, // + [OrderV2.StepType.STOP]: 700_000n, // + [OrderV2.StepType.OCO]: 700_000n, // + [OrderV2.StepType.SWAP_EXACT_OUT]: 700_000n, // + [OrderV2.StepType.DEPOSIT]: 750_000n, // + [OrderV2.StepType.WITHDRAW]: 700_000n, // + [OrderV2.StepType.ZAP_OUT]: 700_000n, // + [OrderV2.StepType.PARTIAL_SWAP]: 720_000n, // + [OrderV2.StepType.WITHDRAW_IMBALANCE]: 750_000n, + [OrderV2.StepType.SWAP_ROUTING]: 900_000n, + [OrderV2.StepType.DONATION]: 700_000n, +}; - export function getActiveConfig({ - networkEnv, - dexVersion, - currentDate, - }: { - networkEnv: NetworkEnvironment; - dexVersion: DexVersion; - currentDate: Date; - }): BatcherFeeReductionConfig | undefined { - const batcherFeeConfig = CONFIG[networkEnv][dexVersion]; - let activeReductionConfig: BatcherFeeReductionConfig | undefined; - for (const config of batcherFeeConfig.reduction) { - const { startTime, endCondition } = config; - const isAfterStart = startTime.getTime() <= currentDate.getTime(); - let isBeforeEnd: boolean; - if (endCondition) { - isBeforeEnd = currentDate.getTime() <= endCondition.endTime.getTime(); - } else { - isBeforeEnd = true; - } - if (isAfterStart && isBeforeEnd) { - activeReductionConfig = config; - } - } - return activeReductionConfig; - } -} +export const BATCHER_FEE = { + [DexVersion.DEX_V1]: BATCHER_FEE_DEX_V1, + [DexVersion.STABLESWAP]: BATCHER_FEE_STABLESWAP, + [DexVersion.DEX_V2]: BATCHER_FEE_DEX_V2, +}; diff --git a/src/dex-v2.ts b/src/dex-v2.ts index 6112094..1845f9a 100644 --- a/src/dex-v2.ts +++ b/src/dex-v2.ts @@ -14,8 +14,7 @@ import { } from "@spacebudz/lucid"; import { Adapter, DataObject, DataType } from "."; -import { BatcherFee } from "./batcher-fee-reduction/calculate"; -import { DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_DEX_V2, DexVersion } from "./batcher-fee-reduction/configs.internal"; import { compareUtxo, DexV2Calculation } from "./calculate"; import { Asset } from "./types/asset"; import { @@ -71,7 +70,6 @@ export type BulkOrdersOption = { sender: string; orderOptions: OrderOptions[]; expiredOptions?: OrderV2.ExpirySetting; - availableUtxos: Utxo[]; composeTx?: Tx; authorizationMethodType?: OrderV2.AuthorizationMethodType; }; @@ -750,7 +748,6 @@ export class DexV2 { sender, orderOptions, expiredOptions, - availableUtxos, composeTx, authorizationMethodType, }: BulkOrdersOption): Promise { @@ -766,14 +763,6 @@ export class DexV2 { } } } - // calculate batcher fee - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - currentDate: new Date(), - orderAssets: totalOrderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - }); const limitOrders: string[] = []; const lucidTx = this.lucid.newTx(); const necessaryExtraDatums: { @@ -784,6 +773,7 @@ export class DexV2 { const option = orderOptions[i]; const { type, lpAsset, customReceiver } = option; const orderAssets = this.buildOrderValue(option); + const batcherFee = BATCHER_FEE_DEX_V2[type]; const orderStep = this.buildOrderStep(option, batcherFee); if (type === OrderV2.StepType.SWAP_EXACT_IN && option.isLimitOrder) { limitOrders.push(i.toString()); @@ -903,9 +893,6 @@ export class DexV2 { msg: [metadata], ...(limitOrderMessage && { limitOrders: limitOrderMessage }), }); - if (Object.keys(reductionAssets).length !== 0) { - lucidTx.payTo(sender, reductionAssets); - } if (composeTx) { lucidTx.compose(composeTx); } diff --git a/src/dex.ts b/src/dex.ts index c31a2f2..2ea33be 100644 --- a/src/dex.ts +++ b/src/dex.ts @@ -3,8 +3,7 @@ import { Addresses, Assets, Constr, Lucid, TxComplete } from "@spacebudz/lucid"; import { Utxo } from "@spacebudz/lucid"; import { DataObject, DataType } from "."; -import { BatcherFee } from "./batcher-fee-reduction/calculate"; -import { DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_DEX_V1, DexVersion } from "./batcher-fee-reduction/configs.internal"; import { Asset } from "./types/asset"; import { DexV1Constant, @@ -143,18 +142,11 @@ export class Dex { assetOut, minimumAmountOut, isLimitOrder, - availableUtxos, } = options; invariant(amountIn > 0n, "amount in must be positive"); invariant(minimumAmountOut > 0n, "minimum amount out must be positive"); const orderAssets: Assets = { [Asset.toString(assetIn)]: amountIn }; - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - currentDate: new Date(), - orderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - }); + const batcherFee = BATCHER_FEE_DEX_V1[OrderV1.StepType.SWAP_EXACT_IN] if (orderAssets["lovelace"]) { orderAssets["lovelace"] += FIXED_DEPOSIT_ADA + batcherFee; } else { @@ -180,9 +172,6 @@ export class Dex { orderAssets ) .addSigner(Addresses.addressToCredential(sender).hash); - if (Object.keys(reductionAssets).length !== 0) { - tx.payTo(sender, reductionAssets); - } if (isLimitOrder) { tx.attachMetadata(674, { msg: [MetadataMessage.SWAP_EXACT_IN_LIMIT_ORDER], @@ -217,20 +206,13 @@ export class Dex { assetOut, maximumAmountIn, expectedAmountOut, - availableUtxos, } = options; invariant( maximumAmountIn > 0n && expectedAmountOut > 0n, "amount in and out must be positive" ); const orderAssets: Assets = { [Asset.toString(assetIn)]: maximumAmountIn }; - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - orderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - currentDate: new Date(), - }); + const batcherFee = BATCHER_FEE_DEX_V1[OrderV1.StepType.SWAP_EXACT_OUT] if (orderAssets["lovelace"]) { orderAssets["lovelace"] += FIXED_DEPOSIT_ADA + batcherFee; } else { @@ -256,7 +238,6 @@ export class Dex { DataObject.to(OrderV1.Datum.toPlutusData(datum)), orderAssets ) - .payTo(sender, reductionAssets) .addSigner(Addresses.addressToCredential(sender).hash) .attachMetadata(674, { msg: [MetadataMessage.SWAP_EXACT_OUT_ORDER] }); @@ -285,7 +266,6 @@ export class Dex { lpAmount, minimumAssetAReceived, minimumAssetBReceived, - availableUtxos, } = options; invariant(lpAmount > 0n, "LP amount must be positive"); invariant( @@ -293,13 +273,7 @@ export class Dex { "minimum asset received must be positive" ); const orderAssets: Assets = { [Asset.toString(lpAsset)]: lpAmount }; - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - orderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - currentDate: new Date(), - }); + const batcherFee = BATCHER_FEE_DEX_V1[OrderV1.StepType.WITHDRAW] if (orderAssets["lovelace"]) { orderAssets["lovelace"] += FIXED_DEPOSIT_ADA + batcherFee; } else { @@ -324,7 +298,6 @@ export class Dex { DataObject.to(OrderV1.Datum.toPlutusData(datum)), orderAssets ) - .payTo(sender, reductionAssets) .addSigner(Addresses.addressToCredential(sender).hash) .attachMetadata(674, { msg: [MetadataMessage.WITHDRAW_ORDER] }) .commit(); @@ -337,18 +310,11 @@ export class Dex { amountIn, assetOut, minimumLPReceived, - availableUtxos, } = options; invariant(amountIn > 0n, "amount in must be positive"); invariant(minimumLPReceived > 0n, "minimum LP received must be positive"); const orderAssets: Assets = { [Asset.toString(assetIn)]: amountIn }; - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - orderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - currentDate: new Date(), - }); + const batcherFee = BATCHER_FEE_DEX_V1[OrderV1.StepType.ZAP_IN]; if (orderAssets["lovelace"]) { orderAssets["lovelace"] += FIXED_DEPOSIT_ADA + batcherFee; } else { @@ -374,7 +340,6 @@ export class Dex { DataObject.to(OrderV1.Datum.toPlutusData(datum)), orderAssets ) - .payTo(sender, reductionAssets) .addSigner(Addresses.addressToCredential(sender).hash) .attachMetadata(674, { msg: [MetadataMessage.ZAP_IN_ORDER] }) .commit(); @@ -388,7 +353,6 @@ export class Dex { amountA, amountB, minimumLPReceived, - availableUtxos, } = options; invariant(amountA > 0n && amountB > 0n, "amount must be positive"); invariant(minimumLPReceived > 0n, "minimum LP received must be positive"); @@ -396,13 +360,7 @@ export class Dex { [Asset.toString(assetA)]: amountA, [Asset.toString(assetB)]: amountB, }; - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - orderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - currentDate: new Date(), - }); + const batcherFee = BATCHER_FEE_DEX_V1[OrderV1.StepType.DEPOSIT]; if (orderAssets["lovelace"]) { orderAssets["lovelace"] += FIXED_DEPOSIT_ADA + batcherFee; } else { @@ -426,7 +384,6 @@ export class Dex { DataObject.to(OrderV1.Datum.toPlutusData(datum)), orderAssets ) - .payTo(sender, reductionAssets) .addSigner(Addresses.addressToCredential(sender).hash) .attachMetadata(674, { msg: [MetadataMessage.DEPOSIT_ORDER] }) .commit(); diff --git a/src/stableswap.ts b/src/stableswap.ts index 4095ff3..afd8837 100644 --- a/src/stableswap.ts +++ b/src/stableswap.ts @@ -11,8 +11,7 @@ import { StableswapConstant, V1AndStableswapCustomReceiver, } from "."; -import { BatcherFee } from "./batcher-fee-reduction/calculate"; -import { DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_STABLESWAP, DexVersion } from "./batcher-fee-reduction/configs.internal"; import { Asset } from "./types/asset"; import { NetworkEnvironment, NetworkId } from "./types/network"; import { lucidToNetworkEnv } from "./utils/network.internal"; @@ -282,7 +281,7 @@ export class Stableswap { } async createBulkOrdersTx(options: BulkOrdersOption): Promise { - const { sender, availableUtxos, options: orderOptions } = options; + const { sender, options: orderOptions } = options; invariant( orderOptions.length > 0, @@ -300,25 +299,16 @@ export class Stableswap { } } } - - // calculate batcher fee - const { batcherFee, reductionAssets } = BatcherFee.finalizeFee({ - utxos: availableUtxos, - orderAssets: totalOrderAssets, - networkEnv: this.networkEnv, - dexVersion: this.dexVersion, - currentDate: new Date(), - }); - const tx = this.lucid.newTx(); for (const orderOption of orderOptions) { const config = StableswapConstant.getConfigByLpAsset( orderOption.lpAsset, this.networkId ); - const { customReceiver } = orderOption; + const { customReceiver, type } = orderOption; const orderAssets = this.buildOrderValue(orderOption); const step = this.buildOrderStep(orderOption); + const batcherFee = BATCHER_FEE_STABLESWAP[type]; if ("lovelace" in orderAssets) { orderAssets["lovelace"] += batcherFee; } else { @@ -355,9 +345,6 @@ export class Stableswap { } } } - if (Object.keys(reductionAssets).length !== 0) { - tx.payTo(sender, reductionAssets); - } tx.attachMetadata(674, { msg: [ orderOptions.length > 1 diff --git a/test/adapter.test.ts b/test/adapter.test.ts index b707e1e..3e09bcc 100644 --- a/test/adapter.test.ts +++ b/test/adapter.test.ts @@ -2,10 +2,15 @@ import { BlockFrostAPI } from "@blockfrost/blockfrost-js"; import { Configuration, MaestroClient } from "@maestro-org/typescript-sdk"; import { Network } from "@spacebudz/lucid"; -import { Adapter, BlockfrostAdapter, MaestroAdapter } from "../src/adapters"; -import { ADA, Asset } from "../src/types/asset"; -import { StableswapConstant } from "../src/types/constants"; -import { NetworkId } from "../src/types/network"; +import { + ADA, + Adapter, + Asset, + BlockfrostAdapter, + MaestroAdapter, + NetworkId, + StableswapConstant +} from "../src"; function mustGetEnv(key: string): string { const val = process.env[key]; diff --git a/test/batcher-fee.test.ts b/test/batcher-fee.test.ts deleted file mode 100644 index 06b6f7c..0000000 --- a/test/batcher-fee.test.ts +++ /dev/null @@ -1,201 +0,0 @@ -import invariant from "@minswap/tiny-invariant"; -import { Assets } from "@spacebudz/lucid"; - -import { NetworkEnvironment } from "../src"; -import { BatcherFee } from "../src/batcher-fee-reduction/calculate"; -import { - BatcherFeeConfig, - DexVersion, -} from "../src/batcher-fee-reduction/configs.internal"; - -function compareAssets(a1: Assets, a2: Assets): boolean { - if (Object.keys(a1).length !== Object.keys(a2).length) { - return false; - } - - let isEqual: boolean = true; - for (const [asset1, amount1] of Object.entries(a1)) { - if (asset1 in a2) { - if (amount1 !== a2[asset1]) { - isEqual = false; - break; - } - } else { - isEqual = false; - break; - } - } - return isEqual; -} - -test("Batcher Fee reduction test", () => { - for (const [networkEnvStr, batcherFeeMap] of Object.entries( - BatcherFeeConfig.CONFIG - )) { - let networkEnv: NetworkEnvironment; - switch (networkEnvStr) { - case NetworkEnvironment.MAINNET.toString(): { - networkEnv = NetworkEnvironment.MAINNET; - break; - } - case NetworkEnvironment.TESTNET_PREPROD.toString(): { - networkEnv = NetworkEnvironment.TESTNET_PREPROD; - break; - } - case NetworkEnvironment.TESTNET_PREVIEW.toString(): { - networkEnv = NetworkEnvironment.TESTNET_PREVIEW; - break; - } - default: { - throw new Error("Unexpected Network"); - } - } - for (const [dexVersionStr, batcherFeeConfig] of Object.entries( - batcherFeeMap - )) { - let dexVersion: DexVersion; - switch (dexVersionStr) { - case DexVersion.DEX_V1: - case DexVersion.DEX_V2: - case DexVersion.STABLESWAP: { - dexVersion = dexVersionStr; - break; - } - default: { - throw new Error("Unexpected DEX version"); - } - } - for (const reduction of batcherFeeConfig.reduction) { - const date = new Date(reduction.startTime.getTime() + 1); - // const defaultFee = getStandardBatcherFee(networkEnv, dexVersion, date); - // No Reduction - const nonReductionFee = BatcherFee.finalizeFee({ - networkEnv: networkEnv, - dexVersion: dexVersion, - currentDate: date, - utxos: [], - orderAssets: {}, - }); - - invariant(nonReductionFee.batcherFee === reduction.maxFee); - // Maximum Reduction - for (const { asset, maximumAmount } of reduction.assets) { - const discountFee1 = BatcherFee.finalizeFee({ - networkEnv: networkEnv, - dexVersion: dexVersion, - currentDate: reduction.startTime, - utxos: [ - { - txHash: - "73fe9271c8e2b11430d76bfe4b0dad4816c326d08e63439130c863b0a1932649", - outputIndex: 0, - address: - "addr_test1qz09ls06gtsnws8dhquh273tnzj0avf8fumakgmdc40cwazvh204krl8rn5cvnepdzn5zj55wk4uy8nnzwklhzcvtyws67g5de", - assets: { - lovelace: 10_000000n, - [asset]: maximumAmount, - }, - }, - ], - orderAssets: {}, - }); - - const discountFee2 = BatcherFee.finalizeFee({ - networkEnv: networkEnv, - dexVersion: dexVersion, - currentDate: reduction.startTime, - utxos: [ - { - txHash: - "73fe9271c8e2b11430d76bfe4b0dad4816c326d08e63439130c863b0a1932649", - outputIndex: 0, - address: - "addr_test1qz09ls06gtsnws8dhquh273tnzj0avf8fumakgmdc40cwazvh204krl8rn5cvnepdzn5zj55wk4uy8nnzwklhzcvtyws67g5de", - assets: { - lovelace: 10_000000n, - [asset]: maximumAmount * 2n, - }, - }, - ], - orderAssets: { - lovelace: 2_000000n, - [asset]: maximumAmount, - }, - }); - invariant(discountFee1.batcherFee === reduction.minFee); - invariant(discountFee2.batcherFee === reduction.minFee); - invariant( - compareAssets(discountFee1.reductionAssets, { - [asset]: maximumAmount, - }) - ); - invariant( - compareAssets(discountFee2.reductionAssets, { - [asset]: maximumAmount, - }) - ); - } - - // Partial Reduction - for (const { asset, maximumAmount } of reduction.assets) { - const discountFee1 = BatcherFee.finalizeFee({ - networkEnv: networkEnv, - dexVersion: dexVersion, - currentDate: reduction.startTime, - utxos: [ - { - txHash: - "73fe9271c8e2b11430d76bfe4b0dad4816c326d08e63439130c863b0a1932649", - outputIndex: 0, - address: - "addr_test1qz09ls06gtsnws8dhquh273tnzj0avf8fumakgmdc40cwazvh204krl8rn5cvnepdzn5zj55wk4uy8nnzwklhzcvtyws67g5de", - assets: { - lovelace: 10_000000n, - [asset]: maximumAmount / 2n, - }, - }, - ], - orderAssets: {}, - }); - const discountFee2 = BatcherFee.finalizeFee({ - networkEnv: networkEnv, - dexVersion: dexVersion, - currentDate: reduction.startTime, - utxos: [ - { - txHash: - "73fe9271c8e2b11430d76bfe4b0dad4816c326d08e63439130c863b0a1932649", - outputIndex: 0, - address: - "addr_test1qz09ls06gtsnws8dhquh273tnzj0avf8fumakgmdc40cwazvh204krl8rn5cvnepdzn5zj55wk4uy8nnzwklhzcvtyws67g5de", - assets: { - lovelace: 10_000000n, - [asset]: maximumAmount, - }, - }, - ], - orderAssets: { - lovelace: 2_000000n, - [asset]: maximumAmount / 2n, - }, - }); - - const fiftyPercentDiscountFee = - (reduction.maxFee + reduction.minFee) / 2n; - invariant(discountFee1.batcherFee === fiftyPercentDiscountFee); - invariant(discountFee2.batcherFee === fiftyPercentDiscountFee); - invariant( - compareAssets(discountFee1.reductionAssets, { - [asset]: maximumAmount / 2n, - }) - ); - invariant( - compareAssets(discountFee2.reductionAssets, { - [asset]: maximumAmount / 2n, - }) - ); - } - } - } - } -}); diff --git a/test/order.test.ts b/test/order.test.ts index 4237d6e..d46274d 100644 --- a/test/order.test.ts +++ b/test/order.test.ts @@ -1,12 +1,20 @@ import invariant from "@minswap/tiny-invariant"; -import { Addresses, Data } from "@spacebudz/lucid"; +import { Addresses } from "@spacebudz/lucid"; -import { FIXED_BATCHER_FEE } from "../src/batcher-fee-reduction/configs.internal"; -import { Asset } from "../src/types/asset"; -import { FIXED_DEPOSIT_ADA } from "../src/types/constants"; -import { NetworkId } from "../src/types/network"; -import { OrderV1, OrderV2, StableOrder } from "../src/types/order"; import { DataObject } from "../src"; +import { + Asset, + FIXED_DEPOSIT_ADA, + NetworkId, + OrderV1, + OrderV2, + StableOrder, +} from "../src"; +import { + BATCHER_FEE_DEX_V1, + BATCHER_FEE_DEX_V2, + BATCHER_FEE_STABLESWAP, +} from "../src/batcher-fee-reduction/configs.internal"; let testSender: string; let testSenderPkh: string; @@ -31,21 +39,29 @@ beforeAll(() => { networkId = NetworkId.TESTNET; }); -function buildCommonV1Datum(): Omit< - OrderV1.Datum, - "receiverDatumHash" | "step" -> { +function buildCommonV1Datum( + type: OrderV1.StepType | StableOrder.StepType +): Omit { + let batcherFee: bigint; + if (type in BATCHER_FEE_DEX_V1) { + batcherFee = BATCHER_FEE_DEX_V1[type]; + } else if (type in BATCHER_FEE_STABLESWAP) { + batcherFee = BATCHER_FEE_STABLESWAP[type]; + } else { + throw new Error(`Unexpected type for ${type}`); + } + return { sender: testSender, receiver: testReceiver, - batcherFee: FIXED_BATCHER_FEE, + batcherFee: batcherFee, depositADA: FIXED_DEPOSIT_ADA, }; } test("V1: SwapExactIn Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.SWAP_EXACT_IN, @@ -55,7 +71,7 @@ test("V1: SwapExactIn Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: undefined, step: { type: OrderV1.StepType.SWAP_EXACT_IN, @@ -78,7 +94,7 @@ test("V1: SwapExactIn Order to PlutusData Converter", () => { test("V1: SwapExactOut Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_OUT), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.SWAP_EXACT_OUT, @@ -88,7 +104,7 @@ test("V1: SwapExactOut Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_OUT), receiverDatumHash: undefined, step: { type: OrderV1.StepType.SWAP_EXACT_OUT, @@ -111,7 +127,7 @@ test("V1: SwapExactOut Order to PlutusData Converter", () => { test("V1: Deposit Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.DEPOSIT), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.DEPOSIT, @@ -120,7 +136,7 @@ test("V1: Deposit Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.DEPOSIT), receiverDatumHash: undefined, step: { type: OrderV1.StepType.DEPOSIT, @@ -142,7 +158,7 @@ test("V1: Deposit Order to PlutusData Converter", () => { test("V1: Withdraw Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.WITHDRAW), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.WITHDRAW, @@ -152,7 +168,7 @@ test("V1: Withdraw Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.WITHDRAW), receiverDatumHash: undefined, step: { type: OrderV1.StepType.WITHDRAW, @@ -175,7 +191,7 @@ test("V1: Withdraw Order to PlutusData Converter", () => { test("V1: Zap Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.ZAP_IN), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.ZAP_IN, @@ -185,7 +201,7 @@ test("V1: Zap Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: undefined, step: { type: OrderV1.StepType.ZAP_IN, @@ -208,7 +224,7 @@ test("V1: Zap Order to PlutusData Converter", () => { test("Stableswap: Swap Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.SWAP), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.SWAP, @@ -219,7 +235,7 @@ test("Stableswap: Swap Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.SWAP), receiverDatumHash: undefined, step: { type: StableOrder.StepType.SWAP, @@ -243,7 +259,7 @@ test("Stableswap: Swap Order to PlutusData Converter", () => { test("Stableswap: Deposit Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.DEPOSIT), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.DEPOSIT, @@ -252,7 +268,7 @@ test("Stableswap: Deposit Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.DEPOSIT), receiverDatumHash: undefined, step: { type: StableOrder.StepType.DEPOSIT, @@ -274,7 +290,7 @@ test("Stableswap: Deposit Order to PlutusData Converter", () => { test("Stableswap: Withdraw Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW, @@ -283,7 +299,7 @@ test("Stableswap: Withdraw Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW, @@ -305,7 +321,7 @@ test("Stableswap: Withdraw Order to PlutusData Converter", () => { test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW_IMBALANCE), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -314,7 +330,7 @@ test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW_IMBALANCE), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -336,7 +352,7 @@ test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { test("Stableswap: Zap Out Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.ZAP_OUT), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -345,7 +361,7 @@ test("Stableswap: Zap Out Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(), + ...buildCommonV1Datum(StableOrder.StepType.ZAP_OUT), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -386,7 +402,7 @@ function buildV2Datums(step: OrderV2.Step): OrderV2.Datum[] { tokenName: "e08460587b08cca542bd2856b8d5e1d23bf3f63f9916fb81f6d95fda0910bf69", }, - maxBatcherFee: FIXED_BATCHER_FEE, + maxBatcherFee: BATCHER_FEE_DEX_V2[step.type], expiredOptions: undefined, }, { @@ -410,7 +426,7 @@ function buildV2Datums(step: OrderV2.Step): OrderV2.Datum[] { tokenName: "e08460587b08cca542bd2856b8d5e1d23bf3f63f9916fb81f6d95fda0910bf69", }, - maxBatcherFee: FIXED_BATCHER_FEE, + maxBatcherFee: BATCHER_FEE_DEX_V2[step.type], expiredOptions: undefined, }, { @@ -434,7 +450,7 @@ function buildV2Datums(step: OrderV2.Step): OrderV2.Datum[] { tokenName: "e08460587b08cca542bd2856b8d5e1d23bf3f63f9916fb81f6d95fda0910bf69", }, - maxBatcherFee: FIXED_BATCHER_FEE, + maxBatcherFee: BATCHER_FEE_DEX_V2[step.type], expiredOptions: undefined, }, { @@ -456,7 +472,7 @@ function buildV2Datums(step: OrderV2.Step): OrderV2.Datum[] { tokenName: "e08460587b08cca542bd2856b8d5e1d23bf3f63f9916fb81f6d95fda0910bf69", }, - maxBatcherFee: FIXED_BATCHER_FEE, + maxBatcherFee: BATCHER_FEE_DEX_V2[step.type], expiredOptions: { expiredTime: 1721010208050n, maxCancellationTip: 300_000n, @@ -716,7 +732,8 @@ test("V2: Partial Swap Order to PlutusData Converter", () => { ioRatioNumerator: 1n, hops: 3n, direction: OrderV2.Direction.A_TO_B, - maxBatcherFeeEachTime: FIXED_BATCHER_FEE * 3n, + maxBatcherFeeEachTime: + BATCHER_FEE_DEX_V2[OrderV2.StepType.PARTIAL_SWAP] * 3n, minimumSwapAmountRequired: 1000n, }; const step2: OrderV2.Step = { @@ -726,7 +743,8 @@ test("V2: Partial Swap Order to PlutusData Converter", () => { ioRatioNumerator: 1n, hops: 3n, direction: OrderV2.Direction.B_TO_A, - maxBatcherFeeEachTime: FIXED_BATCHER_FEE * 3n, + maxBatcherFeeEachTime: + BATCHER_FEE_DEX_V2[OrderV2.StepType.PARTIAL_SWAP] * 3n, minimumSwapAmountRequired: 1000n, }; const datums: OrderV2.Datum[] = [ From b56bdff9cfaa0ae42dae0f1175ea136b1f0763c1 Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 15:13:10 +0700 Subject: [PATCH 2/6] delete comment --- src/batcher-fee-reduction/configs.internal.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/batcher-fee-reduction/configs.internal.ts b/src/batcher-fee-reduction/configs.internal.ts index f909146..d4232d9 100644 --- a/src/batcher-fee-reduction/configs.internal.ts +++ b/src/batcher-fee-reduction/configs.internal.ts @@ -7,30 +7,30 @@ export enum DexVersion { } export const BATCHER_FEE_DEX_V1: Record = { - [OrderV1.StepType.SWAP_EXACT_IN]: 900_000n, // - [OrderV1.StepType.SWAP_EXACT_OUT]: 900_000n, // - [OrderV1.StepType.DEPOSIT]: 1_000_000n, // - [OrderV1.StepType.WITHDRAW]: 1_000_000n, // - [OrderV1.StepType.ZAP_IN]: 1_050_000n, // + [OrderV1.StepType.SWAP_EXACT_IN]: 900_000n, + [OrderV1.StepType.SWAP_EXACT_OUT]: 900_000n, + [OrderV1.StepType.DEPOSIT]: 1_000_000n, + [OrderV1.StepType.WITHDRAW]: 1_000_000n, + [OrderV1.StepType.ZAP_IN]: 1_050_000n, }; export const BATCHER_FEE_STABLESWAP: Record = { - [StableOrder.StepType.SWAP]: 600_000n, // - [StableOrder.StepType.DEPOSIT]: 600_000n, // - [StableOrder.StepType.WITHDRAW]: 600_000n, // - [StableOrder.StepType.WITHDRAW_IMBALANCE]: 600_000n, // + [StableOrder.StepType.SWAP]: 600_000n, + [StableOrder.StepType.DEPOSIT]: 600_000n, + [StableOrder.StepType.WITHDRAW]: 600_000n, + [StableOrder.StepType.WITHDRAW_IMBALANCE]: 600_000n, [StableOrder.StepType.ZAP_OUT]: 600_000n, }; export const BATCHER_FEE_DEX_V2: Record = { - [OrderV2.StepType.SWAP_EXACT_IN]: 700_000n, // - [OrderV2.StepType.STOP]: 700_000n, // - [OrderV2.StepType.OCO]: 700_000n, // - [OrderV2.StepType.SWAP_EXACT_OUT]: 700_000n, // - [OrderV2.StepType.DEPOSIT]: 750_000n, // - [OrderV2.StepType.WITHDRAW]: 700_000n, // - [OrderV2.StepType.ZAP_OUT]: 700_000n, // - [OrderV2.StepType.PARTIAL_SWAP]: 720_000n, // + [OrderV2.StepType.SWAP_EXACT_IN]: 700_000n, + [OrderV2.StepType.STOP]: 700_000n, + [OrderV2.StepType.OCO]: 700_000n, + [OrderV2.StepType.SWAP_EXACT_OUT]: 700_000n, + [OrderV2.StepType.DEPOSIT]: 750_000n, + [OrderV2.StepType.WITHDRAW]: 700_000n, + [OrderV2.StepType.ZAP_OUT]: 700_000n, + [OrderV2.StepType.PARTIAL_SWAP]: 720_000n, [OrderV2.StepType.WITHDRAW_IMBALANCE]: 750_000n, [OrderV2.StepType.SWAP_ROUTING]: 900_000n, [OrderV2.StepType.DONATION]: 700_000n, From 19a41602cc659c062306a7282722eea8496cd45a Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 15:36:20 +0700 Subject: [PATCH 3/6] fix folder --- docs/dex-transaction.md | 9 +++------ .../configs.internal.ts | 0 src/dex-v2.ts | 2 +- src/dex.ts | 2 +- src/stableswap.ts | 2 +- test/order.test.ts | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) rename src/{batcher-fee-reduction => batcher-fee}/configs.internal.ts (100%) diff --git a/docs/dex-transaction.md b/docs/dex-transaction.md index 077d010..992b4dd 100644 --- a/docs/dex-transaction.md +++ b/docs/dex-transaction.md @@ -17,14 +17,11 @@ This documentation provides details on how to interact with the **Stableswap** a - All utility functions are located in the [Calculate](../src/calculate.ts) file. These functions provide the necessary calculations for operations such as trades, deposits, and withdrawals related to the DEX V2 and Stable Liquidity Pool. - You can combine these utility functions with the [Slippage](../src/utils/slippage.internal.ts) file to manage volatile liquidity pools efficiently. -### Batcher Fee Discount +### Batcher Fee -Currently, everyone who swaps on the Minswap DEX pays a 2 $ADA fee to execute the DEX order. To increase the utility of the $MIN token within the platform, $MIN holders are entitled to a discount on this 2 $ADA Batcher Fee. More details about this can be found in the [Minswap Official Docs](https://docs.minswap.org/min-token/usdmin-tokenomics/trading-fee-discount). - -Technically, the Batcher Fee Discount is calculated based on the ADA-MIN LP Tokens and MIN tokens that users are holding. This calculation is handled by the [BatcherFee.finalizeFee](../src/batcher-fee-reduction/calculate.ts#L11) function. - -If you are transacting through the `Stableswap` or `DexV2` classes, the transaction is automatically constructed with the Batcher Fee Discount if you are eligible for it. +Currently, every swap on the Minswap DEX incurs a 2 ADA fee for executing the DEX order. +Additionally, building a transaction requires a Batcher Fee, which is defined in [BatcherFee.finalizeFee](../src/batcher-fee/configs.internal.ts#L11). --- ## Example Usage diff --git a/src/batcher-fee-reduction/configs.internal.ts b/src/batcher-fee/configs.internal.ts similarity index 100% rename from src/batcher-fee-reduction/configs.internal.ts rename to src/batcher-fee/configs.internal.ts diff --git a/src/dex-v2.ts b/src/dex-v2.ts index 1845f9a..194f3f7 100644 --- a/src/dex-v2.ts +++ b/src/dex-v2.ts @@ -14,7 +14,7 @@ import { } from "@spacebudz/lucid"; import { Adapter, DataObject, DataType } from "."; -import { BATCHER_FEE_DEX_V2, DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_DEX_V2, DexVersion } from "./batcher-fee/configs.internal"; import { compareUtxo, DexV2Calculation } from "./calculate"; import { Asset } from "./types/asset"; import { diff --git a/src/dex.ts b/src/dex.ts index 2ea33be..fb10b11 100644 --- a/src/dex.ts +++ b/src/dex.ts @@ -3,7 +3,7 @@ import { Addresses, Assets, Constr, Lucid, TxComplete } from "@spacebudz/lucid"; import { Utxo } from "@spacebudz/lucid"; import { DataObject, DataType } from "."; -import { BATCHER_FEE_DEX_V1, DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_DEX_V1, DexVersion } from "./batcher-fee/configs.internal"; import { Asset } from "./types/asset"; import { DexV1Constant, diff --git a/src/stableswap.ts b/src/stableswap.ts index afd8837..04fc72f 100644 --- a/src/stableswap.ts +++ b/src/stableswap.ts @@ -11,7 +11,7 @@ import { StableswapConstant, V1AndStableswapCustomReceiver, } from "."; -import { BATCHER_FEE_STABLESWAP, DexVersion } from "./batcher-fee-reduction/configs.internal"; +import { BATCHER_FEE_STABLESWAP, DexVersion } from "./batcher-fee/configs.internal"; import { Asset } from "./types/asset"; import { NetworkEnvironment, NetworkId } from "./types/network"; import { lucidToNetworkEnv } from "./utils/network.internal"; diff --git a/test/order.test.ts b/test/order.test.ts index d46274d..b1d16ac 100644 --- a/test/order.test.ts +++ b/test/order.test.ts @@ -14,7 +14,7 @@ import { BATCHER_FEE_DEX_V1, BATCHER_FEE_DEX_V2, BATCHER_FEE_STABLESWAP, -} from "../src/batcher-fee-reduction/configs.internal"; +} from "../src/batcher-fee/configs.internal"; let testSender: string; let testSenderPkh: string; From f3537233f2ead3ddec22a1ad5ff8bf425dab2e41 Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 15:40:03 +0700 Subject: [PATCH 4/6] fix doc --- docs/dex-transaction.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dex-transaction.md b/docs/dex-transaction.md index 992b4dd..5f0ae1f 100644 --- a/docs/dex-transaction.md +++ b/docs/dex-transaction.md @@ -19,9 +19,9 @@ This documentation provides details on how to interact with the **Stableswap** a ### Batcher Fee -Currently, every swap on the Minswap DEX incurs a 2 ADA fee for executing the DEX order. +- Currently, every swap on the Minswap DEX incurs a 2 ADA fee for store UTXO order. It will be refunded after the transaction is completed. -Additionally, building a transaction requires a Batcher Fee, which is defined in [BatcherFee.finalizeFee](../src/batcher-fee/configs.internal.ts#L11). +- Additionally, building a transaction requires a Batcher Fee, which is defined in [BatcherFee](../src/batcher-fee/configs.internal.ts). --- ## Example Usage From 69c69bcad793b01d823da5a732bff50c3b06cfca Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 15:42:46 +0700 Subject: [PATCH 5/6] fix test --- test/order.test.ts | 58 ++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/test/order.test.ts b/test/order.test.ts index b1d16ac..3d94be7 100644 --- a/test/order.test.ts +++ b/test/order.test.ts @@ -1,9 +1,9 @@ import invariant from "@minswap/tiny-invariant"; import { Addresses } from "@spacebudz/lucid"; -import { DataObject } from "../src"; import { Asset, + DataObject, FIXED_DEPOSIT_ADA, NetworkId, OrderV1, @@ -11,9 +11,9 @@ import { StableOrder, } from "../src"; import { - BATCHER_FEE_DEX_V1, + BATCHER_FEE, BATCHER_FEE_DEX_V2, - BATCHER_FEE_STABLESWAP, + DexVersion, } from "../src/batcher-fee/configs.internal"; let testSender: string; @@ -40,28 +40,20 @@ beforeAll(() => { }); function buildCommonV1Datum( + dexVersion: DexVersion, type: OrderV1.StepType | StableOrder.StepType ): Omit { - let batcherFee: bigint; - if (type in BATCHER_FEE_DEX_V1) { - batcherFee = BATCHER_FEE_DEX_V1[type]; - } else if (type in BATCHER_FEE_STABLESWAP) { - batcherFee = BATCHER_FEE_STABLESWAP[type]; - } else { - throw new Error(`Unexpected type for ${type}`); - } - return { sender: testSender, receiver: testReceiver, - batcherFee: batcherFee, + batcherFee: BATCHER_FEE[dexVersion][type], depositADA: FIXED_DEPOSIT_ADA, }; } test("V1: SwapExactIn Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.SWAP_EXACT_IN, @@ -71,7 +63,7 @@ test("V1: SwapExactIn Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: undefined, step: { type: OrderV1.StepType.SWAP_EXACT_IN, @@ -94,7 +86,7 @@ test("V1: SwapExactIn Order to PlutusData Converter", () => { test("V1: SwapExactOut Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_OUT), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.SWAP_EXACT_OUT), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.SWAP_EXACT_OUT, @@ -104,7 +96,7 @@ test("V1: SwapExactOut Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_OUT), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.SWAP_EXACT_OUT), receiverDatumHash: undefined, step: { type: OrderV1.StepType.SWAP_EXACT_OUT, @@ -127,7 +119,7 @@ test("V1: SwapExactOut Order to PlutusData Converter", () => { test("V1: Deposit Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.DEPOSIT), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.DEPOSIT), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.DEPOSIT, @@ -136,7 +128,7 @@ test("V1: Deposit Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.DEPOSIT), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.DEPOSIT), receiverDatumHash: undefined, step: { type: OrderV1.StepType.DEPOSIT, @@ -158,7 +150,7 @@ test("V1: Deposit Order to PlutusData Converter", () => { test("V1: Withdraw Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.WITHDRAW), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.WITHDRAW), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.WITHDRAW, @@ -168,7 +160,7 @@ test("V1: Withdraw Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.WITHDRAW), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.WITHDRAW), receiverDatumHash: undefined, step: { type: OrderV1.StepType.WITHDRAW, @@ -191,7 +183,7 @@ test("V1: Withdraw Order to PlutusData Converter", () => { test("V1: Zap Order to PlutusData Converter", () => { const order1: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.ZAP_IN), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.ZAP_IN), receiverDatumHash: testReceiverDatumHash, step: { type: OrderV1.StepType.ZAP_IN, @@ -201,7 +193,7 @@ test("V1: Zap Order to PlutusData Converter", () => { }; const order2: OrderV1.Datum = { - ...buildCommonV1Datum(OrderV1.StepType.SWAP_EXACT_IN), + ...buildCommonV1Datum(DexVersion.DEX_V1, OrderV1.StepType.SWAP_EXACT_IN), receiverDatumHash: undefined, step: { type: OrderV1.StepType.ZAP_IN, @@ -224,7 +216,7 @@ test("V1: Zap Order to PlutusData Converter", () => { test("Stableswap: Swap Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.SWAP), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.SWAP), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.SWAP, @@ -235,7 +227,7 @@ test("Stableswap: Swap Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.SWAP), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.SWAP), receiverDatumHash: undefined, step: { type: StableOrder.StepType.SWAP, @@ -259,7 +251,7 @@ test("Stableswap: Swap Order to PlutusData Converter", () => { test("Stableswap: Deposit Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.DEPOSIT), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.DEPOSIT), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.DEPOSIT, @@ -268,7 +260,7 @@ test("Stableswap: Deposit Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.DEPOSIT), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.DEPOSIT), receiverDatumHash: undefined, step: { type: StableOrder.StepType.DEPOSIT, @@ -290,7 +282,7 @@ test("Stableswap: Deposit Order to PlutusData Converter", () => { test("Stableswap: Withdraw Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.WITHDRAW), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW, @@ -299,7 +291,7 @@ test("Stableswap: Withdraw Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.WITHDRAW), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW, @@ -321,7 +313,7 @@ test("Stableswap: Withdraw Order to PlutusData Converter", () => { test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW_IMBALANCE), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.WITHDRAW_IMBALANCE), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -330,7 +322,7 @@ test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.WITHDRAW_IMBALANCE), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.WITHDRAW_IMBALANCE), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -352,7 +344,7 @@ test("Stableswap: Withdraw Imbalance Order to PlutusData Converter", () => { test("Stableswap: Zap Out Order to PlutusData Converter", () => { const order1: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.ZAP_OUT), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.ZAP_OUT), receiverDatumHash: testReceiverDatumHash, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, @@ -361,7 +353,7 @@ test("Stableswap: Zap Out Order to PlutusData Converter", () => { }; const order2: StableOrder.Datum = { - ...buildCommonV1Datum(StableOrder.StepType.ZAP_OUT), + ...buildCommonV1Datum(DexVersion.STABLESWAP, StableOrder.StepType.ZAP_OUT), receiverDatumHash: undefined, step: { type: StableOrder.StepType.WITHDRAW_IMBALANCE, From 1959ed5fe7e831504545da0f2864a827b6d8b200 Mon Sep 17 00:00:00 2001 From: datnguyen2k3 Date: Thu, 6 Mar 2025 15:48:27 +0700 Subject: [PATCH 6/6] update ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3d426e..d747dec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,8 @@ jobs: cache: "pnpm" - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Run generate prisma + run: pnpm run prisma:generate - name: Run build run: pnpm run build - name: Run test