From 8365911697576f71bbedd9cabfe067e0cff77b09 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Sat, 22 Feb 2025 14:05:57 +0530 Subject: [PATCH 1/9] feat(#408): update to newer deps of cardano-node and associated libraries --- atlas-cardano.cabal | 270 ++++++++++++++++++++++++-------------------- cabal.project | 36 +++--- 2 files changed, 161 insertions(+), 145 deletions(-) diff --git a/atlas-cardano.cabal b/atlas-cardano.cabal index bcddf02e..20d2820f 100644 --- a/atlas-cardano.cabal +++ b/atlas-cardano.cabal @@ -1,31 +1,32 @@ -cabal-version: 3.8 -name: atlas-cardano -version: 0.11.1 -synopsis: Application backend for Plutus smart contracts on Cardano +cabal-version: 3.8 +name: atlas-cardano +version: 0.11.1 +synopsis: Application backend for Plutus smart contracts on Cardano description: Atlas is an all-in-one, Haskell-native application backend for writing off-chain code for on-chain Plutus smart contracts. -license: Apache-2.0 -license-file: LICENSE -copyright: (c) 2023 GYELD GMBH -author: Lars Bruenjes -maintainer: support@geniusyield.co -build-type: Simple -category: Blockchain, Cardano, Framework -homepage: https://github.com/geniusyield/atlas#readme -bug-reports: https://github.com/geniusyield/atlas/issues -extra-source-files: CHANGELOG.md - README.md +license: Apache-2.0 +license-file: LICENSE +copyright: (c) 2023 GYELD GMBH +author: Lars Bruenjes +maintainer: support@geniusyield.co +build-type: Simple +category: Blockchain, Cardano, Framework +homepage: https://github.com/geniusyield/atlas#readme +bug-reports: https://github.com/geniusyield/atlas/issues +extra-source-files: + CHANGELOG.md + README.md + tested-with: - GHC ==9.6.5 - || ==9.6.6 + ghc ==9.6.5 || ==9.6.6 source-repository head - type: git + type: git location: https://github.com/geniusyield/atlas common common - default-language: GHC2021 + default-language: GHC2021 default-extensions: DataKinds DefaultSignatures @@ -43,28 +44,36 @@ common common UndecidableInstances ViewPatterns - ghc-options: -Wall -Wincomplete-uni-patterns -Wunused-packages + ghc-options: + -Wall + -Wincomplete-uni-patterns + -Wunused-packages -- speed-ups GHCi considerably - ghc-options: -fno-show-valid-hole-fits + ghc-options: -fno-show-valid-hole-fits common plutus-ghc-options -- so unfoldings are present even when compiled without optmizations ghc-options: - -fno-ignore-interface-pragmas -fno-omit-interface-pragmas + -fno-ignore-interface-pragmas + -fno-omit-interface-pragmas -Wno-partial-type-signatures -- expose all unfoldings, so plutustx compiler can do its job ghc-options: - -fexpose-all-unfoldings -fobject-code - -fplugin-opt PlutusTx.Plugin:defer-errors + -fexpose-all-unfoldings + -fobject-code + -fplugin-opt + PlutusTx.Plugin:defer-errors -- set target plutus-core version - ghc-options: -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 + ghc-options: + -fplugin-opt + PlutusTx.Plugin:target-version=1.0.0 library - import: common - hs-source-dirs: src + import: common + hs-source-dirs: src exposed-modules: GeniusYield.Aeson.Utils GeniusYield.Api.TestTokens @@ -111,8 +120,8 @@ library GeniusYield.Transaction.CoinSelection.Balance GeniusYield.Transaction.CoinSelection.Numeric GeniusYield.Transaction.CoinSelection.Types - GeniusYield.Transaction.CoinSelection.UTxOIndex.Internal GeniusYield.Transaction.CoinSelection.UTxOIndex + GeniusYield.Transaction.CoinSelection.UTxOIndex.Internal GeniusYield.Transaction.CoinSelection.UTxOSelection GeniusYield.Transaction.Common GeniusYield.TxBuilder @@ -132,8 +141,8 @@ library GeniusYield.Types.Blueprint.Contract GeniusYield.Types.Blueprint.DefinitionId GeniusYield.Types.Blueprint.Parameter - GeniusYield.Types.Blueprint.Purpose GeniusYield.Types.Blueprint.Preamble + GeniusYield.Types.Blueprint.Purpose GeniusYield.Types.Blueprint.Schema GeniusYield.Types.Blueprint.TH GeniusYield.Types.Blueprint.Validator @@ -141,15 +150,15 @@ library GeniusYield.Types.BuildWitness GeniusYield.Types.Certificate GeniusYield.Types.Credential + GeniusYield.Types.DRep GeniusYield.Types.Datum GeniusYield.Types.Delegatee - GeniusYield.Types.DRep GeniusYield.Types.Epoch GeniusYield.Types.Era GeniusYield.Types.Governance - GeniusYield.Types.KeyHash GeniusYield.Types.Key GeniusYield.Types.Key.Class + GeniusYield.Types.KeyHash GeniusYield.Types.KeyRole GeniusYield.Types.Ledger GeniusYield.Types.Logging @@ -192,76 +201,77 @@ library GeniusYield.Providers.LiteChainIndex GeniusYield.Providers.Node.AwaitTx GeniusYield.Providers.Node.Query - GeniusYield.TxBuilder.IO.Query GeniusYield.TxBuilder.IO.Builder + GeniusYield.TxBuilder.IO.Query GeniusYield.Utils + build-depends: - async ^>=2.2.5, - aeson ^>=2.2.3, - aeson-pretty ^>= 0.8.10, - attoparsec ^>=0.14.4, - auto-update ^>=0.2.1, + MonadRandom, + aeson, + aeson-pretty, + async, + attoparsec, + auto-update, base ^>=4.18.2, - base16-bytestring ^>=1.0.2, - blockfrost-client ^>=0.9.1, - bytestring ^>=0.11.5, - cache ^>=0.1.3, - cassava ^>=0.5.3, - cborg ^>=0.2.10, - containers ^>=0.6.7, - data-default ^>=0.7.1, - data-default-class ^>=0.1.2, - deriving-aeson ^>=0.2.9, - either ^>=5.0.2, + base16-bytestring, + blockfrost-client, + bytestring, + cache, + cassava, + cborg, + containers, + data-default, + data-default-class, + deriving-aeson, + either, extra, generic-lens, - hashable ^>=1.4.7, - hedgehog ^>=1.4, - hedgehog-extras ^>=0.6.5, - http-api-data ^>=0.6.1, - http-client ^>=0.7.17, - http-client-tls ^>=0.3.6, - http-types ^>=0.12.4, - indexed-traversable ^>=0.1.4, - iproute ^>=1.7.14, - katip ^>=0.8.8, - lens ^>=5.2.3, - MonadRandom ^>=0.6, + hashable, + hedgehog, + hedgehog-extras, + http-api-data, + http-client, + http-client-tls, + http-types, + indexed-traversable, + iproute, + katip, + lens, monoidmap, - mtl ^>=2.3.1, - network-uri ^>=2.6.4, - postgresql-simple ^>=0.7.0, - prettyprinter ^>=1.7.1, - raven-haskell ^>=0.1.4.1, - resourcet ^>=1.3.0, - safe-money ^>=0.9.1, - scientific ^>=0.3.8, - servant ^>=0.20.1, - servant-client ^>=0.20, - servant-client-core ^>=0.20, - some ^>=1.0.6, - sop-extras ^>=0.2.0, - stm ^>=2.5.1, - strict-mvar ^>=1.5.0, - string-conv ^>=0.2.0, - swagger2 ^>=2.8.9, - tasty ^>=1.5, - tasty-hunit ^>=0.10.2, - tasty-quickcheck ^>=0.11, - template-haskell ^>=2.20.0, - text ^>=2.0.2, - time ^>=1.12.2, - transformers ^>=0.6.1, - unordered-containers ^>=0.2.20, - vector ^>=0.13.1, - witherable ^>=0.5 + mtl, + network-uri, + postgresql-simple, + prettyprinter, + raven-haskell, + resourcet, + safe-money, + scientific, + servant, + servant-client, + servant-client-core, + some, + sop-extras, + stm, + strict-mvar, + string-conv, + swagger2, + tasty, + tasty-hunit, + tasty-quickcheck, + template-haskell, + text, + time, + transformers, + unordered-containers, + vector, + witherable, -- Dependencies whose version is fixed/constrained by @cabal.project@ file. build-depends: bech32, - maestro-sdk, clb, - openapi3 + maestro-sdk, + openapi3, -- Cardano libraries which are not on hackage. Their version is pinned in @cabal.project@ file or derived from other related dependencies. build-depends: @@ -270,14 +280,13 @@ library cardano-api:internal, cardano-crypto, cardano-crypto-class, + cardano-ledger-alonzo, cardano-ledger-api, - cardano-ledger-core:{cardano-ledger-core, testlib}, + cardano-ledger-binary, cardano-ledger-byron, - cardano-ledger-core, cardano-ledger-conway, - cardano-ledger-shelley, - cardano-ledger-alonzo, - cardano-ledger-binary, + cardano-ledger-core, + cardano-ledger-core:{cardano-ledger-core, testlib}, cardano-ledger-shelley, cardano-slotting, cardano-testnet, @@ -290,12 +299,12 @@ library -- needed for examples -- Version of @plutus-core@ is pinned in @cabal.project@ file. - build-depends: plutus-core - build-depends: atlas-cardano:framework-onchain-plutustx + build-depends: plutus-core + build-depends: atlas-cardano:framework-onchain-plutustx library framework-onchain-plutustx - import: common, plutus-ghc-options - hs-source-dirs: src-plutustx + import: common, plutus-ghc-options + hs-source-dirs: src-plutustx exposed-modules: GeniusYield.OnChain.AStakeValidator GeniusYield.OnChain.AStakeValidator.Compiled @@ -304,32 +313,37 @@ library framework-onchain-plutustx GeniusYield.OnChain.TestToken GeniusYield.OnChain.TestToken.Compiled - build-depends: base ^>=4.18.2 - + build-depends: base ^>=4.18.2 -- Cardano libraries which are not on hackage. Their version is pinned in @cabal.project@ file. build-depends: plutus-core, plutus-ledger-api, plutus-tx, - plutus-tx-plugin + plutus-tx-plugin, test-suite atlas-tests - import: common, plutus-ghc-options - type: exitcode-stdio-1.0 - main-is: atlas-tests.hs + import: common, plutus-ghc-options + type: exitcode-stdio-1.0 + main-is: atlas-tests.hs hs-source-dirs: tests - ghc-options: -threaded -rtsopts -Wall + ghc-options: + -threaded + -rtsopts + -Wall -- set target plutus-core version - ghc-options: -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 + ghc-options: + -fplugin-opt + PlutusTx.Plugin:target-version=1.0.0 + other-modules: GeniusYield.Test.Blueprint GeniusYield.Test.CoinSelection GeniusYield.Test.Config GeniusYield.Test.FeeTracking GeniusYield.Test.GYTxBody - GeniusYield.Test.GYTxSkeleton GeniusYield.Test.GYTxOutRefCbor + GeniusYield.Test.GYTxSkeleton GeniusYield.Test.OnChain.AlwaysSucceeds GeniusYield.Test.OnChain.AlwaysSucceeds.Compiled GeniusYield.Test.OnChain.GuessRefInputDatum @@ -343,6 +357,7 @@ test-suite atlas-tests -- Dependencies inherited from the library. No need to specify bounds. build-depends: + MonadRandom, aeson, atlas-cardano, base, @@ -355,7 +370,6 @@ test-suite atlas-tests filepath, http-api-data, maestro-sdk, - MonadRandom, ouroboros-consensus, plutus-ledger-api, plutus-tx, @@ -365,20 +379,23 @@ test-suite atlas-tests tasty-quickcheck, text, time, - transformers + transformers, -- Additional dependencies. build-depends: QuickCheck, quickcheck-instances, - tasty-golden + tasty-golden, test-suite atlas-privnet-tests - import: common - type: exitcode-stdio-1.0 - ghc-options: -threaded -rtsopts + import: common + type: exitcode-stdio-1.0 + ghc-options: + -threaded + -rtsopts + hs-source-dirs: tests-privnet - main-is: atlas-privnet-tests.hs + main-is: atlas-privnet-tests.hs other-modules: GeniusYield.Test.Privnet.Blueprint GeniusYield.Test.Privnet.Committee @@ -402,23 +419,30 @@ test-suite atlas-privnet-tests mtl, plutus-tx, tasty, - tasty-hunit + tasty-hunit, test-suite atlas-unified-tests - import: common, plutus-ghc-options - type: exitcode-stdio-1.0 - main-is: atlas-unified-tests.hs + import: common, plutus-ghc-options + type: exitcode-stdio-1.0 + main-is: atlas-unified-tests.hs hs-source-dirs: tests-unified - ghc-options: -threaded -rtsopts -Wall + ghc-options: + -threaded + -rtsopts + -Wall -- set target plutus-core version - ghc-options: -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 + ghc-options: + -fplugin-opt + PlutusTx.Plugin:target-version=1.0.0 + other-modules: - GeniusYield.Test.Unified.OnChain.BetRef - GeniusYield.Test.Unified.OnChain.BetRef.Compiled GeniusYield.Test.Unified.BetRef.Operations GeniusYield.Test.Unified.BetRef.PlaceBet GeniusYield.Test.Unified.BetRef.TakePot + GeniusYield.Test.Unified.OnChain.BetRef + GeniusYield.Test.Unified.OnChain.BetRef.Compiled + -- Dependencies inherited from the library. No need to specify bounds. build-depends: atlas-cardano, @@ -428,7 +452,7 @@ test-suite atlas-unified-tests mtl, plutus-core, plutus-ledger-api, - plutus-tx-plugin, plutus-tx, + plutus-tx-plugin, tasty, text, diff --git a/cabal.project b/cabal.project index 9bf12340..5b5858c2 100644 --- a/cabal.project +++ b/cabal.project @@ -14,12 +14,12 @@ packages: . tests: true -- repeating the index-state for hackage to work around hackage.nix parsing limitation -index-state: 2024-10-10T00:52:24Z +index-state: 2025-01-01T23:24:19Z -- NOTE: Do not bump chap index beyond that used by target cardano-node version. index-state: - , hackage.haskell.org 2024-10-10T00:52:24Z - , cardano-haskell-packages 2024-11-26T16:00:26Z + , hackage.haskell.org 2025-01-01T23:24:19Z + , cardano-haskell-packages 2025-02-11T21:18:23Z -- TODO: Default value should be @direct@ in upcoming 3.10 version of cabal, omit this line then. test-show-details: direct @@ -27,42 +27,34 @@ test-show-details: direct package cardano-crypto-praos flags: -external-libsodium-vrf +-- TODO: Temporary, track: https://github.com/maestro-org/haskell-sdk/pull/74. source-repository-package type: git - location: https://github.com/maestro-org/haskell-sdk - tag: v1.7.3 - --sha256: sha256-FYZMbh9Uz+RIjjXIf3PBK94mhd1XMX/wxHDA9LukvQg= + location: https://github.com/sourabhxyz/haskell-sdk + tag: 558924a2379ca9c76562be2214e069118db1b3f6 + --sha256: sha256-OEjlMxcJ8VUVDTEtzHcqQ7ml26Sxgb1X55AZCpJ6TJo= --- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/62) +-- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/72) source-repository-package type: git location: https://github.com/sourabhxyz/clb - tag: 257475d987994db8dc5b1b27c9cdf6d6ea547a2c - --sha256: sha256-Tf9Pxh0W1cyvqPKKA07VVZCOLJBMk8W7BVLV+jwZeOM= + tag: d5ba83f8ecff7a30733c43a1bc0dc0c567d03858 + --sha256: sha256-zfugilZJqbwvF9U3cUSDRGG28g5OHOz8XExqTpBeM0I= subdir: clb emulator --- Obtaining cardano-node stuff for 10.1.3 as cardano-testnet version available on CHaP is not correctly updated. +-- Using latest version which is not on CHaP. source-repository-package type: git location: https://github.com/IntersectMBO/cardano-node - tag: 10.1.3 - --sha256: sha256-v0q8qHdI6LKc8mP43QZt3UGdTNDQXE0aF6QapvZsTvU= + tag: 757f3386fc39dfeadb184d87e06bbf310d58344f + --sha256: sha256-M+LdSrGgh3wM/CN3XruPFoFnNqTcDRMHhnr0SgtLBAc= subdir: cardano-node cardano-testnet trace-dispatcher - --- TODO: Temporary, track https://github.com/IntersectMBO/cardano-api/issues/714. -source-repository-package - type: git - location: https://github.com/sourabhxyz/cardano-api - tag: 7081a82a4c6dd57cc0ab01027a18233d3bca2b3e - --sha256: sha256-JGyNbkEkBl69mfMc42Sq4sBwR2IY84aO2WcQihSKdLM= - subdir: - cardano-api - cardano-api-gen + trace-forward package postgresql-libpq flags: +use-pkg-config From a1cc1c3949fb43702c0d95ddbb9c50e760a6f6ef Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Sun, 23 Feb 2025 19:54:14 +0530 Subject: [PATCH 2/9] feat(#408): update to latest IOG dependencies and updated other dependencies in sync --- cabal.project | 8 +- src/GeniusYield/Providers/LiteChainIndex.hs | 2 +- src/GeniusYield/Test/Privnet/Setup.hs | 4 +- src/GeniusYield/Transaction.hs | 84 +++++++++++---------- src/GeniusYield/Types/BuildScript.hs | 2 +- src/GeniusYield/Types/KeyHash.hs | 12 +-- src/GeniusYield/Types/KeyRole.hs | 5 ++ src/GeniusYield/Types/Pool.hs | 1 - src/GeniusYield/Types/Script.hs | 37 +++++++-- src/GeniusYield/Types/TxBody.hs | 4 +- src/GeniusYield/Types/TxOut.hs | 7 +- src/GeniusYield/Types/UTxO.hs | 2 +- src/GeniusYield/Types/Value.hs | 4 +- 13 files changed, 101 insertions(+), 71 deletions(-) diff --git a/cabal.project b/cabal.project index 5b5858c2..4a29a18e 100644 --- a/cabal.project +++ b/cabal.project @@ -31,15 +31,15 @@ package cardano-crypto-praos source-repository-package type: git location: https://github.com/sourabhxyz/haskell-sdk - tag: 558924a2379ca9c76562be2214e069118db1b3f6 - --sha256: sha256-OEjlMxcJ8VUVDTEtzHcqQ7ml26Sxgb1X55AZCpJ6TJo= + tag: 8367d46936a916d4179ded3148a232a3931c7a62 + --sha256: FIXME: -- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/72) source-repository-package type: git location: https://github.com/sourabhxyz/clb - tag: d5ba83f8ecff7a30733c43a1bc0dc0c567d03858 - --sha256: sha256-zfugilZJqbwvF9U3cUSDRGG28g5OHOz8XExqTpBeM0I= + tag: 1b084647dc9118520c1cc615cf2fa7c3dd8a394e + --sha256: FIXME: subdir: clb emulator diff --git a/src/GeniusYield/Providers/LiteChainIndex.hs b/src/GeniusYield/Providers/LiteChainIndex.hs index 52e1d863..c4d53ab8 100644 --- a/src/GeniusYield/Providers/LiteChainIndex.hs +++ b/src/GeniusYield/Providers/LiteChainIndex.hs @@ -207,6 +207,6 @@ blockDatums (Api.BlockInMode _ block) = goBlock block goDatum :: Api.TxOutDatum Api.CtxTx era -> [Api.HashableScriptData] goDatum Api.TxOutDatumNone = [] - goDatum (Api.TxOutDatumInTx _ sd) = [sd] + goDatum (Api.TxOutSupplementalDatum _ sd) = [sd] goDatum (Api.TxOutDatumHash _ _h) = [] goDatum (Api.TxOutDatumInline _ sd) = [sd] diff --git a/src/GeniusYield/Test/Privnet/Setup.hs b/src/GeniusYield/Test/Privnet/Setup.hs index b1594d80..e90339c0 100644 --- a/src/GeniusYield/Test/Privnet/Setup.hs +++ b/src/GeniusYield/Test/Privnet/Setup.hs @@ -62,7 +62,7 @@ import Test.Cardano.Ledger.Core.Rational (unsafeBoundRational, (%!)) import Test.Tasty (TestName, TestTree) import Test.Tasty.HUnit (testCaseSteps) import Testnet.Property.Util -import Testnet.Start.Types (GenesisOptions (..)) +import Testnet.Start.Types (GenesisOptions (..), UserNodeConfig (UserNodeConfigNotSubmitted)) import Testnet.Types hiding (shelleyGenesis) ------------------------------------------------------------------------------- @@ -374,7 +374,7 @@ withPrivnet (testnetOpts, genesisOpts) setupUser = do Api.AnyShelleyBasedEra sbe <- pure cardanoNodeEra alonzoGenesis <- getDefaultAlonzoGenesis sbe shelleyGenesis <- getDefaultShelleyGenesis cardanoNodeEra cardanoMaxSupply shelleyOptions - cardanoTestnet testnetOptions conf shelleyGenesis alonzoGenesis (conwayGenesis ctxCommittee) + cardanoTestnet testnetOptions conf UserNodeConfigNotSubmitted shelleyGenesis alonzoGenesis (conwayGenesis ctxCommittee) where CardanoTestnetOptions {cardanoNodeEra, cardanoMaxSupply} = testnetOptions diff --git a/src/GeniusYield/Transaction.hs b/src/GeniusYield/Transaction.hs index 064bd31e..16415b91 100644 --- a/src/GeniusYield/Transaction.hs +++ b/src/GeniusYield/Transaction.hs @@ -61,7 +61,6 @@ module GeniusYield.Transaction ( ) where import Cardano.Api qualified as Api -import Cardano.Api.Experimental qualified as Api import Cardano.Api.Ledger qualified as Ledger import Cardano.Api.Shelley qualified as Api import Cardano.Api.Shelley qualified as Api.S @@ -76,20 +75,21 @@ import Cardano.Ledger.Binary qualified as CBOR import Cardano.Ledger.Binary.Crypto qualified as CBOR import Cardano.Ledger.Conway.PParams qualified as Ledger import Cardano.Ledger.Core ( + Era (..), EraTx (sizeTxF), eraProtVerLow, ) import Cardano.Ledger.Core qualified as Ledger import Cardano.Ledger.Crypto (Crypto (..)) -import Cardano.Ledger.Era (Era (..)) import Cardano.Ledger.Keys.WitVKey (WitVKey (..)) import Cardano.Ledger.Shelley.API.Wallet qualified as Shelley import Cardano.Slotting.Time (SystemStart) import Control.Arrow ((&&&)) import Control.Lens (view, (^.)) -import Control.Monad.Random +import Control.Monad.Random (MonadRandom) import Control.Monad.Trans.Except (runExceptT, throwE) import Data.Bifunctor qualified +import Data.Bifunctor qualified as Data.Binfunctor import Data.ByteString.Lazy qualified as LBS import Data.Foldable ( Foldable (foldMap'), @@ -97,10 +97,10 @@ import Data.Foldable ( ) import Data.List (delete) import Data.Map qualified as Map -import Data.Maybe (maybeToList) import Data.Ratio ((%)) import Data.Semigroup (Sum (..)) import Data.Set qualified as Set +import GHC.IsList (IsList (fromList)) import GeniusYield.Imports import GeniusYield.Transaction.CBOR import GeniusYield.Transaction.CoinSelection @@ -497,20 +497,32 @@ finalizeGYBalancedTx mint = case mmint of Nothing -> Api.TxMintNone Just (v, xs) -> - Api.TxMintValue Api.MaryEraOnwardsConway (valueToApi v) $ - Api.BuildTxWith $ - Map.fromList - [ ( mintingPolicyApiIdFromWitness p - , case p of - GYBuildPlutusScript s -> - gyMintingScriptWitnessToApiPlutusSW - s - (redeemerToApi r) - (Api.ExecutionUnits 0 0) - GYBuildSimpleScript s -> simpleScriptWitnessToApi s - ) - | (p, r) <- xs - ] + let policyIdWit = Map.fromList [(mintingPolicyIdFromWitness p, (p, r)) | (p, r) <- xs] + mintVal = + valueToList v + & foldl' + ( \acc (asc, amt) -> case asc of + GYLovelace -> error "absurd: trying to mint ada value" + GYToken pid tn -> case Map.lookup pid policyIdWit of + Nothing -> error $ "absurd: policy id " <> show pid <> " not found in wit map " <> show policyIdWit + Just (p, r) -> + Map.insertWith + (<>) + (mintingPolicyIdToApi pid) + [ + ( tokenNameToApi tn + , Api.Quantity amt + , Api.BuildTxWith + ( case p of + GYBuildPlutusScript s -> gyMintingScriptWitnessToApiPlutusSW s (redeemerToApi r) (Api.ExecutionUnits 0 0) + GYBuildSimpleScript s -> simpleScriptWitnessToApi s + ) + ) + ] + acc + ) + mempty + in Api.TxMintValue Api.MaryEraOnwardsConway mintVal -- Putting `TxTotalCollateralNone` & `TxReturnCollateralNone` would have them appropriately calculated by `makeTransactionBodyAutoBalance` but then return collateral it generates is only for ada. To support multi-asset collateral input we therefore calculate correct values ourselves and put appropriate entries here to have `makeTransactionBodyAutoBalance` calculate appropriate overestimated fees. (dummyTotCol :: Api.TxTotalCollateral ApiEra, dummyRetCol :: Api.TxReturnCollateral Api.CtxTx ApiEra) = @@ -542,16 +554,8 @@ finalizeGYBalancedTx if certs == mempty then Api.TxCertificatesNone else - let apiCertsFromGY = - foldl' - ( \(accCerts, accWits) cert -> - let (apiCert, mapiWit) = txCertToApi cert - apiWit = maybeToList mapiWit - in (apiCert : accCerts, accWits <> apiWit) - ) - (mempty, mempty) - certs - in Api.TxCertificates Api.ShelleyBasedEraConway (reverse $ fst apiCertsFromGY) $ Api.BuildTxWith (snd apiCertsFromGY) + let apiCerts = map (Data.Binfunctor.second pure . txCertToApi) certs + in Api.TxCertificates Api.ShelleyBasedEraConway (fromList apiCerts) unregisteredStakeCredsMap = Map.fromList [(stakeCredentialToApi sc, fromIntegral amt) | GYStakeAddressDeregistrationCertificate amt sc <- map gyTxCertCertificate' certs] @@ -608,8 +612,6 @@ finalizeGYBalancedTx , Api.txFee = fee , Api.txValidityLowerBound = lb' , Api.txValidityUpperBound = ub' - , -- Supplemental data feature was added by cardano-api team in this PR: https://github.com/IntersectMBO/cardano-api/pull/640, we can think on making use of it. - Api.txSupplementalData = Api.BuildTxWith Api.TxSupplementalDataNone , Api.txMetadata = txMetadata , Api.txAuxScripts = Api.TxAuxScriptsNone , Api.txExtraKeyWits = extra @@ -668,7 +670,7 @@ makeTransactionBodyAutoBalanceWrapper collaterals ss eh pp poolids utxos body ch (Just nkeys) -- We should call `makeTransactionBodyAutoBalance` again with updated values of collaterals so as to get slightly lower fee estimate. - Api.BalancedTxBody txBodyContent (Api.UnsignedTx unsignedLTx) extraOut _ <- + Api.BalancedTxBody txBodyContent unsignedLTx extraOut _ <- if collaterals == mempty then return bodyBeforeCollUpdate else @@ -705,11 +707,12 @@ makeTransactionBodyAutoBalanceWrapper collaterals ss eh pp poolids utxos body ch (Just nkeys) let + Api.S.ShelleyTx _ ltx = Api.Tx unsignedLTx [] -- This sums up the ExUnits for all embedded Plutus Scripts anywhere in the transaction: AlonzoScripts.ExUnits { AlonzoScripts.exUnitsSteps = steps , AlonzoScripts.exUnitsMem = mem - } = AlonzoTx.totExUnits unsignedLTx + } = AlonzoTx.totExUnits ltx txSize :: Natural = let -- This low level code is taken verbatim from here: https://github.com/IntersectMBO/cardano-ledger/blob/6db84a7b77e19af58feb2f45dfc50aa70435967b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs#L475-L494, as this is what is referred by @cardano-api@ under the hood. @@ -733,7 +736,7 @@ makeTransactionBodyAutoBalanceWrapper collaterals ss eh pp poolids utxos body ch keyBytes = CBOR.serialize version $ padding <> sw in fromRight (error "corrupt dummy vkey") (CBOR.decodeFull version keyBytes) in - fromInteger $ view sizeTxF $ Shelley.addKeyWitnesses unsignedLTx (Set.fromList [WitVKey (dummyVKey x) dummySig | x <- [1 .. nkeys]]) + fromInteger $ view sizeTxF $ Shelley.addKeyWitnesses ltx (Set.fromList [WitVKey (dummyVKey x) dummySig | x <- [1 .. nkeys]]) -- See: Cardano.Ledger.Alonzo.Rules.validateExUnitsTooBigUTxO unless (steps <= maxSteps && mem <= maxMemory) $ Left $ @@ -742,9 +745,9 @@ makeTransactionBodyAutoBalanceWrapper collaterals ss eh pp poolids utxos body ch unless (txSize <= maxTxSize) $ Left (GYBuildTxSizeTooBig maxTxSize txSize) - (Api.UnsignedTx collapsedUnsignedLTx) <- first GYBuildTxCollapseExtraOutError $ collapseExtraOut extraOut txBodyContent (Api.UnsignedTx unsignedLTx) numSkeletonOuts + collapsedUnsignedLTx <- first GYBuildTxCollapseExtraOutError $ collapseExtraOut extraOut txBodyContent unsignedLTx numSkeletonOuts - first GYBuildTxCborSimplificationError $ getTxBody <$> simplifyTxCbor (txFromLedger collapsedUnsignedLTx) + first GYBuildTxCborSimplificationError $ simplifyGYTxBodyCbor (txBodyFromApi collapsedUnsignedLTx) {- | Collapses the extra out generated in the last step of tx building into another change output (If one exists) @@ -759,11 +762,11 @@ collapseExtraOut :: -- | The body content generated by @makeTransactionBodyAutoBalance@. Api.TxBodyContent Api.S.BuildTx ApiEra -> -- | The body generated by @makeTransactionBodyAutoBalance@. - Api.UnsignedTx ApiEra -> + Api.TxBody ApiEra -> -- | The number of skeleton outputs we don't want to touch. Int -> -- | The updated body with the collapsed outputs - Either Api.S.TxBodyError (Api.UnsignedTx ApiEra) + Either Api.S.TxBodyError (Api.TxBody ApiEra) collapseExtraOut apiOut@(Api.TxOut _ outVal _ _) bodyContent@Api.TxBodyContent {txOuts} unsignedLTx numSkeletonOuts | Api.txOutValueToLovelace outVal == 0 = pure unsignedLTx | otherwise = @@ -781,10 +784,9 @@ collapseExtraOut apiOut@(Api.TxOut _ outVal _ _) bodyContent@Api.TxBodyContent { -- nOuts == new Outs == The new list of outputs nOuts = skeletonOuts ++ remOuts ++ [nOut] in - Api.convertTxBodyToUnsignedTx Api.ShelleyBasedEraConway - <$> ( Api.S.createTransactionBody Api.ShelleyBasedEraConway $ - bodyContent {Api.txOuts = nOuts} - ) + ( Api.S.createTransactionBody Api.ShelleyBasedEraConway $ + bodyContent {Api.txOuts = nOuts} + ) where (skeletonOuts, changeOuts) = splitAt numSkeletonOuts txOuts diff --git a/src/GeniusYield/Types/BuildScript.hs b/src/GeniusYield/Types/BuildScript.hs index cc47a90f..83c955ae 100644 --- a/src/GeniusYield/Types/BuildScript.hs +++ b/src/GeniusYield/Types/BuildScript.hs @@ -106,7 +106,7 @@ simpleScriptWitnessToApi = Api.SimpleScriptWitness Api.SimpleScriptInConway . h where h :: GYBuildSimpleScript u -> Api.S.SimpleScriptOrReferenceInput lang h (GYBuildSimpleScriptInlined v) = Api.SScript $ simpleScriptToApi v - h (GYBuildSimpleScriptReference ref s) = Api.SReferenceScript (txOutRefToApi ref) $ Just $ hashSimpleScript' s + h (GYBuildSimpleScriptReference ref _s) = Api.SReferenceScript (txOutRefToApi ref) type GYStakeValScript v = GYBuildPlutusScript v diff --git a/src/GeniusYield/Types/KeyHash.hs b/src/GeniusYield/Types/KeyHash.hs index a657c1d5..7c93be37 100644 --- a/src/GeniusYield/Types/KeyHash.hs +++ b/src/GeniusYield/Types/KeyHash.hs @@ -43,7 +43,7 @@ import Data.Text (Text) import Data.Text qualified as Text import Data.Text.Encoding qualified as Text import GeniusYield.Imports (coerce, (&), (>>>)) -import GeniusYield.Types.KeyRole (GYKeyRole (..), GYKeyRoleToLedger, GYKeyRoleVRF, SingGYKeyRole (..), SingGYKeyRoleI (..), fromSingGYKeyRole) +import GeniusYield.Types.KeyRole (GYKeyRole (..), GYKeyRoleToLedger, GYKeyRoleVRF, GYKeyRoleVRFToLedger, SingGYKeyRole (..), SingGYKeyRoleI (..), fromSingGYKeyRole) import GeniusYield.Types.PubKeyHash (AsPubKeyHash (fromPubKeyHash, toPubKeyHash), CanSignTx, pubKeyHashFromApi, pubKeyHashToApi) import Text.Printf qualified as Printf @@ -228,13 +228,13 @@ instance SingGYKeyRoleI kr => Swagger.ToSchema (GYKeyHash kr) where ?~ 56 -- | Hash of a public key corresponding to a given `GYKeyRoleVRF`. -newtype GYVRFVerKeyHash (kr :: GYKeyRoleVRF) = GYVRFVerKeyHash (Ledger.Hash Ledger.StandardCrypto (Ledger.VerKeyVRF Ledger.StandardCrypto)) +newtype GYVRFVerKeyHash (kr :: GYKeyRoleVRF) = GYVRFVerKeyHash (Ledger.VRFVerKeyHash (GYKeyRoleVRFToLedger kr) Ledger.StandardCrypto) deriving newtype (Eq, Ord) -vrfVerKeyHashToLedger :: GYVRFVerKeyHash kr -> Ledger.Hash Ledger.StandardCrypto (Ledger.VerKeyVRF Ledger.StandardCrypto) +vrfVerKeyHashToLedger :: GYVRFVerKeyHash kr -> Ledger.VRFVerKeyHash (GYKeyRoleVRFToLedger kr) Ledger.StandardCrypto vrfVerKeyHashToLedger = coerce -vrfVerKeyHashFromLedger :: Ledger.Hash Ledger.StandardCrypto (Ledger.VerKeyVRF Ledger.StandardCrypto) -> GYVRFVerKeyHash kr +vrfVerKeyHashFromLedger :: Ledger.VRFVerKeyHash (GYKeyRoleVRFToLedger kr) Ledger.StandardCrypto -> GYVRFVerKeyHash kr vrfVerKeyHashFromLedger = coerce {- | @@ -250,7 +250,7 @@ instance Show (GYVRFVerKeyHash kr) where -- | Get corresponding raw bytes. vrfVerKeyHashToRawBytes :: GYVRFVerKeyHash kr -> BS.ByteString -vrfVerKeyHashToRawBytes kh = Crypto.hashToBytes $ vrfVerKeyHashToLedger kh +vrfVerKeyHashToRawBytes kh = Crypto.hashToBytes $ Ledger.fromVRFVerKeyHash $ vrfVerKeyHashToLedger kh -- | Get corresponding raw bytes represented as hex. vrfVerKeyHashToRawBytesHex :: GYVRFVerKeyHash kr -> BS.ByteString @@ -262,7 +262,7 @@ vrfVerKeyHashToRawBytesHexText = vrfVerKeyHashToRawBytesHex >>> Text.decodeUtf8 -- | Decode from raw bytes. vrfVerKeyHashFromRawBytes :: BS.ByteString -> Maybe (GYVRFVerKeyHash kr) -vrfVerKeyHashFromRawBytes bs = vrfVerKeyHashFromLedger <$> Crypto.hashFromBytes bs +vrfVerKeyHashFromRawBytes bs = vrfVerKeyHashFromLedger . Ledger.toVRFVerKeyHash <$> Crypto.hashFromBytes bs -- | Decode from raw bytes represented as hex. vrfVerKeyHashFromRawBytesHex :: BS.ByteString -> Either String (GYVRFVerKeyHash kr) diff --git a/src/GeniusYield/Types/KeyRole.hs b/src/GeniusYield/Types/KeyRole.hs index d82564dc..96869058 100644 --- a/src/GeniusYield/Types/KeyRole.hs +++ b/src/GeniusYield/Types/KeyRole.hs @@ -12,9 +12,11 @@ module GeniusYield.Types.KeyRole ( SingGYKeyRoleI (..), GYKeyRoleToLedger, GYKeyRoleVRF (..), + GYKeyRoleVRFToLedger, ) where import Cardano.Api.Ledger qualified as Ledger +import Cardano.Ledger.Keys qualified as Ledger -- | Role of a key. data GYKeyRole @@ -62,3 +64,6 @@ type family GYKeyRoleToLedger (kr :: GYKeyRole) :: Ledger.KeyRole where -- | Role of a VRF key. data GYKeyRoleVRF = GYKeyRoleVRFStakePool + +type family GYKeyRoleVRFToLedger (kr :: GYKeyRoleVRF) :: Ledger.KeyRoleVRF where + GYKeyRoleVRFToLedger 'GYKeyRoleVRFStakePool = Ledger.StakePoolVRF diff --git a/src/GeniusYield/Types/Pool.hs b/src/GeniusYield/Types/Pool.hs index c6ff6b17..ca74655a 100644 --- a/src/GeniusYield/Types/Pool.hs +++ b/src/GeniusYield/Types/Pool.hs @@ -14,7 +14,6 @@ module GeniusYield.Types.Pool ( import Cardano.Api.Address qualified as Api import Cardano.Api.ReexposeLedger qualified as Ledger -import Cardano.Ledger.Api qualified as Ledger import Cardano.Ledger.BaseTypes import Data.IP (IPv4, IPv6) import Data.Maybe (fromMaybe) diff --git a/src/GeniusYield/Types/Script.hs b/src/GeniusYield/Types/Script.hs index 353959b9..2109a33f 100644 --- a/src/GeniusYield/Types/Script.hs +++ b/src/GeniusYield/Types/Script.hs @@ -525,8 +525,10 @@ someScriptToReferenceApi :: GYAnyScript -> Api.S.ReferenceScript ApiEra someScriptToReferenceApi (GYPlutusScript (GYScript v apiScript _)) = Api.S.ReferenceScript Api.S.BabbageEraOnwardsConway - $ Api.ScriptInAnyLang (Api.PlutusScriptLanguage v') - $ Api.PlutusScript v' apiScript + $ case v' of + Api.PlutusScriptV1 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage v') $ Api.PlutusScript v' apiScript + Api.PlutusScriptV2 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage v') $ Api.PlutusScript v' apiScript + Api.PlutusScriptV3 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage v') $ Api.PlutusScript v' apiScript where v' = singPlutusVersionToApi v someScriptToReferenceApi (GYSimpleScript s) = @@ -582,8 +584,12 @@ scriptFromApi :: forall v. SingPlutusVersionI v => Api.PlutusScript (PlutusVersi scriptFromApi script = GYScript v script apiHash where v = singPlutusVersion @v + v' = singPlutusVersionToApi v apiScript :: Api.S.Script (PlutusVersionToApi v) - apiScript = Api.PlutusScript (singPlutusVersionToApi v) script + apiScript = case v' of + Api.PlutusScriptV1 -> Api.PlutusScript v' script + Api.PlutusScriptV2 -> Api.PlutusScript v' script + Api.PlutusScriptV3 -> Api.PlutusScript v' script apiHash = Api.hashScript apiScript -- >>> scriptFromCBOR @'PlutusV2 "59212d010000323232323322332233223232323322323232323232323332223332223232323232332232323232323232323233322232323232323233223232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323223232323223232322323253353232323232323232323232323304e3301c4912054687265616420746f6b656e206d697373696e672066726f6d20696e7075742e00330553304d301a50043035500b480094cd4c0e0030854cd4c100034854ccd400454cccccd4028418041808418441804cc140cc0792411c4e6f74207369676e6564206279207365636f6e6420706c617965722e003355072301b50083355072077303b500d3301e4901124e4654206d757374206265206275726e742e005007221062106015333333500a1330503301e4911c4e6f74207369676e6564206279207365636f6e6420706c617965722e003355072301b50083355072077303b500d3301e4901124e4654206d757374206265206275726e742e00500710602106110601060221062153333335009105f13304f3301d49011c4e6f74207369676e6564206279207365636f6e6420706c617965722e003355071301a50073355071076303a500c3304f3301d4914043616e6e6f7420636c61696d206265666f72652074696d65206475726174696f6e20676976656e20666f7220666972737420706c617965722773206d6f76652e0033350455052350443332001505948009402cc071401ccc075241124e4654206d757374206265206275726e742e00500621060105f105f221330513301f49011b4e6f74207369676e656420627920666972737420706c617965722e003355073301c50093355073078303d500e330513301f49110436f6d6d6974206d69736d617463682e0033036372466e28008c178004c10c03ccc144cc07d241104d697373656420646561646c696e652e003335047505433502f3039500e500d301e50095333553353332001505d001003106d1533553335001153335003106110621061153335003106110611062153335003106210611061106c106b1330513301f49011357726f6e67206f757470757420646174756d2e00330513303630435005305e001330513332001505c303b50053507b0033332001505a500406d330513301f4911a546f6b656e206d697373696e672066726f6d206f75747075742e003305833050301d50063038500e48008cc07d24012d5365636f6e6420706c617965722773207374616b65206d697373696e6720696e2064726177206f75747075742e00330583505f301d5006303a500e13301f4901124e4654206d757374206265206275726e742e0050081330513301f4911357726f6e67206f757470757420646174756d2e00330513303630435005305e001330513332001505c303b50053507b0033332001505a500406b330513301f4911a546f6b656e206d697373696e672066726f6d206f75747075742e003305833050301d50063038500e48008cc07d240126596f75206c6f73742c2063616e6e6f742074616b65207374616b652066726f6d2067616d652e00330583505f301d50063332001505948010c0e9403854cd4c0fc0308417c54cccccd40204178417884cc13ccc0752411c4e6f74207369676e6564206279207365636f6e6420706c617965722e003355071301a50073355071076303a500c3304f3301d49120466972737420706c617965722773207374616b65206973206d697373696e672e00330563505d301b50053038500c3304f3301d4901215365636f6e6420706c617965722773207374616b65206973206d697373696e672e00330563505d301b50043332001505748010c0e14030cc13ccc07524011357726f6e67206f757470757420646174756d2e003304f3303430415003304100d3304f3332001505a3039500335079001325335001210611061304050033304f3301d491104d697373656420646561646c696e652e003335045505233502d3037500c500a301c50073301d49011a546f6b656e206d697373696e672066726f6d206f75747075742e00330563304e301b50043036500c480084cc138cc07124011b4e6f74207369676e656420627920666972737420706c617965722e003355070301950063075303a500b3304e3301c4914143616e6e6f7420636c61696d206265666f72652074696d65206475726174696f6e20676976656e20666f72207365636f6e6420706c617965722773206d6f76652e00333504450513504333320015058480094024c06d4018cc071241124e4654206d757374206265206275726e742e005005105e22106015335303e50012100113507c4901334d6174636820726573756c7420657870656374656420627574206f757470757420646174756d20686173206e6f7468696e672e001335506e05f306f500115335335506d3355302a1200122533532323304f33033303b002303b0013304f33033303a002303a0013304f33056303800230380013304f33056303700230370013304f33056303f002303f0013304f3232350022235003225335333573466e3c0100081981944cc0e800c0044194c0dc008c0d8008cc13ccc0c8c0d4008c0d4004cc13ccc0d0c0f0008c0f0004cc13ccc158c0f4008c0f4004cc13ccc0d0c108008c108004cc0d0c10c008c10c004c0f4030c0f0cd541bc180c1c00084cd41c4008004400541c14cd4c0ac01084d400488d40048888d402c88d4008888888888888ccd54c0fc4800488d400888894cd4cc1280600104cd42280401801440154214040284c98c81f0cd5ce2481024c660007c13507a491384e6f206f7574707574206174207468697320736372697074206164647265737320686176696e672073616d6520706172616d65746572732e00221533500110022213507e49012145787065637465642065786163746c79206f6e652067616d65206f75747075742e0015335302a00321350012200113507949011347616d6520696e707574206d697373696e672e00133050330483235001222222222222008500130305006480044d400488008cccd5cd19b8735573aa00e9000119910919800801801191919191919191919191919191999ab9a3370e6aae754031200023333333333332222222222221233333333333300100d00c00b00a00900800700600500400300233502502635742a01866a04a04c6ae85402ccd409409cd5d0a805199aa814bae502835742a012666aa052eb940a0d5d0a80419a8128179aba150073335502903075a6ae854018c8c8c8cccd5cd19b8735573aa0049000119a8289919191999ab9a3370e6aae7540092000233505633503a75a6ae854008c0ecd5d09aba2500223263208f013357380c011e0211a0226aae7940044dd50009aba150023232323333573466e1cd55cea80124000466a0b066a074eb4d5d0a801181d9aba135744a004464c6411e0266ae7018023c04234044d55cf280089baa001357426ae8940088c98c822c04cd5ce02e045808448089aab9e5001137540026ae854014cd4095d71aba150043335502902c200135742a006666aa052eb88004d5d0a80118171aba135744a004464c6410e0266ae7016021c04214044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135573ca00226ea8004d5d0a803980f1aba135744a00e464c640f266ae701281e41dccccd5cd19b87500848028848888880188cccd5cd19b87500948020848888880088cccd5cd19b87500a48018848888880148cccd5cd19b87500b480108488888800c8cccd5cd19b87500c480088c8c84888888cc00402001cc134d5d09aba2500f375c6ae8540388cccd5cd19b87500d480008c84888888c01001cc134d5d09aab9e501023263207d33573809c0fa0f60f40f20f00ee0ec26664002a09e605aa00464002606aa00426664002a09c6664002a09c6058a002640026068a002640026068a002260640026666ae68cdc39aab9d500b480008cccc160c8c8c8c8c8c8c8c8c8c8c8c8cccd5cd19b8735573aa016900011999999999983218121aba1500b302435742a0146eb4d5d0a8049bad35742a0106eb4d5d0a8039919191999ab9a3370e6aae75400920002335507a375c6ae854008dd71aba135744a004464c6410a0266ae701582140420c044d55cf280089baa00135742a00c604e6ae854014dd71aba15004375a6ae85400cdd71aba15002375c6ae84d5d128011193190408099ab9c0520810107f135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226aae7940044dd50009aba1500b375c6ae854028cd4060110d5d0a80499a80c1191999ab9a3370ea0029002103111999ab9a3370ea0049001103091999ab9a3370ea0069000103191931903c99ab9c04a079077076075135573a6ea8004d5d09aba2500923263207433573808a0e80e420e626a0e292010350543500135573ca00226ea80044d55cea80109aab9e50011375400226ae8940044d5d1280089aab9e500113754002446a004444444444444a66a666aa604a24002a0484a66a666ae68cdc780700082a82a09a8370008a8368021082a882991a800911100191a80091111111111100291299a8008822899ab9c0020441232230023758002640026aa0c8446666aae7c004941688cd4164c010d5d080118019aba2002065232323333573466e1cd55cea8012400046644246600200600460166ae854008c014d5d09aba2500223263206533573806c0ca0c626aae7940044dd50009191919191999ab9a3370e6aae7540112000233332222123333001005004003002300935742a008666aa010eb9401cd5d0a8019919191999ab9a3370ea0029002119091118010021aba135573ca00646666ae68cdc3a80124004464244460020086eb8d5d09aab9e500423333573466e1d400d20002122200323263206c33573807a0d80d40d20d026aae7540044dd50009aba1500233500a75c6ae84d5d1280111931903319ab9c037066064135744a00226ae8940044d55cf280089baa0011335500175ceb44488c88c008dd5800990009aa83091191999aab9f0022505823350573355059300635573aa004600a6aae794008c010d5d100183189aba1001232323333573466e1cd55cea801240004660b060166ae854008cd4014028d5d09aba250022326320613357380640c20be26aae7940044dd500089119191999ab9a3370ea002900011a82d18029aba135573ca00646666ae68cdc3a801240044a0b4464c640c466ae700cc18818017c4d55cea80089baa001232323333573466e1d400520062321222230040053007357426aae79400c8cccd5cd19b875002480108c848888c008014c024d5d09aab9e500423333573466e1d400d20022321222230010053007357426aae7940148cccd5cd19b875004480008c848888c00c014dd71aba135573ca00c464c640c466ae700cc18818017c1781744d55cea80089baa001232323333573466e1cd55cea80124000466086600a6ae854008dd69aba135744a004464c640bc66ae700bc1781704d55cf280089baa0012323333573466e1cd55cea800a400046eb8d5d09aab9e500223263205c33573805a0b80b426ea80048c8c8c8c8c8cccd5cd19b8750014803084888888800c8cccd5cd19b875002480288488888880108cccd5cd19b875003480208cc8848888888cc004024020dd71aba15005375a6ae84d5d1280291999ab9a3370ea00890031199109111111198010048041bae35742a00e6eb8d5d09aba2500723333573466e1d40152004233221222222233006009008300c35742a0126eb8d5d09aba2500923333573466e1d40192002232122222223007008300d357426aae79402c8cccd5cd19b875007480008c848888888c014020c038d5d09aab9e500c23263206533573806c0ca0c60c40c20c00be0bc0ba26aae7540104d55cf280189aab9e5002135573ca00226ea80048c8c8c8c8cccd5cd19b875001480088ccc15cdd69aba15004375a6ae85400cdd69aba135744a00646666ae68cdc3a80124000460b260106ae84d55cf280311931902f19ab9c02f05e05c05b135573aa00626ae8940044d55cf280089baa001232323333573466e1d4005200223056375c6ae84d55cf280191999ab9a3370ea00490001182c1bae357426aae7940108c98c816ccd5ce01602d82c82c09aab9d50011375400224464646666ae68cdc3a800a40084a04a46666ae68cdc3a8012400446a04e600c6ae84d55cf280211999ab9a3370ea00690001091100111931902e19ab9c02d05c05a059058135573aa00226ea80048c8cccd5cd19b8750014800880dc8cccd5cd19b8750024800080dc8c98c8160cd5ce01482c02b02a89aab9d375400224466a03666a0386a04200406a66a03c6a04200206a640026aa0a64422444a66a00220044426600a004666aa600e2400200a00800246a002446a0044444444444446666a01a4a0b24a0b24a0b24666aa602424002a02246a00244a66a6602c00400826a0ba0062a0b801a264246600244a66a004420062002004a090640026aa0a04422444a66a00226a00644002442666a00a440046008004666aa600e2400200a00800244a66a666ae68cdc79a801110011a800910010180178999ab9a3370e6a004440026a0024400206005e205e446a004446a006446466a00a466a0084a66a666ae68cdc780100081b01a8a801881a901a919a802101a9299a999ab9a3371e00400206c06a2a006206a2a66a00642a66a0044266a004466a004466a004466a00446601a0040024070466a004407046601a00400244407044466a0084070444a66a666ae68cdc380300181d81d0a99a999ab9a3370e00a0040760742660620080022074207420662a66a00242066206644666ae68cdc780100081701691a8009111111111100291a8009111111111100311a8009111111111100411a8009111111111100491a800911100111a8009111111111100511a8009111111111100591a8009111111111100211a8009111111111100191a800911100211a8009111111111100391a800911100091a800911100191a8009111111111100111a800911111111110008919a80199a8021a80480080e99a803280400e89111a801111a801111a802911a801112999a999a8080058030010a99a8008a99a8028999a80700580180388128999a80700580180388128999a8070058018038910919800801801091091980080180109111a801111a801912999a999a8048038020010a99a8018800880f880f080f89109198008018010911191919192999a80310a999a80310a999a80410980224c26006930a999a80390980224c2600693080a08090a999a80390980224c26006930a999a80310980224c260069308098a999a80290808880908080a999a80290a999a803909802a4c26008930a999a803109802a4c2600893080988088a999a803109802a4c26008930a999a802909802a4c2600893080912999a80290a999a80390a999a80390999a8068050010008b0b0b08090a999a80310a999a80310999a8060048010008b0b0b0808880812999a80210a999a80310a999a80310999a8060048010008b0b0b08088a999a80290a999a80290999a8058040010008b0b0b0808080792999a80190a999a80290a999a80290999a8058040010008b0b0b08080a999a80210a999a80210999a8050038010008b0b0b0807880712999a80110a999a80210a999a80210999a8050038010008b0b0b08078a999a80190a999a80190999a8048030010008b0b0b08070806890911180180208911000891a80091111111003911a8009119980a00200100091299a801080088091191999ab9a3370ea0029002100c91999ab9a3370ea0049001100e11999ab9a3370ea0069000100e11931901a99ab9c006035033032031135573a6ea8005241035054310011233333333001005225335333573466e1c008004044040401854cd4ccd5cd19b890020010110101004100522333573466e2000800404404088ccd5cd19b8900200101101022333573466e2400800404004488ccd5cd19b88002001010011225335333573466e2400800404404040044008894cd4ccd5cd19b890020010110101002100112220031222002122200122333573466e1c00800403002c488cdc10010008912999a8010a999a8008805080488048a999a8008804880508048a999a80088048804880509119b8000200113222533500221533500221330050020011009153350012100910095001122533350021533350011007100610061533350011006100710061533350011006100610072333500148905506170657200488104526f636b0048810853636973736f72730012320013330020010050052223232300100532001355027223350014800088d4008894cd4ccd5cd19b8f00200900c00b130070011300600332001355026223350014800088d4008894cd4ccd5cd19b8f00200700b00a100113006003122002122001488100253353355010232323232323333333574800c46666ae68cdc39aab9d5006480008cccd55cfa8031281011999aab9f500625021233335573ea00c4a04446666aae7d40189408c8cccd55cf9aba2500725335533553355335323232323232323232323232323333333574801a46666ae68cdc39aab9d500d480008cccd55cfa8069281a11999aab9f500d25035233335573ea01a4a06c46666aae7d4034940dc8cccd55cfa8069281c11999aab9f500d25039233335573ea01a4a07446666aae7d4034940ec8cccd55cfa8069281e11999aab9f500d2503d233335573ea01a4a07c46666aae7cd5d128071299aa99aa99aa99aa99aa99aa99aa99aa99aa99aa99a98199aba150192135041302b0011503f215335303435742a032426a08460040022a0802a07e42a66a606a6ae85406084d4108c00800454100540fc854cd4c0d4d5d0a80b909a82118010008a8200a81f90a99a981a9aba1501621350423002001150401503f215335323232323333333574800846666ae68cdc39aab9d5004480008cccd55cfa8021282391999aab9f500425048233335573e6ae89401494cd4c100d5d0a80390a99a98209aba15007213504c33550480020011504a150492504905004f04e2504604c2504525045250452504504c135744a00226aae7940044dd50009aba1501521350423002001150401503f215335323232323333333574800846666ae68cdc39aab9d5004480008cccd55cfa8021282391999aab9f500425048233335573e6ae89401494cd4c8c8c8ccccccd5d200191999ab9a3370e6aae75400d2000233335573ea0064a09e46666aae7cd5d128021299a98239aba15005213505200115050250500570562504e0542504d2504d2504d2504d054135573ca00226ea8004d5d0a80390a99a981f9aba15007213504c330380020011504a150492504905004f04e2504604c2504525045250452504504c135744a00226aae7940044dd50009aba1501421350423002001150401503f215335303735742a026426a08460040022a0802a07e42a66a606a6ae85404884d4108c00800454100540fc854cd4c0dcd5d0a808909a82118010008a8200a81f90a99a981b9aba1501021350423002001150401503f2503f04604504404304204104003f03e03d03c03b2503303925032250322503225032039135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a016426a04c60220022a04842a66a60386ae85402c84d409cc0080045409454090854cd4cd40748c8c8c8ccccccd5d200211999ab9a3370ea004900211999aab9f500423502d01a2502c03323333573466e1d400d2002233335573ea00a46a05c03a4a05a06846666ae68cdc3a8022400046666aae7d40188d40bc074940b80d4940b40cc0c80c4940a8940a8940a8940a80c44d55cea80109aab9e5001137540026ae85402884d409cc0080045409454090854cd4cd40748c8c8c8ccccccd5d200211999ab9a3370ea004900211999aab9f500423502d01f2502c03323333573466e1d400d2002233335573ea00a46a05c03c4a05a06846666ae68cdc3a8022400046666aae7d40188d40bc080940b80d4940b40cc0c80c4940a8940a8940a8940a80c44d55cea80109aab9e5001137540026ae85402484d409cc0080045409454090940900ac0a80a40a009c9407c094940789407894078940780944d5d1280089aba25001135744a00226aae7940044dd50008009080089a80ea491e446174756d20636f756c646e277420626520646573657269616c697365640022222222222123333333333300100c00b00a009008007006005004003002222212333300100500400300222123300100300212220031222002122200112220031222002122200123232323333333574800846666ae68cdc39aab9d5004480008cccd55cfa8021280991999aab9f500425014233335573e6ae89401494cd4c02cd5d0a80390a99a99a807119191919191999999aba400623333573466e1d40092002233335573ea00c4a03e46666aae7d4018940808cccd55cfa8031281091999aab9f35744a00e4a66a602e6ae854028854cd4c060d5d0a80510a99a980c9aba1500a21350263330270030020011502415023150222502202902802702623333573466e1d400d2000233335573ea00e4a04046666aae7cd5d128041299a980b9aba150092135023302500115021250210280272501f0250242501d2501d2501d2501d024135573aa00826ae8940044d5d1280089aab9e5001137540026ae85401c84d4060cc05800800454058540549405407006c06894048060940449404494044940440604d5d1280089aab9e50011375400246666666ae900049403494034940348d4038dd68011280680a11919191999999aba400423333573466e1d40092002233335573ea0084a02246666aae7cd5d128029299a98049aba1500621350143017001150122501201901823333573466e1d400d2000233335573ea00a4a02446666aae7cd5d128031299a98051aba1500721350153019001150132501301a019250110170162500f2500f2500f2500f016135573aa00426aae7940044dd500091999999aba40012500b2500b2500b2500b23500c375c0040242446464646666666ae900108cccd5cd19b875002480008cccd55cfa8021280811999aab9f35744a00a4a66a60126ae85401884d404cd404c004540449404406005c8cccd5cd19b875003480088cccd55cfa80291a80928089280880c1280800b00a9280712807128071280700a89aab9d5002135573ca00226ea80044488c00800494ccd4d400488880084d40352411e47616d65206f757470757420646f65736e2774206861766520646174756d0021001213500e49012647616d65206f757470757420646f65736e2774206861766520646174756d20696e6c696e65640011220021221223300100400311221233001003002253353500122335002235007001250062100113500949012d4e6f205075624b65792063726564656e7469616c7320657869737420666f72207468697320616464726573732e002212330010030021212230020031122001212230020032221223330010050040032122300200321223001003123263200333573800200693090008891918008009119801980100100081" @@ -645,10 +651,22 @@ referenceScriptToApiPlutusScriptWitness :: Api.S.ScriptWitness witctx ApiEra referenceScriptToApiPlutusScriptWitness r s = let apiV = singPlutusVersionToApi (scriptVersion s) - in Api.PlutusScriptWitness - (case apiV of Api.PlutusScriptV1 -> Api.PlutusScriptV1InConway; Api.PlutusScriptV2 -> Api.PlutusScriptV2InConway; Api.PlutusScriptV3 -> Api.PlutusScriptV3InConway) - apiV - (Api.S.PReferenceScript (txOutRefToApi r) (Just (scriptApiHash s))) + in case apiV of + Api.PlutusScriptV1 -> + Api.PlutusScriptWitness + Api.PlutusScriptV1InConway + apiV + (Api.S.PReferenceScript (txOutRefToApi r)) + Api.PlutusScriptV2 -> + Api.PlutusScriptWitness + Api.PlutusScriptV2InConway + apiV + (Api.S.PReferenceScript (txOutRefToApi r)) + Api.PlutusScriptV3 -> + Api.PlutusScriptWitness + Api.PlutusScriptV3InConway + apiV + (Api.S.PReferenceScript (txOutRefToApi r)) scriptSize :: GYAnyScript -> Int scriptSize s = anyScriptToApiScriptInEra s & Api.toShelleyScript & originalBytesSize -- Maybe we could have done it a simpler way but this is how it script size is actually determined inside ledger codebase. @@ -717,5 +735,8 @@ anyScriptToApiScriptInEra (GYPlutusScript s@(GYScript v _ _)) = Api.ScriptInEra Api.PlutusScriptV3 -> Api.PlutusScriptV3InConway scriptToApiScript :: GYScript v -> Api.Script (PlutusVersionToApi v) - scriptToApiScript (GYScript v' api _) = Api.PlutusScript (singPlutusVersionToApi v') api + scriptToApiScript (GYScript (singPlutusVersionToApi -> v') api _) = case v' of + Api.PlutusScriptV1 -> Api.PlutusScript v' api + Api.PlutusScriptV2 -> Api.PlutusScript v' api + Api.PlutusScriptV3 -> Api.PlutusScript v' api anyScriptToApiScriptInEra (GYSimpleScript s) = Api.ScriptInEra Api.SimpleScriptInConway (Api.SimpleScript $ simpleScriptToApi s) diff --git a/src/GeniusYield/Types/TxBody.hs b/src/GeniusYield/Types/TxBody.hs index 6eed7d14..01b60715 100644 --- a/src/GeniusYield/Types/TxBody.hs +++ b/src/GeniusYield/Types/TxBody.hs @@ -214,9 +214,7 @@ txBodyReqSignatories body = case Api.txExtraKeyWits $ txBodyToApiTxBodyContent b -- | Returns the mint 'GYValue' of the given 'GYTxBody'. txBodyMintValue :: GYTxBody -> GYValue -txBodyMintValue body = case Api.txMintValue $ txBodyToApiTxBodyContent body of - Api.TxMintNone -> mempty - Api.TxMintValue _ v _ -> valueFromApi v +txBodyMintValue body = valueFromApi $ Api.txMintValueToValue $ Api.txMintValue $ txBodyToApiTxBodyContent body -- | Returns the validity range of the given 'GYTxBody'. txBodyValidityRange :: GYTxBody -> (Maybe GYSlot, Maybe GYSlot) diff --git a/src/GeniusYield/Types/TxOut.hs b/src/GeniusYield/Types/TxOut.hs index aaee4a72..5b79b53a 100644 --- a/src/GeniusYield/Types/TxOut.hs +++ b/src/GeniusYield/Types/TxOut.hs @@ -83,13 +83,16 @@ txOutToApi (GYTxOut addr v md mrs) = resolveOutputScript (GYSimpleScript s) = Api.ScriptInAnyLang Api.SimpleScriptLanguage (Api.SimpleScript $ simpleScriptToApi s) resolveOutputScript (GYPlutusScript s) = let version = singPlutusVersionToApi $ scriptVersion s - in Api.ScriptInAnyLang (Api.PlutusScriptLanguage version) (Api.PlutusScript version (scriptToApi s)) + in case version of + Api.PlutusScriptV1 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage version) (Api.PlutusScript version (scriptToApi s)) + Api.PlutusScriptV2 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage version) (Api.PlutusScript version (scriptToApi s)) + Api.PlutusScriptV3 -> Api.ScriptInAnyLang (Api.PlutusScriptLanguage version) (Api.PlutusScript version (scriptToApi s)) mkDatum :: Maybe (GYDatum, GYTxOutUseInlineDatum v) -> Api.TxOutDatum Api.CtxTx ApiEra mkDatum Nothing = Api.TxOutDatumNone mkDatum (Just (d, di)) | di' = Api.TxOutDatumInline Api.BabbageEraOnwardsConway d' - | otherwise = Api.TxOutDatumInTx Api.AlonzoEraOnwardsConway d' + | otherwise = Api.TxOutSupplementalDatum Api.AlonzoEraOnwardsConway d' where d' = datumToApi' d diff --git a/src/GeniusYield/Types/UTxO.hs b/src/GeniusYield/Types/UTxO.hs index 7630a883..8737172e 100644 --- a/src/GeniusYield/Types/UTxO.hs +++ b/src/GeniusYield/Types/UTxO.hs @@ -153,7 +153,7 @@ utxoFromApi txIn (Api.TxOut a v d s) = f :: Api.TxOutDatum Api.CtxTx ApiEra -> GYOutDatum f Api.TxOutDatumNone = GYOutDatumNone f (Api.TxOutDatumHash _ hash) = GYOutDatumHash $ datumHashFromApi hash - f (Api.TxOutDatumInTx _ sd) = GYOutDatumHash . hashDatum $ datumFromApi' sd + f (Api.TxOutSupplementalDatum _ sd) = GYOutDatumHash . hashDatum $ datumFromApi' sd f (Api.TxOutDatumInline _ sd) = GYOutDatumInline $ datumFromApi' sd utxoFromApi' :: Api.TxIn -> Api.TxOut Api.CtxUTxO era -> GYUTxO diff --git a/src/GeniusYield/Types/Value.hs b/src/GeniusYield/Types/Value.hs index 850395c6..a0b34c6a 100644 --- a/src/GeniusYield/Types/Value.hs +++ b/src/GeniusYield/Types/Value.hs @@ -83,6 +83,7 @@ module GeniusYield.Types.Value ( tokenNameFromBS, tokenNameToPlutus, tokenNameFromPlutus, + tokenNameToApi, tokenNameFromHex, unsafeTokenNameFromHex, makeAssetClass, @@ -96,6 +97,7 @@ import Data.Aeson.KeyMap qualified as KM import Data.Csv qualified as Csv import Data.List (intercalate) import Data.Scientific qualified as SC +import GHC.IsList qualified (toList) import GeniusYield.Imports import PlutusTx.Builtins (fromBuiltin, toBuiltin) @@ -226,7 +228,7 @@ valueFromApi :: Api.Value -> GYValue valueFromApi v = valueFromList [ (assetClassFromApi ac, n) - | (ac, Api.Quantity n) <- Api.valueToList v + | (ac, Api.Quantity n) <- GHC.IsList.toList v ] valueFromApiTxOutValue :: Api.TxOutValue era -> GYValue From 21cda6a59edf521c4740e45c64da1ba279304780 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Sun, 23 Feb 2025 19:59:05 +0530 Subject: [PATCH 3/9] docs(#408): update doctests --- src/GeniusYield/Types/Tx.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GeniusYield/Types/Tx.hs b/src/GeniusYield/Types/Tx.hs index 2f80dcc4..4fa6fa13 100644 --- a/src/GeniusYield/Types/Tx.hs +++ b/src/GeniusYield/Types/Tx.hs @@ -104,7 +104,7 @@ instance IsString GYTx where {- | >>> txToApi <$> (Aeson.fromJSON @GYTx $ Aeson.toJSON tx) -Success (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AuxiliaryDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) +Success (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AlonzoTxAuxDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) -} instance Aeson.FromJSON GYTx where parseJSON = Aeson.withText "GYTx" $ \t -> do @@ -150,7 +150,7 @@ instance Printf.PrintfArg GYTx where {- | >>> txToApi <$> txFromHex (Text.unpack $ TE.decodeUtf8 txHexBS) -Just (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AuxiliaryDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) +Just (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AlonzoTxAuxDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) -} txFromHex :: String -> Maybe GYTx txFromHex s = rightToMaybe $ txFromHexE s @@ -161,7 +161,7 @@ txFromHexE s = txFromHexBS $ BS8.pack s {- | >>> txToApi <$> txFromHexBS txHexBS -Right (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AuxiliaryDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) +Right (ShelleyTx ShelleyBasedEraConway (AlonzoTx {body = TxBodyConstr ConwayTxBodyRaw {ctbrSpendInputs = fromList [TxIn (TxId {unTxId = SafeHash "677b32cca6387836fc53ec35b4060800893c22edc1e1d20ff74c42e67aca1e21"}) (TxIx {unTxIx = 1}),TxIn (TxId {unTxId = SafeHash "f13e16fafb7df5fbdff775d949a28edd586a3e0426739bc782c9f5d82ecdb70a"}) (TxIx {unTxIx = 0})], ctbrCollateralInputs = fromList [TxIn (TxId {unTxId = SafeHash "c816519a759e300acc16d1e2812500392c85ae6d5af886dd154c9084a610a120"}) (TxIx {unTxIx = 0})], ctbrReferenceInputs = fromList [TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 0}),TxIn (TxId {unTxId = SafeHash "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624"}) (TxIx {unTxIx = 1})], ctbrOutputs = StrictSeq {fromStrict = fromList [Sized {sizedValue = (Addr Testnet (ScriptHashObj (ScriptHash "44376a5f63342097a4f20401088c62da272639e60644a9ec1d70f444")) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 103400000) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])])),DatumHash (SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"),SNothing), sizedSize = 167},Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 997296677) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}]}, ctbrCollateralReturn = SJust (Sized {sizedValue = (Addr Testnet (KeyHashObj (KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"})) (StakeRefBase (KeyHashObj (KeyHash {unKeyHash = "1d3554e12c8aed91818a0600a57bea9d50e509beda567387d1247315"}))),MaryValue (Coin 4486868) (MultiAsset (fromList [])),NoDatum,SNothing), sizedSize = 65}), ctbrTotalCollateral = SJust (Coin 513132), ctbrCerts = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrWithdrawals = Withdrawals {unWithdrawals = fromList []}, ctbrTxfee = Coin 342088, ctbrVldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, ctbrReqSignerHashes = fromList [], ctbrMint = MultiAsset (fromList [(PolicyID {policyID = ScriptHash "53827a77e4ed3d5c211706708c0aa9b9a3be19db901b1cbf7fa515b8"},fromList [("b7f1e540a130b7d9010c9ad87f284d914ab9753ae846c9b5221436086efe5f01",1)])]), ctbrScriptIntegrityHash = SJust (SafeHash "a23cebd1aef6f5c9a3bb5c4469bc0b5c316a7090c6306109ebe6ce1d088b3fe5"), ctbrAuxDataHash = SJust (AuxiliaryDataHash {unsafeAuxiliaryDataHash = SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"}), ctbrTxNetworkId = SNothing, ctbrVotingProcedures = VotingProcedures {unVotingProcedures = fromList []}, ctbrProposalProcedures = OSet {osSSeq = StrictSeq {fromStrict = fromList []}, osSet = fromList []}, ctbrCurrentTreasuryValue = SNothing, ctbrTreasuryDonation = Coin 0} (blake2b_256: SafeHash "dfd37a5f16ecb4203ff240e0c426890f8c400e1ddfbdf1accaeb8cc348fa3b5c"), wits = AlonzoTxWitsRaw {atwrAddrTxWits = fromList [WitVKeyInternal {wvkKey = VKey (VerKeyEd25519DSIGN "e8807993d91ac035385bea2cc7577876d1ed3ca05b78ac0fc1be65b741c61957"), wvkSig = SignedDSIGN (SigEd25519DSIGN "9a37152ba1fe5b8a2026eca077d1e154795812bdc8008c43cd6028d08485062f91a980f88f0739cfb1763117debe6673f0fc0ffb2362659b89449a1b30a49d08"), wvkKeyHash = KeyHash {unKeyHash = "99f8985db8b9076f61ecec59eca67e30224dc20afb40491aecc6aa97"}, wvkBytes = "\130X \232\128y\147\217\SUB\192\&58[\234,\199Wxv\209\237<\160[x\172\SI\193\190e\183A\198\EMWX@\154\&7\NAK+\161\254[\138 &\236\160w\209\225TyX\DC2\189\200\NUL\140C\205`(\208\132\133\ACK/\145\169\128\248\143\a9\207\177v1\ETB\222\190fs\240\252\SI\251#be\155\137D\154\ESC0\164\157\b"}], atwrBootAddrTxWits = fromList [], atwrScriptTxWits = fromList [], atwrDatsTxWits = TxDatsConstr TxDatsRaw {unTxDatsRaw = fromList [(SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575",DataConstr Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151",Constr 0 [Constr 0 [B "\153\248\152]\184\185\aoa\236\236Y\236\166~0\"M\194\n\251@I\SUB\236\198\170\151"],Constr 0 [Constr 0 [Constr 0 [B "\GS5T\225,\138\237\145\129\138\ACK\NUL\165{\234\157P\229\t\190\218Vs\135\209$s\NAK"]]]],Constr 0 [B "",B ""],I 100000000,I 100000000,Constr 0 [B "\198\230[\167\135\139/\142\160\173\&9(}>/\210V\220\\A`\252\EM\189\244\196\216~",B "tGENS"],Constr 0 [I 1,I 1],B "\183\241\229@\161\&0\183\217\SOH\f\154\216\DEL(M\145J\185u:\232F\201\181\"\DC46\bn\254_\SOH",Constr 1 [],Constr 1 [],I 0,I 1000000,I 1000000,Constr 0 [I 1000000,I 300000,I 0],I 0] (blake2b_256: SafeHash "7caffd4aa6d4942ad42cf8d109feee13994ab5dc3bd657a571b70d679538d575"))]} (blake2b_256: SafeHash "f9be8c20a8c55a5c744f293db49f89505a82a2ce89ad86479f95983e044b4fe9"), atwrRdmrsTxWits = RedeemersConstr fromList [(ConwayMinting (AsIx {unAsIx = 0}),(DataConstr Constr 0 [Constr 0 [Constr 0 [B "g{2\204\166\&8x6\252S\236\&5\180\ACK\b\NUL\137<\"\237\193\225\210\SI\247LB\230z\202\RS!"],I 1]] (blake2b_256: SafeHash "63392b71d2cdffc553e10e7804c08897c9eb5a2ca6d83e647bf523796ca35741"),WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 726550, exUnitsSteps' = 231770400}}))] (blake2b_256: SafeHash "df0708c4c44f7ff380ded920ebe4e51be34b100e9235df0294cb64948c047c0f")} (blake2b_256: SafeHash "0a0052247e0995d8010860a20560f5cd9faf78b057fa6cd1f367fd900f8248fa"), isValid = IsValid True, auxiliaryData = SJust (AlonzoTxAuxDataConstr AlonzoTxAuxDataRaw {atadrMetadata = fromList [(674,Map [(S "msg",List [S "GeniusYield: Order placed"])])], atadrTimelock = StrictSeq {fromStrict = fromList []}, atadrPlutus = fromList []} (blake2b_256: SafeHash "37c0555635ab7e45ec39bd8feb873080d036c9a67c4cdd0c85e1c5291b0482f2"))})) -} txFromHexBS :: BS.ByteString -> Either String GYTx txFromHexBS bs = BS16.decode bs >>= txFromCBOR From a14e9503d8346e02c0fee0fd6e9becd5feba0dbc Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Sun, 23 Feb 2025 21:13:03 +0530 Subject: [PATCH 4/9] feat(#408): use custom cardano-api fork --- cabal.project | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cabal.project b/cabal.project index 4a29a18e..fe3db2bf 100644 --- a/cabal.project +++ b/cabal.project @@ -27,23 +27,32 @@ test-show-details: direct package cardano-crypto-praos flags: -external-libsodium-vrf --- TODO: Temporary, track: https://github.com/maestro-org/haskell-sdk/pull/74. source-repository-package type: git - location: https://github.com/sourabhxyz/haskell-sdk - tag: 8367d46936a916d4179ded3148a232a3931c7a62 - --sha256: FIXME: + location: https://github.com/maestro-org/haskell-sdk + tag: 3e39a6d485d7c6f98222b1ca58aed2fb45e5ff27 + --sha256: sha256-plfrSgirKf7WGESYvEBqBkR1s673Qd0ZhGs0KzGfOig= -- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/72) source-repository-package type: git location: https://github.com/sourabhxyz/clb tag: 1b084647dc9118520c1cc615cf2fa7c3dd8a394e - --sha256: FIXME: + --sha256: sha256-QliJng5PmJIRJd/l644T0zxBBOKhuMkIgeu1B5ymfVU= subdir: clb emulator +-- TODO: Temporary, remove once we are on 10.9 or above. Fix relates to issue: https://github.com/IntersectMBO/cardano-api/issues/714. +source-repository-package + type: git + location: https://github.com/sourabhxyz/cardano-api + tag: 14674d6b099e8fc36e5044e206bfc32164f75cee + --sha256: sha256-Qr4rv9bLz+wJdICYjxDVnnzgsVwx+wsU+tSFwDYr/kE= + subdir: + cardano-api + cardano-api-gen + -- Using latest version which is not on CHaP. source-repository-package type: git From 20b88ef07d68127441514a67a3b8c16fbdc3e102 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 24 Feb 2025 09:47:02 +0530 Subject: [PATCH 5/9] feat(#408): update fixtures --- fixtures/script-env-v1.json | 2 +- fixtures/script-env-v2.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fixtures/script-env-v1.json b/fixtures/script-env-v1.json index 791a6043..855d2fe1 100644 --- a/fixtures/script-env-v1.json +++ b/fixtures/script-env-v1.json @@ -1,5 +1,5 @@ { "type": "PlutusScriptV1", "description": "", - "cborHex": "484701000022200101" + "cborHex": "4701000022200101" } diff --git a/fixtures/script-env-v2.json b/fixtures/script-env-v2.json index da5cd504..06481efa 100644 --- a/fixtures/script-env-v2.json +++ b/fixtures/script-env-v2.json @@ -1,5 +1,5 @@ { "type": "PlutusScriptV2", "description": "", - "cborHex": "484701000022200101" + "cborHex": "4701000022200101" } From e69c4dbf11ec1730c4281a65cdf54b81976674a3 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 24 Feb 2025 16:05:46 +0530 Subject: [PATCH 6/9] feat(#408): add method to fetch proposals --- src/GeniusYield/GYConfig.hs | 12 +- src/GeniusYield/Providers/Blockfrost.hs | 5 + src/GeniusYield/Providers/Maestro.hs | 5 + src/GeniusYield/Providers/Node.hs | 6 + src/GeniusYield/Providers/Ogmios.hs | 461 ++++++++++++++++------- src/GeniusYield/Test/Clb.hs | 2 + src/GeniusYield/Test/Privnet/Ctx.hs | 1 + src/GeniusYield/TxBuilder/IO/Query.hs | 5 + src/GeniusYield/TxBuilder/Query/Class.hs | 17 +- src/GeniusYield/Types/Address.hs | 4 + src/GeniusYield/Types/Governance.hs | 65 +++- src/GeniusYield/Types/Providers.hs | 7 +- 12 files changed, 451 insertions(+), 139 deletions(-) diff --git a/src/GeniusYield/GYConfig.hs b/src/GeniusYield/GYConfig.hs index b7b05c34..e5bca076 100644 --- a/src/GeniusYield/GYConfig.hs +++ b/src/GeniusYield/GYConfig.hs @@ -40,6 +40,8 @@ import GeniusYield.Imports import GeniusYield.Providers.Blockfrost qualified as Blockfrost -- import qualified GeniusYield.Providers.CachedQueryUTxOs as CachedQuery + +import Data.Sequence qualified as Seq import GeniusYield.Providers.Kupo qualified as KupoApi import GeniusYield.Providers.Maestro qualified as MaestroApi import GeniusYield.Providers.Node (nodeGetDRepState, nodeGetDRepsState, nodeStakeAddressInfo) @@ -168,7 +170,7 @@ withCfgProviders ns f = do - (gyGetParameters, gySlotActions', gyQueryUTxO', gyLookupDatum, gySubmitTx, gyAwaitTxConfirmed, gyGetStakeAddressInfo, gyGetDRepState, gyGetDRepsState, gyGetStakePools, gyGetConstitution) <- case cfgCoreProvider of + (gyGetParameters, gySlotActions', gyQueryUTxO', gyLookupDatum, gySubmitTx, gyAwaitTxConfirmed, gyGetStakeAddressInfo, gyGetDRepState, gyGetDRepsState, gyGetStakePools, gyGetConstitution, gyGetProposals) <- case cfgCoreProvider of GYNodeKupo path kupoUrl -> do let info = nodeConnectInfo path cfgNetworkId kEnv <- KupoApi.newKupoApiEnv $ Text.unpack kupoUrl @@ -186,6 +188,7 @@ withCfgProviders , nodeGetDRepsState info , Node.nodeStakePools info , Node.nodeConstitution info + , Node.nodeProposals info ) GYOgmiosKupo ogmiosUrl kupoUrl -> do oEnv <- OgmiosApi.newOgmiosApiEnv $ Text.unpack ogmiosUrl @@ -209,6 +212,7 @@ withCfgProviders , OgmiosApi.ogmiosGetDRepsState oEnv , OgmiosApi.ogmiosStakePools oEnv , OgmiosApi.ogmiosConstitution oEnv + , OgmiosApi.ogmiosProposals oEnv ) GYMaestro (Confidential apiToken) turboSubmit -> do maestroApiEnv <- MaestroApi.networkIdToMaestroEnv apiToken cfgNetworkId @@ -231,6 +235,7 @@ withCfgProviders , MaestroApi.maestroDRepsState maestroApiEnv , MaestroApi.maestroStakePools maestroApiEnv , MaestroApi.maestroConstitution maestroApiEnv + , MaestroApi.maestroProposals maestroApiEnv ) GYBlockfrost (Confidential key) -> do let proj = Blockfrost.networkIdToProject cfgNetworkId key @@ -253,6 +258,7 @@ withCfgProviders , Blockfrost.blockfrostDRepsState proj , Blockfrost.blockfrostStakePools proj , Blockfrost.blockfrostConstitution proj + , Blockfrost.blockfrostProposals proj ) bracket (mkLogEnv ns cfgLogging) closeScribes $ \logEnv -> do @@ -300,6 +306,7 @@ logTiming providers@GYProviders {..} = , gyLog' = gyLog' , gyGetStakePools = gyGetStakePools' , gyGetConstitution = gyGetConstitution' + , gyGetProposals = gyGetProposals' } where wrap :: String -> IO a -> IO a @@ -375,6 +382,9 @@ logTiming providers@GYProviders {..} = gyGetConstitution' :: IO GYConstitution gyGetConstitution' = wrap "gyGetConstitution" gyGetConstitution + gyGetProposals' :: Set GYGovActionId -> IO (Seq.Seq GYGovActionState) + gyGetProposals' = wrap "gyGetProposals" . gyGetProposals + duration :: IO a -> IO (a, NominalDiffTime) duration m = do start <- getCurrentTime diff --git a/src/GeniusYield/Providers/Blockfrost.hs b/src/GeniusYield/Providers/Blockfrost.hs index 8831e132..eddeaca6 100644 --- a/src/GeniusYield/Providers/Blockfrost.hs +++ b/src/GeniusYield/Providers/Blockfrost.hs @@ -13,6 +13,7 @@ module GeniusYield.Providers.Blockfrost ( blockfrostDRepState, blockfrostDRepsState, blockfrostConstitution, + blockfrostProposals, networkIdToProject, ) where @@ -40,6 +41,7 @@ import Data.Either.Combinators (maybeToRight) import Data.Foldable (fold) import Data.Map.Strict qualified as Map import Data.Maybe (fromJust) +import Data.Sequence qualified as Seq import Data.Set qualified as Set import Data.Text qualified as Text import Data.Text.Encoding qualified as Text @@ -599,6 +601,9 @@ blockfrostDRepsState _p _cs = error "Blockfrost SDK does not support fetching th blockfrostConstitution :: Blockfrost.Project -> IO GYConstitution blockfrostConstitution = error "Blockfrost does not support fetching the constitution" +blockfrostProposals :: Blockfrost.Project -> Set GYGovActionId -> IO (Seq.Seq GYGovActionState) +blockfrostProposals _p _actionIds = error "Blockfrost SDK does not support fetching the proposals" + ------------------------------------------------------------------------------- -- Auxiliary functions ------------------------------------------------------------------------------- diff --git a/src/GeniusYield/Providers/Maestro.hs b/src/GeniusYield/Providers/Maestro.hs index 9e22f10f..e8e8ae98 100644 --- a/src/GeniusYield/Providers/Maestro.hs +++ b/src/GeniusYield/Providers/Maestro.hs @@ -24,6 +24,7 @@ module GeniusYield.Providers.Maestro ( maestroDRepState, maestroDRepsState, maestroConstitution, + maestroProposals, ) where import Cardano.Api qualified as Api @@ -46,6 +47,7 @@ import Data.Either.Combinators (maybeToRight) import Data.Int (Int64) import Data.Map.Strict qualified as M import Data.Maybe (fromJust) +import Data.Sequence qualified as Seq import Data.Set qualified as Set import Data.Text qualified as Text import Data.Time qualified as Time @@ -667,3 +669,6 @@ maestroDRepsState _p _cs = error "Maestro does not support fetching the DReps st maestroConstitution :: Maestro.MaestroEnv 'Maestro.V1 -> IO GYConstitution maestroConstitution = error "Maestro does not support fetching the constitution" + +maestroProposals :: Maestro.MaestroEnv 'Maestro.V1 -> Set GYGovActionId -> IO (Seq.Seq GYGovActionState) +maestroProposals _p _actionIds = error "Maestro does not support fetching the proposals" diff --git a/src/GeniusYield/Providers/Node.hs b/src/GeniusYield/Providers/Node.hs index 145fb799..d7c7ca25 100644 --- a/src/GeniusYield/Providers/Node.hs +++ b/src/GeniusYield/Providers/Node.hs @@ -16,6 +16,7 @@ module GeniusYield.Providers.Node ( nodeGetDRepState, nodeGetDRepsState, nodeConstitution, + nodeProposals, -- * Auxiliary networkIdToLocalNodeConnectInfo, @@ -28,6 +29,7 @@ import Cardano.Slotting.Time (SystemStart) import Control.Exception (throwIO) import Data.Map.Strict qualified as Map import Data.Maybe (listToMaybe) +import Data.Sequence qualified as Seq import Data.Set qualified as Set import Data.Text qualified as Txt import GeniusYield.CardanoApi.Query @@ -90,6 +92,10 @@ nodeGetDRepsState info dreps = do nodeConstitution :: Api.LocalNodeConnectInfo -> IO GYConstitution nodeConstitution info = constitutionFromLedger <$> queryConwayEra info Api.QueryConstitution +nodeProposals :: Api.LocalNodeConnectInfo -> Set.Set GYGovActionId -> IO (Seq.Seq GYGovActionState) +nodeProposals info (Set.map govActionIdToLedger -> proposals) = do + fmap govActionStateFromLedger <$> queryConwayEra info (Api.QueryProposals proposals) + nodeStakePools :: Api.LocalNodeConnectInfo -> IO (Set.Set Api.S.PoolId) nodeStakePools info = queryConwayEra info Api.QueryStakePools diff --git a/src/GeniusYield/Providers/Ogmios.hs b/src/GeniusYield/Providers/Ogmios.hs index 9aeaa8f4..e0be53cf 100644 --- a/src/GeniusYield/Providers/Ogmios.hs +++ b/src/GeniusYield/Providers/Ogmios.hs @@ -20,6 +20,7 @@ module GeniusYield.Providers.Ogmios ( ogmiosStartTime, ogmiosEraSummaries, ogmiosConstitution, + ogmiosProposals, ) where import Cardano.Api qualified as Api @@ -31,17 +32,21 @@ import Cardano.Ledger.Conway.PParams ( ConwayPParams (..), THKD (..), ) +import Cardano.Ledger.Core qualified as Ledger +import Cardano.Ledger.HKD (HKD, HKDFunctor (..)) import Cardano.Ledger.Plutus qualified as Ledger import Cardano.Slotting.Slot qualified as CSlot import Cardano.Slotting.Time qualified as CTime import Control.Monad ((<=<)) import Data.Aeson (Value (Null), object, withArray, withObject, (.:), (.:?), (.=)) +import Data.Aeson.Types qualified as Aeson import Data.Map.Strict qualified as Map import Data.Maybe (fromJust, listToMaybe) +import Data.Sequence qualified as Seq import Data.Set qualified as Set import Data.Text qualified as Text import Data.Time.Clock.POSIX (posixSecondsToUTCTime) -import Data.Word (Word64) +import Data.Word (Word16, Word32, Word64) import Deriving.Aeson import GHC.Int (Int64) import GeniusYield.Imports @@ -53,6 +58,7 @@ import GeniusYield.Providers.Common ( import GeniusYield.Types hiding (poolId) import Maestro.Types.V1 (AsAda (..), AsBytes, AsLovelace (..), CostModel, EpochNo, EpochSize, EpochSlotLength, EraBound, LowerFirst, MaestroRational, MemoryCpuWith, MinFeeReferenceScripts, ProtocolParametersUpdateStakePool, ProtocolVersion) import Maestro.Types.V1 qualified as Maestro +import Ouroboros.Consensus.Cardano.Block (StandardConway) import Ouroboros.Consensus.HardFork.History qualified as Ouroboros import Servant.API ( JSON, @@ -300,6 +306,127 @@ data OgmiosConstitutionResponse = OgmiosConstitutionResponse deriving stock (Show, Generic) deriving anyclass FromJSON +constitutionFromOgmios :: OgmiosConstitutionResponse -> GYConstitution +constitutionFromOgmios OgmiosConstitutionResponse {..} = GYConstitution {constitutionAnchor = anchorFromOgmiosMetadata metadata, constitutionScript = asHashHash <$> guardrails} + +newtype OgmiosProposals = OgmiosProposals (Set GYGovActionId) + +instance ToJSONRPC OgmiosProposals where + toMethod = const "queryLedgerState/governanceProposals" + toParams (OgmiosProposals proposals) = Just $ object ["proposals" .= Set.map encodeProposal proposals] + where + encodeProposal govActionId = + object ["transaction" .= object ["id" .= gaidTxId govActionId], "index" .= gaidIx govActionId] + +data OgmiosProposalResponse = OgmiosProposalResponse + { oprProposal :: GYGovActionId + , oprDeposit :: AsAda + , oprReturnAccount :: GYStakeAddressBech32 + , oprMetadata :: OgmiosMetadata + , oprAction :: GYGovAction + , oprSince :: AsEpoch + , oprUntil :: AsEpoch + , oprVotes :: [OgmiosVote] + } + +instance FromJSON OgmiosProposalResponse where + parseJSON = withObject "OgmiosProposalResponse" $ \o -> do + oprProposal <- do + oproposal <- o .: "proposal" + parseGovActionId oproposal + oprDeposit <- o .: "deposit" + oprReturnAccount <- o .: "returnAccount" + oprMetadata <- o .: "metadata" + oprAction <- do + obj <- o .: "action" + parseAction obj + + oprSince <- o .: "since" + oprUntil <- o .: "until" + oprVotes <- o .: "votes" + pure OgmiosProposalResponse {..} + where + parseAction :: Aeson.Object -> Aeson.Parser GYGovAction + parseAction obj = do + actionType <- obj .: "type" + case actionType of + "information" -> pure InfoAction + "noConfidence" -> do + mancestor <- parseAncestor obj + pure $ NoConfidence mancestor + "constitution" -> do + mancestor <- parseAncestor obj + ogmiosConstitutionResp <- parseJSON @OgmiosConstitutionResponse (Aeson.Object obj) + pure $ NewConstitution mancestor (constitutionFromOgmios ogmiosConstitutionResp) + "constitutionalCommittee" -> do + mancestor <- parseAncestor obj + undefined + "treasuryWithdrawals" -> do + withdrawals :: Map GYStakeAddressBech32 AsAda <- obj .: "withdrawals" + guardrails :: Maybe AsHash <- obj .: "guardrails" + pure $ TreasuryWithdrawals (Map.mapKeys stakeAddressFromBech32 $ Map.map (asLovelaceLovelace . asAdaAda) withdrawals) (asHashHash <$> guardrails) + "hardForkInitiation" -> do + mancestor <- parseAncestor obj + version <- obj .: "version" >>= parseJSON @ProtocolVersion + pure $ HardForkInitiation mancestor (protocolVersionFromOgmios "parseJSON (ogmiosProposalResponse)" version) + "protocolParametersUpdate" -> do + mancestor <- parseAncestor obj + guardrails :: Maybe AsHash <- obj .: "guardrails" + pparamsUpd :: ProtocolParametersM <- obj .: "parameters" + pure $ ParameterChange mancestor (Ledger.PParamsUpdate $ pparamsFromOgmios "parseJSON (OgmiosProposalResponse)" pparamsUpd) (asHashHash <$> guardrails) + anyOther -> fail $ "Invalid action type: " <> show anyOther + parseAncestor obj = do + ancestor <- obj .:? "ancestor" + case ancestor of + Nothing -> pure Nothing + Just a -> do + ancestorGovActionId <- parseGovActionId a + pure $ Just ancestorGovActionId + parseGovActionId :: Aeson.Object -> Aeson.Parser GYGovActionId + parseGovActionId obj = do + GYGovActionId + <$> (obj .: "transaction" >>= (.: "id")) + <*> (obj .: "index") + +data OgmiosVoter = OgmiosVoterCommittee !(GYCredential 'GYKeyRoleHotCommittee) | OgmiosVoterDRep !(GYCredential 'GYKeyRoleDRep) | OgmiosVoterStakePool !GYStakePoolIdBech32 + +data OgmiosVote = OgmiosVote + { ovVoter :: !OgmiosVoter + , ovVote :: !GYVote + } + +instance FromJSON OgmiosVote where + parseJSON = + withObject "OgmiosVote" $ + \o -> do + ovVoter <- do + issuer <- o .: "issuer" + voterRole <- issuer .: "role" + case voterRole of + "delegateRepresentative" -> do + cred <- getCredential issuer + pure $ OgmiosVoterDRep cred + "committee" -> do + cred <- getCredential issuer + pure $ OgmiosVoterCommittee cred + "stakePoolOperator" -> do + poolId <- issuer .: "id" + pure $ OgmiosVoterStakePool poolId + anyOther -> fail $ "Invalid voter role: " <> show anyOther + voteResult <- o .: "vote" + ovVote <- case voteResult of + "yes" -> pure Yes + "no" -> pure No + "abstain" -> pure Abstain + anyOther -> fail $ "Invalid vote result: " <> show anyOther + pure OgmiosVote {..} + where + getCredential o = do + credType <- o .: "from" + case credType of + OgCredTypeVerificationKey -> GYCredentialByKey <$> o .: "id" + OgCredTypeScript -> GYCredentialByScript <$> o .: "id" + submitTx :: OgmiosRequest GYTx -> ClientM (OgmiosResponse TxSubmissionResponse) protocolParams :: OgmiosRequest OgmiosPP -> ClientM (OgmiosResponse ProtocolParameters) tip :: OgmiosRequest OgmiosTip -> ClientM (OgmiosResponse OgmiosTipResponse) @@ -309,6 +436,7 @@ stakeAddressInfo :: OgmiosRequest GYStakeAddress -> ClientM (OgmiosResponse (Map startTime :: OgmiosRequest OgmiosStartTime -> ClientM (OgmiosResponse GYTime) eraSummaries :: OgmiosRequest OgmiosEraSummaries -> ClientM (OgmiosResponse [EraSummary]) constitution :: OgmiosRequest OgmiosConstitution -> ClientM (OgmiosResponse OgmiosConstitutionResponse) +proposals :: OgmiosRequest OgmiosProposals -> ClientM (OgmiosResponse [OgmiosProposalResponse]) type OgmiosApi = ReqBody '[JSON] (OgmiosRequest GYTx) :> Post '[JSON] (OgmiosResponse TxSubmissionResponse) @@ -320,8 +448,9 @@ type OgmiosApi = :<|> ReqBody '[JSON] (OgmiosRequest OgmiosStartTime) :> Post '[JSON] (OgmiosResponse GYTime) :<|> ReqBody '[JSON] (OgmiosRequest OgmiosEraSummaries) :> Post '[JSON] (OgmiosResponse [EraSummary]) :<|> ReqBody '[JSON] (OgmiosRequest OgmiosConstitution) :> Post '[JSON] (OgmiosResponse OgmiosConstitutionResponse) + :<|> ReqBody '[JSON] (OgmiosRequest OgmiosProposals) :> Post '[JSON] (OgmiosResponse [OgmiosProposalResponse]) -submitTx :<|> protocolParams :<|> tip :<|> stakePools :<|> drepState :<|> stakeAddressInfo :<|> startTime :<|> eraSummaries :<|> constitution = client @OgmiosApi Proxy +submitTx :<|> protocolParams :<|> tip :<|> stakePools :<|> drepState :<|> stakeAddressInfo :<|> startTime :<|> eraSummaries :<|> constitution :<|> proposals = client @OgmiosApi Proxy -- | Submit a transaction to the node via Ogmios. ogmiosSubmitTx :: OgmiosApiEnv -> GYSubmitTx @@ -384,145 +513,204 @@ data CostModels = CostModels deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "costModels", Rename "PlutusV1" "plutus:v1", Rename "PlutusV2" "plutus:v2", Rename "PlutusV3" "plutus:v3"]] CostModels -- | Protocol parameters. -data ProtocolParameters = ProtocolParameters - { protocolParametersCollateralPercentage :: !Natural - , protocolParametersConstitutionalCommitteeMaxTermLength :: !Natural - , protocolParametersConstitutionalCommitteeMinSize :: !Natural - , protocolParametersDelegateRepresentativeDeposit :: !AsAda - , protocolParametersDelegateRepresentativeMaxIdleTime :: !Natural - , protocolParametersDelegateRepresentativeVotingThresholds :: !DRepVotingThresholds - , protocolParametersDesiredNumberOfStakePools :: !Natural - , protocolParametersGovernanceActionDeposit :: !AsAda - , protocolParametersGovernanceActionLifetime :: !Natural - , protocolParametersMaxBlockBodySize :: !AsBytes - , protocolParametersMaxBlockHeaderSize :: !AsBytes - , protocolParametersMaxCollateralInputs :: !Natural - , protocolParametersMaxExecutionUnitsPerBlock :: !(MemoryCpuWith Natural) - , protocolParametersMaxExecutionUnitsPerTransaction :: !(MemoryCpuWith Natural) - , protocolParametersMaxReferenceScriptsSize :: !AsBytes - , protocolParametersMaxTransactionSize :: !AsBytes - , protocolParametersMaxValueSize :: !AsBytes - , protocolParametersMinFeeCoefficient :: !Natural - , protocolParametersMinFeeConstant :: !AsAda - , protocolParametersMinFeeReferenceScripts :: !MinFeeReferenceScripts - , protocolParametersMinStakePoolCost :: !AsAda - , protocolParametersMinUtxoDepositCoefficient :: !Natural - , protocolParametersMonetaryExpansion :: !MaestroRational - , protocolParametersPlutusCostModels :: !CostModels - , protocolParametersScriptExecutionPrices :: !(MemoryCpuWith MaestroRational) - , protocolParametersStakeCredentialDeposit :: !AsAda - , protocolParametersStakePoolDeposit :: !AsAda - , protocolParametersStakePoolPledgeInfluence :: !MaestroRational - , protocolParametersStakePoolRetirementEpochBound :: !EpochNo - , protocolParametersStakePoolVotingThresholds :: !StakePoolVotingThresholds - , protocolParametersTreasuryExpansion :: !MaestroRational - , protocolParametersVersion :: !ProtocolVersion +data ProtocolParametersHKD f = ProtocolParameters + { protocolParametersCollateralPercentage :: !(HKD f Natural) + , protocolParametersConstitutionalCommitteeMaxTermLength :: !(HKD f Natural) + , protocolParametersConstitutionalCommitteeMinSize :: !(HKD f Natural) + , protocolParametersDelegateRepresentativeDeposit :: !(HKD f AsAda) + , protocolParametersDelegateRepresentativeMaxIdleTime :: !(HKD f Natural) + , protocolParametersDelegateRepresentativeVotingThresholds :: !(HKD f DRepVotingThresholds) + , protocolParametersDesiredNumberOfStakePools :: !(HKD f Natural) + , protocolParametersGovernanceActionDeposit :: !(HKD f AsAda) + , protocolParametersGovernanceActionLifetime :: !(HKD f Natural) + , protocolParametersMaxBlockBodySize :: !(HKD f AsBytes) + , protocolParametersMaxBlockHeaderSize :: !(HKD f AsBytes) + , protocolParametersMaxCollateralInputs :: !(HKD f Natural) + , protocolParametersMaxExecutionUnitsPerBlock :: !(HKD f (MemoryCpuWith Natural)) + , protocolParametersMaxExecutionUnitsPerTransaction :: !(HKD f (MemoryCpuWith Natural)) + , protocolParametersMaxReferenceScriptsSize :: !(HKD f AsBytes) + , protocolParametersMaxTransactionSize :: !(HKD f AsBytes) + , protocolParametersMaxValueSize :: !(HKD f AsBytes) + , protocolParametersMinFeeCoefficient :: !(HKD f Natural) + , protocolParametersMinFeeConstant :: !(HKD f AsAda) + , protocolParametersMinFeeReferenceScripts :: !(HKD f MinFeeReferenceScripts) + , protocolParametersMinStakePoolCost :: !(HKD f AsAda) + , protocolParametersMinUtxoDepositCoefficient :: !(HKD f Natural) + , protocolParametersMonetaryExpansion :: !(HKD f MaestroRational) + , protocolParametersPlutusCostModels :: !(HKD f CostModels) + , protocolParametersScriptExecutionPrices :: !(HKD f (MemoryCpuWith MaestroRational)) + , protocolParametersStakeCredentialDeposit :: !(HKD f AsAda) + , protocolParametersStakePoolDeposit :: !(HKD f AsAda) + , protocolParametersStakePoolPledgeInfluence :: !(HKD f MaestroRational) + , protocolParametersStakePoolRetirementEpochBound :: !(HKD f EpochNo) + , protocolParametersStakePoolVotingThresholds :: !(HKD f StakePoolVotingThresholds) + , protocolParametersTreasuryExpansion :: !(HKD f MaestroRational) + , protocolParametersVersion :: !(HKD f ProtocolVersion) } - deriving stock (Eq, Show, Generic) - deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "protocolParameters", LowerFirst]] ProtocolParameters + deriving stock Generic + +type ProtocolParameters = ProtocolParametersHKD Identity + +deriving via (CustomJSON '[FieldLabelModifier '[StripPrefix "protocolParameters", LowerFirst]] ProtocolParameters) instance FromJSON ProtocolParameters +deriving instance Eq ProtocolParameters +deriving instance Show ProtocolParameters + +type ProtocolParametersM = ProtocolParametersHKD Ledger.StrictMaybe +deriving via (CustomJSON '[FieldLabelModifier '[StripPrefix "protocolParameters", LowerFirst]] ProtocolParametersM) instance FromJSON ProtocolParametersM +deriving instance Eq ProtocolParametersM +deriving instance Show ProtocolParametersM + +protocolVersionFromOgmios :: String -> ProtocolVersion -> Ledger.ProtVer +protocolVersionFromOgmios errPath protocolParametersVersion = + Ledger.ProtVer + { Ledger.pvMajor = Ledger.mkVersion (Maestro.protocolVersionMajor protocolParametersVersion) & fromMaybe (error (errPath <> "Major version received from Maestro is out of bounds")) + , Ledger.pvMinor = Maestro.protocolVersionMinor protocolParametersVersion + } + +pparamsFromOgmios :: forall f. HKDFunctor f => String -> ProtocolParametersHKD f -> ConwayPParams f StandardConway +pparamsFromOgmios errPath ProtocolParameters {..} = + ConwayPParams + { cppMinFeeA = THKD $ hkdMap prxy (Ledger.Coin . (toInteger @Natural)) protocolParametersMinFeeCoefficient + , cppMinFeeB = THKD $ hkdMap prxy (Ledger.Coin . toInteger . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersMinFeeConstant + , cppMaxBBSize = THKD $ hkdMap prxy ((fromIntegral @Natural @Word32) . Maestro.asBytesBytes) protocolParametersMaxBlockBodySize + , cppMaxTxSize = THKD $ hkdMap prxy ((fromIntegral @Natural @Word32) . Maestro.asBytesBytes) protocolParametersMaxTransactionSize + , cppMaxBHSize = THKD $ hkdMap prxy (fromIntegral @Natural @Word16 . Maestro.asBytesBytes) protocolParametersMaxBlockHeaderSize + , cppKeyDeposit = THKD $ hkdMap prxy (Ledger.Coin . toInteger . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersStakeCredentialDeposit + , cppPoolDeposit = THKD $ hkdMap prxy (Ledger.Coin . toInteger . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersStakePoolDeposit + , cppEMax = + THKD $ + hkdMap + prxy + ( Ledger.EpochInterval + . fromIntegral + . Maestro.unEpochNo + ) + protocolParametersStakePoolRetirementEpochBound + , cppNOpt = THKD $ fromIntegral protocolParametersDesiredNumberOfStakePools + , cppA0 = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Pool influence received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.NonNegativeInterval . Maestro.unMaestroRational) protocolParametersStakePoolPledgeInfluence + , cppRho = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Monetory expansion parameter received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.UnitInterval . Maestro.unMaestroRational) protocolParametersMonetaryExpansion + , cppTau = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Treasury expansion parameter received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.UnitInterval . Maestro.unMaestroRational) protocolParametersTreasuryExpansion + , cppProtocolVersion = toNoUpdate @f @Ledger.ProtVer $ hkdMap prxy (protocolVersionFromOgmios errPath) protocolParametersVersion + , cppMinPoolCost = THKD $ hkdMap prxy (Ledger.Coin . toInteger . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersMinStakePoolCost + , cppCoinsPerUTxOByte = THKD $ hkdMap prxy (Api.L.CoinPerByte . Ledger.Coin . toInteger @Natural) protocolParametersMinUtxoDepositCoefficient + , cppCostModels = + THKD $ + hkdMap + prxy + ( \ppPlutusCostModels -> + Ledger.mkCostModels $ + Map.fromList + [ + ( Ledger.PlutusV1 + , either (error (errPath <> "Couldn't build PlutusV1 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV1 $ coerce @_ @[Int64] (costModelsPlutusV1 ppPlutusCostModels) + ) + , + ( Ledger.PlutusV2 + , either (error (errPath <> "Couldn't build PlutusV2 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV2 $ coerce @_ @[Int64] (costModelsPlutusV2 ppPlutusCostModels) + ) + , + ( Ledger.PlutusV3 + , either (error (errPath <> "Couldn't build PlutusV3 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV3 $ coerce @_ @[Int64] (costModelsPlutusV3 ppPlutusCostModels) + ) + ] + ) + protocolParametersPlutusCostModels + , cppPrices = + THKD $ + hkdMap + prxy + ( \ppScriptExecutionPrices -> + Ledger.Prices + { Ledger.prSteps = fromMaybe (error (errPath <> "Couldn't bound Maestro's cpu steps")) $ Ledger.boundRational $ Maestro.unMaestroRational $ Maestro.memoryCpuWithCpu ppScriptExecutionPrices + , Ledger.prMem = fromMaybe (error (errPath <> "Couldn't bound Maestro's memory units")) $ Ledger.boundRational $ Maestro.unMaestroRational $ Maestro.memoryCpuWithMemory ppScriptExecutionPrices + } + ) + protocolParametersScriptExecutionPrices + , cppMaxTxExUnits = + THKD $ + hkdMap + prxy + ( \ppMaxExecutionUnitsPerTransaction -> + Ledger.OrdExUnits $ + Ledger.ExUnits + { Ledger.exUnitsSteps = + Maestro.memoryCpuWithCpu ppMaxExecutionUnitsPerTransaction + , Ledger.exUnitsMem = + Maestro.memoryCpuWithMemory ppMaxExecutionUnitsPerTransaction + } + ) + protocolParametersMaxExecutionUnitsPerTransaction + , cppMaxBlockExUnits = + THKD $ + hkdMap + prxy + ( \ppMaxExecutionUnitsPerBlock -> + Ledger.OrdExUnits $ + Ledger.ExUnits + { Ledger.exUnitsSteps = + Maestro.memoryCpuWithCpu ppMaxExecutionUnitsPerBlock + , Ledger.exUnitsMem = + Maestro.memoryCpuWithMemory ppMaxExecutionUnitsPerBlock + } + ) + protocolParametersMaxExecutionUnitsPerBlock + , cppMaxValSize = THKD $ hkdMap prxy (fromIntegral @Natural @Word32 . Maestro.asBytesBytes) protocolParametersMaxValueSize + , cppCollateralPercentage = THKD $ fromIntegral protocolParametersCollateralPercentage + , cppMaxCollateralInputs = THKD $ fromIntegral protocolParametersMaxCollateralInputs + , cppPoolVotingThresholds = + THKD $ + hkdMap + prxy + ( \ppStakePoolVotingThresholds -> + Ledger.PoolVotingThresholds + { pvtPPSecurityGroup = unsafeBoundRational $ Maestro.unMaestroRational $ Maestro.ppUpdateStakePoolSecurity $ stakePoolVotingThresholdsProtocolParametersUpdate ppStakePoolVotingThresholds + , pvtMotionNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ stakePoolVotingThresholdsNoConfidence ppStakePoolVotingThresholds + , pvtHardForkInitiation = unsafeBoundRational $ Maestro.unMaestroRational $ stakePoolVotingThresholdsHardForkInitiation ppStakePoolVotingThresholds + , pvtCommitteeNormal = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeDefault $ stakePoolVotingThresholdsConstitutionalCommittee ppStakePoolVotingThresholds + , pvtCommitteeNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeStateOfNoConfidence $ stakePoolVotingThresholdsConstitutionalCommittee ppStakePoolVotingThresholds + } + ) + protocolParametersStakePoolVotingThresholds + , cppDRepVotingThresholds = + THKD $ + hkdMap + prxy + ( \ppDelegateRepresentativeVotingThresholds -> + Ledger.DRepVotingThresholds + { dvtUpdateToConstitution = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsConstitution ppDelegateRepresentativeVotingThresholds + , dvtTreasuryWithdrawal = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsTreasuryWithdrawals ppDelegateRepresentativeVotingThresholds + , dvtPPTechnicalGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepTechnical $ drepVotingThresholdsProtocolParametersUpdate ppDelegateRepresentativeVotingThresholds + , dvtPPNetworkGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepNetwork $ drepVotingThresholdsProtocolParametersUpdate ppDelegateRepresentativeVotingThresholds + , dvtPPGovGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepGovernance $ drepVotingThresholdsProtocolParametersUpdate ppDelegateRepresentativeVotingThresholds + , dvtPPEconomicGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepEconomic $ drepVotingThresholdsProtocolParametersUpdate ppDelegateRepresentativeVotingThresholds + , dvtMotionNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsNoConfidence ppDelegateRepresentativeVotingThresholds + , dvtHardForkInitiation = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsHardForkInitiation ppDelegateRepresentativeVotingThresholds + , dvtCommitteeNormal = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeDefault $ drepVotingThresholdsConstitutionalCommittee ppDelegateRepresentativeVotingThresholds + , dvtCommitteeNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeStateOfNoConfidence $ drepVotingThresholdsConstitutionalCommittee ppDelegateRepresentativeVotingThresholds + } + ) + protocolParametersDelegateRepresentativeVotingThresholds + , cppCommitteeMinSize = THKD $ fromIntegral protocolParametersConstitutionalCommitteeMinSize + , cppCommitteeMaxTermLength = THKD $ hkdMap prxy (Ledger.EpochInterval . fromIntegral @Natural) protocolParametersConstitutionalCommitteeMaxTermLength + , cppGovActionLifetime = THKD $ hkdMap prxy (Ledger.EpochInterval . fromIntegral @Natural) protocolParametersGovernanceActionLifetime + , cppGovActionDeposit = THKD $ hkdMap prxy (Ledger.Coin . fromIntegral . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersGovernanceActionDeposit + , cppDRepDeposit = THKD $ hkdMap prxy (Ledger.Coin . fromIntegral . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersDelegateRepresentativeDeposit + , cppDRepActivity = THKD $ hkdMap prxy (Ledger.EpochInterval . fromIntegral @Natural) protocolParametersDelegateRepresentativeMaxIdleTime + , cppMinFeeRefScriptCostPerByte = THKD $ hkdMap prxy (unsafeBoundRational @Ledger.NonNegativeInterval . Maestro.minFeeReferenceScriptsBase) protocolParametersMinFeeReferenceScripts + } + where + prxy = Proxy @f -- | Fetch protocol parameters. ogmiosProtocolParameters :: OgmiosApiEnv -> IO ApiProtocolParameters ogmiosProtocolParameters env = do - ProtocolParameters {..} <- + ogmiosPParams <- handleOgmiosError fn <=< runOgmiosClient env $ protocolParams (OgmiosRequest OgmiosPP) pure $ Ledger.PParams $ - ConwayPParams - { cppMinFeeA = THKD $ Ledger.Coin $ toInteger protocolParametersMinFeeCoefficient - , cppMinFeeB = THKD $ Ledger.Coin $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersMinFeeConstant - , cppMaxBBSize = THKD $ fromIntegral $ Maestro.asBytesBytes protocolParametersMaxBlockBodySize - , cppMaxTxSize = THKD $ fromIntegral $ Maestro.asBytesBytes protocolParametersMaxTransactionSize - , cppMaxBHSize = THKD $ fromIntegral $ Maestro.asBytesBytes protocolParametersMaxBlockHeaderSize - , cppKeyDeposit = THKD $ Ledger.Coin $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersStakeCredentialDeposit - , cppPoolDeposit = THKD $ Ledger.Coin $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersStakePoolDeposit - , cppEMax = - THKD $ - Ledger.EpochInterval . fromIntegral $ - Maestro.unEpochNo protocolParametersStakePoolRetirementEpochBound - , cppNOpt = THKD $ fromIntegral protocolParametersDesiredNumberOfStakePools - , cppA0 = THKD $ fromMaybe (error (errPath <> "Pool influence received from Maestro is out of bounds")) $ Ledger.boundRational $ Maestro.unMaestroRational protocolParametersStakePoolPledgeInfluence - , cppRho = THKD $ fromMaybe (error (errPath <> "Monetory expansion parameter received from Maestro is out of bounds")) $ Ledger.boundRational $ Maestro.unMaestroRational protocolParametersMonetaryExpansion - , cppTau = THKD $ fromMaybe (error (errPath <> "Treasury expansion parameter received from Maestro is out of bounds")) $ Ledger.boundRational $ Maestro.unMaestroRational protocolParametersTreasuryExpansion - , cppProtocolVersion = - Ledger.ProtVer - { Ledger.pvMajor = Ledger.mkVersion (Maestro.protocolVersionMajor protocolParametersVersion) & fromMaybe (error (errPath <> "Major version received from Maestro is out of bounds")) - , Ledger.pvMinor = Maestro.protocolVersionMinor protocolParametersVersion - } - , cppMinPoolCost = THKD $ Ledger.Coin $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersMinStakePoolCost - , cppCoinsPerUTxOByte = THKD $ Api.L.CoinPerByte $ Ledger.Coin $ toInteger protocolParametersMinUtxoDepositCoefficient - , cppCostModels = - THKD $ - Ledger.mkCostModels $ - Map.fromList - [ - ( Ledger.PlutusV1 - , either (error (errPath <> "Couldn't build PlutusV1 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV1 $ coerce @_ @[Int64] (costModelsPlutusV1 protocolParametersPlutusCostModels) - ) - , - ( Ledger.PlutusV2 - , either (error (errPath <> "Couldn't build PlutusV2 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV2 $ coerce @_ @[Int64] (costModelsPlutusV2 protocolParametersPlutusCostModels) - ) - , - ( Ledger.PlutusV3 - , either (error (errPath <> "Couldn't build PlutusV3 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV3 $ coerce @_ @[Int64] (costModelsPlutusV3 protocolParametersPlutusCostModels) - ) - ] - , cppPrices = THKD $ Ledger.Prices {Ledger.prSteps = fromMaybe (error (errPath <> "Couldn't bound Maestro's cpu steps")) $ Ledger.boundRational $ Maestro.unMaestroRational $ Maestro.memoryCpuWithCpu protocolParametersScriptExecutionPrices, Ledger.prMem = fromMaybe (error (errPath <> "Couldn't bound Maestro's memory units")) $ Ledger.boundRational $ Maestro.unMaestroRational $ Maestro.memoryCpuWithMemory protocolParametersScriptExecutionPrices} - , cppMaxTxExUnits = - THKD $ - Ledger.OrdExUnits $ - Ledger.ExUnits - { Ledger.exUnitsSteps = - Maestro.memoryCpuWithCpu protocolParametersMaxExecutionUnitsPerTransaction - , Ledger.exUnitsMem = - Maestro.memoryCpuWithMemory protocolParametersMaxExecutionUnitsPerTransaction - } - , cppMaxBlockExUnits = - THKD $ - Ledger.OrdExUnits $ - Ledger.ExUnits - { Ledger.exUnitsSteps = - Maestro.memoryCpuWithCpu protocolParametersMaxExecutionUnitsPerBlock - , Ledger.exUnitsMem = - Maestro.memoryCpuWithMemory protocolParametersMaxExecutionUnitsPerBlock - } - , cppMaxValSize = THKD $ fromIntegral $ Maestro.asBytesBytes protocolParametersMaxValueSize - , cppCollateralPercentage = THKD $ fromIntegral protocolParametersCollateralPercentage - , cppMaxCollateralInputs = THKD $ fromIntegral protocolParametersMaxCollateralInputs - , cppPoolVotingThresholds = - THKD $ - Ledger.PoolVotingThresholds - { pvtPPSecurityGroup = unsafeBoundRational $ Maestro.unMaestroRational $ Maestro.ppUpdateStakePoolSecurity $ stakePoolVotingThresholdsProtocolParametersUpdate protocolParametersStakePoolVotingThresholds - , pvtMotionNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ stakePoolVotingThresholdsNoConfidence protocolParametersStakePoolVotingThresholds - , pvtHardForkInitiation = unsafeBoundRational $ Maestro.unMaestroRational $ stakePoolVotingThresholdsHardForkInitiation protocolParametersStakePoolVotingThresholds - , pvtCommitteeNormal = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeDefault $ stakePoolVotingThresholdsConstitutionalCommittee protocolParametersStakePoolVotingThresholds - , pvtCommitteeNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeStateOfNoConfidence $ stakePoolVotingThresholdsConstitutionalCommittee protocolParametersStakePoolVotingThresholds - } - , cppDRepVotingThresholds = - THKD $ - Ledger.DRepVotingThresholds - { dvtUpdateToConstitution = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsConstitution protocolParametersDelegateRepresentativeVotingThresholds - , dvtTreasuryWithdrawal = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsTreasuryWithdrawals protocolParametersDelegateRepresentativeVotingThresholds - , dvtPPTechnicalGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepTechnical $ drepVotingThresholdsProtocolParametersUpdate protocolParametersDelegateRepresentativeVotingThresholds - , dvtPPNetworkGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepNetwork $ drepVotingThresholdsProtocolParametersUpdate protocolParametersDelegateRepresentativeVotingThresholds - , dvtPPGovGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepGovernance $ drepVotingThresholdsProtocolParametersUpdate protocolParametersDelegateRepresentativeVotingThresholds - , dvtPPEconomicGroup = unsafeBoundRational $ Maestro.unMaestroRational $ ppUpdateDrepEconomic $ drepVotingThresholdsProtocolParametersUpdate protocolParametersDelegateRepresentativeVotingThresholds - , dvtMotionNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsNoConfidence protocolParametersDelegateRepresentativeVotingThresholds - , dvtHardForkInitiation = unsafeBoundRational $ Maestro.unMaestroRational $ drepVotingThresholdsHardForkInitiation protocolParametersDelegateRepresentativeVotingThresholds - , dvtCommitteeNormal = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeDefault $ drepVotingThresholdsConstitutionalCommittee protocolParametersDelegateRepresentativeVotingThresholds - , dvtCommitteeNoConfidence = unsafeBoundRational $ Maestro.unMaestroRational $ constitutionalCommitteeStateOfNoConfidence $ drepVotingThresholdsConstitutionalCommittee protocolParametersDelegateRepresentativeVotingThresholds - } - , cppCommitteeMinSize = THKD $ fromIntegral protocolParametersConstitutionalCommitteeMinSize - , cppCommitteeMaxTermLength = THKD (Ledger.EpochInterval $ fromIntegral protocolParametersConstitutionalCommitteeMaxTermLength) - , cppGovActionLifetime = THKD (Ledger.EpochInterval $ fromIntegral protocolParametersGovernanceActionLifetime) - , cppGovActionDeposit = THKD $ Ledger.Coin $ fromIntegral $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersGovernanceActionDeposit - , cppDRepDeposit = THKD $ Ledger.Coin $ fromIntegral $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersDelegateRepresentativeDeposit - , cppDRepActivity = THKD (Ledger.EpochInterval $ fromIntegral protocolParametersDelegateRepresentativeMaxIdleTime) - , cppMinFeeRefScriptCostPerByte = THKD $ unsafeBoundRational $ Maestro.minFeeReferenceScriptsBase protocolParametersMinFeeReferenceScripts - } + pparamsFromOgmios errPath ogmiosPParams where errPath = "GeniusYield.Providers.Ogmios.ogmiosProtocolParameters: " fn = "ogmiosProtocolParameters" @@ -637,7 +825,14 @@ ogmiosEraSummaries env = do ogmiosConstitution :: OgmiosApiEnv -> IO GYConstitution ogmiosConstitution env = do - OgmiosConstitutionResponse {..} <- handleOgmiosError fn <=< runOgmiosClient env $ constitution (OgmiosRequest OgmiosConstitution) - pure $ GYConstitution {constitutionAnchor = anchorFromOgmiosMetadata metadata, constitutionScript = asHashHash <$> guardrails} + ogmiosConstitutionResp <- handleOgmiosError fn <=< runOgmiosClient env $ constitution (OgmiosRequest OgmiosConstitution) + pure $ constitutionFromOgmios ogmiosConstitutionResp where fn = "ogmiosConstitution" + +ogmiosProposals :: OgmiosApiEnv -> Set GYGovActionId -> IO (Seq.Seq GYGovActionState) +ogmiosProposals env actionIds = do + proposalsResp <- handleOgmiosError fn <=< runOgmiosClient env $ proposals (OgmiosRequest $ OgmiosProposals actionIds) + pure $ Seq.fromList $ map govActionStateFromOgmiosProposalResponse proposalsResp + where + fn = "ogmiosProposals" \ No newline at end of file diff --git a/src/GeniusYield/Test/Clb.hs b/src/GeniusYield/Test/Clb.hs index 2eb82d65..4d3dca60 100644 --- a/src/GeniusYield/Test/Clb.hs +++ b/src/GeniusYield/Test/Clb.hs @@ -351,6 +351,8 @@ instance GYTxQueryMonad GYTxMonadClb where drepState = const $ pure Nothing constitution = error "CLB does not support fetching of constitution" + proposals _actionIds = error "CLB does not support fetching of proposals" + -- Note, we need to define only one of drepState or drepsState unless required for performace reasons as they have default definition in terms of each other. slotConfig = do diff --git a/src/GeniusYield/Test/Privnet/Ctx.hs b/src/GeniusYield/Test/Privnet/Ctx.hs index 71c6597d..2b96983d 100644 --- a/src/GeniusYield/Test/Privnet/Ctx.hs +++ b/src/GeniusYield/Test/Privnet/Ctx.hs @@ -231,6 +231,7 @@ ctxProviders ctx = , gyGetDRepsState = nodeGetDRepsState (ctxInfo ctx) , gyGetStakePools = nodeStakePools (ctxInfo ctx) , gyGetConstitution = nodeConstitution (ctxInfo ctx) + , gyGetProposals = nodeProposals (ctxInfo ctx) } -- | Function to find for the first locked output in the given `GYTxBody` at the given `GYAddress`. diff --git a/src/GeniusYield/TxBuilder/IO/Query.hs b/src/GeniusYield/TxBuilder/IO/Query.hs index 5d84c44a..b421155c 100644 --- a/src/GeniusYield/TxBuilder/IO/Query.hs +++ b/src/GeniusYield/TxBuilder/IO/Query.hs @@ -145,6 +145,11 @@ instance GYTxQueryMonad GYTxQueryMonadIO where providers <- asks envProviders ioToQueryMonad $ gyGetConstitution providers + proposals actionIds = do + logMsg mempty GYDebug "Querying Proposals" + providers <- asks envProviders + ioToQueryMonad $ gyGetProposals providers actionIds + slotConfig = do providers <- asks envProviders ioToQueryMonad $ gyGetSlotConfig providers diff --git a/src/GeniusYield/TxBuilder/Query/Class.hs b/src/GeniusYield/TxBuilder/Query/Class.hs index 592f9761..01bb3cb9 100644 --- a/src/GeniusYield/TxBuilder/Query/Class.hs +++ b/src/GeniusYield/TxBuilder/Query/Class.hs @@ -21,6 +21,7 @@ import Data.Map.Strict qualified as Map import Data.Maybe (listToMaybe) import GHC.Stack (withFrozenCallStack) +import Data.Sequence qualified as Seq import Data.Set qualified as Set import GeniusYield.Imports import GeniusYield.TxBuilder.Errors @@ -32,7 +33,7 @@ import GeniusYield.Types -- | Class of monads for querying chain data. class MonadError GYTxMonadException m => GYTxQueryMonad m where - {-# MINIMAL networkId, lookupDatum, (utxoAtTxOutRef | utxosAtTxOutRefs), utxosAtAddress, utxosAtPaymentCredential, stakeAddressInfo, slotConfig, slotOfCurrentBlock, logMsg, waitUntilSlot, waitForNextBlock, (drepState | drepsState), constitution #-} + {-# MINIMAL networkId, lookupDatum, (utxoAtTxOutRef | utxosAtTxOutRefs), utxosAtAddress, utxosAtPaymentCredential, stakeAddressInfo, slotConfig, slotOfCurrentBlock, logMsg, waitUntilSlot, waitForNextBlock, (drepState | drepsState), constitution, proposals #-} -- | Get the network id networkId :: m GYNetworkId @@ -135,6 +136,13 @@ class MonadError GYTxMonadException m => GYTxQueryMonad m where -- | Query the current constitution definition. constitution :: m GYConstitution + -- | Query proposals that are considered for ratification.. + proposals :: + -- | Specify a set of Governance Action IDs to filter the proposals. When this set is + -- empty, all the proposals considered for ratification will be returned. + Set GYGovActionId -> + m (Seq.Seq GYGovActionState) + -- | Class of monads for querying special chain data. {- Note [Necessity of 'GYTxSpecialQueryMonad' and transaction building as a class method] @@ -202,6 +210,7 @@ instance GYTxQueryMonad m => GYTxQueryMonad (RandT g m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance GYTxUserQueryMonad m => GYTxUserQueryMonad (RandT g m) where ownAddresses = lift ownAddresses @@ -240,6 +249,7 @@ instance GYTxQueryMonad m => GYTxQueryMonad (ReaderT env m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance GYTxUserQueryMonad m => GYTxUserQueryMonad (ReaderT env m) where ownAddresses = lift ownAddresses @@ -304,6 +314,7 @@ instance GYTxQueryMonad m => GYTxQueryMonad (Strict.StateT s m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance GYTxUserQueryMonad m => GYTxUserQueryMonad (Strict.StateT s m) where ownAddresses = lift ownAddresses @@ -342,6 +353,7 @@ instance GYTxQueryMonad m => GYTxQueryMonad (Lazy.StateT s m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance GYTxUserQueryMonad m => GYTxUserQueryMonad (Lazy.StateT s m) where ownAddresses = lift ownAddresses @@ -380,6 +392,7 @@ instance (GYTxQueryMonad m, Monoid w) => GYTxQueryMonad (CPS.WriterT w m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance (GYTxUserQueryMonad m, Monoid w) => GYTxUserQueryMonad (CPS.WriterT w m) where ownAddresses = lift ownAddresses @@ -418,6 +431,7 @@ instance (GYTxQueryMonad m, Monoid w) => GYTxQueryMonad (Strict.WriterT w m) whe waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance (GYTxUserQueryMonad m, Monoid w) => GYTxUserQueryMonad (Strict.WriterT w m) where ownAddresses = lift ownAddresses @@ -456,6 +470,7 @@ instance (GYTxQueryMonad m, Monoid w) => GYTxQueryMonad (Lazy.WriterT w m) where waitUntilSlot = lift . waitUntilSlot waitForNextBlock = lift waitForNextBlock constitution = lift constitution + proposals = lift . proposals instance (GYTxUserQueryMonad m, Monoid w) => GYTxUserQueryMonad (Lazy.WriterT w m) where ownAddresses = lift ownAddresses diff --git a/src/GeniusYield/Types/Address.hs b/src/GeniusYield/Types/Address.hs index f401fc34..719563ad 100644 --- a/src/GeniusYield/Types/Address.hs +++ b/src/GeniusYield/Types/Address.hs @@ -42,6 +42,7 @@ module GeniusYield.Types.Address ( unsafeStakeAddressFromText, stakeAddressToText, stakeAddressToLedger, + stakeAddressFromLedger, stakeAddressCredential, stakeAddressToCredential, stakeAddressFromCredential, @@ -672,6 +673,9 @@ stakeAddressToText = Api.serialiseAddress . stakeAddressToApi stakeAddressToLedger :: GYStakeAddress -> Ledger.RewardAccount Ledger.StandardCrypto stakeAddressToLedger (stakeAddressToApi -> Api.StakeAddress nw sc) = Ledger.RewardAccount nw sc +stakeAddressFromLedger :: Ledger.RewardAccount Ledger.StandardCrypto -> GYStakeAddress +stakeAddressFromLedger (Ledger.RewardAccount nw sc) = stakeAddressFromApi $ Api.StakeAddress nw sc + {-# DEPRECATED stakeAddressCredential "Use stakeAddressToCredential." #-} -- | Get a stake credential from a stake address. This drops the network information. diff --git a/src/GeniusYield/Types/Governance.hs b/src/GeniusYield/Types/Governance.hs index 30e18e86..1676cf82 100644 --- a/src/GeniusYield/Types/Governance.hs +++ b/src/GeniusYield/Types/Governance.hs @@ -28,11 +28,16 @@ module GeniusYield.Types.Governance ( GYProposalProcedure (..), completeProposalProcedure, propProcToLedger, + propProcFromLedger, GYConstitution (..), constitutionToLedger, constitutionFromLedger, GYGovAction (..), govActionToLedger, + govActionFromLedger, + GYGovActionState (..), + govActionStateToLedger, + govActionStateFromLedger, ) where import Cardano.Api.Ledger (maybeToStrictMaybe, strictMaybeToMaybe) @@ -43,11 +48,11 @@ import Data.Map.Strict qualified as Map import Data.Set qualified as Set import Data.Word (Word16) import GeniusYield.Imports (Map, Natural, Set, (&)) -import GeniusYield.Types.Address (GYStakeAddress, stakeAddressToLedger) +import GeniusYield.Types.Address (GYStakeAddress, stakeAddressFromLedger, stakeAddressToLedger) import GeniusYield.Types.Anchor import GeniusYield.Types.BuildWitness import GeniusYield.Types.Credential (GYCredential, credentialFromLedger, credentialToLedger) -import GeniusYield.Types.Epoch (GYEpochNo, epochNoToLedger) +import GeniusYield.Types.Epoch (GYEpochNo, epochNoFromLedger, epochNoToLedger) import GeniusYield.Types.KeyHash import GeniusYield.Types.KeyRole (GYKeyRole (..)) import GeniusYield.Types.Reexpose (ProtVer, UnitInterval) @@ -162,6 +167,15 @@ propProcToLedger GYProposalProcedure {..} = , Ledger.pProcAnchor = anchorToLedger propProcAnchor } +propProcFromLedger :: Ledger.ProposalProcedure Consensus.StandardConway -> GYProposalProcedure +propProcFromLedger Ledger.ProposalProcedure {..} = + GYProposalProcedure + { propProcDeposit = fromIntegral pProcDeposit + , propProcReturnAddr = stakeAddressFromLedger pProcReturnAddr + , propProcGovAction = govActionFromLedger pProcGovAction + , propProcAnchor = anchorFromLedger pProcAnchor + } + data GYConstitution = GYConstitution { constitutionAnchor :: !GYAnchor , constitutionScript :: !(Maybe GYScriptHash) @@ -229,3 +243,50 @@ govActionToLedger ga = case ga of castPurposeM mgid = ms $ castPurpose <$> mgid castScriptHashM sh = ms $ scriptHashToLedger <$> sh + +govActionFromLedger :: Ledger.GovAction Consensus.StandardConway -> GYGovAction +govActionFromLedger ga = case ga of + Ledger.ParameterChange mgaid ppup msh -> ParameterChange (govActionIdFromLedger' <$> strictMaybeToMaybe mgaid) ppup (scriptHashFromLedger <$> strictMaybeToMaybe msh) + Ledger.HardForkInitiation mgaid pv -> HardForkInitiation (govActionIdFromLedger' <$> strictMaybeToMaybe mgaid) pv + Ledger.TreasuryWithdrawals tw msh -> TreasuryWithdrawals (Map.mapKeys stakeAddressFromLedger $ Map.map fromIntegral tw) (scriptHashFromLedger <$> strictMaybeToMaybe msh) + Ledger.NoConfidence mgaid -> NoConfidence (govActionIdFromLedger' <$> strictMaybeToMaybe mgaid) + Ledger.UpdateCommittee mgaid rm add thr -> UpdateCommittee (govActionIdFromLedger' <$> strictMaybeToMaybe mgaid) (Set.map credentialFromLedger rm) (Map.mapKeys credentialFromLedger $ Map.map epochNoFromLedger add) thr + Ledger.NewConstitution mgaid c -> NewConstitution (govActionIdFromLedger' <$> strictMaybeToMaybe mgaid) (constitutionFromLedger c) + Ledger.InfoAction -> InfoAction + where + govActionIdFromLedger' (Ledger.GovPurposeId gid) = govActionIdFromLedger gid + +data GYGovActionState = GYGovActionState + { gasId :: !GYGovActionId + , gasCommitteeVotes :: !(Map (GYCredential 'GYKeyRoleHotCommittee) GYVote) + , gasDRepVotes :: !(Map (GYCredential 'GYKeyRoleDRep) GYVote) + , gasStakePoolVotes :: !(Map (GYKeyHash 'GYKeyRoleStakePool) GYVote) + , gasProposalProcedure :: !GYProposalProcedure + , gasProposedIn :: !GYEpochNo + , gasExpiresAfter :: !GYEpochNo + } + deriving stock (Eq, Show, Ord) + +govActionStateToLedger :: GYGovActionState -> Ledger.GovActionState Consensus.StandardConway +govActionStateToLedger GYGovActionState {..} = + Ledger.GovActionState + { Ledger.gasId = govActionIdToLedger gasId + , Ledger.gasCommitteeVotes = Map.mapKeys credentialToLedger $ Map.map voteToLedger gasCommitteeVotes + , Ledger.gasDRepVotes = Map.mapKeys credentialToLedger $ Map.map voteToLedger gasDRepVotes + , Ledger.gasStakePoolVotes = Map.mapKeys keyHashToLedger $ Map.map voteToLedger gasStakePoolVotes + , Ledger.gasProposalProcedure = propProcToLedger gasProposalProcedure + , Ledger.gasProposedIn = epochNoToLedger gasProposedIn + , Ledger.gasExpiresAfter = epochNoToLedger gasExpiresAfter + } + +govActionStateFromLedger :: Ledger.GovActionState Consensus.StandardConway -> GYGovActionState +govActionStateFromLedger Ledger.GovActionState {..} = + GYGovActionState + { gasId = govActionIdFromLedger gasId + , gasCommitteeVotes = Map.mapKeys credentialFromLedger $ Map.map voteFromLedger gasCommitteeVotes + , gasDRepVotes = Map.mapKeys credentialFromLedger $ Map.map voteFromLedger gasDRepVotes + , gasStakePoolVotes = Map.mapKeys keyHashFromLedger $ Map.map voteFromLedger gasStakePoolVotes + , gasProposalProcedure = propProcFromLedger gasProposalProcedure + , gasProposedIn = epochNoFromLedger gasProposedIn + , gasExpiresAfter = epochNoFromLedger gasExpiresAfter + } \ No newline at end of file diff --git a/src/GeniusYield/Types/Providers.hs b/src/GeniusYield/Types/Providers.hs index 3672a221..861ce6ee 100644 --- a/src/GeniusYield/Types/Providers.hs +++ b/src/GeniusYield/Types/Providers.hs @@ -88,6 +88,7 @@ import Control.Concurrent.Class.MonadMVar.Strict ( ) import Control.Monad.IO.Class (MonadIO (..)) import Data.Default (Default, def) +import Data.Sequence qualified as Seq import Data.Text qualified as Txt import Data.Time import Data.Time.Clock.POSIX (posixSecondsToUTCTime) @@ -100,7 +101,7 @@ import GeniusYield.Types.Credential (GYCredential, GYPaymentCredential) import GeniusYield.Types.DRep import GeniusYield.Types.Datum import GeniusYield.Types.Epoch (GYEpochNo (GYEpochNo)) -import GeniusYield.Types.Governance (GYConstitution) +import GeniusYield.Types.Governance (GYConstitution, GYGovActionId, GYGovActionState) import GeniusYield.Types.KeyRole import GeniusYield.Types.Logging import GeniusYield.Types.ProtocolParameters @@ -159,7 +160,9 @@ data GYProviders = GYProviders gyLog' :: !GYLogConfiguration , gyGetStakePools :: !(IO (Set Api.S.PoolId)) , gyGetConstitution :: IO GYConstitution - -- Don't make this strict since it's not defined for all providers! + , -- Don't make this strict since it's not defined for all providers! + gyGetProposals :: Set GYGovActionId -> IO (Seq.Seq GYGovActionState) + -- Don't make this strict since it's not defined for all providers! } gyGetSlotOfCurrentBlock :: GYProviders -> IO GYSlot From d4cf6b16f23bba85e81066934bd1f690a0cc8df4 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 24 Feb 2025 16:31:31 +0530 Subject: [PATCH 7/9] feat(#408): updates to proposal fetching in ogmios provider --- src/GeniusYield/Providers/Ogmios.hs | 37 +++++++++++++++++++++-------- src/GeniusYield/Types/Address.hs | 3 +++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/GeniusYield/Providers/Ogmios.hs b/src/GeniusYield/Providers/Ogmios.hs index e0be53cf..1157200b 100644 --- a/src/GeniusYield/Providers/Ogmios.hs +++ b/src/GeniusYield/Providers/Ogmios.hs @@ -205,6 +205,9 @@ newtype AsEpoch = AsEpoch deriving stock (Eq, Show, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "asEpoch", LowerFirst]] AsEpoch +epochFromOgmios :: AsEpoch -> GYEpochNo +epochFromOgmios asEpoch = asEpoch & asEpochEpoch & fromIntegral & GYEpochNo + data OgmiosMetadata = OgmiosMetadata { metadataUrl :: !GYUrl , metadataHash :: !GYAnchorDataHash @@ -313,7 +316,7 @@ newtype OgmiosProposals = OgmiosProposals (Set GYGovActionId) instance ToJSONRPC OgmiosProposals where toMethod = const "queryLedgerState/governanceProposals" - toParams (OgmiosProposals proposals) = Just $ object ["proposals" .= Set.map encodeProposal proposals] + toParams (OgmiosProposals proposalsSet) = Just $ object ["proposals" .= Set.map encodeProposal proposalsSet] where encodeProposal govActionId = object ["transaction" .= object ["id" .= gaidTxId govActionId], "index" .= gaidIx govActionId] @@ -340,7 +343,6 @@ instance FromJSON OgmiosProposalResponse where oprAction <- do obj <- o .: "action" parseAction obj - oprSince <- o .: "since" oprUntil <- o .: "until" oprVotes <- o .: "votes" @@ -348,7 +350,7 @@ instance FromJSON OgmiosProposalResponse where where parseAction :: Aeson.Object -> Aeson.Parser GYGovAction parseAction obj = do - actionType <- obj .: "type" + actionType :: Text <- obj .: "type" case actionType of "information" -> pure InfoAction "noConfidence" -> do @@ -401,7 +403,7 @@ instance FromJSON OgmiosVote where \o -> do ovVoter <- do issuer <- o .: "issuer" - voterRole <- issuer .: "role" + voterRole :: Text <- issuer .: "role" case voterRole of "delegateRepresentative" -> do cred <- getCredential issuer @@ -413,7 +415,7 @@ instance FromJSON OgmiosVote where poolId <- issuer .: "id" pure $ OgmiosVoterStakePool poolId anyOther -> fail $ "Invalid voter role: " <> show anyOther - voteResult <- o .: "vote" + voteResult :: Text <- o .: "vote" ovVote <- case voteResult of "yes" -> pure Yes "no" -> pure No @@ -427,6 +429,21 @@ instance FromJSON OgmiosVote where OgCredTypeVerificationKey -> GYCredentialByKey <$> o .: "id" OgCredTypeScript -> GYCredentialByScript <$> o .: "id" +govActionStateFromOgmiosProposalResponse :: OgmiosProposalResponse -> GYGovActionState +govActionStateFromOgmiosProposalResponse OgmiosProposalResponse {..} = + let (gasStakePoolVotes, gasDRepVotes, gasCommitteeVotes) = + foldl' + ( \(!accGasStakePoolVotes, !accGasDRepVotes, !accGasCommitteeVotes) OgmiosVote {..} -> + case ovVoter of + OgmiosVoterCommittee cred -> (accGasStakePoolVotes, accGasDRepVotes, Map.insert cred ovVote accGasCommitteeVotes) + OgmiosVoterDRep cred -> (accGasStakePoolVotes, Map.insert cred ovVote accGasDRepVotes, accGasCommitteeVotes) + OgmiosVoterStakePool (stakePoolIdFromBech32 -> poolId) -> (Map.insert poolId ovVote accGasStakePoolVotes, accGasDRepVotes, accGasCommitteeVotes) + ) + (mempty, mempty, mempty) + oprVotes + gasProposalProcedure = GYProposalProcedure {propProcDeposit = oprDeposit & asAdaAda & asLovelaceLovelace, propProcReturnAddr = oprReturnAccount & stakeAddressFromBech32, propProcGovAction = oprAction, propProcAnchor = oprMetadata & anchorFromOgmiosMetadata} + in GYGovActionState {gasStakePoolVotes = gasStakePoolVotes, gasProposedIn = epochFromOgmios oprSince, gasProposalProcedure = gasProposalProcedure, gasId = oprProposal, gasExpiresAfter = epochFromOgmios oprUntil, gasDRepVotes = gasDRepVotes, gasCommitteeVotes = gasCommitteeVotes} + submitTx :: OgmiosRequest GYTx -> ClientM (OgmiosResponse TxSubmissionResponse) protocolParams :: OgmiosRequest OgmiosPP -> ClientM (OgmiosResponse ProtocolParameters) tip :: OgmiosRequest OgmiosTip -> ClientM (OgmiosResponse OgmiosTipResponse) @@ -586,7 +603,7 @@ pparamsFromOgmios errPath ProtocolParameters {..} = . Maestro.unEpochNo ) protocolParametersStakePoolRetirementEpochBound - , cppNOpt = THKD $ fromIntegral protocolParametersDesiredNumberOfStakePools + , cppNOpt = THKD $ hkdMap prxy (fromIntegral @Natural @Word16) protocolParametersDesiredNumberOfStakePools , cppA0 = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Pool influence received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.NonNegativeInterval . Maestro.unMaestroRational) protocolParametersStakePoolPledgeInfluence , cppRho = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Monetory expansion parameter received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.UnitInterval . Maestro.unMaestroRational) protocolParametersMonetaryExpansion , cppTau = THKD $ hkdMap prxy (fromMaybe (error (errPath <> "Treasury expansion parameter received from Maestro is out of bounds")) . Ledger.boundRational @Ledger.UnitInterval . Maestro.unMaestroRational) protocolParametersTreasuryExpansion @@ -655,8 +672,8 @@ pparamsFromOgmios errPath ProtocolParameters {..} = ) protocolParametersMaxExecutionUnitsPerBlock , cppMaxValSize = THKD $ hkdMap prxy (fromIntegral @Natural @Word32 . Maestro.asBytesBytes) protocolParametersMaxValueSize - , cppCollateralPercentage = THKD $ fromIntegral protocolParametersCollateralPercentage - , cppMaxCollateralInputs = THKD $ fromIntegral protocolParametersMaxCollateralInputs + , cppCollateralPercentage = THKD $ hkdMap prxy (fromIntegral @Natural @Word16) protocolParametersCollateralPercentage + , cppMaxCollateralInputs = THKD $ hkdMap prxy (fromIntegral @Natural @Word16) protocolParametersMaxCollateralInputs , cppPoolVotingThresholds = THKD $ hkdMap @@ -690,7 +707,7 @@ pparamsFromOgmios errPath ProtocolParameters {..} = } ) protocolParametersDelegateRepresentativeVotingThresholds - , cppCommitteeMinSize = THKD $ fromIntegral protocolParametersConstitutionalCommitteeMinSize + , cppCommitteeMinSize = THKD $ hkdMap prxy (fromIntegral @Natural @Word16) protocolParametersConstitutionalCommitteeMinSize , cppCommitteeMaxTermLength = THKD $ hkdMap prxy (Ledger.EpochInterval . fromIntegral @Natural) protocolParametersConstitutionalCommitteeMaxTermLength , cppGovActionLifetime = THKD $ hkdMap prxy (Ledger.EpochInterval . fromIntegral @Natural) protocolParametersGovernanceActionLifetime , cppGovActionDeposit = THKD $ hkdMap prxy (Ledger.Coin . fromIntegral . Maestro.asLovelaceLovelace . Maestro.asAdaAda) protocolParametersGovernanceActionDeposit @@ -743,7 +760,7 @@ ogmiosGetDRepsState env dreps = do ( ogDRepStateCred s , Just $ GYDRepState - { drepExpiry = ogDRepStateMandate s & asEpochEpoch & (GYEpochNo . fromIntegral) + { drepExpiry = ogDRepStateMandate s & epochFromOgmios , drepAnchor = let man = ogDRepStateAnchor s in man >>= \an -> Just $ anchorFromOgmiosMetadata an diff --git a/src/GeniusYield/Types/Address.hs b/src/GeniusYield/Types/Address.hs index 719563ad..06d62c1b 100644 --- a/src/GeniusYield/Types/Address.hs +++ b/src/GeniusYield/Types/Address.hs @@ -893,6 +893,9 @@ instance FromJSON GYStakeAddressBech32 where Just stakeAddr -> return $ GYStakeAddressBech32 stakeAddr Nothing -> fail "cannot deserialise stake address" +instance Aeson.FromJSONKey GYStakeAddressBech32 where + fromJSONKey = Aeson.FromJSONKeyTextParser (either (fail . Text.unpack) pure . Web.parseUrlPiece) + instance PQ.ToField GYStakeAddressBech32 where toField (GYStakeAddressBech32 stakeAddr) = PQ.toField $ stakeAddressToText stakeAddr From af17fbccb62e2ab4b343bdebfd0efb9656926425 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 24 Feb 2025 16:55:07 +0530 Subject: [PATCH 8/9] feat(#408): finish proposals support of ogmios provider, add test to verify proposals fetchign --- src/GeniusYield/Providers/Ogmios.hs | 25 ++++++++++++++-------- src/GeniusYield/Types/Governance.hs | 2 +- tests/GeniusYield/Test/Providers/Mashup.hs | 24 ++++++++++++--------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/GeniusYield/Providers/Ogmios.hs b/src/GeniusYield/Providers/Ogmios.hs index 1157200b..b61f23f2 100644 --- a/src/GeniusYield/Providers/Ogmios.hs +++ b/src/GeniusYield/Providers/Ogmios.hs @@ -362,7 +362,13 @@ instance FromJSON OgmiosProposalResponse where pure $ NewConstitution mancestor (constitutionFromOgmios ogmiosConstitutionResp) "constitutionalCommittee" -> do mancestor <- parseAncestor obj - undefined + removedMembers <- obj .: "members" >>= (.: "removed") + removedMembersSet :: Set (GYCredential 'GYKeyRoleColdCommittee) <- Set.fromList <$> traverse getCredential removedMembers + addedMembers <- obj .: "members" >>= (.: "added") + addedMembersMap :: Map (GYCredential 'GYKeyRoleColdCommittee) GYEpochNo <- Map.fromList <$> traverse (\o -> (,) <$> getCredential o <*> (o .: "mandate" >>= (.: "epoch") <&> GYEpochNo)) addedMembers + quorum :: MaestroRational <- obj .: "quorum" + let quorumUnitInterval = (\r -> fromMaybe (error $ "parseJSON (OgmiosProposalResponse): unable to bound rational " <> show r) r) $ Ledger.boundRational $ Maestro.unMaestroRational quorum + pure $ UpdateCommittee mancestor removedMembersSet addedMembersMap quorumUnitInterval "treasuryWithdrawals" -> do withdrawals :: Map GYStakeAddressBech32 AsAda <- obj .: "withdrawals" guardrails :: Maybe AsHash <- obj .: "guardrails" @@ -408,7 +414,7 @@ instance FromJSON OgmiosVote where "delegateRepresentative" -> do cred <- getCredential issuer pure $ OgmiosVoterDRep cred - "committee" -> do + "constitutionalCommittee" -> do cred <- getCredential issuer pure $ OgmiosVoterCommittee cred "stakePoolOperator" -> do @@ -422,12 +428,13 @@ instance FromJSON OgmiosVote where "abstain" -> pure Abstain anyOther -> fail $ "Invalid vote result: " <> show anyOther pure OgmiosVote {..} - where - getCredential o = do - credType <- o .: "from" - case credType of - OgCredTypeVerificationKey -> GYCredentialByKey <$> o .: "id" - OgCredTypeScript -> GYCredentialByScript <$> o .: "id" + +getCredential :: SingGYKeyRoleI kr => Aeson.Object -> Aeson.Parser (GYCredential kr) +getCredential o = do + credType <- o .: "from" + case credType of + OgCredTypeVerificationKey -> GYCredentialByKey <$> o .: "id" + OgCredTypeScript -> GYCredentialByScript <$> o .: "id" govActionStateFromOgmiosProposalResponse :: OgmiosProposalResponse -> GYGovActionState govActionStateFromOgmiosProposalResponse OgmiosProposalResponse {..} = @@ -852,4 +859,4 @@ ogmiosProposals env actionIds = do proposalsResp <- handleOgmiosError fn <=< runOgmiosClient env $ proposals (OgmiosRequest $ OgmiosProposals actionIds) pure $ Seq.fromList $ map govActionStateFromOgmiosProposalResponse proposalsResp where - fn = "ogmiosProposals" \ No newline at end of file + fn = "ogmiosProposals" diff --git a/src/GeniusYield/Types/Governance.hs b/src/GeniusYield/Types/Governance.hs index 1676cf82..0337743f 100644 --- a/src/GeniusYield/Types/Governance.hs +++ b/src/GeniusYield/Types/Governance.hs @@ -289,4 +289,4 @@ govActionStateFromLedger Ledger.GovActionState {..} = , gasProposalProcedure = propProcFromLedger gasProposalProcedure , gasProposedIn = epochNoFromLedger gasProposedIn , gasExpiresAfter = epochNoFromLedger gasExpiresAfter - } \ No newline at end of file + } diff --git a/tests/GeniusYield/Test/Providers/Mashup.hs b/tests/GeniusYield/Test/Providers/Mashup.hs index 1938056d..178644b8 100644 --- a/tests/GeniusYield/Test/Providers/Mashup.hs +++ b/tests/GeniusYield/Test/Providers/Mashup.hs @@ -33,18 +33,13 @@ providersMashupTests configs = dats <- forM configs $ \config -> withCfgProviders config mempty $ \GYProviders {..} -> fromJust <$> gyLookupDatum "a7ed3e81ef2e98a85c8d5649ed6344b7f7b36a31103ab18395ef4e80b8cac565" -- A datum hash seen at always fail script's address. assertBool "Datums are not all equal" $ allEqual dats , testCase "Fetching constitution" $ do - let supportedProviders = - filter - ( \(cfgCoreProvider -> cp) -> case cp of - GYMaestro {} -> False - GYBlockfrost {} -> False - _anyOther -> True - ) - configs - constitutions <- forM supportedProviders $ \config -> withCfgProviders config mempty $ \GYProviders {..} -> do + constitutions <- forM (supportedProviders configs) $ \config -> withCfgProviders config mempty $ \GYProviders {..} -> do gyGetConstitution - print constitutions assertBool "Constitutions are not all equal" $ allEqual constitutions + , testCase "Fetching proposals" $ do + proposalsList <- forM (supportedProviders configs) $ \config -> withCfgProviders config mempty $ \GYProviders {..} -> do + gyGetProposals mempty + assertBool "Proposals are not all equal" $ allEqual proposalsList , testCase "Parameters" $ do paramsList <- forM configs $ \config -> withCfgProviders config mempty $ \provider -> do delayBySecond @@ -178,3 +173,12 @@ providersMashupTests configs = allEqual :: Eq a => [a] -> Bool allEqual [] = True allEqual (x : xs) = all (== x) xs + +supportedProviders :: [GYCoreConfig] -> [GYCoreConfig] +supportedProviders = + filter + ( \(cfgCoreProvider -> cp) -> case cp of + GYMaestro {} -> False + GYBlockfrost {} -> False + _anyOther -> True + ) From 163784590a887c24bba861adbd5d566d13c0e303 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 24 Feb 2025 18:04:01 +0530 Subject: [PATCH 9/9] feat(#408): temporarily omit committee tests --- src/GeniusYield/Providers/Node.hs | 6 ++++++ src/GeniusYield/Test/Privnet/Ctx.hs | 1 + tests-privnet/atlas-privnet-tests.hs | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/GeniusYield/Providers/Node.hs b/src/GeniusYield/Providers/Node.hs index d7c7ca25..1044894f 100644 --- a/src/GeniusYield/Providers/Node.hs +++ b/src/GeniusYield/Providers/Node.hs @@ -17,13 +17,16 @@ module GeniusYield.Providers.Node ( nodeGetDRepsState, nodeConstitution, nodeProposals, + nodeCommitteeMembersState, -- * Auxiliary networkIdToLocalNodeConnectInfo, ) where import Cardano.Api qualified as Api +import Cardano.Api.Ledger qualified as Ledger import Cardano.Api.Shelley qualified as Api.S +import Cardano.Ledger.Api.State.Query qualified as Ledger import Cardano.Ledger.Coin qualified as Ledger import Cardano.Slotting.Time (SystemStart) import Control.Exception (throwIO) @@ -96,6 +99,9 @@ nodeProposals :: Api.LocalNodeConnectInfo -> Set.Set GYGovActionId -> IO (Seq.Se nodeProposals info (Set.map govActionIdToLedger -> proposals) = do fmap govActionStateFromLedger <$> queryConwayEra info (Api.QueryProposals proposals) +nodeCommitteeMembersState :: Api.LocalNodeConnectInfo -> IO (Ledger.CommitteeMembersState Ledger.StandardCrypto) +nodeCommitteeMembersState info = queryConwayEra info $ Api.QueryCommitteeMembersState mempty mempty mempty + nodeStakePools :: Api.LocalNodeConnectInfo -> IO (Set.Set Api.S.PoolId) nodeStakePools info = queryConwayEra info Api.QueryStakePools diff --git a/src/GeniusYield/Test/Privnet/Ctx.hs b/src/GeniusYield/Test/Privnet/Ctx.hs index 2b96983d..137726b9 100644 --- a/src/GeniusYield/Test/Privnet/Ctx.hs +++ b/src/GeniusYield/Test/Privnet/Ctx.hs @@ -96,6 +96,7 @@ data CtxCommittee = CtxCommittee , ctxCommitteeThreshold :: !UnitInterval -- ^ Threshold of the committee that is necessary for a successful vote } + deriving stock Show ctxNetworkId :: Ctx -> GYNetworkId ctxNetworkId Ctx {ctxNetworkInfo} = GYPrivnet ctxNetworkInfo diff --git a/tests-privnet/atlas-privnet-tests.hs b/tests-privnet/atlas-privnet-tests.hs index d35fd44f..c9f3fecc 100644 --- a/tests-privnet/atlas-privnet-tests.hs +++ b/tests-privnet/atlas-privnet-tests.hs @@ -15,6 +15,7 @@ import Test.Tasty.HUnit (testCaseSteps) import GeniusYield.CardanoApi.EraHistory import GeniusYield.Types +import GeniusYield.Providers.Node (nodeCommitteeMembersState) import GeniusYield.Test.Privnet.Blueprint qualified import GeniusYield.Test.Privnet.Committee qualified import GeniusYield.Test.Privnet.Ctx @@ -63,6 +64,10 @@ main = do pp <- ctxRunQuery ctx protocolParams info $ printf "Protocol parameters: %s" (show pp) + , testCaseSteps "Committee state" $ \info -> withSetup info setup $ \ctx -> do + cs <- nodeCommitteeMembersState (ctxInfo ctx) + info $ "Committee members state: " <> show cs <> "\n" + info $ "Committee as present in Ctx: " <> show (ctxCommittee ctx) <> "\n" , GeniusYield.Test.Privnet.Blueprint.blueprintTests setup , GeniusYield.Test.Privnet.Examples.tests setup , GeniusYield.Test.Privnet.Stake.stakeKeyTests setup @@ -70,6 +75,6 @@ main = do , GeniusYield.Test.Privnet.SimpleScripts.simpleScriptsTests setup , GeniusYield.Test.Privnet.DRep.drepTests setup , GeniusYield.Test.Privnet.StakePool.stakePoolTests setup - , GeniusYield.Test.Privnet.Committee.committeeTests setup - , GeniusYield.Test.Privnet.Gov.govTests setup + -- , GeniusYield.Test.Privnet.Committee.committeeTests setup + -- , GeniusYield.Test.Privnet.Gov.govTests setup ]