From 1238869ec2ee0d8f818107845e8a1791f7d9072d Mon Sep 17 00:00:00 2001 From: Pi Lanningham Date: Fri, 8 Dec 2023 23:49:36 -0500 Subject: [PATCH] Move pool examples --- lib/tests/examples/ex_pool.ak | 58 +++++++++++++++++++++++++++++++++ lib/types/pool.ak | 61 ----------------------------------- validators/pool.ak | 3 -- 3 files changed, 58 insertions(+), 64 deletions(-) create mode 100644 lib/tests/examples/ex_pool.ak diff --git a/lib/tests/examples/ex_pool.ak b/lib/tests/examples/ex_pool.ak new file mode 100644 index 0000000..fd5f18f --- /dev/null +++ b/lib/tests/examples/ex_pool.ak @@ -0,0 +1,58 @@ +use types/pool.{PoolDatum, PoolRedeemer, PoolMintRedeemer, PoolScoop, WithdrawFees, CreatePool} +use tests/examples/ex_shared.{print_example} + +fn mk_pool_datum() -> PoolDatum { + PoolDatum { + identifier: "123", + assets: ( + (#"", #""), + ( + #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77", + #"53554e444145", + ), + ), + circulating_lp: 20229488080013, + fees_per_10_thousand: (2000, 500), + market_open: 100, + fee_finalized: 1000, + protocol_fees: 10000000, + } +} + +test example_pool_datum() { + print_example(mk_pool_datum()) +} + +fn mk_pool_scoop() -> PoolRedeemer { + PoolScoop { signatory_index: 0, scooper_index: 0, amortized_base_fee: 2_500_000, input_order: [(1, None)] } +} + +test example_pool_scoop_redeemer() { + print_example(mk_pool_scoop()) +} + +fn mk_withdraw_fees_redeemer() -> PoolRedeemer { + WithdrawFees { amount: 100, treasury_output: 1 } +} + +test example_pool_withdraw_fees_redeemer() { + print_example(mk_withdraw_fees_redeemer()) +} + +fn mk_pool_mint_redeemer() -> PoolMintRedeemer { + CreatePool { + assets: ( + (#"", #""), + ( + #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77", + #"53554e444145", + ), + ), + pool_output: 0, + metadata_output: 1, + } +} + +test example_pool_mint_redeemer() { + print_example(mk_pool_mint_redeemer()) +} diff --git a/lib/types/pool.ak b/lib/types/pool.ak index 1862573..eb7fff5 100644 --- a/lib/types/pool.ak +++ b/lib/types/pool.ak @@ -1,5 +1,3 @@ -use aiken/bytearray -use aiken/cbor use aiken/time.{PosixTime} use shared.{AssetClass, Ident} use types/order.{SignedStrategyExecution} @@ -14,29 +12,6 @@ pub type PoolDatum { protocol_fees: Int, } -test example_pool_datum() { - trace bytearray.to_hex( - cbor.serialise( - PoolDatum { - identifier: "123", - assets: ( - (#"", #""), - ( - #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77", - #"53554e444145", - ), - ), - circulating_lp: 20229488080013, - fees_per_10_thousand: (2000, 500), - market_open: 100, - fee_finalized: 1000, - protocol_fees: 10000000, - }, - ), - ) - True -} - pub type PoolRedeemer { PoolScoop { signatory_index: Int, @@ -50,44 +25,8 @@ pub type PoolRedeemer { } } -test example_pool_scoop_redeemer() { - trace bytearray.to_hex( - cbor.serialise( - PoolScoop { signatory_index: 0, scooper_index: 0, amortized_base_fee: 2_500_000, input_order: [(1, None)] }, - ), - ) - True -} - -test example_pool_withdraw_fees_redeemer() { - trace bytearray.to_hex( - cbor.serialise( - WithdrawFees { amount: 100, treasury_output: 1 }, - ), - ) - True -} pub type PoolMintRedeemer { MintLP { identifier: Ident } CreatePool { assets: (AssetClass, AssetClass), pool_output: Int, metadata_output: Int } } - -test example_pool_mint_redeemer() { - trace bytearray.to_hex( - cbor.serialise( - CreatePool { - assets: ( - (#"", #""), - ( - #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77", - #"53554e444145", - ), - ), - pool_output: 0, - metadata_output: 1, - }, - ), - ) - True -} diff --git a/validators/pool.ak b/validators/pool.ak index d4d8980..68c98ea 100644 --- a/validators/pool.ak +++ b/validators/pool.ak @@ -138,7 +138,6 @@ validator(settings_policy_id: PolicyId) { when redeemer is { PoolScoop{ signatory_index, scooper_index, amortized_base_fee, input_order } -> { - // Deconstruct the settings datum with the fields we need for a scoop let SettingsDatum { authorized_scoopers, base_fee, simple_fee, strategy_fee, .. } = settings_datum @@ -147,7 +146,6 @@ validator(settings_policy_id: PolicyId) { let initial_state = pool_input_to_state(pool_script_hash, datum, pool_input, validity_range.lower_bound) // Process the orders in order, and decide the final pool state we should see // OPTIMIZATION: pass in the list of outputs, to pop off and compare in parallel - trace @"Start" let (outcome, simple_count, strategy_count, total_protocol_fee) = process_orders( actual_identifier, @@ -167,7 +165,6 @@ validator(settings_policy_id: PolicyId) { 0, 0, ) - trace @"Done" let PoolState { quantity_lp: expected_circulating_lp, protocol_fees: expected_protocol_fees,