This smart contract should validate that ADA is sent in and the same amount of DOTARE (51b164296435702ac8bfa3e8e8b5aca287b841237af02c99a69c64e2) is minted and sent back. Then when the same address that sent the ADA in wants to withdraw, it should ensure they don't withdraw more than they put in.
Created
February 14, 2025 00:57
-
-
Save dmurawsky/02e3a6d68634c067b45cdce09102c120 to your computer and use it in GitHub Desktop.
Aiken smart contract for Dotare
This file contains hidden or 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
use aiken/collection/dict | |
use aiken/collection/list | |
use aiken/crypto.{Blake2b_224, Hash, VerificationKey} | |
use cardano/assets.{PolicyId, policies} | |
use cardano/transaction.{InlineDatum, OutputReference, Transaction} | |
pub type Datum { | |
/// Owner's credentials | |
owner: VerificationKeyHash, | |
/// Beneficiary's credentials | |
beneficiary: VerificationKeyHash, | |
} | |
pub type Action { | |
Minting | |
Burning | |
} | |
type VerificationKeyHash = | |
Hash<Blake2b_224, VerificationKey> | |
validator dotare(utxo_ref: OutputReference) { | |
mint(_redeemer: Action, policy_id: PolicyId, self: Transaction) { | |
let Transaction { inputs, outputs, mint, .. } = self | |
expect [Pair(asset_name, quantity)] = | |
mint |> assets.tokens(policy_id) |> dict.to_pairs() | |
let is_output_consumed = | |
list.any(inputs, fn(input) { input.output_reference == utxo_ref }) | |
expect Some(nft_output) = | |
list.find( | |
outputs, | |
fn(output) { list.has(policies(output.value), policy_id) }, | |
) | |
expect InlineDatum(datum) = nft_output.datum | |
expect counter: Int = datum | |
let asset_is_dotare = | |
asset_name == #"51b164296435702ac8bfa3e8e8b5aca287b841237af02c99a69c64e2" | |
is_output_consumed? && (1 == quantity)? && counter == 0 && asset_is_dotare? | |
} | |
spend( | |
datum: Option<Datum>, | |
_redeemer: Action, | |
_own_ref: OutputReference, | |
self: Transaction, | |
) { | |
expect Some(Datum { owner, beneficiary }) = datum | |
let must_be_signed_by_owner = list.has(self.extra_signatories, owner) | |
let must_be_signed_by_beneficiary = | |
list.has(self.extra_signatories, beneficiary) | |
must_be_signed_by_owner? && must_be_signed_by_beneficiary? | |
} | |
else(_) { | |
fail | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment