Skip to content
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

implement loan example #137

Open
aleeusgr opened this issue Oct 25, 2024 · 2 comments
Open

implement loan example #137

aleeusgr opened this issue Oct 25, 2024 · 2 comments

Comments

@aleeusgr
Copy link
Owner

aleeusgr commented Oct 25, 2024

@aleeusgr
Copy link
Owner Author

aleeusgr commented Oct 25, 2024

data LoanActions = RequestLoan | CancelLoan deriving Eq
data LoanBond = LB { borrower :: PubKeyHash
                   , request  :: Ledger.Value
                   , duration :: POSIXTime
                   , collateral :: Ledger.Value
                   }

https://github.com/Vortecsmaster/EA_PlutusExamples/blob/f66688a3eecd803eed4582a3de279c844a427505/PlutusApps/V2_110/LendingPlatform/src/RequestLoan.hs#L48-L53

@aleeusgr
Copy link
Owner Author

aleeusgr commented Oct 25, 2024

{-# INLINABLE loanRequest #-} 
loanRequest :: LoanBond -> LoanActions -> PlutusV2.ScriptContext -> Bool   
loanRequest datum action sContext 
  | action == RequestLoan      = requestLoan 
  | action == CancelLoan       = cancelLoan  
  | otherwise                  = False
  where


    info :: LedgerV2.TxInfo
    info = LedgerV2.scriptContextTxInfo sContext


    timeoutReached :: Bool
    timeoutReached = contains (from $ duration datum) (LedgerV2.txInfoValidRange info)   
 
    requestLoan :: Bool
    requestLoan = timeoutReached  


    cancelLoan :: Bool
    cancelLoan = if (length (txInfoOutputs info) == 1) then (pubKeyHashAddress $ borrower datum) == txOutAddress $ head ((txInfoOutputs info))

https://github.com/Vortecsmaster/EA_PlutusExamples/blob/f66688a3eecd803eed4582a3de279c844a427505/PlutusApps/V2_110/LendingPlatform/src/UsingSCvalidator.hs#L70-L76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant