-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbfa664
commit ce23cba
Showing
13 changed files
with
438 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
MetaLamp/lending-pool/src/Plutus/Abstract/IncentivizedAmount.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE DeriveFunctor #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# OPTIONS_GHC -fno-specialise #-} | ||
{-# OPTIONS_GHC -fno-strictness #-} | ||
{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fobject-code #-} | ||
|
||
module Plutus.Abstract.IncentivizedAmount where | ||
|
||
import Plutus.V1.Ledger.Slot (Slot(..)) | ||
import PlutusTx.Prelude | ||
import qualified Prelude | ||
import Data.Aeson(ToJSON, FromJSON) | ||
import GHC.Generics | ||
import Schema (ToSchema) | ||
import qualified PlutusTx | ||
import PlutusTx.Ratio (Ratio) | ||
import qualified Plutus.Abstract.TxUtils as TxUtils | ||
import qualified Control.Lens as Lens | ||
|
||
data IncentivizedAmount = IncentivizedAmount{ iaSlot :: Slot, iaRate :: Rational, iaAmount :: Rational } | ||
deriving stock (Prelude.Eq, Prelude.Show, Generic) | ||
deriving anyclass (ToJSON, FromJSON) | ||
|
||
Lens.makeClassy_ ''IncentivizedAmount | ||
|
||
instance Eq IncentivizedAmount where | ||
a == b = iaSlot a == iaSlot b && iaAmount a == iaAmount b && iaRate a == iaRate b | ||
|
||
{-# INLINABLE accrue #-} | ||
accrue :: Rational -> Slot -> IncentivizedAmount -> IncentivizedAmount | ||
accrue newRate newSlot (IncentivizedAmount oldSlot oldRate amount) = IncentivizedAmount newSlot newRate (amount * oldRate) | ||
|
||
{-(worker amount (getSlot $ newSlot - oldSlot)) | ||
where | ||
worker amount slot = if slot > 0 then worker (rate * amount) (slot - 1) else amount-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.