Skip to content

Commit 7f4d5ad

Browse files
committed
feat(#98): update to Atlas version v0.6.2, updated contract & operations documentation
1 parent f8fe81f commit 7f4d5ad

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

src/module/home/components/DescriptionSection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const DescriptionSection: FC = () => (
5151
<FirstColumn container display="flex" flexDirection="row" maxWidth="1464px" padding="50px" overflow="hidden">
5252
<TextWithIcon
5353
title="Always up to date"
54-
subtitle="Benefit from Cardano's latest innovations such as Reference Inputs, Inline Datum and Reference Scripts."
54+
subtitle="Benefit from Cardano's latest innovations such as Reference Inputs, Governance actions and so on."
5555
image={
5656
<img className="blueLogo" alt="alwaysUpToDate" src={"/images/descriptionSection/AlwaysUpToDate.png"} />
5757
}
@@ -80,7 +80,7 @@ const DescriptionSection: FC = () => (
8080

8181
<TextWithIcon
8282
title="Unit tests"
83-
subtitle="Write realistic tests true to onchain behavior with Atlas' test harness framework based on Plutus Simple Model."
83+
subtitle="Write realistic tests true to onchain behavior utilizing Cardano ledger backend."
8484
image={
8585
<img
8686
className="blueLogo"
@@ -234,7 +234,7 @@ const RightRow = styled(Grid)(({ theme }) => ({
234234
},
235235
}));
236236

237-
const IllustrationWrapper = styled(Grid)(({}) => ({
237+
const IllustrationWrapper = styled(Grid)(({ }) => ({
238238
margin: "0 auto",
239239
}));
240240

src/pages/getting-started/operations.mdx

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,10 @@ betRefValidator betRefParams =
3535
$$(PlutusTx.compile [|| mkBetRefValidator||]) `PlutusTx.unsafeApplyCode` PlutusTx.liftCode plcVersion100 betRefParams
3636
```
3737

38-
Note that since spending validator takes in a datum, redeemer and a script context and thus it's type signature, `PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ())` takes three `PlutusTx.BuiltinData`. We encapsulate it with `GYValidator` inside framework.
38+
Inside Atlas, Plutus scripts are represented as [`GYScript (v :: PlutusVersion)`](https://haddock.atlas-app.io/GeniusYield-Types-Script.html#t:GYScript).
39+
The mentioned [`GeniusYield.Types.Script`](https://haddock.atlas-app.io/GeniusYield-Types-Script.html) module contains a lot of helper utilities such as `scriptFromPlutus` which takes in Plutus's `PlutusTx.CompiledCode a` type to give out `GYScript v` where type variable `v` is of _kind_ `PlutusVersion` which is defined in [`GeniusYield.Types.PlutusVersion`](https://haddock.atlas-app.io/GeniusYield-Types-PlutusVersion.html) module and is used to tag plutus ledger version of our validator script[^1].
3940

40-
Likewise minting policies and stake validators take in only redeemer and script context, thus having type `PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ())` which is represented in Atlas as `GYMintingPolicy` and `GYStakeValidator` respectively.
41-
42-
`GYValidator`, `GYMintingPolicy` and `GYStakeValidator` are nothing but `newtype` wrapper around `GYScript` where `GYScript` holds information of raw serialized Plutus script, [version of Plutus ledger language](https://plutus.readthedocs.io/en/latest/explanations/language-versions.html#what-are-plutus-language-versions) and script's hash.
43-
44-
Thus encapsulating `GYScript` under say `GYValidator` gives us additional context regarding script's purpose.
45-
46-
<Callout type="info">
47-
Checkout [`GeniusYield.Types.Script`](https://haddock.atlas-app.io/GeniusYield-Types-Script.html) module for definitions of these types and corresponding helper utilities.
48-
</Callout>
49-
50-
The mentioned `GeniusYield.Types.Script` module contains a lot of helper utilities such as `validatorFromPlutus` which takes in Plutus's `PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ())` type to give out `GYValidator`. Though there has been slight abuse in mentioning type here as what is actually given out is `GYValidator v` where type variable `v` is of _kind_ `PlutusVersion` which is defined in [`GeniusYield.Types.PlutusVersion`](https://haddock.atlas-app.io/GeniusYield-Types-PlutusVersion.html) module and is used to tag plutus ledger version of our validator script[^1].
51-
52-
If we look at the type signature of `validatorFromPlutus`, we see: `validatorFromPlutus :: forall v. SingPlutusVersionI v => PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ()) -> GYValidator v` where for the time being we can ignore the description of the typeclass `SingPlutusVersionI`[^1] besides noting the fact that only types (currently `'PlutusV1` & `'PlutusV2`) of kind `PlutusVersion` have an instance for it. So here, our function `validatorFromPlutus` works for all type variable `v` which have an instance of `SingPlutusVersionI` but there is no way to learn what this `v` is based solely on the input `PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ())` and therefore, caller must specify it, either by providing type signature (of callee or caller due to type inference) or by using [visible type application](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/type_applications.html). Our first operation does make use of it but before looking at it, we need to understand about `GYTxQueryMonad`.
41+
If we look at the type signature of `scriptFromPlutus`, we see: `scriptFromPlutus :: forall v a. SingPlutusVersionI v => PlutusTx.CompiledCode a -> GYScript v` where for the time being we can ignore the description of the typeclass `SingPlutusVersionI`[^1] besides noting the fact that only types (currently `'PlutusV1`, `'PlutusV2` & `'PlutusV3`) of kind `PlutusVersion` have an instance for it. So here, our function `scriptFromPlutus` works for all type variable `v` which have an instance of `SingPlutusVersionI` but there is no way to learn what this `v` is based solely on the input `PlutusTx.CompiledCode a` and therefore, caller must specify it, either by providing type signature (of callee or caller due to type inference) or by using [visible type application](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/type_applications.html). Our first operation does make use of it but before looking at it, we need to understand about `GYTxQueryMonad`.
5342

5443
### Interlude - `GYTxQueryMonad`
5544

@@ -66,7 +55,7 @@ So, if we are working inside a monad which happens to also provide an instance f
6655
In this operation, we only need to obtain network details with the help of this monad. Here is the code to obtain address (notice that we have provided multiple versions of the same code here):
6756

6857
<Callout type="info">
69-
Type of [`scriptAddress`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#v:scriptAddress) used below is `scriptAddress :: forall (m :: * -> *) (v :: PlutusVersion). GYTxQueryMonad m => GYValidator v -> m GYAddress`. Thus with respect to type application, the first parameter is for monad and second one is `PlutusVersion` kinded.
58+
Type of [`scriptAddress`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#v:scriptAddress) used below is `scriptAddress :: forall (m :: * -> *) (v :: PlutusVersion). GYTxQueryMonad m => GYScript v -> m GYAddress`. Thus with respect to type application, the first parameter is for monad and second one is `PlutusVersion` kinded.
7059

7160
Internally this function queries for network details.
7261
</Callout>
@@ -77,8 +66,8 @@ In this operation, we only need to obtain network details with the help of this
7766
-- A. Type is given by `scriptAddress`.
7867

7968
-- | Validator in question, obtained after giving required parameters.
80-
betRefValidator' :: SingPlutusVersionI v => BetRefParams -> GYValidator v
81-
betRefValidator' brp = validatorFromPlutus $ betRefValidator brp
69+
betRefValidator' :: SingPlutusVersionI v => BetRefParams -> GYScript v
70+
betRefValidator' brp = scriptFromPlutus $ betRefValidator brp
8271

8372
-- | Address of the validator, given params.
8473
betRefAddress :: (HasCallStack, GYTxQueryMonad m) => BetRefParams -> m GYAddress
@@ -87,10 +76,10 @@ In this operation, we only need to obtain network details with the help of this
8776
</Tab>
8877
<Tab>
8978
```haskell
90-
-- B. Type is given by `validatorFromPlutus` using type application.
79+
-- B. Type is given by `scriptFromPlutus` using type application.
9180

9281
-- | Validator in question, obtained after giving required parameters.
93-
betRefValidator' brp = validatorFromPlutus @'PlutusV2 $ betRefValidator brp
82+
betRefValidator' brp = scriptFromPlutus @'PlutusV2 $ betRefValidator brp
9483

9584
-- | Address of the validator, given params.
9685
betRefAddress :: (HasCallStack, GYTxQueryMonad m) => BetRefParams -> m GYAddress
@@ -102,8 +91,8 @@ In this operation, we only need to obtain network details with the help of this
10291
-- C. Type is specified using signature.
10392

10493
-- | Validator in question, obtained after giving required parameters.
105-
betRefValidator' :: BetRefParams -> GYValidator 'PlutusV2
106-
betRefValidator' brp = validatorFromPlutus $ betRefValidator brp
94+
betRefValidator' :: BetRefParams -> GYScript 'PlutusV2
95+
betRefValidator' brp = scriptFromPlutus $ betRefValidator brp
10796

10897
-- | Address of the validator, given params.
10998
betRefAddress :: (HasCallStack, GYTxQueryMonad m) => BetRefParams -> m GYAddress
@@ -190,7 +179,7 @@ Note that we have mentioned the value as empty for this UTxO and this is one of
190179

191180
<details>
192181
<summary> Toggle Answer </summary>
193-
Given the output address `addr :: GYAddress{:haskell}` and the Plutus V2 validator `script :: GYValidator 'PlutusV2{:haskell}`, we can write `mustHaveOutput $ GYTxOut addr mempty (Just (datumFromPlutusData (), GYTxOutDontUseInlineDatum)) (Just $ validatorToScript script){:haskell}`
182+
Given the output address `addr :: GYAddress{:haskell}` and the Plutus V2 validator `script :: GYScript 'PlutusV2{:haskell}`, we can write `mustHaveOutput $ GYTxOut addr mempty (Just (datumFromPlutusData (), GYTxOutDontUseInlineDatum)) (Just script){:haskell}`
194183
</details>
195184

196185
## Operation _3_: Placing a bet
@@ -239,22 +228,24 @@ Thus, we have its definition as:
239228

240229
```haskell
241230
-- | Utility function to consume script UTxO.
242-
input :: BetRefParams -> GYTxOutRef -> GYTxOutRef -> BetRefDatum -> BetRefAction -> GYTxSkeleton 'PlutusV2
231+
input :: BetRefParams -> GYTxOutRef -> GYTxOutRef -> BetRefDatum -> BetRefAction -> GYTxSkeleton 'PlutusV3
243232
input brp refScript inputRef dat red =
244-
mustHaveInput GYTxIn
245-
{ gyTxInTxOutRef = inputRef
246-
, gyTxInWitness = GYTxInWitnessScript
247-
(GYInReference refScript $ validatorToScript $ betRefValidator' brp)
248-
(datumFromPlutusData dat)
249-
(redeemerFromPlutusData red)
250-
}
233+
mustHaveInput
234+
GYTxIn
235+
{ gyTxInTxOutRef = inputRef
236+
, gyTxInWitness =
237+
GYTxInWitnessScript
238+
(GYInReference refScript $ betRefValidator' brp)
239+
(datumFromPlutusData dat)
240+
(redeemerFromPlutusData red)
241+
}
251242
```
252243

253244
<Callout type="info">
254245
In case we didn't want to use reference script, we would write `gyTxInWitness` as:
255246
```haskell
256247
gyTxInWitness = GYTxInWitnessScript
257-
(GYInScript (validatorToScript $ betRefValidator' brp))
248+
(GYInScript (betRefValidator' brp))
258249
(datumFromPlutusData dat)
259250
(redeemerFromPlutusData red)
260251
```

src/pages/getting-started/smart-contract-intro.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ Let's now start by writing a smart contract that we will use to convey framework
1212

1313
<Callout>
1414

15-
Here we'll be writing our smart contract in Haskell but do note that we are not limited to it. You for instance could write your smart contract in any language of your choice and read the compiled CBOR using `scriptFromCBOR` function defined [here](https://github.com/geniusyield/atlas/tree/main/src/GeniusYield/Types/Script.hs) ([Operations over Contract](./operations.mdx) chapter explains about types such as `GYScript`, `PlutusVersion` which are used in this function). Similarly, there is `readScript` defined in the [same](https://github.com/geniusyield/atlas/tree/main/src/GeniusYield/Types/Script.hs) file to read from the compiled [text envelope](https://cardano-api.cardano.intersectmbo.org/cardano-api/Cardano-Api-SerialiseTextEnvelope.html#t:TextEnvelope) file.
15+
Here we'll be writing our smart contract in Plutus-tx (aka Plinth) but do note that we are not limited to it. If you are using [Aiken](https://aiken-lang.org/), check out our [Blueprint](./../additional-features/blueprint) section to see how easily Aiken validators can be plugged into Atlas, also supporting creation of high level Haskell types corresponding to blueprint schema.
16+
17+
And in general, one can read the compiled validator's CBOR using `scriptFromCBOR` function defined [here](https://github.com/geniusyield/atlas/tree/main/src/GeniusYield/Types/Script.hs) ([Operations over Contract](./operations.mdx) chapter explains about types such as `GYScript`, `PlutusVersion` which are used in this function). Similarly, there is `readScript` defined in the [same](https://github.com/geniusyield/atlas/tree/main/src/GeniusYield/Types/Script.hs) file to read from the compiled [text envelope](https://cardano-api.cardano.intersectmbo.org/cardano-api/Cardano-Api-SerialiseTextEnvelope.html#t:TextEnvelope) file.
18+
19+
Note that if your validator is written in Plutarch, we recommend [Ply](https://github.com/geniusyield/ply) to read Plutarch compiled scripts. In particular, check out [this](https://github.com/geniusyield/dex-contracts-api/blob/main/geniusyield-dex-api/src/GeniusYield/Scripts/Common.hs) example where GeniusYield reads it's plutarch validators into Atlas.
1620

1721
</Callout>
1822

23+
<Callout type="info">
24+
Besides Plutus scripts, Atlas also supports Simple scripts. Check out [Simple Scripts](../additional-features/simple-scripts) section to learn more!
25+
</Callout>
26+
1927
## Contract Description
2028

2129
A setting here is that we have a sport match happening and a group of friends want to bet on the number of goals scored by their favorite team in it.
@@ -26,7 +34,7 @@ The smart contract code is available [here](https://github.com/geniusyield/atlas
2634

2735
<Callout type="info">
2836

29-
Since the underlying version of `plutus` library we are using defaults to version 1.1.0 of plutus core, we need to explicitly set [`target-version`](https://plutus.readthedocs.io/en/latest/reference/writing-scripts/compiler-options.html) to 1.0.0, and that is why there is `ghc-options: -fplugin-opt PlutusTx.Plugin:target-version=1.0.0` in [our cabal file](https://github.com/geniusyield/atlas-examples/blob/main/bet-ref/betref.cabal).
37+
Since the underlying version of `plutus` library we are using defaults to version 1.1.0 of plutus core, we need to explicitly set [`target-version`](https://plutus.readthedocs.io/en/latest/reference/writing-scripts/compiler-options.html) to 1.0.0 (as this example uses Plutus V2 ledger version, but Atlas also supports Plutus V3), and that is why there is `ghc-options: -fplugin-opt PlutusTx.Plugin:target-version=1.0.0` in [our cabal file](https://github.com/geniusyield/atlas-examples/blob/main/bet-ref/betref.cabal).
3038

3139
</Callout>
3240

@@ -47,7 +55,7 @@ data BetRefParams = BetRefParams
4755
, brpBetReveal :: POSIXTime -- ^ Time at which Oracle will reveal the correct match result.
4856
, brpBetStep :: Value -- ^ Each newly placed bet must be more than previous bet by `brpBetStep` amount.
4957
}
50-
PlutusTx.makeLift ''BetRefParams
58+
PlutusTx.unstableMakeIsData ''BetRefParams
5159
```
5260

5361
### Reference Input Datum

src/pages/introduction.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ Atlas is an all-in-one, Haskell-native application backend for writing off-chain
1010
Use an intuitive API to abstract away the complexity around building transactions, balancing UTxOs, and interfacing with Plutus smart contracts.
1111

1212
### Leverage first-class Haskell
13-
Avoid code duplication between on-chain and off-chain code, interoperate with advanced functionalities offered by IOG's Cardano/Plutus libraries, and easily convert between Atlas and [Cardano API](https://github.com/IntersectMBO/cardano-api)/[Plutus Ledger API](https://github.com/IntersectMBO/plutus/tree/master/plutus-ledger-api) types.
13+
Write type-safe abstractions, harnessing the power & security of Haskell.
1414

1515
### Utilize modular data providers
1616
Query ledger state information from remote provider such as [Maestro](https://www.gomaestro.org/dapp-platform), [Blockfrost](https://blockfrost.io/) or from your own node with the help of [Kupo](https://cardanosolutions.github.io/kupo/). You can also build and contribute your own data provider!
1717

1818
### Test extensively
19-
Use Atlas' test harness to write realistic [tests](./getting-started/testing)
20-
that can be run against an emulator or a private Cardano network.
19+
Use Atlas' test harness to write realistic [test](./getting-started/testing) harness,
20+
which can be run against either an emulator or a private Cardano network. Atlas offers a unified testing approach and the same test code can seamlessly execute on both an emulated mock ledger and an actual private Cardano test network.
2121

2222
### Stay up to date
23-
Benefit from Cardano's latest innovations such as **Reference Inputs**, **Inline Datums** and **Reference Scripts**. Conway we are looking at you 👀.
23+
Benefit from Cardano's latest innovations such as **Reference Inputs**, **Inline Datums**, **Reference Scripts**, governance actions and so on.
2424

2525
## Where to next?
2626
Work through an end-to-end example here: [Getting Started](./getting-started).
2727

2828
<Callout>
2929

30-
This guide tracks the latest commit of Atlas. We bring changes into Atlas, only when corresponding updates have been made into the documentation as well.
30+
This guide tracks the Atlas version [0.6.2](https://github.com/geniusyield/atlas/releases/tag/v0.6.2).
3131

3232
</Callout>

0 commit comments

Comments
 (0)