From 3363d323ca48a745393574633125651f6ac15a5d Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 19:13:31 +0530 Subject: [PATCH 01/10] feat(#81): conway update --- .gitignore | 1 + cabal.project | 93 ++++++++------- .../src/GeniusYield/Api/Dex/PartialOrder.hs | 27 +++-- .../src/GeniusYield/Api/Dex/Types.hs | 4 +- .../geniusyield-server-lib.cabal | 2 +- .../src/GeniusYield/Server/Ctx.hs | 17 +-- .../src/GeniusYield/Server/ErrorMiddleware.hs | 110 +++++++++--------- 7 files changed, 131 insertions(+), 123 deletions(-) diff --git a/.gitignore b/.gitignore index 32201fc3..9c279573 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ cabal.project.local~ *.skey secrets/ *.env +.vscode diff --git a/cabal.project b/cabal.project index 9febcb31..392cb90b 100644 --- a/cabal.project +++ b/cabal.project @@ -10,11 +10,11 @@ repository cardano-haskell-packages d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee -- repeating the index-state for hackage to work around hackage.nix parsing limitation -index-state: 2024-06-15T17:35:54Z +index-state: 2024-08-27T16:28:01Z index-state: - , hackage.haskell.org 2024-06-15T17:35:54Z - , cardano-haskell-packages 2024-06-13T23:12:13Z + , hackage.haskell.org 2024-08-27T16:28:01Z + , cardano-haskell-packages 2024-07-24T14:16:32Z packages: geniusyield-dex-api @@ -22,62 +22,54 @@ packages: geniusyield-server-lib geniusyield-onchain/geniusyield-common --- TODO: Default value should be @direct@ in upcoming 3.10 version of cabal, omit this line then. -test-show-details: direct - source-repository-package type: git location: https://github.com/geniusyield/ply - tag: b13674633771f572a5eedfb47276c0ac3993ab85 - --sha256: sha256-a63OdFAbo0sWOXxceI2bW/ZMrS8wo1t7aPFrfXvVhvE= + tag: 4a61941b3287782d2c11f9ab1cae0889d0a57385 + --sha256: sha256-24WKaBs6qiJzi++wTyqIh61Dc1QeCzeo0YqLE4wsEbg= subdir: ply-core source-repository-package type: git location: https://github.com/geniusyield/atlas - tag: 0066924f0f93be16f3d5de32d94d53cde9eeb0f9 - --sha256: sha256-G8+Kdm6qwWvp7BSPnPffHVEkcHt7COpXRWRqgofQj74= + tag: 6f1f770ea3ffa7c1b8cd6db21262ffd43a619053 + --sha256: sha256-xQbzGWDPqXMzYVCr//3nTmS23BixKhCeB7yXQ5NkG60= -------- Begin contents from @atlas@'s @cabal.project@ file. -------- package cardano-crypto-praos flags: -external-libsodium-vrf --- TODO: This is fixed for in their later version, omit this when we update to it. -package strict-containers - ghc-options: -Wwarn=noncanonical-monad-instances - source-repository-package type: git location: https://github.com/maestro-org/haskell-sdk - tag: d70479ce3be06d6b7c52bf39d783f36d6771e36d - --sha256: sha256-8se+xlIB1BDEuKGwjaldmW5G4LpCujD1ABgBaY0cY6Y= + tag: v1.7.2 + --sha256: sha256-nXnelHH4a+V0nguP8oUDlyEz/fLQ/i1fs/flyZTmvAc= +-- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/44) source-repository-package type: git - location: https://github.com/mlabs-haskell/clb - tag: 18e781b5b53adc1aa1d8c057c1b606b536a80350 - --sha256: sha256-PDmrXYTBHPcY0x+JnF21uupLMBwURLSiNMqNmwwapkc= + location: https://github.com/sourabhxyz/clb + tag: 09414a93047b4c7f6e03e20d1730c9c0f88e1d46 + --sha256: sha256-y5fF8IDywt/pQ3HsRE6CpAlqK4uiU/SRuDIqSHxBED0= --- Obtaining cardano-node stuff for 8.9.*. These aren't published on CHaP yet. +-- Obtaining cardano-node stuff for 9.1.0. These aren't published on CHaP yet. source-repository-package type: git location: https://github.com/IntersectMBO/cardano-node - tag: 8.9.2 - --sha256: sha256-PxMlVzTLMuVeu04QcGOxjaSMnpWJG78J0Rul3423too= + tag: 9.1.0 + --sha256: sha256-F5wgRA820x16f+8c/LlEEBG0rMJIA1XWw6X0ZwX5UWs= subdir: cardano-node cardano-testnet - cardano-git-rev trace-dispatcher --- Everything below is essentially copied from cardano-wallet's cabal.project. - +-- TODO: Make changes upstream source-repository-package type: git - location: https://github.com/input-output-hk/cardano-wallet - tag: v2024-03-27 - --sha256: sha256-rxMPopa3nxQaM0yOxUCq5oj3+XSL68jkuuFVhj/SY+w= + location: https://github.com/geniusyield/cardano-wallet + tag: 3413fdf74fd25b100662abf2a49c1afc892f1b79 + --sha256: sha256-V5DNUzraaDJo6cXc1eeVVIJNWqC8JayQrJeNNLg/Els= subdir: lib/address-derivation-discovery lib/balance-tx/ @@ -100,15 +92,15 @@ source-repository-package lib/wallet-benchmarks/ lib/wallet/ ------- Begin contents from @cardano-wallet@'s @cabal.project@ file. -------- +------ Following is mostly from @cardano-wallet@'s @cabal.project@ file. ------- -------------------------------------------------------------------------------- source-repository-package type: git location: https://github.com/IntersectMBO/cardano-addresses - tag: 126964483d188c2362393d2a6eea8c65dfc43097 - --sha256: 1w152imj28ap5dfdc8x9ly0cy7dn500v7k63vw11f70gvgg6x7my + tag: 2bca06deaa60e54a5322ac757387d744bf043367 + --sha256: 1y1mzfly7jac40b9g4xc078rcm5zqhc3xxv77kwxi10yph1jwq7z subdir: command-line core @@ -149,21 +141,30 @@ source-repository-package -------------------------------------------------------------------------------- -- BEGIN Constraints tweaking section --- cardano-addresses unit tests bring in some version constraint conflicts. --- --- 1. hjsonschema and hjsonpointer deps have overly strict bounds. --- 2. it has strict aeson < 1.5 dep - this will be fixed in the next release. allow-newer: - hjsonschema:* - , hjsonpointer:* - , *:aeson - , *:hashable - , async-timer:unliftio-core - , ekg:* - , ntp-client:* - , libsystemd-journal:base - , cardano-addresses-cli:mtl + async-timer:unliftio-core , servant-openapi3:* + , katip:Win32 + , raven-haskell:aeson + +constraints: + base >= 4.18.2.0 && < 5 + , openapi3 >= 3.2.0 + , persistent ^>= 2.14.6.0 + , cardano-node ^>= 9.1.0 + , bech32 >= 1.1.7 + + -- lower versions of katip won't build with the Win32-2.12.0.1 + -- which is shipped with the ghc-9.2.8 + , katip >= 0.8.7.4 + + + -- Cardano Node dependencies: + , io-classes >= 1.4 + , io-classes -asserts + , ouroboros-consensus-cardano ^>= 0.18 + , ouroboros-network ^>= 0.16.1 + , ouroboros-network-protocols ^>= 0.9 -- END Constraints tweaking section -------------------------------------------------------------------------------- @@ -185,8 +186,10 @@ package cardano-config package cardano-node flags: -systemd +package bitvec + flags: -simd + -- ------------------------------------------------------------------------- -------- End contents from @cardano-wallet@'s @cabal.project@ file. -------- - -------- End contents from @atlas@'s @cabal.project@ file. -------- \ No newline at end of file diff --git a/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs b/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs index a29c77ce..88f44d62 100644 --- a/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs +++ b/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs @@ -65,7 +65,6 @@ module GeniusYield.Api.Dex.PartialOrder ( preferentiallySelectLatestPocd, ) where -import Control.Monad.Except (ExceptT (..), liftEither, runExceptT) import Control.Monad.Reader (ask) import Data.Bifunctor (Bifunctor) import Data.Foldable (foldlM) @@ -410,16 +409,12 @@ partialOrdersHavingAsset pors hasAsset = do datumsV1_1 = utxosDatumsPureWithOriginalDatum utxosWithDatumsV1_1 m1 ← iwither - ( \oref vod → - either (const Nothing) Just - <$> runExceptT (makePartialOrderInfo policyIdV1 oref vod POCVersion1) + ( \oref vod → makePartialOrderInfo' policyIdV1 oref vod POCVersion1 ) datumsV1 m1_1 ← iwither - ( \oref vod → - either (const Nothing) Just - <$> runExceptT (makePartialOrderInfo policyIdV1_1 oref vod POCVersion1_1) + ( \oref vod → makePartialOrderInfo' policyIdV1_1 oref vod POCVersion1_1 ) datumsV1_1 pure $! m1 <> m1_1 @@ -468,8 +463,7 @@ getPartialOrderInfo pors orderRef = do pocVersion ← getPartialOrderVersion pors (utxoAddress utxo :!: utxoRef utxo) vod ← utxoDatumPureWithOriginalDatum' utxoWithDatum policyId ← withSomePORef (selectPor pors pocVersion) partialOrderNftPolicyId - - runExceptT (makePartialOrderInfo policyId orderRef vod pocVersion) >>= liftEither + makePartialOrderInfo policyId orderRef vod pocVersion getPartialOrdersInfos ∷ GYDexApiQueryMonad m a @@ -481,11 +475,11 @@ getPartialOrdersInfos pors orderRefs = do ps ← applyToBoth addressToPaymentCredential <$> partialOrderAddrTuple pors let vod = utxosDatumsPureWithOriginalDatum utxosWithDatums when (Map.size vod /= length orderRefs) $ throwAppError $ PodNotAllOrderRefsPresent $ Set.fromList orderRefs `Set.difference` Map.keysSet vod - let makePartialOrderInfo' oref v@(addr, _, _, _) = do + let makePartialOrderInfo'' oref v@(addr, _, _, _) = do pocVersion ← getPartialOrderVersion' ps (addr :!: oref) policyId ← withSomePORef (selectPor pors pocVersion) partialOrderNftPolicyId makePartialOrderInfo policyId oref v pocVersion - runExceptT (Map.traverseWithKey makePartialOrderInfo' vod) >>= liftEither + Map.traverseWithKey makePartialOrderInfo'' vod getPartialOrdersInfos' ∷ GYDexApiQueryMonad m a ⇒ PORefs → [(GYTxOutRef, Natural)] → m [(PartialOrderInfo, Natural)] getPartialOrdersInfos' por ordersWithTokenBuyAmount = do @@ -494,13 +488,22 @@ getPartialOrdersInfos' por ordersWithTokenBuyAmount = do -- Even though we use `dropMissing`, `getPartialOrdersInfos` verify that all entries are present. pure $ Map.elems $ Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched (\_ poi amt → (poi, amt))) orders ordersWithTokenBuyAmount' +makePartialOrderInfo' + ∷ GYDexApiQueryMonad m a + ⇒ GYMintingPolicyId + → GYTxOutRef + → (GYAddress, GYValue, PartialOrderDatum, GYDatum) + → POCVersion + → m (Maybe PartialOrderInfo) +makePartialOrderInfo' policyId orderRef tuple pocVersion = catchError (Just <$> makePartialOrderInfo policyId orderRef tuple pocVersion) $ \(_ ∷ GYTxMonadException) → pure Nothing + makePartialOrderInfo ∷ GYDexApiQueryMonad m a ⇒ GYMintingPolicyId → GYTxOutRef → (GYAddress, GYValue, PartialOrderDatum, GYDatum) → POCVersion - → ExceptT GYTxMonadException m PartialOrderInfo + → m PartialOrderInfo makePartialOrderInfo policyId orderRef (utxoAddr, v, PartialOrderDatum {..}, origDatum) pocVersion = do addr ← addressFromPlutus' podOwnerAddr diff --git a/geniusyield-dex-api/src/GeniusYield/Api/Dex/Types.hs b/geniusyield-dex-api/src/GeniusYield/Api/Dex/Types.hs index 6b4106fb..77b312e7 100644 --- a/geniusyield-dex-api/src/GeniusYield/Api/Dex/Types.hs +++ b/geniusyield-dex-api/src/GeniusYield/Api/Dex/Types.hs @@ -13,10 +13,10 @@ module GeniusYield.Api.Dex.Types ( import Control.Monad.Reader (MonadReader) import GeniusYield.Scripts.Dex (HasPartialOrderConfigAddr, HasPartialOrderNftScript, HasPartialOrderScript) -import GeniusYield.TxBuilder.Class (GYTxMonad, GYTxQueryMonad) +import GeniusYield.TxBuilder.Class (GYTxQueryMonad, GYTxUserQueryMonad) type HasDexScripts a = (HasPartialOrderConfigAddr a, HasPartialOrderScript a, HasPartialOrderNftScript a) type GYDexApiQueryMonad m a = (HasDexScripts a, MonadReader a m, GYTxQueryMonad m) -type GYDexApiMonad m a = (GYDexApiQueryMonad m a, GYTxMonad m) +type GYDexApiMonad m a = (GYDexApiQueryMonad m a, GYTxUserQueryMonad m) diff --git a/geniusyield-server-lib/geniusyield-server-lib.cabal b/geniusyield-server-lib/geniusyield-server-lib.cabal index 77cd56cd..5b3e3281 100644 --- a/geniusyield-server-lib/geniusyield-server-lib.cabal +++ b/geniusyield-server-lib/geniusyield-server-lib.cabal @@ -1,4 +1,4 @@ -cabal-version: 3.6 +cabal-version: 3.12 name: geniusyield-server-lib version: 0.10.0 synopsis: GeniusYield server library diff --git a/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs b/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs index 9e2775b8..a9cc2fb2 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs @@ -51,7 +51,7 @@ runSkeletonI -- ^ User's change address. → Maybe GYTxOutRef -- ^ User's collateral. - → ReaderT DEXInfo GYTxMonadNode (GYTxSkeleton v) + → ReaderT DEXInfo GYTxBuilderMonadIO (GYTxSkeleton v) → IO GYTxBody runSkeletonI = coerce (runSkeletonF @Identity) @@ -65,7 +65,7 @@ runSkeletonWithStrategyI -- ^ User's change address. → Maybe GYTxOutRef -- ^ User's collateral. - → ReaderT DEXInfo GYTxMonadNode (GYTxSkeleton v) + → ReaderT DEXInfo GYTxBuilderMonadIO (GYTxSkeleton v) → IO GYTxBody runSkeletonWithStrategyI cstrat = coerce (runSkeletonWithStrategyF @Identity cstrat) @@ -78,7 +78,7 @@ runSkeletonF -- ^ User's change address. → Maybe GYTxOutRef -- ^ User's collateral. - → ReaderT DEXInfo GYTxMonadNode (t (GYTxSkeleton v)) + → ReaderT DEXInfo GYTxBuilderMonadIO (t (GYTxSkeleton v)) → IO (t GYTxBody) runSkeletonF = runSkeletonWithStrategyF GYRandomImproveMultiAsset @@ -92,7 +92,7 @@ runSkeletonWithStrategyF -- ^ User's change address. → Maybe GYTxOutRef -- ^ User's collateral. - → ReaderT DEXInfo GYTxMonadNode (t (GYTxSkeleton v)) + → ReaderT DEXInfo GYTxBuilderMonadIO (t (GYTxSkeleton v)) → IO (t GYTxBody) runSkeletonWithStrategyF cstrat ctx addrs addr mcollateral skeleton = do let nid = ctxNetworkId ctx @@ -104,11 +104,14 @@ runSkeletonWithStrategyF cstrat ctx addrs addr mcollateral skeleton = do runGYTxMonadNodeF cstrat nid providers (addr : addrs) addr mcollateral' $ runReaderT skeleton di -runQuery ∷ Ctx → ReaderT DEXInfo GYTxQueryMonadNode a → IO a +runQuery ∷ Ctx → ReaderT DEXInfo GYTxQueryMonadIO a → IO a runQuery ctx = runQueryWithReader ctx (ctxDexInfo ctx) -runQueryWithReader ∷ Ctx → a → ReaderT a GYTxQueryMonadNode b → IO b +runQueryWithReader ∷ Ctx → a → ReaderT a GYTxQueryMonadIO b → IO b runQueryWithReader ctx a q = do let nid = ctxNetworkId ctx providers = ctxProviders ctx - runGYTxQueryMonadNode nid providers $ runReaderT q a + runGYTxQueryMonadIO nid providers $ runReaderT q a + +runGYTxMonadNodeF :: forall t v. Traversable t => GYCoinSelectionStrategy -> GYNetworkId -> GYProviders -> [GYAddress] -> GYAddress -> Maybe (GYTxOutRef, Bool) -> GYTxBuilderMonadIO (t (GYTxSkeleton v)) -> IO (t GYTxBody) +runGYTxMonadNodeF strat nid providers addrs change collateral act = runGYTxBuilderMonadIO nid providers addrs change collateral $ act >>= traverse (buildTxBodyWithStrategy strat) diff --git a/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs b/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs index 45b3d251..d6e42deb 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs @@ -16,8 +16,6 @@ import GeniusYield.HTTP.Errors import GeniusYield.Imports (lazyDecodeUtf8Lenient) import GeniusYield.Providers.Common (SubmitTxException (SubmitTxException)) import GeniusYield.Server.Dex.PartialOrder (PodOrderNotFound, PodServerException) -import GeniusYield.Transaction (BuildTxException (..)) -import GeniusYield.Transaction.Common (BalancingError (..)) import GeniusYield.TxBuilder import Network.HTTP.Types ( Status (statusCode, statusMessage), @@ -46,9 +44,9 @@ errorJsonWrapMiddleware app req respond = app req $ \res → do if lookup "Content-Type" headers /= Just "application/json" -- Don't overwrite responses which are already json! && statusCode status - >= 400 + >= 400 && statusCode status - < 600 + < 600 then do lbs ← if statusCode status == 404 @@ -61,10 +59,10 @@ errorJsonWrapMiddleware app req respond = app req $ \res → do errorLoggerMiddleware ∷ (LT.Text → IO ()) → Wai.Middleware errorLoggerMiddleware errorLogger app req respond = app req $ \res → do let (status, _headers, body) = Wai.responseToStream res - when (statusCode status >= 400 && statusCode status < 600) - $ sinkStreamingBody body - >>= errorLogger - . lazyDecodeUtf8Lenient + when (statusCode status >= 400 && statusCode status < 600) $ + sinkStreamingBody body + >>= errorLogger + . lazyDecodeUtf8Lenient respond res {- | Reinterpret exceptions raised by the server (mostly contract exceptions) into 'GYApiError's. @@ -75,39 +73,6 @@ exceptionHandler ∷ SomeException → GYApiError exceptionHandler = catchesWaiExc [ WH $ \case - BuildTxBalancingError (BalancingErrorInsufficientFunds x) → - GYApiError - { gaeErrorCode = "INSUFFICIENT_BALANCE", - gaeHttpStatus = status400, - gaeMsg = "Value dip: " <> tShow x - } - BuildTxBalancingError BalancingErrorEmptyOwnUTxOs → - GYApiError - { gaeErrorCode = "INSUFFICIENT_BALANCE", - gaeHttpStatus = status400, - gaeMsg = "No UTxOs available to build transaction from in wallet" - } - BuildTxBalancingError (BalancingErrorChangeShortFall a) → - GYApiError - { gaeErrorCode = "INSUFFICIENT_BALANCE", - gaeHttpStatus = status400, - gaeMsg = "When trying to balance the transaction, our coin balancer felt short by " <> tShow a <> " lovelaces" - } - BuildTxCollateralShortFall req given → - GYApiError - { -- This won't really happen as the collateral UTxO we choose has >= 5 ada. - gaeErrorCode = "INSUFFICIENT_BALANCE", - gaeHttpStatus = status400, - gaeMsg = "Total lovelaces required as collateral to build for this transaction " <> tShow req <> " but only available " <> tShow given - } - BuildTxNoSuitableCollateral → - GYApiError - { gaeErrorCode = "NO_SUITABLE_COLLATERAL", - gaeHttpStatus = status400, - gaeMsg = "Could not find the suitable UTxO as collateral, wallet must have a UTxO containing more than " <> tShow collateralLovelace <> " lovelaces" - } - e → someBackendError $ displayException' e, - WH $ \case SubmitTxException errBody → if "BadInputsUTxO" `isInfixOf` errBody -- See https://github.com/input-output-hk/cardano-ledger/blob/de7c29eef6d7eaabf5d704e976f7840a2edce355/eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs#L350-L351. then @@ -135,24 +100,57 @@ exceptionHandler = WH $ \case GYConversionException convErr → someBackendError $ tShow convErr GYQueryUTxOException txErr → someBackendError $ tShow txErr + e@(GYBuildTxException buildErr) → case buildErr of + GYBuildTxBalancingError (GYBalancingErrorInsufficientFunds x) → + GYApiError + { gaeErrorCode = "INSUFFICIENT_BALANCE", + gaeHttpStatus = status400, + gaeMsg = "Value dip: " <> tShow x + } + GYBuildTxBalancingError GYBalancingErrorEmptyOwnUTxOs → + GYApiError + { gaeErrorCode = "INSUFFICIENT_BALANCE", + gaeHttpStatus = status400, + gaeMsg = "No UTxOs available to build transaction from in wallet" + } + GYBuildTxBalancingError (GYBalancingErrorChangeShortFall a) → + GYApiError + { gaeErrorCode = "INSUFFICIENT_BALANCE", + gaeHttpStatus = status400, + gaeMsg = "When trying to balance the transaction, our coin balancer felt short by " <> tShow a <> " lovelaces" + } + GYBuildTxCollateralShortFall req given → + GYApiError + { -- This won't really happen as the collateral UTxO we choose has >= 5 ada. + gaeErrorCode = "INSUFFICIENT_BALANCE", + gaeHttpStatus = status400, + gaeMsg = "Total lovelaces required as collateral to build for this transaction " <> tShow req <> " but only available " <> tShow given + } + GYBuildTxNoSuitableCollateral → + GYApiError + { gaeErrorCode = "NO_SUITABLE_COLLATERAL", + gaeHttpStatus = status400, + gaeMsg = "Could not find the suitable UTxO as collateral, wallet must have a UTxO containing more than " <> tShow collateralLovelace <> " lovelaces" + } + _anyOther → someBackendError $ displayException' e GYNoSuitableCollateralException minAmt addr → - someBackendError - $ "No suitable collateral of at least " - <> tShow minAmt - <> " was found at the address " - <> tShow addr + someBackendError $ + "No suitable collateral of at least " + <> tShow minAmt + <> " was found at the address " + <> tShow addr GYSlotOverflowException slot advAmt → - someBackendError - $ "Slot value " - <> tShow slot - <> " overflows when advanced by " - <> tShow advAmt + someBackendError $ + "Slot value " + <> tShow slot + <> " overflows when advanced by " + <> tShow advAmt GYTimeUnderflowException sysStart time → - someBackendError - $ "Timestamp " - <> tShow time - <> " is before known system start " - <> tShow sysStart + someBackendError $ + "Timestamp " + <> tShow time + <> " is before known system start " + <> tShow sysStart GYQueryDatumException qdErr → someBackendError $ tShow qdErr GYDatumMismatch actualDatum scriptWitness → someBackendError $ "Actual datum in UTxO is: " <> tShow actualDatum <> ", but witness has wrong corresponding datum information: " <> tShow scriptWitness GYApplicationException e → toApiError e, From cc229053ed0e4fc620f80b8d2d6959e2d0dd5d1b Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 20:24:08 +0530 Subject: [PATCH 02/10] feat(#81): update cabal-version --- geniusyield-server-lib/geniusyield-server-lib.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geniusyield-server-lib/geniusyield-server-lib.cabal b/geniusyield-server-lib/geniusyield-server-lib.cabal index 5b3e3281..77cd56cd 100644 --- a/geniusyield-server-lib/geniusyield-server-lib.cabal +++ b/geniusyield-server-lib/geniusyield-server-lib.cabal @@ -1,4 +1,4 @@ -cabal-version: 3.12 +cabal-version: 3.6 name: geniusyield-server-lib version: 0.10.0 synopsis: GeniusYield server library From 9c6080b41fba28602fd2e7910b50a81aa6f934be Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 20:49:27 +0530 Subject: [PATCH 03/10] feat(#81): update haskell workflow to also include postgresql --- .github/workflows/haskell.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 167ed7ea..9eaa71d8 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -48,7 +48,8 @@ jobs: procps \ tmux \ xz-utils \ - zlib1g-dev + zlib1g-dev \ + postgresql - name: Validate code (run pre-commit hooks) uses: pre-commit/action@v3.0.0 with: From 741a8f23d97a6394b5da74bd133c12cea8db22c0 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 20:56:49 +0530 Subject: [PATCH 04/10] chore(#81): fourmolu --- .../src/GeniusYield/Server/Ctx.hs | 2 +- .../src/GeniusYield/Server/ErrorMiddleware.hs | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs b/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs index a9cc2fb2..0a0e1a98 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/Ctx.hs @@ -113,5 +113,5 @@ runQueryWithReader ctx a q = do providers = ctxProviders ctx runGYTxQueryMonadIO nid providers $ runReaderT q a -runGYTxMonadNodeF :: forall t v. Traversable t => GYCoinSelectionStrategy -> GYNetworkId -> GYProviders -> [GYAddress] -> GYAddress -> Maybe (GYTxOutRef, Bool) -> GYTxBuilderMonadIO (t (GYTxSkeleton v)) -> IO (t GYTxBody) +runGYTxMonadNodeF ∷ ∀ t v. Traversable t ⇒ GYCoinSelectionStrategy → GYNetworkId → GYProviders → [GYAddress] → GYAddress → Maybe (GYTxOutRef, Bool) → GYTxBuilderMonadIO (t (GYTxSkeleton v)) → IO (t GYTxBody) runGYTxMonadNodeF strat nid providers addrs change collateral act = runGYTxBuilderMonadIO nid providers addrs change collateral $ act >>= traverse (buildTxBodyWithStrategy strat) diff --git a/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs b/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs index d6e42deb..de60b9ef 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/ErrorMiddleware.hs @@ -44,9 +44,9 @@ errorJsonWrapMiddleware app req respond = app req $ \res → do if lookup "Content-Type" headers /= Just "application/json" -- Don't overwrite responses which are already json! && statusCode status - >= 400 + >= 400 && statusCode status - < 600 + < 600 then do lbs ← if statusCode status == 404 @@ -59,10 +59,10 @@ errorJsonWrapMiddleware app req respond = app req $ \res → do errorLoggerMiddleware ∷ (LT.Text → IO ()) → Wai.Middleware errorLoggerMiddleware errorLogger app req respond = app req $ \res → do let (status, _headers, body) = Wai.responseToStream res - when (statusCode status >= 400 && statusCode status < 600) $ - sinkStreamingBody body - >>= errorLogger - . lazyDecodeUtf8Lenient + when (statusCode status >= 400 && statusCode status < 600) + $ sinkStreamingBody body + >>= errorLogger + . lazyDecodeUtf8Lenient respond res {- | Reinterpret exceptions raised by the server (mostly contract exceptions) into 'GYApiError's. @@ -134,23 +134,23 @@ exceptionHandler = } _anyOther → someBackendError $ displayException' e GYNoSuitableCollateralException minAmt addr → - someBackendError $ - "No suitable collateral of at least " - <> tShow minAmt - <> " was found at the address " - <> tShow addr + someBackendError + $ "No suitable collateral of at least " + <> tShow minAmt + <> " was found at the address " + <> tShow addr GYSlotOverflowException slot advAmt → - someBackendError $ - "Slot value " - <> tShow slot - <> " overflows when advanced by " - <> tShow advAmt + someBackendError + $ "Slot value " + <> tShow slot + <> " overflows when advanced by " + <> tShow advAmt GYTimeUnderflowException sysStart time → - someBackendError $ - "Timestamp " - <> tShow time - <> " is before known system start " - <> tShow sysStart + someBackendError + $ "Timestamp " + <> tShow time + <> " is before known system start " + <> tShow sysStart GYQueryDatumException qdErr → someBackendError $ tShow qdErr GYDatumMismatch actualDatum scriptWitness → someBackendError $ "Actual datum in UTxO is: " <> tShow actualDatum <> ", but witness has wrong corresponding datum information: " <> tShow scriptWitness GYApplicationException e → toApiError e, From 0ec37788a0e620b5df2f6141975663c3fb735eea Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 21:00:29 +0530 Subject: [PATCH 05/10] ci(#81): update postgresql version --- .github/workflows/haskell.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 9eaa71d8..2444e9e9 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -30,6 +30,8 @@ jobs: dpkg-dev \ gcc \ gnupg \ + gnupg2 \ + gnupg1 \ g++ \ hlint \ libc6-dev \ @@ -48,8 +50,11 @@ jobs: procps \ tmux \ xz-utils \ - zlib1g-dev \ - postgresql + zlib1g-dev + sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + sudo apt-get update -y + sudo apt-get install postgresql-14 -y - name: Validate code (run pre-commit hooks) uses: pre-commit/action@v3.0.0 with: From ba873283d41ca2448d49197ed6e8c82c7b4d4d03 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 28 Aug 2024 21:14:17 +0530 Subject: [PATCH 06/10] ci(#81): add sudo for some of the build commands --- .github/workflows/haskell.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 2444e9e9..7b9be549 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -51,8 +51,8 @@ jobs: tmux \ xz-utils \ zlib1g-dev - sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - sudo apt-get update -y sudo apt-get install postgresql-14 -y - name: Validate code (run pre-commit hooks) From 5d2748906890b0cf1995fd07cfd0103c5dff60a7 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 29 Aug 2024 13:45:24 +0530 Subject: [PATCH 07/10] ci(#81): add `sudo` for `apt-key add -` command --- .github/workflows/haskell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 7b9be549..93b8d81e 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -52,7 +52,7 @@ jobs: xz-utils \ zlib1g-dev sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update -y sudo apt-get install postgresql-14 -y - name: Validate code (run pre-commit hooks) From 655073e8f4851f82b6d5a168bdcbfaa17003bc68 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 29 Aug 2024 15:02:05 +0530 Subject: [PATCH 08/10] feat(#81): add constraints for `postgresql-libpq`, run latest versino of fourmolu --- .github/workflows/haskell.yml | 6 ------ cabal.project | 1 + geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs | 6 ++---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 93b8d81e..167ed7ea 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -30,8 +30,6 @@ jobs: dpkg-dev \ gcc \ gnupg \ - gnupg2 \ - gnupg1 \ g++ \ hlint \ libc6-dev \ @@ -51,10 +49,6 @@ jobs: tmux \ xz-utils \ zlib1g-dev - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - sudo apt-get update -y - sudo apt-get install postgresql-14 -y - name: Validate code (run pre-commit hooks) uses: pre-commit/action@v3.0.0 with: diff --git a/cabal.project b/cabal.project index 392cb90b..54458b0b 100644 --- a/cabal.project +++ b/cabal.project @@ -153,6 +153,7 @@ constraints: , persistent ^>= 2.14.6.0 , cardano-node ^>= 9.1.0 , bech32 >= 1.1.7 + , postgresql-libpq ^>= 0.11 -- lower versions of katip won't build with the Win32-2.12.0.1 -- which is shipped with the ghc-9.2.8 diff --git a/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs b/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs index 88f44d62..676e1c7a 100644 --- a/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs +++ b/geniusyield-dex-api/src/GeniusYield/Api/Dex/PartialOrder.hs @@ -409,13 +409,11 @@ partialOrdersHavingAsset pors hasAsset = do datumsV1_1 = utxosDatumsPureWithOriginalDatum utxosWithDatumsV1_1 m1 ← iwither - ( \oref vod → makePartialOrderInfo' policyIdV1 oref vod POCVersion1 - ) + (\oref vod → makePartialOrderInfo' policyIdV1 oref vod POCVersion1) datumsV1 m1_1 ← iwither - ( \oref vod → makePartialOrderInfo' policyIdV1_1 oref vod POCVersion1_1 - ) + (\oref vod → makePartialOrderInfo' policyIdV1_1 oref vod POCVersion1_1) datumsV1_1 pure $! m1 <> m1_1 From 985fa67a483195371f4d9ef3643de9cc0158cfb7 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 29 Aug 2024 15:10:13 +0530 Subject: [PATCH 09/10] feat(#81): constrain `postgresql-libpq` to `^>= 0.10` --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 54458b0b..6c96e17f 100644 --- a/cabal.project +++ b/cabal.project @@ -153,7 +153,7 @@ constraints: , persistent ^>= 2.14.6.0 , cardano-node ^>= 9.1.0 , bech32 >= 1.1.7 - , postgresql-libpq ^>= 0.11 + , postgresql-libpq ^>= 0.10 -- lower versions of katip won't build with the Win32-2.12.0.1 -- which is shipped with the ghc-9.2.8 From 9800372a8227eef83c1208511bf297cabe13e512 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 30 Aug 2024 11:39:39 +0530 Subject: [PATCH 10/10] feat(#81): handle changelog and versioning --- cabal.project | 4 ++-- geniusyield-dex-api/CHANGELOG.md | 6 +++++- geniusyield-dex-api/geniusyield-dex-api.cabal | 2 +- geniusyield-server-lib/CHANGELOG.md | 4 ++++ geniusyield-server-lib/geniusyield-server-lib.cabal | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cabal.project b/cabal.project index 6c96e17f..51407739 100644 --- a/cabal.project +++ b/cabal.project @@ -32,8 +32,8 @@ source-repository-package source-repository-package type: git location: https://github.com/geniusyield/atlas - tag: 6f1f770ea3ffa7c1b8cd6db21262ffd43a619053 - --sha256: sha256-xQbzGWDPqXMzYVCr//3nTmS23BixKhCeB7yXQ5NkG60= + tag: v0.6.0 + --sha256: sha256-v+tTCIz8uyaQfsMJRc5F36TNK9ZPfrBxwXLYaXqZrZA= -------- Begin contents from @atlas@'s @cabal.project@ file. -------- diff --git a/geniusyield-dex-api/CHANGELOG.md b/geniusyield-dex-api/CHANGELOG.md index 7c9201cd..cc04a81c 100644 --- a/geniusyield-dex-api/CHANGELOG.md +++ b/geniusyield-dex-api/CHANGELOG.md @@ -1,6 +1,10 @@ # Revision history for geniusyield-dex-api -## 0.4.0.0 -- 2024-27-06 +## 0.5.0.0 -- 2024-08-30 + +* Update to Atlas v0.6.0. + +## 0.4.0.0 -- 2024-06-27 * Updates definition of `fillMultiplePartialOrders'` to call `buildWithFeeOutput` even in case more than one order is being filled. diff --git a/geniusyield-dex-api/geniusyield-dex-api.cabal b/geniusyield-dex-api/geniusyield-dex-api.cabal index 7c54a3fe..be1cb26d 100644 --- a/geniusyield-dex-api/geniusyield-dex-api.cabal +++ b/geniusyield-dex-api/geniusyield-dex-api.cabal @@ -4,7 +4,7 @@ name: geniusyield-dex-api -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.4.0.0 +version: 0.5.0.0 synopsis: API code to interact with GeniusYield DEX. description: API code to interact with GeniusYield DEX. Learn more about GeniusYield by visiting https://www.geniusyield.co/. diff --git a/geniusyield-server-lib/CHANGELOG.md b/geniusyield-server-lib/CHANGELOG.md index d0e4d5e8..4009aa97 100644 --- a/geniusyield-server-lib/CHANGELOG.md +++ b/geniusyield-server-lib/CHANGELOG.md @@ -1,5 +1,9 @@ # Revision history for geniusyield-server-lib +## 0.11.0 -- 2024-08-30 + +* Update to Atlas v0.6.0. + ## 0.10.1 -- 2024-08-29 * Updated Atlas & Maestro SDK version to not make use Maestro's recently deprecated protocol parameters & era summaries endpoint. diff --git a/geniusyield-server-lib/geniusyield-server-lib.cabal b/geniusyield-server-lib/geniusyield-server-lib.cabal index 4c3020fc..ed776144 100644 --- a/geniusyield-server-lib/geniusyield-server-lib.cabal +++ b/geniusyield-server-lib/geniusyield-server-lib.cabal @@ -1,6 +1,6 @@ cabal-version: 3.6 name: geniusyield-server-lib -version: 0.10.1 +version: 0.11.0 synopsis: GeniusYield server library description: Library for GeniusYield server. license: Apache-2.0