Skip to content

Commit

Permalink
feat: FeeRefToken dev
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Dec 14, 2023
1 parent 07bda91 commit b49f5bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
53 changes: 37 additions & 16 deletions lib/aiken-virtual-dex/validators/fee_ref_token.ak
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use aiken/list
use aiken/transaction.{Input, Mint, OutputReference, ScriptContext, Transaction}
use aiken/transaction.{InlineDatum, Mint, ScriptContext, Transaction}
use aiken/transaction/value.{PolicyId}
use aiken_virtual_dex/common.{check_policy_only_burn}
use aiken_virtual_dex/types.{MintPolarity, RBurn, RMint}
use aiken_virtual_dex/common.{
check_policy_only_burn, key_signed, only_input_datum_with, only_minted_token,
outputs_at_with, value_length,
}
use aiken_virtual_dex/types.{
FeeInfoDatum, MintPolarity, OracleDatum, RBurn, RMint,
}

pub fn fee_ref_token_logic(
oracle_nft: PolicyId,
Expand All @@ -14,19 +18,36 @@ pub fn fee_ref_token_logic(
Mint(current_policy) ->
when redeemer is {
RMint -> {
let Transaction { inputs, .. } = transaction
True
let Transaction {
mint,
reference_inputs,
extra_signatories,
outputs,
..
} = transaction
expect OracleDatum {
fee_ref_token,
fee_info_address,
operation_key,
..
}: OracleDatum =
only_input_datum_with(reference_inputs, oracle_nft, "")
expect [output] =
outputs_at_with(outputs, fee_info_address, fee_ref_token, "")
expect InlineDatum(raw_datum) = output.datum
expect FeeInfoDatum {
long_token: _,
short_token: _,
min_fee,
percentage_fee,
}: FeeInfoDatum = raw_datum
let fee_token_minted = only_minted_token(mint, fee_ref_token, "", 1)
let fee_token_output_clean = value_length(output.value) == 2
let fee_datum_format_correct = min_fee >= 0 && percentage_fee >= 0
let is_operating_key_signed =
key_signed(extra_signatories, operation_key)
fee_token_minted && fee_token_output_clean && fee_datum_format_correct && is_operating_key_signed
}

// let hash_equal =
// fn(input: Input) {
// let hash = input.output_reference
// utxo_ref == hash
// }
// let target_input_exist = list.find(inputs, hash_equal)
// when target_input_exist is {
// Some(_) -> True
// None -> False
RBurn -> check_policy_only_burn(transaction.mint, current_policy)
}
_ -> False
Expand Down
4 changes: 2 additions & 2 deletions specs/3_fee_ref_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

- Only 1 `FeeToken` is minted with empty token name
- 1 output to `FeeInfoValidator`, value length of 2
- The inline datum attached with the output is in format of `FeeInfoDatum`
- Signed by both operation key and `owner_pub_key`
- The inline datum attached with the output is in format of `FeeInfoDatum` (geq 0 fee)
- Signed by both operation key

2. Burn - Redeemer RBurn

Expand Down

0 comments on commit b49f5bb

Please sign in to comment.