Skip to content

Commit ede94c5

Browse files
committed
[Chore] Delete InitialStorageData and mkInitialStorage
Problem: we have a data type we only use once in exactly one place, and a function that immediately consume it. There's no need for this. Solution: Inline `mkInitialStorage`
1 parent 6d0a628 commit ede94c5

File tree

3 files changed

+23
-57
lines changed

3 files changed

+23
-57
lines changed

haskell/src/Stablecoin/Client.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module Stablecoin.Client
55
( module Stablecoin.Client.Impl
6-
, InitialStorageData(..)
6+
, InitialStorageOptions(..)
77
, Alias
88
) where
99

haskell/src/Stablecoin/Client/Contract.hs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33

44
module Stablecoin.Client.Contract
55
( InitialStorageOptions(..)
6-
, InitialStorageData(..)
7-
, mkInitialStorage
86
) where
97

10-
import Lorentz as L
11-
import Lorentz.Contracts.Spec.TZIP16Interface (MetadataMap)
12-
import Lorentz.Contracts.Stablecoin (Expiry, Roles(..), Storage(..))
13-
import Morley.Tezos.Address (ContractAddress, L1Address)
8+
import Lorentz.Contracts.Stablecoin (Expiry)
149
import Stablecoin.Client.L1AddressOrAlias (ContractAddressOrAlias, L1AddressOrAlias)
1510
import Stablecoin.Client.Parser (ContractMetadataOptions(..))
1611

@@ -26,38 +21,3 @@ data InitialStorageOptions = InitialStorageOptions
2621
, isoContractMetadataStorage :: ContractMetadataOptions
2722
, isoDefaultExpiry :: Expiry
2823
}
29-
30-
-- | The data needed in order to create the stablecoin contract's initial storage.
31-
data InitialStorageData = InitialStorageData
32-
{ isdMasterMinter :: L1Address
33-
, isdContractOwner :: L1Address
34-
, isdPauser :: L1Address
35-
, isdTransferlist :: Maybe ContractAddress
36-
, isdTokenSymbol :: Text
37-
, isdTokenName :: Text
38-
, isdTokenDecimals :: Natural
39-
, isdContractMetadataStorage :: MetadataMap
40-
, isdDefaultExpiry :: Expiry
41-
}
42-
43-
-- | Construct the stablecoin contract's initial storage in order to deploy it.
44-
mkInitialStorage :: InitialStorageData -> Storage
45-
mkInitialStorage InitialStorageData {..} =
46-
Storage
47-
{ sDefaultExpiry = isdDefaultExpiry
48-
, sLedger = def
49-
, sMintingAllowances = mempty
50-
, sOperators = def
51-
, sPaused = False
52-
, sPermitCounter = 0
53-
, sPermits = def
54-
, sRoles = Roles
55-
{ rMasterMinter = toAddress isdMasterMinter
56-
, rOwner = toAddress isdContractOwner
57-
, rPauser = toAddress isdPauser
58-
, rPendingOwner = Nothing
59-
}
60-
, sTransferlistContract = toAddress <$> isdTransferlist
61-
, sMetadata = isdContractMetadataStorage
62-
, sTotalSupply = 0
63-
}

haskell/src/Stablecoin/Client/Impl.hs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Morley.Tezos.Address
5656
(Address, ConstrainedAddress(..), ContractAddress, KindedAddress(..), L1Address, TxRollupAddress)
5757
import Morley.Tezos.Address.Alias (AddressOrAlias(..), Alias(..), ContractAlias, unAlias)
5858
import Morley.Tezos.Core (Mutez, zeroMutez)
59+
import Morley.Util.Default (def)
5960
import Morley.Util.Interpolate (itu)
6061
import Morley.Util.Named (arg, pattern (:!), (:!))
6162

@@ -65,8 +66,7 @@ import Lorentz.Contracts.Stablecoin
6566
Roles(..), Storage(..), StorageRPC(..), UpdateOperatorData(..), contractMetadataContract,
6667
metadataJSON, metadataMap, mkContractMetadataRegistryStorage, parseMetadataUri,
6768
stablecoinContract)
68-
import Stablecoin.Client.Contract
69-
(InitialStorageData(..), InitialStorageOptions(..), mkInitialStorage)
69+
import Stablecoin.Client.Contract (InitialStorageOptions(..))
7070
import Stablecoin.Client.L1AddressOrAlias
7171
import Stablecoin.Client.Metadata (ViewParam(..), callOffChainView)
7272
import Stablecoin.Client.Parser (ContractMetadataOptions(..))
@@ -120,19 +120,25 @@ deploy (arg #sender -> sender) alias InitialStorageOptions {..} = do
120120
Nothing
121121
pure $ RemoteContract contractMetadataRegistryAddress
122122

123-
let initialStorageData = InitialStorageData
124-
{ isdMasterMinter = masterMinter
125-
, isdContractOwner = contractOwner
126-
, isdPauser = pauser
127-
, isdTransferlist = transferlist
128-
, isdContractMetadataStorage = metadataMap contractMetadataUri
129-
, isdTokenSymbol = isoTokenSymbol
130-
, isdTokenName = isoTokenName
131-
, isdTokenDecimals = isoTokenDecimals
132-
, isdDefaultExpiry = isoDefaultExpiry
133-
}
134-
135-
let initialStorage = mkInitialStorage initialStorageData
123+
let initialStorage =
124+
Storage
125+
{ sDefaultExpiry = isoDefaultExpiry
126+
, sLedger = def
127+
, sMintingAllowances = mempty
128+
, sOperators = def
129+
, sPaused = False
130+
, sPermitCounter = 0
131+
, sPermits = def
132+
, sRoles = Roles
133+
{ rMasterMinter = toAddress masterMinter
134+
, rOwner = toAddress contractOwner
135+
, rPauser = toAddress pauser
136+
, rPendingOwner = Nothing
137+
}
138+
, sTransferlistContract = toAddress <$> transferlist
139+
, sMetadata = metadataMap contractMetadataUri
140+
, sTotalSupply = 0
141+
}
136142

137143
let cmdAddress = case contractMetadataUri of
138144
RemoteContract addr -> Just addr

0 commit comments

Comments
 (0)