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 d2b7bfa..4317096 100644 --- a/lib/amm_dex_v2/math.ak +++ b/lib/amm_dex_v2/math.ak @@ -362,8 +362,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, diff --git a/lib/amm_dex_v2/order_validation.ak b/lib/amm_dex_v2/order_validation.ak index e600262..35c78a0 100644 --- a/lib/amm_dex_v2/order_validation.ak +++ b/lib/amm_dex_v2/order_validation.ak @@ -42,7 +42,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, @@ -98,8 +98,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) @@ -220,8 +220,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) @@ -317,8 +317,8 @@ fn validate_deposit( trading_fee_b_denominator: trading_fee_b_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) @@ -392,11 +392,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) @@ -486,8 +486,8 @@ fn validate_zap_out( trading_fee_b_denominator: trading_fee_b_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) @@ -706,8 +706,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) @@ -1060,7 +1060,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 }, ) @@ -1089,7 +1089,7 @@ pub fn apply_orders( profit_sharing_opt: profit_sharing_opt, pool_state: pool_state, kill_on_failed: False, - is_slippage_sastified: fn(amount_out) { + is_slippage_satisfied: fn(amount_out) { amount_out <= stop_loss_receive }, ) @@ -1119,7 +1119,7 @@ pub fn apply_orders( profit_sharing_opt: profit_sharing_opt, pool_state: pool_state, kill_on_failed: False, - is_slippage_sastified: fn(amount_out) { + is_slippage_satisfied: fn(amount_out) { amount_out >= minimum_receive || amount_out <= stop_loss_receive }, ) diff --git a/plutus.json b/plutus.json index cc3622f..462cc16 100644 --- a/plutus.json +++ b/plutus.json @@ -64,8 +64,8 @@ } } ], - "compiledCode": "590ca1010000323232323232323232232232222232323232533300f3232323253330133370e900118090008991919191919191919191919191919191919191919191919191929998169919191919191919299981a99b8f00700313372000a002266e4001c00cdd7181c800981c8011bae3037001302f011375c606a002606a0046eb8c0cc004c0ac03c4c8c94ccc0bccdc3a4000605c002264646464646464646464646464a66607e6084002264a66607a66e1cccc0040180e5221024d5300480084c8c8c8c94ccc110c11c0084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1594ccc158cdc80038028a99982b19b90003001153330563371e00e0682a6660ac66e3c0040c854ccc158cdc7814802899b8f02900314a029405280a5014a026464a6660b660bc0042646464646464646464646464646464646464646464646464646464646464646464646464646464a6660fea6660fe66e1c04c03c4cdc38088068a501325333080013375e0400f22a6661000266ebc07818854ccc20004cdd780e0300a9998400099b8701a00615333080013370e0300102a6661000266e1c05801c54ccc2000400454ccc200054ccc20004028528099984000a504a094454ccc20004cdd780626103d87a800015333080013375e6e98c8cc004004194894ccc2140400452f5bded8c0264646464a66610c0266e3d220100002100313308a01337606ea4008dd3000998030030019bab308701003375c610a02004611202004610e020026e98cccc00ccccc00ccccc00d2f5bded8c00f89101024d5300480081f12201034d535000480081f014d20feffffffffffffffff0113375e6e98008dd30130a5014a029405280a5014a029405280a5014a0a6660fe64646600200297adef6c6110105000103192710008101030001031903e800810101000102186400112999842808008a50132325333084013375e6e98cc220040092f5bded8c06e98cc220040152f5bded8c029444cc010010004c22404008c21c04004cdd81ba8013375002229444c94ccc20c04c2180400454ccc20004cdc4240000242a6661000266e24cdc100a2402866e08049200213371266e08049200a3370402890504e008a5014a02c6608a0cc466e1cccc110dd5984280984300983f000a451c229013ad3a22d2d051a28e7f9214a32444ecf19998f7bdf0c2849862004881034d5341004800858cccc004cccc004cccc004cccc004cccc0052f5bded8c0910100488100482026fb8081601580181501480141e814400c1e9221034d5350004800888894ccc20404cdc3800a40002008264646600200200c44a66610e020022661100266ec0dd48031ba60034bd6f7b63009919191929998440099baf3300c00a0024c0103d879800013308c01337606ea4028dd30038028a9998440099b8f00a00213232533308a013370e90000008998470099bb03752018611e0261100200400a200a61100200264a66611202a6661180200229445280a60103d87a800013374a900019846809ba60014bd701919800800801112999846808008998470099bb037520166ea00292f5bded8c0264646464a66611c0266ebccc04803c00930103d879800013309201337606ea403cdd40070028a9998470099b8f00f002132325333090013370e900000089984a0099bb03752022612a02611c0200400a200a611c0200264a66611e0266e1c005200014c103d87a800013374a900019849809ba80014bd7019b8000100e13309201337606ea4008dd4000998030030019bad308f01003375c611a02004612202004611e020022661180266ec0dd48011ba60013300600600337566112020066eb8c21c04008c22c04008c22404004c8c8008c8cc004004008894ccc21c0400452613253330880100114984c8c8c8c8c8c8c94ccc23004cdc3a4000002266014014661200200c00a2c6114020026601c0040026eb8c2280400cdd7184480801984680801984580801184500801184500800998428099bb037520046ea00052f5bded8c044a6660fc66e400080045300103d87980001533307e3371e0040022980103d87a800014c103d87b800033702907f7fffffffffffffff808009919299983e19b8833704002002004266e0000520021001533307b3371000290000b0a99983d99b8700148000520001533307b3370e00290010a40042a6660f666e1c00520041480084c8c8ccc00400400c0088894ccc1fccdc4000801099980180180099b833370066e0c014004005200410023370066e0c005200448008cdc100100099981e80f827826a99983c299983c19b8f05248810013371e0a09110014a0266e0400520809bee02100133303b01d05104f3370e9001183b9baa307b001307b00230790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de0046eb4c1b4004c1b4008dd69835800983580118348009834801183380098338011832800982e80119299982f99b87480000044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1e8c1f40084c8c8c8c92632533307b3370e90000008991929998400098418080109924c646eb4c20004008dd6983f0008b1919bb0308201001308201308301001375861020200260f200e2a6660f666e1d20020011533307e307900714985858c1e4018c1b0054c1ac058c94ccc1e0cdc3a400000226464a6660fa6100020042649319299983d99b87480000044c8c94ccc20004c20c0400852616375c61020200260f20042a6660f666e1d200200113232533308001308301002149858dd7184080800983c8010b183c8008b183f000983b00c0a99983c19b87480080044c8c8c8c8c8c94ccc20404c2100400852616375a6104020026104020046eb4c20004004c20004008dd6983f000983b00c0b183b00b8b19b8748008c1dcdd5183d800983d801183c800983c8011bad30770013077002375a60ea00260ea0046eb4c1cc004c1cc008dd6983880098388011bad306f001306f002375a60da00260da0046eb4c1ac004c1ac008c1a4004c1a4008c19c004c19c008c194004c17400858c174004c050004c184004c184008dd5982f800982f800982b0008b182e0009980e01e919191919191919299982f19b87480080044c8c94ccc180cdc782d000899b8733302400605c4881034d535000480085281bae3064001305c00214a060b800260c200260b20066eacc17c004c17c008c174004c15400458dd7182d000982d0011bae30580013050006375c60ac00260ac0046eb8c150004c130010c108004c00c010c100004c0040188c94ccc12ccdc3a4008002260a060920042c6092002609a002609a0026098002608600a609200260920026090002607e0062c608a002608a0046086002660060484646464646464a66608866ebc02c0044cdc39998040018202441024d530048008528182400098200019bab304600130460023044001303c0011622232323253330423370e90010008a400026eb4c11cc100008c100004c94ccc104cdc3a4004002298103d87a8000132323300100100222533304700114c103d87a800013232323253330483371e014004266e9520003304c375000297ae0133006006003375a60920066eb8c11c008c12c008c124004dd59823181f801181f80099198008008021129998220008a6103d87a800013232323253330453371e010004266e95200033049374c00297ae01330060060033756608c0066eb8c110008c120008c11800458cc0040948cdd78019820981d1820981d18209821181d0009119198008008019129998208008a5eb804c8c94ccc100c0140084cc110008cc0100100044cc010010004c114008c10c004c0f8004c0d800cdd5981e000981e001181d0009819000981c000981c0009817800981a80098168008b191980080080c9129998198008a60103d87a80001323253330323375e606e606000403c266e952000330360024bd70099802002000981b801181a80099191801198009801198008048039801198008028019119b8a002001237260022c6eb8c0c4004c0c4008dd7181780098138049bae302d001302d002375c6056002604600e6eb8c0a4004c0a4008dd71813800980f80c981280098128011811800980d80a1bab3021001302100130200023758603c002603c002603a0046eb0c06c004c04c014c064004c04400458c05c004c05c008c054004c0340145261365632533300f3370e9000000899191919299980b180c8010991924c600e004600c0062c602e002602e004602a002601a00c2c601a00a464a66601e66e1d200000113232323253330163019002149858dd7180b800980b8011bae3015001300d00216300d0013001004232533300d3370e9000000899191919299980a180b8010a4c2c6eb8c054004c054008dd7180980098058010b18058009bae001375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "1e59d3693711b222d24821cc562b64605949ca666a369c02bbd189b7" + "compiledCode": "590cc9010000323232323232323232232232222232323232533300f3232323253330133370e900118090008991919191919191919191919191919191919191919191919191929998169919191919191919299981a99b8f00700313372000a002266e4001c00cdd7181c800981c8011bae3037001302f011375c606a002606a0046eb8c0cc004c0ac03c4c8c94ccc0bccdc3a4000605c002264646464646464646464646464a66607e6084002264a66607a66e1cccc0040180e5221024d5300480084c8c8c8c94ccc110c11c0084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1594ccc158cdc80038028a99982b19b90003001153330563371e00e0682a6660ac66e3c0040c854ccc158cdc7814802899b8f02900314a029405280a5014a026464a6660b660bc0042646464646464646464646464646464646464646464646464646464646464646464646464646464a6660fea6660fe66e1c04c03c4cdc38088068a501325333080013375e0400f22a6661000266ebc07818854ccc20004cdd780e0300a9998400099b8701a00615333080013370e0300102a6661000266e1c05801c54ccc20004cdc4240000102a6661000266e21200000715333080013371090000030a999840008008a99984000a999840008050a501333080014a0941288a9998400099baf00c4c0103d87a800015333080013375e6e98c8cc004004194894ccc2140400452f5bded8c0264646464a66610c0266e3d220100002100313308a01337606ea4008dd3000998030030019bab308701003375c610a02004611202004610e020026e98cccc00ccccc00ccccc00d2f5bded8c00f89101024d5300480081f12201034d535000480081f014d20feffffffffffffffff0113375e6e98008dd30130a5014a029405280a5014a029405280a5014a029405280a50533307f3232330010014bd6f7b630810105000103192710008101030001031903e800810101000102186400112999842808008a50132325333084013375e6e98cc220040092f5bded8c06e98cc220040152f5bded8c029444cc010010004c22404008c21c04004cdd81ba8013375002229444c94ccc20c04c2180400454ccc20004cdc4240000242a6661000266e24cdc100a2402866e08049200213371266e08049200a3370402890504e008a5014a02c6608a0cc466e1cccc110dd5984280984300983f000a451c229013ad3a22d2d051a28e7f9214a32444ecf19998f7bdf0c2849862004881034d5341004800858cccc004cccc004cccc004cccc004cccc0052f5bded8c0910100488100482026fb8081601580181501480141e814400c1e9221034d5350004800888894ccc20404cdc3800a40002008264646600200200c44a66610e020022661100266ec0dd48031ba60034bd6f7b63009919191929998440099baf3300c00a0024c0103d879800013308c01337606ea4028dd30038028a9998440099b8f00a00213232533308a013370e90000008998470099bb03752018611e0261100200400a200a61100200264a66611202a6661180200229445280a60103d87a800013374a900019846809ba60014bd701919800800801112999846808008998470099bb037520166ea00292f5bded8c0264646464a66611c0266ebccc04803c00930103d879800013309201337606ea403cdd40070028a9998470099b8f00f002132325333090013370e900000089984a0099bb03752022612a02611c0200400a200a611c0200264a66611e0266e1c005200014c103d87a800013374a900019849809ba80014bd7019b8000100e13309201337606ea4008dd4000998030030019bad308f01003375c611a02004612202004611e020022661180266ec0dd48011ba60013300600600337566112020066eb8c21c04008c22c04008c22404004c8c8008c8cc004004008894ccc21c0400452613253330880100114984c8c8c8c8c8c8c94ccc23004cdc3a4000002266014014661200200c00a2c6114020026601c0040026eb8c2280400cdd7184480801984680801984580801184500801184500800998428099bb037520046ea00052f5bded8c044a6660fc66e400080045300103d87980001533307e3371e0040022980103d87a800014c103d87b800033702907f7fffffffffffffff808009919299983e19b8833704002002004266e0000520021001533307b3371000290000b0a99983d99b8700148000520001533307b3370e00290010a40042a6660f666e1c00520041480084c8c8ccc00400400c0088894ccc1fccdc4000801099980180180099b833370066e0c014004005200410023370066e0c005200448008cdc100100099981e80f827826a99983c299983c19b8f05248810013371e0a09110014a0266e0400520809bee02100133303b01d05104f3370e9001183b9baa307b001307b00230790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de0046eb4c1b4004c1b4008dd69835800983580118348009834801183380098338011832800982e80119299982f99b87480000044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1e8c1f40084c8c8c8c92632533307b3370e90000008991929998400098418080109924c646eb4c20004008dd6983f0008b1919bb0308201001308201308301001375861020200260f200e2a6660f666e1d20020011533307e307900714985858c1e4018c1b0054c1ac058c94ccc1e0cdc3a400000226464a6660fa6100020042649319299983d99b87480000044c8c94ccc20004c20c0400852616375c61020200260f20042a6660f666e1d200200113232533308001308301002149858dd7184080800983c8010b183c8008b183f000983b00c0a99983c19b87480080044c8c8c8c8c8c94ccc20404c2100400852616375a6104020026104020046eb4c20004004c20004008dd6983f000983b00c0b183b00b8b19b8748008c1dcdd5183d800983d801183c800983c8011bad30770013077002375a60ea00260ea0046eb4c1cc004c1cc008dd6983880098388011bad306f001306f002375a60da00260da0046eb4c1ac004c1ac008c1a4004c1a4008c19c004c19c008c194004c17400858c174004c050004c184004c184008dd5982f800982f800982b0008b182e0009980e01e919191919191919299982f19b87480080044c8c94ccc180cdc782d000899b8733302400605c4881034d535000480085281bae3064001305c00214a060b800260c200260b20066eacc17c004c17c008c174004c15400458dd7182d000982d0011bae30580013050006375c60ac00260ac0046eb8c150004c130010c108004c00c010c100004c0040188c94ccc12ccdc3a4008002260a060920042c6092002609a002609a0026098002608600a609200260920026090002607e0062c608a002608a0046086002660060484646464646464a66608866ebc02c0044cdc39998040018202441024d530048008528182400098200019bab304600130460023044001303c0011622232323253330423370e90010008a400026eb4c11cc100008c100004c94ccc104cdc3a4004002298103d87a8000132323300100100222533304700114c103d87a800013232323253330483371e014004266e9520003304c375000297ae0133006006003375a60920066eb8c11c008c12c008c124004dd59823181f801181f80099198008008021129998220008a6103d87a800013232323253330453371e010004266e95200033049374c00297ae01330060060033756608c0066eb8c110008c120008c11800458cc0040948cdd78019820981d1820981d18209821181d0009119198008008019129998208008a5eb804c8c94ccc100c0140084cc110008cc0100100044cc010010004c114008c10c004c0f8004c0d800cdd5981e000981e001181d0009819000981c000981c0009817800981a80098168008b191980080080c9129998198008a60103d87a80001323253330323375e606e606000403c266e952000330360024bd70099802002000981b801181a80099191801198009801198008048039801198008028019119b8a002001237260022c6eb8c0c4004c0c4008dd7181780098138049bae302d001302d002375c6056002604600e6eb8c0a4004c0a4008dd71813800980f80c981280098128011811800980d80a1bab3021001302100130200023758603c002603c002603a0046eb0c06c004c04c014c064004c04400458c05c004c05c008c054004c0340145261365632533300f3370e9000000899191919299980b180c8010991924c600e004600c0062c602e002602e004602a002601a00c2c601a00a464a66601e66e1d200000113232323253330163019002149858dd7180b800980b8011bae3015001300d00216300d0013001004232533300d3370e9000000899191919299980a180b8010a4c2c6eb8c054004c054008dd7180980098058010b18058009bae001375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", + "hash": "96ac8583651b71682fdb6422cd9abd927c000429a3172e5dffeac47d" }, { "title": "order_validator.validate_expired_order_cancel", diff --git a/validators/authen_minting_policy.ak b/validators/authen_minting_policy.ak index 1a76c62..5f42ed9 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, .. } = transaction diff --git a/validators/factory_validator.ak b/validators/factory_validator.ak index 5232d75..5f988b3 100644 --- a/validators/factory_validator.ak +++ b/validators/factory_validator.ak @@ -238,6 +238,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, // Dynamic Fee is not allowed in Pool Creation