From 6e9b54589f331ed70847a8449f560810a8a08a54 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 17 Apr 2024 15:51:48 +0530 Subject: [PATCH 1/2] feat: add support of both v1 & v1.1 family of scripts Closes #100. --- Dockerfile | 5 - README.md | 2 - cabal.project | 18 +- compiled-scripts/minting-policy | 13 - compiled-scripts/partial-order | 12 - geniusyield-dex-api/geniusyield-dex-api.cabal | 107 ---- .../src/GeniusYield/DEX/Api/PartialOrder.hs | 543 ------------------ .../GeniusYield/DEX/Api/PartialOrderConfig.hs | 114 ---- .../src/GeniusYield/DEX/Api/Types.hs | 96 ---- .../src/GeniusYield/DEX/Api/Utils.hs | 80 --- .../geniusyield-orderbot-framework.cabal | 3 +- .../lib-common/GeniusYield/OrderBot/Types.hs | 2 +- .../GeniusYield/OrderBot/DataSource.hsig | 33 +- .../GeniusYield/OrderBot/OrderBook.hsig | 6 +- .../src/GeniusYield/OrderBot.hs | 27 +- .../GeniusYield/OrderBot/MatchingStrategy.hs | 24 +- geniusyield-orderbot.cabal | 1 + geniusyield-orderbot/src/Main.hs | 21 +- geniusyield-orderbot/src/OrderBotConfig.hs | 81 +-- .../OrderBot/DataSource/Providers.hs | 26 +- .../GeniusYield/OrderBot/OrderBook/List.hs | 24 +- 21 files changed, 76 insertions(+), 1162 deletions(-) delete mode 100644 compiled-scripts/minting-policy delete mode 100644 compiled-scripts/partial-order delete mode 100644 geniusyield-dex-api/geniusyield-dex-api.cabal delete mode 100644 geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrder.hs delete mode 100644 geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrderConfig.hs delete mode 100644 geniusyield-dex-api/src/GeniusYield/DEX/Api/Types.hs delete mode 100644 geniusyield-dex-api/src/GeniusYield/DEX/Api/Utils.hs diff --git a/Dockerfile b/Dockerfile index 2250be6..cce8b98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,11 +46,9 @@ WORKDIR /SOR RUN cabal update COPY cabal.project ./ COPY geniusyield-orderbot.cabal ./ -COPY geniusyield-dex-api/geniusyield-dex-api.cabal ./geniusyield-dex-api/ COPY geniusyield-orderbot-framework/geniusyield-orderbot-framework.cabal geniusyield-orderbot-framework/ RUN cabal update -RUN cabal build geniusyield-dex-api --only-dependencies COPY . . @@ -62,15 +60,12 @@ RUN cabal install --global LABEL org.opencontainers.image.source="https://github.com/geniusyield/smart-order-router" # Default values: -ENV BOTC_FP_NFT_POLICY='compiled-scripts/minting-policy' -ENV BOTC_FP_ORDER_VALIDATOR='compiled-scripts/partial-order' ENV BOTC_EXECUTION_STRAT='OneSellToManyBuy' ENV BOTC_RESCAN_DELAY='30000000' ENV BOTC_MAX_ORDERS_MATCHES='5' ENV BOTC_MAX_TXS_PER_ITERATION='4' ENV BOTC_RANDOMIZE_MATCHES_FOUND='True' ENV BOTC_ASSET_FILTER='[{ "commodityAsset" : "1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e.776f726c646d6f62696c65746f6b656e", "currencyAsset" : "lovelace"},{ "commodityAsset" : "1ddcb9c9de95361565392c5bdff64767492d61a96166cb16094e54be.4f5054", "currencyAsset" : "lovelace"},{ "commodityAsset" : "25f0fc240e91bd95dcdaebd2ba7713fc5168ac77234a3d79449fc20c.534f4349455459", "currencyAsset" : "lovelace"},{ "commodityAsset" : "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f.534e454b", "currencyAsset" : "lovelace"},{ "commodityAsset" : "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6.4d494e", "currencyAsset" : "lovelace"},{ "commodityAsset" : "51a5e236c4de3af2b8020442e2a26f454fda3b04cb621c1294a0ef34.424f4f4b", "currencyAsset" : "lovelace"},{ "commodityAsset" : "533bb94a8850ee3ccbe483106489399112b74c905342cb1792a797a0.494e4459", "currencyAsset" : "lovelace"},{ "commodityAsset" : "5c1c91a65bedac56f245b8184b5820ced3d2f1540e521dc1060fa683.4a454c4c59", "currencyAsset" : "lovelace"},{ "commodityAsset" : "5d16cc1a177b5d9ba9cfa9793b07e60f1fb70fea1f8aef064415d114.494147", "currencyAsset" : "lovelace"},{ "commodityAsset" : "5dac8536653edc12f6f5e1045d8164b9f59998d3bdc300fc92843489.4e4d4b52", "currencyAsset" : "lovelace"},{ "commodityAsset" : "681b5d0383ac3b457e1bcc453223c90ccef26b234328f45fa10fd276.4a5047", "currencyAsset" : "lovelace"},{ "commodityAsset" : "682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63.4e45574d", "currencyAsset" : "lovelace"},{ "commodityAsset" : "6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d10.4d454c44", "currencyAsset" : "lovelace"},{ "commodityAsset" : "6c8642400e8437f737eb86df0fc8a8437c760f48592b1ba8f5767e81.456d706f7761", "currencyAsset" : "lovelace"},{ "commodityAsset" : "75fcc276057db5fc48eae0e11453c773c8a54604c3086bf9d95ac1b7.43485259", "currencyAsset" : "lovelace"},{ "commodityAsset" : "7914fae20eb2903ed6fd5021a415c1bd2626b64a2d86a304cb40ff5e.4c494649", "currencyAsset" : "lovelace"},{ "commodityAsset" : "804f5544c1962a40546827cab750a88404dc7108c0f588b72964754f.56594649", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa.4d494c4b", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8cfd6893f5f6c1cc954cec1a0a1460841b74da6e7803820dde62bb78.524a56", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8daefa391220bd0d8d007f3748d870f7f3c106040314c8515ccc35a5.464c4143", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61.446a65644d6963726f555344", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61.5368656e4d6963726f555344", "currencyAsset" : "lovelace"},{ "commodityAsset" : "8fef2d34078659493ce161a6c7fba4b56afefa8535296a5743f69587.41414441", "currencyAsset" : "lovelace"},{ "commodityAsset" : "95a427e384527065f2f8946f5e86320d0117839a5e98ea2c0b55fb00.48554e54", "currencyAsset" : "lovelace"},{ "commodityAsset" : "9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77.53554e444145", "currencyAsset" : "lovelace"},{ "commodityAsset" : "9abf0afd2f236a19f2842d502d0450cbcd9c79f123a9708f96fd9b96.454e4353", "currencyAsset" : "lovelace"},{ "commodityAsset" : "a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235.484f534b59", "currencyAsset" : "lovelace"},{ "commodityAsset" : "a3931691f5c4e65d01c429e473d0dd24c51afdb6daf88e632a6c1e51.6f7263666178746f6b656e", "currencyAsset" : "lovelace"},{ "commodityAsset" : "b34b3ea80060ace9427bda98690a73d33840e27aaa8d6edb7f0c757a.634e455441", "currencyAsset" : "lovelace"},{ "commodityAsset" : "b6a7467ea1deb012808ef4e87b5ff371e85f7142d7b356a40d9b42a0.436f726e75636f70696173205b76696120436861696e506f72742e696f5d", "currencyAsset" : "lovelace"},{ "commodityAsset" : "c0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d5073.57696e67526964657273", "currencyAsset" : "lovelace"},{ "commodityAsset" : "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d24.4c51", "currencyAsset" : "lovelace"},{ "commodityAsset" : "dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53", "currencyAsset" : "lovelace"},{ "commodityAsset" : "e52964af4fffdb54504859875b1827b60ba679074996156461143dc1.4f5054494d", "currencyAsset" : "lovelace"},{ "commodityAsset" : "edfd7a1d77bcb8b884c474bdc92a16002d1fb720e454fa6e99344479.4e5458", "currencyAsset" : "lovelace"},{ "commodityAsset" : "f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958", "currencyAsset" : "lovelace"},{ "commodityAsset" : "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880.69425443", "currencyAsset" : "lovelace"},{ "commodityAsset" : "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880.69455448", "currencyAsset" : "lovelace"},{ "commodityAsset" : "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880.69555344", "currencyAsset" : "lovelace"},{ "commodityAsset" : "fbae99b8679369079a7f6f0da14a2cf1c2d6bfd3afdf3a96a64ab67a.0014df1047454e5358", "currencyAsset" : "lovelace"},{ "commodityAsset" : "577f0b1342f8f8f4aed3388b80a8535812950c7a892495c0ecdf0f1e.0014df10464c4454", "currencyAsset" : "lovelace"},{ "commodityAsset" : "fc11a9ef431f81b837736be5f53e4da29b9469c983d07f321262ce61.4652454e", "currencyAsset" : "lovelace"},{ "commodityAsset" : "af2e27f580f7f08e93190a81f72462f153026d06450924726645891b.44524950", "currencyAsset" : "lovelace"}]' -ENV BOTC_POREFS='{ "refAddr": "addr1w9zr09hgj7z6vz3d7wnxw0u4x30arsp5k8avlcm84utptls8uqd0z", "refNftAC": "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.4aff78908ef2dce98bfe435fb3fd2529747b1c4564dff5adebedf4e46d0fc63d", "nftPolicyRef": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#1" , "scriptRef": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#2" }' ENTRYPOINT ["/bin/bash", "./start.sh"] diff --git a/README.md b/README.md index 9adffa3..9a10e39 100644 --- a/README.md +++ b/README.md @@ -472,8 +472,6 @@ For running the tests we can just simply execute `make orderbot-tests`. The SOR is organized into 5 main folders: -- [`compiled-scripts`](./compiled-scripts), contains the compiled validator and minting policy of the DEX. -- [`geniusyield-dex-api`](./geniusyield-dex-api), defines the DEX interface to query and build transactions. - [`geniusyield-orderbot-framework`](./geniusyield-orderbot-framework), implement the main abstract tools for the SOR. - [`geniusyield-orderbot`](./geniusyield-orderbot), the executable is implemented here, together with the strategies. - [`impl`](./impl), specific implementations of the orderbook and data-provider. diff --git a/cabal.project b/cabal.project index 482749e..5f87f4a 100644 --- a/cabal.project +++ b/cabal.project @@ -17,7 +17,6 @@ index-state: , cardano-haskell-packages 2023-06-05T06:39:32Z packages: . -packages: geniusyield-dex-api packages: geniusyield-orderbot-framework -- TODO: Default value should be @direct@ in upcoming 3.10 version of cabal, omit this line then. @@ -33,8 +32,8 @@ package strict-containers source-repository-package type: git location: https://github.com/maestro-org/haskell-sdk - tag: fb8e32869f7a8f5fa2585b542e4eb4207eaf735b - --sha256: sha256-LOiC9zPXjPFshKfb/SKkFBkAFnOuQDwCqeDB7ZyB3b0= + tag: 609515b3f8861efaa17adf4e599aa1b845775a6d + --sha256: sha256-8se+xlIB1BDEuKGwjaldmW5G4LpCujD1ABgBaY0cY6Y= -- Unfortunately, cardano-node 8.1.2 is constrained with plutus-ledger-api 1.5.0.0 and we would like at least 1.6.0.0. -- This is done in accordance with changes in https://github.com/input-output-hk/cardano-ledger/pull/3430/files. @@ -64,8 +63,17 @@ source-repository-package source-repository-package type: git location: https://github.com/geniusyield/atlas - tag: be490dcc5b99d0ff10e9d7cd801c4e0ae3a4865a - --sha256: sha256-HxwD8p7eg1yMo3hVDtGduU9zOQobFPONKj+064fdjVU= + tag: 105ff78b32935ae5c18c53ccf4fb8462b8c1ca03 + --sha256: sha256-Ee/UIoJ8OYBxgdnSv61hN8DH7CrIOPn4DjqOBxFL3Js= + +source-repository-package + type: git + location: https://github.com/geniusyield/dex-contracts-api + tag: ef2904d2d06dd068e5b4e2ac2513bcf61d2ca74c + --sha256: sha256-vXA5mVG7POEbezxMUQlxfyQbApdX5kG7L9BRlar+th0= + subdir: + geniusyield-dex-api + geniusyield-onchain/geniusyield-common source-repository-package type: git diff --git a/compiled-scripts/minting-policy b/compiled-scripts/minting-policy deleted file mode 100644 index 8b8521b..0000000 --- a/compiled-scripts/minting-policy +++ /dev/null @@ -1,13 +0,0 @@ -{ - "cborHex": "591157591154010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323222222323232323232323232325333038303f304600213232323232323232323232323232533304700116153330465330393303e23303900f304630410010081533039303530440011533039304e375a60aa608a002266e3cdd7182a18228008048991999821918281981c1bab30473046304200100200823232533304a533304a3051305800214a0266e3c084dd7182480089919191919191919191919191919191919191919191919191919191919191929998349838983b80109919192999836183b8098a99983619b870120131533306c3371e6eb8c1ac0680bc54ccc1b0c1cc04454ccc1b0c1dc03c54ccc1b0c15ccc17801c01854ccc1b1288a99983619baf00e00a1533306c3370e01a0522a6660d86609e6eacc1acc1a8c198094c120ccc149c0198220039ba801330483330527006608804c0e060906660a4e00cc110cc16522010048810037500506666608a00e00c0140120102a6660d860e66eb402054ccc1b14cc17ccdc48159bad00a133712609c66098609605460940266eb402454ccc1b0c1cc040418458585858585858585858585858c1e8008c1e0004dd5183400a8991929998359839183c8010a999835983b0090a99983599b870110121533306b3371e6eb8c1a80640b854ccc1acc1c804054ccc1acc1d803854ccc1acc158cc17401801454ccc1accdc49bad306a003375a60d40022a6660d666ebc03402454ccc1accdc38060140a999835998271bab306a3069306502430473330517006608600c6ea0048c11cccc145c0198218128379823999828b803304333058488100488100375004e6666608800c00a01201000e2a6660d660e46eb401c54ccc1ad4cc178cdc48151bad009133712609a66096609405260920246eb402054ccc1acc1c803c41805858585858585858585858585854ccc1acc1d804854ccc1accdc38088090a99983599b8f375c60d403205c2a6660d660e40202a6660d660ec01c2a6660d660ac660ba00c00a2a6660d694454ccc1accdd78068048a99983599b8700c0281533306b3304e375660d460d260ca048608e6660a2e00cc10c018dd40091823999828b803304302506f304733305170066086660b091100488100375004e6666608800c00a01201000e2a6660d660e46eb401c54ccc1ad4cc178cdc48151bad009133712609a66096609405260920246eb402054ccc1acc1c803c418058585858585858585858585858c1e4004dd5183400a983b8009baa3066014306501630640183063306200330620023061002305f001305a305f008375a60bc01060ba0106eb4c170c15cc170030dd6982d982d0021bad305a006375a60b20186eb4c160028c158004c154004c150004c14c004c148004c144004c140004c13c004c138004c134004c130004c12cc12cc11d4ccc134c1540084ccccc1108c888c00800cc174004dd49bae304c00100d232323200453330503057305e00215333050305a371a6eb8c13c0044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc188c1a4c1c00044c8c8c8c94ccc198cdd79ba7306400250731325333067337126e34dd71833000a4080264646464646464646464646464646464646464646464640e6a6660fc60f600420e42c6eb4c1ec004c1e40114ccc1e8c20404c220040084c8c8c8c8c8c81d54ccc20004c1f400841d058dd6983e800983d8011bad307b0013079002375a60f20022c6110020026ea8c1dc004c1d4008dd6983a80098398011bad30730013071002375a60e200260de00aa6660e060ee0042a6660e060f86eb4c1bc0044c81994ccc1c4c1b80044194585854ccc1c0c1e00084c81994ccc1c400441945858c1f8008c1f0004dd518360009835002a99983598390010a999835983b9bad306a001132061533306c3069001106016161533306b3073002132061533306c0011060161630790023077001375460ce00260ca0022c60c800c2c6ea0c144dd6983200098310011bad3062001307100116375460c000260bc008a6660be60cc60da004264a6660c0a660b260ce002260d4002264a6660c266e24dc69bae3060001481004c815d4ccc188c17c00441585858c17800858dc69bae305e00116306d001375460b800260b40046eb4c168004c160008dd6982c000982b002299982b982f1832801099299982c299828982f80089831000899299982c99b89371a6eb8c160005204013204f533305a3057001104e1616305600216371a6eb8c15800458c194004dd5182a00098290022999829982d1830801099191919191919191919029299982e982d00288288b299982d98310010991919191902aa999830182e802882a0b299982f18328010991919191902c29998319830002882b8b299983098340010a99983098359b8d375c60c00022640aea6660c460be00220ac2c2c2a6660c260d20042a6660c260d66e34dd7183000089902ba999831182f800882b0b0b0b183780118368009baa305d0011533305e3066002132323232323205953330643061002105816375a60c200260be0046eb4c17c004c174008dd6982e8008b183600118350009baa305a0011533305b3063002132051533305c0011050161630690023067001375460ae00260aa00aa6660ac60ba0042a6660ac60c06e34dd7182a800899026299982b982a00088258b0b0a99982b182f0010a99982b18301b8d375c60aa002264098a6660ae60a800220962c2c2c60c800460c40026ea8c14800458c184004dd5182800098270008b0b182f0009baa001161533304d305600213232323200453330503057305e00215333050305a371a6eb8c13c0044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc188c1a4c1c00044c8c8c8c94ccc198cdd79ba7306400250731325333067337126e34dd71833000a4080264646464646464646464646464646464646464646464640e6a6660fc60f600420e42c6eb4c1ec004c1e40114ccc1e8c20404c220040084c8c8c8c8c8c81d54ccc20004c1f400841d058dd6983e800983d8011bad307b0013079002375a60f20022c6110020026ea8c1dc004c1d4008dd6983a80098398011bad30730013071002375a60e200260de00aa6660e060ee0042a6660e060f86eb4c1bc0044c81994ccc1c4c1b80044194585854ccc1c0c1e00084c81994ccc1c400441945858c1f8008c1f0004dd518360009835002a99983598390010a999835983b9bad306a001132061533306c3069001106016161533306b3073002132061533306c0011060161630790023077001375460ce00260ca0022c60c800c2c6ea0c144dd6983200098310011bad3062001307100116375460c000260bc008a6660be60cc60da004264a6660c0a660b260ce002260d4002264a6660c266e24dc69bae3060001481004c815d4ccc188c17c00441585858c17800858dc69bae305e00116306d001375460b800260b40046eb4c168004c160008dd6982c000982b002299982b982f1832801099299982c299828982f80089831000899299982c99b89371a6eb8c160005204013204f533305a3057001104e1616305600216371a6eb8c15800458c194004dd5182a00098290022999829982d1830801099191919191919191919029299982e982d00288288b299982d98310010991919191902aa999830182e802882a0b299982f18328010991919191902c29998319830002882b8b299983098340010a99983098359b8d375c60c00022640aea6660c460be00220ac2c2c2a6660c260d20042a6660c260d66e34dd7183000089902ba999831182f800882b0b0b0b183780118368009baa305d0011533305e3066002132323232323205953330643061002105816375a60c200260be0046eb4c17c004c174008dd6982e8008b183600118350009baa305a0011533305b3063002132051533305c0011050161630690023067001375460ae00260aa00aa6660ac60ba0042a6660ac60c06e34dd7182a800899026299982b982a00088258b0b0a99982b182f0010a99982b18301b8d375c60aa002264098a6660ae60a800220962c2c2c60c800460c40026ea8c14800458c184004dd5182800098270008b0b182f0009baa001304c00116305b0023059001375460926090609060880062c60b00026ea8c11cc108c11cc10800458cc0cc05802458cccc0ec054040800458dd6982198210049bad30420083041008375a60800106eacc0fcc0f8c0d0c0f8030dd6181f0061bac303d00d372466e2cdd6981e181d8009bae303c3037303c001303600430390013038001302d3033333303523253302e3302d303a001011130433302b37566074607200202060686072607060680026eb0c0e001c8c8c94ccc0f0c114c1280084c0ec00458c128004dd5181c981c181c181a181c981c181a0008b181b8008a99981c19818118229bad3048001333302e00800320011616102d304600137540146eacc0d0004c0c8c0c8004c0c4004c0c0004c0acc0c0c0ac0114ccc0c0c0dcc0f80084dd718178008b181f0009baa302d302c3028001223232533302c3375e00605e05c26600e0046e98cc01c00400cc0a8c0a4c09400cc0a4c09000888888ccc049c0198031980ca45004881000033330127006600c00a0046600c008002446464a66605466e24dd6801a400005826600a0046e98cc01400400cc0a0c09cc08c00cc09cc08800888cc054cdd800100081611980111919a999813980b000891280089118010019191118010019ba6001122500133003253330273375e002054244a00224460040066eac00400488cc088894ccc0a00040a44c8ccc014c0dcc09c0088cc05ccdd8181b981400180080108009801181280080091198008012400446464644660020060046eb4c08cc088008dd69811000980e00091180111180191191919191919191911980080180119b820023370600c00666e08004cdc1803001299981598190020a40002a66605666e2401120001480045200233025533302a3371200400220022004a66605466e2400800440084004c028008c024008cdc100200119b8200400225333020337120029000898050008800919299981018011119b88302800233704900000088008a99981018011119b873028002337046008e1000440044cdc0240040026002e1088cc0108cc0148c0b4dd698180009bab302f0013330057000046600646e98cc0108dd418059bad0013756002002446603644a66604200204426601c66ec0c0b8c07c004c010c0bcc07c004c008c0780040048c064894ccc07c0045288a998089801980e80089801180e000911199802111ba63330062237506600e6eb4008dd68009bab00237560020040024446666032446600244a666042004200226666008010603e004603c004002444a66604400226601e0060042646464a66604866ebc0080044cc048cdd8001198059819803181980199980400680298110020a99981219b90375c0046eb80044cc048018cccc02003000cc0880100144cc04800ccccc020030018014c088010c0c4008c0c0010c0800040140080048800488008dc0a4000466602c002941289299980a99b890014800058400488cdd2a4000660066ea4008cc00cdd4800a5eb815d02ba322323333004375c6024601a00490001199980280124000eb4dd58008019bae30113010300c001232222330112253330170011005153330163375e6048602a00200c26008604a602a0022600460280020026ea400488cdd79ba7300a002374e60140024466601e00400229408c02cc02cc02cc02c00526233002232223002003375660360026ea4004888cc024894ccc03c004489400454ccc038cdd7980e1806800802098029806800898011806000800918031129998060008a5015330043003300a00113002300900123300800114a24602c6ea8004c0088894ccc020c03c00440084cc00c004cdc30010009800911299980400089128008a9998039801180300089911180100198030008998018011802800919180111980100100091801119801001000aba25742ae6955cf8801a610100004c010101004bd6f7b6301b8248008dc3a40006e1d2002370e90021b87480e0dc4240006e2520001374e97ae05573aaae79", - "description": "DEX.PartialOrderNFT", - "params": [ - "PlutusLedgerApi.V1.Scripts:ScriptHash", - "PlutusLedgerApi.V1.Address:Address", - "PlutusLedgerApi.V1.Value:AssetClass" - ], - "rawHex": "591154010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323222222323232323232323232325333038303f304600213232323232323232323232323232533304700116153330465330393303e23303900f304630410010081533039303530440011533039304e375a60aa608a002266e3cdd7182a18228008048991999821918281981c1bab30473046304200100200823232533304a533304a3051305800214a0266e3c084dd7182480089919191919191919191919191919191919191919191919191919191919191929998349838983b80109919192999836183b8098a99983619b870120131533306c3371e6eb8c1ac0680bc54ccc1b0c1cc04454ccc1b0c1dc03c54ccc1b0c15ccc17801c01854ccc1b1288a99983619baf00e00a1533306c3370e01a0522a6660d86609e6eacc1acc1a8c198094c120ccc149c0198220039ba801330483330527006608804c0e060906660a4e00cc110cc16522010048810037500506666608a00e00c0140120102a6660d860e66eb402054ccc1b14cc17ccdc48159bad00a133712609c66098609605460940266eb402454ccc1b0c1cc040418458585858585858585858585858c1e8008c1e0004dd5183400a8991929998359839183c8010a999835983b0090a99983599b870110121533306b3371e6eb8c1a80640b854ccc1acc1c804054ccc1acc1d803854ccc1acc158cc17401801454ccc1accdc49bad306a003375a60d40022a6660d666ebc03402454ccc1accdc38060140a999835998271bab306a3069306502430473330517006608600c6ea0048c11cccc145c0198218128379823999828b803304333058488100488100375004e6666608800c00a01201000e2a6660d660e46eb401c54ccc1ad4cc178cdc48151bad009133712609a66096609405260920246eb402054ccc1acc1c803c41805858585858585858585858585854ccc1acc1d804854ccc1accdc38088090a99983599b8f375c60d403205c2a6660d660e40202a6660d660ec01c2a6660d660ac660ba00c00a2a6660d694454ccc1accdd78068048a99983599b8700c0281533306b3304e375660d460d260ca048608e6660a2e00cc10c018dd40091823999828b803304302506f304733305170066086660b091100488100375004e6666608800c00a01201000e2a6660d660e46eb401c54ccc1ad4cc178cdc48151bad009133712609a66096609405260920246eb402054ccc1acc1c803c418058585858585858585858585858c1e4004dd5183400a983b8009baa3066014306501630640183063306200330620023061002305f001305a305f008375a60bc01060ba0106eb4c170c15cc170030dd6982d982d0021bad305a006375a60b20186eb4c160028c158004c154004c150004c14c004c148004c144004c140004c13c004c138004c134004c130004c12cc12cc11d4ccc134c1540084ccccc1108c888c00800cc174004dd49bae304c00100d232323200453330503057305e00215333050305a371a6eb8c13c0044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc188c1a4c1c00044c8c8c8c94ccc198cdd79ba7306400250731325333067337126e34dd71833000a4080264646464646464646464646464646464646464646464640e6a6660fc60f600420e42c6eb4c1ec004c1e40114ccc1e8c20404c220040084c8c8c8c8c8c81d54ccc20004c1f400841d058dd6983e800983d8011bad307b0013079002375a60f20022c6110020026ea8c1dc004c1d4008dd6983a80098398011bad30730013071002375a60e200260de00aa6660e060ee0042a6660e060f86eb4c1bc0044c81994ccc1c4c1b80044194585854ccc1c0c1e00084c81994ccc1c400441945858c1f8008c1f0004dd518360009835002a99983598390010a999835983b9bad306a001132061533306c3069001106016161533306b3073002132061533306c0011060161630790023077001375460ce00260ca0022c60c800c2c6ea0c144dd6983200098310011bad3062001307100116375460c000260bc008a6660be60cc60da004264a6660c0a660b260ce002260d4002264a6660c266e24dc69bae3060001481004c815d4ccc188c17c00441585858c17800858dc69bae305e00116306d001375460b800260b40046eb4c168004c160008dd6982c000982b002299982b982f1832801099299982c299828982f80089831000899299982c99b89371a6eb8c160005204013204f533305a3057001104e1616305600216371a6eb8c15800458c194004dd5182a00098290022999829982d1830801099191919191919191919029299982e982d00288288b299982d98310010991919191902aa999830182e802882a0b299982f18328010991919191902c29998319830002882b8b299983098340010a99983098359b8d375c60c00022640aea6660c460be00220ac2c2c2a6660c260d20042a6660c260d66e34dd7183000089902ba999831182f800882b0b0b0b183780118368009baa305d0011533305e3066002132323232323205953330643061002105816375a60c200260be0046eb4c17c004c174008dd6982e8008b183600118350009baa305a0011533305b3063002132051533305c0011050161630690023067001375460ae00260aa00aa6660ac60ba0042a6660ac60c06e34dd7182a800899026299982b982a00088258b0b0a99982b182f0010a99982b18301b8d375c60aa002264098a6660ae60a800220962c2c2c60c800460c40026ea8c14800458c184004dd5182800098270008b0b182f0009baa001161533304d305600213232323200453330503057305e00215333050305a371a6eb8c13c0044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc188c1a4c1c00044c8c8c8c94ccc198cdd79ba7306400250731325333067337126e34dd71833000a4080264646464646464646464646464646464646464646464640e6a6660fc60f600420e42c6eb4c1ec004c1e40114ccc1e8c20404c220040084c8c8c8c8c8c81d54ccc20004c1f400841d058dd6983e800983d8011bad307b0013079002375a60f20022c6110020026ea8c1dc004c1d4008dd6983a80098398011bad30730013071002375a60e200260de00aa6660e060ee0042a6660e060f86eb4c1bc0044c81994ccc1c4c1b80044194585854ccc1c0c1e00084c81994ccc1c400441945858c1f8008c1f0004dd518360009835002a99983598390010a999835983b9bad306a001132061533306c3069001106016161533306b3073002132061533306c0011060161630790023077001375460ce00260ca0022c60c800c2c6ea0c144dd6983200098310011bad3062001307100116375460c000260bc008a6660be60cc60da004264a6660c0a660b260ce002260d4002264a6660c266e24dc69bae3060001481004c815d4ccc188c17c00441585858c17800858dc69bae305e00116306d001375460b800260b40046eb4c168004c160008dd6982c000982b002299982b982f1832801099299982c299828982f80089831000899299982c99b89371a6eb8c160005204013204f533305a3057001104e1616305600216371a6eb8c15800458c194004dd5182a00098290022999829982d1830801099191919191919191919029299982e982d00288288b299982d98310010991919191902aa999830182e802882a0b299982f18328010991919191902c29998319830002882b8b299983098340010a99983098359b8d375c60c00022640aea6660c460be00220ac2c2c2a6660c260d20042a6660c260d66e34dd7183000089902ba999831182f800882b0b0b0b183780118368009baa305d0011533305e3066002132323232323205953330643061002105816375a60c200260be0046eb4c17c004c174008dd6982e8008b183600118350009baa305a0011533305b3063002132051533305c0011050161630690023067001375460ae00260aa00aa6660ac60ba0042a6660ac60c06e34dd7182a800899026299982b982a00088258b0b0a99982b182f0010a99982b18301b8d375c60aa002264098a6660ae60a800220962c2c2c60c800460c40026ea8c14800458c184004dd5182800098270008b0b182f0009baa001304c00116305b0023059001375460926090609060880062c60b00026ea8c11cc108c11cc10800458cc0cc05802458cccc0ec054040800458dd6982198210049bad30420083041008375a60800106eacc0fcc0f8c0d0c0f8030dd6181f0061bac303d00d372466e2cdd6981e181d8009bae303c3037303c001303600430390013038001302d3033333303523253302e3302d303a001011130433302b37566074607200202060686072607060680026eb0c0e001c8c8c94ccc0f0c114c1280084c0ec00458c128004dd5181c981c181c181a181c981c181a0008b181b8008a99981c19818118229bad3048001333302e00800320011616102d304600137540146eacc0d0004c0c8c0c8004c0c4004c0c0004c0acc0c0c0ac0114ccc0c0c0dcc0f80084dd718178008b181f0009baa302d302c3028001223232533302c3375e00605e05c26600e0046e98cc01c00400cc0a8c0a4c09400cc0a4c09000888888ccc049c0198031980ca45004881000033330127006600c00a0046600c008002446464a66605466e24dd6801a400005826600a0046e98cc01400400cc0a0c09cc08c00cc09cc08800888cc054cdd800100081611980111919a999813980b000891280089118010019191118010019ba6001122500133003253330273375e002054244a00224460040066eac00400488cc088894ccc0a00040a44c8ccc014c0dcc09c0088cc05ccdd8181b981400180080108009801181280080091198008012400446464644660020060046eb4c08cc088008dd69811000980e00091180111180191191919191919191911980080180119b820023370600c00666e08004cdc1803001299981598190020a40002a66605666e2401120001480045200233025533302a3371200400220022004a66605466e2400800440084004c028008c024008cdc100200119b8200400225333020337120029000898050008800919299981018011119b88302800233704900000088008a99981018011119b873028002337046008e1000440044cdc0240040026002e1088cc0108cc0148c0b4dd698180009bab302f0013330057000046600646e98cc0108dd418059bad0013756002002446603644a66604200204426601c66ec0c0b8c07c004c010c0bcc07c004c008c0780040048c064894ccc07c0045288a998089801980e80089801180e000911199802111ba63330062237506600e6eb4008dd68009bab00237560020040024446666032446600244a666042004200226666008010603e004603c004002444a66604400226601e0060042646464a66604866ebc0080044cc048cdd8001198059819803181980199980400680298110020a99981219b90375c0046eb80044cc048018cccc02003000cc0880100144cc04800ccccc020030018014c088010c0c4008c0c0010c0800040140080048800488008dc0a4000466602c002941289299980a99b890014800058400488cdd2a4000660066ea4008cc00cdd4800a5eb815d02ba322323333004375c6024601a00490001199980280124000eb4dd58008019bae30113010300c001232222330112253330170011005153330163375e6048602a00200c26008604a602a0022600460280020026ea400488cdd79ba7300a002374e60140024466601e00400229408c02cc02cc02cc02c00526233002232223002003375660360026ea4004888cc024894ccc03c004489400454ccc038cdd7980e1806800802098029806800898011806000800918031129998060008a5015330043003300a00113002300900123300800114a24602c6ea8004c0088894ccc020c03c00440084cc00c004cdc30010009800911299980400089128008a9998039801180300089911180100198030008998018011802800919180111980100100091801119801001000aba25742ae6955cf8801a610100004c010101004bd6f7b6301b8248008dc3a40006e1d2002370e90021b87480e0dc4240006e2520001374e97ae05573aaae79", - "role": "MintingPolicyRole", - "type": "PlutusScriptV2", - "version": "ScriptV2" -} diff --git a/compiled-scripts/partial-order b/compiled-scripts/partial-order deleted file mode 100644 index 557cada..0000000 --- a/compiled-scripts/partial-order +++ /dev/null @@ -1,12 +0,0 @@ -{ - "cborHex": "5912f95912f6010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232222223232323232323232323232323232323232533304c3054305a002132323232323232333304f23304d0083053304e001375860a400c4646464646464a6660b460c46660a000800400c2646464646464646464646464646464a6660d260e0008264a6660d4660ce44a6660da002294054ccc1b0cdd798358008018a5113002306a001375860d20302a6660d466e1c034c161200213232323232533306f33051333305502300d01501430083333304601000f0030020011533306f53304f3076375a60dc0542660d001860f8660c40e8660c40e8660c40e897ae010631533306f33333304b0140150160744a04666660b00960480024646464646609a6666609802c02a0126ea0cdc09bad00853330753304b002077153330753304a002304730027082002266e040052002100100700530017086608c608a02a4660020060046eb4c1c40d0dd68020a5010631616306d306c003306c002306b00230690013064007161637526eb8c1a00b854ccc1a4c1c40104c94ccc1a8c1d800454ccc1a8cdc400080609929998359981b80098350140a9998359981b0009835013899191919191919191919191999983991299983c80089112800891919a99983d19839802983c80089999983102a9ba9022375660f260f00024a6660f8002244a002264a6660f86108026eb4c22c04c1ec00854ccc1f0c20c04ccc1c8080090004488c00800c48940044894004dd7184480983d000891280089128009299983d99b8f001027132223002233001007004307a00413300530790044a026600860f000600460e660f00040369448c00488c8d4ccc1e94cc1c800c4ccc1e80192825113232233001003002375066e00dd68071bad00933306970000200e246600200401c44646464646464646464a66610a02660ce0080162a66610a0266ebc014c24804cc1e0c21004128cc1e008ccc1e0098cc1e0c2100411ccc1e0dd419b8102701c3307802533078024330783752062660f0610802084660f0610802082660f06ea0cdc01bad30840104048008cc1e0c210040fccc1e004ccc1e0c24804cc1e0dd419b80375a014002660f002e660f06ea0cdc000b00125eb80cc1e0dd400a25eb8054ccc21404cdc49998331119b8000233308401222533308b010011002133003337000049001184400800a40006eacc2580400520000044805041e45858594ccc21004cc1f4090cc1bd221004881001480004cc1e4008cc1bd220100488100330780010233306e001008375661000200aa66610002610e020042c2a66610002611202004260fe002266660ce6eb8c1fc004098800458c23804008c23004004dd5183e183d800983d183b002199834380330620193750012660ca046660c40346ea004058c1d0080cccccc14006406806c0092812513305c3305e488100488100001307102b337006eb4c1c0c1bc0a4004c02001cdd69837183680198368011836001183500098328040b0b183480c8b0b1bad3068003153330693370e01860ae900109929998351981b00098348138a9998351981a80098348130991919299983699827999982981080580980919982e38030060013305600d3750600a01e26464a6660de66666609602802a02c004a660ce002266ebc0081d08ccccc16012c0900048cc1240140044008418c58cc19c02cc1eccc1841cccc1841cccc1841cd2f5c060d804c2c6666608601a01860d600460d600260d660d400260d200260c800e2c2c60d00302c46464646464a6660dc660880040e020022a6660dc6608600460806004e1040044cdc0240040026002e10cc0fcc0f80108cc00400c008dd6983518348011bad30690013063008233054012333057700660a2660a6020028981010100333057700660a20126ea0028004c1d4008c1cc004dd5015983100d98308131830010182f810182f0111bad305d01f333053001005009375660b60186eb0c168030dd5982c982c182c0040827182c182b8011bae30570013055305530513333053232533051330523058001023130613304e375660b060ae00204460a460ae60ac60a40026eb0c1580248c8c94ccc168c18cc1a00084c16400458c1a0004dd5182b982b182b1829182b982b18290008b1bab30553054001304f30543053304f002375c60a60242c60a0002609e609e609e002609c609c002609a0026098002608e609800860960022c60b40026ea8c124c120004c10c03cc118004c114004c110004c10c004c108004c104004c100004c0fc004c0f8004c0f4004c0f0004c0ec004c0e8004c0d400c88c8c94ccc0e4c104c11c008528899804182319816182319816182325eb80cc0b0c01d28a5eb80cc0b0c018dd6981c000a5eb80010c11c004dd5000911919299981c182018230010a5113300730453302b3005375a606e00266056608a6605666e9520044bd701981598032514bd7025eb80010c118004dd5000918209981399ba548008cc09cdd4000a5eb80cc09cc00928a5eb808cdd2999819800a4004900025eb8088c8c94cc0b4cc014c0d0008c0d00044cc014c0d0c0cc004c0d0c0cc008c0b8008c0b400888c8c8c8c8c8c8c8c94ccc0e94ccc0e8cdc40010008a511533303a3370e00400226464a6660786088008266e20dd6981d8011bad303b00114a06094008609200829405288991919299981ea99981e982280109919299981f98239826801099baf374e0066e9c00452818268009baa0081533303d304600213232533303f3048304d00213375e6e9c00cdd38008a50304d001375401026464a66607e608c609a004266ebcdd38019ba700114a0609a0026ea80204ccc0f4c038c0f0c0ec02cc038c0f0c0ec029288a50304b0023049001375400c608e004608c0046ea8008dd5001181a0011819801181680118160011181c181f1baa00122330010024800888c00888c00c88c8c8c8c8c8c8c8c88cc00400c008cdc100119b830060033370400266e0c0180094ccc0e0c0fc01052000153330383371200890000a40022900119819299981b99b8900200110011002533303733712004002200420026014004601200466e08010008cdc10020011299981699b89001480044c06c004400488c00888c00c88cdc399b82001004337040040064460044460064466e20cdc100080219b820020032222233301d7006602e660329110048810000333301d7006602e00a0046602e0080024466604e444a66605c00426602446600e0686eacc0f40040044c94ccc0bc00854cc098cc01c0040d04cc04c8cc020dd5981f00081a98160018991919299981899b8f00200115330293300a004003133007302f006302f00515333031337200040022a660526601400806e26600e605e00c00a2a660526601406e00626600e00c605e00a6eb8c0f8c0bc010dd7181e98170021bab303d302d0023756607860580040040024466604c444a66605a004266022466e2401cdd6981e00080089929998170010a9981299b890010071330122337126eb4c0f4004020c0ac00c4c8c8c94ccc0c0cdc78010008a9981419b89004003133007302e006302e00515333030337200040022a6605066e240100284cc01cc0b801801454cc0a0cdc480500189980380318170029bae303d302e004375c6078605a0086eb4c0f0c0b0008dd6981d9815801001000a40004644460040066eacc0d4004888888cccc0988cc090c0a8c0940040140188c8c8c8c8c8c94ccc0c4cc04ccc074dd598180031bab3030302f00233302070066602444666044e00008dd5982100081b8009980d1980e24410048810000a13008001163756605e0026052a66605e606c0042c2a66605e6070004264646464008a666064607260800042646464646464646464646464064a66607c607600a20622ca6660786086004264646464068a666080607a00820662ca66607c608a6098004264a66607e608c609a002264a66608060866e9cc0f800454ccc100c12cdc69bae303f001132323203753330433040002103616375a6080002607c0062c2c609c0022c6ea8c0f400458c130004dd5181d8008a99981e1822001099018a99981e80088180b0b182500118240009baa303800130360053016375600660286eac008cc0488c8c8c8cdd8299981ca9980c982000189821801898238020b1824002180b1bab30470033301423233760a66607266e24dc69bae3047002481004c11c00858c120008dd698238009bab3046002371a6eb8c110004dd58009819800981880119807919191919191919bb03047007304800730173756608e00ca66606e607c608a008264a666070607e608c002264a66607260786e9cc0dc00454ccc0e4c110dc69bae30380011323232030533303c3039002102f16375a6072002606e0082c2c608e0022c6ea8c0d800858c050dd59822802182200119808919191919bb05333038533018303f003130420031304600416304700430153756608c0066602646466ec14ccc0e0cdc49b8d375c608c0049020098230010b18238011bad30460013756608a0046e34dd718218009bab3043002375460820026eacc0c400458c100004dd500098170008999980b1bae302e00100a23232320045333032303930400021323232323232323232323232032533303e303b005103116533303c30430021323232320345333040303d004103316533303e3045304c002132533303f3046304d00113253330403043374e607c0022a66608060966e34dd7181f800899191901ba9998219820001081b0b1bad3040001303e0031616304e001163754607a0022c60980026ea8c0ec00454ccc0f0c1100084c80c54ccc0f400440c05858c128008c120004dd5181c000981b002980b1bab0033014375600466024464646466ec14ccc0e54cc064c10000c4c10c00c4c11c01058c120010c058dd598238019980a11919bb05333039337126e34dd71823801240802608e0042c60900046eb4c11c004dd598230011b8d375c60880026eac004c0cc004c0c4008cc03c8c8c8c8c8c8c8cdd818238039824003980b9bab30470065333037303e30450041325333038303f30460011325333039303c374e606e0022a66607260886e34dd7181c0008991919018299981e181c80108178b1bad3039001303700416163047001163754606c0042c60286eacc114010c110008cc0448c8c8c8cdd8299981c29980c181f80189821001898230020b1823802180a9bab30460033301323233760a66607066e24dc69bae3046002481004c11800858c11c008dd698230009bab3045002371a6eb8c10c004dd598218011baa3041001375660620022c60800026ea800458c0f4008c0ec004dd5181598150009814981280088011181091299981380081509980c98019812800980118120009199810112999813000890020991299981398008010b0998021812801919b90001003375c60666048002002494094ccc088cc0188cc0180bc0040044004588cc0840045289180e91129998120008801099801998020011811000981080091198021198021b8948000004cc03000800488cc0108c00cdd698178008009119801918019bab302e0010012301922533301f00114a22a6602c6006603a00226004603800244644603644a66604200204826464646464a66604aa66604a6058004294054ccc094c0b40084cccc030dd718120008041198050008028a5013300930240010041375660486046603e604800c2600e604600c606600460620026ea8c084c080c080008c080004c068c07c004894cc058cdd780100209980b80080191980111911180100198150009ba90012223301822533301e00112250011533301d3375e605660380020082600a6038002260046036002002446464a66603666e24dd6801a400003e26600a0046e98cc01400400cc064c060c05000cc060c04c00888cc02ccdd800100080f111812198051ba90023300a375200297ae0223330057000046600646e98cc0108dd418031bad0013756002002446602444a66603000203626601466ec0c094c058004c010c098c058004c008c054004004dc0a4000444666008446e98ccc01888dd4198039bad002375a0026eac008dd58008010009111999808111980091299980c001080089999802004180b001180a801000911299980c8008998058018010991919299980d99baf00200113300e3376000466016605400c605400666601001a00a60320082a66603666e40dd70011bae00113300e006333300800c003301900400513300e003333300800c00600530190043028002302700430170010050020012200122002574093111998018011bae300c3007001375c60186016600e002444666600800490001199980280124000eb4dd58008019191111980591299980880088028a99980819baf301e300f00100613004301f300f00113002300e001001375200244666014004002294088cdd79ba73003002374e60060024602c6ea8004c0088894ccc020c03c00440084cc00c004cdc30010009800911299980400089128008a9998039801180300089911180100198030008998018011802800919180111980100100091801119801001000aba25742ae6955cf919800a400090011baf374e97ae010024c010100004bd6f7b6301b8748000dc3a40046e1d2004370e901c1b8748100dc4240006e9520005573aaae79", - "description": "DEX.PartialOrder", - "params": [ - "PlutusLedgerApi.V1.Address:Address", - "PlutusLedgerApi.V1.Value:AssetClass" - ], - "rawHex": "5912f6010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232222223232323232323232323232323232323232533304c3054305a002132323232323232333304f23304d0083053304e001375860a400c4646464646464a6660b460c46660a000800400c2646464646464646464646464646464a6660d260e0008264a6660d4660ce44a6660da002294054ccc1b0cdd798358008018a5113002306a001375860d20302a6660d466e1c034c161200213232323232533306f33051333305502300d01501430083333304601000f0030020011533306f53304f3076375a60dc0542660d001860f8660c40e8660c40e8660c40e897ae010631533306f33333304b0140150160744a04666660b00960480024646464646609a6666609802c02a0126ea0cdc09bad00853330753304b002077153330753304a002304730027082002266e040052002100100700530017086608c608a02a4660020060046eb4c1c40d0dd68020a5010631616306d306c003306c002306b00230690013064007161637526eb8c1a00b854ccc1a4c1c40104c94ccc1a8c1d800454ccc1a8cdc400080609929998359981b80098350140a9998359981b0009835013899191919191919191919191999983991299983c80089112800891919a99983d19839802983c80089999983102a9ba9022375660f260f00024a6660f8002244a002264a6660f86108026eb4c22c04c1ec00854ccc1f0c20c04ccc1c8080090004488c00800c48940044894004dd7184480983d000891280089128009299983d99b8f001027132223002233001007004307a00413300530790044a026600860f000600460e660f00040369448c00488c8d4ccc1e94cc1c800c4ccc1e80192825113232233001003002375066e00dd68071bad00933306970000200e246600200401c44646464646464646464a66610a02660ce0080162a66610a0266ebc014c24804cc1e0c21004128cc1e008ccc1e0098cc1e0c2100411ccc1e0dd419b8102701c3307802533078024330783752062660f0610802084660f0610802082660f06ea0cdc01bad30840104048008cc1e0c210040fccc1e004ccc1e0c24804cc1e0dd419b80375a014002660f002e660f06ea0cdc000b00125eb80cc1e0dd400a25eb8054ccc21404cdc49998331119b8000233308401222533308b010011002133003337000049001184400800a40006eacc2580400520000044805041e45858594ccc21004cc1f4090cc1bd221004881001480004cc1e4008cc1bd220100488100330780010233306e001008375661000200aa66610002610e020042c2a66610002611202004260fe002266660ce6eb8c1fc004098800458c23804008c23004004dd5183e183d800983d183b002199834380330620193750012660ca046660c40346ea004058c1d0080cccccc14006406806c0092812513305c3305e488100488100001307102b337006eb4c1c0c1bc0a4004c02001cdd69837183680198368011836001183500098328040b0b183480c8b0b1bad3068003153330693370e01860ae900109929998351981b00098348138a9998351981a80098348130991919299983699827999982981080580980919982e38030060013305600d3750600a01e26464a6660de66666609602802a02c004a660ce002266ebc0081d08ccccc16012c0900048cc1240140044008418c58cc19c02cc1eccc1841cccc1841cccc1841cd2f5c060d804c2c6666608601a01860d600460d600260d660d400260d200260c800e2c2c60d00302c46464646464a6660dc660880040e020022a6660dc6608600460806004e1040044cdc0240040026002e10cc0fcc0f80108cc00400c008dd6983518348011bad30690013063008233054012333057700660a2660a6020028981010100333057700660a20126ea0028004c1d4008c1cc004dd5015983100d98308131830010182f810182f0111bad305d01f333053001005009375660b60186eb0c168030dd5982c982c182c0040827182c182b8011bae30570013055305530513333053232533051330523058001023130613304e375660b060ae00204460a460ae60ac60a40026eb0c1580248c8c94ccc168c18cc1a00084c16400458c1a0004dd5182b982b182b1829182b982b18290008b1bab30553054001304f30543053304f002375c60a60242c60a0002609e609e609e002609c609c002609a0026098002608e609800860960022c60b40026ea8c124c120004c10c03cc118004c114004c110004c10c004c108004c104004c100004c0fc004c0f8004c0f4004c0f0004c0ec004c0e8004c0d400c88c8c94ccc0e4c104c11c008528899804182319816182319816182325eb80cc0b0c01d28a5eb80cc0b0c018dd6981c000a5eb80010c11c004dd5000911919299981c182018230010a5113300730453302b3005375a606e00266056608a6605666e9520044bd701981598032514bd7025eb80010c118004dd5000918209981399ba548008cc09cdd4000a5eb80cc09cc00928a5eb808cdd2999819800a4004900025eb8088c8c94cc0b4cc014c0d0008c0d00044cc014c0d0c0cc004c0d0c0cc008c0b8008c0b400888c8c8c8c8c8c8c8c94ccc0e94ccc0e8cdc40010008a511533303a3370e00400226464a6660786088008266e20dd6981d8011bad303b00114a06094008609200829405288991919299981ea99981e982280109919299981f98239826801099baf374e0066e9c00452818268009baa0081533303d304600213232533303f3048304d00213375e6e9c00cdd38008a50304d001375401026464a66607e608c609a004266ebcdd38019ba700114a0609a0026ea80204ccc0f4c038c0f0c0ec02cc038c0f0c0ec029288a50304b0023049001375400c608e004608c0046ea8008dd5001181a0011819801181680118160011181c181f1baa00122330010024800888c00888c00c88c8c8c8c8c8c8c8c88cc00400c008cdc100119b830060033370400266e0c0180094ccc0e0c0fc01052000153330383371200890000a40022900119819299981b99b8900200110011002533303733712004002200420026014004601200466e08010008cdc10020011299981699b89001480044c06c004400488c00888c00c88cdc399b82001004337040040064460044460064466e20cdc100080219b820020032222233301d7006602e660329110048810000333301d7006602e00a0046602e0080024466604e444a66605c00426602446600e0686eacc0f40040044c94ccc0bc00854cc098cc01c0040d04cc04c8cc020dd5981f00081a98160018991919299981899b8f00200115330293300a004003133007302f006302f00515333031337200040022a660526601400806e26600e605e00c00a2a660526601406e00626600e00c605e00a6eb8c0f8c0bc010dd7181e98170021bab303d302d0023756607860580040040024466604c444a66605a004266022466e2401cdd6981e00080089929998170010a9981299b890010071330122337126eb4c0f4004020c0ac00c4c8c8c94ccc0c0cdc78010008a9981419b89004003133007302e006302e00515333030337200040022a6605066e240100284cc01cc0b801801454cc0a0cdc480500189980380318170029bae303d302e004375c6078605a0086eb4c0f0c0b0008dd6981d9815801001000a40004644460040066eacc0d4004888888cccc0988cc090c0a8c0940040140188c8c8c8c8c8c94ccc0c4cc04ccc074dd598180031bab3030302f00233302070066602444666044e00008dd5982100081b8009980d1980e24410048810000a13008001163756605e0026052a66605e606c0042c2a66605e6070004264646464008a666064607260800042646464646464646464646464064a66607c607600a20622ca6660786086004264646464068a666080607a00820662ca66607c608a6098004264a66607e608c609a002264a66608060866e9cc0f800454ccc100c12cdc69bae303f001132323203753330433040002103616375a6080002607c0062c2c609c0022c6ea8c0f400458c130004dd5181d8008a99981e1822001099018a99981e80088180b0b182500118240009baa303800130360053016375600660286eac008cc0488c8c8c8cdd8299981ca9980c982000189821801898238020b1824002180b1bab30470033301423233760a66607266e24dc69bae3047002481004c11c00858c120008dd698238009bab3046002371a6eb8c110004dd58009819800981880119807919191919191919bb03047007304800730173756608e00ca66606e607c608a008264a666070607e608c002264a66607260786e9cc0dc00454ccc0e4c110dc69bae30380011323232030533303c3039002102f16375a6072002606e0082c2c608e0022c6ea8c0d800858c050dd59822802182200119808919191919bb05333038533018303f003130420031304600416304700430153756608c0066602646466ec14ccc0e0cdc49b8d375c608c0049020098230010b18238011bad30460013756608a0046e34dd718218009bab3043002375460820026eacc0c400458c100004dd500098170008999980b1bae302e00100a23232320045333032303930400021323232323232323232323232032533303e303b005103116533303c30430021323232320345333040303d004103316533303e3045304c002132533303f3046304d00113253330403043374e607c0022a66608060966e34dd7181f800899191901ba9998219820001081b0b1bad3040001303e0031616304e001163754607a0022c60980026ea8c0ec00454ccc0f0c1100084c80c54ccc0f400440c05858c128008c120004dd5181c000981b002980b1bab0033014375600466024464646466ec14ccc0e54cc064c10000c4c10c00c4c11c01058c120010c058dd598238019980a11919bb05333039337126e34dd71823801240802608e0042c60900046eb4c11c004dd598230011b8d375c60880026eac004c0cc004c0c4008cc03c8c8c8c8c8c8c8cdd818238039824003980b9bab30470065333037303e30450041325333038303f30460011325333039303c374e606e0022a66607260886e34dd7181c0008991919018299981e181c80108178b1bad3039001303700416163047001163754606c0042c60286eacc114010c110008cc0448c8c8c8cdd8299981c29980c181f80189821001898230020b1823802180a9bab30460033301323233760a66607066e24dc69bae3046002481004c11800858c11c008dd698230009bab3045002371a6eb8c10c004dd598218011baa3041001375660620022c60800026ea800458c0f4008c0ec004dd5181598150009814981280088011181091299981380081509980c98019812800980118120009199810112999813000890020991299981398008010b0998021812801919b90001003375c60666048002002494094ccc088cc0188cc0180bc0040044004588cc0840045289180e91129998120008801099801998020011811000981080091198021198021b8948000004cc03000800488cc0108c00cdd698178008009119801918019bab302e0010012301922533301f00114a22a6602c6006603a00226004603800244644603644a66604200204826464646464a66604aa66604a6058004294054ccc094c0b40084cccc030dd718120008041198050008028a5013300930240010041375660486046603e604800c2600e604600c606600460620026ea8c084c080c080008c080004c068c07c004894cc058cdd780100209980b80080191980111911180100198150009ba90012223301822533301e00112250011533301d3375e605660380020082600a6038002260046036002002446464a66603666e24dd6801a400003e26600a0046e98cc01400400cc064c060c05000cc060c04c00888cc02ccdd800100080f111812198051ba90023300a375200297ae0223330057000046600646e98cc0108dd418031bad0013756002002446602444a66603000203626601466ec0c094c058004c010c098c058004c008c054004004dc0a4000444666008446e98ccc01888dd4198039bad002375a0026eac008dd58008010009111999808111980091299980c001080089999802004180b001180a801000911299980c8008998058018010991919299980d99baf00200113300e3376000466016605400c605400666601001a00a60320082a66603666e40dd70011bae00113300e006333300800c003301900400513300e003333300800c00600530190043028002302700430170010050020012200122002574093111998018011bae300c3007001375c60186016600e002444666600800490001199980280124000eb4dd58008019191111980591299980880088028a99980819baf301e300f00100613004301f300f00113002300e001001375200244666014004002294088cdd79ba73003002374e60060024602c6ea8004c0088894ccc020c03c00440084cc00c004cdc30010009800911299980400089128008a9998039801180300089911180100198030008998018011802800919180111980100100091801119801001000aba25742ae6955cf919800a400090011baf374e97ae010024c010100004bd6f7b6301b8748000dc3a40046e1d2004370e901c1b8748100dc4240006e9520005573aaae79", - "role": "ValidatorRole", - "type": "PlutusScriptV2", - "version": "ScriptV2" -} diff --git a/geniusyield-dex-api/geniusyield-dex-api.cabal b/geniusyield-dex-api/geniusyield-dex-api.cabal deleted file mode 100644 index cee1279..0000000 --- a/geniusyield-dex-api/geniusyield-dex-api.cabal +++ /dev/null @@ -1,107 +0,0 @@ -cabal-version: 3.4 -name: geniusyield-dex-api -version: 0.1.0.0 -synopsis: GeniusYield DEX Api -build-type: Simple -license: Apache-2.0 -copyright: (c) 2023 GYELD GMBH -author: Lars Bruenjes -maintainer: support@geniusyield.co -category: Blockchain, Cardano, Api - --- Common sections - -common common-ghc-opts - ghc-options: - -Wall -Wcompat -Wincomplete-uni-patterns -Wno-unused-do-bind - -Wno-partial-type-signatures -Wincomplete-record-updates - -Wmissing-deriving-strategies -Wno-name-shadowing -Wunused-foralls - -Wno-unticked-promoted-constructors -fprint-explicit-foralls - -fprint-explicit-kinds - -common common-deps - build-depends: - , aeson - , atlas-cardano - , base - , cardano-api - , containers - , http-types - , mtl - , plutus-ledger-api - , plutus-tx - , ply-core - , postgresql-simple - , postgresql-simple-url - , text - -common common-lang - default-language: Haskell2010 - default-extensions: - ApplicativeDo - BangPatterns - BinaryLiterals - ConstrainedClassMethods - ConstraintKinds - DataKinds - DeriveAnyClass - DeriveDataTypeable - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - DerivingVia - DoAndIfThenElse - EmptyCase - EmptyDataDecls - EmptyDataDeriving - ExistentialQuantification - ExplicitForAll - FlexibleContexts - FlexibleInstances - GADTSyntax - GeneralisedNewtypeDeriving - HexFloatLiterals - ImplicitPrelude - InstanceSigs - KindSignatures - LambdaCase - MonomorphismRestriction - MultiParamTypeClasses - NamedFieldPuns - MultiWayIf - NoStarIsType - NumericUnderscores - OverloadedStrings - PatternGuards - PatternSynonyms - PolyKinds - PostfixOperators - RankNTypes - RecordWildCards - RelaxedPolyRec - RoleAnnotations - ScopedTypeVariables - StandaloneDeriving - StandaloneKindSignatures - TraditionalRecordSyntax - TupleSections - TypeApplications - TypeFamilyDependencies - TypeOperators - ViewPatterns - --- Build targets - -library - import: common-lang - import: common-deps - import: common-ghc-opts - hs-source-dirs: src - exposed-modules: - GeniusYield.DEX.Api.PartialOrder - GeniusYield.DEX.Api.PartialOrderConfig - GeniusYield.DEX.Api.Utils - GeniusYield.DEX.Api.Types diff --git a/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrder.hs b/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrder.hs deleted file mode 100644 index ff7d6a1..0000000 --- a/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrder.hs +++ /dev/null @@ -1,543 +0,0 @@ -{-# LANGUAGE TemplateHaskell #-} -{-| -Module : GeniusYield.DEX.Api.PartialOrder -Copyright : (c) 2023 GYELD GMBH -License : Apache 2.0 -Maintainer : support@geniusyield.co -Stability : develop - --} -module GeniusYield.DEX.Api.PartialOrder - ( PartialOrderDatum (..) - , PartialOrderAction (..) - , PartialOrderInfo (..) - , partialOrders - , fillMultiplePartialOrders - , getPartialOrderInfo - , getPartialOrdersInfos - ) where - -import Control.Monad.Except (ExceptT (..), - runExceptT) -import qualified Data.Map.Merge.Strict as Map -import qualified Data.Map.Strict as Map -import qualified Data.Set as Set -import qualified PlutusLedgerApi.V1 as Plutus -import qualified PlutusLedgerApi.V1.Value as Plutus -import qualified PlutusTx -import qualified PlutusTx.AssocMap as PlutusTx -import qualified PlutusTx.Prelude as PlutusTx -import qualified PlutusTx.Ratio as PlutusTx - -import Control.Monad.Error.Class (liftEither) -import Control.Monad.Reader -import Data.Foldable (foldlM) -import Data.Maybe (fromJust) -import GeniusYield.DEX.Api.PartialOrderConfig (PartialOrderConfigInfoF (..), - fetchPartialOrderConfig) -import GeniusYield.DEX.Api.Types -import GeniusYield.HTTP.Errors (IsGYApiError (..)) -import GeniusYield.Imports -import GeniusYield.TxBuilder.Class -import GeniusYield.TxBuilder.Errors (GYTxMonadException, - throwAppError) -import GeniusYield.Types - -------------------------------------------------------------------------------- --- Partial Order Datum -------------------------------------------------------------------------------- - --- | Representation of total fees contained in the order. -data PartialOrderContainedFee = PartialOrderContainedFee - { pocfLovelaces :: Integer - -- ^ Fees explicitly charged in lovelaces, like flat lovelace fee collected - -- from maker and taker(s). - , pocfOfferedTokens :: Integer - -- ^ Fees explicitly collected as percentage of offered tokens from maker. - , pocfAskedTokens :: Integer - -- ^ Fees explicitly collected as percentage of asked tokens from taker. - } deriving stock (Generic, Show) - -PlutusTx.unstableMakeIsData ''PartialOrderContainedFee - - -instance Semigroup PartialOrderContainedFee where - (<>) a b = - PartialOrderContainedFee - { pocfLovelaces = pocfLovelaces a + pocfLovelaces b - , pocfOfferedTokens = pocfOfferedTokens a + pocfOfferedTokens b - , pocfAskedTokens = pocfAskedTokens a + pocfAskedTokens b - } - -instance Monoid PartialOrderContainedFee where mempty = PartialOrderContainedFee 0 0 0 - --- | Datum of the fee output. -data PartialOrderFeeOutput = PartialOrderFeeOutput - { pofdMentionedFees :: PlutusTx.Map Plutus.TxOutRef Plutus.Value - -- ^ Map, mapping order being consumed to the collected fees. - , pofdReservedValue :: Plutus.Value - -- ^ Value reserved in this UTxO which is not to be considered as fees. - , pofdSpentUTxORef :: Maybe Plutus.TxOutRef - -- ^ If not @Nothing@, it mentions the UTxO being consumed, whose value is used to provide for UTxOs minimum ada requirement. - } deriving stock (Generic, Show) - -PlutusTx.unstableMakeIsData ''PartialOrderFeeOutput - -data PartialOrderDatum = PartialOrderDatum - { podOwnerKey :: Plutus.PubKeyHash - -- ^ Public key hash of the owner. Order cancellations must be signed by this. - , podOwnerAddr :: Plutus.Address - -- ^ Address of the owner. Payments must be made to this address. - , podOfferedAsset :: Plutus.AssetClass - -- ^ The asset being offered. - , podOfferedOriginalAmount :: Integer - -- ^ Original number of units being offered. Initially, this would be same as `podOfferedAmount`. - , podOfferedAmount :: Integer - -- ^ The number of units being offered. - , podAskedAsset :: Plutus.AssetClass - -- ^ The asset being asked for as payment. - , podPrice :: PlutusTx.Rational - -- ^ The price for one unit of the offered asset. - , podNFT :: Plutus.TokenName - -- ^ Token name of the NFT identifying this order. - , podStart :: Maybe Plutus.POSIXTime - -- ^ The time when the order can earliest be filled (optional). - , podEnd :: Maybe Plutus.POSIXTime - -- ^ The time when the order can latest be filled (optional). - , podPartialFills :: Integer - -- ^ Number of partial fills order has undergone, initially would be 0. - , podMakerLovelaceFlatFee :: Integer - -- ^ Flat fee (in lovelace) paid by the maker. - , podTakerLovelaceFlatFee :: Integer - -- ^ Flat fee (in lovelace) paid by the taker. - , podContainedFee :: PartialOrderContainedFee - -- ^ Total fees contained in the order. - , podContainedPayment :: Integer - -- ^ Payment (in asked asset) contained in the order. - } deriving stock (Generic, Show) - -PlutusTx.makeIsDataIndexed ''PartialOrderDatum [('PartialOrderDatum, 0)] - --- | Exceptions raised while (partially) filling (partial) orders. -data FillOrderException - -- | Attempt to (partially) fill an order too early. - = TooEarlyFill { foeStart :: !GYSlot, foeNow :: !GYSlot } - -- | Attempt to (partially) fill an order too late. - | TooLateFill { foeEnd :: !GYSlot, foeNow :: !GYSlot } - deriving stock Show - deriving anyclass (Exception, IsGYApiError) - -data PodException = PodNftNotAvailable - | PodNonPositiveAmount !Integer - | PodNonPositivePrice !GYRational - | PodRequestedAmountGreaterOrEqualToOfferedAmount - { poeReqAmt :: !Natural - , poeOfferedAmount :: !Natural - } - | PodRequestedAmountGreaterThanOfferedAmount {poeReqAmt:: !Natural, poeOfferedAmount :: !Natural} - | PodNonDifferentAssets !GYAssetClass - -- ^ Offered asset is same as asked asset. - | PodEndEarlierThanStart - !GYTime -- ^ Start time. - !GYTime -- ^ End time. - | PodNegativeFrontendFee !GYValue - | PodNotAllOrderRefsPresent -- ^ We couldn't fetch information for some of the given `GYTxOutRef`s. Note that this does not relate to UTxO being spent as depending upon provider, we would fetch information for even those `GYTxOutRef` which have been spent. - !(Set.Set GYTxOutRef) -- ^ Missing output refs. - deriving stock Show - deriving anyclass (Exception, IsGYApiError) - -------------------------------------------------------------------------------- --- Partial Order action -------------------------------------------------------------------------------- - -data PartialOrderAction - = PartialCancel - | PartialFill !Integer - | CompleteFill - deriving stock (Show, Eq, Ord) - -PlutusTx.makeIsDataIndexed ''PartialOrderAction [ ('PartialCancel, 0) - , ('PartialFill, 1) - , ('CompleteFill, 2) - ] - -------------------------------------------------------------------------------- --- Partial Order info -------------------------------------------------------------------------------- - -data POIContainedFee = POIContainedFee - { poifLovelaces :: !Natural - , poifOfferedTokens :: !Natural - , poifAskedTokens :: !Natural - } deriving stock (Show, Eq, Generic) - -instance Semigroup POIContainedFee where - (<>) a b = - POIContainedFee - { poifLovelaces = poifLovelaces a + poifLovelaces b - , poifOfferedTokens = poifOfferedTokens a + poifOfferedTokens b - , poifAskedTokens = poifAskedTokens a + poifAskedTokens b - } - -instance Monoid POIContainedFee where mempty = POIContainedFee 0 0 0 - -data PartialOrderInfo = PartialOrderInfo - { poiRef :: !GYTxOutRef -- ^ Reference to the partial order. - , poiOwnerKey :: !GYPubKeyHash -- ^ Public key hash of the owner. - , poiOwnerAddr :: !GYAddress -- ^ Address of the owner. - , poiOfferedAsset :: !GYAssetClass -- ^ The asset being offered. - , poiOfferedOriginalAmount :: !Natural -- ^ The number of units originally offered. - , poiOfferedAmount :: !Natural -- ^ The number of units being offered. - , poiAskedAsset :: !GYAssetClass -- ^ The asset being asked for as payment. - , poiPrice :: !GYRational -- ^ The price for one unit of the offered asset. - , poiNFT :: !GYTokenName -- ^ Token name of the NFT identifying this partial order. - , poiStart :: !(Maybe GYTime) -- ^ The time when the order can earliest be filled (optional). - , poiEnd :: !(Maybe GYTime) -- ^ The time when the order can latest be filled (optional). - , poiPartialFills :: !Natural -- ^ The number of past partial fills. - , poiMakerLovelaceFlatFee :: !Natural -- ^ Flat fee (in lovelace) paid by the maker. - , poiTakerLovelaceFlatFee :: !Natural -- ^ Flat fee (in lovelace) paid by the taker. - , poiContainedFee :: !POIContainedFee -- ^ Fee contained in the order. - , poiContainedPayment :: !Natural -- ^ Payment (in asked asset) contained in the order. - , poiUTxOValue :: !GYValue -- ^ Total value in the UTxO. - , poiUTxOAddr :: !GYAddress -- ^ Address of the order UTxO. - , poiNFTCS :: !GYMintingPolicyId -- ^ Caching the CS to avoid recalculating for it. - } deriving stock (Show, Eq, Generic) - -poiContainedFeeToPlutus :: POIContainedFee -> PartialOrderContainedFee -poiContainedFeeToPlutus POIContainedFee {..} = - PartialOrderContainedFee - { pocfLovelaces = fromIntegral poifLovelaces - , pocfOfferedTokens = fromIntegral poifOfferedTokens - , pocfAskedTokens = fromIntegral poifAskedTokens - } - -poiContainedFeeFromPlutus :: PartialOrderContainedFee -> POIContainedFee -poiContainedFeeFromPlutus PartialOrderContainedFee {..} = - POIContainedFee - { poifLovelaces = fromIntegral pocfLovelaces - , poifOfferedTokens = fromIntegral pocfOfferedTokens - , poifAskedTokens = fromIntegral pocfAskedTokens - } - -------------------------------------------------------------------------------- --- Queries -------------------------------------------------------------------------------- - --- | List and transform all the partial orders for the given function. -partialOrders - :: forall a m - . GYApiQueryMonad m - => (PartialOrderInfo -> Maybe a) - -- ^ Filter + Transformer function. Nothing means ignore that partial order. - -> m [a] -partialOrders pOrderPredicate = do - DEXInfo {dexPartialOrderValidator} <- ask - - addr <- scriptAddress dexPartialOrderValidator - let paymentCred = addressToPaymentCredential addr & fromJust - foldM mkPOrderInfo [] =<< utxosAtPaymentCredentialWithDatums paymentCred - - where - mkPOrderInfo - :: GYApiQueryMonad m - => [a] - -> (GYUTxO, Maybe GYDatum) - -> m [a] - mkPOrderInfo acc (_, Nothing) = return acc - mkPOrderInfo acc (GYUTxO {utxoRef, utxoAddress, utxoValue}, Just gyDatum) = - case Plutus.fromBuiltinData $ datumToPlutus' gyDatum of - Nothing -> return acc - Just d -> either (const acc) (addPartialOrderInfo acc) <$> - runExceptT - (makePartialOrderInfo utxoRef (utxoAddress, utxoValue, d)) - - addPartialOrderInfo - :: [a] - -> PartialOrderInfo - -> [a] - addPartialOrderInfo pois = maybe pois (:pois) . pOrderPredicate - -------------------------------------------------------------------------------- --- Tx building -------------------------------------------------------------------------------- - -{- | Fills multiple orders. If the provided amount of offered tokens to buy in an order is equal to the offered amount, then we completely fill the order. Otherwise, it gets partially filled. --} -fillMultiplePartialOrders - :: (HasCallStack, GYApiMonad m) - => [(Either GYTxOutRef PartialOrderInfo, Natural)] - -> m (GYTxSkeleton PlutusV2) -fillMultiplePartialOrders eOrders = do - di <- ask - - -- This machinery is needed to accomodate the fact that MatchExecutionInfos may not have the PartialOrderInfo. In that case we must query it from the ref. - let separateOrders :: ([(GYTxOutRef, Natural)], [(PartialOrderInfo, Natural)]) - -> (Either GYTxOutRef PartialOrderInfo, Natural) - -> ([(GYTxOutRef, Natural)], [(PartialOrderInfo, Natural)]) - separateOrders (!refOrders, !poiOrders) (Left ref, n) = ((ref, n) : refOrders, poiOrders) - separateOrders (!refOrders, !poiOrders) (Right poi, n) = (refOrders, (poi, n) : poiOrders) - - (!ordersWithRefAndAmount, !ordersWithPoiAndAmount) = foldl' separateOrders ([],[]) eOrders - ordersWithRefAndAmount' = Map.fromList ordersWithRefAndAmount - queriedOrders <- getPartialOrdersInfos $ Map.keys ordersWithRefAndAmount' - -- Even though we use `dropMissing`, `getPartialOrdersInfos` verify that all entries are present. - let otherOrdersWithPoiAndAmount = Map.elems $ Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched (\_ poi amt -> (poi, amt))) queriedOrders ordersWithRefAndAmount' - orders = otherOrdersWithPoiAndAmount ++ ordersWithPoiAndAmount - por = dexPORefs di - - (cfgRef, poci) <- fetchPartialOrderConfig (porRefAddr por) (porRefNft por) - - let buildWithFeeOutput = do - let (!feeOutputMap, !totalContainedFee, !maxTakerFee) = - foldl' - (\(!mapAcc, !feeAcc, !prevMaxTakerFee) (PartialOrderInfo {..}, amtToFill) -> - let curMaxTakerFee = max prevMaxTakerFee poiTakerLovelaceFlatFee in - if amtToFill == poiOfferedAmount then - let orderContainedFee = poiContainedFeeToValue poiContainedFee poiOfferedAsset poiAskedAsset - in (PlutusTx.unionWith (<>) mapAcc (PlutusTx.singleton (txOutRefToPlutus poiRef) (valueToPlutus orderContainedFee)), feeAcc <> orderContainedFee, curMaxTakerFee) - else (mapAcc, feeAcc, curMaxTakerFee) - ) - (PlutusTx.empty, mempty, 0) - orders - fee = totalContainedFee <> valueFromLovelace (fromIntegral maxTakerFee) - feeOutput - | fee == mempty = mempty - | otherwise = - mustHaveOutput $ mkGYTxOut (pociFeeAddr poci) fee $ datumFromPlutusData $ PartialOrderFeeOutput feeOutputMap mempty Nothing - foldlM - (\(!prevSkel) (poi@PartialOrderInfo {..}, amt) -> do - commonCheck amt poiOfferedAmount - cs <- validFillRangeConstraints poiStart poiEnd - let skel = - if amt == poiOfferedAmount then - - let expectedValueOut = expectedPaymentWithDeposit poi True - - in - mustHaveInput (partialOrderInfoToIn poi CompleteFill di) - <> mustHaveOutput (partialOrderInfoToPayment poi expectedValueOut) - <> mustMint (mintingScript di) nothingRedeemer poiNFT (-1) - <> cs - - else - - let price' = partialOrderPrice poi amt - od = partialOrderInfoToPartialOrderDatum poi - { poiOfferedAmount = poiOfferedAmount - amt - , poiPartialFills = poiPartialFills + 1 - , poiContainedPayment = poiContainedPayment + fromIntegral (valueAssetClass price' poiAskedAsset) - } - - expectedValueOut = poiUTxOValue <> price' `valueMinus` valueSingleton poiOfferedAsset (toInteger amt) - o = mkGYTxOut poiUTxOAddr expectedValueOut (datumFromPlutusData od) - - in - mustHaveInput (partialOrderInfoToIn poi (PartialFill $ toInteger amt) di) - <> mustHaveOutput o - <> cs - - pure $! prevSkel <> skel - ) - (mustHaveRefInput cfgRef <> feeOutput) - orders - - - let buildWithoutFeeOutput = do - let maxTakerFee = foldl' (\prevMaxTakerFee (PartialOrderInfo {..}, _) -> max prevMaxTakerFee poiTakerLovelaceFlatFee) 0 orders - foldlM - (\(!prevSkel) (idx, (poi@PartialOrderInfo {..}, amt)) -> do - commonCheck amt poiOfferedAmount - let price' = partialOrderPrice poi amt - tf = if idx == 1 then mempty { poifLovelaces = fromIntegral maxTakerFee } else mempty - od = partialOrderInfoToPartialOrderDatum poi - { poiOfferedAmount = poiOfferedAmount - amt - , poiPartialFills = poiPartialFills + 1 - , poiContainedFee = poiContainedFee <> tf - , poiContainedPayment = poiContainedPayment + fromIntegral (valueAssetClass price' poiAskedAsset) - } - - expectedValueOut = poiUTxOValue <> price' <> poiContainedFeeToValue tf poiOfferedAsset poiAskedAsset `valueMinus` valueSingleton poiOfferedAsset (toInteger amt) - o = mkGYTxOut poiUTxOAddr expectedValueOut (datumFromPlutusData od) - - cs <- validFillRangeConstraints poiStart poiEnd - - pure $! - prevSkel - <> mustHaveInput (partialOrderInfoToIn poi (PartialFill $ toInteger amt) di) - <> mustHaveOutput o - <> cs - ) - (mustHaveRefInput cfgRef) - (zip [(1 :: Natural).. ] orders) - - if isJust $ find (\(PartialOrderInfo {..}, amt) -> amt == poiOfferedAmount) orders then buildWithFeeOutput - else buildWithoutFeeOutput - where - commonCheck amt poiOfferedAmount = do - when (amt == 0) . throwAppError $ PodNonPositiveAmount $ toInteger amt - when (amt > poiOfferedAmount) . throwAppError $ PodRequestedAmountGreaterThanOfferedAmount amt poiOfferedAmount - -------------------------------------------------------------------------------- --- Utilities -------------------------------------------------------------------------------- - -partialOrderInfoToPartialOrderDatum :: PartialOrderInfo -> PartialOrderDatum -partialOrderInfoToPartialOrderDatum PartialOrderInfo {..} = PartialOrderDatum - { podOwnerKey = pubKeyHashToPlutus poiOwnerKey - , podOwnerAddr = addressToPlutus poiOwnerAddr - , podOfferedAsset = assetClassToPlutus poiOfferedAsset - , podOfferedOriginalAmount = fromIntegral poiOfferedOriginalAmount - , podOfferedAmount = fromIntegral poiOfferedAmount - , podAskedAsset = assetClassToPlutus poiAskedAsset - , podPrice = PlutusTx.fromGHC $ toRational poiPrice - , podNFT = tokenNameToPlutus poiNFT - , podStart = timeToPlutus <$> poiStart - , podEnd = timeToPlutus <$> poiEnd - , podPartialFills = fromIntegral poiPartialFills - , podMakerLovelaceFlatFee = fromIntegral poiMakerLovelaceFlatFee - , podTakerLovelaceFlatFee = toInteger poiTakerLovelaceFlatFee - , podContainedFee = poiContainedFeeToPlutus poiContainedFee - , podContainedPayment = toInteger poiContainedPayment - } - -poiGetContainedFeeValue :: PartialOrderInfo -> GYValue -poiGetContainedFeeValue PartialOrderInfo {..} = poiContainedFeeToValue poiContainedFee poiOfferedAsset poiAskedAsset - -poiContainedFeeToValue :: POIContainedFee -> GYAssetClass -> GYAssetClass -> GYValue -poiContainedFeeToValue POIContainedFee {..} offAC askAC = - valueSingleton GYLovelace (fromIntegral poifLovelaces) - <> valueSingleton offAC (fromIntegral poifOfferedTokens) - <> valueSingleton askAC (fromIntegral poifAskedTokens) - --- | Builds an input consuming the given order for a particular action. -partialOrderInfoToIn :: PartialOrderInfo - -> PartialOrderAction - -> DEXInfo - -> GYTxIn PlutusV2 -partialOrderInfoToIn oi@PartialOrderInfo {..} oa DEXInfo {..} = GYTxIn - { gyTxInTxOutRef = poiRef - , gyTxInWitness = GYTxInWitnessScript - script - (datumFromPlutusData $ partialOrderInfoToPartialOrderDatum oi) - $ redeemerFromPlutusData oa - } - where - script = case porValidatorRef dexPORefs of - Nothing -> GYInScript dexPartialOrderValidator - Just ref -> GYInReference ref (validatorToScript dexPartialOrderValidator) - - -mintingScript :: DEXInfo -> GYMintScript PlutusV2 -mintingScript DEXInfo{dexNftPolicy, dexPORefs} = case porNftPolicyRef dexPORefs of - Nothing -> GYMintScript dexNftPolicy - Just ref -> GYMintReference ref (mintingPolicyToScript dexNftPolicy) - --- | Builds an output paying some value to the order owner, also adds the UTxO --- reference of the order to the datum. -partialOrderInfoToPayment :: PartialOrderInfo -> GYValue -> GYTxOut 'PlutusV2 -partialOrderInfoToPayment oi v = mkGYTxOut (poiOwnerAddr oi) v (datumFromPlutusData $ txOutRefToPlutus $ poiRef oi) - --- | Given an order and the bought amount from that order, returns the total --- price. -partialOrderPrice :: PartialOrderInfo -> Natural -> GYValue -partialOrderPrice PartialOrderInfo {..} amt = valueSingleton poiAskedAsset $ ceiling $ rationalToGHC poiPrice * toRational amt - -{- | Note that at any moment, an order UTxO contains:- - * An NFT. - * Remaining offered tokens. - * Payment for tokens consumed. - * Initial deposit. - * Collected fees. --} -expectedPaymentWithDeposit :: PartialOrderInfo -> Bool -> GYValue -expectedPaymentWithDeposit poi@PartialOrderInfo {..} isCompleteFill = - let toSubtract = valueSingleton (GYToken poiNFTCS poiNFT) 1 <> valueSingleton poiOfferedAsset (toInteger poiOfferedAmount) <> poiGetContainedFeeValue poi - toAdd = if isCompleteFill then partialOrderPrice poi poiOfferedAmount else mempty - in poiUTxOValue <> toAdd `valueMinus` toSubtract - --- | Given a UTxO reference of an order, returns the complete information. -getPartialOrderInfo :: GYApiQueryMonad m - => GYTxOutRef - -> m PartialOrderInfo -getPartialOrderInfo orderRef = do - utxoWithDatum <- utxoAtTxOutRefWithDatum' orderRef - vod <- utxoDatumPure' utxoWithDatum - - runExceptT (makePartialOrderInfo orderRef vod) >>= liftEither - -getPartialOrdersInfos :: GYApiQueryMonad m - => [GYTxOutRef] - -> m (Map.Map GYTxOutRef PartialOrderInfo) -getPartialOrdersInfos orderRefs = do - utxosWithDatums <- utxosAtTxOutRefsWithDatums orderRefs - let vod = utxosDatumsPure utxosWithDatums - when (Map.size vod /= length orderRefs) $ throwAppError $ PodNotAllOrderRefsPresent $ Set.fromList orderRefs `Set.difference` Map.keysSet vod - runExceptT (Map.traverseWithKey makePartialOrderInfo vod) >>= liftEither - --- | Given the UTxO reference of an order, returns the complete information. --- Checking the validity of the order. -makePartialOrderInfo :: GYApiQueryMonad m - => GYTxOutRef - -> (GYAddress, GYValue, PartialOrderDatum) - -> ExceptT GYTxMonadException m PartialOrderInfo -makePartialOrderInfo orderRef (utxoAddr, v, PartialOrderDatum {..}) = do - DEXInfo{dexNftPolicy} <- ask - addr <- addressFromPlutus' podOwnerAddr - - key <- pubKeyHashFromPlutus' podOwnerKey - - offeredAsset <- assetClassFromPlutus' podOfferedAsset - nft <- tokenNameFromPlutus' podNFT - askedAsset <- assetClassFromPlutus' podAskedAsset - - when (valueAssetClass v (GYToken (mintingPolicyId dexNftPolicy) nft) /= 1) $ - throwAppError PodNftNotAvailable - - return PartialOrderInfo - { poiRef = orderRef - , poiOwnerKey = key - , poiOwnerAddr = addr - , poiOfferedAsset = offeredAsset - , poiOfferedOriginalAmount = fromInteger podOfferedOriginalAmount - , poiOfferedAmount = fromInteger podOfferedAmount - , poiAskedAsset = askedAsset - , poiPrice = rationalFromPlutus podPrice - , poiNFT = nft - , poiStart = timeFromPlutus <$> podStart - , poiEnd = timeFromPlutus <$> podEnd - , poiPartialFills = fromInteger podPartialFills - , poiMakerLovelaceFlatFee = fromIntegral podMakerLovelaceFlatFee - , poiTakerLovelaceFlatFee = fromInteger podTakerLovelaceFlatFee - , poiContainedFee = poiContainedFeeFromPlutus podContainedFee - , poiContainedPayment = fromInteger podContainedPayment - , poiUTxOValue = v - , poiUTxOAddr = utxoAddr - , poiNFTCS = mintingPolicyId dexNftPolicy - } - -validFillRangeConstraints - :: forall m - . GYTxQueryMonad m - => Maybe GYTime - -> Maybe GYTime - -> m (GYTxSkeleton PlutusV2) -validFillRangeConstraints Nothing Nothing = return mempty -validFillRangeConstraints mstart mend = do - now <- slotOfCurrentBlock - sc <- maybe (return mempty) (startConstraint now) mstart - ec <- maybe (return mempty) (endConstraint now) mend - return $ sc <> ec - where - startConstraint :: GYSlot -> GYTime -> m (GYTxSkeleton PlutusV2) - startConstraint now start = do - startSlot <- enclosingSlotFromTime' start - if now >= startSlot - then return $ isInvalidBefore now - else throwAppError $ TooEarlyFill {foeStart = startSlot, foeNow = now} - - endConstraint :: GYSlot -> GYTime -> m (GYTxSkeleton PlutusV2) - endConstraint now end = do - endSlot <- enclosingSlotFromTime' end - if now <= endSlot - then return $ isInvalidAfter $ min endSlot $ unsafeAdvanceSlot now 120 - else throwAppError $ TooLateFill {foeEnd = endSlot, foeNow = now} diff --git a/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrderConfig.hs b/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrderConfig.hs deleted file mode 100644 index 53ffc64..0000000 --- a/geniusyield-dex-api/src/GeniusYield/DEX/Api/PartialOrderConfig.hs +++ /dev/null @@ -1,114 +0,0 @@ -{-# LANGUAGE TemplateHaskell #-} -{-| -Module : GeniusYield.DEX.Api.PartialOrderConfig -Copyright : (c) 2023 GYELD GMBH -License : Apache 2.0 -Maintainer : support@geniusyield.co -Stability : develop - --} - -module GeniusYield.DEX.Api.PartialOrderConfig - ( PocdException (..) - , PartialOrderConfigInfoF (..) - , PartialOrderConfigInfo - , fetchPartialOrderConfig - ) where - -import Data.Text (pack) -import Network.HTTP.Types (status400) - -import GeniusYield.HTTP.Errors (GYApiError (..), IsGYApiError (..)) -import GeniusYield.Imports -import GeniusYield.TxBuilder (GYTxQueryMonad (utxosAtAddressWithDatums), - addressFromPlutus', throwAppError, - utxoDatumPure') -import GeniusYield.Types -import qualified PlutusLedgerApi.V1 as Plutus -import PlutusTx (BuiltinData, - FromData (fromBuiltinData)) -import qualified PlutusTx -import PlutusTx.Ratio as PlutusTx (Rational) - -data PartialOrderConfigDatum = PartialOrderConfigDatum - { pocdSignatories :: [Plutus.PubKeyHash] - -- ^ Public key hashes of the potential signatories. - , pocdReqSignatories :: Integer - -- ^ Number of required signatures. - , pocdNftSymbol :: Plutus.CurrencySymbol - -- ^ Currency symbol of the partial order Nft. - , pocdFeeAddr :: Plutus.Address - -- ^ Address to which fees are paid. - , pocdMakerFeeFlat :: Integer - -- ^ Flat fee (in lovelace) paid by the maker. - , pocdMakerFeeRatio :: PlutusTx.Rational - -- ^ Proportional fee (in the offered token) paid by the maker. - , pocdTakerFee :: Integer - -- ^ Flat fee (in lovelace) paid by the taker. - , pocdMinDeposit :: Integer - -- ^ Minimum required deposit (in lovelace). - } deriving stock (Generic, Show) - -PlutusTx.unstableMakeIsData ''PartialOrderConfigDatum - -data PartialOrderConfigInfoF addr = PartialOrderConfigInfo - { pociSignatories :: ![GYPubKeyHash] - -- ^ Public key hashes of the potential signatories. - , pociReqSignatories :: !Integer - -- ^ Number of required signatures. - , pociNftSymbol :: !GYMintingPolicyId - -- ^ Minting Policy Id of the partial order Nft. - , pociFeeAddr :: !addr - -- ^ Address to which fees are paid. - , pociMakerFeeFlat :: !Integer - -- ^ Flat fee (in lovelace) paid by the maker. - , pociMakerFeeRatio :: !GYRational - -- ^ Proportional fee (in the offered token) paid by the maker. - , pociTakerFee :: !Integer - -- ^ Flat fee (in lovelace) paid by the taker. - , pociMinDeposit :: !Integer - -- ^ Minimum required deposit (in lovelace). - } deriving stock (Show, Generic, Functor) - -type PartialOrderConfigInfo = PartialOrderConfigInfoF GYAddress - -instance FromData (PartialOrderConfigInfoF Plutus.Address) where - fromBuiltinData :: BuiltinData -> Maybe (PartialOrderConfigInfoF Plutus.Address) - fromBuiltinData d = do - PartialOrderConfigDatum{..} <- fromBuiltinData d - signatories <- fromEither $ mapM pubKeyHashFromPlutus pocdSignatories - nftSymbol <- fromEither $ mintingPolicyIdFromCurrencySymbol pocdNftSymbol - pure PartialOrderConfigInfo - { pociSignatories = signatories - , pociReqSignatories = pocdReqSignatories - , pociNftSymbol = nftSymbol - , pociFeeAddr = pocdFeeAddr - , pociMakerFeeFlat = pocdMakerFeeFlat - , pociMakerFeeRatio = rationalFromPlutus pocdMakerFeeRatio - , pociTakerFee = pocdTakerFee - , pociMinDeposit = pocdMinDeposit - } - where - fromEither :: Either e a -> Maybe a - fromEither = either (const Nothing) Just - -newtype PocdException = PocdException GYAssetClass - deriving stock Show - deriving anyclass Exception - -instance IsGYApiError PocdException where - toApiError (PocdException nftToken) = GYApiError - { gaeErrorCode = "PARTIAL_ORDER_CONFIG_NOT_FOUND" - , gaeHttpStatus = status400 - , gaeMsg = pack $ printf "Partial order config not found for NFT: %s" nftToken - } - -fetchPartialOrderConfig :: GYTxQueryMonad m => GYAddress -> GYAssetClass -> m (GYTxOutRef, PartialOrderConfigInfo) -fetchPartialOrderConfig addr nftToken = do - utxos <- utxosAtAddressWithDatums addr $ Just nftToken - case utxos of - [p@(utxo, Just _)] -> do - (_, _, d') <- utxoDatumPure' p - feeAddr <- addressFromPlutus' $ pociFeeAddr d' - pure (utxoRef utxo, feeAddr <$ d') - _ -> throwAppError $ PocdException nftToken \ No newline at end of file diff --git a/geniusyield-dex-api/src/GeniusYield/DEX/Api/Types.hs b/geniusyield-dex-api/src/GeniusYield/DEX/Api/Types.hs deleted file mode 100644 index 904d6b3..0000000 --- a/geniusyield-dex-api/src/GeniusYield/DEX/Api/Types.hs +++ /dev/null @@ -1,96 +0,0 @@ -{-| -Module : GeniusYield.DEX.Api.Types -Copyright : (c) 2023 GYELD GMBH -License : Apache 2.0 -Maintainer : support@geniusyield.co -Stability : develop - --} -module GeniusYield.DEX.Api.Types - ( GYApiQueryMonad - , GYApiMonad - , DEXInfo (..) - , PORefs (..) - , mkDEXValidator - , mkDEXMintingPolicy - , mkPORefs - ) where - -import Control.Monad.Reader (MonadReader) - -import PlutusLedgerApi.V1 (Address) -import PlutusLedgerApi.V1.Scripts (ScriptHash) -import PlutusLedgerApi.V1.Value (AssetClass) -import Ply (ScriptRole (..), TypedScript) -import Ply.Core.Apply ((#)) - -import GeniusYield.DEX.Api.Utils (mintingPolicyFromPly, - validatorFromPly) -import GeniusYield.TxBuilder.Class (GYTxMonad, GYTxQueryMonad) -import GeniusYield.Types (GYAddress, GYAssetClass, - GYMintingPolicy, GYTxOutRef, - GYValidator, - PlutusVersion (PlutusV2), - assetClassToPlutus, - scriptPlutusHash, - validatorToScript) - -type GYApiQueryMonad m = (MonadReader DEXInfo m, GYTxQueryMonad m) - -type GYApiMonad m = (GYApiQueryMonad m, GYTxMonad m) - --- | Type that encapsulates the scripts needed for the dex api. -data DEXInfo = DEXInfo - { dexPartialOrderValidator :: !(GYValidator PlutusV2) - , dexNftPolicy :: !(GYMintingPolicy PlutusV2) - , dexPORefs :: !PORefs - } - --- | Type that encapsulates the nescesary information por the partial order contract -data PORefs = PORefs - { porRefAddr :: !GYAddress - -- ^ The address where the reference NFT will be placed. - , porRefNft :: !GYAssetClass - -- ^ The reference NFT. - , porValidatorRef :: !(Maybe GYTxOutRef) - -- ^ The reference for the partial order validator. - , porNftPolicyRef :: !(Maybe GYTxOutRef) - -- ^ The reference for the partial order minting policy. - } deriving stock Show - --- Smart Constructors - -mkDEXMintingPolicy - :: TypedScript 'MintingPolicyRole '[ScriptHash, Address, AssetClass] - -> GYValidator PlutusV2 - -> Address - -> GYAssetClass - -> GYMintingPolicy PlutusV2 -mkDEXMintingPolicy mintingPolicyRaw v addr ac = - mintingPolicyFromPly $ mintingPolicyRaw - # scriptPlutusHash (validatorToScript v) - # addr - # assetClassToPlutus ac - -mkDEXValidator - :: TypedScript 'ValidatorRole '[Address, AssetClass] - -> Address - -> GYAssetClass - -> GYValidator PlutusV2 -mkDEXValidator validatorRaw addr ac = validatorFromPly $ validatorRaw - # addr - # assetClassToPlutus ac - -mkPORefs - :: GYAddress - -> GYAssetClass - -> Maybe GYTxOutRef - -> Maybe GYTxOutRef - -> PORefs -mkPORefs porAddr porAC mVRef mNPRef = - PORefs - { porRefAddr = porAddr - , porRefNft = porAC - , porValidatorRef = mVRef - , porNftPolicyRef = mNPRef - } diff --git a/geniusyield-dex-api/src/GeniusYield/DEX/Api/Utils.hs b/geniusyield-dex-api/src/GeniusYield/DEX/Api/Utils.hs deleted file mode 100644 index 519f855..0000000 --- a/geniusyield-dex-api/src/GeniusYield/DEX/Api/Utils.hs +++ /dev/null @@ -1,80 +0,0 @@ -{-| -Module : GeniusYield.DEX.Api.Utils -Copyright : (c) 2023 GYELD GMBH -License : Apache 2.0 -Maintainer : support@geniusyield.co -Stability : develop - --} -module GeniusYield.DEX.Api.Utils - ( maybeToExceptT - , expectedTokenName - , gyExpectedTokenName - , validatorFromPly - , mintingPolicyFromPly - ) where - -import Control.Monad.Except ( ExceptT (..) ) -import Data.Maybe ( fromJust ) - -import qualified PlutusLedgerApi.V1 as Plutus ( TokenName(..), TxOutRef(..) - , TxId(..), serialiseUPLC - ) -import qualified PlutusTx.Builtins as Plutus ( BuiltinByteString - , consByteString, sha2_256 - ) - -import Ply (ScriptRole (..), TypedScript (..)) -import qualified Ply -import GeniusYield.Types ( SingPlutusVersion(..), GYValidator - , GYMintingPolicy, GYTxOutRef, GYTokenName - , tokenNameFromPlutus, txOutRefToPlutus - , validatorFromSerialisedScript - , mintingPolicyFromSerialisedScript - ) -import GeniusYield.Types.PlutusVersion ( SingPlutusVersionI(singPlutusVersion) - , PlutusVersion(..) - ) - -maybeToExceptT :: Functor m => e -> m (Maybe a) -> ExceptT e m a -maybeToExceptT err m = ExceptT $ fmap (maybe (Left err) Right) m - -expectedTokenName :: Plutus.TxOutRef -> Plutus.TokenName -expectedTokenName (Plutus.TxOutRef (Plutus.TxId tid) ix) = Plutus.TokenName s - where - s :: Plutus.BuiltinByteString - s = Plutus.sha2_256 (Plutus.consByteString ix tid) - -gyExpectedTokenName :: GYTxOutRef -> GYTokenName -gyExpectedTokenName = fromJust . tokenNameFromPlutus . expectedTokenName . - txOutRefToPlutus - -validatorFromPly - :: forall v - . SingPlutusVersionI v - => TypedScript 'ValidatorRole '[] - -> GYValidator v -validatorFromPly ts = case singPlutusVersion @v of - SingPlutusV1 -> if Ply.getPlutusVersion ts == Ply.ScriptV1 - then validatorFromSerialisedScript @PlutusV1 $ toSerialisedValidator ts - else error "validatorFromPly: Invalid script version" - SingPlutusV2 -> if Ply.getPlutusVersion ts == Ply.ScriptV2 - then validatorFromSerialisedScript @PlutusV2 $ toSerialisedValidator ts - else error "validatorFromPly: Invalid script version" - where - toSerialisedValidator (TypedScript _ s) = Plutus.serialiseUPLC s - -mintingPolicyFromPly - :: forall v - . SingPlutusVersionI v - => TypedScript 'MintingPolicyRole '[] - -> GYMintingPolicy v -mintingPolicyFromPly ts = case singPlutusVersion @v of - SingPlutusV1 -> if Ply.getPlutusVersion ts == Ply.ScriptV1 - then mintingPolicyFromSerialisedScript @PlutusV1 $ toSerialisedMintingPolicy ts - else error "mintingPolicyFromPly: Invalid script version" - SingPlutusV2 -> if Ply.getPlutusVersion ts == Ply.ScriptV2 - then mintingPolicyFromSerialisedScript @PlutusV2 $ toSerialisedMintingPolicy ts - else error "mintingPolicyFromPly: Invalid script version" - where - toSerialisedMintingPolicy (TypedScript _ s) = Plutus.serialiseUPLC s diff --git a/geniusyield-orderbot-framework/geniusyield-orderbot-framework.cabal b/geniusyield-orderbot-framework/geniusyield-orderbot-framework.cabal index f237860..4e249d9 100644 --- a/geniusyield-orderbot-framework/geniusyield-orderbot-framework.cabal +++ b/geniusyield-orderbot-framework/geniusyield-orderbot-framework.cabal @@ -117,7 +117,7 @@ library datasource import: common-ghc-opts visibility: public hs-source-dirs: lib-datasource - build-depends: base, atlas-cardano, geniusyield-orderbot-framework:common + build-depends: base, atlas-cardano, geniusyield-orderbot-framework:common, geniusyield-dex-api signatures: GeniusYield.OrderBot.DataSource @@ -132,6 +132,7 @@ library orderbook , base , geniusyield-orderbot-framework:common , geniusyield-orderbot-framework:datasource + , geniusyield-dex-api signatures: GeniusYield.OrderBot.OrderBook diff --git a/geniusyield-orderbot-framework/lib-common/GeniusYield/OrderBot/Types.hs b/geniusyield-orderbot-framework/lib-common/GeniusYield/OrderBot/Types.hs index 0deb22f..f333e7a 100644 --- a/geniusyield-orderbot-framework/lib-common/GeniusYield/OrderBot/Types.hs +++ b/geniusyield-orderbot-framework/lib-common/GeniusYield/OrderBot/Types.hs @@ -31,7 +31,7 @@ import Numeric.Natural (Natural) import GeniusYield.Types.TxOutRef (GYTxOutRef) import GeniusYield.Types.Value (GYAssetClass (..)) -import GeniusYield.DEX.Api.PartialOrder (PartialOrderInfo (..)) +import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..)) import GeniusYield.Types (rationalToGHC) ------------------------------------------------------------------------------- diff --git a/geniusyield-orderbot-framework/lib-datasource/GeniusYield/OrderBot/DataSource.hsig b/geniusyield-orderbot-framework/lib-datasource/GeniusYield/OrderBot/DataSource.hsig index 4b49ca2..1990b46 100644 --- a/geniusyield-orderbot-framework/lib-datasource/GeniusYield/OrderBot/DataSource.hsig +++ b/geniusyield-orderbot-framework/lib-datasource/GeniusYield/OrderBot/DataSource.hsig @@ -11,23 +11,18 @@ a connection to a _data source_ and fetch information on DEX orders. -} signature GeniusYield.OrderBot.DataSource ( Connection - , DEX , connectDB , closeDB - , mkDEX , withEachAssetOrders ) where -import Prelude ( IO, Maybe ) +import Prelude ( IO ) -import GeniusYield.Types ( GYNetworkId, GYProviders, GYAssetClass - , GYAddress, GYMintingPolicy, GYValidator - , PlutusVersion(PlutusV2) - , GYTxOutRef - ) +import GeniusYield.Types ( GYNetworkId, GYProviders ) import GeniusYield.OrderBot.Types ( OrderAssetPair, OrderInfo , OrderType (BuyOrder, SellOrder) ) +import GeniusYield.Api.Dex.Constants (DEXInfo (..)) -- | Means to connect to a data source for orders/liquidity positions. data Connection @@ -40,26 +35,6 @@ connectDB :: GYNetworkId -> GYProviders -> IO Connection -- | Close the DB connection. closeDB :: Connection -> IO () -{- | DEX Compiled Scripts to use in the dex operations, optionally the utxo - reference to use as reference scripts, along with additional information - about other ecosystem components. --} -data DEX - -{- | Given the DEX NFT minting policy and the Partial Orders validator, create - the DEX Compiled Scripts. Optionally add utxo reference to use as script ref - for the validator and nft minting policy. --} -mkDEX - :: GYMintingPolicy PlutusV2 - -> GYValidator PlutusV2 - -> Maybe GYTxOutRef - -- ^ Script Ref for the Partial Orders Validator - -> Maybe GYTxOutRef - -- ^ Script Ref for the NFT minting policy - -> (GYAddress, GYAssetClass) - -> DEX - {- | Fetch all unique DEX order asset pairings, and for each such asset pair, fetch all buy and sell orders. It takes a list of asset pairs. Only orders operating these asset class pairs, are @@ -74,7 +49,7 @@ IO action. -} withEachAssetOrders :: Connection - -> DEX + -> DEXInfo -> [OrderAssetPair] -> (a -> (# OrderAssetPair, [OrderInfo 'BuyOrder], [OrderInfo 'SellOrder] #) -> a) -> a diff --git a/geniusyield-orderbot-framework/lib-orderbook/GeniusYield/OrderBot/OrderBook.hsig b/geniusyield-orderbot-framework/lib-orderbook/GeniusYield/OrderBot/OrderBook.hsig index c5dbf8d..5fe3ad4 100644 --- a/geniusyield-orderbot-framework/lib-orderbook/GeniusYield/OrderBot/OrderBook.hsig +++ b/geniusyield-orderbot-framework/lib-orderbook/GeniusYield/OrderBot/OrderBook.hsig @@ -54,7 +54,9 @@ import GeniusYield.OrderBot.Types ( OrderAssetPair(..) , OrderType (BuyOrder, SellOrder) , OrderInfo, Price, Volume ) -import GeniusYield.OrderBot.DataSource ( Connection, DEX ) +import GeniusYield.OrderBot.DataSource ( Connection ) + +import GeniusYield.Api.Dex.Constants (DEXInfo) ------------------------------------------------------------------------------- -- Core Order book types @@ -113,7 +115,7 @@ This implementation may use those as necessary. -} populateOrderBook :: Connection - -> DEX + -> DEXInfo -> [OrderAssetPair] -> IO MultiAssetOrderBook diff --git a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs index 095691e..dfb7ae8 100644 --- a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs +++ b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs @@ -35,10 +35,8 @@ import qualified Data.Map as M import qualified Data.Text as Txt import GeniusYield.GYConfig (GYCoreConfig (cfgNetworkId), - coreConfigIO, withCfgProviders) -import GeniusYield.OrderBot.DataSource (closeDB, connectDB, - mkDEX) +import GeniusYield.OrderBot.DataSource (closeDB, connectDB) import GeniusYield.OrderBot.MatchingStrategy (IndependentStrategy, MatchExecutionInfo (..), MatchResult, @@ -61,10 +59,7 @@ import GeniusYield.TxBuilder (GYTxBuildResult (..), import GeniusYield.TxBuilder.Node (runGYTxMonadNodeParallelWithStrategy) import GeniusYield.Types -import GeniusYield.DEX.Api.Types (DEXInfo (..), - PORefs (..), - dexNftPolicy, - dexPartialOrderValidator) +import GeniusYield.Api.Dex.Constants (DEXInfo (..)) import GeniusYield.Transaction (BuildTxException, GYCoinSelectionStrategy (GYLegacy)) @@ -105,7 +100,7 @@ data OrderBot = OrderBot newtype ExecutionStrategy = MultiAssetTraverse IndependentStrategy runOrderBot - :: FilePath + :: GYCoreConfig -- ^ Path to the config file for the GY framework. -> DEXInfo -- ^ Complete DEX information. @@ -113,7 +108,7 @@ runOrderBot -- ^ OrderBot configuration. -> IO () runOrderBot - confFile + cfg di OrderBot { botSkey @@ -124,7 +119,6 @@ runOrderBot , botRescanDelay , botTakeMatches } = do - cfg <- coreConfigIO confFile withCfgProviders cfg "" $ \providers -> do let logInfo = gyLogInfo providers "SOR" logDebug = gyLogDebug providers "SOR" @@ -134,13 +128,6 @@ runOrderBot botChangeAddr = addressFromCredential netId (GYPaymentCredentialByKey botPkh) (stakeAddressToCredential . stakeAddressFromBech32 <$> botStakeAddress) botAddrs = [botChangeAddr] - por = dexPORefs di - dex = mkDEX (dexNftPolicy di) - (dexPartialOrderValidator di) - (porNftPolicyRef por) - (porValidatorRef por) - (porRefAddr por, porRefNft por) - logInfo $ unlines [ "" , "Starting bot with given credentials" @@ -148,8 +135,6 @@ runOrderBot , " Wallet Addresses: " ++ show (Txt.unpack . addressToText <$> botAddrs) , " Change Address: " ++ (Txt.unpack . addressToText $ botChangeAddr) , " Collateral: " ++ show botCollateral - , " Reference Script ref: " ++ show (porValidatorRef por) - , " Reference Minting ref: " ++ show (porNftPolicyRef por) , " Scan delay (µs): " ++ show botRescanDelay , " Token Pairs to scan:" , unlines (map (("\t - " ++) . show) botAssetPairFilter) @@ -162,7 +147,7 @@ runOrderBot -- First we populate the multi asset orderbook, using the provided -- @populateOrderBook@. - book <- populateOrderBook conn dex botAssetPairFilter + book <- populateOrderBook conn di botAssetPairFilter let bookList = maOrderBookToList book logInfo $ unwords [ "MultiAsset Order Book Info:" @@ -284,7 +269,7 @@ buildTransactions matchesToExecute di netId getBodies = NE.toList . runIdentity . sequence resultToSkeleton :: MatchResult -> GYTxMonadNode (GYTxSkeleton 'PlutusV2) - resultToSkeleton mResult = runReaderT (executionSkeleton mResult) di + resultToSkeleton mResult = runReaderT (executionSkeleton (dexPORefs di) mResult) di handlerBuildTx :: BuildTxException -> IO [(GYTxBody, MatchResult)] handlerBuildTx ex = logWarn (unwords ["BuildTxException:", show ex]) diff --git a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot/MatchingStrategy.hs b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot/MatchingStrategy.hs index ffbbe15..c53eece 100644 --- a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot/MatchingStrategy.hs +++ b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot/MatchingStrategy.hs @@ -23,9 +23,10 @@ import Data.Maybe (fromJust) import Data.Text (Text) import Numeric.Natural (Natural) -import GeniusYield.DEX.Api.PartialOrder (PartialOrderInfo (poiOfferedAmount), - fillMultiplePartialOrders) -import GeniusYield.DEX.Api.Types (GYApiMonad) +import GeniusYield.Api.Dex.PartialOrder (PORefs, + PartialOrderInfo (poiOfferedAmount), + fillMultiplePartialOrders') +import GeniusYield.Api.Dex.Types (GYDexApiMonad) import GeniusYield.OrderBot.OrderBook (OrderBook) import GeniusYield.OrderBot.Types import GeniusYield.TxBuilder (GYTxSkeleton) @@ -96,15 +97,17 @@ must be paid by the order. data FillType = CompleteFill | PartialFill Natural deriving stock (Eq, Show) executionSkeleton - :: GYApiMonad m - => MatchResult + :: GYDexApiMonad m a + => PORefs + -> MatchResult -> m (GYTxSkeleton 'PlutusV2) -executionSkeleton mr = fillMultiplePartialOrders $ map f mr +executionSkeleton pors mr = fillMultiplePartialOrders' pors (map f mr) Nothing mempty where f (OrderExecutionInfo ft o) = - (poiSource o + let oi = fromJust $ mPoi o in -- It's always under `Just` constructor in our code, but we aren't able to get rid of `Maybe` type for now since that would require significant changes in the test-suite. + (oi , case ft of - CompleteFill -> poiOfferedAmount $ fromJust $ mPoi o + CompleteFill -> poiOfferedAmount oi PartialFill n -> if isBuyOrder o then floor $ fromIntegral n * getPrice (price o) @@ -116,8 +119,3 @@ executionSkeleton mr = fillMultiplePartialOrders $ map f mr matchExecutionInfoUtxoRef :: MatchExecutionInfo -> GYTxOutRef matchExecutionInfoUtxoRef (OrderExecutionInfo CompleteFill OrderInfo {orderRef}) = orderRef matchExecutionInfoUtxoRef (OrderExecutionInfo (PartialFill _) OrderInfo {orderRef}) = orderRef - --- | If the order contains the PartialOrderInfo, return it. If not, return the ref -poiSource :: forall t. OrderInfo t -> Either GYTxOutRef PartialOrderInfo -poiSource OrderInfo {orderRef, mPoi = Nothing} = Left orderRef -poiSource OrderInfo {mPoi = Just poi} = Right poi diff --git a/geniusyield-orderbot.cabal b/geniusyield-orderbot.cabal index 8cb9b9b..deedf0c 100644 --- a/geniusyield-orderbot.cabal +++ b/geniusyield-orderbot.cabal @@ -120,6 +120,7 @@ library orderbook-list build-depends: , geniusyield-orderbot-framework:common , geniusyield-orderbot-framework:datasource + , geniusyield-dex-api exposed-modules: GeniusYield.OrderBot.OrderBook.List diff --git a/geniusyield-orderbot/src/Main.hs b/geniusyield-orderbot/src/Main.hs index eaca161..91b04b2 100644 --- a/geniusyield-orderbot/src/Main.hs +++ b/geniusyield-orderbot/src/Main.hs @@ -8,10 +8,14 @@ Stability : develop -} module Main ( main ) where -import Control.Exception ( throwIO ) -import System.Environment ( getArgs ) -import GeniusYield.OrderBot ( runOrderBot ) -import OrderBotConfig ( readBotConfig, buildOrderBot, getDexInfo ) +import Control.Exception (throwIO) +import GeniusYield.Api.Dex.Constants (dexInfoDefaultMainnet, + dexInfoDefaultPreprod) +import GeniusYield.GYConfig +import GeniusYield.OrderBot (runOrderBot) +import GeniusYield.Types (GYNetworkId (..)) +import OrderBotConfig (buildOrderBot, readBotConfig) +import System.Environment (getArgs) parseArgs :: IO (String, FilePath, Maybe FilePath) parseArgs = do @@ -33,8 +37,13 @@ main :: IO () main = do (action, pConfFile,obConfFile) <- parseArgs obc <- readBotConfig obConfFile - di <- getDexInfo obc + cfg <- coreConfigIO pConfFile + di <- + case cfgNetworkId cfg of + GYTestnetPreprod -> pure dexInfoDefaultPreprod + GYMainnet -> pure dexInfoDefaultMainnet + _ -> throwIO $ userError "Only Preprod and Mainnet are supported." ob <- buildOrderBot obc case action of - "run" -> runOrderBot pConfFile di ob + "run" -> runOrderBot cfg di ob _ -> throwIO . userError $ unwords ["Action: ", show action, " not supported."] diff --git a/geniusyield-orderbot/src/OrderBotConfig.hs b/geniusyield-orderbot/src/OrderBotConfig.hs index 908e95f..b7b4abd 100644 --- a/geniusyield-orderbot/src/OrderBotConfig.hs +++ b/geniusyield-orderbot/src/OrderBotConfig.hs @@ -31,11 +31,6 @@ import System.Envy ( FromEnv (fromEnv), Var, Parser, envMaybe, env ) import System.Random.MWC (fromSeed, initialize, createSystemSeed) -import Ply (readTypedScript, TypedScript, ScriptRole (..)) -import PlutusLedgerApi.V1 ( Address ) -import PlutusLedgerApi.V1.Scripts ( ScriptHash ) -import PlutusLedgerApi.V1.Value ( AssetClass ) - import GeniusYield.OrderBot import GeniusYield.OrderBot.Types ( OrderAssetPair(..) , equivalentAssetPair @@ -47,7 +42,6 @@ import Cardano.Api ( AsType (AsSigningKey, AsPaymentKey) ) import Strategies ( BotStrategy(..), allStrategies, mkIndependentStrategy ) -import GeniusYield.DEX.Api.Types -- | Order bot vanilla config. data OrderBotConfig = @@ -71,10 +65,6 @@ data OrderBotConfig = {- ^ The duration (microseconds) of time we wait before re-initiating a complete iteration for the bot. -} - , botCFPNftPolicy :: FilePath - -- ^ FilePath of the partial order minting policy. - , botCFPOrderValidator :: FilePath - -- ^ FilePath of the partial order validator. , botCMaxOrderMatches :: Int -- ^ The maximum amount of orders to be matched into a single transaction. , botCMaxTxsPerIteration :: Int @@ -85,14 +75,6 @@ data OrderBotConfig = {- ^ A boolean that dictates whether the bot chooses the tx to submit at random (to decrease collisions), or not (to maximize profit) -} - , botCPORConfig :: PORConfig - {- ^ UTxO reference of the UTxO storing the NFT that is placed in each order. - Address of the previous UTxO, together with a "must have" NFT to officially - identification. - - UTxO reference of the partial order minting policy. - UTxO reference of the partial order validator. - -} } deriving stock (Show, Eq, Generic) @@ -105,12 +87,9 @@ instance FromEnv OrderBotConfig where <*> envWithMsg ("Invalid Strategy. Must be one of: " ++ show allStrategies) "BOTC_EXECUTION_STRAT" <*> (parseArray <$> env "BOTC_ASSET_FILTER") <*> envIntWithMsg "BOTC_RESCAN_DELAY" - <*> env "BOTC_FP_NFT_POLICY" - <*> env "BOTC_FP_ORDER_VALIDATOR" <*> envIntWithMsg "BOTC_MAX_ORDERS_MATCHES" <*> envIntWithMsg "BOTC_MAX_TXS_PER_ITERATION" <*> envWithMsg "Must be either 'True' or 'False'" "BOTC_RANDOMIZE_MATCHES_FOUND" - <*> (parsePORDict <$> env "BOTC_POREFS") where parseCBORSKey :: String -> GYPaymentSigningKey parseCBORSKey s = @@ -118,10 +97,6 @@ instance FromEnv OrderBotConfig where eitherDecodeStrict (fromString s) >>= first show . deserialiseFromTextEnvelope (AsSigningKey AsPaymentKey) - parsePORDict :: String -> PORConfig - parsePORDict = either (error . ("Error parsing 'BOTC_POREFS': " ++)) id - . eitherDecodeStrict . fromString - parseArray :: String -> [OrderAssetPair] parseArray s = either (error . ("Error parsing 'BOTC_ASSET_FILTER': " ++) ) id $ eitherDecodeStrict (fromString s) >>= @@ -141,12 +116,9 @@ instance FromJSON OrderBotConfig where <*> obj .: "strategy" <*> (parseScanTokenPairs =<< obj .: "scanTokens") <*> obj .: "scanDelay" - <*> obj .: "nftMintingPolicyFP" - <*> obj .: "orderValidatorFP" <*> obj .: "maxOrderMatches" <*> obj .: "maxTxsPerIteration" <*> obj .: "randomizeMatchesFound" - <*> obj .: "validatorRefs" parseJSON _ = fail "Expecting object value" @@ -161,24 +133,6 @@ parseObjectTokenPair = withObject "OrderAssetPair" $ \v -> OAssetPair <$> v .: "currencyAsset" <*> v .: "commodityAsset" -data PORConfig = - PORConfig - { botCRefAddr :: GYAddress - , botCRefNft :: GYAssetClass - , botCScriptRef :: Maybe GYTxOutRef - , botCNftPolicyRef :: Maybe GYTxOutRef - } - deriving stock (Show, Eq, Generic) - -instance FromJSON PORConfig where - parseJSON (Object obj) = - PORConfig - <$> (addressFromBech32 <$> obj .: "refAddr") - <*> obj .: "refNftAC" - <*> obj .:? "scriptRef" - <*> obj .:? "nftPolicyRef" - parseJSON _ = fail "Expecting object value" - -- | Given a vanilla order bot configuration, builds a complete order bot setup. buildOrderBot :: OrderBotConfig -> IO OrderBot buildOrderBot OrderBotConfig @@ -234,37 +188,4 @@ takeMatches r (fromIntegral -> maxTxPerIter) matches = shuffleList :: [a] -> IO [a] shuffleList xs = createSystemSeed >>= initialize . fromSeed - >>= runReaderT (sample (shuffle xs)) - --- | Read the compiled scripts from the paths included in the OrderBotConfig -getDexInfo :: OrderBotConfig -> IO DEXInfo -getDexInfo OrderBotConfig{ botCFPNftPolicy - , botCFPOrderValidator - , botCPORConfig - } = do - dexPolicyRaw <- readNftPolicy - dexValidatorRaw <- readOrderValidator - - let partialOrderValidator = mkDEXValidator dexValidatorRaw - (addressToPlutus $ botCRefAddr botCPORConfig) - (botCRefNft botCPORConfig) - nftPolicy = mkDEXMintingPolicy dexPolicyRaw partialOrderValidator (addressToPlutus $ botCRefAddr botCPORConfig) (botCRefNft botCPORConfig) - porefs = PORefs { porRefAddr = botCRefAddr botCPORConfig - , porRefNft = botCRefNft botCPORConfig - , porValidatorRef = botCScriptRef botCPORConfig - , porNftPolicyRef = botCNftPolicyRef botCPORConfig - } - return DEXInfo - { dexPartialOrderValidator = partialOrderValidator - , dexNftPolicy = nftPolicy - , dexPORefs = porefs - } - - where - readNftPolicy - :: IO (TypedScript 'MintingPolicyRole '[ScriptHash, Address, AssetClass]) - readNftPolicy = readTypedScript botCFPNftPolicy - - readOrderValidator - :: IO (TypedScript 'ValidatorRole '[Address, AssetClass]) - readOrderValidator = readTypedScript botCFPOrderValidator + >>= runReaderT (sample (shuffle xs)) \ No newline at end of file diff --git a/impl/datasource-providers/GeniusYield/OrderBot/DataSource/Providers.hs b/impl/datasource-providers/GeniusYield/OrderBot/DataSource/Providers.hs index 6a1e795..ab3f3c7 100644 --- a/impl/datasource-providers/GeniusYield/OrderBot/DataSource/Providers.hs +++ b/impl/datasource-providers/GeniusYield/OrderBot/DataSource/Providers.hs @@ -8,10 +8,8 @@ Stability : develop -} module GeniusYield.OrderBot.DataSource.Providers ( Connection - , DEX , connectDB , closeDB - , mkDEX , withEachAssetOrders ) where @@ -20,16 +18,14 @@ import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import Control.Monad.Reader (ReaderT (runReaderT)) -import GeniusYield.DEX.Api.PartialOrder -import GeniusYield.DEX.Api.Types (DEXInfo (..), mkPORefs) +import GeniusYield.Api.Dex.Constants (DEXInfo (..)) +import GeniusYield.Api.Dex.PartialOrder import GeniusYield.OrderBot.Types import GeniusYield.TxBuilder import GeniusYield.Types data Connection = Connection !GYNetworkId {-# UNPACK #-} !GYProviders -type DEX = DEXInfo - type OrderData = (# OrderAssetPair, [OrderInfo 'BuyOrder], [OrderInfo 'SellOrder] #) connectDB :: GYNetworkId -> GYProviders -> IO Connection @@ -38,21 +34,9 @@ connectDB netId providers = pure $ Connection netId providers closeDB :: Connection -> IO () closeDB = const $ return () -mkDEX :: GYMintingPolicy PlutusV2 - -> GYValidator PlutusV2 - -> Maybe GYTxOutRef - -> Maybe GYTxOutRef - -> (GYAddress, GYAssetClass) - -> DEX -mkDEX nft partialOrder mVRef mNPRef (porAddr, porAC) = - DEXInfo { dexNftPolicy = nft - , dexPartialOrderValidator = partialOrder - , dexPORefs = mkPORefs porAddr porAC mVRef mNPRef - } - withEachAssetOrders :: Connection - -> DEX + -> DEXInfo -> [OrderAssetPair] -> (a -> OrderData -> a) -> a @@ -80,14 +64,14 @@ runQuery (Connection nid providers) = runGYTxQueryMonadNode nid providers allOrderInfos :: Connection - -> DEX + -> DEXInfo -> [OrderAssetPair] -> IO (Map OrderAssetPair [SomeOrderInfo]) allOrderInfos c dex assetPairs = do cTime <- getCurrentGYTime partialOrderInfos <- runQuery c $ - runReaderT (partialOrders $ partialOrderFilter cTime) dex + runReaderT (partialOrdersWithTransformerPredicate (dexPORefs dex) $ partialOrderFilter cTime) dex return $ foldl' f Map.empty partialOrderInfos where diff --git a/impl/orderbook-list/GeniusYield/OrderBot/OrderBook/List.hs b/impl/orderbook-list/GeniusYield/OrderBot/OrderBook/List.hs index 3ee625d..c09e4a1 100644 --- a/impl/orderbook-list/GeniusYield/OrderBot/OrderBook/List.hs +++ b/impl/orderbook-list/GeniusYield/OrderBot/OrderBook/List.hs @@ -39,15 +39,17 @@ module GeniusYield.OrderBot.OrderBook.List ( withEachAsset, ) where -import Data.Aeson (ToJSON, toJSON, object) -import Data.Foldable (foldl') -import Data.List (sortOn) -import Data.Map.Strict (Map) -import qualified Data.Map.Strict as M -import Data.Ord (Down (Down)) - -import GeniusYield.OrderBot.DataSource (Connection, DEX, withEachAssetOrders) -import GeniusYield.OrderBot.Types +import Data.Aeson (ToJSON, object, toJSON) +import Data.Foldable (foldl') +import Data.List (sortOn) +import Data.Map.Strict (Map) +import qualified Data.Map.Strict as M +import Data.Ord (Down (Down)) + +import GeniusYield.Api.Dex.Constants (DEXInfo) +import GeniusYield.OrderBot.DataSource (Connection, + withEachAssetOrders) +import GeniusYield.OrderBot.Types type MultiAssetOrderBook = Map OrderAssetPair OrderBook @@ -62,7 +64,7 @@ newtype Orders t = Orders {unOrders :: [OrderInfo t]} data OrderBook = OrderBook { sellOrders :: Orders 'SellOrder - , buyOrders :: Orders 'BuyOrder + , buyOrders :: Orders 'BuyOrder } deriving stock (Show, Eq) @@ -71,7 +73,7 @@ instance ToJSON OrderBook where populateOrderBook :: Connection - -> DEX + -> DEXInfo -> [OrderAssetPair] -> IO MultiAssetOrderBook populateOrderBook conn dex f = do From bd0057ec27d3c5649e80dbbfeea5a5525baad8de Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 17 Apr 2024 17:31:06 +0530 Subject: [PATCH 2/2] docs: update readme with latest update (#100) Related to #100 --- README.md | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) diff --git a/README.md b/README.md index 9a10e39..66d1528 100644 --- a/README.md +++ b/README.md @@ -325,14 +325,6 @@ file. The complete bot configuration looks like this: ```json { "signingKeyFP": "bot.skey", - "nftMintingPolicyFP": "compiled-scripts/minting-policy", - "orderValidatorFP": "compiled-scripts/partial-order", - "validatorRefs": { - "refAddr": "addr_test1wrgvy8fermjrruaf7fnndtmpuw4xx4cnvfqjp5zqu8kscfcvh32qk", - "refNftAC": "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.8309f9861928a55d37e84f6594b878941edce5e351f7904c2c63b559bde45c5c", - "scriptRef": "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#2", - "nftPolicyRef": "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#1" - }, "strategy": "OneSellToManyBuy", "scanDelay": 40000000, "maxOrderMatches": 5, @@ -350,17 +342,6 @@ file. The complete bot configuration looks like this: on a file. - `collateral`, an optional field to specify the collateral for the bot. If not present, Atlas will choose a suitable UTxO as collateral. -- `nftMintingPolicyFP` and `orderValidatorFP`, the filepath where the minting policy - and validator are stored. -- `"validatorsRefs"`, contains the information necessary for the validator. Contains 3 - mandatory fields and 2 optional ones. - - `"refAddr"`, address where the reference NFT is placed. - - `"refNftAc"`, assetClass of the reference NFT is placed. - - `"refNftUtxoRef"`, UTxO reference where the reference NFT is placed. - - `"scriptRef"`, an optional parameter for the script reference. This UTxO has to - have the partial order validator as a script ref. - - `"nftPolicyRef"`, an optional parameter for the script reference of the partial - orders NFT. This UTxO has to have the partial order NFT minting policy as a script ref. - `strategy`, currently the SOR supports one possible strategy: OneSellToManyBuy. - `scanDelay`, the duration of time in µs we wait before re-initiating a complete iteration for the bot. - `maxOrderMatches`, is the maximum amount of orders to be matched into a single transaction. @@ -422,37 +403,6 @@ Assign the selected UTXO (hash + index) to `COLLATERAL_UTXO_REF` when running t Alternatively, the UTXO information can also be obtained from a block explorer service such as https://cexplorer.io/ -#### Deployed Contract - -The SOR has the ability to use reference scripts on the filling transactions to -help minimize the fees. To do that, we need to use the official contract information -that is completely placed on the blockchain. That is the validator and the minting policy. - -##### Preprod -```json -{ - "validatorRefs": { - "refAddr": "addr_test1wrgvy8fermjrruaf7fnndtmpuw4xx4cnvfqjp5zqu8kscfcvh32qk", - "refNftAC": "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.8309f9861928a55d37e84f6594b878941edce5e351f7904c2c63b559bde45c5c", - "scriptRef": "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#2", - "nftPolicyRef": "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#1" - } -} -``` - -##### Mainnet - -```json -{ - "validatorRefs":{ - "refAddr": "addr1w9zr09hgj7z6vz3d7wnxw0u4x30arsp5k8avlcm84utptls8uqd0z", - "refNftAC": "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.4aff78908ef2dce98bfe435fb3fd2529747b1c4564dff5adebedf4e46d0fc63d", - "scriptRef": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#2", - "nftPolicyRef": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#1" - } -} -``` - #### Running Once we compiled and configured the order bot, you can execute the SOR using the [Makefile](./Makefile):