Skip to content

Commit

Permalink
Merge pull request #52 from input-output-hk/MetaLamp/lending-pool/cha…
Browse files Browse the repository at this point in the history
…nge-folder-structure

[WIP] Change folder structure
  • Loading branch information
stanislav-az authored Jul 2, 2021
2 parents 58ccc2c + 6367a55 commit 5057326
Show file tree
Hide file tree
Showing 46 changed files with 1,347 additions and 873 deletions.
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/Business/Aave.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Data.Lens (Prism', preview)
import Data.Maybe (Maybe, maybe)
import Data.RawJson (RawJson(..))
import Foreign.Generic (class Decode, class Encode, decodeJSON)
import Plutus.Contracts.Endpoints (ContractResponse(..))
import Plutus.Abstract.ContractResponse (ContractResponse(..))
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse(..))
import Plutus.PAB.Simulation (AaveContracts)
import Plutus.PAB.Webserver.Types (ContractInstanceClientState(..))
Expand Down
4 changes: 2 additions & 2 deletions MetaLamp/lending-pool/client/src/Business/AaveInfo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Data.Either (Either)
import Data.Json.JsonTuple (JsonTuple)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype, unwrap)
import Plutus.Contracts.Core (Reserve, UserConfig)
import Plutus.Contracts.Endpoints (_FundsAt, _PoolFunds, _Reserves, _Users)
import Plutus.Contracts.LendingPool.OnChain.Core.Script (Reserve, UserConfig)
import Plutus.Contracts.LendingPool.OffChain.Info (_FundsAt, _PoolFunds, _Reserves, _Users)
import Plutus.PAB.Simulation (AaveContracts, _AaveInfo)
import Plutus.PAB.Webserver.Types (ContractInstanceClientState)
import Plutus.V1.Ledger.Crypto (PubKeyHash)
Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/Business/AaveUser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Capability.PollContract (class PollContract, PollError)
import Data.Either (Either)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype, unwrap)
import Plutus.Contracts.Endpoints (BorrowParams, ProvideCollateralParams, RevokeCollateralParams, DepositParams, RepayParams, WithdrawParams, _Borrowed, _Deposited, _GetPubKey, _GetPubKeyBalance, _Repaid, _Withdrawn, _CollateralProvided, _CollateralRevoked)
import Plutus.Contracts.LendingPool.OffChain.User (BorrowParams, ProvideCollateralParams, RevokeCollateralParams, DepositParams, RepayParams, WithdrawParams, _Borrowed, _Deposited, _GetPubKey, _GetPubKeyBalance, _Repaid, _Withdrawn, _CollateralProvided, _CollateralRevoked)
import Plutus.PAB.Simulation (AaveContracts, _AaveUser)
import Plutus.PAB.Webserver.Types (ContractInstanceClientState)
import Plutus.V1.Ledger.Crypto (PubKeyHash)
Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/Component/Contract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Halogen as H
import Halogen.HTML as HH
import Network.RemoteData (RemoteData(..))
import Network.RemoteData as RD
import Plutus.Contracts.Endpoints (BorrowParams(..), DepositParams(..), RepayParams(..), WithdrawParams(..), ProvideCollateralParams(..), RevokeCollateralParams(..))
import Plutus.Contracts.LendingPool.OffChain.User (BorrowParams(..), DepositParams(..), RepayParams(..), WithdrawParams(..), ProvideCollateralParams(..), RevokeCollateralParams(..))
import Plutus.V1.Ledger.Crypto (PubKeyHash)
import Plutus.V1.Ledger.Value (AssetClass(..), TokenName(..), Value)
import View.FundsTable (fundsTable)
Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/Component/MainPage.purs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Halogen.HTML.Properties (classes)
import Network.RemoteData (RemoteData(..))
import Network.RemoteData as RD
import Network.RemoteData as RemoteData
import Plutus.Contracts.Core (Reserve(..), UserConfig)
import Plutus.Contracts.LendingPool.OnChain.Core.Script (Reserve(..), UserConfig)
import Plutus.PAB.Simulation (AaveContracts)
import Plutus.PAB.Webserver.Types (ContractInstanceClientState)
import Plutus.V1.Ledger.Crypto (PubKeyHash)
Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/View/ReserveInfo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module View.ReserveInfo where
import Prelude
import Data.BigInteger (BigInteger)
import Halogen.HTML as HH
import Plutus.Contracts.Core (Reserve(..))
import Plutus.Contracts.LendingPool.OnChain.Core.Script (Reserve(..))
import Plutus.V1.Ledger.Value (AssetClass)
import View.Utils (assetName)

Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/client/src/View/UsersTable.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.BigInteger (fromInt)
import Data.Maybe (fromMaybe)
import Data.Tuple (Tuple(..))
import Halogen.HTML as HH
import Plutus.Contracts.Core (UserConfig(..))
import Plutus.Contracts.LendingPool.OnChain.Core.Script (UserConfig(..))
import Plutus.V1.Ledger.Value (AssetClass)
import View.Utils (assetName)

Expand Down
50 changes: 27 additions & 23 deletions MetaLamp/lending-pool/generate-purs/AaveTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@

module AaveTypes where

import Control.Monad.Reader (MonadReader)
import Data.Proxy (Proxy (Proxy))
import Language.PureScript.Bridge (BridgePart,
Language (Haskell),
PSType, SumType,
TypeInfo (TypeInfo),
buildBridge, equal,
genericShow,
haskType, mkSumType,
order,
psTypeParameters,
typeModule,
typeName,
writePSTypesWith,
(^==))
import Language.PureScript.Bridge.Builder (BridgeData)
import Language.PureScript.Bridge.TypeParameters (A, E)
import Control.Monad.Reader (MonadReader)
import Data.Proxy (Proxy (Proxy))
import Language.PureScript.Bridge (BridgePart,
Language (Haskell),
PSType, SumType,
TypeInfo (TypeInfo),
buildBridge,
equal,
genericShow,
haskType,
mkSumType, order,
psTypeParameters,
typeModule,
typeName,
writePSTypesWith,
(^==))
import Language.PureScript.Bridge.Builder (BridgeData)
import Language.PureScript.Bridge.TypeParameters (A, E)
import qualified PSGenerator.Common
import qualified Plutus.Contracts.Core as Aave
import qualified Plutus.Contracts.Endpoints as Aave
import qualified Plutus.Contracts.Oracle as Oracle
import Plutus.PAB.Simulation (AaveContracts (..))
import Plutus.V1.Ledger.Value (AssetClass)
import Plutus.Abstract.ContractResponse (ContractResponse)
import qualified Plutus.Contracts.LendingPool.OffChain.Info as Aave
import qualified Plutus.Contracts.LendingPool.OffChain.Owner as Aave
import qualified Plutus.Contracts.LendingPool.OffChain.User as Aave
import qualified Plutus.Contracts.LendingPool.OnChain.Core as Aave
import qualified Plutus.Contracts.Service.Oracle as Oracle
import Plutus.PAB.Simulation (AaveContracts (..))
import Plutus.V1.Ledger.Value (AssetClass)

ratioBridge :: BridgePart
ratioBridge = do
Expand All @@ -50,7 +54,7 @@ aaveTypes :: [SumType 'Haskell]
aaveTypes = [ (equal <*> (genericShow <*> mkSumType)) (Proxy @AaveContracts)
, (equal <*> (genericShow <*> mkSumType)) (Proxy @Aave.Aave)
, (equal <*> (genericShow <*> mkSumType)) (Proxy @Oracle.Oracle)
, (equal <*> (genericShow <*> mkSumType)) (Proxy @(Aave.ContractResponse E A))
, (equal <*> (genericShow <*> mkSumType)) (Proxy @(ContractResponse E A))
, (equal <*> (genericShow <*> mkSumType)) (Proxy @Aave.CreateParams)
, (order <*> (equal <*> (genericShow <*> mkSumType))) (Proxy @AssetClass)
, (equal <*> (genericShow <*> mkSumType)) (Proxy @Aave.UserContractState)
Expand Down
1 change: 0 additions & 1 deletion MetaLamp/lending-pool/generate-purs/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Main where

Expand Down
2 changes: 1 addition & 1 deletion MetaLamp/lending-pool/plutus-starter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ maintainer: Your email

library
exposed-modules:
Plutus.Contracts.Endpoints Plutus.Contracts.FungibleToken Plutus.Contracts.AToken Plutus.Contracts.Core Plutus.Contracts.Oracle Plutus.Contracts.State Plutus.State.Select Plutus.State.Update Plutus.Contracts.TxUtils Plutus.OutputValue Ext.Plutus.Ledger.Contexts Plutus.PAB.Simulation
Plutus.Abstract.State Plutus.Abstract.State.Select Plutus.Abstract.State.Update Plutus.Abstract.ContractResponse Plutus.Abstract.OutputValue Plutus.Abstract.TxUtils Plutus.Contracts.Service.FungibleToken Plutus.Contracts.Service.Oracle Plutus.Contracts.LendingPool.OnChain.Core Plutus.Contracts.LendingPool.OnChain.Core.Script Plutus.Contracts.LendingPool.OnChain.Core.Validator Plutus.Contracts.LendingPool.OnChain.Core.Logic Plutus.Contracts.LendingPool.OnChain.AToken Plutus.Contracts.LendingPool.OffChain.AToken Plutus.Contracts.LendingPool.OffChain.Info Plutus.Contracts.LendingPool.OffChain.Owner Plutus.Contracts.LendingPool.OffChain.State Plutus.Contracts.LendingPool.OffChain.User Plutus.PAB.Simulation Ext.Plutus.Ledger.Value Ext.Plutus.Ledger.Contexts
build-depends:
base >= 4.9 && < 5,
aeson,
Expand Down
10 changes: 10 additions & 0 deletions MetaLamp/lending-pool/src/Ext/Plutus/Ledger/Value.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Ext.Plutus.Ledger.Value where

import qualified Data.Map as Map
import Ledger (TxOut (txOutValue),
TxOutTx (txOutTxOut), Value)
import Ledger.AddressMap (UtxoMap)
import Plutus.V1.Ledger.Value (Value)

utxoValue :: UtxoMap -> Value
utxoValue = foldMap (txOutValue . txOutTxOut . snd) . Map.toList
85 changes: 85 additions & 0 deletions MetaLamp/lending-pool/src/Plutus/Abstract/ContractResponse.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Plutus.Abstract.ContractResponse where

import qualified Control.Lens as Lens
import Control.Monad hiding (fmap)
import qualified Data.ByteString as BS
import qualified Data.Map as Map
import Data.Monoid (Last (..))
import Data.Proxy (Proxy (..))
import Data.Text (Text, pack)
import qualified Data.Text as Text
import Data.Void (Void)
import Ledger hiding (singleton)
import Ledger.Constraints as Constraints
import Ledger.Constraints.OnChain as Constraints
import Ledger.Constraints.TxConstraints as Constraints
import qualified Ledger.Scripts as Scripts
import qualified Ledger.Typed.Scripts as Scripts
import Playground.Contract
import Plutus.Abstract.OutputValue (OutputValue (..))
import qualified Plutus.Abstract.TxUtils as TxUtils
import Plutus.Contract hiding (when)
import Plutus.Contracts.Currency as Currency
import Plutus.Contracts.LendingPool.OnChain.Core (Aave,
AaveDatum (..),
AaveRedeemer (..),
Reserve (..),
UserConfig (..))
import qualified Plutus.Contracts.LendingPool.OnChain.Core as Core
import qualified Plutus.Contracts.Service.FungibleToken as FungibleToken
import Plutus.V1.Ledger.Ada (adaValueOf,
lovelaceValueOf)
import qualified Plutus.V1.Ledger.Address as Addr
import Plutus.V1.Ledger.Value as Value
import qualified PlutusTx
import qualified PlutusTx.AssocMap as AssocMap
import PlutusTx.Prelude hiding (Monoid (..),
Semigroup (..),
mconcat, unless)
import Prelude (Monoid (..),
Semigroup (..),
show, subtract)
import qualified Prelude
import Text.Printf (printf)

data ContractResponse e a = ContractSuccess a | ContractError e | ContractPending
deriving stock (Prelude.Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

instance Semigroup (ContractResponse e a) where
a <> b = b

instance Monoid (ContractResponse e a) where
mempty = ContractPending
mappend = (<>)

withContractResponse :: forall l a p r s.
HasEndpoint l p s
=> Proxy l
-> (a -> r)
-> (p -> Contract (ContractResponse Text r) s Text a)
-> Contract (ContractResponse Text r) s Void ()
withContractResponse _ g c = do
e <- runError $ do
p <- endpoint @l
_ <- tell ContractPending
errorHandler `handleError` c p
tell $ case e of
Left err -> ContractError err
Right a -> ContractSuccess $ g a
where
errorHandler e = do
logInfo @Text ("Error submiting the transaction: " <> e)
throwError e
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}

module Plutus.OutputValue where
module Plutus.Abstract.OutputValue where

import Control.Lens (makeClassy_)
import Ledger (TxOutRef, TxOutTx)
Expand Down
6 changes: 6 additions & 0 deletions MetaLamp/lending-pool/src/Plutus/Abstract/State.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Plutus.Abstract.State (module Export)

where

import Plutus.Abstract.State.Select as Export
import Plutus.Abstract.State.Update as Export
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

module Plutus.State.Select where
module Plutus.Abstract.State.Select where

import Control.Monad hiding (fmap)
import qualified Data.ByteString as BS
Expand All @@ -22,8 +22,8 @@ import Ledger.Constraints.TxConstraints as Constraints
import qualified Ledger.Scripts as Scripts
import qualified Ledger.Typed.Scripts as Scripts
import Playground.Contract
import Plutus.Abstract.OutputValue (OutputValue (..))
import Plutus.Contract hiding (when)
import Plutus.OutputValue (OutputValue (..))
import Plutus.V1.Ledger.Value
import qualified PlutusTx
import PlutusTx.Prelude hiding (Semigroup (..),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Plutus.State.Update where
module Plutus.Abstract.State.Update where

import Control.Monad hiding (fmap)
import qualified Data.ByteString as BS
Expand All @@ -31,9 +31,9 @@ import qualified Ledger.Scripts as UntypedScripts
import Ledger.Typed.Scripts (DatumType, RedeemerType)
import qualified Ledger.Typed.Scripts as Scripts
import Playground.Contract
import Plutus.Abstract.OutputValue (OutputValue (..))
import qualified Plutus.Abstract.TxUtils as TxUtils
import Plutus.Contract hiding (when)
import qualified Plutus.Contracts.TxUtils as TxUtils
import Plutus.OutputValue (OutputValue (..))
import Plutus.V1.Ledger.Value
import PlutusTx (IsData)
import qualified PlutusTx
Expand Down
Loading

0 comments on commit 5057326

Please sign in to comment.