hi I am getting this error while trying to unlock tokens from my treasury contract it is already topp up with tokens when trying to unlock with the access token doesn't know the exact reason behind this pls help me out
StackingTreasury.hs
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
module Stake.StackingTreasury where
import Ledger hiding (singleton)
import qualified Ledger.Typed.Scripts as Scripts
import Ledger.Value as Value
import Ledger.Ada
import qualified PlutusTx
import PlutusTx.Prelude hiding (Semigroup (..), unless)
import Stake.StackingTypes
{-# INLINEABLE mkValidator #-}
mkValidator :: TreasuryParam -> WithdrawalDatum -> StackingDetails -> ScriptContext -> Bool
mkValidator tp dat b ctx = traceIfFalse "Only Issuer can change Treasury" signedByIssuer ||
traceIfFalse "Access token missing from input" inputHasAuthToken &&
traceIfFalse "Access token missing from contract output" contractOutputHasAuthToken &&
traceIfFalse "Output Value must match StackingDetails" checkValueToStackingContract &&
traceIfFalse "Treasury must keep remaining tokens" treasuryGetsTokensBack &&
traceIfFalse "redeemer is not datum" checkReIsOutDat
where
info :: TxInfo
info = scriptContextTxInfo ctx
signedByIssuer :: Bool
signedByIssuer = txSignedBy info $ tTreasuryIssuerPkh tp
-- Create a list of all CurrencySymbol in tx input
inVals :: [CurrencySymbol]
inVals = symbols $ valueSpent info
-- Check that list of CurrencySymbols includes Auth CurrencySymbol
inputHasAuthToken :: Bool
inputHasAuthToken = tAccessTokenPolicyId tp `elem` inVals
-- The Value to be included in Stacking Contract UTXO
toStackingContract :: Value
toStackingContract = valueLockedBy info (bountyContractHash tp)
-- Check that the Auth Token is sent to Bounty Contract UTXO
contractOutputHasAuthToken :: Bool
contractOutputHasAuthToken = tAccessTokenPolicyId tp `elem` symbols toStackingContract
-- Check that the Value sent to Contract UTXO matches what is specified in the Redeemer
-- Note: For now, we can just remember to match Treasury Redeemer to Bounty Datum
-- when we build transactions
checkValueToStackingContract :: Bool
checkValueToStackingContract = valueOf toStackingContract (tBountyTokenPolicyId tp) (tBountyTokenName tp) >= tokenAmount b
-- The UTXO input from Treasury
ownInput :: TxOut
ownInput = case findOwnInput ctx of
Nothing -> traceError "treasury input missing"
Just i -> txInInfoResolved i
-- The UTXO output back to Treasury
ownOutput :: TxOut
ownOutput = case getContinuingOutputs ctx of
[o] -> o -- There must be exactly ONE output UTXO
_ -> traceError "expected exactly one treasury output"
-- Values of each
treasuryInputValue :: Value
treasuryInputValue = txOutValue ownInput
treasuryOutputValue :: Value
treasuryOutputValue = txOutValue ownOutput
-- Compare Values from and to Treasury to make sure that Treasury gets the right value back.
treasuryGetsTokensBack :: Bool
treasuryGetsTokensBack = valueOf treasuryInputValue (tBountyTokenPolicyId tp) (tBountyTokenName tp) - valueOf treasuryOutputValue (tBountyTokenPolicyId tp) (tBountyTokenName tp) <= valueOf toStackingContract (tBountyTokenPolicyId tp) (tBountyTokenName tp)
getStackingDatum :: Maybe StackingDatum
getStackingDatum = let os = [ o | o <- txInfoOutputs info, txOutValue o == toStackingContract ] in
case os of
[o] -> stackingDatum o (`findDatum` info)
_ -> Nothing
checkReIsOutDat :: Bool
checkReIsOutDat = case getStackingDatum of
Nothing -> False
Just ns -> bedIssuerPkh ns == issuerPkh b &&
bedContributorPkh ns == contributorPkh b &&
bedTokenAmount ns == tokenAmount b &&
bedExpirationTime ns == expirationTime b
-- typedValidator :: TreasuryParam -> TypedValidator TreasuryTypes
-- typedValidator tp =
-- mkTypedValidator @TreasuryTypes
-- $$(PlutusTx.compile [||mkValidator||]) `PlutusTx.applyCode` PlutusTx.liftCode tp
-- $$(PlutusTx.compile [||wrap||])
-- where
-- wrap = wrapValidator @WithdrawalDatum @StackingDetails
-- validator :: TreasuryParam -> Validator
-- validator = validatorScript . typedValidator
typedValidator :: TreasuryParam -> Scripts.TypedValidator TreasuryTypes
typedValidator tp = Scripts.mkTypedValidator @TreasuryTypes
($$(PlutusTx.compile [|| mkValidator ||])
`PlutusTx.applyCode` PlutusTx.liftCode tp)
$$(PlutusTx.compile [|| wrap ||])
where
wrap = Scripts.wrapValidator @WithdrawalDatum @StackingDetails
validator :: TreasuryParam -> Validator
validator = Scripts.validatorScript . typedValidator
utxo at treasury address with datum hash of 123
cardano-cli query utxo --address addr_test1wpcsng9wvph3yn6felqewnq9wwcvuwpwdumrax2dset0vecwhasah --testnet-magic 1
result
TxHash TxIx Amount
--------------------------------------------------------------------------------------
0e4f0c3c372bb3c3d044f4ff72f200ad962f0f51190794dc43ca8f119b0faec2 1 2000000 lovelace + 99999999 d7d0b7e1195d3c51fefcf4e40146de39fe11162dcc56427f9e9db196.48616c + TxOutDatumHash ScriptDataInBabbageEra "7cfec515f56d4413375aa9775f5de15ee60180861e9eaa954bcf9d015054857c"
getting this error while trying to unlock funds from treasury conttract to stacking contract
Command failed: transaction build Error: The following scripts have execution failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred: User error:
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [ (builtin unConstrData) (con data #187b) ]
Script debugging logs:
unlocking command
CONTRACT_TXIN="0e4f0c3c372bb3c3d044f4ff72f200ad962f0f51190794dc43ca8f119b0faec2#1"
TOKENS_BACK_TO_TREASURY=99999989
BOUNTY_ADDR=addr_test1wz0r05r5gmfykqzt6uavku4ncacxxd60sj2auadaefudntc3cyvrk
BOUNTY_ASSET="d7d0b7e1195d3c51fefcf4e40146de39fe11162dcc56427f9e9db196.48616c"
CONTRIBUTOR_ASSET="e8abf29fc898134b44c1af4148ad15a6840c53d4d5e67483fba24ac3.6e696b6b69"
TREASURY_ADDR=addr_test1wpcsng9wvph3yn6felqewnq9wwcvuwpwdumrax2dset0vecwhasah
TREASURY_PLUTUS_SCRIPT="output/treasury.plutus"
BOUNTY_DATUM="datum.json"
CONTRIBUTOR=addr_test1vr5uap3n4mu4kcetl0luz25re3x93yfjc3kdq0ud4c2xassvq0wsd
TXIN1="b61083800814c048d1c464d8306cc817a559565e6ca10d7f887eb23cfd3e5f1b#1"
TXIN2="b72f8592ab7f740f46ba461d0302f82a69c0134c95df1622fb31ca7b5141f405#0"
COLLATERAL="290fa91f253f968f20fa347c9a8371263c7e852e9bf611a7eb91c35818fd0edf#0"
BOUNTY_AMOUNT=10
cardano-cli transaction build \
--babbage-era \
--tx-in $CONTRACT_TXIN \
--tx-in-script-file $TREASURY_PLUTUS_SCRIPT \
--tx-in-datum-value 123 \
--tx-in-redeemer-file $BOUNTY_DATUM \
--tx-in $TXIN1 \
--tx-in $TXIN2 \
--tx-in-collateral $COLLATERAL \
--tx-out $BOUNTY_ADDR+"2000000 + 1 $CONTRIBUTOR_ASSET + $BOUNTY_AMOUNT $BOUNTY_ASSET" \
--tx-out-datum-embed-file $BOUNTY_DATUM \
--tx-out $TREASURY_ADDR+"2000000 + $TOKENS_BACK_TO_TREASURY $BOUNTY_ASSET" \
--tx-out-datum-hash 7cfec515f56d4413375aa9775f5de15ee60180861e9eaa954bcf9d015054857c \
--change-address $CONTRIBUTOR \
--protocol-params-file protocol.json \
--testnet-magic 1 \
--out-file commitment-tx.draft