diff --git a/lib/aiken-virtual-dex/placeholder.ak b/lib/aiken-virtual-dex/placeholder.ak index c09f54e..f753d80 100644 --- a/lib/aiken-virtual-dex/placeholder.ak +++ b/lib/aiken-virtual-dex/placeholder.ak @@ -3,8 +3,8 @@ use aiken/hash.{blake2b_256} use aiken/transaction.{InlineDatum, Input, NoDatum, Output} use aiken/transaction/value.{PolicyId, Value, add, from_asset} use aiken_virtual_dex/types.{ - AccountNormalDatum, EmergencyUnlockPhase1, EmergencyUnlockPhase2, OracleDatum, - VirtualDexDatum, + AccountNormalDatum, AccountOracleDatum, DexOracleDatum, EmergencyUnlockPhase1, + EmergencyUnlockPhase2, VirtualDexDatum, } use aiken_virtual_dex/utils.{get_emergency_token_name} use sidan_placeholder/address.{mock_pub_key_address, mock_script_address} @@ -14,14 +14,22 @@ use sidan_placeholder/key_hex.{ use sidan_placeholder/output_reference.{mock_utxo_ref} // Smart contract specific placeholders -pub fn mock_oracle_policy_id() -> PolicyId { +pub fn mock_account_oracle_policy_id() -> PolicyId { mock_policy_id(0) } -pub fn mock_oracle_address() { +pub fn mock_dex_oracle_policy_id() -> PolicyId { + mock_policy_id(3) +} + +pub fn mock_account_oracle_address() { mock_script_address(1, None) } +pub fn mock_dex_oracle_address() { + mock_script_address(6, None) +} + pub fn mock_fee_ref_token() { mock_policy_id(1) } @@ -58,29 +66,56 @@ pub fn mock_token_asset_class() { (mock_policy_id(4), "A potentially very long name") } -pub fn mock_oracle_datum() { - OracleDatum { - oracle_nft: mock_oracle_policy_id(), - oracle_address: mock_oracle_address(), +pub fn mock_account_oracle_datum() { + AccountOracleDatum { + oracle_nft: mock_account_oracle_policy_id(), + oracle_address: mock_account_oracle_address(), operation_key: mock_operation_key(), stop_key: mock_stop_key(), } } -pub fn mock_oracle_output(oracle_datum: OracleDatum) -> Output { +pub fn mock_account_oracle_output(oracle_datum: AccountOracleDatum) -> Output { Output { - address: mock_oracle_address(), - value: from_asset(mock_oracle_policy_id(), "", 1) + address: mock_account_oracle_address(), + value: from_asset(mock_account_oracle_policy_id(), "", 1) |> add(#"", #"", 2_000_000), datum: InlineDatum(oracle_datum), reference_script: None, } } -pub fn mock_oracle_ref_input() -> Input { +pub fn mock_account_oracle_ref_input() -> Input { Input { output_reference: mock_utxo_ref(0, 0), - output: mock_oracle_output(mock_oracle_datum()), + output: mock_account_oracle_output(mock_account_oracle_datum()), + } +} + +pub fn mock_dex_oracle_datum() { + DexOracleDatum { + oracle_nft: mock_dex_oracle_policy_id(), + oracle_address: mock_dex_oracle_address(), + dex_address: mock_virtual_dex_address(), + operation_key: mock_operation_key(), + stop_key: mock_stop_key(), + } +} + +pub fn mock_dex_oracle_output(oracle_datum: DexOracleDatum) -> Output { + Output { + address: mock_dex_oracle_address(), + value: from_asset(mock_dex_oracle_policy_id(), "", 1) + |> add(#"", #"", 2_000_000), + datum: InlineDatum(oracle_datum), + reference_script: None, + } +} + +pub fn mock_dex_oracle_ref_input() -> Input { + Input { + output_reference: mock_utxo_ref(1, 0), + output: mock_dex_oracle_output(mock_dex_oracle_datum()), } } @@ -126,6 +161,7 @@ pub fn mock_buy_ada_order_input( list_price_times_1mil: Int, lot_size: Int, extra_lovelace: Int, + fee_lovelace: Int, ) { Input { output_reference: mock_utxo_ref(0, 50 + variation), @@ -135,7 +171,8 @@ pub fn mock_buy_ada_order_input( mock_token_asset_class().1st, mock_token_asset_class().2nd, lot_size, - ), + ) + |> add("", "", extra_lovelace + fee_lovelace), datum: InlineDatum( VirtualDexDatum { account_address: mock_account_address(), @@ -155,12 +192,13 @@ pub fn mock_sell_ada_order_input( list_price_times_1mil: Int, lot_size: Int, extra_lovelace: Int, + fee_lovelace: Int, ) { Input { output_reference: mock_utxo_ref(0, 60 + variation), output: Output { address: mock_virtual_dex_address(), - value: from_asset("", "", lot_size), + value: from_asset("", "", lot_size + extra_lovelace + fee_lovelace), datum: InlineDatum( VirtualDexDatum { account_address: mock_account_address(), diff --git a/lib/aiken-virtual-dex/types.ak b/lib/aiken-virtual-dex/types.ak index 0e47cf7..3e1da22 100644 --- a/lib/aiken-virtual-dex/types.ak +++ b/lib/aiken-virtual-dex/types.ak @@ -8,25 +8,25 @@ pub type MintPolarity { RBurn } -// 2. OracleValidator -pub type OracleDatum { +// 2. EmergencyToken +pub type EmergencyTokenMintingPolarity { + EMint { current_timestamp: Int, account_address: Address } + EBurn +} + +// 3. AccountOracle +pub type AccountOracleDatum { oracle_nft: PolicyId, oracle_address: Address, operation_key: ByteArray, stop_key: ByteArray, } -pub type OracleRedeemer { +pub type AccountOracleRedeemer { RotateKey { new_operation_key: ByteArray, new_stop_key: ByteArray } StopApp } -// 3. EmergencyToken -pub type EmergencyTokenMintingPolarity { - EMint { current_timestamp: Int, account_address: Address } - EBurn -} - // 3. Account pub type AccountRedeemer { AccountUserUnlock @@ -41,7 +41,7 @@ pub type AccountDatum { EmergencyUnlockPhase2 { valid_since: Int, minter: ByteArray } } -pub type AccountEmergencyActionPhase1Redeemer { +pub type AccountEmergencyPhase1Redeemer { owner: ByteArray, own_input: Input, initiate_before: Int, @@ -53,7 +53,22 @@ pub type AccountEmergencyActionPhase2Redeemer { withdraw_output: OutputReference, } -// 5. VirtualDex +// 5. DexOracle + +pub type DexOracleDatum { + oracle_nft: PolicyId, + oracle_address: Address, + dex_address: Address, + operation_key: ByteArray, + stop_key: ByteArray, +} + +pub type DexOracleRedeemer { + DexRotateKey { new_operation_key: ByteArray, new_stop_key: ByteArray } + StopDex +} + +// 6. VirtualDex pub type VirtualDexDatum { account_address: Address, is_long: Bool, diff --git a/lib/aiken-virtual-dex/validators/account/account.ak b/lib/aiken-virtual-dex/validators/account/account.ak index 3be6bd3..0827e09 100644 --- a/lib/aiken-virtual-dex/validators/account/account.ak +++ b/lib/aiken-virtual-dex/validators/account/account.ak @@ -1,9 +1,10 @@ use aiken/hash.{Blake2b_224, Hash} +use aiken/pairs use aiken/transaction.{ScriptContext, Spend, Transaction, find_input} use aiken/transaction/credential.{Inline, Script, ScriptCredential} use aiken_virtual_dex/types.{ - AccountAppUnlock, AccountDatum, AccountEmergencyActionPhase1Redeemer, - AccountEmergencyActionPhase2Redeemer, AccountEmergencyUnlockPhase1, + AccountAppUnlock, AccountDatum, AccountEmergencyActionPhase2Redeemer, + AccountEmergencyPhase1Redeemer, AccountEmergencyUnlockPhase1, AccountEmergencyUnlockPhase2, AccountRedeemer, AccountUserUnlock, } use sidan_utils/redeemers.{withdrawal_redeemer} @@ -19,29 +20,42 @@ pub fn account_logic( context: ScriptContext, ) -> Bool { let ScriptContext { transaction, purpose } = context - when transaction.withdrawals is { - [Pair(stake_cred, _)] -> { - expect Inline(ScriptCredential(stake_script_hash)) = stake_cred - when redeemer is { - AccountUserUnlock -> stake_script_hash == user_unlock - AccountAppUnlock -> stake_script_hash == app_unlock - AccountEmergencyUnlockPhase1 -> { + when redeemer is { + AccountUserUnlock -> + pairs.has_key( + transaction.withdrawals, + Inline(ScriptCredential(user_unlock)), + ) + AccountAppUnlock -> + pairs.has_key( + transaction.withdrawals, + Inline(ScriptCredential(app_unlock)), + ) + AccountEmergencyUnlockPhase1 -> + when transaction.withdrawals is { + [Pair(stake_cred, _)] -> { + expect Inline(ScriptCredential(stake_script_hash)) = stake_cred expect Spend(own_utxo) = purpose expect Some(own_input) = find_input(transaction.inputs, own_utxo) expect Some(withdrawal_script_redeemer) = transaction.redeemers |> withdrawal_redeemer(stake_script_hash) - expect AccountEmergencyActionPhase1Redeemer { + expect AccountEmergencyPhase1Redeemer { owner: redeemer_owner, own_input: redeemer_own_input, .. - }: AccountEmergencyActionPhase1Redeemer = withdrawal_script_redeemer + }: AccountEmergencyPhase1Redeemer = withdrawal_script_redeemer let is_withdrawal_redeemer_correct = redeemer_owner == owner && redeemer_own_input == own_input let is_withdrawal_script_present = stake_script_hash == emergency_unlock_phase1 is_withdrawal_redeemer_correct && is_withdrawal_script_present } - AccountEmergencyUnlockPhase2 -> { + _ -> False + } + AccountEmergencyUnlockPhase2 -> + when transaction.withdrawals is { + [Pair(stake_cred, _)] -> { + expect Inline(ScriptCredential(stake_script_hash)) = stake_cred expect Spend(own_utxo) = purpose expect Some(own_input) = find_input(transaction.inputs, own_utxo) expect Some(withdrawal_script_redeemer) = @@ -57,8 +71,8 @@ pub fn account_logic( stake_script_hash == emergency_unlock_phase2 is_withdrawal_redeemer_correct && is_withdrawal_script_present } + + _ -> False } - } - _ -> False } } diff --git a/lib/aiken-virtual-dex/validators/account/app_unlock.ak b/lib/aiken-virtual-dex/validators/account/app_unlock.ak index 1263517..3369db3 100644 --- a/lib/aiken-virtual-dex/validators/account/app_unlock.ak +++ b/lib/aiken-virtual-dex/validators/account/app_unlock.ak @@ -3,7 +3,7 @@ use aiken/transaction.{ScriptContext, Transaction, WithdrawFrom} use aiken/transaction/value.{PolicyId, merge, zero} use aiken_virtual_dex/common.{get_all_value_to, only_input_datum_with, value_geq} -use aiken_virtual_dex/types.{OracleDatum} +use aiken_virtual_dex/types.{AccountOracleDatum} use sidan_utils/address.{address_script_hash} use sidan_utils/extra_signatories.{key_signed} @@ -15,7 +15,7 @@ pub fn account_app_unlock_logic( let ScriptContext { purpose, transaction } = context let Transaction { inputs, outputs, extra_signatories, .. } = transaction expect WithdrawFrom(_) = purpose - expect OracleDatum { operation_key, .. }: OracleDatum = + expect AccountOracleDatum { operation_key, .. }: AccountOracleDatum = only_input_datum_with(transaction.reference_inputs, oracle_nft, "") let (is_only_single_script_address, maybe_script_address, account_input_value) = diff --git a/lib/aiken-virtual-dex/validators/account/emergency_unlock_phase1.ak b/lib/aiken-virtual-dex/validators/account/emergency_unlock_phase1.ak index d9191df..b368bba 100644 --- a/lib/aiken-virtual-dex/validators/account/emergency_unlock_phase1.ak +++ b/lib/aiken-virtual-dex/validators/account/emergency_unlock_phase1.ak @@ -1,6 +1,6 @@ use aiken/transaction.{InlineDatum, Input, ScriptContext, WithdrawFrom} use aiken_virtual_dex/types.{ - AccountDatum, AccountEmergencyActionPhase1Redeemer, EmergencyUnlockPhase1, + AccountDatum, AccountEmergencyPhase1Redeemer, EmergencyUnlockPhase1, EmergencyUnlockPhase2, } use aiken_virtual_dex/utils.{get_emergency_token_name} @@ -11,13 +11,13 @@ use sidan_utils/validity_range.{valid_before} pub fn account_emergency_unlock_phase_1_logic( emergency_token: ByteArray, - redeemer: AccountEmergencyActionPhase1Redeemer, + redeemer: AccountEmergencyPhase1Redeemer, context: ScriptContext, ) -> Bool { let ScriptContext { purpose, transaction } = context expect WithdrawFrom(_) = purpose - let AccountEmergencyActionPhase1Redeemer { owner, own_input, initiate_before } = + let AccountEmergencyPhase1Redeemer { owner, own_input, initiate_before } = redeemer let current_address = own_input.output.address expect [own_output] = diff --git a/lib/aiken-virtual-dex/validators/account/user_unlock.ak b/lib/aiken-virtual-dex/validators/account/user_unlock.ak index 9de1860..69d35e2 100644 --- a/lib/aiken-virtual-dex/validators/account/user_unlock.ak +++ b/lib/aiken-virtual-dex/validators/account/user_unlock.ak @@ -1,7 +1,7 @@ use aiken/transaction.{ScriptContext, WithdrawFrom} use aiken/transaction/value.{PolicyId} use aiken_virtual_dex/common.{only_input_datum_with} -use aiken_virtual_dex/types.{OracleDatum} +use aiken_virtual_dex/types.{AccountOracleDatum} use sidan_utils/extra_signatories.{all_key_signed} pub fn account_user_unlock_logic( @@ -12,7 +12,7 @@ pub fn account_user_unlock_logic( ) -> Bool { let ScriptContext { purpose, transaction } = context expect WithdrawFrom(_) = purpose - expect OracleDatum { operation_key, .. }: OracleDatum = + expect AccountOracleDatum { operation_key, .. }: AccountOracleDatum = only_input_datum_with(transaction.reference_inputs, oracle_nft, "") all_key_signed(transaction.extra_signatories, [owner, operation_key]) } diff --git a/lib/aiken-virtual-dex/validators/oracle_validator.ak b/lib/aiken-virtual-dex/validators/account_oracle.ak similarity index 74% rename from lib/aiken-virtual-dex/validators/oracle_validator.ak rename to lib/aiken-virtual-dex/validators/account_oracle.ak index a5380c5..98d9ced 100644 --- a/lib/aiken-virtual-dex/validators/oracle_validator.ak +++ b/lib/aiken-virtual-dex/validators/account_oracle.ak @@ -1,28 +1,31 @@ use aiken/transaction.{InlineDatum, Output, ScriptContext, Spend, Transaction} -use aiken_virtual_dex/types.{OracleDatum, OracleRedeemer, RotateKey, StopApp} +use aiken_virtual_dex/types.{ + AccountOracleDatum, AccountOracleRedeemer, RotateKey, StopApp, +} use sidan_utils/extra_signatories.{all_key_signed, key_signed} use sidan_utils/mints.{only_minted_token} use sidan_utils/outputs.{outputs_at_with} -pub fn oracle_validator_logic( - datum: OracleDatum, - redeemer: OracleRedeemer, +pub fn account_oracle_logic( + datum: AccountOracleDatum, + redeemer: AccountOracleRedeemer, context: ScriptContext, ) { let ScriptContext { purpose, transaction } = context when purpose is { Spend(_) -> { let Transaction { outputs, mint, extra_signatories, .. } = transaction - let OracleDatum { oracle_nft, oracle_address, stop_key, .. } = datum + let AccountOracleDatum { oracle_nft, oracle_address, stop_key, .. } = + datum when redeemer is { RotateKey { new_operation_key, new_stop_key } -> { expect [own_output] = outputs_at_with(outputs, oracle_address, oracle_nft, "") expect InlineDatum(dat) = own_output.datum - expect own_datum: OracleDatum = dat + expect own_datum: AccountOracleDatum = dat let datum_correct = - own_datum == OracleDatum { + own_datum == AccountOracleDatum { ..datum, operation_key: new_operation_key, stop_key: new_stop_key, diff --git a/lib/aiken-virtual-dex/validators/dex_oracle.ak b/lib/aiken-virtual-dex/validators/dex_oracle.ak new file mode 100644 index 0000000..2550404 --- /dev/null +++ b/lib/aiken-virtual-dex/validators/dex_oracle.ak @@ -0,0 +1,46 @@ +use aiken/transaction.{InlineDatum, Output, ScriptContext, Spend, Transaction} +use aiken_virtual_dex/types.{ + DexOracleDatum, DexOracleRedeemer, DexRotateKey, StopDex, +} +use sidan_utils/extra_signatories.{all_key_signed, key_signed} +use sidan_utils/mints.{only_minted_token} +use sidan_utils/outputs.{outputs_at_with} + +pub fn dex_oracle_logic( + datum: DexOracleDatum, + redeemer: DexOracleRedeemer, + context: ScriptContext, +) { + let ScriptContext { purpose, transaction } = context + when purpose is { + Spend(_) -> { + let Transaction { outputs, mint, extra_signatories, .. } = transaction + let DexOracleDatum { oracle_nft, oracle_address, stop_key, .. } = datum + + when redeemer is { + DexRotateKey { new_operation_key, new_stop_key } -> { + expect [own_output] = + outputs_at_with(outputs, oracle_address, oracle_nft, "") + expect InlineDatum(dat) = own_output.datum + expect own_datum: DexOracleDatum = dat + let datum_correct = + own_datum == DexOracleDatum { + ..datum, + operation_key: new_operation_key, + stop_key: new_stop_key, + } + all_key_signed(extra_signatories, [new_stop_key, stop_key]) && datum_correct + } + + StopDex -> + key_signed(extra_signatories, stop_key) && only_minted_token( + mint, + oracle_nft, + "", + -1, + ) + } + } + _ -> False + } +} diff --git a/lib/aiken-virtual-dex/validators/virtual_dex/take_orders.ak b/lib/aiken-virtual-dex/validators/virtual_dex/take_orders.ak index da1b641..6c6bcc2 100644 --- a/lib/aiken-virtual-dex/validators/virtual_dex/take_orders.ak +++ b/lib/aiken-virtual-dex/validators/virtual_dex/take_orders.ak @@ -8,7 +8,7 @@ use aiken/transaction/value.{ use aiken_virtual_dex/common.{ only_input_datum_with, output_inline_datum, value_geq, } -use aiken_virtual_dex/types.{OracleDatum, VirtualDexDatum} +use aiken_virtual_dex/types.{DexOracleDatum, VirtualDexDatum} use sidan_utils/address.{address_script_hash} use sidan_utils/extra_signatories.{key_signed} @@ -16,58 +16,54 @@ pub fn accumulate_all_to_return_value( long_token: (PolicyId, AssetName), short_token: (PolicyId, AssetName), inputs: List, -) -> (Bool, Option
, Pairs, Int) { + dex_address: Address, +) -> (Pairs, Int) { list.foldr( inputs, - (True, None, [], 0), - fn(input: Input, acc: (Bool, Option
, Pairs, Int)) { + ([], 0), + fn(input: Input, acc: (Pairs, Int)) { when address_script_hash(input.output.address) is { None -> acc Some(_) -> { let current_address = input.output.address - let is_address_valid = - when acc.2nd is { - None -> True - Some(script_address) -> script_address == current_address + if current_address != dex_address { + acc + } else { + expect VirtualDexDatum { + account_address, + is_long, + list_price_times_1mil, + lot_size, + extra_lovelace, + }: VirtualDexDatum = output_inline_datum(input.output) + let current_item = pairs.get_first(acc.1st, account_address) + let to_return_value = + if is_long { + from_asset(long_token.1st, long_token.2nd, lot_size) + } else { + from_asset( + short_token.1st, + short_token.2nd, + list_price_times_1mil * lot_size / 1000000, + ) + } + |> merge(from_lovelace(extra_lovelace)) + when current_item is { + None -> + ( + acc.1st + |> list.push(Pair(account_address, to_return_value)), + acc.2nd + lot_size, + ) + Some(value) -> + ( + acc.1st + |> list.push( + Pair(account_address, merge(value, to_return_value)), + ), + acc.2nd + lot_size, + ) } - expect VirtualDexDatum { - account_address, - is_long, - list_price_times_1mil, - lot_size, - extra_lovelace, - }: VirtualDexDatum = output_inline_datum(input.output) - let current_item = pairs.get_first(acc.3rd, account_address) - let to_return_value = - if is_long { - from_asset(long_token.1st, long_token.2nd, lot_size) - } else { - from_asset( - short_token.1st, - short_token.2nd, - list_price_times_1mil * lot_size / 1000000, - ) - } - |> merge(from_lovelace(extra_lovelace)) - when current_item is { - None -> - ( - is_address_valid, - Some(current_address), - acc.3rd - |> list.push(Pair(account_address, to_return_value)), - acc.4th + lot_size, - ) - Some(value) -> - ( - is_address_valid, - Some(current_address), - acc.3rd - |> list.push( - Pair(account_address, merge(value, to_return_value)), - ), - acc.4th + lot_size, - ) } } } @@ -103,10 +99,15 @@ pub fn virtual_dex_take_orders_logic( expect WithdrawFrom(_) = purpose let Transaction { reference_inputs, inputs, outputs, .. } = transaction - expect OracleDatum { operation_key, .. }: OracleDatum = + expect DexOracleDatum { operation_key, dex_address, .. }: DexOracleDatum = only_input_datum_with(reference_inputs, oracle_nft, "") - let (is_only_one_script_address, _, trade_payment_map, _long_token_quantity) = - accumulate_all_to_return_value(param_long_token, param_short_token, inputs) + let (trade_payment_map, _long_token_quantity) = + accumulate_all_to_return_value( + param_long_token, + param_short_token, + inputs, + dex_address, + ) let payment_values = accumuate_all_payment_value(outputs) let is_operation_key_signed = key_signed(transaction.extra_signatories, operation_key) @@ -129,5 +130,5 @@ pub fn virtual_dex_take_orders_logic( let is_token_paid_to_makers = trade_payment_map |> list.all(is_token_paid_to_inidividual_maker) - is_only_one_script_address && is_operation_key_signed && is_token_paid_to_makers + is_operation_key_signed && is_token_paid_to_makers } diff --git a/lib/aiken-virtual-dex/validators/virtual_dex/virtual_dex.ak b/lib/aiken-virtual-dex/validators/virtual_dex/virtual_dex.ak index d9b5e92..93de95f 100644 --- a/lib/aiken-virtual-dex/validators/virtual_dex/virtual_dex.ak +++ b/lib/aiken-virtual-dex/validators/virtual_dex/virtual_dex.ak @@ -1,4 +1,5 @@ use aiken/hash.{Blake2b_224, Hash} +use aiken/pairs use aiken/transaction.{ Input, Output, ScriptContext, Spend, Transaction, find_input, } @@ -6,7 +7,7 @@ use aiken/transaction/credential.{Inline, Script, ScriptCredential} use aiken/transaction/value.{PolicyId} use aiken_virtual_dex/common.{inputs_at, only_input_datum_with, outputs_at} use aiken_virtual_dex/types.{ - CancelOrder, EmergencyCancel, OracleDatum, TakeOrders, VirtualDexDatum, + CancelOrder, DexOracleDatum, EmergencyCancel, TakeOrders, VirtualDexDatum, VirtualDexRedeemer, } use aiken_virtual_dex/utils.{get_emergency_token_name} @@ -25,13 +26,10 @@ pub fn virtual_dex_logic( when redeemer is { TakeOrders -> - when transaction.withdrawals is { - [Pair(stake_cred, _)] -> { - expect Inline(ScriptCredential(stake_script_hash)) = stake_cred - stake_script_hash == take_orders - } - _ -> False - } + pairs.has_key( + transaction.withdrawals, + Inline(ScriptCredential(take_orders)), + ) CancelOrder -> { expect Spend(own_utxo) = purpose @@ -46,7 +44,7 @@ pub fn virtual_dex_logic( expect Some(input) = find_input(transaction.inputs, own_utxo) expect [own_input] = inputs_at(inputs, input.output.address) expect [trade_output] = outputs_at(outputs, account_address) - expect OracleDatum { operation_key, .. }: OracleDatum = + expect DexOracleDatum { operation_key, .. }: DexOracleDatum = only_input_datum_with(reference_inputs, oracle_nft, "") let is_order_value_returned = own_input.output.value == trade_output.value let is_operation_key_signed = key_signed(extra_signatories, operation_key) diff --git a/plutus.json b/plutus.json index 01c8f51..537036d 100644 --- a/plutus.json +++ b/plutus.json @@ -77,13 +77,13 @@ "datum": { "title": "datum", "schema": { - "$ref": "#/definitions/aiken_virtual_dex~1types~1OracleDatum" + "$ref": "#/definitions/aiken_virtual_dex~1types~1AccountOracleDatum" } }, "redeemer": { "title": "redeemer", "schema": { - "$ref": "#/definitions/aiken_virtual_dex~1types~1OracleRedeemer" + "$ref": "#/definitions/aiken_virtual_dex~1types~1AccountOracleRedeemer" } }, "compiledCode": "59055501000032323232323232323222232323232533300a32323232323253330103370e900100089919191919191919191919191919191919191919299981219b87480000044c8c8c8c8c8c94ccc0b4c0c00084c94ccc0accdc3a40086054002264646464a66605e64646600200200444a66606a00229444c8c94ccc0d0cc0a80640084cc010010004528181c8011bae3037001330333752010660666ea40352f5c020022940cdd78011919ba548000cc0ccc0d0004cc0ccc0d0c0d4004cc0ccdd4805198199ba90084bd7018160159813000981880098148008b18179818181818140008b1817000991980080080b1129998168008a5eb804c8c94ccc0b14ccc0b0cdd798189815001006899b873232323253330303370e90010008a400026eb4c0d4c0b8008c0b8004c94ccc0bccdc3a4004002298103d87a8000132323300100100222533303500114c103d87a800013232323253330363371e9110000213374a90001981d1ba80014bd700998030030019bad3037003375c606a0046072004606e0026eacc0d0c0b4008c0b4004c8cc004004008894ccc0c80045300103d87a800013232323253330333371e02c004266e95200033037374c00297ae0133006006003375660680066eb8c0c8008c0d8008c0d0004dd59818981918150012400429404cc0c0008cc0100100044cc010010004c0c4008c0bc004dd7181600098160011bae302a0013022020153330243301a009002132533302800114a0264a666052002264646464a666054a66605466e3c0040344cdc78012450014a0266e1c00d200114a06eb8c0b800cdd7181698170011bad302c302d302d001375860560042940c0ac004c8c8cc004004008894ccc0a800452f5c0264666444646600200200644a6660600022006264660646e9ccc0c8dd4803198191ba9375c605e002660646ea0dd69818000a5eb80cc00c00cc0d0008c0c8004dd718148009bab302a00133003003302e002302c001323300100100f22533302900114bd6f7b630099191919299981519b8f488100002100313302e337606ea4008dd3000998030030019bab302b003375c6052004605a00460560022940c08807cdd7181380098138009813001181200098120011bae3022001301a019375860400026040002603e002603c002603a0046eacc06c004c06c004c068008dd6180c000980c000980b80098070020a50300e001301300130130023011001300900622323300100100322533301100114a026464a66602066e3c008014528899802002000980a8011bae301300114984d958c94ccc028cdc3a4000002264646464a66602260280042930b1bae30120013012002375c6020002601000c2a66601466e1d20020011533300d300800614985858c020014c0040148c94ccc024cdc3a400000226464646464646464a666028602e0042649319299980919b87480000044c8c8c8c94ccc064c0700084c8c9263253330183370e900000089919299980e981000109924c64a66603666e1d20000011323253330203023002132498c05c00458c084004c06400854ccc06ccdc3a40040022646464646464a666048604e0042930b1bad30250013025002375a604600260460046eb4c084004c06400858c06400458c078004c05800c54ccc060cdc3a40040022a666036602c0062930b0b180b00118080018b180d000980d001180c00098080030b18080028b1bae30150013015002375c60260026026004602200260220046eb8c03c004c01c00858c01c0048c94ccc020cdc3a400000226464a66601a60200042930b1bae300e0013006002153330083370e900100089919299980698080010a4c2c6eb8c038004c01800858c0180048c014dd5000918019baa0015734aae7555cf2ab9f5740ae855d11", @@ -431,11 +431,11 @@ } ] }, - "aiken_virtual_dex/types/OracleDatum": { - "title": "OracleDatum", + "aiken_virtual_dex/types/AccountOracleDatum": { + "title": "AccountOracleDatum", "anyOf": [ { - "title": "OracleDatum", + "title": "AccountOracleDatum", "dataType": "constructor", "index": 0, "fields": [ @@ -459,8 +459,8 @@ } ] }, - "aiken_virtual_dex/types/OracleRedeemer": { - "title": "OracleRedeemer", + "aiken_virtual_dex/types/AccountOracleRedeemer": { + "title": "AccountOracleRedeemer", "anyOf": [ { "title": "RotateKey", diff --git a/specs/0_scripts.md b/specs/0_scripts.md index 13a5f7a..ea59780 100644 --- a/specs/0_scripts.md +++ b/specs/0_scripts.md @@ -6,13 +6,13 @@ There are in total 6 scripts for the DeltaDeFi virtual dex to work. Below provid - The one time minting policy, minting the NFT to be reference token locking in `OracleValidator`. It is used for serving static app information. -2. OracleValidator - [specification](./2_oracle_validator.md) +2. EmergencyToken - [specification](./2_emergency_token.md) - - The validator locking `OracleNFT`, for serving app static information while protecting information integrity. + - The minting policy for taking any withdrawal / cancel actions solely by users. -3. EmergencyToken - [specification](./3_emergency_token.md) +3. AccountOracle - [specification](./3_account_oracle.md) - - The minting policy for taking any withdrawal / cancel actions solely by users. + - The validator locking `OracleNFT`, for serving app static information on `Account` while protecting information integrity. 4. Account - [specification](./4_account/4_account.md) @@ -23,11 +23,15 @@ There are in total 6 scripts for the DeltaDeFi virtual dex to work. Below provid - 4.3: Emergency Unlock Phase 1 - [specification](./4_account/4.3_emergency_unlock_phase1.md) - 4.4: Emergency Unlock Phase 2- [specification](./4_account/4.4_emergency_unlock_phase2.md) -5. VirtualDEX - [specification](./5_virtual_dex/5_virtual_dex.md) +5. DexOracle - [specification](./5_account_oracle.md) + + - The validator locking a specific `OracleNFT`, for serving app static information on `VirtualDEX` while protecting information integrity. + +6. VirtualDEX - [specification](./6_virtual_dex/6_virtual_dex.md) - The script governing the transaction logic. - Action specification: - - 5.1: Take Orders - [specification](./5_virtual_dex/5.1_take_orders.md) + - 5.1: Take Orders - [specification](./6_virtual_dex/6.1_take_orders.md) ## Param Dependency Graph diff --git a/specs/3_emergency_token.md b/specs/2_emergency_token.md similarity index 100% rename from specs/3_emergency_token.md rename to specs/2_emergency_token.md diff --git a/specs/2_oracle_validator.md b/specs/3_account_oracle.md similarity index 100% rename from specs/2_oracle_validator.md rename to specs/3_account_oracle.md diff --git a/specs/4_account/4.3_emergency_unlock_phase1.md b/specs/4_account/4.3_emergency_unlock_phase1.md index 4a7641d..8b3b9df 100644 --- a/specs/4_account/4.3_emergency_unlock_phase1.md +++ b/specs/4_account/4.3_emergency_unlock_phase1.md @@ -4,7 +4,7 @@ - `emergency_token`: The policy id of the emergency token -1. Emergency operation - Redeemer `AccountEmergencyActionPhase1Redeemer { owner, own_input, initiate_before }` +1. Emergency operation - Redeemer `AccountEmergencyPhase1Redeemer { owner, own_input, initiate_before }` - Signed by owner - `emergency_token` is minted diff --git a/specs/5_dex_oracle.md b/specs/5_dex_oracle.md new file mode 100644 index 0000000..596b8c3 --- /dev/null +++ b/specs/5_dex_oracle.md @@ -0,0 +1,24 @@ +# Specification - DexOracle + +## Parameter + +## Datum + +- `oracle_nft`: The policy id of `OracleNFT` +- `oracle_address`: The address of the current oracle validator +- `dex_address`: The address of the dex +- `operation_key`: The key for operation use. E.g. processing orders +- `stop_key`: The key for stopping the services + +## User Action + +1. Rotate operation and stop keys - Redeemer `DexRotateKey {new_operation_key, new_stop_key}` + + - Only 1 input from oracle address + - The only 1 output datum is updated with new operation key and stop key + - Required signers include both original and the new stop key + +2. Stop the oracle validator - Redeemer `StopDex` + + - The transaction is signed by stop key + - The `OracleNFT` is burnt diff --git a/specs/5_virtual_dex/5.1_take_orders.md b/specs/6_virtual_dex/6.1_take_orders.md similarity index 100% rename from specs/5_virtual_dex/5.1_take_orders.md rename to specs/6_virtual_dex/6.1_take_orders.md diff --git a/specs/5_virtual_dex/5_virtual_dex.md b/specs/6_virtual_dex/6_virtual_dex.md similarity index 100% rename from specs/5_virtual_dex/5_virtual_dex.md rename to specs/6_virtual_dex/6_virtual_dex.md diff --git a/validators/account/emergency_unlock_phase1.ak b/validators/account/emergency_unlock_phase1.ak index 02bd571..cff2893 100644 --- a/validators/account/emergency_unlock_phase1.ak +++ b/validators/account/emergency_unlock_phase1.ak @@ -1,13 +1,13 @@ use aiken/transaction.{ScriptContext} use aiken/transaction/value.{PolicyId} -use aiken_virtual_dex/types.{AccountEmergencyActionPhase1Redeemer} +use aiken_virtual_dex/types.{AccountEmergencyPhase1Redeemer} use aiken_virtual_dex/validators/account/emergency_unlock_phase1.{ account_emergency_unlock_phase_1_logic, } validator(emergency_token: PolicyId) { pub fn account_emergency_unlock_phase_1( - redeemer: AccountEmergencyActionPhase1Redeemer, + redeemer: AccountEmergencyPhase1Redeemer, context: ScriptContext, ) -> Bool { account_emergency_unlock_phase_1_logic(emergency_token, redeemer, context) diff --git a/validators/account_oracle.ak b/validators/account_oracle.ak new file mode 100644 index 0000000..561d0ec --- /dev/null +++ b/validators/account_oracle.ak @@ -0,0 +1,13 @@ +use aiken/transaction.{ScriptContext} +use aiken_virtual_dex/types.{AccountOracleDatum, AccountOracleRedeemer} +use aiken_virtual_dex/validators/account_oracle.{account_oracle_logic} + +validator { + fn account_oracle( + datum: AccountOracleDatum, + redeemer: AccountOracleRedeemer, + context: ScriptContext, + ) { + account_oracle_logic(datum, redeemer, context) + } +} diff --git a/validators/oracle_validator.ak b/validators/oracle_validator.ak deleted file mode 100644 index f845794..0000000 --- a/validators/oracle_validator.ak +++ /dev/null @@ -1,13 +0,0 @@ -use aiken/transaction.{ScriptContext} -use aiken_virtual_dex/types.{OracleDatum, OracleRedeemer} -use aiken_virtual_dex/validators/oracle_validator.{oracle_validator_logic} - -validator { - fn oracle_validator( - datum: OracleDatum, - redeemer: OracleRedeemer, - context: ScriptContext, - ) { - oracle_validator_logic(datum, redeemer, context) - } -} diff --git a/validators/tests/integration-tests/mass_fill_order.ak b/validators/tests/integration-tests/mass_fill_order.ak index fc60b1a..20b5f9e 100644 --- a/validators/tests/integration-tests/mass_fill_order.ak +++ b/validators/tests/integration-tests/mass_fill_order.ak @@ -1,60 +1,167 @@ -// use aiken/transaction.{ -// InlineDatum, Input, Output, ScriptContext, Transaction, WithdrawFrom, -// } -// use aiken/transaction/credential.{Inline, ScriptCredential} -// use aiken/transaction/value.{from_asset} -// use aiken_virtual_dex/placeholder.{ -// ada_asset_class, mock_account_address, mock_buy_ada_order_input, -// mock_fee_output, mock_operation_key, mock_oracle_address, -// mock_oracle_policy_id, mock_oracle_ref_input, mock_post_trade_account_output, -// mock_token_asset_class, script_hash_5_1, -// } -// use aiken_virtual_dex/types.{TakeOrders, VirtualDexDatum} -// use aiken_virtual_dex/validators/virtual_dex/take_orders.{ -// virtual_dex_take_orders_logic, -// } -// use sidan_placeholder/builder.{ -// complete, new_tx_tester, required_signer_hash, script_withdrawal, -// } -// use sidan_placeholder/output_reference.{mock_utxo_ref} -// use sidan_placeholder/transaction.{add_input, -// add_output, add_reference_input} as sidan_transaction -// use tests/unit_tests/virtual_dex/virtual_dex.{virtual_dex_process} as tvirtual_dex - -// fn add_buy_ada_order_inputs(tx: Transaction, count: Int) -> Transaction { -// todo -// } - -// fn take_order_test(buy_count: Int, sell_count: Int) -> Transaction { -// let token_lot_size = 310_000_000 -// let ada_lot_size = 500_000_000 -// let min_fee = 2_000_000 -// let list_price_times_1mil = ada_lot_size * 1000000 / token_lot_size -// let percentage_fee_times_10k = 5 - -// new_tx_tester() -// |> script_withdrawal(True, script_hash_5_1(), 0) -// |> required_signer_hash(True, mock_operation_key()) -// |> complete() -// |> add_reference_input(True, mock_oracle_ref_input()) -// |> add_output( -// True, -// mock_fee_output(ada_lot_size * 3, min_fee, percentage_fee_times_10k), -// ) -// |> add_output( -// True, -// mock_post_trade_account_output(from_asset("", "", ada_lot_size * 3)), -// ) -// |> add_input( -// True, -// mock_buy_ada_order_input(1, list_price_times_1mil, ada_lot_size, 0), -// ) -// |> add_input( -// True, -// mock_buy_ada_order_input(2, list_price_times_1mil, ada_lot_size, 0), -// ) -// |> add_input( -// True, -// mock_buy_ada_order_input(3, list_price_times_1mil, ada_lot_size, 0), -// ) -// } +use aiken/list +use aiken/transaction.{ScriptContext, Transaction, WithdrawFrom} +use aiken/transaction/credential.{Inline, ScriptCredential} +use aiken/transaction/value.{from_asset} +use aiken_virtual_dex/placeholder.{ + ada_asset_class, mock_account_address, mock_account_oracle_policy_id, + mock_account_oracle_ref_input, mock_buy_ada_order_input, + mock_dex_oracle_policy_id, mock_dex_oracle_ref_input, mock_fee_output, + mock_operation_key, mock_post_trade_account_output, mock_token_asset_class, + mock_trade_input, mock_user_vkey_hex, script_hash_4_1, script_hash_5_1, +} +use aiken_virtual_dex/types.{AccountUserUnlock, TakeOrders, VirtualDexDatum} +use aiken_virtual_dex/validators/account/user_unlock.{account_user_unlock_logic} +use aiken_virtual_dex/validators/virtual_dex/take_orders.{ + virtual_dex_take_orders_logic, +} +use sidan_placeholder/builder.{ + complete, new_tx_tester, required_signer_hash, script_withdrawal, +} +use sidan_placeholder/transaction.{add_input, + add_output, add_reference_input} as sidan_transaction +use tests/unit_tests/account/account.{account_process} +use tests/unit_tests/virtual_dex/virtual_dex.{virtual_dex_process} as tvirtual_dex + +fn add_buy_ada_order_inputs( + tx: Transaction, + count: Int, + token_lot_size: Int, + ada_lot_size: Int, + extra_lovelace: Int, + fee_lovelace: Int, +) -> Transaction { + let list_price_times_1mil = ada_lot_size * 1000000 / token_lot_size + let count_list = list.range(1, count) + list.foldr( + count_list, + tx, + fn(index, tx_acc) { + tx_acc + |> add_input( + True, + mock_buy_ada_order_input( + 50 + index, + list_price_times_1mil, + token_lot_size, + extra_lovelace, + fee_lovelace, + ), + ) + }, + ) +} + +fn take_order_test(buy_count: Int) -> Transaction { + let token_lot_size = 310_000_000 + let ada_lot_size = 500_000_000 + let min_fee = 2_000_000 + let percentage_fee_times_10k = 5 + let extra_lovelace = 4_750_000 + let fee_per_limit_order = 250_000 + + let to_maker = ( ada_lot_size + extra_lovelace ) * buy_count + + let count_list = list.range(1, buy_count) + + let tx = + new_tx_tester() + |> required_signer_hash(True, mock_user_vkey_hex()) + |> script_withdrawal(True, script_hash_4_1(), 0) + |> script_withdrawal(True, script_hash_5_1(), 0) + |> required_signer_hash(True, mock_operation_key()) + |> complete() + |> add_reference_input(True, mock_dex_oracle_ref_input()) + |> add_reference_input(True, mock_account_oracle_ref_input()) + |> add_output( + True, + mock_fee_output(ada_lot_size * 3, min_fee, percentage_fee_times_10k), + ) + |> add_output( + True, + mock_post_trade_account_output(from_asset("", "", to_maker)), + ) + |> add_buy_ada_order_inputs( + buy_count, + token_lot_size, + ada_lot_size, + extra_lovelace, + fee_per_limit_order, + ) + list.foldr( + count_list, + tx, + fn(index, tx_acc) { + tx_acc + |> add_input(True, mock_trade_input(index)) + |> add_input(True, mock_trade_input(index + 50)) + }, + ) +} + +fn mass_virtual_dex_processing( + count: Int, + tx: Transaction, + dat: VirtualDexDatum, +) { + let count_list = list.range(1, count) + list.foldr( + count_list, + True, + fn(index, acc) { acc && virtual_dex_process(index, tx, dat, TakeOrders) }, + ) +} + +fn mass_account_utxo_processing(count: Int, tx: Transaction) { + let count_list = list.range(1, count) + list.foldr( + count_list, + True, + fn(index, acc) { + acc && account_process(index, tx, AccountUserUnlock) && account_process( + index + 50, + tx, + AccountUserUnlock, + ) + }, + ) +} + +test integration_test_mass_take_orders() { + let number_of_orders = 20 + + let dat = + VirtualDexDatum { + account_address: mock_account_address(), + is_long: True, + list_price_times_1mil: 60000, + lot_size: 500, + extra_lovelace: 0, + } + let tx = take_order_test(number_of_orders) + let dex_ctx = + ScriptContext { + purpose: WithdrawFrom(Inline(ScriptCredential(script_hash_5_1()))), + transaction: tx, + } + let account_ctx = + ScriptContext { + purpose: WithdrawFrom(Inline(ScriptCredential(script_hash_4_1()))), + transaction: tx, + } + mass_account_utxo_processing(number_of_orders, tx) && mass_virtual_dex_processing( + number_of_orders, + tx, + dat, + ) && virtual_dex_take_orders_logic( + mock_dex_oracle_policy_id(), + ada_asset_class(), + mock_token_asset_class(), + Void, + dex_ctx, + ) && account_user_unlock_logic( + mock_account_oracle_policy_id(), + mock_user_vkey_hex(), + Void, + account_ctx, + ) +} diff --git a/validators/tests/unit-tests/account/app_unlock.ak b/validators/tests/unit-tests/account/app_unlock.ak index adca681..f02fc05 100644 --- a/validators/tests/unit-tests/account/app_unlock.ak +++ b/validators/tests/unit-tests/account/app_unlock.ak @@ -2,8 +2,9 @@ use aiken/transaction.{ScriptContext, WithdrawFrom} use aiken/transaction/credential.{Inline, ScriptCredential} use aiken/transaction/value.{from_lovelace} use aiken_virtual_dex/placeholder.{ - mock_account_address, mock_another_account_address, mock_operation_key, - mock_oracle_policy_id, mock_oracle_ref_input, script_hash_4_2, + mock_account_address, mock_account_oracle_policy_id, + mock_account_oracle_ref_input, mock_another_account_address, + mock_operation_key, script_hash_4_2, } use aiken_virtual_dex/types.{AccountAppUnlock, AccountNormalDatum} use aiken_virtual_dex/validators/account/app_unlock.{account_app_unlock_logic} @@ -87,7 +88,7 @@ fn mock_test_case_4_2(number_of_inputs: Int, test_case: TestCase42) { |> required_signer_hash(is_operation_key_signed, mock_operation_key()) |> script_withdrawal(is_withdrawal_script_present, script_hash_4_2(), 0) |> complete() - |> add_reference_input(True, mock_oracle_ref_input()) + |> add_reference_input(True, mock_account_oracle_ref_input()) } test t4_2_success() { @@ -98,7 +99,7 @@ test t4_2_success() { transaction: tx, } account_process(0, tx, AccountAppUnlock) && account_app_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), Void, withdrawal_ctx, ) @@ -116,7 +117,7 @@ test t4_2_failed_without_operation_key_signed() { transaction: tx, } account_process(0, tx, AccountAppUnlock) && !account_app_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), Void, withdrawal_ctx, ) @@ -137,7 +138,7 @@ test t4_2_failed_without_value_resepnt_into_account() { transaction: tx, } account_process(0, tx, AccountAppUnlock) && !account_app_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), Void, withdrawal_ctx, ) @@ -155,7 +156,7 @@ test t4_2_failed_with_other_account_unlock_attempt() { transaction: tx, } account_process(0, tx, AccountAppUnlock) && !account_app_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), Void, withdrawal_ctx, ) @@ -173,7 +174,7 @@ test t4_2_failed_without_withdrawal_script_present() { transaction: tx, } !account_process(0, tx, AccountAppUnlock) && account_app_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), Void, withdrawal_ctx, ) diff --git a/validators/tests/unit-tests/account/emergency_unlock_phase1.ak b/validators/tests/unit-tests/account/emergency_unlock_phase1.ak index ebc641e..2c53f23 100644 --- a/validators/tests/unit-tests/account/emergency_unlock_phase1.ak +++ b/validators/tests/unit-tests/account/emergency_unlock_phase1.ak @@ -6,7 +6,7 @@ use aiken_virtual_dex/placeholder.{ mock_operation_key, mock_user_vkey_hex, script_hash_4_3, } use aiken_virtual_dex/types.{ - AccountEmergencyActionPhase1Redeemer, AccountEmergencyUnlockPhase1, + AccountEmergencyPhase1Redeemer, AccountEmergencyUnlockPhase1, } use aiken_virtual_dex/utils.{get_emergency_token_name} use aiken_virtual_dex/validators/account/emergency_unlock_phase1.{ @@ -42,7 +42,7 @@ fn base_test_case() { } fn mock_redeemer() { - AccountEmergencyActionPhase1Redeemer { + AccountEmergencyPhase1Redeemer { owner: mock_user_vkey_hex(), own_input: mock_emergency_unlock_phase1_input(1), initiate_before: 100, diff --git a/validators/tests/unit-tests/account/user_unlock.ak b/validators/tests/unit-tests/account/user_unlock.ak index a48ae9d..128a435 100644 --- a/validators/tests/unit-tests/account/user_unlock.ak +++ b/validators/tests/unit-tests/account/user_unlock.ak @@ -1,8 +1,8 @@ use aiken/transaction.{ScriptContext, WithdrawFrom} use aiken/transaction/credential.{Inline, ScriptCredential} use aiken_virtual_dex/placeholder.{ - mock_operation_key, mock_oracle_policy_id, mock_oracle_ref_input, - mock_user_vkey_hex, script_hash_4_1, + mock_account_oracle_policy_id, mock_account_oracle_ref_input, + mock_operation_key, mock_user_vkey_hex, script_hash_4_1, } use aiken_virtual_dex/types.{AccountUserUnlock} use aiken_virtual_dex/validators/account/user_unlock.{account_user_unlock_logic} @@ -38,7 +38,7 @@ fn mock_test_case_4_1(test_case: TestCase41) { |> required_signer_hash(is_operation_key_signed, mock_operation_key()) |> script_withdrawal(is_withdrawal_script_present, script_hash_4_1(), 0) |> complete() - |> add_reference_input(True, mock_oracle_ref_input()) + |> add_reference_input(True, mock_account_oracle_ref_input()) } test t4_1_success() { @@ -50,7 +50,7 @@ test t4_1_success() { transaction: tx, } account_process(1, tx, redeemer) && account_user_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), mock_user_vkey_hex(), Void, withdrawal_ctx, @@ -71,7 +71,7 @@ test t4_1_success_mass() { let unlock_process = fn(index: Int) { account_process(index, tx, redeemer) } unlock_process(0) && unlock_process(1) && unlock_process(2) && account_user_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), mock_user_vkey_hex(), Void, withdrawal_ctx, @@ -90,7 +90,7 @@ test t4_1_fail_without_owner_signed() { transaction: tx, } account_process(1, tx, redeemer) && !account_user_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), mock_user_vkey_hex(), Void, withdrawal_ctx, @@ -109,7 +109,7 @@ test t4_1_fail_without_app_signed() { transaction: tx, } account_process(1, tx, redeemer) && !account_user_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), mock_user_vkey_hex(), Void, withdrawal_ctx, @@ -128,7 +128,7 @@ test t4_1_fail_without_withdrawal_script_present() { transaction: tx, } !account_process(1, tx, redeemer) && account_user_unlock_logic( - mock_oracle_policy_id(), + mock_account_oracle_policy_id(), mock_user_vkey_hex(), Void, withdrawal_ctx, diff --git a/validators/tests/unit-tests/oracle_validator.ak b/validators/tests/unit-tests/account_oracle.ak similarity index 67% rename from validators/tests/unit-tests/oracle_validator.ak rename to validators/tests/unit-tests/account_oracle.ak index f2da36d..001f4ec 100644 --- a/validators/tests/unit-tests/oracle_validator.ak +++ b/validators/tests/unit-tests/account_oracle.ak @@ -2,11 +2,12 @@ use aiken/list use aiken/transaction.{Input, ScriptContext, Spend, Transaction, placeholder} use aiken/transaction/value.{from_asset, to_minted_value} use aiken_virtual_dex/placeholder.{ - mock_operation_key, mock_oracle_datum, mock_oracle_output, mock_stop_key, + mock_account_oracle_datum, mock_account_oracle_output, + mock_account_oracle_policy_id, mock_operation_key, mock_stop_key, } -use aiken_virtual_dex/types.{OracleDatum, RotateKey, StopApp} -use aiken_virtual_dex/validators/oracle_validator.{oracle_validator_logic} -use sidan_placeholder/key_hex.{mock_policy_id, mock_pub_key_hex} +use aiken_virtual_dex/types.{AccountOracleDatum, RotateKey, StopApp} +use aiken_virtual_dex/validators/account_oracle.{account_oracle_logic} +use sidan_placeholder/key_hex.{mock_pub_key_hex} use sidan_placeholder/output_reference.{mock_utxo_ref} type RotateTestCase { @@ -50,21 +51,21 @@ fn mock_rotate_test_case(test_case: RotateTestCase) { ) let new_datum = if is_datum_updated { - OracleDatum { - ..mock_oracle_datum(), + AccountOracleDatum { + ..mock_account_oracle_datum(), operation_key: mock_stop_key(), stop_key: new_stop_key, } } else { - mock_oracle_datum() + mock_account_oracle_datum() } let input = Input { output_reference: input_utxo, - output: mock_oracle_output(mock_oracle_datum()), + output: mock_account_oracle_output(mock_account_oracle_datum()), } - let output = mock_oracle_output(new_datum) + let output = mock_account_oracle_output(new_datum) Transaction { ..placeholder(), inputs: [input], @@ -73,7 +74,7 @@ fn mock_rotate_test_case(test_case: RotateTestCase) { } } -test success_rotate_key() { +test t3_1_success_rotate_key() { let redeemer = RotateKey { new_operation_key: mock_stop_key(), @@ -84,10 +85,10 @@ test success_rotate_key() { let tx = mock_rotate_test_case(base_rotate_test_case()) let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } - oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } -test fail_rotate_key_without_old_stop_signature() { +test t3_1_fail_rotate_key_without_old_stop_signature() { let redeemer = RotateKey { new_operation_key: mock_stop_key(), @@ -104,10 +105,10 @@ test fail_rotate_key_without_old_stop_signature() { ) let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } - !oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + !account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } -test fail_rotate_key_without_new_stop_signature() { +test t3_1_fail_rotate_key_without_new_stop_signature() { let redeemer = RotateKey { new_operation_key: mock_stop_key(), @@ -124,49 +125,51 @@ test fail_rotate_key_without_new_stop_signature() { ) let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } - !oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + !account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } // test fail_ -test success_stop_app() { +test t3_2_success_stop_app() { let redeemer = StopApp let tx = Transaction { ..placeholder(), - mint: to_minted_value(from_asset(mock_policy_id(0), "", -1)), + mint: to_minted_value(from_asset(mock_account_oracle_policy_id(), "", -1)), extra_signatories: [mock_pub_key_hex(2)], } let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } - oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } -test fail_stop_app_without_stop_key() { +test t3_2_fail_stop_app_without_stop_key() { let redeemer = StopApp let tx = Transaction { ..placeholder(), - mint: to_minted_value(from_asset(mock_policy_id(0), "", -1)), + mint: to_minted_value(from_asset(mock_account_oracle_policy_id(), "", -1)), extra_signatories: [mock_operation_key()], } let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } - !oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + !account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } -test success_stop_app_without_oracle_nft_burnt() { +test t3_2_success_stop_app_without_oracle_nft_burnt() { let redeemer = StopApp let tx = Transaction { ..placeholder(), - mint: to_minted_value(from_asset(mock_policy_id(0), "not oracle nft", -1)), + mint: to_minted_value( + from_asset(mock_account_oracle_policy_id(), "not oracle nft", -1), + ), extra_signatories: [mock_stop_key()], } let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } - !oracle_validator_logic(mock_oracle_datum(), redeemer, ctx) + !account_oracle_logic(mock_account_oracle_datum(), redeemer, ctx) } diff --git a/validators/tests/unit-tests/dex_oracle.ak b/validators/tests/unit-tests/dex_oracle.ak new file mode 100644 index 0000000..8f1a587 --- /dev/null +++ b/validators/tests/unit-tests/dex_oracle.ak @@ -0,0 +1,175 @@ +use aiken/list +use aiken/transaction.{Input, ScriptContext, Spend, Transaction, placeholder} +use aiken/transaction/value.{from_asset, to_minted_value} +use aiken_virtual_dex/placeholder.{ + mock_dex_oracle_datum, mock_dex_oracle_output, mock_dex_oracle_policy_id, + mock_operation_key, mock_stop_key, +} +use aiken_virtual_dex/types.{DexOracleDatum, DexRotateKey, StopDex} +use aiken_virtual_dex/validators/dex_oracle.{dex_oracle_logic} +use sidan_placeholder/key_hex.{mock_pub_key_hex} +use sidan_placeholder/output_reference.{mock_utxo_ref} + +type RotateTestCase { + is_old_stop_key_signed: Bool, + is_new_stop_key_signed: Bool, + is_datum_updated: Bool, +} + +fn base_rotate_test_case() { + RotateTestCase { + is_old_stop_key_signed: True, + is_new_stop_key_signed: True, + is_datum_updated: True, + } +} + +fn mock_rotate_test_case(test_case: RotateTestCase) { + let RotateTestCase { + is_old_stop_key_signed, + is_new_stop_key_signed, + is_datum_updated, + } = test_case + let input_utxo = mock_utxo_ref(0, 0) + let new_stop_key = mock_pub_key_hex(3) + + let extra_signatories = + [] + |> list.concat( + if is_old_stop_key_signed { + [mock_stop_key()] + } else { + [] + }, + ) + |> list.concat( + if is_new_stop_key_signed { + [new_stop_key] + } else { + [] + }, + ) + let new_datum = + if is_datum_updated { + DexOracleDatum { + ..mock_dex_oracle_datum(), + operation_key: mock_stop_key(), + stop_key: new_stop_key, + } + } else { + mock_dex_oracle_datum() + } + + let input = + Input { + output_reference: input_utxo, + output: mock_dex_oracle_output(mock_dex_oracle_datum()), + } + let output = mock_dex_oracle_output(new_datum) + Transaction { + ..placeholder(), + inputs: [input], + outputs: [output], + extra_signatories: extra_signatories, + } +} + +test t5_1_success_rotate_key() { + let redeemer = + DexRotateKey { + new_operation_key: mock_stop_key(), + new_stop_key: mock_pub_key_hex(3), + } + let input_utxo = mock_utxo_ref(0, 0) + + let tx = mock_rotate_test_case(base_rotate_test_case()) + let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } + + dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} + +test t5_1_fail_rotate_key_without_old_stop_signature() { + let redeemer = + DexRotateKey { + new_operation_key: mock_stop_key(), + new_stop_key: mock_pub_key_hex(3), + } + let input_utxo = mock_utxo_ref(0, 0) + + let tx = + mock_rotate_test_case( + RotateTestCase { + ..base_rotate_test_case(), + is_old_stop_key_signed: False, + }, + ) + let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } + + !dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} + +test t5_1_fail_rotate_key_without_new_stop_signature() { + let redeemer = + DexRotateKey { + new_operation_key: mock_stop_key(), + new_stop_key: mock_pub_key_hex(3), + } + let input_utxo = mock_utxo_ref(0, 0) + + let tx = + mock_rotate_test_case( + RotateTestCase { + ..base_rotate_test_case(), + is_new_stop_key_signed: False, + }, + ) + let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx } + + !dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} + +// test fail_ + +test t5_2_success_stop_app() { + let redeemer = StopDex + let tx = + Transaction { + ..placeholder(), + mint: to_minted_value(from_asset(mock_dex_oracle_policy_id(), "", -1)), + extra_signatories: [mock_pub_key_hex(2)], + } + let ctx = + ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } + + dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} + +test t5_2_fail_stop_app_without_stop_key() { + let redeemer = StopDex + let tx = + Transaction { + ..placeholder(), + mint: to_minted_value(from_asset(mock_dex_oracle_policy_id(), "", -1)), + extra_signatories: [mock_operation_key()], + } + let ctx = + ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } + + !dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} + +test t5_2_success_stop_app_without_oracle_nft_burnt() { + let redeemer = StopDex + let tx = + Transaction { + ..placeholder(), + mint: to_minted_value( + from_asset(mock_dex_oracle_policy_id(), "not oracle nft", -1), + ), + extra_signatories: [mock_stop_key()], + } + let ctx = + ScriptContext { purpose: Spend(mock_utxo_ref(0, 0)), transaction: tx } + + !dex_oracle_logic(mock_dex_oracle_datum(), redeemer, ctx) +} diff --git a/validators/tests/unit-tests/emergency_token.ak b/validators/tests/unit-tests/emergency_token.ak index f6a4ff9..781de65 100644 --- a/validators/tests/unit-tests/emergency_token.ak +++ b/validators/tests/unit-tests/emergency_token.ak @@ -85,7 +85,7 @@ fn mint_test_case(test_case: TestCase) { } } -test success_mint() { +test t2_1_success_mint() { let redeemer = EMint { current_timestamp: 100, account_address: mock_account_address() } let policy_id = mock_emergency_token() @@ -95,7 +95,7 @@ test success_mint() { emergency_token_logic(redeemer, ctx) } -test fail_mint_without_owner_signature() { +test t2_1_fail_mint_without_owner_signature() { let redeemer = EMint { current_timestamp: 100, account_address: mock_account_address() } let policy_id = mock_emergency_token() @@ -106,7 +106,7 @@ test fail_mint_without_owner_signature() { !emergency_token_logic(redeemer, ctx) } -test fail_mint_with_incorrect_emergency_token_name() { +test t2_1_fail_mint_with_incorrect_emergency_token_name() { let redeemer = EMint { current_timestamp: 100, account_address: mock_account_address() } let policy_id = mock_emergency_token() @@ -119,7 +119,7 @@ test fail_mint_with_incorrect_emergency_token_name() { !emergency_token_logic(redeemer, ctx) } -test fail_mint_without_correct_datum() { +test t2_1_fail_mint_without_correct_datum() { let redeemer = EMint { current_timestamp: 100, account_address: mock_account_address() } let policy_id = mock_emergency_token() @@ -130,7 +130,7 @@ test fail_mint_without_correct_datum() { !emergency_token_logic(redeemer, ctx) } -test fail_mint_with_invalid_time() { +test t2_1_fail_mint_with_invalid_time() { let redeemer = EMint { current_timestamp: 100, account_address: mock_account_address() } let policy_id = mock_emergency_token() @@ -140,7 +140,7 @@ test fail_mint_with_invalid_time() { !emergency_token_logic(redeemer, ctx) } -test success_burn() { +test t2_2_success_burn() { let redeemer = EBurn let policy_id = mock_emergency_token() @@ -153,7 +153,7 @@ test success_burn() { emergency_token_logic(redeemer, ctx) } -test success_burn_with_other_minting() { +test t2_2_success_burn_with_other_minting() { let redeemer = EBurn let policy_id = mock_emergency_token() @@ -168,7 +168,7 @@ test success_burn_with_other_minting() { emergency_token_logic(redeemer, ctx) } -test fail_burn_with_mint() { +test t2_2_fail_burn_with_mint() { let redeemer = EBurn let policy_id = mock_emergency_token() @@ -181,7 +181,7 @@ test fail_burn_with_mint() { !emergency_token_logic(redeemer, ctx) } -test fail_burn_with_mix() { +test t2_2_fail_burn_with_mix() { let redeemer = EBurn let policy_id = mock_emergency_token() diff --git a/validators/tests/unit-tests/virtual_dex/take_orders.ak b/validators/tests/unit-tests/virtual_dex/take_orders.ak index e4f941b..47ebb14 100644 --- a/validators/tests/unit-tests/virtual_dex/take_orders.ak +++ b/validators/tests/unit-tests/virtual_dex/take_orders.ak @@ -1,11 +1,11 @@ -use aiken/transaction.{InlineDatum, Input, Output, ScriptContext, WithdrawFrom} +use aiken/transaction.{ScriptContext, WithdrawFrom} use aiken/transaction/credential.{Inline, ScriptCredential} use aiken/transaction/value.{from_asset} use aiken_virtual_dex/placeholder.{ ada_asset_class, mock_account_address, mock_buy_ada_order_input, - mock_fee_output, mock_operation_key, mock_oracle_address, - mock_oracle_policy_id, mock_oracle_ref_input, mock_post_trade_account_output, - mock_token_asset_class, script_hash_5_1, + mock_dex_oracle_policy_id, mock_dex_oracle_ref_input, mock_fee_output, + mock_operation_key, mock_post_trade_account_output, mock_token_asset_class, + script_hash_5_1, } use aiken_virtual_dex/types.{TakeOrders, VirtualDexDatum} use aiken_virtual_dex/validators/virtual_dex/take_orders.{ @@ -14,23 +14,22 @@ use aiken_virtual_dex/validators/virtual_dex/take_orders.{ use sidan_placeholder/builder.{ complete, new_tx_tester, required_signer_hash, script_withdrawal, } -use sidan_placeholder/output_reference.{mock_utxo_ref} use sidan_placeholder/transaction.{add_input, add_output, add_reference_input} as sidan_transaction use tests/unit_tests/virtual_dex/virtual_dex.{virtual_dex_process} as tvirtual_dex type TestCase51 { is_token_paid_to_maker: Bool, + is_extra_lovelace_returned: Bool, is_operation_key_signed: Bool, - is_only_one_script_address: Bool, is_withdrawal_script_present: Bool, } fn take_order_base_case() { TestCase51 { is_token_paid_to_maker: True, + is_extra_lovelace_returned: True, is_operation_key_signed: True, - is_only_one_script_address: True, is_withdrawal_script_present: True, } } @@ -38,8 +37,8 @@ fn take_order_base_case() { fn take_order_test(test_case: TestCase51) { let TestCase51 { is_token_paid_to_maker, + is_extra_lovelace_returned, is_operation_key_signed, - is_only_one_script_address, is_withdrawal_script_present, } = test_case let token_lot_size = 310_000_000 @@ -52,7 +51,7 @@ fn take_order_test(test_case: TestCase51) { |> script_withdrawal(is_withdrawal_script_present, script_hash_5_1(), 0) |> required_signer_hash(is_operation_key_signed, mock_operation_key()) |> complete() - |> add_reference_input(True, mock_oracle_ref_input()) + |> add_reference_input(True, mock_dex_oracle_ref_input()) |> add_output( True, mock_fee_output(ada_lot_size * 3, min_fee, percentage_fee_times_10k), @@ -71,45 +70,53 @@ fn take_order_test(test_case: TestCase51) { ), ), ) - |> add_input( + |> add_output( True, - mock_buy_ada_order_input(1, list_price_times_1mil, ada_lot_size, 0), + mock_post_trade_account_output( + from_asset( + "", + "", + if is_extra_lovelace_returned { + 5_000_000 * 3 + } else { + 4_999_999 * 3 + }, + ), + ), ) |> add_input( True, - mock_buy_ada_order_input(2, list_price_times_1mil, ada_lot_size, 0), + mock_buy_ada_order_input( + 1, + list_price_times_1mil, + ada_lot_size, + 5_000_000, + 0, + ), ) |> add_input( True, - mock_buy_ada_order_input(3, list_price_times_1mil, ada_lot_size, 0), + mock_buy_ada_order_input( + 2, + list_price_times_1mil, + ada_lot_size, + 5_000_000, + 0, + ), ) |> add_input( - !is_only_one_script_address, - Input { - output_reference: mock_utxo_ref(1, 51), - output: Output { - address: mock_oracle_address(), - value: from_asset( - mock_token_asset_class().1st, - mock_token_asset_class().2nd, - ada_lot_size, - ), - datum: InlineDatum( - VirtualDexDatum { - account_address: mock_account_address(), - is_long: True, - list_price_times_1mil, - lot_size: ada_lot_size, - extra_lovelace: 0, - }, - ), - reference_script: None, - }, - }, + True, + mock_buy_ada_order_input( + 3, + list_price_times_1mil, + ada_lot_size, + 5_000_000, + 0, + ), ) } -test t5_1_success_take_order() { +test t6_1_success_take_order() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -125,7 +132,7 @@ test t5_1_success_take_order() { transaction: tx, } virtual_dex_process(1, tx, dat, TakeOrders) && virtual_dex_take_orders_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), ada_asset_class(), mock_token_asset_class(), Void, @@ -133,7 +140,7 @@ test t5_1_success_take_order() { ) } -test t5_1_fail_take_order_without_token_paid_to_maker() { +test t6_1_fail_take_order_without_extra_lovelace_returned() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -144,7 +151,7 @@ test t5_1_fail_take_order_without_token_paid_to_maker() { } let tx = take_order_test( - TestCase51 { ..take_order_base_case(), is_token_paid_to_maker: False }, + TestCase51 { ..take_order_base_case(), is_extra_lovelace_returned: False }, ) let withdrawal_ctx = ScriptContext { @@ -152,7 +159,7 @@ test t5_1_fail_take_order_without_token_paid_to_maker() { transaction: tx, } virtual_dex_process(1, tx, dat, TakeOrders) && !virtual_dex_take_orders_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), ada_asset_class(), mock_token_asset_class(), Void, @@ -160,7 +167,7 @@ test t5_1_fail_take_order_without_token_paid_to_maker() { ) } -test t5_1_fail_take_order_without_operation_key_signed() { +test t6_1_fail_take_order_without_token_paid_to_maker() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -171,7 +178,7 @@ test t5_1_fail_take_order_without_operation_key_signed() { } let tx = take_order_test( - TestCase51 { ..take_order_base_case(), is_operation_key_signed: False }, + TestCase51 { ..take_order_base_case(), is_token_paid_to_maker: False }, ) let withdrawal_ctx = ScriptContext { @@ -179,7 +186,7 @@ test t5_1_fail_take_order_without_operation_key_signed() { transaction: tx, } virtual_dex_process(1, tx, dat, TakeOrders) && !virtual_dex_take_orders_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), ada_asset_class(), mock_token_asset_class(), Void, @@ -187,7 +194,7 @@ test t5_1_fail_take_order_without_operation_key_signed() { ) } -test t5_1_fail_take_order_with_more_than_one_script_address() { +test t6_1_fail_take_order_without_operation_key_signed() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -198,7 +205,7 @@ test t5_1_fail_take_order_with_more_than_one_script_address() { } let tx = take_order_test( - TestCase51 { ..take_order_base_case(), is_only_one_script_address: False }, + TestCase51 { ..take_order_base_case(), is_operation_key_signed: False }, ) let withdrawal_ctx = ScriptContext { @@ -206,7 +213,7 @@ test t5_1_fail_take_order_with_more_than_one_script_address() { transaction: tx, } virtual_dex_process(1, tx, dat, TakeOrders) && !virtual_dex_take_orders_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), ada_asset_class(), mock_token_asset_class(), Void, @@ -214,7 +221,7 @@ test t5_1_fail_take_order_with_more_than_one_script_address() { ) } -test t5_1_failed_without_withdrawal_script_present() { +test t6_1_failed_without_withdrawal_script_present() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -236,11 +243,10 @@ test t5_1_failed_without_withdrawal_script_present() { transaction: tx, } !virtual_dex_process(1, tx, dat, TakeOrders) && virtual_dex_take_orders_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), ada_asset_class(), mock_token_asset_class(), Void, withdrawal_ctx, ) } - diff --git a/validators/tests/unit-tests/virtual_dex/virtual_dex.ak b/validators/tests/unit-tests/virtual_dex/virtual_dex.ak index e430892..dab1ea8 100644 --- a/validators/tests/unit-tests/virtual_dex/virtual_dex.ak +++ b/validators/tests/unit-tests/virtual_dex/virtual_dex.ak @@ -4,8 +4,8 @@ use aiken/transaction.{ use aiken/transaction/value.{add, from_asset, to_minted_value} use aiken_virtual_dex/placeholder.{ mock_account_address, mock_another_account_address, mock_buy_ada_order_input, - mock_emergency_token, mock_operation_key, mock_oracle_policy_id, - mock_oracle_ref_input, mock_post_trade_account_output, script_hash_5_1, + mock_dex_oracle_policy_id, mock_dex_oracle_ref_input, mock_emergency_token, + mock_operation_key, mock_post_trade_account_output, script_hash_5_1, } use aiken_virtual_dex/types.{ CancelOrder, EmergencyCancel, VirtualDexDatum, VirtualDexRedeemer, @@ -23,7 +23,7 @@ pub fn virtual_dex_process( let output_reference = mock_utxo_ref(0, 50 + index) let ctx = ScriptContext { purpose: Spend(output_reference), transaction: tx } virtual_dex_logic( - mock_oracle_policy_id(), + mock_dex_oracle_policy_id(), mock_emergency_token(), script_hash_5_1(), datum, @@ -45,14 +45,14 @@ fn cancel_order_test(test_case: TestCase52) { let TestCase52 { is_order_value_returned, is_operation_key_signed } = test_case let inputs = - [mock_buy_ada_order_input(1, 1612000, 310_000_000, 0)] + [mock_buy_ada_order_input(1, 1612000, 310_000_000, 0, 0)] let outputs = [ mock_post_trade_account_output( if is_order_value_returned { - mock_buy_ada_order_input(1, 1612000, 310_000_000, 0).output.value + mock_buy_ada_order_input(1, 1612000, 310_000_000, 0, 0).output.value } else { - mock_buy_ada_order_input(1, 1612000, 310_000_000, 0).output.value + mock_buy_ada_order_input(1, 1612000, 310_000_000, 0, 0).output.value |> add("", "", -1) }, ), @@ -64,7 +64,7 @@ fn cancel_order_test(test_case: TestCase52) { [] } let reference_inputs = - [mock_oracle_ref_input()] + [mock_dex_oracle_ref_input()] Transaction { ..placeholder(), inputs: inputs, @@ -74,7 +74,7 @@ fn cancel_order_test(test_case: TestCase52) { } } -test t5_2_success_cancel_order() { +test t6_2_success_cancel_order() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -88,7 +88,7 @@ test t5_2_success_cancel_order() { virtual_dex_process(1, tx, dat, red) } -test t5_2_fail_cancel_order_without_value_returned() { +test t6_2_fail_cancel_order_without_value_returned() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -105,7 +105,7 @@ test t5_2_fail_cancel_order_without_value_returned() { !virtual_dex_process(1, tx, dat, red) } -test t5_2_fail_cancel_order_without_operation_key_signed() { +test t6_2_fail_cancel_order_without_operation_key_signed() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -126,7 +126,7 @@ test t5_2_fail_cancel_order_without_operation_key_signed() { // is_emergency_token_burnt: Bool, // } -test t5_3_success_emergency_cancel() { +test t6_3_success_emergency_cancel() { let dat = VirtualDexDatum { account_address: mock_account_address(), @@ -151,7 +151,7 @@ test t5_3_success_emergency_cancel() { virtual_dex_process(1, tx, dat, red) } -test t5_3_fail_emergency_cancel_without_emergency_token_burnt() { +test t6_3_fail_emergency_cancel_without_emergency_token_burnt() { let dat = VirtualDexDatum { account_address: mock_account_address(),