Skip to content

Commit

Permalink
use list.any for better performance and update some wording on commen…
Browse files Browse the repository at this point in the history
…t/docs
  • Loading branch information
h2physics committed Jun 15, 2024
1 parent f25b204 commit 5f4d4bf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions amm-v2-docs/amm-v2-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Pool validator is the most important part in the system. It's responsible for gu
- validate there is a single Pool UTxO in Transaction Inputs and single Pool UTxO in Transaction Outputs and:
- Pool Input contains 1 valid Pool NFT Token
- Pool Input and Output Value must be unchanged
- Transaction contain only 1 Spending Script (Pool Script). It will avoid bad Admin stealing money from Order Contract.
- Transaction spends only one Single Pool Script and does not contain any other scripts in its inputs, except for the Author, in cases where the Author is a script
- validate Transaction won't mint any assets
- Each **UpdatePoolParameters** action has limited power to change some of Pool's parameters and stake address. Otherwise, it's not allowed
- _UpdatePoolFee_:
Expand All @@ -380,7 +380,7 @@ Pool validator is the most important part in the system. It's responsible for gu
- Pool Input contains 1 valid Pool NFT Token
- Pool Input and Output Address must be unchanged (both Payment and Stake Credential)
- Pool Datum must be unchanged
- Transaction contain only 1 Spending Script (Pool Script). It will avoid bad Admin stealing money from Order Contract.
- Transaction spends only one Single Pool Script and does not contain any other scripts in its inputs, except for the Author, in cases where the Author is a script
- validate Transaction won't mint any assets
- validate Admin withdraws the exact earned Fee Sharing amount:
- Earned Asset A: Reserve A in Value - Reserve A in Datum
Expand Down
40 changes: 18 additions & 22 deletions lib/amm_dex_v2/utils.ak
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,15 @@ pub fn authorize_pool_license(
// If the authorization method is SpendScript, ensure the Utxo is present in the transaction inputs.
PAMSpendScript(script_hash) -> {
let auth_cred = ScriptCredential(script_hash)
!builtin.null_list(
list.filter(
transaction_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 == auth_cred
},
),
list.any(
transaction_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 == auth_cred
},
)
}
// If the authorization method is WithdrawScript, validate the presence of a withdrawal in the transaction.
Expand All @@ -562,17 +560,15 @@ pub fn authorize_order_license(
// If the authorization method is SpendScript, ensure the Utxo is present in the transaction inputs.
OAMSpendScript(script_hash) -> {
let auth_cred = ScriptCredential(script_hash)
!builtin.null_list(
list.filter(
transaction_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 == auth_cred
},
),
list.any(
transaction_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 == auth_cred
},
)
}
// If the authorization method is WithdrawScript, validate the presence of a withdrawal in the transaction.
Expand Down
Loading

0 comments on commit 5f4d4bf

Please sign in to comment.