Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds on-chain smart contracts #40

Merged
merged 13 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This repository houses on-chain smart contracts, Haskell off-chain interaction l

## Structure of repository

- [`geniusyield-onchain`](./geniusyield-onchain/) houses on-chain smart contracts.
- [`geniusyield-dex-api`](./geniusyield-dex-api/) provides off-chain code to interact with our DEX. See it's [`README.md`](./geniusyield-dex-api/README.md) for more information about it.
- [`geniusyield-server-lib`](./geniusyield-server-lib/) serves endpoints using our off-chain code to easily interact with GeniusYield DEX in language of user's choice.
- [`geniusyield-orderbot-lib`](./geniusyield-orderbot-lib/) cater to additional requirements such as building up of an order-book, receiving price feed, etc.
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ packages:
geniusyield-dex-api
geniusyield-orderbot-lib
geniusyield-server-lib
geniusyield-onchain/geniusyield-common

-- TODO: Default value should be @direct@ in upcoming 3.10 version of cabal, omit this line then.
test-show-details: direct
Expand Down
5 changes: 5 additions & 0 deletions geniusyield-dex-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Revision history for geniusyield-dex-api

## 0.2.0.0 -- 2024-04-17

* Adds support for v1.1 family of scripts.
* Adds CIP-20 metadata messages on transactions.

## 0.1.0.0 -- 2023-12-22

* First version.
Binary file not shown.
16 changes: 9 additions & 7 deletions geniusyield-dex-api/geniusyield-dex-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: geniusyield-dex-api
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0
version: 0.2.0.0
synopsis: API code to interact with GeniusYield DEX.
description:
API code to interact with GeniusYield DEX. Learn more about GeniusYield by visiting https://www.geniusyield.co/.
Expand All @@ -21,11 +21,6 @@ extra-doc-files:
README.md

tested-with: GHC ==9.2.8
data-dir: data
data-files:
compiled-scripts/minting-policy.txt
compiled-scripts/partial-order-config.uplc
compiled-scripts/partial-order.txt

source-repository head
type: git
Expand Down Expand Up @@ -59,6 +54,7 @@ library
import: common
hs-source-dirs: src
exposed-modules:
GeniusYield.Api.Dex.Constants
GeniusYield.Api.Dex.PartialOrder
GeniusYield.Api.Dex.PartialOrderConfig
GeniusYield.Api.Dex.Types
Expand All @@ -71,21 +67,27 @@ library
GeniusYield.Scripts.Dex.PartialOrderConfig
GeniusYield.Scripts.Dex.PartialOrderConfig.Internal
GeniusYield.Scripts.Dex.PartialOrderNft
GeniusYield.Scripts.Dex.Version

build-depends:
, aeson
, base ^>=4.16.4.0
, base ^>=4.16.4.0
, bytestring
, containers
, data-default
, file-embed
, http-types
, lens
, mtl
, some
, strict
, swagger2
, text

-- Dependencies whose version is fixed by @cabal.project@ file.
build-depends:
, atlas-cardano
, geniusyield-common
, ply-core

-- Cardano libraries which are not on hackage. Their version is pinned in @cabal.project@ file or derived from other related dependencies.
Expand Down
109 changes: 109 additions & 0 deletions geniusyield-dex-api/src/GeniusYield/Api/Dex/Constants.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
module GeniusYield.Api.Dex.Constants (
poRefsMainnet,
poRefsPreprod,
poConfigAddrMainnet,
poConfigAddrPreprod,
DEXInfo (..),
dexInfoDefaultMainnet,
dexInfoDefaultPreprod,
) where

import GeniusYield.Api.Dex.PartialOrderConfig (PORef (..), PORefs (..))
import GeniusYield.OnChain.Common.Scripts.DEX.Data
import GeniusYield.Scripts (HasPartialOrderConfigAddr (..), HasPartialOrderNftScript (..), HasPartialOrderScript (..))
import GeniusYield.Scripts.Dex.Version (POCVersion (POCVersion1, POCVersion1_1))
import GeniusYield.Types (GYAddress, unsafeAddressFromText)
import PlutusLedgerApi.V1 (Address)
import PlutusLedgerApi.V1.Scripts (ScriptHash)
import PlutusLedgerApi.V1.Value (AssetClass)
import Ply (ScriptRole (..), TypedScript)

poRefsMainnet ∷ PORefs
poRefsMainnet =
PORefs
{ porV1 =
PORef
{ porValRef = "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#2",
porRefNft = "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.4aff78908ef2dce98bfe435fb3fd2529747b1c4564dff5adebedf4e46d0fc63d",
porMintRef = "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#1"
},
porV1_1 =
PORef
{ porValRef = "c8adf3262d769f5692847501791c0245068ed5b6746e7699d23152e94858ada7#2",
porRefNft = "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.682fd5d4b0d834a3aa219880fa193869b946ffb80dba5532abca0910c55ad5cd",
porMintRef = "c8adf3262d769f5692847501791c0245068ed5b6746e7699d23152e94858ada7#1"
}
}

poRefsPreprod ∷ PORefs
poRefsPreprod =
PORefs
{ porV1 =
PORef
{ porValRef = "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#2",
porRefNft = "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.8309f9861928a55d37e84f6594b878941edce5e351f7904c2c63b559bde45c5c",
porMintRef = "be6f8dc16d4e8d5aad566ff6b5ffefdda574817a60d503e2a0ea95f773175050#1"
},
porV1_1 =
PORef
{ porValRef = "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624#2",
porRefNft = "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.b5121487c7661f202bc1f95cbc16f0fce720a0a9d3dba63a9f128e617f2ddedc",
porMintRef = "16647d6365020555d905d6e0edcf08b90a567886f875b40b3d7cec1c70482624#1"
}
}

poConfigAddrMainnet ∷ POCVersion → GYAddress
poConfigAddrMainnet =
let v1Addr = unsafeAddressFromText "addr1w9zr09hgj7z6vz3d7wnxw0u4x30arsp5k8avlcm84utptls8uqd0z"
v1_1Addr = unsafeAddressFromText "addr1wxcqkdhe7qcfkqcnhlvepe7zmevdtsttv8vdfqlxrztaq2gge58rd"
in \case
POCVersion1 → v1Addr
POCVersion1_1 → v1_1Addr

poConfigAddrPreprod ∷ POCVersion → GYAddress
poConfigAddrPreprod =
let v1Addr = unsafeAddressFromText "addr_test1wrgvy8fermjrruaf7fnndtmpuw4xx4cnvfqjp5zqu8kscfcvh32qk"
v1_1Addr = unsafeAddressFromText "addr_test1wqzy2cay2twmcq68ypk4wjyppz6e4vjj4udhvkp7dfjet2quuh3la"
in \case
POCVersion1 → v1Addr
POCVersion1_1 → v1_1Addr

-- | Type that encapsulates the scripts needed for the dex api.
data DEXInfo = DEXInfo
{ dexPartialOrderValidator ∷ !(TypedScript 'ValidatorRole '[Address, AssetClass]),
dexNftPolicy ∷ !(POCVersion → TypedScript 'MintingPolicyRole '[ScriptHash, Address, AssetClass]),
dexPartialOrderConfigAddr ∷ !(POCVersion → GYAddress),
dexPORefs ∷ !PORefs
}

instance HasPartialOrderScript DEXInfo where
getPartialOrderValidator = dexPartialOrderValidator

instance HasPartialOrderNftScript DEXInfo where
getPartialOrderNftPolicy = dexNftPolicy

instance HasPartialOrderConfigAddr DEXInfo where
getPartialOrderConfigAddr = dexPartialOrderConfigAddr

nftPolicy ∷ POCVersion → TypedScript 'MintingPolicyRole '[ScriptHash, Address, AssetClass]
nftPolicy = \case
POCVersion1 → nftPolicyV1
POCVersion1_1 → nftPolicyV1_1

dexInfoDefaultMainnet ∷ DEXInfo
dexInfoDefaultMainnet =
DEXInfo
{ dexPartialOrderValidator = orderValidator,
dexNftPolicy = nftPolicy,
dexPartialOrderConfigAddr = poConfigAddrMainnet,
dexPORefs = poRefsMainnet
}

dexInfoDefaultPreprod ∷ DEXInfo
dexInfoDefaultPreprod =
DEXInfo
{ dexPartialOrderValidator = orderValidator,
dexNftPolicy = nftPolicy,
dexPartialOrderConfigAddr = poConfigAddrPreprod,
dexPORefs = poRefsPreprod
}
Loading
Loading