From 90ed8fd3663e7cb0f374c2b33d6971b845d3f0c6 Mon Sep 17 00:00:00 2001 From: Clark Alesna Date: Sun, 26 May 2024 07:26:26 +0800 Subject: [PATCH 1/3] chore: updated code for `aiken-v1.0.28-alpha+c9a1519` compatiblity #1 --- aiken.lock | 2 +- lib/sundae/multisig.ak | 54 +++++++++++++++++++++--------------------- plutus.json | 14 +++++++++++ 3 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 plutus.json diff --git a/aiken.lock b/aiken.lock index e4a7aef..e102311 100644 --- a/aiken.lock +++ b/aiken.lock @@ -13,4 +13,4 @@ requirements = [] source = "github" [etags] -"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1700966727, nanos_since_epoch = 192028417 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"] +"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716678635, nanos_since_epoch = 47597898 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"] diff --git a/lib/sundae/multisig.ak b/lib/sundae/multisig.ak index f836383..85f729b 100644 --- a/lib/sundae/multisig.ak +++ b/lib/sundae/multisig.ak @@ -1,10 +1,9 @@ -use aiken/bytearray +use aiken/dict.{Dict} use aiken/interval.{Finite, Interval, IntervalBound} use aiken/list -use aiken/dict.{Dict} use aiken/time.{PosixTime} use aiken/transaction.{ValidityRange} -use aiken/transaction/credential.{StakeCredential, Inline, ScriptCredential} +use aiken/transaction/credential.{StakeCredential} use sundae/test_utils.{trace_example} pub type MultisigScript { @@ -26,9 +25,15 @@ pub fn satisfied( when script is { Signature { key_hash } -> list.has(signatories, key_hash) AllOf { scripts } -> - list.all(scripts, fn(s) { satisfied(s, signatories, valid_range, withdrawals) }) + list.all( + scripts, + fn(s) { satisfied(s, signatories, valid_range, withdrawals) }, + ) AnyOf { scripts } -> - list.any(scripts, fn(s) { satisfied(s, signatories, valid_range, withdrawals) }) + list.any( + scripts, + fn(s) { satisfied(s, signatories, valid_range, withdrawals) }, + ) AtLeast { required, scripts } -> required <= list.count( scripts, @@ -55,7 +60,7 @@ pub fn satisfied( } _ -> False } - Script { script_hash } -> dict.has_key(withdrawals, Inline(ScriptCredential(script_hash))) + Script { script_hash } -> dict.has_key(withdrawals, script_hash) } } @@ -107,29 +112,24 @@ test satisfying() { } } let no_w = dict.new() - let correct_credential = Inline(ScriptCredential("some_script")) - let incorrect_credential = Inline(ScriptCredential("other_script")) - let compare_credential = fn(a: StakeCredential, b: StakeCredential) -> Ordering { - when a is { - Inline(ScriptCredential(a))-> { - when b is { - Inline(ScriptCredential(b)) -> bytearray.compare(a, b) - _ -> Less - } - } - _ -> Greater - } - } - let correct_w = dict.new() - |> dict.insert(correct_credential, 0, compare_credential) - let incorrect_w = dict.new() - |> dict.insert(incorrect_credential, 0, compare_credential) - let both_w = dict.new() - |> dict.insert(correct_credential, 0, compare_credential) - |> dict.insert(incorrect_credential, 0, compare_credential) + let correct_w = + dict.new() + |> dict.insert("some_script", 0) + let incorrect_w = + dict.new() + |> dict.insert("other_script", 0) + let both_w = + dict.new() + |> dict.insert("some_script", 0) + |> dict.insert("other_script", 0) // Helper method because ? binds more tightly than ! let unsatisfied = - fn(n: MultisigScript, s: List, v: ValidityRange, w: Dict) { + fn( + n: MultisigScript, + s: List, + v: ValidityRange, + w: Dict, + ) { !satisfied(n, s, v, w) } list.all( diff --git a/plutus.json b/plutus.json new file mode 100644 index 0000000..c1a7590 --- /dev/null +++ b/plutus.json @@ -0,0 +1,14 @@ +{ + "preamble": { + "title": "sundaeswap-finance/aicone", + "description": "Aiken contracts for project 'sundaeswap-finance/aicone'", + "version": "0.0.0", + "plutusVersion": "v2", + "compiler": { + "name": "Aiken", + "version": "v1.0.28-alpha+c9a1519" + }, + "license": "Apache-2.0" + }, + "validators": [] +} \ No newline at end of file From 41335f0044845786c949188f9a0b7e428f9fbc6f Mon Sep 17 00:00:00 2001 From: Clark Alesna Date: Sun, 26 May 2024 07:53:32 +0800 Subject: [PATCH 2/3] chore: convert dict to pairs (#2) --- aiken.lock | 2 +- lib/sundae/multisig.ak | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/aiken.lock b/aiken.lock index e102311..48e8f09 100644 --- a/aiken.lock +++ b/aiken.lock @@ -13,4 +13,4 @@ requirements = [] source = "github" [etags] -"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716678635, nanos_since_epoch = 47597898 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"] +"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716680697, nanos_since_epoch = 311385814 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"] diff --git a/lib/sundae/multisig.ak b/lib/sundae/multisig.ak index 85f729b..4b57f06 100644 --- a/lib/sundae/multisig.ak +++ b/lib/sundae/multisig.ak @@ -1,9 +1,9 @@ -use aiken/dict.{Dict} use aiken/interval.{Finite, Interval, IntervalBound} use aiken/list +use aiken/pairs use aiken/time.{PosixTime} use aiken/transaction.{ValidityRange} -use aiken/transaction/credential.{StakeCredential} +use aiken/transaction/credential.{Inline, ScriptCredential, StakeCredential} use sundae/test_utils.{trace_example} pub type MultisigScript { @@ -20,7 +20,7 @@ pub fn satisfied( script: MultisigScript, signatories: List, valid_range: ValidityRange, - withdrawals: Dict, + withdrawals: Pairs, ) -> Bool { when script is { Signature { key_hash } -> list.has(signatories, key_hash) @@ -60,7 +60,8 @@ pub fn satisfied( } _ -> False } - Script { script_hash } -> dict.has_key(withdrawals, script_hash) + Script { script_hash } -> + pairs.has_key(withdrawals, Inline(ScriptCredential(script_hash))) } } @@ -111,24 +112,24 @@ test satisfying() { }, } } - let no_w = dict.new() + let no_w: Pairs = + [] let correct_w = - dict.new() - |> dict.insert("some_script", 0) + [Pair(Inline(ScriptCredential("some_script")), 0)] let incorrect_w = - dict.new() - |> dict.insert("other_script", 0) + [Pair(Inline(ScriptCredential("other_script")), 0)] let both_w = - dict.new() - |> dict.insert("some_script", 0) - |> dict.insert("other_script", 0) + [ + Pair(Inline(ScriptCredential("some_script")), 0), + Pair(Inline(ScriptCredential("other_script")), 0), + ] // Helper method because ? binds more tightly than ! let unsatisfied = fn( n: MultisigScript, s: List, v: ValidityRange, - w: Dict, + w: Pairs, ) { !satisfied(n, s, v, w) } From b44901025c6d17a0f24c01efc95af273ac3793f9 Mon Sep 17 00:00:00 2001 From: Clark Alesna Date: Sun, 26 May 2024 07:58:33 +0800 Subject: [PATCH 3/3] chore: Remove plutus.json file --- plutus.json | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 plutus.json diff --git a/plutus.json b/plutus.json deleted file mode 100644 index c1a7590..0000000 --- a/plutus.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "preamble": { - "title": "sundaeswap-finance/aicone", - "description": "Aiken contracts for project 'sundaeswap-finance/aicone'", - "version": "0.0.0", - "plutusVersion": "v2", - "compiler": { - "name": "Aiken", - "version": "v1.0.28-alpha+c9a1519" - }, - "license": "Apache-2.0" - }, - "validators": [] -} \ No newline at end of file