Skip to content

Commit

Permalink
ignore checking datum if order's sender or receiver is PubKey address
Browse files Browse the repository at this point in the history
  • Loading branch information
h2physics committed Dec 22, 2023
1 parent 27d68e5 commit 033b4c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
42 changes: 28 additions & 14 deletions lib/amm_dex_v2/order_validation.ak
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use aiken/builtin
use aiken/hash
use aiken/list
use aiken/transaction.{Datum, DatumHash, InlineDatum, Input, NoDatum, Output}
use aiken/transaction/credential.{Address, ScriptCredential}
use aiken/transaction/credential.{
Address, ScriptCredential, VerificationKeyCredential,
}
use aiken/transaction/value.{Value, ada_asset_name, ada_policy_id}
use amm_dex_v2/math
use amm_dex_v2/types.{
Expand Down Expand Up @@ -938,12 +940,17 @@ pub fn validate_order_receiver(
) -> Bool {
let Output { address: output_address, datum: raw_order_output_datum, .. } =
output
and {
receiver == output_address,
is_valid_datum(
raw_datum: raw_order_output_datum,
datum_hash_opt: receiver_datum_hash_opt,
),
let Address { payment_credential: receiver_payment_cred, .. } = receiver
let is_correct_address = receiver == output_address
when receiver_payment_cred is {
VerificationKeyCredential(_) -> is_correct_address
ScriptCredential(_) -> and {
is_correct_address,
is_valid_datum(
raw_datum: raw_order_output_datum,
datum_hash_opt: receiver_datum_hash_opt,
),
}
}
}

Expand All @@ -960,13 +967,20 @@ fn validate_order_output(
..
} = output

and {
receiver == output_address,
is_valid_datum(
raw_datum: raw_order_output_datum,
datum_hash_opt: receiver_datum_hash_opt,
),
value == output_value,
let is_correct_address_and_value = and {
receiver == output_address,
value == output_value,
}
let Address { payment_credential: receiver_payment_cred, .. } = receiver
when receiver_payment_cred is {
VerificationKeyCredential(_) -> is_correct_address_and_value
ScriptCredential(_) -> and {
is_correct_address_and_value,
is_valid_datum(
raw_datum: raw_order_output_datum,
datum_hash_opt: receiver_datum_hash_opt,
),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/amm_dex_v2/types.ak
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub type OrderStep {
pub type OrderDatum {
// The address of order's creator, only sender can cancel the order immediately
sender: Address,
// The datum hash of the output after cancel by KillOnFailed or reach Order Expired time
// The datum hash of the output after being killed by Batcher or cancelled by bots (order is expired)
sender_datum_hash_opt: Option<CustomDatumHash>,
// The address which receives the funds after order is processed
receiver: Address,
Expand Down
Loading

0 comments on commit 033b4c9

Please sign in to comment.