Skip to content

Commit

Permalink
Move pool examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 9, 2023
1 parent 102614a commit 1238869
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 64 deletions.
58 changes: 58 additions & 0 deletions lib/tests/examples/ex_pool.ak
Original file line number Diff line number Diff line change
@@ -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())
}
61 changes: 0 additions & 61 deletions lib/types/pool.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use aiken/bytearray
use aiken/cbor
use aiken/time.{PosixTime}
use shared.{AssetClass, Ident}
use types/order.{SignedStrategyExecution}
Expand All @@ -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,
Expand All @@ -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
}
3 changes: 0 additions & 3 deletions validators/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 1238869

Please sign in to comment.