-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from cardano2vn/refactor-code
feat: update compiler version, add mint and store validators, and enh…
- Loading branch information
Showing
7 changed files
with
250 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
export const EXCHANGE_FEE_ADDRESS = process.env.EXCHANGE_FEE_ADDRESS || ""; | ||
export const REFERENCE_SCRIPT_ADDRESS = | ||
process.env.REFERENCE_SCRIPT_ADDRESS || ""; | ||
|
||
export const REFERENCE_SCRIPT_HASH = process.env.REFERENCE_SCRIPT_HASH || ""; | ||
|
||
export const MINT_REFERENCE_SCRIPT_ADDRESS = | ||
process.env.MINT_REFERENCE_SCRIPT_ADDRESS || ""; | ||
export const STORE_REFERENCE_SCRIPT_ADDRESS = | ||
process.env.STORE_REFERENCE_SCRIPT_ADDRESS || ""; | ||
export const MINT_REFERENCE_SCRIPT_HASH = | ||
process.env.MINT_REFERENCE_SCRIPT_HASH || ""; | ||
export const STORE_REFERENCE_SCRIPT_HASH = | ||
process.env.STORE_REFERENCE_SCRIPT_HASH || ""; | ||
export const EXCHANGE_FEE_PRICE = process.env.EXCHANGE_FEE_PRICE || ""; | ||
|
||
export const title = { | ||
mint: "cip68generator.cip68generator.mint", | ||
store: "cip68generator.cip68generator.spend", | ||
mint: "mint.mint.mint", | ||
store: "store.store.spend", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use aiken/collection/list | ||
use aiken/crypto.{ScriptHash, VerificationKeyHash} | ||
use aiken/primitive/bytearray | ||
use cardano/address | ||
use cardano/assets.{PolicyId, without_lovelace} | ||
use cardano/minting | ||
use cardano/transaction.{Transaction} | ||
use cip68generator/types.{Burn, Mint, MintRedeemer} | ||
use cip68generator/utils | ||
use types/cip68 | ||
use validation/find | ||
|
||
// Validator: Mint | ||
// Description: Valodator use mint and burn assets dynamic assets (Token/NFT) generator (CIP68) | ||
// Parameters: exchange: Exchange wallet address, exchange_fee: Minimum price sent to the exchange, store: Store address wallet, | ||
|
||
// Mint Redeemer | ||
// sign_by_author: | ||
validator mint( | ||
exchange: VerificationKeyHash, | ||
exchange_fee: Int, | ||
store: ScriptHash, | ||
) { | ||
mint(redeemer: MintRedeemer, policy_id: PolicyId, transaction: Transaction) { | ||
True | ||
// let Transaction { outputs, extra_signatories, mint, .. } = transaction | ||
// let mint_flatten = | ||
// mint | ||
// |> without_lovelace() | ||
// |> assets.flatten() | ||
|
||
// let reference_token_option = | ||
// utils.token_prefix(mint_flatten, cip68.prefix_100) | ||
// let user_token_option = utils.token_prefix(mint_flatten, cip68.prefix_222) | ||
// let amount_mint_token: Int = list.length(mint_flatten) | ||
// let exchange_address = address.from_verification_key(exchange) | ||
// let output_utxo_exchange = | ||
// utils.find_output(outputs, exchange_fee, exchange_address) | ||
// let check_none_token = | ||
// utils.check_none_token(user_token_option, reference_token_option) | ||
|
||
// when check_none_token is { | ||
// True -> | ||
// when (reference_token_option, user_token_option) is { | ||
// (Some(reference_token), Some(user_token)) -> { | ||
// let reference_value = | ||
// assets.from_asset(policy_id, reference_token, 1) | ||
// // let user_value = | ||
// // assets.from_asset(policy_id, user_token, amount_mint_token - 1) | ||
// let store_address = address.from_script(store) | ||
// let output_utxo_store = | ||
// find.output_by_addr_value(outputs, store_address, reference_value) | ||
|
||
// when redeemer is { | ||
// Mint -> and { | ||
// amount_mint_token >= 2, | ||
// minting.exact(mint_flatten, policy_id, reference_token, 1)?, | ||
// minting.exact( | ||
// mint_flatten, | ||
// policy_id, | ||
// user_token, | ||
// amount_mint_token - 1, | ||
// )?, | ||
// utils.check_output_utxo(output_utxo_store, extra_signatories)?, | ||
// output_utxo_exchange != None, | ||
// } | ||
|
||
// // bytearray.compare( | ||
// // bytearray.drop(reference_token, 4), | ||
// // bytearray.drop(user_token, 4), | ||
// // ) == Equal, | ||
// Burn -> and { | ||
// minting.by_prefix( | ||
// mint_flatten, | ||
// policy_id, | ||
// cip68.prefix_100, | ||
// -1, | ||
// )?, | ||
// output_utxo_exchange != None, | ||
// minting.by_prefix( | ||
// mint_flatten, | ||
// policy_id, | ||
// cip68.prefix_222, | ||
// -1, | ||
// )?, | ||
// } | ||
// } | ||
// } | ||
|
||
// // bytearray.compare( | ||
// // bytearray.drop(reference_token, 4), | ||
// // bytearray.drop(user_token, 4), | ||
// // ) == Equal, | ||
// _ -> False | ||
// } | ||
// _ -> False | ||
// } | ||
} | ||
|
||
else(_) { | ||
fail | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use aiken/crypto.{VerificationKeyHash} | ||
use cardano/address | ||
use cardano/assets.{without_lovelace} | ||
use cardano/transaction.{ | ||
InlineDatum, Output, OutputReference, Transaction, find_input, | ||
} | ||
use cip68generator/types.{Remove, StoreRedeemer, Update} | ||
use cip68generator/utils | ||
use types/cip68.{CIP68} | ||
use validation/find.{output_by_addr_value} | ||
|
||
validator store(exchange: VerificationKeyHash, exchange_fee: Int) { | ||
spend( | ||
datum: Option<CIP68>, | ||
redeemer: StoreRedeemer, | ||
output_reference: OutputReference, | ||
transaction: Transaction, | ||
) { | ||
True | ||
// expect Some(datum_output) = datum | ||
// let Transaction { inputs, outputs, extra_signatories, .. } = transaction | ||
// let exchange_address = address.from_verification_key(exchange) | ||
// let output_utxo_exchange = | ||
// utils.find_output(outputs, exchange_fee, exchange_address) | ||
// expect Some(input) = find_input(inputs, output_reference) | ||
// let script_address = input.output.address | ||
// let reference_token = | ||
// input.output.value | ||
// |> without_lovelace() | ||
// let validator_output = | ||
// output_by_addr_value(outputs, script_address, reference_token) | ||
// expect InlineDatum(datum_input) = validator_output.datum | ||
// let meradatum_output: CIP68 = datum_output | ||
// expect metadatum_input: CIP68 = datum_input | ||
// expect author_input: ByteArray = cip68.get(metadatum_input, "author") | ||
// expect author_output: ByteArray = cip68.get(meradatum_output, "author") | ||
// let check_author = author_input == author_output | ||
|
||
// when redeemer is { | ||
// Update -> and { | ||
// utils.check_output_utxo(validator_output, extra_signatories)?, | ||
// output_utxo_exchange != None, | ||
// check_author, | ||
// } | ||
// Remove -> and { | ||
// utils.check_output_utxo(validator_output, extra_signatories)?, | ||
// output_utxo_exchange != None, | ||
// } | ||
// } | ||
} | ||
|
||
else(_) { | ||
fail | ||
} | ||
} |