sidan-lab / plutus-cborhex-automation

A Haskell package for creating RESTful API endpoints for dynamic parameterized Cardano Plutus script.
15 stars 3 forks source link

Decomposing token-gated Faucet #26

Closed aleeusgr closed 1 year ago

aleeusgr commented 1 year ago

@SIDANWhatever — Yesterday at 17:56

Okay, then maybe you try to understand the above 3 contracts first and give me some time to develop the package function

https://gitlab.com/gimbalabs/plutus-pbl-summer-2022/ppbl-course-02/-/tree/master/project-301-faucet

aleeusgr commented 1 year ago

Extensions and imports.

Lines 1: 12 are extensions 15: 18 - FaucetValidatorScript has 2 parameters: FaucetParam and Validator..?? 21:31 - Imports.

import Data.Aeson (ToJSON, FromJSON) means only 2 functions are imported

qualified imports

aleeusgr commented 1 year ago

THe parameters

data FaucetParams = FaucetParams
  { accessTokenSymbol   :: !CurrencySymbol
  , accessTokenName     :: !TokenName
  , faucetTokenSymbol   :: !CurrencySymbol
  , faucetTokenName     :: !TokenName
  , withdrawalAmount    :: !Integer
  } deriving (Pr.Eq, Pr.Ord, Show, Generic, ToJSON, FromJSON, ToSchema)

deriving

aleeusgr commented 1 year ago

makeLift unstableMakeIsData - ??

55. PlutusTx.makeLift ''FaucetParams

...

59. PlutusTx.unstableMakeIsData ''FaucetRedeemer
60. PlutusTx.makeLift ''FaucetRedeemer
aleeusgr commented 1 year ago

newtype FaucetRedeemer - ?? PubKeyHash

newtype FaucetRedeemer = FaucetRedeemer {senderPkh :: PubKeyHash}
faucetValidator :: FaucetParams -> Integer -> FaucetRedeemer -> ScriptContext -> Bool
faucetValidator faucet _ receiver ctx =  traceIfFalse "Input needs PPBL2022AccessToken"           inputHasAccessToken &&
                                                  traceIfFalse "PPBL2022AccessToken must return to sender" outputHasAccessToken &&
                                                  traceIfFalse "Faucet token must be distributed to sender" outputHasFaucetToken &&
                                                  traceIfFalse "Must return remaining tokens to contract"   faucetContractGetsRemainingTokens &&
                                                  traceIfFalse "Do we need to check datum"                  checkDatumIsOk

Compare


mkValidator :: TestParam -> Integer -> () -> Plutus.ScriptContext -> Bool
mkValidator param dat _ _ = dat == testNumber param```
HinsonSIDAN commented 1 year ago

makeLift - low level haskell function for deriving instances in order to make data usable in plutus-core unstableMakeIsData - deriving instances for haskell function to understand JSON format for this data type in a particular order newtype - same as data declaration, just for this data type, there is only one value constructor with one element stored inside. This is introduced for efficiency purposes

-- upon basic research, you can try to implement the 3 contracts into endpoints as described at #25

aleeusgr commented 1 year ago

SIDAN.createEndpoint "get-parameterized-script" $ SIDAN.mkV1Validator V1V.validator

aleeusgr commented 1 year ago

So how does that work?

If Validator confirms the details of a transaction, it [signals the on-chain part to execute it].

This is a gated faucet, it generates tokens out of thin air. It could be used in a economic loop where tokens are constantly created and burned, E.g.: On-Chain Governance of Decentralized Autonomous Organizations: Blockchain Organization Using Semada, Calcaterra C.

To get your free tokens, you need a transaction (link to (how to create a transaction), and an [Auth Token].

HinsonSIDAN commented 1 year ago

We could take this discussion offline. The use case should be covered in PPBL or other Gimbalabs resources. Closing as the integration with examples are completed