Skip to content

Commit

Permalink
Fix discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
performanceArtist committed Jul 27, 2021
1 parent f57adab commit 95b5e4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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.IncentivizedAmount (accrue)
import Plutus.Abstract.OutputValue (OutputValue (..),
_ovValue)
import qualified Plutus.Abstract.State as State
Expand All @@ -40,7 +41,10 @@ import Plutus.Contracts.LendingPool.OnChain.Core (Aave (..),
AaveScript,
Reserve (..),
UserConfig (..),
UserConfigId, getAaveState, reserveStateToken, userStateToken)
UserConfigId,
getAaveState,
reserveStateToken,
userStateToken)
import qualified Plutus.Contracts.LendingPool.OnChain.Core as Core
import qualified Plutus.Contracts.Service.FungibleToken as FungibleToken
import Plutus.V1.Ledger.Ada (adaValueOf,
Expand All @@ -54,7 +58,6 @@ import PlutusTx.Prelude hiding (Functor (..),
import Prelude (Semigroup (..),
fmap)
import qualified Prelude
import Plutus.Abstract.IncentivizedAmount (accrue)

findOutputsBy :: Aave -> AssetClass -> (AaveDatum -> Maybe a) -> Contract w s Text [OutputValue a]
findOutputsBy aave = State.findOutputsBy (Core.aaveAddress aave)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ toBoolPrefixed prefix = toBool . Bifunctor.first (Builtins.appendString prefix)

assertValidCurrentSlot :: ScriptContext -> Slot -> Either Builtins.String ()
assertValidCurrentSlot ctx slot = fromBool "Invalid current slot value" $
Interval.member slot (posixTimeRangeToSlotRange . txInfoValidRange . scriptContextTxInfo $ ctx)
Interval.LowerBound (Interval.Finite slot) True == Interval.ivFrom (posixTimeRangeToSlotRange . txInfoValidRange . scriptContextTxInfo $ ctx)

findUserConfigs :: ScriptContext -> AaveState -> Either Builtins.String (AssocMap.Map UserConfigId UserConfig)
findUserConfigs ctx state@AaveState{..} = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ aaveInstance aave = Scripts.mkTypedValidator @AaveScript
-- Main validator
-- Each state field must have one or more associated actions(Redeemer types),
-- produced on state update, which are then validated here
-- TODO: combine state(datums) in order to ensure that there is only one redeemer for all inputs
makeAaveValidator :: Aave
-> AaveDatum
-> AaveRedeemer
-> ScriptContext
-> Bool
makeAaveValidator aave datum StartRedeemer ctx = trace "StartRedeemer" $ validateStart aave datum ctx
makeAaveValidator aave datum StartRedeemer ctx = trace "StartRedeemer" $ validateStart aave datum ctx
makeAaveValidator aave datum (DepositRedeemer userConfigId) ctx = trace "DepositRedeemer" $ validateDeposit aave datum ctx userConfigId
makeAaveValidator aave datum (WithdrawRedeemer userConfigId) ctx = trace "WithdrawRedeemer" $ validateWithdraw aave datum ctx userConfigId
makeAaveValidator aave datum (BorrowRedeemer userConfigId oracles slot) ctx = trace "BorrowRedeemer" $ validateBorrow aave datum ctx userConfigId oracles slot
Expand Down Expand Up @@ -132,7 +133,7 @@ validateDeposit aave (UserConfigsDatum state@AaveState{..} userConfigs) ctx user
unless
(maybe ((iaAmount . ucCollateralizedInvestment) newState == (fromInteger 0)) ((ucCollateralizedInvestment newState ==) . ucCollateralizedInvestment) oldState &&
(iaAmount . ucDebt $ newState) == (fromInteger 0) && maybe True ((== (fromInteger 0)) . iaAmount . ucDebt) oldState)
(throwError "")
(throwError "Change is not valid")

validateDeposit aave (ReservesDatum state reserves) ctx userConfigId =
traceIfFalse "validateDeposit: Reserves Datum change is not valid" $ checkPositiveReservesTransformation state reserves ctx userConfigId
Expand Down Expand Up @@ -178,7 +179,7 @@ validateBorrow aave (UserConfigsDatum state@AaveState{..} userConfigs) ctx userC
unless
(debtAmount == disbursementAmount && debtAmount > fromInteger 0 && disbursementAmount > fromInteger 0 &&
(iaAmount . ucCollateralizedInvestment $ newState) == (fromInteger 0) && maybe True ((== (fromInteger 0)) . iaAmount . ucCollateralizedInvestment) oldState)
(throwError "")
(throwError "Change is not valid")

validateBorrow aave (ReservesDatum stateToken reserves) ctx userConfigId oracles _ =
traceIfFalse "validateBorrow: Reserves Datum change is not valid" $ checkNegativeReservesTransformation stateToken reserves ctx userConfigId && areOraclesTrusted oracles reserves
Expand Down Expand Up @@ -208,7 +209,7 @@ validateRepay aave (UserConfigsDatum state@AaveState{..} userConfigs) ctx userCo
unless
(debtChange == reimbursementAmount && debtChange > fromInteger 0 && reimbursementAmount > fromInteger 0 && newDebt >= (fromInteger 0) &&
ucCollateralizedInvestment newState == ucCollateralizedInvestment accState)
(throwError "")
(throwError "Change is not valid")

validateRepay aave (ReservesDatum stateToken reserves) ctx userConfigId _ =
traceIfFalse "validateRepay: Reserves Datum change is not valid" $ checkPositiveReservesTransformation stateToken reserves ctx userConfigId
Expand All @@ -234,7 +235,7 @@ validateProvideCollateral aave (UserConfigsDatum state@AaveState{..} userConfigs
unless
(user == actor && investmentAmount == disbursementAmount && investmentAmount > fromInteger 0 && disbursementAmount > fromInteger 0 &&
(iaAmount . ucDebt $ newState) == (fromInteger 0) && maybe True ((== (fromInteger 0)) . iaAmount . ucDebt) oldState)
(throwError "")
(throwError "Change is not valid")

validateProvideCollateral _ _ _ _ = trace "Lending Pool Datum management is not allowed" False

Expand Down Expand Up @@ -263,7 +264,7 @@ validateRevokeCollateral aave (UserConfigsDatum state@AaveState{..} userConfigs)
unless
(investmentShrinkedBy == disbursementAmount && investmentShrinkedBy > fromInteger 0 &&
disbursementAmount > fromInteger 0 && ucDebt newState == IncentivizedAmount slot (rCurrentStableBorrowRate reserve) (iaAmount . ucDebt $ accState))
(throwError "")
(throwError "Change is not valid")

validateRevokeCollateral aave (UserCollateralFundsDatum owner aTokenAsset) ctx (reserveId, actor) revokedAsset oracles _ =
traceIfFalse "validateRevokeCollateral: UserCollateralFundsDatum change is not valid" $
Expand Down

0 comments on commit 95b5e4d

Please sign in to comment.