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

prefixes are now custom prefixes and cip68 moved to types/cip68 #79

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- Added `input_by_nft` to the find submodule.
- Added additional power mod tests.
- A large prime number has been added to maths.
- Prefixes are now placed where they belong, the cip68 labels are now in cip68 sub type and prefixes are now custom prefixes.
- Added `seed` prefix.

# v0.4.5

Expand Down
34 changes: 14 additions & 20 deletions lib/assist/minting.ak
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use aiken/bytearray
use aiken/transaction/value.{AssetName, PolicyId}
use assist/prefixes
use assist/types/cip68

/// This checks if a specific policy id, token name, and amount exist inside
/// the flattened exact value. It is searching for an exact match. If found
Expand Down Expand Up @@ -105,27 +105,23 @@ pub fn by_prefix(
}

test good_by_prefix_mint() {
let flat =
value.from_asset(#"acab", prefixes.prefix_222, 1) |> value.flatten()
by_prefix(flat, #"acab", prefixes.prefix_222, 1) == True
let flat = value.from_asset(#"acab", cip68.prefix_222, 1) |> value.flatten()
by_prefix(flat, #"acab", cip68.prefix_222, 1) == True
}

test good_by_prefix_burn() {
let flat =
value.from_asset(#"acab", prefixes.prefix_222, -1) |> value.flatten()
by_prefix(flat, #"acab", prefixes.prefix_222, -1) == True
let flat = value.from_asset(#"acab", cip68.prefix_222, -1) |> value.flatten()
by_prefix(flat, #"acab", cip68.prefix_222, -1) == True
}

test bad_by_prefix_mint() {
let flat =
value.from_asset(#"acab", prefixes.prefix_333, 1) |> value.flatten()
by_prefix(flat, #"acab", prefixes.prefix_222, 1) == False
let flat = value.from_asset(#"acab", cip68.prefix_333, 1) |> value.flatten()
by_prefix(flat, #"acab", cip68.prefix_222, 1) == False
}

test bad_by_prefix_burn() {
let flat =
value.from_asset(#"acab", prefixes.prefix_333, -1) |> value.flatten()
by_prefix(flat, #"acab", prefixes.prefix_222, -1) == False
let flat = value.from_asset(#"acab", cip68.prefix_333, -1) |> value.flatten()
by_prefix(flat, #"acab", cip68.prefix_222, -1) == False
}

test empty_by_prefix_mint() {
Expand Down Expand Up @@ -166,17 +162,15 @@ pub fn is_occurring(
test tx_is_empty_minting() {
let flat =
[]
is_occurring(flat, #"acab", prefixes.prefix_222) == False
is_occurring(flat, #"acab", cip68.prefix_222) == False
}

test tx_is_minting() {
let flat =
value.from_asset(#"acab", prefixes.prefix_222, 1) |> value.flatten()
is_occurring(flat, #"acab", prefixes.prefix_222) == True
let flat = value.from_asset(#"acab", cip68.prefix_222, 1) |> value.flatten()
is_occurring(flat, #"acab", cip68.prefix_222) == True
}

test tx_is_not_minting() {
let flat =
value.from_asset(#"acab", prefixes.prefix_222, 1) |> value.flatten()
is_occurring(flat, #"acab", prefixes.prefix_333) == False
let flat = value.from_asset(#"acab", cip68.prefix_222, 1) |> value.flatten()
is_occurring(flat, #"acab", cip68.prefix_333) == False
}
21 changes: 6 additions & 15 deletions lib/assist/prefixes.ak
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
//// This module provides the currently accepted token prefixes.
//// This module provides token prefixes for labeling unique tokens.
////

/// (100) Reference Token Prefix
pub const prefix_100: ByteArray = #"000643b0"

/// (222) Non-Fungible Token Prefix
pub const prefix_222: ByteArray = #"000de140"

/// (333) Fungible Token Prefix
pub const prefix_333: ByteArray = #"0014df10"

/// (444) Rich-Fungible Token Prefix
pub const prefix_444: ByteArray = #"001bc280"

/// Callable Token Prefix
pub const prefix_callable: ByteArray = #"ca11ab1e"
pub const callable: ByteArray = #"ca11ab1e"

/// Database Token Prefix
pub const prefix_database: ByteArray = #"da7aba5e"
pub const database: ByteArray = #"da7aba5e"

/// Seed Token Prefix
pub const seed: ByteArray = #"5eed0e1f"
16 changes: 16 additions & 0 deletions lib/assist/types/cip68.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
use aiken/dict.{Dict}

/// (100) Reference Token Prefix
/// https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0068/#222-nft-standard
pub const prefix_100: ByteArray = #"000643b0"

/// (222) Non-Fungible Token Prefix
/// https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0068/#222-nft-standard
pub const prefix_222: ByteArray = #"000de140"

/// (333) Fungible Token Prefix
/// https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0068/#333-ft-standard
pub const prefix_333: ByteArray = #"0014df10"

/// (444) Rich-Fungible Token Prefix
/// https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0068/#333-ft-standard
pub const prefix_444: ByteArray = #"001bc280"

/// The generic CIP68 metadatum type as defined in the CIP at
/// https://cips.cardano.org/cips/cip68/.
pub type CIP68 {
Expand Down
10 changes: 5 additions & 5 deletions lib/assist/values.ak
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aiken/hash
use aiken/list
use aiken/string
use aiken/transaction/value.{AssetName, PolicyId, Value}
use assist/prefixes
use assist/types/cip68
use assist/types/hashes.{TxHash}
use assist/types/token.{Token, Tokens}

Expand Down Expand Up @@ -217,7 +217,7 @@ test hash_large_value() {
/// utxo inside the transaction.
///
/// ```aiken
/// values.unique_token_name(tx_id, tx_idx, prefixes.prefix_333)
/// values.unique_token_name(tx_id, tx_idx, cip68.prefix_333)
/// ```
pub fn unique_token_name(txid: TxHash, idx: Int, prefix: ByteArray) -> AssetName {
// sha3_256 hash of the tx id
Expand All @@ -236,17 +236,17 @@ test no_prefix_token_name() {
}

test prefix_222_token_name() {
let tkn: AssetName = unique_token_name(#"", 0, prefixes.prefix_222)
let tkn: AssetName = unique_token_name(#"", 0, cip68.prefix_222)
// the prefixes all have length 4
bytearray.take(tkn, 4) == prefixes.prefix_222
bytearray.take(tkn, 4) == cip68.prefix_222
}

test real_token_name() {
let tkn: AssetName =
unique_token_name(
#"82fca2f3221cf2d3ef017e8aa76f5c70317df0af32d327c84af4b9b9bddad91f",
0,
prefixes.prefix_100,
cip68.prefix_100,
)
bytearray.length(tkn) == 32
}
Expand Down
Loading