Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard fork code #35

Merged
merged 29 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
358fae9
start on skeleton of hard fork contract
MicroProofs Sep 4, 2023
5a56a66
chore: add some util functions and start add validation requirements
MicroProofs Sep 4, 2023
faba26e
Due to the interdependence among many state inputs,
MicroProofs Sep 4, 2023
84fceb0
finish switching spend validator to depend on withdraw validator
MicroProofs Sep 4, 2023
a7522f2
Include one spending condition to prevent minting in a certain case
MicroProofs Sep 4, 2023
d50f4c1
remove unneeded condition,
MicroProofs Sep 4, 2023
364efb5
checkpoint commit
MicroProofs Sep 5, 2023
01f4428
remove the commented out code and implement it
MicroProofs Sep 6, 2023
0f2a042
add updated fortuna logic into the mine validator
MicroProofs Sep 8, 2023
5d52f82
chore: formatting
MicroProofs Sep 8, 2023
5fb26ec
rewrite the lock action of the hard fork validator
MicroProofs Sep 9, 2023
65b367f
chore: some renames and more comments
MicroProofs Sep 9, 2023
d3aed06
feat: finish genesis and redeem actions
MicroProofs Sep 15, 2023
089e202
fix: need to check exact tokens that are minted under own policy
MicroProofs Sep 15, 2023
e44c108
check input too in genesis
MicroProofs Sep 15, 2023
a136648
feat: Add initialize and unlock actions to hard fork contract
MicroProofs Sep 15, 2023
6351dd2
feat: finish lock other than miner readiness
MicroProofs Sep 18, 2023
a8f9701
chore: Remove some warnings
MicroProofs Sep 18, 2023
ecadaad
reminder: every action of the withdraw validator must check both mint…
MicroProofs Sep 18, 2023
cc1f4f8
feat: Add Burn action
MicroProofs Sep 18, 2023
a70b142
commit current changes
MicroProofs Sep 27, 2023
7206277
add miner readiness calculation to lock check
MicroProofs Sep 28, 2023
5619b16
feat: implement calculate emission
MicroProofs Sep 28, 2023
335ef4d
commit partially done hard fork action
MicroProofs Oct 1, 2023
718f9fe
feat: refactor hardfork validator with a cleaner abstraction over the…
MicroProofs Oct 4, 2023
7bc4874
chore: setup hard fork action with lock field
MicroProofs Oct 4, 2023
3a4f5fd
feat: nearly done, one more branch case to finish
MicroProofs Oct 4, 2023
66ec498
add one more check
MicroProofs Oct 5, 2023
76cd68a
feat: finish up hard fork validation, onto tests
MicroProofs Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ docs/
seed.txt
.env

.idea/
.idea/
aiken.lock
6 changes: 4 additions & 2 deletions aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

[[requirements]]
name = "aiken-lang/stdlib"
version = "main"
version = "1.6.0"
source = "github"

[[packages]]
name = "aiken-lang/stdlib"
version = "main"
version = "1.6.0"
requirements = []
source = "github"

[etags]
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ platform = 'github'

[[dependencies]]
name = 'aiken-lang/stdlib'
version = 'main'
version = '1.6.0'
source = 'github'
10 changes: 10 additions & 0 deletions lib/fortuna/types.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub type State {
block_number: Int,
current_hash: ByteArray,
leading_zeros: Int,
target_number: Int,
epoch_time: Int,
current_posix_time: Int,
extra: Data,
interlink: List<Data>,
}
87 changes: 87 additions & 0 deletions lib/fortuna/utils.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use aiken/dict
use aiken/transaction.{Input, Output, OutputReference} as tx
use aiken/transaction/value.{AssetName, PolicyId, Value}

pub fn resolve_output_reference(
inputs: List<Input>,
output_ref: OutputReference,
) -> Output {
expect [input, ..inputs] = inputs

if input.output_reference == output_ref {
input.output
} else {
resolve_output_reference(inputs, output_ref)
}
}

pub fn list_at(l: List<a>, index: Int) -> a {
expect [head, ..rest] = l

if index == 0 {
head
} else {
list_at(rest, index - 1)
}
}

pub fn quantity_of(
val: Value,
policy_id: PolicyId,
asset_name: AssetName,
) -> Int {
when val |> value.to_dict |> dict.get(policy_id) is {
Some(asset) ->
when dict.get(asset, asset_name) is {
Some(quantity) -> quantity
None -> 0
}
None -> 0
}
}

pub fn filter_resolved_inputs(
self: List<Input>,
predicate: fn(Input) -> Bool,
) -> List<Input> {
when self is {
[] ->
[]
[x, ..xs] ->
if predicate(x) {
[x, ..filter_resolved_inputs(xs, predicate)]
} else {
filter_resolved_inputs(xs, predicate)
}
}
}

pub fn value_has_nft_and_lovelace(
val: Value,
policy: PolicyId,
asset_name: AssetName,
) -> Bool {
expect [(policy1, amount1), (policy2, amount2)] =
val
|> value.to_dict
|> dict.to_list()

if policy1 == value.ada_policy_id {
// Should always reach here since maps come in ordered on chain
expect [(token_name, quantity)] = amount2 |> dict.to_list()

and {
policy2 == policy,
quantity == 1,
token_name == asset_name,
}
} else {
expect [(token_name, quantity)] = amount1 |> dict.to_list()

and {
policy1 == policy,
quantity == 1,
token_name == asset_name,
}
}
}
Loading