From 66aa37cd813192af547654e7f7d1db6359ed83c7 Mon Sep 17 00:00:00 2001 From: Richard Nguyen Date: Fri, 12 Jan 2024 15:48:24 +0700 Subject: [PATCH 1/2] use Withdrawal script to validate cancel expired orders tx --- lib/amm_dex_v2/order_validation.ak | 319 ----------------------------- plutus.json | 23 ++- validators/order_validator.ak | 162 ++++++++------- 3 files changed, 105 insertions(+), 399 deletions(-) diff --git a/lib/amm_dex_v2/order_validation.ak b/lib/amm_dex_v2/order_validation.ak index 9c74c64..b4564fa 100644 --- a/lib/amm_dex_v2/order_validation.ak +++ b/lib/amm_dex_v2/order_validation.ak @@ -1295,325 +1295,6 @@ pub fn apply_orders( } } -// test test_validate_swap_exact_in_with_no_fee_sharing() { -// let asset_a = Asset { policy_id: ada_policy_id, asset_name: ada_asset_name } -// let asset_b = -// Asset { -// policy_id: #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// asset_name: #"4d494e", -// } -// let sender = -// credential.from_verification_key( -// #"84b1e6990b172a07ca85d479b0708e750a98d32d13ad61887c010b78", -// ) -// let receiver = -// credential.from_verification_key( -// #"830335f3c2fe6c96b61ee835face48ea0c658e877ac4c81a6a284fb0", -// ) -// let max_batcher_fee = 2000000 -// let output_ada = 2000000 -// let amount_in = 1000000000 -// let amount_out = 14834146387 -// let order_in_value = -// value.zero() -// |> value.add( -// ada_policy_id, -// ada_asset_name, -// max_batcher_fee + output_ada + amount_in, -// ) -// let order_out_value = -// value.zero() -// |> value.add(ada_policy_id, ada_asset_name, output_ada) -// |> value.add( -// #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// #"4d494e", -// amount_out, -// ) -// let order_output = -// Output { -// address: receiver, -// value: order_out_value, -// datum: NoDatum, -// reference_script: None, -// } -// let new_pool_state = -// validate_swap_exact_in( -// order_in_value: order_in_value, -// order_output: order_output, -// sender: sender, -// sender_datum_hash_opt: None, -// receiver: receiver, -// receiver_datum_hash_opt: None, -// a_to_b_direction: True, -// asset_a: asset_a, -// asset_b: asset_b, -// max_batcher_fee: max_batcher_fee, -// used_batcher_fee: max_batcher_fee, -// output_ada: output_ada, -// trading_fee_numerator: 3, -// trading_fee_denominator: 1000, -// profit_sharing_opt: None, -// kill_on_failed: False, -// pool_state: ( -// 27877961987941, -// 414804973691450, -// 27877961987941, -// 414804973691450, -// 106241703280080, -// ), -// is_slippage_sastified: fn(o) { o > 1 }, -// ) -// // let fee_share = amount_in * 3 / ( 1000 * 6 ) -// new_pool_state == ( -// 27878961987941, -// 414790139545063, -// 27878961987941, -// 414790139545063, -// 106241703280080, -// ) -// } - -// test test_validate_swap_exact_in_with_fee_sharing() { -// let asset_a = Asset { policy_id: ada_policy_id, asset_name: ada_asset_name } -// let asset_b = -// Asset { -// policy_id: #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// asset_name: #"4d494e", -// } -// let sender = -// credential.from_verification_key( -// #"84b1e6990b172a07ca85d479b0708e750a98d32d13ad61887c010b78", -// ) -// let receiver = -// credential.from_verification_key( -// #"830335f3c2fe6c96b61ee835face48ea0c658e877ac4c81a6a284fb0", -// ) -// let max_batcher_fee = 2000000 -// let output_ada = 2000000 -// let amount_in = 1000000000 -// let amount_out = 16200168971 -// let order_in_value = -// value.zero() -// |> value.add( -// ada_policy_id, -// ada_asset_name, -// max_batcher_fee + output_ada + amount_in, -// ) -// let order_out_value = -// value.zero() -// |> value.add(ada_policy_id, ada_asset_name, output_ada) -// |> value.add( -// #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// #"4d494e", -// amount_out, -// ) -// let order_output = -// Output { -// address: receiver, -// value: order_out_value, -// datum: NoDatum, -// reference_script: None, -// } -// let new_pool_state = -// validate_swap_exact_in( -// order_in_value: order_in_value, -// order_output: order_output, -// sender: sender, -// sender_datum_hash_opt: None, -// receiver: receiver, -// receiver_datum_hash_opt: None, -// a_to_b_direction: True, -// asset_a: asset_a, -// asset_b: asset_b, -// max_batcher_fee: max_batcher_fee, -// used_batcher_fee: max_batcher_fee, -// output_ada: output_ada, -// trading_fee_numerator: 3, -// trading_fee_denominator: 1000, -// profit_sharing_opt: Some((1, 6)), -// kill_on_failed: False, -// pool_state: ( -// 25434557769208, -// 413300185707175, -// 25434557769208, -// 413300185707175, -// 101211362398220, -// ), -// is_slippage_sastified: fn(o) { o > 1 }, -// ) -// let fee_share = amount_in * 3 / ( 1000 * 6 ) -// new_pool_state == ( -// 25434557769208 + amount_in - fee_share, -// 413300185707175 - amount_out, -// 25434557769208 + amount_in, -// 413300185707175 - amount_out, -// 101211362398220, -// ) -// } - -// test test_validate_swap_multi_routing_order() { -// let pool_1_asset_a = -// Asset { policy_id: ada_policy_id, asset_name: ada_asset_name } -// let pool_1_asset_b = -// Asset { -// policy_id: #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// asset_name: #"4d494e", -// } -// let pool_1_lp_asset = -// Asset { -// policy_id: #"1a919d30617fcbc8a92c337c59c3aecb6c4ded8f154e4c24528ccea2", -// asset_name: #"6c3ea488e6ff940bb6fb1b18fd605b5931d9fefde6440117015ba484cf321200", -// } -// let pool_1_pool_state_in = -// ( -// 27877961987941, -// 414804973691450, -// 27877961987941, -// 414804973691450, -// 106241703280080, -// ) - -// let pool_1_pool_state_out = -// ( -// 27871263020717, -// 414904973691450, -// 27871263020717, -// 414904973691450, -// 106241703280080, -// ) - -// let pool1 = -// BatchingPool { -// asset_a: pool_1_asset_a, -// asset_b: pool_1_asset_b, -// lp_asset: pool_1_lp_asset, -// trading_fee_numerator: 3, -// trading_fee_denominator: 1000, -// profit_sharing: None, -// order_hash: #"6dc232f0f5832da2070a232ad2f58433883b9a277577048b40d17673", -// address: credential.from_script( -// #"11f3fb05033cb08e95f5c6d4b11891003dc762a46828a4b6f164efe2", -// ), -// pool_state_in: pool_1_pool_state_in, -// pool_state_out: pool_1_pool_state_out, -// } -// let pool_2_asset_a = -// Asset { policy_id: ada_policy_id, asset_name: ada_asset_name } -// let pool_2_asset_b = -// Asset { -// policy_id: #"f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880", -// asset_name: #"69555344", -// } -// let pool_2_lp_asset = -// Asset { -// policy_id: #"1a919d30617fcbc8a92c337c59c3aecb6c4ded8f154e4c24528ccea2", -// asset_name: #"452089abb5bf8cc59b678a2cd7b9ee952346c6c0aa1cf27df324310a70d02fc3", -// } -// let pool_2_pool_state_in = -// (5281584632864, 1432277778019, 5281584632864, 1432277778019, 2450077671602) -// let pool_2_pool_state_out = -// (5288283600088, 1430468867110, 5288283600088, 1430468867110, 2450077671602) -// let pool2 = -// BatchingPool { -// asset_a: pool_2_asset_a, -// asset_b: pool_2_asset_b, -// lp_asset: pool_2_lp_asset, -// trading_fee_numerator: 3, -// trading_fee_denominator: 1000, -// profit_sharing: None, -// order_hash: #"6dc232f0f5832da2070a232ad2f58433883b9a277577048b40d17673", -// address: credential.from_script( -// #"11f3fb05033cb08e95f5c6d4b11891003dc762a46828a4b6f164efe2", -// ), -// pool_state_in: pool_2_pool_state_in, -// pool_state_out: pool_2_pool_state_out, -// } -// let pools = -// [pool1, pool2] -// let routing1 = -// SwapRouting { lp_asset: pool_1_lp_asset, a_to_b_direction: False } -// let routing2 = -// SwapRouting { lp_asset: pool_2_lp_asset, a_to_b_direction: True } -// let routings = -// [routing1, routing2] -// let amount_out = -// get_swap_multi_amount_out( -// amount_in: 100000000000, -// all_pools: pools, -// all_routings: routings, -// ) -// amount_out == 1808910909 -// } - -// test test_validate_deposit() { -// let asset_a = Asset { policy_id: ada_policy_id, asset_name: ada_asset_name } -// let asset_b = -// Asset { -// policy_id: #"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72", -// asset_name: #"4d494e", -// } -// let lp_asset = -// Asset { -// policy_id: #"51eee5fe126a1337497dd4d0a43efb31c9f791436b74472a4fc4536a", -// asset_name: #"6c3ea488e6ff940bb6fb1b18fd605b5931d9fefde6440117015ba484cf321200", -// } -// let sender = -// credential.from_verification_key( -// #"84b1e6990b172a07ca85d479b0708e750a98d32d13ad61887c010b78", -// ) -// let receiver = -// credential.from_verification_key( -// #"830335f3c2fe6c96b61ee835face48ea0c658e877ac4c81a6a284fb0", -// ) -// let max_batcher_fee = 2000000 -// let output_ada = 2000000 -// let amount_a = 1000000 -// let amount_b = 123112 -// let amount_out = 867556 -// let order_in_value = -// value.zero() -// |> value.add( -// ada_policy_id, -// ada_asset_name, -// max_batcher_fee + output_ada + amount_a, -// ) -// |> value.add(asset_b.policy_id, asset_b.asset_name, amount_b) -// let order_out_value = -// value.zero() -// |> value.add(ada_policy_id, ada_asset_name, output_ada) -// |> value.add(lp_asset.policy_id, lp_asset.asset_name, amount_out) -// let order_output = -// Output { -// address: receiver, -// value: order_out_value, -// datum: NoDatum, -// reference_script: None, -// } -// let new_pool_state = -// validate_deposit( -// order_in_value: order_in_value, -// order_output: order_output, -// sender: sender, -// sender_datum_hash_opt: None, -// receiver: receiver, -// receiver_datum_hash_opt: None, -// minimum_lp: amount_out, -// asset_a: asset_a, -// asset_b: asset_b, -// lp_asset: lp_asset, -// max_batcher_fee: max_batcher_fee, -// used_batcher_fee: max_batcher_fee, -// output_ada: output_ada, -// trading_fee_numerator: 1, -// trading_fee_denominator: 100, -// profit_sharing_opt: None, -// kill_on_failed: False, -// pool_state: (1000000, 4000000, 1000000, 4000000, 2000000), -// ) -// new_pool_state == (2000000, 4123112, 2000000, 4123112, 2867556) -// } - -// TODO: Need to rework later pub fn validate_cancel_expired_orders( order_inputs: List, all_outputs: List, diff --git a/plutus.json b/plutus.json index d136b30..b3c8ade 100644 --- a/plutus.json +++ b/plutus.json @@ -61,6 +61,17 @@ "compiledCode": "590bb001000032323232323232323223223222232323232533300e3232323253330123370e90011808800899191919191919191919191919191919191919191919191919191919191919191929998199919191919191919299981d99b8f00700313372000a002266e4001c00cdd7181f800981f8011bae303d0013035011375c607600260760046eb8c0e4004c0c403c4c8c94ccc0d4cdc3a40006068002264646464646464646464646464a66608a6090002264a66608666e1cccc0040180fd2201024d5300480084c8c8c8c94ccc128c1340084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc1714ccc170cdc80038028a99982e19b900030011533305c3371e00e0682a6660b866e3c0040c854ccc170cdc7814802899b8f02900314a029405280a5014a026464a6660c260c800426464646464646464646464646464646464646464646464a6660ea66e1d200230740011323232323232323232533307e3375e0300b42a6660fc66ebc05816054ccc1f8cdc380a0030a99983f19b870120081533307e3370e02000e2a6660fc0022a6660fc66ebcdd31919800800832112999841808008a5eb7bdb1804c8c8c8c94ccc21004cdc7a44100002100313308801337606ea4008dd3000998030030019bab308501003375c610602004610e02004610a020026e98cccc00ccccc00ccccc00d2f5bded8c00f49101024d5300480081e92201034d535000480081e812d20feffffffffffffffff0113375e6e98008dd300f0a5014a029405280a5014a029414ccc1f4c8c8cc0040052f5bded8c30105000103192710008101030001031903e800810101000102186400112999841808008a50132325333082013375e6e98cc218040092f5bded8c06e98cc218040152f5bded8c029444cc010010004c21c04008c21404004cdd81ba800d375001629444c94ccc20404c210040044c8c94ccc20004008400452819b893370401a900519b8200f482827004cdc499b8200e48050cdc1006240042c6607a0ca466e1cccc0f0dd5984180984200983e000a451c229013ad3a22d2d051a28e7f9214a32444ecf19998f7bdf0c2849862004881034d53410048008cccc004cccc004cccc004cccc004cccc0052f5bded8c0910100488100482026fb8081401380181301280141e012400c1e1221034d5350004800888894ccc1fccdc3800a40002008264646600200200c44a66610a0200226610c0266ec0dd48031ba60034bd6f7b63009919191929998430099baf3300c00a0024c0103d879800013308a01337606ea4028dd30038028a9998430099b8f00a002132325333088013370e90000008998460099bb03752018611a02610c0200400a200a610c0200264a66610e02a6661140200229445280a60103d87a800013374a900019845809ba60014bd701919800800801112999845808008998460099bb037520166ea00292f5bded8c0264646464a6661180266ebccc04803c00930103d879800013309001337606ea403cdd40070028a9998460099b8f00f00213232533308e013370e90000008998490099bb0375202261260261180200400a200a61180200264a66611a0266e1c005200014c103d87a800013374a900019848809ba80014bd7019b8000100e13309001337606ea4008dd4000998030030019bad308d01003375c611602004611e02004611a020022661140266ec0dd48011ba6001330060060033756610e020066eb8c21404008c22404008c21c04004c8c8008c8cc004004008894ccc2140400452613253330860100114984c8c8c8c8c8c8c94ccc22804cdc3a40000022660140146611c0200c00a2c6110020026601c0040026eb8c2200400cdd7184380801984580801984480801184400801184400800998418099bb037520046ea00052f5bded8c044a6660f866e400080045300103d87980001533307c3371e0040022980103d87a800014c103d87b800033702907f7fffffffffffffff808009919299983d19b8833704002002004266e000052002100153330793371000290000b0a99983c99b870014800052000153330793370e00290010a40042a6660f266e1c00520041480084c8c8ccc00400400c0088894ccc1f4cdc4000801099980180180099b833370066e0c014004005200410023370066e0c005200448008cdc100100099981a80b823822a99983b299983b19b8f04a48810013371e0909110014a0266e0400520809bee0210013330330150490471630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c600464a6660ca66e1d20000011323232323232323232323232323232325333078307b0021323232498c94ccc1e0cdc3a400000226464a6660fa61000200426493191bad307d002375a60f60022c6466ec0c1fc004c1fcc20004004dd6183f000983b0020a99983c19b874800800454ccc1ecc1d801052616163076003306a00e306900f1630790013079002375a60ee00260ee0046eb4c1d4004c1d4008dd6983980098398011bad30710013071002375a60de00260de00460da00260da00460d600260c60042c60c60026602808200260ce00260ce0046eacc194004c194004c17000458c188004cc0701108c8c8c8c8c8c8c94ccc190cdc3a400400226464a6660cc66e3c1800044cdc3999812003031245034d535000480085281bae306a001306200214a060c400260ce00260be0066eacc194004c194008c18c004c16c00458dd7183000098300011bae305e0013056006375c60b800260b80046eb8c168004c148010c124004cc00c0c0010c11c004cc0040b801888c94ccc148cdc3a4008002260ae60a00042a6660a466e1d200200113232330010010052253330580011613232323253330593371e00e004200226600c00c00660b40066eb8c160008c170008c168004dd7182b98280010b1828000982980098298009829000982480298278009827800982700098228018b182580098258011824800998018159191919191919299982519baf00b00113370e66601000608c911024d530048008528182700098230019bab304c001304c002304a00130420011622232323253330483370e90010008a400026eb4c134c118008c118004c94ccc11ccdc3a4004002298103d87a8000132323300100100222533304d00114c103d87a8000132323232533304e3371e014004266e95200033052375000297ae0133006006003375a609e0066eb8c134008c144008c13c004dd598261822801182280099198008008021129998250008a6103d87a8000132323232533304b3371e010004266e9520003304f374c00297ae0133006006003375660980066eb8c128008c138008c13000458cc0040b08cdd780198239820182398201823982418200009119198008008019129998238008a5eb804c8c94ccc118c0140084cc128008cc0100100044cc010010004c12c008c124004c110004c0f000cdd5982100098210011820000981c000981f000981f000981a800981d80098198008b191980080081011299981c8008a60103d87a80001323253330383375e607a606c00404a266e9520003303c0024bd70099802002000981e801181d80099191801198009801198008048039801198008028019119b8a002001237260022c6eb8c0dc004c0dc008dd7181a80098168049bae30330013033002375c6062002605200e6eb8c0bc004c0bc008dd718168009812810181580098158011814800981080d9bab3027001302700130260013025001302400130230013022002375660400026040002603e0046eb0c074004c074004c070008dd6180d0009809002980c00098080008b180b000980b001180a00098060028a4c26cac64a66601c66e1d20000011323232325333015301800213232498c01c008c01800c58c058004c058008c050004c03001858c0300148c94ccc038cdc3a4000002264646464a66602a60300042930b1bae30160013016002375c602800260180042c60180026002008464a66601866e1d200000113232323253330133016002149858dd7180a000980a0011bae3012001300a00216300a001375c0026eb80048c014dd5000918019baa0015734aae7555cf2ab9f5740ae855d11", "hash": "ebcbbb0f4e4238548fc3ca3b382189b9a420d0a20f5aa2c489a0d635" }, + { + "title": "order_validator.validate_expired_order_cancelling", + "redeemer": { + "title": "_raw_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "590a8b0100003232323232323232322253330053232323253330093370e90021804000899191919191919191919191919191919191919191919299980fa99980f99b8700233702646600200201244a66604800229000099b8048008cc008008c09c00520021533301f337120040022646600200201244a66604800229444c8c94ccc08cc8c8c94ccc098cdc3a400400226466ebc00d30103d87b80003253330273370e90000008a99981518128018a4c2c2a66604e66e1d20020011533302a302500314985854ccc09ccdc3a40080022a666054604a0062930b0b18128010a5130240023026003302400213300400400114a06050004604c0022940528099191919299981199b8748008c0880044c8c8c8c8c8c8c8c8c8ccc004004048078888c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc134cdc3a40006098002264646464a6660a2a6660a266e200080b454ccc144cdd780700b0a99982899b8933702605003400260500282a6660a266ebcdd3181380a1ba6302701a13375e64a6660a466e1d200000114c0103d87a8000153330523370e9001000899ba548000cc158c15cc14004d2f5c0266e9520003305637526e50dd9982b9828009a5eb80c1400480305280a5014a0294054ccc144cdd79ba70224c101800014a2266604c04c0440402c6eb4c148008dd698280009919bb0305400130543055001375860a600260960022c60a200260a200260a0002609e002609c002609a0026098004609400260940046090002608000464a66608466e1d200000113232323232323232323232323232323253330553058002132323232323232498c94ccc164cdc3a400000226464a6660bc60c200426493191bad305e002375a60b80022c6466ec0c180004c180c184004dd6182f800982b8040a99982c99b874800800454ccc170c15c020526161630570073253330583370e900000089919191919191919299983198330010a4c2c66e1d20023060375460c800260c80046eb4c188004c188008dd69830000983000119b8748008c168dd5182f000982b0058a99982c19b87480080044c8c8c8c8c8c8c8c94ccc18cc198008526163370e900118301baa30640013064002375a60c400260c40046eb4c180004c180008cdc3a400460b46ea8c178004c15802c54ccc160cdc3a4008002264646464646464646464a6660ca60d00042930b19b8748008c188dd5183300098330011bad30640013064002375a60c400260c40046eb4c180004c180008cdc3a400460b46ea8c178004c15802c54ccc160cdc3a400c00226464646464646464a6660c660cc0042930b19b8748008c180dd5183200098320011bad30620013062002375a60c000260c000466e1d2002305a375460bc00260ac0162a6660b066e1d20080011323232323232323253330633066002149858cdc3a400460c06ea8c190004c190008dd6983100098310011bad30600013060002375a60bc00260ac0162a6660b066e1d200a0011323232323232323253330633066002149858cdc3a400460c06ea8c190004c190008dd6983100098310011bad30600013060002375a60bc00260ac0162a6660b066e1d200c0011323232323232323253330633066002149858cdc3a400460c06ea8c190004c190008dd6983100098310011bad306000130600023370e9001182d1baa305e001305600b153330583370e900700089919191919191919191919191919299983498360010a4c2c6eb4c1a8004c1a8008dd6983400098340011bad30660013066002375a60c800260c80046eb4c188004c188008dd69830000983000119b8748008c168dd5182f000982b0058a99982c19b87480400044c8c8c8c8c8c8c8c8c8c94ccc194c1a0008526163370e900118311baa30660013066002375a60c800260c80046eb4c188004c188008dd6983000098300011bad305e001305600b153330583370e900900089919191919192999830983200109924c646600200200c44a6660c60022930991980180198338011919299983119b87480000044c8c8c8c94ccc1a4c1b00084c9263040003163370e900118331baa306a001306a00230680013060002163060001306500116375a60c400260c40046eb4c180004c180008dd6182f000982b0058b182b005181800598170061816006981600718150078b182b000982b0011bad305400130540023052001305200230500013050002304e001304e002304c001304c002304a001304a002304800130400021630400013253330413370e900200089823181f8040a99982099b87480080044c8c8cc0040040a8894ccc11c004584c8c8c8c94ccc120cdc7803801080089980300300198248019bae3047002304b0023049001375c608c607e0102c607e00e608800260880046eacc108004c108008c100004c0e0028c0f8004c0f8008dd5981e000981e0009819800981c800981c8009818002181b802181a801981a8019819801119198008008011129998180008a5eb7bdb1804c8c8c8c94ccc0c4cdc7a45000021003133035337606ea4008dd3000998030030019bab3032003375c6060004606800460640024646464a66605a66e1d20020011480004dd698191815801181580099299981619b8748008004530103d87a8000132323300100100222533303200114c103d87a800013232323253330333371e9110000213374a90001981b9ba80014bd700998030030019bad3034003375c6064004606c00460680026eacc0c4c0a8008c0a8004c8cc004004008894ccc0bc0045300103d87a800013232323253330303371e9110000213374a90001981a1ba60014bd700998030030019bab3031003375c605e00460660046062002464a66605466e1d20000011323232325333031303400213232498c94ccc0c0cdc3a400000226464a66606a60700042649319299981999b87480000044c8c94ccc0e0c0ec0084c92630100011630390013031002153330333370e90010008991919191919299981e181f8010a4c2c6eb4c0f4004c0f4008dd6981d800981d8011bad30390013031002163031001163036001302e003153330303370e90010008a99981998170018a4c2c2c605c00460120062c60640026064004606000260500042c6050002464a66605266e1d200000113232533302e3031002149858dd7181780098138010a99981499b874800800454ccc0b0c09c0085261616302700123253330283370e9000000899191919299981798190010a4c2c6eb8c0c0004c0c0008dd7181700098130010b1813000919299981399b87480000044c8c94ccc0b0c0bc00852616375c605a002604a0042a66604e66e1d200200113232533302c302f002149858dd7181680098128010b18128009bad30290013021001163027001301f0013025001301d00b163002010300100330010012253330200011480004cdc024004660040046046002646600200202044a66603e002297ae013232533301e323232323232323253330263370e90010008a5114a0604800260520026042002604e002603e002604a002604a002603800426604400466008008002266008008002604600460420026eacc078004c078008dd5980e000980e000980d801180c800980c800980c000980b800980b000980a8011bac301300130130013012002375860200026010008600e0022c601a002601a0046016002600600229309b2b118029baa001230033754002ae6955ceaab9e5573eae815d0aba201", + "hash": "3c82744bd6a83ddb3e1fdf95b965038e7b0c66cba7a64829d8d8dd89" + }, { "title": "order_validator.validate_order", "datum": { @@ -77,14 +88,20 @@ }, "parameters": [ { - "title": "stake_credential", + "title": "batching_withdrawal_cred", + "schema": { + "$ref": "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential" + } + }, + { + "title": "expired_order_withdrawal_cred", "schema": { "$ref": "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential" } } ], - "compiledCode": "590c280100003232323232323232322222533300732323232533300b3370e900118050008991919299980719b87480000044c8c8c8c8c8c8c8c8c8cc004004008894ccc06c0045280991919299980d99baf01800114a226600a00a0046036004603e004603a0026eacc068004c068004c064004c060004c05c004c058004c054004c0300184c8c8c8c8c8c8c8c94ccc058cdc3a400401226464646464646464646464646464646464a66604e66e1d200000113232323300100100a22533302e00114a026464a66605a66e3c00801452889980200200098190011bae3030001375c605a002604a004266e21200030173301901023375e605a604c605a604c605a605c604c002006604a002605400260440026050002604003c601803a6eb0c094004c094004c090004c08c004c088004c084004c080004c07c004c078008dd6180e000980a007099191919191919191919191919191919299981319b8748008c0940704c8c8c94ccc0a4cdc3a400060500022646464646464646464646464a66606aa66606a66e1c008c8cc00400404c894ccc0e800452000133700900119801001181e8008a99981a99b890020011323300100101322533303a00114a226464a66607266ebcc0ec0080d04cc010010004528181f001181e0008a5014a0264646464a66607266e1d200230380011323232323233300100100c02422232323232323232323232323232323232323232323232323232323232323232533305f3370e9000182f0008991919192999831a99983199b88002029153330633375e01c02c2a6660c666e24cdc0981400d000981400a0a99983199baf374c604e0286e98c09c0684cdd799299983219b87480000045300103d87a8000153330643370e9001000899ba548000cc1a0c1a4c18804d2f5c0266e9520003306837526e50dd998349831009a5eb80c1880480305280a5014a0294054ccc18ccdd79ba70224c101800014a2266604c04c0440402c6eb4c190008dd698310009919bb0306600130663067001375860ca00260ba0022c60c600260c600260c400260c200260c000260be00260bc00460b800260b800460b400260a4004607c00264a6660a666e1d2004001130583051008153330533370e9001000899191980080081811299982c8008b099191919299982d19b8f0070021001133006006003305b003375c60b200460ba00460b60026eb8c160c14402058c14401cc158004c158008dd5982a000982a00118290009825005182800098280011bab304e001304e0013045001304b001304b001304200430490043047003304700330450022323300100100222533304200114bd6f7b630099191919299982199b8f489000021003133047337606ea4008dd3000998030030019bab3044003375c6084004608c00460880024646464a66607e66e1d20020011480004dd69822181e801181e80099299981f19b8748008004530103d87a8000132323300100100222533304400114c103d87a800013232323253330453371e9110000213374a9000198249ba80014bd700998030030019bad3046003375c60880046090004608c0026eacc10cc0f0008c0f0004c8cc004004008894ccc1040045300103d87a800013232323253330423371e9110000213374a9000198231ba60014bd700998030030019bab3043003375c6082004608a00460860026eb4c0fc004c0dc00458c0f4004c0d4004c0ec004c0cc05458c090068c08c004cc09006c8c8c8c8c8c8c8c8c94ccc0eccdc3a40040022a66607666ebc0080285288b0a503039001303e0013036001303c0013034001303a001303a00130310013036001302e0013034001302c001303200130320013029001302f001302700116323300100101222533302d00114c103d87a800013232533302c3375e6062605400400a266e952000330300024bd70099802002000981880118178009816000981200e0b1bab302a001302a002375660500026050002604e004604a002604a00260480026046002604400260420046eb0c07c004c07c004c078008dd6180e000980a007119299980b99b87480000044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc0a8c0b40084c8c8c8c8c8c8c92632533302e3370e9000000899192999819981b00109924c646eb4c0cc008dd698188008b1919bb03035001303530360013758606800260580102a66605c66e1d200200115333031302c00814985858c0b001cc94ccc0b4cdc3a400000226464646464646464a66607060760042930b19b8748008c0d4dd5181c800981c8011bad30370013037002375a606a002606a00466e1d2002302f3754606600260560162a66605a66e1d2002001132323232323232325333038303b002149858cdc3a4004606a6ea8c0e4004c0e4008dd6981b800981b8011bad303500130350023370e900118179baa3033001302b00b1533302d3370e9002000899191919191919191919299981d181e8010a4c2c66e1d200230373754607600260760046eb4c0e4004c0e4008dd6981b800981b8011bad303500130350023370e900118179baa3033001302b00b1533302d3370e900300089919191919191919299981c181d8010a4c2c66e1d200230353754607200260720046eb4c0dc004c0dc008dd6981a800981a80119b8748008c0bcdd5181980098158058a99981699b87480200044c8c8c8c8c8c8c8c94ccc0e0c0ec008526163370e9001181a9baa30390013039002375a606e002606e0046eb4c0d4004c0d4008dd6981980098158058a99981699b87480280044c8c8c8c8c8c8c8c94ccc0e0c0ec008526163370e9001181a9baa30390013039002375a606e002606e0046eb4c0d4004c0d4008dd6981980098158058a99981699b87480300044c8c8c8c8c8c8c8c94ccc0e0c0ec008526163370e9001181a9baa30390013039002375a606e002606e0046eb4c0d4004c0d4008cdc3a4004605e6ea8c0cc004c0ac02c54ccc0b4cdc3a401c00226464646464646464646464646464a66607c60820042930b1bad303f001303f002375a607a002607a0046eb4c0ec004c0ec008dd6981c800981c8011bad30370013037002375a606a002606a00466e1d2002302f3754606600260560162a66605a66e1d2010001132323232323232323232533303a303d002149858cdc3a4004606e6ea8c0ec004c0ec008dd6981c800981c8011bad30370013037002375a606a002606a0046eb4c0cc004c0ac02c54ccc0b4cdc3a40240022646464646464a66606c607200426493191980080080311299981c0008a4c2646600600660780046464a66606e66e1d2000001132323232533303e3041002132498c0a400c58cdc3a400460766ea8c0fc004c0fc008c0f4004c0d400858c0d4004c0e800458dd6981b800981b8011bad303500130350023758606600260560162c60560146032016602c018602c01a602801c602801e2c605600260560046eb4c0a4004c0a4008c09c004c09c008c094004c094008c08c004c08c008c084004c084008c07c004c07c008c074004c05400858c0540048c94ccc058cdc3a400000226464a666036603c0042930b1bae301c0013014002153330163370e90010008a99980c980a0010a4c2c2c6028002464a66602a66e1d2000001132323232533301c301f00213232498c94ccc06ccdc3a400000226464a66604060460042649319299980f19b87480000044c8c94ccc08cc0980084c926300f001163024001301c0021533301e3370e90010008991919191919299981398150010a4c2c6eb4c0a0004c0a0008dd6981300098130011bad3024001301c00216301c00116302100130190031533301b3370e90010008a99980f180c8018a4c2c2c603200460100062c603a002603a004603600260260042c6026002464a66602866e1d2000001132323232533301b301e002149858dd7180e000980e0011bae301a001301200216301200123253330133370e900000089919299980c180d8010a4c2c6eb8c064004c04400854ccc04ccdc3a400400226464a66603060360042930b1bae3019001301100216301100130010012253330140011480004cdc02400466004004602e00244646600200200644a66602a002297ae013232533301430050021330180023300400400113300400400130190023017001300c00832533300d3370e90000008a99980818058040a4c2c2a66601a66e1d200200115333010300b00814985854ccc034cdc3a40080022a66602060160102930b0b180580398048008b18078009807801180680098028008a4c26cac4600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "10a9dfa1df3430f97e171ec0705a77df2c1853639ba19098290e63f0" + "compiledCode": "590774010000323232323232323222222533300832323232533300c3370e90011805800899191919299980819b87480000084cc004dd5980a180a980a980a980a980a980a98070038068a99980819b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc084cdc3a400000226464646600200201444a66605000229404c8c94ccc09ccdc78010028a51133004004001302b002375c60520026eb8c098004c07c0084c8cc004004044894ccc09800452809919299981299baf30293023302930233029302a302300200614a22660080080026052004604e002603e002604600260380026042002603402e6464646464a66604066e1d200000113232323232323232323232323232323253330333035002132323232323232498c94ccc0dccdc3a400000226464a666078607c00426493191bad303c002375a60740022c6466ec0c0f4004c0f4c0f8004dd6181e000981a8040a99981b99b874800800454ccc0e8c0d4020526161630350073253330363370e900000089919191919191919299982098218010a4c2c66e1d2002303e3754608200260820046eb4c0fc004c0fc008dd6981e800981e80119b8748008c0e0dd5181d800981a0058a99981b19b87480080044c8c8c8c8c8c8c8c94ccc104c10c008526163370e9001181f1baa30410013041002375a607e002607e0046eb4c0f4004c0f4008cdc3a400460706ea8c0ec004c0d002c54ccc0d8cdc3a4008002264646464646464646464a666086608a0042930b19b8748008c100dd5182180098218011bad30410013041002375a607e002607e0046eb4c0f4004c0f4008cdc3a400460706ea8c0ec004c0d002c54ccc0d8cdc3a400c00226464646464646464a66608260860042930b19b8748008c0f8dd5182080098208011bad303f001303f002375a607a002607a00466e1d200230383754607600260680162a66606c66e1d20080011323232323232323253330413043002149858cdc3a4004607c6ea8c104004c104008dd6981f800981f8011bad303d001303d002375a607600260680162a66606c66e1d200a0011323232323232323253330413043002149858cdc3a4004607c6ea8c104004c104008dd6981f800981f8011bad303d001303d002375a607600260680162a66606c66e1d200c0011323232323232323253330413043002149858cdc3a4004607c6ea8c104004c104008dd6981f800981f8011bad303d001303d0023370e9001181c1baa303b001303400b153330363370e900700089919191919191919191919191919299982398248010a4c2c6eb4c11c004c11c008dd6982280098228011bad30430013043002375a608200260820046eb4c0fc004c0fc008dd6981e800981e80119b8748008c0e0dd5181d800981a0058a99981b19b87480400044c8c8c8c8c8c8c8c8c8c94ccc10cc114008526163370e900118201baa30430013043002375a608200260820046eb4c0fc004c0fc008dd6981e800981e8011bad303b001303400b153330363370e90090008991919191919299981f982080109924c646600200200c44a6660820022930991980180198220011919299982019b87480000044c8c8c8c94ccc11cc1240084c9263028003163370e900118221baa304700130470023045001303e00216303e001304200116375a607e002607e0046eb4c0f4004c0f4008dd6181d800981a0058b181a005180c005980a806180a806980980718098078b181980098198011bad30310013031002302f001302f002302d001302d002302b001302b00230290013029002302700130270023025001301e01b16301e01a23253330203370e900000089919299981298138010a4c2c6eb8c094004c07800854ccc080cdc3a40040022a666046603c0042930b0b180f000919299980f99b87480000044c8c8c8c94ccc098c0a00084c8c9263253330253370e9000000899192999815181600109924c64a66605066e1d200000113232533302d302f002132498c03c00458c0b4004c09800854ccc0a0cdc3a40040022646464646464a66606260660042930b1bad30310013031002375a605e002605e0046eb4c0b4004c09800858c09800458c0a8004c08c00c54ccc094cdc3a40040022a66605060460062930b0b181180118040018b181300098130011812000980e8010b180e800919299980f19b87480000044c8c8c8c94ccc094c09c00852616375c604a002604a0046eb8c08c004c07000858c0700048c94ccc074cdc3a400000226464a66604460480042930b1bae3022001301b0021533301d3370e900100089919299981118120010a4c2c6eb8c088004c06c00858c06c004dd6180f000980f000980e800980e000980d800980d000980c800980c000980b8011bac3015001300e00713300137566028602a602a602a602a602a602a601c00e01844646600200200644a66602c00229404c8c8c94ccc058cdd78030008a51133005005002301600230190023017001300d00832533300e3370e90000008a99980898060040a4c2c2a66601c66e1d200200115333011300c00814985854ccc038cdc3a40080022a66602260180102930b0b180600398050008b18078009807801180680098030008a4c26cac4600a6ea80048c00cdd5000ab9a5573aaae7955cfaba15745", + "hash": "3944039da8cd87971e374796d0560988481eb67796d87316c84c0ba4" }, { "title": "order_validator.validate_order_spending_in_batching", diff --git a/validators/order_validator.ak b/validators/order_validator.ak index 9165fee..7c3f07e 100644 --- a/validators/order_validator.ak +++ b/validators/order_validator.ak @@ -16,7 +16,8 @@ use amm_dex_v2/utils validator( // the Stake Credential of Order Batching Validator - stake_credential: StakeCredential, + batching_withdrawal_cred: StakeCredential, + expired_order_withdrawal_cred: StakeCredential, ) { fn validate_order(raw_datum: Data, raw_redeemer: Data, context: ScriptContext) { let ScriptContext { transaction, purpose } = context @@ -26,7 +27,7 @@ validator( ApplyOrder -> { let Transaction { withdrawals, .. } = transaction // validate that an Order can be spent if there's a `Order Batching` validator in the `withdrawals` - dict.has_key(withdrawals, stake_credential) + dict.has_key(withdrawals, batching_withdrawal_cred) } CancelOrderByOwner -> { let Transaction { inputs, extra_signatories, .. } = transaction @@ -43,89 +44,30 @@ validator( ScriptCredential(_) -> // In case owner is script address, this script will require at least 1 owner UTxO in input // If owner UTxO has enough condition to unlock itself, it can unlock this script as well - list.length( - list.filter( - inputs, - fn(input) { - let Input { output, .. } = input - let Output { address: out_address, .. } = output - let Address { payment_credential: out_payment_credential, .. } = - out_address - out_payment_credential == owner_payment_credential - }, - ), - ) > 0 + list.any( + inputs, + fn(input) { + let Input { output, .. } = input + let Output { address: out_address, .. } = output + let Address { payment_credential: out_payment_credential, .. } = + out_address + out_payment_credential == owner_payment_credential + }, + ) } } CancelExpiredOrderByAnyone -> { - let Transaction { - inputs, - outputs, - redeemers, - validity_range, - datums, - .. - } = transaction - expect Spend(order_ref) = purpose - expect Some(own_order_input) = - list.find( - inputs, - fn(input) { - let Input { output_reference: out_ref, .. } = input - out_ref == order_ref - }, - ) - let Input { output: Output { address: own_order_address, .. }, .. } = - own_order_input - let Address { payment_credential: own_order_payment_cred, .. } = - own_order_address - let order_inputs = - list.filter( - inputs, - fn(input) { - let Input { output: Output { address: addr, .. }, .. } = input - let Address { payment_credential: payment_cred, .. } = addr - when payment_cred is { - ScriptCredential(_) -> { - expect payment_cred == own_order_payment_cred - True - } - VerificationKeyCredential(_) -> False - } - }, - ) - let orders_input_length = list.length(order_inputs) - let outputs_length = list.length(outputs) - let redeemers_list = dict.to_list(redeemers) - expect and { - orders_input_length == dict.size(redeemers), - outputs_length >= orders_input_length, - list.all( - redeemers_list, - fn(r) { - let (_, redeemer) = r - redeemer == raw_redeemer - }, - ), - } - let Interval { - lower_bound: IntervalBound { bound_type: lower_bound_type, .. }, - .. - } = validity_range - expect Finite(start_valid_time_range) = lower_bound_type - - // We need to consider this logic - order_validation.validate_cancel_expired_orders( - order_inputs: order_inputs, - all_outputs: outputs, - datum_map: datums, - start_valid_time_range: start_valid_time_range, - ) + let Transaction { withdrawals, .. } = transaction + // validate that an Order can be spent if there's a `Expired Order Cancelling` validator in the `withdrawals` + dict.has_key(withdrawals, expired_order_withdrawal_cred) } } } } +// This validator will be used in Batching transaction. +// It will make sure that Pool contract is presented in the Transaction Input +// The rest validation logic is forwared to Pool Contract validator( // the hash of Liquidity Pool Script pool_hash: ValidatorHash, @@ -147,3 +89,69 @@ validator( pool_hash == hash } } + +// This validator will be used in cancelling Expired Orders transaction. +// It only allows PubKey Address can trigger the cancel +validator { + fn validate_expired_order_cancelling( + _raw_redeemer: Data, + context: ScriptContext, + ) -> Bool { + expect ScriptContext { transaction, purpose: WithdrawFrom(_) } = context + + let Transaction { inputs, outputs, redeemers, validity_range, datums, .. } = + transaction + // Assume all script inputs are order scripts. + // All scripts that have the same Order Datum structure will be accepted in this transaction. + let order_inputs = + list.filter( + inputs, + fn(input) { + let Input { + output: Output { + address: Address { payment_credential: payment_cred, .. }, + .. + }, + .. + } = input + when payment_cred is { + ScriptCredential(_) -> True + _ -> False + } + }, + ) + + let orders_input_length = list.length(order_inputs) + let outputs_length = list.length(outputs) + let redeemers_list = dict.to_list(redeemers) + expect and { + // Redeemers contains a Withdrawal element, so we subtract 1 here + orders_input_length == dict.size(redeemers) - 1, + outputs_length >= orders_input_length, + list.all( + redeemers_list, + fn(r) { + let (pp, redeemer) = r + when pp is { + Spend(_) -> { + expect x: OrderRedeemer = redeemer + x == CancelExpiredOrderByAnyone + } + _ -> True + } + }, + ), + } + let Interval { + lower_bound: IntervalBound { bound_type: lower_bound_type, .. }, + .. + } = validity_range + expect Finite(start_valid_time_range) = lower_bound_type + order_validation.validate_cancel_expired_orders( + order_inputs: order_inputs, + all_outputs: outputs, + datum_map: datums, + start_valid_time_range: start_valid_time_range, + ) + } +} From e92e2ce0b730c9be242ce0cb25d33e524cceb195 Mon Sep 17 00:00:00 2001 From: Richard Nguyen Date: Fri, 12 Jan 2024 16:12:07 +0700 Subject: [PATCH 2/2] add doc --- amm-v2-docs/amm-v2-specs.md | 56 ++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/amm-v2-docs/amm-v2-specs.md b/amm-v2-docs/amm-v2-specs.md index b2ca38d..cdd8f5e 100644 --- a/amm-v2-docs/amm-v2-specs.md +++ b/amm-v2-docs/amm-v2-specs.md @@ -80,20 +80,38 @@ Order Batching validator is a Withdrawal Script, is responsible for validating P - **OrderBatchingRedeemer**: The redeemer contains `pool_input_index`, it's used for finding Pool Input faster, it will be called on Batching Transaction. - validate that there's a Pool Input which have Address's Payment Credential matching with `pool_hash` +#### 3.3.2 Expired Order Cancel Validator -#### 3.3.2 Order Validator + +Expired Order Cancel validator is a Withdrawal Script, is responsible for validating expired orders are cancelled in the correct way by anyone. +The orders' funds have to be paid back to sender + + +#### 3.3.1.2 Parameter +Nothing + + +#### 3.3.2.3 Redeemer +Any Data + +#### 3.3.2.3 Validation +- validate the transaction inputs only contains Order scripts +- validate *start_valid_time_range* must be greater than the *expired time* +- All users' funds have to be paid back to senders. *Cancel tip* might be deducted from the funds, anyone make the transaction can choose the tip amount and the amount must not exceed the maximum tip + +#### 3.3.3 Order Validator Order validator is responsible for holding "User Requests" funds and details about what users want to do with the liquidity pool. An order can only be applied to the liquidity pool by Batcher or cancelled by User's payment signature / Script Owner Representation (in case Owner is a Smart Contract) -#### 3.3.2.1 Parameter +#### 3.3.3.1 Parameter - _stake_credential_: the Stake Credential of `Order Batching Validator` -#### 3.3.2.2 Datum +#### 3.3.3.2 Datum There are 10 order types: @@ -166,7 +184,7 @@ An Order Datum keeps information about Order Type and some other informations: - _expired_time_opt_: Order Expired time. If the order is not executed after Expired Time, anyone can help the owner cancel it -#### 3.3.2.3 Redeemer +#### 3.3.3.3 Redeemer - **ApplyOrder** @@ -174,7 +192,7 @@ An Order Datum keeps information about Order Type and some other informations: - **TODO: CancelExpiredOrderByAnyone** -#### 3.3.2.4 Validation +#### 3.3.3.4 Validation - **ApplyOrder**: the redeemer will allow spending Order UTxO in Batching transaction @@ -183,24 +201,24 @@ An Order Datum keeps information about Order Type and some other informations: - validate that the transaction has _sender_'s signature or _sender_ script UTxO in the Transaction Inputs -#### 3.3.3 Authen Minting Policy +#### 3.3.4 Authen Minting Policy Authen Minting Policy is responsible for creating initial Factory `Linked List`, minting legitimate Factory, Liquidity Pool and Liquidity Pool `Share` Tokens -#### 3.3.3.1 Parameter +#### 3.3.4.1 Parameter - _out_ref_: is a Reference of an Unspent Transaction Output, which will only be spent on `MintFactoryAuthen` redeemer to make sure this redeemer can only be called once -#### 3.3.3.2 Redeemer +#### 3.3.4.2 Redeemer - **MintFactoryAuthen** - **CreatePool** -#### 3.3.3.3 Validation +#### 3.3.4.3 Validation - **MintFactoryAuthen**: The redeemer can be called once to initialize the whole AMM V2 system @@ -217,7 +235,7 @@ Authen Minting Policy is responsible for creating initial Factory `Linked List`, - MAX_INT64 LP Token, LP Token must have PolicyID is **AuthenMintingPolicy** and TokenName is Hash of Pool's Asset A and Asset B (`SHA_256(SHA_256(AssetA), SHA_256(AssetB))`). Asset A and Asset B are in Factory Redeemer and they must be sorted -#### 3.3.4 Factory Validator +#### 3.3.5 Factory Validator Factory Validator is responsible for creating a non-duplicated Liquidity Pool. Each Factory UTxO is an element of Factory `Linked List`, contains a head and tail which are existing Pool's LP Asset Token Name except `#"00"` and `#"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00"` aka intial head and tail @@ -251,24 +269,24 @@ Anytime new Pool is created, a Factory UTxO will be spent can create the 2 new o - old head < Pool LP Token Name < old tail -#### 3.3.4.1 Parameter +#### 3.3.5.1 Parameter - _authen_policy_id_: The PolicyID of `Authen Minting Policy` - _pool_hash_: ValidatorHash of Pool Contract -#### 3.3.4.2 Datum +#### 3.3.5.2 Datum - _head_: The Head of Factory `LinkedList`` element - _tail_: The Head of Factory `LinkedList`` element -#### 3.3.4.3 Redeemer +#### 3.3.5.3 Redeemer - **Factory Redeemer**: - _asset_a_: Asset A of new Liquidity Pool - _asset_b_: Asset B of new Liquidity Pool -#### 3.3.4.4 Validation +#### 3.3.5.4 Validation - **Factory Redeemer**: - validate that Asset A and Asset B must be sorted - validate that there's single Factory UTxO in Transaction Input and contain single legitimate Factory NFT Token @@ -288,19 +306,19 @@ Anytime new Pool is created, a Factory UTxO will be spent can create the 2 new o - MAX_INT64 LP Token, LP Token must have PolicyID is **AuthenMintingPolicy** and TokenName is Hash of Pool's Asset A and Asset B (`SHA_256(SHA_256(AssetA), SHA_256(AssetB))`). Asset A and Asset B are in Factory Redeemer and they must be sorted -#### 3.3.5 Pool Validator +#### 3.3.6 Pool Validator Pool validator is the most important part in the system. It's responsible for guaranteeing that Orders must be processed in the correct way and Liquidity Providers' funds cannot be stolen in any way. -#### 3.3.5.1 Parameter +#### 3.3.6.1 Parameter - _authen_policy_id_: The PolicyID of `Authen Minting Policy` -#### 3.3.5.2 Datum +#### 3.3.6.2 Datum - _asset_a_: The Pool's Asset A - _asset_b_: The Pool's Asset B - _total_liquidity_: Total Share of Liquidity Providers @@ -311,7 +329,7 @@ Pool validator is the most important part in the system. It's responsible for gu - _profit_sharing_opt_: (Optional) Numerator and Denominator of Profit Sharing percentage, this is the percentage of Trading Fee. (eg, Trading Fee is 3%, Profit Sharing is 1/6 -> Profit Sharing = 1/6 * 3%) -#### 3.3.5.3 Redeemer +#### 3.3.6.3 Redeemer - **Batching**: - _batcher_address_: Address of Batcher - _input_indexes_: The Indexes of Orders are processing (it will be explained below) @@ -332,7 +350,7 @@ Pool validator is the most important part in the system. It's responsible for gu - _admin_index_: Index of the UTxO holding Admin License Token in the Transaction Inputs. -#### 3.3.5.4 Validation +#### 3.3.6.4 Validation - **Batching**: This redeemer will be called on Batching Transaction. It can process all types of Orders except **SwapMultiRouting** Order - validate batcher with valid License Token must be presented in Transaction Inputs: - Batcher must sign a Batching transaction.