Skip to content

Commit

Permalink
update to latest dstoken and morley 1.0.0, remove unsafe Generic stub…
Browse files Browse the repository at this point in the history
…s, define new entrypoints instances (tests sans known balance bug passing)
  • Loading branch information
michaeljklein committed Apr 9, 2020
1 parent 338253e commit 661ca74
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 115 deletions.
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ someLorentzContract (SomeContract (contract' :: FullContract cp st)) =
assertNestedBigMapAbsense @st $
assertContractTypeAbsense @st $
L.SomeContract $
(L.I fcCode :: L.Contract param (L.Value st))
(L.I fcCode :: L.ContractCode param (L.Value st))

main :: IO ()
main = do
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ flags:
dependencies:
- base >= 4.7 && < 5
- morley
- lorentz
- named
- singletons
- text
Expand Down Expand Up @@ -63,7 +64,6 @@ executables:
dependencies:
- prototype-forwarder-contract
- morley
# - morley-prelude
- morley-nettest
- fmt
- optparse-applicative
Expand Down
9 changes: 6 additions & 3 deletions prototype-forwarder-contract.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.1.
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: e7222fd6fc9c99f39ba4ef0ed09be6d93bb3f430ed9c84aebf62c7126ebbc38f
-- hash: 8dd11b0d753bd02e4d5444d784136fd7caf894e26118b1a805f85c279f82c371

name: prototype-forwarder-contract
version: 0.1.0.0
Expand Down Expand Up @@ -32,7 +32,6 @@ flag dstoken

library
exposed-modules:
GHC.Natural.Orphans
Lorentz.Contracts.Expiring
Lorentz.Contracts.Forwarder
Lorentz.Contracts.Forwarder.DS.V1
Expand All @@ -46,6 +45,7 @@ library
Lorentz.Contracts.Product
Lorentz.Contracts.Validate.Reception
Lorentz.Contracts.View
Michelson.Typed.Value.Orphans
other-modules:
Paths_prototype_forwarder_contract
hs-source-dirs:
Expand All @@ -54,6 +54,7 @@ library
base >=4.7 && <5
, constraints
, containers
, lorentz
, morley
, morley-ledgers
, morley-nettest
Expand Down Expand Up @@ -84,6 +85,7 @@ executable prototype-forwarder-contract
, constraints
, containers
, fmt
, lorentz
, morley
, morley-ledgers
, morley-nettest
Expand Down Expand Up @@ -129,6 +131,7 @@ test-suite prototype-forwarder-contract-test
, containers
, fmt
, hspec
, lorentz
, morley
, morley-ledgers
, morley-nettest
Expand Down
48 changes: 0 additions & 48 deletions src/GHC/Natural/Orphans.hs

This file was deleted.

8 changes: 5 additions & 3 deletions src/Lorentz/Contracts/Expiring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ data Parameter cp
| GetExpiration (View_ Timestamp)
deriving (Generic)

instance NiceParameter cp => ParameterHasEntryPoints (Parameter cp) where
instance HasTypeAnn cp => HasTypeAnn (Parameter cp)

instance (HasTypeAnn cp, NiceParameter cp) => ParameterHasEntryPoints (Parameter cp) where
type ParameterEntryPointsDerivation (Parameter cp) = EpdNone

deriving instance Read cp => Read (Parameter cp)
Expand Down Expand Up @@ -92,8 +94,8 @@ assertNotExpired = do
--
-- Caveat: Up to error due to `now`, see `assertNotExpired` for more info
expiringContract :: forall cp st. IsoValue cp
=> Contract cp st
-> Contract (Parameter cp) (Storage st)
=> ContractCode cp st
-> ContractCode (Parameter cp) (Storage st)
expiringContract wrappedContract = do
unpair
caseT @(Parameter cp)
Expand Down
3 changes: 2 additions & 1 deletion src/Lorentz/Contracts/Forwarder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Lorentz.Contracts.Forwarder where

import Lorentz
import qualified Lorentz.Contracts.ManagedLedger as ManagedLedger
import qualified Lorentz.Contracts.Spec.AbstractLedgerInterface as ManagedLedger (TransferParams)

import Prelude (Show(..), Enum(..))

Expand Down Expand Up @@ -92,7 +93,7 @@ processRefund = do

-- | Given a method to calculate the number of `Mutez` to refund from the number
-- of sub-tokens transferred, produce a forwarder contract.
forwarderContract :: (forall s. (Natural & s) :-> (Mutez & s)) -> Contract Parameter Storage
forwarderContract :: (forall s. (Natural & s) :-> (Mutez & s)) -> ContractCode Parameter Storage
forwarderContract calculateGasCost = do
unpair
dup
Expand Down
2 changes: 1 addition & 1 deletion src/Lorentz/Contracts/Forwarder/DS/V1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ runTransfer = do

-- | Forwarder contract: forwards the given number of sub-tokens
-- from its own address to the central wallet.
forwarderContract :: Contract Parameter Storage
forwarderContract :: ContractCode Parameter Storage
forwarderContract = do
unpair
runTransfer
Expand Down
6 changes: 3 additions & 3 deletions src/Lorentz/Contracts/Forwarder/DS/V1/Specialized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ runSpecializedTransfer centralWalletAddr' (ContractRef contractAddr' _) = do

-- | Forwarder contract: forwards the given number of sub-tokens
-- from its own address to the central wallet.
specializedForwarderContract :: Address -> ContractRef DS.Parameter -> Contract Parameter Storage
specializedForwarderContract :: Address -> ContractRef DS.Parameter -> ContractCode Parameter Storage
specializedForwarderContract centralWalletAddr' contractAddr' = do
car
runSpecializedTransfer centralWalletAddr' contractAddr'
Expand All @@ -77,13 +77,13 @@ analyzeSpecializedForwarder :: Address -> ContractRef DS.Parameter -> AnalyzerRe
analyzeSpecializedForwarder centralWalletAddr' contractAddr' =
analyzeLorentz $ specializedForwarderContract centralWalletAddr' contractAddr'

contractOverValue :: forall cp st. Contract cp st -> Contract (Value (ToT cp)) (Value (ToT st))
contractOverValue :: forall cp st. ContractCode cp st -> ContractCode (Value (ToT cp)) (Value (ToT st))
contractOverValue x = forcedCoerce_ # x # forcedCoerce_

-- | Verify that `SomeContract` is an instance of `specializedForwarderContract`, for some
-- particular central wallet address and DS Token address.
verifyForwarderContract :: Address -> ContractRef DS.Parameter -> SomeContract -> Either String ()
verifyForwarderContract centralWalletAddr' dsTokenContractRef' (SomeContract (contract' :: Contract cp st)) =
verifyForwarderContract centralWalletAddr' dsTokenContractRef' (SomeContract (contract' :: ContractCode cp st)) =
case eqT @(ToT cp) @(ToT Parameter) of
Nothing -> Left $ "Unexpected parameter type: " <> show (typeRep (Proxy @(ToT cp)))
Just Refl ->
Expand Down
2 changes: 1 addition & 1 deletion src/Lorentz/Contracts/Forwarder/DS/V1/Validated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mkStorageWithInvestorIds whitelist' =
-- | A contract that:
-- - Offers a `Forwarder.specializedForwarderContract` interface
-- - Offers a `ValidateReception.validateReceptionContract` interface
validatedForwarderContract :: Address -> ContractRef DS.Parameter -> Contract Parameter Storage
validatedForwarderContract :: Address -> ContractRef DS.Parameter -> ContractCode Parameter Storage
validatedForwarderContract centralWalletAddr' contractAddr' =
productContract
(Forwarder.specializedForwarderContract centralWalletAddr' contractAddr')
Expand Down
2 changes: 1 addition & 1 deletion src/Lorentz/Contracts/Forwarder/DS/V1/ValidatedExpiring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mkStorageWithInvestorIds whitelist' =
-- - Expires after the given timestamp in `Expiring.Storage`
-- - Offers a `Forwarder.specializedForwarderContract` interface
-- - Offers a `ValidateReception.validateReceptionContract` interface
validatedExpiringForwarderContract :: Address -> ContractRef DS.Parameter -> Contract Parameter Storage
validatedExpiringForwarderContract :: Address -> ContractRef DS.Parameter -> ContractCode Parameter Storage
validatedExpiringForwarderContract centralWalletAddr' contractAddr' =
Expiring.expiringContract $
productContract
Expand Down
10 changes: 5 additions & 5 deletions src/Lorentz/Contracts/Forwarder/Specialized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import Lorentz.Base (SomeContract(..))
import Michelson.Analyzer (AnalyzerRes)
import Michelson.Text

import Lorentz.Contracts.Spec.AbstractLedgerInterface (TransferParams)
import Lorentz.Contracts.Spec.AbstractLedgerInterface (TransferParams)

import Data.Type.Equality
import Data.Typeable
import Prelude (Enum(..), Eq(..), ($), String, show)

import GHC.Natural.Orphans ()
import Michelson.Typed.Value.Orphans ()


-- | The number of sub-tokens to forward
Expand Down Expand Up @@ -67,7 +67,7 @@ runSpecializedTransfer centralWalletAddr' contractAddr' = do

-- | Forwarder contract: forwards the given number of sub-tokens
-- from its own address to the central wallet.
specializedForwarderContract :: Address -> Address -> Contract Parameter Storage
specializedForwarderContract :: Address -> Address -> ContractCode Parameter Storage
specializedForwarderContract centralWalletAddr' contractAddr' = do
car
runSpecializedTransfer centralWalletAddr' contractAddr'
Expand All @@ -81,13 +81,13 @@ analyzeSpecializedForwarder centralWalletAddr' contractAddr' =
analyzeLorentz $ specializedForwarderContract centralWalletAddr' contractAddr'

-- | `forcedCoerce_` to convert parameter and storage types to their `Value` equivalents
contractOverValue :: forall cp st. Contract cp st -> Contract (Value (ToT cp)) (Value (ToT st))
contractOverValue :: forall cp st. ContractCode cp st -> ContractCode (Value (ToT cp)) (Value (ToT st))
contractOverValue x = forcedCoerce_ # x # forcedCoerce_

-- | Verify that `SomeContract` is an instance of `specializedForwarderContract`, for some
-- particular central wallet address and token address.
verifyForwarderContract :: Address -> Address -> SomeContract -> Either String ()
verifyForwarderContract centralWalletAddr' tokenAddr' (SomeContract (contract' :: Contract cp st)) =
verifyForwarderContract centralWalletAddr' tokenAddr' (SomeContract (contract' :: ContractCode cp st)) =
case eqT @(ToT cp) @(ToT Parameter) of
Nothing -> Left $ "Unexpected parameter type: " <> show (typeRep (Proxy @(ToT cp)))
Just Refl ->
Expand Down
11 changes: 6 additions & 5 deletions src/Lorentz/Contracts/Forwarder/Specialized/FlushAny.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ import Lorentz.Contracts.Spec.AbstractLedgerInterface (TransferParams)
import qualified Lorentz.Contracts.Spec.AbstractLedgerInterface as AL
import qualified Lorentz.Contracts.Forwarder.Specialized as Specialized

import Data.Singletons
import Data.Type.Equality
import Data.Typeable
import Prelude (Show(..), Enum(..), Eq(..), ($), String, show)

import GHC.Natural.Orphans ()
import Michelson.Typed.Value.Orphans ()


-- | The number of sub-tokens to forward and which token to forward it on
Expand All @@ -50,6 +49,8 @@ data Parameter = Parameter
deriving stock Generic
deriving anyclass IsoValue

instance HasTypeAnn Parameter

instance ParameterHasEntryPoints Parameter where
type ParameterEntryPointsDerivation Parameter = EpdNone

Expand All @@ -72,7 +73,7 @@ mkParameter amountToFlush' tokenContract' =
mkEPCallRes' =
case mkEntryPointCall @(ToT AL.Parameter)
(EpNameUnsafe "transfer")
(sing, epParamNotes') of
epParamNotes' of
Nothing -> error "mkParameter: TransferParams does not have label 'transfer'"
Just xs -> xs

Expand Down Expand Up @@ -108,7 +109,7 @@ runSpecializedAnyTransfer centralWalletAddr' = do

-- | Forwarder contract: forwards the given number of sub-tokens
-- from its own address to the central wallet.
specializedAnyForwarderContract :: Address -> Contract Parameter Storage
specializedAnyForwarderContract :: Address -> ContractCode Parameter Storage
specializedAnyForwarderContract centralWalletAddr' = do
car
unParameter
Expand All @@ -126,7 +127,7 @@ analyzeSpecializedAnyForwarder centralWalletAddr' =
-- | Verify that `SomeContract` is an instance of `specializedAnyForwarderContract`, for some
-- particular central wallet address and token address.
verifyForwarderContract :: Address -> SomeContract -> Either String ()
verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: Contract cp st)) =
verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: ContractCode cp st)) =
case eqT @(ToT cp) @(ToT Parameter) of
Nothing -> Left $ "Unexpected parameter type: " <> show (typeRep (Proxy @(ToT cp)))
Just Refl ->
Expand Down
6 changes: 3 additions & 3 deletions src/Lorentz/Contracts/Forwarder/Specialized/FlushAny/Tez.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Data.Type.Equality
import Data.Typeable
import Prelude (Show(..), Enum(..), Eq(..), ($), String, show)

import GHC.Natural.Orphans ()
import Michelson.Typed.Value.Orphans ()

-- | We have the addresses of:
-- - The central wallet to transfer sub-tokens to
Expand Down Expand Up @@ -73,7 +73,7 @@ runSpecializedAnyTezTransfer centralWalletAddr' = do
-- from its own address to the central wallet.
--
-- It also forwards all held Tez to the central wallet.
specializedAnyTezForwarderContract :: Address -> Contract Parameter Storage
specializedAnyTezForwarderContract :: Address -> ContractCode Parameter Storage
specializedAnyTezForwarderContract centralWalletAddr' = do
car
FlushAny.unParameter
Expand All @@ -89,7 +89,7 @@ analyzeSpecializedAnyTezForwarder centralWalletAddr' =
-- | Verify that `SomeContract` is an instance of `specializedAnyTezForwarderContract`, for some
-- particular central wallet address and token address.
verifyForwarderContract :: Address -> SomeContract -> Either String ()
verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: Contract cp st)) =
verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: ContractCode cp st)) =
case eqT @(ToT cp) @(ToT Parameter) of
Nothing -> Left $ "Unexpected parameter type: " <> show (typeRep (Proxy @(ToT cp)))
Just Refl ->
Expand Down
14 changes: 9 additions & 5 deletions src/Lorentz/Contracts/Product.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ data (:|:) cp1 cp2
| RightParameter !cp2
deriving (Generic)

instance (HasTypeAnn cp1, HasTypeAnn cp2) => HasTypeAnn ((:|:) cp1 cp2)

instance ( NiceParameter cp1
, HasNoOp (ToT cp1)
, HasNoNestedBigMaps (ToT cp1)
, NiceParameter cp2
, HasNoOp (ToT cp1)
, HasNoOp (ToT cp2)
, HasNoNestedBigMaps (ToT cp1)
, HasNoNestedBigMaps (ToT cp2)
, HasTypeAnn cp1
, HasTypeAnn cp2
) => ParameterHasEntryPoints (cp1 :|: cp2) where
-- parameterEntryPoints = pepNone
type ParameterEntryPointsDerivation (cp1 :|: cp2) = EpdNone
Expand Down Expand Up @@ -74,9 +78,9 @@ toStorage = forcedCoerce_
-- accepting parameters from either (`:|:`) and holding storage
-- for both (`:&:`)
productContract :: forall cp1 st1 cp2 st2. (IsoValue cp1, IsoValue cp2)
=> Contract cp1 st1
-> Contract cp2 st2
-> Contract (cp1 :|: cp2) (st1 :&: st2)
=> ContractCode cp1 st1
-> ContractCode cp2 st2
-> ContractCode (cp1 :|: cp2) (st1 :&: st2)
productContract wrappedLeft wrappedRight = do
unpair
caseT @(cp1 :|: cp2)
Expand Down
2 changes: 1 addition & 1 deletion src/Lorentz/Contracts/Validate/Reception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ assertInWhitelist = do
assert $ mkMTextUnsafe "not in whitelist"

validateReceptionContract :: ()
=> Contract Parameter Storage
=> ContractCode Parameter Storage
validateReceptionContract = do
unpair
caseT @Parameter
Expand Down
Loading

0 comments on commit 661ca74

Please sign in to comment.