From d51628e907f4c2a5b4f55f95c58a2a15bed066ef Mon Sep 17 00:00:00 2001 From: Minggggg <80378612+haminh02@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:03:58 +0700 Subject: [PATCH 1/2] doc for withdraw imbalance formula (#30) * docs for withdraw imbalance * update docs * update docs --------- Co-authored-by: h2physics --- amm-v2-docs/formula.md | 39 +++++++++++++++++++++++++++++++++++++-- lib/amm_dex_v2/math.ak | 4 ++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/amm-v2-docs/formula.md b/amm-v2-docs/formula.md index 31db604..b8d9dcd 100644 --- a/amm-v2-docs/formula.md +++ b/amm-v2-docs/formula.md @@ -70,5 +70,40 @@ $$\Delta y = \frac{\Delta L}{L} * y_{0}$$ In case users want to zap out to Asset B, $\Delta x$ will be swapped, then total amount users receive is $$Out = \Delta y + \frac{(f_{d} - f_{n}) * \Delta x * y_{0}}{x_{0} * f_{d} + (f_{d} - f_{n}) * \Delta x}$$ -### 5. Withdraw Imbalance -TODO \ No newline at end of file +### 6. Withdraw Imbalance + +Users want to withdraw with a ratio $A/B$. + +We have the basic withdrawal formulas: + +$$\Delta x = \frac{\Delta L}{L} * x_{0}$$ +$$\Delta y = \frac{\Delta L}{L} * y_{0}$$ + +Suppose we need to swap some in $\Delta x$ to get $\frac{\Delta x'}{\Delta y'} = \frac{A}{B}$. + +So we have the formula: +$$\frac{\Delta x - swap_{x}}{\Delta y + receive_{y}} =\frac{A}{B} (1)$$ + + +$$ receive_{y} = \frac{(f_{d} - f_{n}) * swap_{x} * y_{0}}{x_{0} * f_{d} + (f_{d} - f_{n}) * swap_{x}}(2)$$ + +(With $x_{0}$ and $y_{0}$ being $x$ and $y$ after withdrawal, $swap_{x}$ is the amount need to be swapped to adapt the ratio $A/B$ that users expect). + +Combination of formula (1) and (2), we have: + +$$a * swap_{x} ^ 2 + b * swap_{x} + c = 0$$ +where +$$a = (f_{d} - f_{n}) * B$$ +$$b = A*(f_{d} - f_{n})*(y_{0}+\Delta y) + B *(f_{d} * x_{0} - (f_{d} - f_{n})*\Delta x)$$ +$$ c =f_{d} * x_{0} *(A * \Delta y - B * \Delta x) $$ + +### 7. Partial Swap +Allow users swap only if price is exactly matched. + +In case users want to swap with price $A/B$ +We have 2 formulas: +$$\frac{\Delta x}{\Delta y} = \frac{A}{B} (1)$$ +$$ \Delta y = \frac{(f_{d} - f_{n}) * \Delta x * y_{0}}{x_{0} * f_{d} + (f_{d} - f_{n}) * \Delta x} (2)$$ +We can calculate $\Delta x$: +$$\Delta x = \frac{A * (f_{d} - f_{n}) * y_{0} - B * f_{d} * x_{0}}{(f_{d} - f_{n}) * B}$$ +where $\Delta x$ is the maximum amount can be swapped to adapt $A/B$ ratio \ No newline at end of file diff --git a/lib/amm_dex_v2/math.ak b/lib/amm_dex_v2/math.ak index b258ef7..2ea4748 100644 --- a/lib/amm_dex_v2/math.ak +++ b/lib/amm_dex_v2/math.ak @@ -358,8 +358,8 @@ pub fn calculate_zap_out( // a * swap_amount_in ^ 2 + b * swap_amount_in + c = 0 // Where: // - a = fee_diff * expect_io_ratio_denominator -// - b = expect_io_ratio_numerator * fee_diff ( reserve_out + amount_out ) * expect_io_ratio_denominator * (fee_denominator * reserve_in - fee_diff * amount_in) -// - c = fee_denominator * (expect_io_ratio_numerator * amount_out - expect_io_ratio_denominator * amount_in) +// - b = expect_io_ratio_numerator * fee_diff ( reserve_out + amount_out ) + expect_io_ratio_denominator * (fee_denominator * reserve_in - fee_diff * amount_in) +// - c = fee_denominator * reserve_in* (expect_io_ratio_numerator * amount_out - expect_io_ratio_denominator * amount_in) fn calculate_withdraw_swap_amount( amount_in: Int, amount_out: Int, From ec38cd102e6bdb6b8a2bfd489f850d0ffb97ec01 Mon Sep 17 00:00:00 2001 From: Richard Nguyen Date: Thu, 15 Feb 2024 11:06:51 +0700 Subject: [PATCH 2/2] add safety check on factory validators & update some incorrect comments and variable names (#34) --- lib/amm_dex_v2/order_validation.ak | 32 ++++++++++++++--------------- lib/amm_dex_v2/pool_validation.ak | 5 ++--- plutus.json | 4 ++-- validators/authen_minting_policy.ak | 3 +-- validators/factory_validator.ak | 4 ++++ 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/amm_dex_v2/order_validation.ak b/lib/amm_dex_v2/order_validation.ak index 6aeae6c..e8b194b 100644 --- a/lib/amm_dex_v2/order_validation.ak +++ b/lib/amm_dex_v2/order_validation.ak @@ -40,7 +40,7 @@ fn validate_swap_exact_in( profit_sharing_opt: Option<(Int, Int)>, pool_state: PoolState, kill_on_failed: Bool, - is_slippage_sastified: fn(Int) -> Bool, + is_slippage_satisfied: fn(Int) -> Bool, ) -> PoolState { let ( datum_reserve_a, @@ -75,8 +75,8 @@ fn validate_swap_exact_in( trading_fee_denominator: trading_fee_denominator, fee_sharing_opt: profit_sharing_opt, ) - let slippage_sastified = is_slippage_sastified(amount_out) - if slippage_sastified { + let slippage_satisfied = is_slippage_satisfied(amount_out) + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -174,8 +174,8 @@ fn validate_swap_exact_out( trading_fee_denominator: trading_fee_denominator, fee_sharing_opt: profit_sharing_opt, ) - let slippage_sastified = necessary_amount_in <= maximum_swap_amount - if slippage_sastified { + let slippage_satisfied = necessary_amount_in <= maximum_swap_amount + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -267,8 +267,8 @@ fn validate_deposit( trading_fee_denominator: trading_fee_denominator, profit_sharing_opt: profit_sharing_opt, ) - let slippage_sastified = lp_amount >= minimum_lp - if slippage_sastified { + let slippage_satisfied = lp_amount >= minimum_lp + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -342,11 +342,11 @@ fn validate_withdraw( withdrawal_lp_amount, total_liquidity, ) - let slippage_sastified = and { + let slippage_satisfied = and { amount_a_out >= minimum_amount_a, amount_b_out >= minimum_amount_b, } - if slippage_sastified { + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -432,8 +432,8 @@ fn validate_zap_out( trading_fee_denominator: trading_fee_denominator, profit_sharing_opt: profit_sharing_opt, ) - let slippage_sastified = amount_out >= minimum_receive - if slippage_sastified { + let slippage_satisfied = amount_out >= minimum_receive + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -625,8 +625,8 @@ fn validate_withdraw_imbalance( total_liquidity: total_liquidity, profit_sharing_opt: profit_sharing_opt, ) - let slippage_sastified = amount_a_out >= minimum_amount_a - if slippage_sastified { + let slippage_satisfied = amount_a_out >= minimum_amount_a + if slippage_satisfied { let expect_order_value_out = order_in_value |> value.add(ada_policy_id, ada_asset_name, -used_batcher_fee) @@ -962,7 +962,7 @@ pub fn apply_orders( profit_sharing_opt: profit_sharing_opt, pool_state: pool_state, kill_on_failed: order_killable, - is_slippage_sastified: fn(amount_out) { + is_slippage_satisfied: fn(amount_out) { amount_out >= minimum_receive }, ) @@ -989,7 +989,7 @@ pub fn apply_orders( profit_sharing_opt: profit_sharing_opt, pool_state: pool_state, kill_on_failed: order_killable, - is_slippage_sastified: fn(amount_out) { + is_slippage_satisfied: fn(amount_out) { amount_out <= stop_loss_receive }, ) @@ -1023,7 +1023,7 @@ pub fn apply_orders( profit_sharing_opt: profit_sharing_opt, pool_state: pool_state, kill_on_failed: order_killable, - is_slippage_sastified: fn(amount_out) { + is_slippage_satisfied: fn(amount_out) { amount_out >= minimum_receive || amount_out <= stop_loss_receive }, ) diff --git a/lib/amm_dex_v2/pool_validation.ak b/lib/amm_dex_v2/pool_validation.ak index 31af7ad..996c10c 100644 --- a/lib/amm_dex_v2/pool_validation.ak +++ b/lib/amm_dex_v2/pool_validation.ak @@ -412,7 +412,6 @@ pub fn validate_swap_multi_routing( } } -// TODO: We need carefully verify these logic below fn find_multi_routing_pools( authen_policy_id: PolicyId, pool_input_ref: OutputReference, @@ -446,7 +445,7 @@ fn find_multi_routing_pools( }, .. } = own_pool_input - // verify that there's only 2 pools the inputs + // verify that the number of pool's utxo in the inputs must be matched with @pool_len expect list.length( list.filter( @@ -460,7 +459,7 @@ fn find_multi_routing_pools( }, ), ) == pool_len - // verify that there's only 2 pools the outputs + // verify that the number of pool's utxo in the outputs must be matched with @pool_len expect list.length( list.filter( diff --git a/plutus.json b/plutus.json index 69c0ed9..54407b2 100644 --- a/plutus.json +++ b/plutus.json @@ -58,8 +58,8 @@ } } ], - "compiledCode": "590bbc01000032323232323232323223223222232323232533300e3232323253330123370e90011808800899191919191919191919191919191919191919191919191919191919191919191929998199919191919191919299981d99b8f00700313372000a002266e4001c00cdd7181f800981f8011bae303d0013035011375c607600260760046eb8c0e4004c0c403c4c8c94ccc0d4cdc3a40006068002264646464646464646464646464a66608a6090002264a66608666e1cccc0040180fd2201024d5300480084c8c8c8c94ccc128c1340084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1714ccc170cdc80038028a99982e19b900030011533305c3371e00e0682a6660b866e3c0040c854ccc170cdc7814802899b8f02900314a029405280a5014a026464a6660c260c800426464646464646464646464646464646464646464646464a6660ea66e1d200230740011323232323232323232533307e3375e0300b42a6660fc66ebc05816054ccc1f8cdc380a0030a99983f19b870120081533307e3370e02000e2a6660fc0022a6660fc66ebcdd31919800800832112999841808008a5eb7bdb1804c8c8c8c94ccc21004cdc7a44100002100313308801337606ea4008dd3000998030030019bab308501003375c610602004610e02004610a020026e98cccc00ccccc00ccccc00d2f5bded8c00f49101024d5300480081e92201034d535000480081e812d20feffffffffffffffff0113375e6e98008dd300f0a5014a029405280a5014a029414ccc1f4c8c8cc0040052f5bded8c30105000103192710008101030001031903e800810101000102186400112999841808008a50132325333082013375e6e98cc218040092f5bded8c06e98cc218040152f5bded8c029444cc010010004c21c04008c21404004cdd81ba800d375001629444c94ccc20404c2100400454ccc1f8cdc42400001826464a6661000200420022940cdc499b8200d48028cdc1007a4141380266e24cdc10072402866e08031200216163303d06523370e6660786eacc20c04c21004c1f000522011c229013ad3a22d2d051a28e7f9214a32444ecf19998f7bdf0c2849862004881034d53410048008cccc004cccc004cccc004cccc004cccc0052f5bded8c0910100488100482026fb8081401380181301280141e012400c1e1221034d5350004800888894ccc1fccdc3800a40002008264646600200200c44a66610a0200226610c0266ec0dd48031ba60034bd6f7b63009919191929998430099baf3300c00a0024c0103d879800013308a01337606ea4028dd30038028a9998430099b8f00a002132325333088013370e90000008998460099bb03752018611a02610c0200400a200a610c0200264a66610e02a6661140200229445280a60103d87a800013374a900019845809ba60014bd701919800800801112999845808008998460099bb037520166ea00292f5bded8c0264646464a6661180266ebccc04803c00930103d879800013309001337606ea403cdd40070028a9998460099b8f00f00213232533308e013370e90000008998490099bb0375202261260261180200400a200a61180200264a66611a0266e1c005200014c103d87a800013374a900019848809ba80014bd7019b8000100e13309001337606ea4008dd4000998030030019bad308d01003375c611602004611e02004611a020022661140266ec0dd48011ba6001330060060033756610e020066eb8c21404008c22404008c21c04004c8c8008c8cc004004008894ccc2140400452613253330860100114984c8c8c8c8c8c8c94ccc22804cdc3a40000022660140146611c0200c00a2c6110020026601c0040026eb8c2200400cdd7184380801984580801984480801184400801184400800998418099bb037520046ea00052f5bded8c044a6660f866e400080045300103d87980001533307c3371e0040022980103d87a800014c103d87b800033702907f7fffffffffffffff808009919299983d19b8833704002002004266e000052002100153330793371000290000b0a99983c99b870014800052000153330793370e00290010a40042a6660f266e1c00520041480084c8c8ccc00400400c0088894ccc1f4cdc4000801099980180180099b833370066e0c014004005200410023370066e0c005200448008cdc100100099981a80b823822a99983b299983b19b8f04a48810013371e0909110014a0266e0400520809bee0210013330330150490471630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c600464a6660ca66e1d20000011323232323232323232323232323232325333078307b0021323232498c94ccc1e0cdc3a400000226464a6660fa61000200426493191bad307d002375a60f60022c6466ec0c1fc004c1fcc20004004dd6183f000983b0020a99983c19b874800800454ccc1ecc1d801052616163076003306a00e306900f1630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c60042c60c60026602808200260ce00260ce0046eacc194004c194004c17000458c188004cc0701108c8c8c8c8c8c8c94ccc190cdc3a400400226464a6660cc66e3c1800044cdc3999812003031245034d535000480085281bae306a001306200214a060c400260ce00260be0066eacc194004c194008c18c004c16c00458dd7183000098300011bae305e0013056006375c60b800260b80046eb8c168004c148010c124004cc00c0c0010c11c004cc0040b801888c94ccc148cdc3a4008002260ae60a00042a6660a466e1d200200113232330010010052253330580011613232323253330593371e00e004200226600c00c00660b40066eb8c160008c170008c168004dd7182b98280010b1828000982980098298009829000982480298278009827800982700098228018b182580098258011824800998018159191919191919299982519baf00b00113370e66601000608c911024d530048008528182700098230019bab304c001304c002304a00130420011622232323253330483370e90010008a400026eb4c134c118008c118004c94ccc11ccdc3a4004002298103d87a8000132323300100100222533304d00114c103d87a8000132323232533304e3371e014004266e95200033052375000297ae0133006006003375a609e0066eb8c134008c144008c13c004dd598261822801182280099198008008021129998250008a6103d87a8000132323232533304b3371e010004266e9520003304f374c00297ae0133006006003375660980066eb8c128008c138008c13000458cc0040b08cdd780198239820182398201823982418200009119198008008019129998238008a5eb804c8c94ccc118c0140084cc128008cc0100100044cc010010004c12c008c124004c110004c0f000cdd5982100098210011820000981c000981f000981f000981a800981d80098198008b191980080081011299981c8008a60103d87a80001323253330383375e607a606c00404a266e9520003303c0024bd70099802002000981e801181d80099191801198009801198008048039801198008028019119b8a002001237260022c6eb8c0dc004c0dc008dd7181a80098168049bae30330013033002375c6062002605200e6eb8c0bc004c0bc008dd718168009812810181580098158011814800981080d9bab3027001302700130260013025001302400130230013022002375660400026040002603e0046eb0c074004c074004c070008dd6180d0009809002980c00098080008b180b000980b001180a00098060028a4c26cac64a66601c66e1d20000011323232325333015301800213232498c01c008c01800c58c058004c058008c050004c03001858c0300148c94ccc038cdc3a4000002264646464a66602a60300042930b1bae30160013016002375c602800260180042c60180026002008464a66601866e1d200000113232323253330133016002149858dd7180a000980a0011bae3012001300a00216300a001375c0026eb80048c014dd5000918019baa0015734aae7555cf2ab9f5740ae855d11", - "hash": "c19f97923d6f6628637dc0b671c47549d710728cd20c78ca842743c4" + "compiledCode": "590be001000032323232323232323223223222232323232533300e3232323253330123370e90011808800899191919191919191919191919191919191919191919191919191919191919191929998199919191919191919299981d99b8f00700313372000a002266e4001c00cdd7181f800981f8011bae303d0013035011375c607600260760046eb8c0e4004c0c403c4c8c94ccc0d4cdc3a40006068002264646464646464646464646464a66608a6090002264a66608666e1cccc0040180fd2201024d5300480084c8c8c8c94ccc128c1340084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1714ccc170cdc80038028a99982e19b900030011533305c3371e00e0682a6660b866e3c0040c854ccc170cdc7814802899b8f02900314a029405280a5014a026464a6660c260c800426464646464646464646464646464646464646464646464a6660ea66e1d200230740011323232323232323232533307e3375e0300b42a6660fc66ebc05816054ccc1f8cdc380a0030a99983f19b870120081533307e3370e02000e2a6660fc66e2120000081533307e3371090000038a99983f19b884800001854ccc1f800454ccc1f8cdd79ba632330010010642253330830100114bd6f7b63009919191929998420099b8f48900002100313308801337606ea4008dd3000998030030019bab308501003375c610602004610e02004610a020026e98cccc00ccccc00ccccc00d2f5bded8c00f49101024d5300480081e92201034d535000480081e812d20feffffffffffffffff0113375e6e98008dd300f0a5014a029405280a5014a029405280a5014a0a6660fa64646600200297adef6c6110105000103192710008101030001031903e800810101000102186400112999841808008a50132325333082013375e6e98cc218040092f5bded8c06e98cc218040152f5bded8c029444cc010010004c21c04008c21404004cdd81ba800d375001629444c94ccc20404c2100400454ccc1f8cdc42400001826464a6661000200420022940cdc499b8200d48028cdc1007a4141380266e24cdc10072402866e08031200216163303d06523370e6660786eacc20c04c21004c1f000522011c229013ad3a22d2d051a28e7f9214a32444ecf19998f7bdf0c2849862004881034d53410048008cccc004cccc004cccc004cccc004cccc0052f5bded8c0910100488100482026fb8081401380181301280141e012400c1e1221034d5350004800888894ccc1fccdc3800a40002008264646600200200c44a66610a0200226610c0266ec0dd48031ba60034bd6f7b63009919191929998430099baf3300c00a0024c0103d879800013308a01337606ea4028dd30038028a9998430099b8f00a002132325333088013370e90000008998460099bb03752018611a02610c0200400a200a610c0200264a66610e02a6661140200229445280a60103d87a800013374a900019845809ba60014bd701919800800801112999845808008998460099bb037520166ea00292f5bded8c0264646464a6661180266ebccc04803c00930103d879800013309001337606ea403cdd40070028a9998460099b8f00f00213232533308e013370e90000008998490099bb0375202261260261180200400a200a61180200264a66611a0266e1c005200014c103d87a800013374a900019848809ba80014bd7019b8000100e13309001337606ea4008dd4000998030030019bad308d01003375c611602004611e02004611a020022661140266ec0dd48011ba6001330060060033756610e020066eb8c21404008c22404008c21c04004c8c8008c8cc004004008894ccc2140400452613253330860100114984c8c8c8c8c8c8c94ccc22804cdc3a40000022660140146611c0200c00a2c6110020026601c0040026eb8c2200400cdd7184380801984580801984480801184400801184400800998418099bb037520046ea00052f5bded8c044a6660f866e400080045300103d87980001533307c3371e0040022980103d87a800014c103d87b800033702907f7fffffffffffffff808009919299983d19b8833704002002004266e000052002100153330793371000290000b0a99983c99b870014800052000153330793370e00290010a40042a6660f266e1c00520041480084c8c8ccc00400400c0088894ccc1f4cdc4000801099980180180099b833370066e0c014004005200410023370066e0c005200448008cdc100100099981a80b823822a99983b299983b19b8f04a48810013371e0909110014a0266e0400520809bee0210013330330150490471630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c600464a6660ca66e1d20000011323232323232323232323232323232325333078307b0021323232498c94ccc1e0cdc3a400000226464a6660fa61000200426493191bad307d002375a60f60022c6466ec0c1fc004c1fcc20004004dd6183f000983b0020a99983c19b874800800454ccc1ecc1d801052616163076003306a00e306900f1630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c60042c60c60026602808200260ce00260ce0046eacc194004c194004c17000458c188004cc0701108c8c8c8c8c8c8c94ccc190cdc3a400400226464a6660cc66e3c1800044cdc3999812003031245034d535000480085281bae306a001306200214a060c400260ce00260be0066eacc194004c194008c18c004c16c00458dd7183000098300011bae305e0013056006375c60b800260b80046eb8c168004c148010c124004cc00c0c0010c11c004cc0040b801888c94ccc148cdc3a4008002260ae60a00042a6660a466e1d200200113232330010010052253330580011613232323253330593371e00e004200226600c00c00660b40066eb8c160008c170008c168004dd7182b98280010b1828000982980098298009829000982480298278009827800982700098228018b182580098258011824800998018159191919191919299982519baf00b00113370e66601000608c911024d530048008528182700098230019bab304c001304c002304a00130420011622232323253330483370e90010008a400026eb4c134c118008c118004c94ccc11ccdc3a4004002298103d87a8000132323300100100222533304d00114c103d87a8000132323232533304e3371e014004266e95200033052375000297ae0133006006003375a609e0066eb8c134008c144008c13c004dd598261822801182280099198008008021129998250008a6103d87a8000132323232533304b3371e010004266e9520003304f374c00297ae0133006006003375660980066eb8c128008c138008c13000458cc0040b08cdd780198239820182398201823982418200009119198008008019129998238008a5eb804c8c94ccc118c0140084cc128008cc0100100044cc010010004c12c008c124004c110004c0f000cdd5982100098210011820000981c000981f000981f000981a800981d80098198008b191980080081011299981c8008a60103d87a80001323253330383375e607a606c00404a266e9520003303c0024bd70099802002000981e801181d80099191801198009801198008048039801198008028019119b8a002001237260022c6eb8c0dc004c0dc008dd7181a80098168049bae30330013033002375c6062002605200e6eb8c0bc004c0bc008dd718168009812810181580098158011814800981080d9bab3027001302700130260013025001302400130230013022002375660400026040002603e0046eb0c074004c074004c070008dd6180d0009809002980c00098080008b180b000980b001180a00098060028a4c26cac64a66601c66e1d20000011323232325333015301800213232498c01c008c01800c58c058004c058008c050004c03001858c0300148c94ccc038cdc3a4000002264646464a66602a60300042930b1bae30160013016002375c602800260180042c60180026002008464a66601866e1d200000113232323253330133016002149858dd7180a000980a0011bae3012001300a00216300a001375c0026eb80048c014dd5000918019baa0015734aae7555cf2ab9f5740ae855d11", + "hash": "18c824324e6b4fb94bb47e169636f16c230bbb04c18d9bcc216e964b" }, { "title": "order_validator.validate_order", diff --git a/validators/authen_minting_policy.ak b/validators/authen_minting_policy.ak index 17b0897..7b84a42 100644 --- a/validators/authen_minting_policy.ak +++ b/validators/authen_minting_policy.ak @@ -20,7 +20,6 @@ validator( let ScriptContext { transaction, purpose } = context expect Mint(authen_policy_id) = purpose when redeemer is { - // The redeemer can be called once to initialize the whole AMM V2 system CreatePool -> { let Transaction { inputs, mint, redeemers, .. } = transaction // validate that there's a single Factory UTxO in the Transaction Inputs. @@ -61,7 +60,6 @@ validator( policy_id: asset_b_policy_id, asset_name: asset_b_asset_name, } = asset_b - // todo, consider whether we need this logic or not? expect utils.sorted_asset(asset_a, asset_b) let lp_asset_name = utils.compute_lp_asset_name( @@ -75,6 +73,7 @@ validator( lp_asset_name: lp_asset_name, ) } + // The redeemer can be called once to initialize the whole AMM V2 system MintFactoryAuthen -> { let Transaction { inputs, mint, outputs, datums, .. } = transaction diff --git a/validators/factory_validator.ak b/validators/factory_validator.ak index 7bf0a9a..a3326e1 100644 --- a/validators/factory_validator.ak +++ b/validators/factory_validator.ak @@ -222,6 +222,10 @@ validator( // Pool Reserve must be the same between datum and value pool_datum_reserve_a == amount_a, pool_datum_reserve_b == amount_b, + // Initial Pool Reserves and liquditiy must be positive + amount_a > 0, + amount_b > 0, + total_liquidity > 0, // trading_fee_percentage must be between **0.05%** and **10%** is_valid_trading_fee, value.from_minted_value(mint) == pool_validation.get_pool_creation_expected_mint(