Skip to content

Commit

Permalink
build: update fourmolu checks to reflect multi-project state
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhxyz committed Mar 13, 2024
1 parent 48bac3e commit e85dbae
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ jobs:
- name: Install fourmolu
run: cabal install fourmolu --overwrite-policy=always
- name: Run checks (fourmolu)
run: fourmolu --mode check src
run: |
fourmolu --mode check geniusyield-dex-api
fourmolu --mode check geniusyield-orderbot
fourmolu --mode check geniusyield-server-lib
- name: Build dependencies (cabal)
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
- name: Build all targets (cabal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ instance Domain.HasMarkets MaestroProvider where
then pure GYLovelace
else case parseAssetClassWithSep '.' (polId <> "." <> tkName) of
Left e throwIO $ MpeDeserializationException (pack e)
Right ac pure ac
Right ac pure ac
10 changes: 5 additions & 5 deletions geniusyield-orderbot/src/GeniusYield/OrderBot/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ instance Swagger.ToParamSchema OrderAssetPair where
toParamSchema _ =
mempty
& Swagger.type_
?~ Swagger.SwaggerString
?~ Swagger.SwaggerString

instance Swagger.ToSchema OrderAssetPair where
declareNamedSchema p =
pure $
Swagger.named "OrderAssetPair" $
Swagger.paramSchemaToSchema p
& Swagger.example
?~ toJSON ("f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958_dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53" String)
& Swagger.description
?~ "Market pair identifier. It's an underscore delimited concatenation of offered and asked asset's \"token detail\". A token detail is given by dot delimited concatenation of policy id and token name."
?~ toJSON ("f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958_dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53" String)
& Swagger.description
?~ "Market pair identifier. It's an underscore delimited concatenation of offered and asked asset's \"token detail\". A token detail is given by dot delimited concatenation of policy id and token name."

{- | Two order asset pairs are considered "equivalent" (but not strictly equal, as in 'Eq'),
if they contain the same 2 assets irrespective of order.
Expand All @@ -115,4 +115,4 @@ mkOrderAssetPair curAsset comAsset =
OAssetPair
{ currencyAsset = curAsset,
commodityAsset = comAsset
}
}
2 changes: 1 addition & 1 deletion geniusyield-server-lib/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ main = runCommand =<< execParser opts
( fullDesc
<> progDesc "GeniusYield DEX helpful operations"
<> header "GeniusYield DEX"
)
)
46 changes: 23 additions & 23 deletions geniusyield-server-lib/src/GeniusYield/Server/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ instance HasSwagger api ⇒ HasSwagger (APIKeyAuthProtect :> api) where
toSwagger _ =
toSwagger (Proxy Proxy api)
& securityDefinitions
.~ SecurityDefinitions (IOHM.fromList [(apiKeyHeaderText, apiKeySecurityScheme)])
.~ SecurityDefinitions (IOHM.fromList [(apiKeyHeaderText, apiKeySecurityScheme)])
& allOperations
. security
.~ [SecurityRequirement (IOHM.singleton apiKeyHeaderText [])]
. security
.~ [SecurityRequirement (IOHM.singleton apiKeyHeaderText [])]
& allOperations
. responses
%~ addCommonResponses
. responses
%~ addCommonResponses

addCommonResponses Responses Responses
addCommonResponses resps = resps & at 401 ?~ Inline response401 & at 403 ?~ Inline response403
Expand All @@ -223,26 +223,26 @@ geniusYieldAPISwagger ∷ Swagger
geniusYieldAPISwagger =
toSwagger geniusYieldAPI
& info
. title
.~ "Genius Yield DEX Server API"
. title
.~ "Genius Yield DEX Server API"
& info
. version
.~ "1.0"
. version
.~ "1.0"
& info
. license
?~ ("Apache-2.0" & url ?~ URL "https://opensource.org/licenses/apache-2-0")
& info
. license
?~ ("Apache-2.0" & url ?~ URL "https://opensource.org/licenses/apache-2-0")
& info
. description
?~ "API to interact with GeniusYield DEX."
& applyTagsFor (subOperations (Proxy Proxy ("tx" +> TxAPI)) (Proxy Proxy GeniusYieldAPI)) ["Transaction" & description ?~ "Endpoints related to transaction hex such as submitting a transaction"]
& applyTagsFor (subOperations (Proxy Proxy ("markets" +> MarketsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Markets" & description ?~ "Endpoints related to accessing markets information"]
& applyTagsFor (subOperations (Proxy Proxy ("orders" +> OrdersAPI)) (Proxy Proxy GeniusYieldAPI)) ["Orders" & description ?~ "Endpoints related to interacting with orders"]
& applyTagsFor (subOperations (Proxy Proxy ("settings" +> SettingsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Settings" & description ?~ "Endpoint to get server settings such as network, version, and revision"]
& applyTagsFor (subOperations (Proxy Proxy ("trading-fees" +> TradingFeesAPI)) (Proxy Proxy GeniusYieldAPI)) ["Trading Fees" & description ?~ "Endpoint to get trading fees of DEX."]
& applyTagsFor (subOperations (Proxy Proxy ("assets" +> AssetsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Assets" & description ?~ "Endpoint to fetch asset details."]
& applyTagsFor (subOperations (Proxy Proxy ("order-book" +> OrderBookAPI)) (Proxy Proxy GeniusYieldAPI)) ["Order Book" & description ?~ "Endpoint to fetch order book."]
& applyTagsFor (subOperations (Proxy Proxy ("historical-prices" +> "maestro" :> MaestroPriceHistoryAPI)) (Proxy Proxy GeniusYieldAPI)) ["Historical Prices" & description ?~ "Endpoints to fetch historical prices."]
& applyTagsFor (subOperations (Proxy Proxy ("balances" +> BalancesAPI)) (Proxy Proxy GeniusYieldAPI)) ["Balances" & description ?~ "Endpoint to fetch token balances."]
?~ "API to interact with GeniusYield DEX."
& applyTagsFor (subOperations (Proxy Proxy ("tx" +> TxAPI)) (Proxy Proxy GeniusYieldAPI)) ["Transaction" & description ?~ "Endpoints related to transaction hex such as submitting a transaction"]
& applyTagsFor (subOperations (Proxy Proxy ("markets" +> MarketsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Markets" & description ?~ "Endpoints related to accessing markets information"]
& applyTagsFor (subOperations (Proxy Proxy ("orders" +> OrdersAPI)) (Proxy Proxy GeniusYieldAPI)) ["Orders" & description ?~ "Endpoints related to interacting with orders"]
& applyTagsFor (subOperations (Proxy Proxy ("settings" +> SettingsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Settings" & description ?~ "Endpoint to get server settings such as network, version, and revision"]
& applyTagsFor (subOperations (Proxy Proxy ("trading-fees" +> TradingFeesAPI)) (Proxy Proxy GeniusYieldAPI)) ["Trading Fees" & description ?~ "Endpoint to get trading fees of DEX."]
& applyTagsFor (subOperations (Proxy Proxy ("assets" +> AssetsAPI)) (Proxy Proxy GeniusYieldAPI)) ["Assets" & description ?~ "Endpoint to fetch asset details."]
& applyTagsFor (subOperations (Proxy Proxy ("order-book" +> OrderBookAPI)) (Proxy Proxy GeniusYieldAPI)) ["Order Book" & description ?~ "Endpoint to fetch order book."]
& applyTagsFor (subOperations (Proxy Proxy ("historical-prices" +> "maestro" :> MaestroPriceHistoryAPI)) (Proxy Proxy GeniusYieldAPI)) ["Historical Prices" & description ?~ "Endpoints to fetch historical prices."]
& applyTagsFor (subOperations (Proxy Proxy ("balances" +> BalancesAPI)) (Proxy Proxy GeniusYieldAPI)) ["Balances" & description ?~ "Endpoint to fetch token balances."]

geniusYieldServer Ctx ServerT GeniusYieldAPI IO
geniusYieldServer ctx =
Expand Down Expand Up @@ -357,4 +357,4 @@ handleBalancesApi ctx addr = do
logInfo ctx $ "Fetching balance of address: " +|| addr ||+ ""
runQuery ctx $ do
utxos utxosAtAddress (addressFromBech32 addr) Nothing
pure $ foldMapUTxOs utxoValue utxos
pure $ foldMapUTxOs utxoValue utxos
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Assets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ type AssetsAPI = Summary "Get assets information" :> Description "Get informatio
handleAssetsApi Ctx GYAssetClass IO AssetDetails
handleAssetsApi ctx@Ctx {..} ac = do
logInfo ctx $ "Fetching details of asset: " +|| ac ||+ ""
getAssetDetails ctxMaestroProvider ac
getAssetDetails ctxMaestroProvider ac
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ apiKeyAuthHandler (ApiKey key) = mkAuthHandler handler
Just key'
if key' == key
then pure ()
else throwError err403 {errBody = "Invalid API key"}
else throwError err403 {errBody = "Invalid API key"}
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ optionalSigningKeyFromServerConfig ServerConfig {..} = do
let wk' = walletKeysFromMnemonicIndexed mnemonic (fromMaybe 0 accIx) (fromMaybe 0 addrIx)
in case wk' of
Left _ Nothing
Right wk Just $ AGYExtendedPaymentSigningKey $ walletKeysToExtendedPaymentSigningKey wk
Right wk Just $ AGYExtendedPaymentSigningKey $ walletKeysToExtendedPaymentSigningKey wk
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ poConfigAddrPreprod = unsafeAddressFromText "addr_test1wrgvy8fermjrruaf7fnndtmpu

-- | The git hash of the current commit.
gitHash String
gitHash = $$tGitInfoCwd & giHash
gitHash = $$tGitInfoCwd & giHash
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ handleMaestroPriceHistory ctx marketId dex mresolution mfrom mto mlimit msort =
marketOHLCTargetVolume = ohlcCandleInfoCoinBVolume,
marketOHLCCount = ohlcCandleInfoCount,
marketOHLCTimestamp = ohlcCandleInfoTimestamp & utcTimeToPOSIXSeconds & timeFromPOSIX
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ handleMarkets ctx = do
fmap fromOrderAssetPair <$> getMarkets (ctxMaestroProvider ctx)
where
fromOrderAssetPair OrderAssetPair Market
fromOrderAssetPair oap = Market {marketId = oap, baseAsset = currencyAsset oap, targetAsset = commodityAsset oap}
fromOrderAssetPair oap = Market {marketId = oap, baseAsset = currencyAsset oap, targetAsset = commodityAsset oap}
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ handleCancelOrderAndSignSubmit ctx cops = do
signedTx handleTxSign ctx $ cotdTransaction details
txId handleTxSubmit ctx signedTx
-- Though transaction id would be same, but we are returning it again, just in case...
pure $ details {cotdTransactionId = txId, cotdTransaction = signedTx}
pure $ details {cotdTransactionId = txId, cotdTransaction = signedTx}
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ runCommand ∷ Command → IO ()
runCommand (Serve serveCommand) = runServeCommand serveCommand

runServeCommand ServeCommand IO ()
runServeCommand (ServeCommand mcfp) = runServer mcfp
runServeCommand (ServeCommand mcfp) = runServer mcfp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ gcpReqLogger =

-- Why does wai use ZonedDate from fast-logger + unix-time?
zonedDateToSensibleTime ByteString UTCTime
zonedDateToSensibleTime = parseTimeOrError False defaultTimeLocale (bytestringToString simpleTimeFormat) . bytestringToString
zonedDateToSensibleTime = parseTimeOrError False defaultTimeLocale (bytestringToString simpleTimeFormat) . bytestringToString
8 changes: 4 additions & 4 deletions geniusyield-server-lib/src/GeniusYield/Server/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ runServer mfp = do
ctxNetworkId = nid,
ctxDexInfo =
if
| nid == GYMainnet dexInfoDefaultMainnet
| nid == GYTestnetPreprod dexInfoDefaultPreprod
| otherwise error "Only mainnet & preprod network are supported",
| nid == GYMainnet dexInfoDefaultMainnet
| nid == GYTestnetPreprod dexInfoDefaultPreprod
| otherwise error "Only mainnet & preprod network are supported",
ctxMaestroProvider = MaestroProvider menv,
ctxSigningKey = optionalSigningKey
}
Expand All @@ -93,4 +93,4 @@ runServer mfp = do
mainAPI
(Proxy Proxy '[AuthHandler Wai.Request ()])
(\ioAct Handler . ExceptT $ first (apiErrorToServerError . exceptionHandler) <$> try ioAct)
$ mainServer ctx
$ mainServer ctx
2 changes: 1 addition & 1 deletion geniusyield-server-lib/src/GeniusYield/Server/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ isMatchedException (etype :>> etypes) se = isJust (f etype) || isMatchedExceptio
f _ = fromException @e se

bytestringToString ByteString String
bytestringToString = RIO.decodeUtf8Lenient >>> Text.unpack
bytestringToString = RIO.decodeUtf8Lenient >>> Text.unpack

0 comments on commit e85dbae

Please sign in to comment.