Skip to content

Add cardano-loans Smart Contract to plutus-benchmark #7206

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions plutus-benchmark/cardano-loans/exe/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Main (main) where

import CardanoLoans.Test (validatorCodeFullyApplied)
import Data.Text qualified as Text
import PlutusTx.Test (displayEvalResult, evaluateCompiledCode)

main :: IO ()
main = do
putStrLn ""
putStrLn $
Text.unpack $
displayEvalResult $
evaluateCompiledCode validatorCodeFullyApplied
104 changes: 104 additions & 0 deletions plutus-benchmark/cardano-loans/src/CardanoLoans/Test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Strict #-}

module CardanoLoans.Test where

import PlutusTx
import PlutusTx.Prelude

import CardanoLoans.Validator (LoanDatum (..), LoanRedeemer (..), loanValidatorCode)
import PlutusLedgerApi.V1.Address (pubKeyHashAddress)
import PlutusLedgerApi.V1.Value qualified as Value
import PlutusLedgerApi.V2.Tx qualified as Tx
import PlutusLedgerApi.V3
import PlutusTx.AssocMap qualified as Map

validatorCodeFullyApplied :: CompiledCode BuiltinUnit
validatorCodeFullyApplied =
loanValidatorCode `unsafeApplyCode` liftCodeDef (toBuiltinData testScriptContext)

testScriptContext :: ScriptContext
testScriptContext =
ScriptContext
{ scriptContextTxInfo = txInfo
, scriptContextRedeemer
, scriptContextScriptInfo
}
where
txInfo =
TxInfo
{ txInfoInputs =
[
TxInInfo
{ txInInfoOutRef = txOutRef
, txInInfoResolved = Tx.pubKeyHashTxOut (Value.lovelaceValue 1000) testBeneficiaryPKH
}
]
, txInfoReferenceInputs = mempty
, txInfoOutputs = [
TxOut
{ txOutAddress = pubKeyHashAddress testBeneficiaryPKH
, txOutValue = Value.lovelaceValue 1000
, txOutDatum = NoOutputDatum
, txOutReferenceScript = Nothing
}
]
, txInfoTxCerts = mempty
, txInfoRedeemers = Map.empty
, txInfoVotes = Map.empty
, txInfoProposalProcedures = mempty
, txInfoCurrentTreasuryAmount = Nothing
, txInfoTreasuryDonation = Nothing
, txInfoFee = 0
, txInfoMint = emptyMintValue
, txInfoWdrl = Map.empty
, txInfoValidRange =
Interval
(LowerBound (Finite 110) True)
(UpperBound (Finite 1100) True)
, txInfoSignatories = [testBeneficiaryPKH]
, txInfoData = Map.empty
, txInfoId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145"
}

scriptContextRedeemer :: Redeemer
scriptContextRedeemer = Redeemer $ toBuiltinData CloseAsk

txOutRef :: TxOutRef
txOutRef = TxOutRef txOutRefId txOutRefIdx
where
txOutRefId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145"
txOutRefIdx = 0

scriptContextScriptInfo :: ScriptInfo
scriptContextScriptInfo = SpendingScript txOutRef (Just datum)
where
datum :: Datum
datum = Datum (toBuiltinData testLoanDatum)

testLoanDatum :: LoanDatum
testLoanDatum = askDatum
where
testCurSym :: CurrencySymbol
testCurSym = CurrencySymbol "mysymbol"

testTokName :: TokenName
testTokName = TokenName "mytoken"

askDatum :: LoanDatum
askDatum = AskDatum
{ collateral = [(testCurSym, testTokName)]
, askBeacon = (testCurSym, testTokName)
, borrowerId = (testCurSym, testTokName)
, loanAsset = (testCurSym, testTokName)
, loanPrinciple = 10
, loanTerm = 10
}

testBeneficiaryPKH :: PubKeyHash
testBeneficiaryPKH = PubKeyHash ""
Loading