<p>We have <code>wrapMintingPolicy :: UnsafeFromData r =&gt; (r -&gt; ScriptContext -&gt; Bool) -&gt; WrappedMintingPolicyType</code>.</p>
<p>In the first case, we can spell out the details like:</p>
<pre><code>policy :: PaymentPubKeyHash -&gt; Scripts.MintingPolicy
policy pkh = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| \pkh' -&gt; Scripts.wrapMintingPolicy $  mkPolicy pkh' ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh
</code></pre>
<p>This means we partially apply <code>mkPolicy</code> and we get something that we can apply <code>wrapMintingPolicy</code> to.</p>
<p>In the second case we want to have:</p>
<pre><code>policy :: PaymentPubKeyHash -&gt; POSIXTime -&gt; Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| \pkh' deadline' -&gt; Scripts.wrapMintingPolicy $  mkPolicy pkh' deadline' ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh
    `PlutusTx.applyCode`
    PlutusTx.liftCode deadline
</code></pre>
<p>Here we can't use composition anymore: <code>wrapMintingPolicy :: y -&gt; z</code> and <code>mkPolicy :: a -&gt; b -&gt; y</code>.</p>

CC BY-SA 4.0
2022-02-14T08:21:41.647Z
2022-02-14T08:21:41.647Z
Mihai Codescu
<p>I'm on homework 5 of the pioneer program. If I check <code>Signed.hs</code>:</p>
<pre><code>{-# INLINABLE mkPolicy #-}
mkPolicy :: PaymentPubKeyHash -&gt; () -&gt; ScriptContext -&gt; Bool
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ unPaymentPubKeyHash pkh

policy :: PaymentPubKeyHash -&gt; Scripts.MintingPolicy
policy pkh = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh

curSymbol :: PaymentPubKeyHash -&gt; CurrencySymbol
curSymbol = scriptCurrencySymbol . policy
</code></pre>
<p>For some reason, this works, although <code>mkPolicy</code> has 3 arguments and while compiling, there's only 1. It seems that <code>() -&gt; ScriptContext</code> is dropped while wrapping the script (which kind a makes sense). This results in only one argument, the <code>PaymentPubKeyHash</code>.</p>
<p>However, when I try Homework1, I need 2 arguments, so I try this:</p>
<pre><code>mkPolicy :: PaymentPubKeyHash -&gt; POSIXTime -&gt; () -&gt; ScriptContext -&gt; Bool
mkPolicy pkh deadline () ctx = 
   txSignedBy txInfo $ unPaymentPubKeyHash pkh &amp;&amp;
      to deadline `contains` txInfoValidRange txInfo
         where txInfo :: txInfo
               txInfo = scriptContextInfo ctx

policy :: PaymentPubKeyHash -&gt; POSIXTime -&gt; Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
   $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
   `PlutusTx.applyCode`
   PlutusTx.liftCode pkh
   `PlutusTx.applyCode`
   PlutusTx.liftCode deadline

curSymbol :: PaymentPubKeyHash -&gt; POSIXTime -&gt; CurrencySymbol
curSymbol pkh deadline = scriptCurrencySymbol . policy 

</code></pre>
<p>I would expect the <code>Scripts.wrapMintingPolicy</code> again drops <code>() -&gt; ScriptContext</code> while compiling, making it using the first two <code>PaymentPubKeyHash -&gt; POSIXTime</code>. However, when I try to compile this, I get an error:</p>
<pre><code>src/Week05/Homework1.hs:51:56: error:
    • Couldn't match type ‘()’ with ‘ScriptContext’
      Expected type: PaymentPubKeyHash
                     -&gt; POSIXTime -&gt; ScriptContext -&gt; Bool
        Actual type: PaymentPubKeyHash
                     -&gt; POSIXTime -&gt; () -&gt; ScriptContext -&gt; Bool
    • Probable cause: ‘mkPolicy’ is applied to too few arguments
      In the second argument of ‘(.)’, namely ‘mkPolicy’
      In the Template Haskell quotation
        [|| Scripts.wrapMintingPolicy . mkPolicy ||]
      In the first argument of ‘PlutusTx.compile’, namely
        ‘[|| Scripts.wrapMintingPolicy . mkPolicy ||]’
   |
51 |    $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
   |                                                        ^^^^^^^^
Failed, no modules loaded.
</code></pre>
<p>So I've got the arguments wrong. I fail to understand why in the example of <code>Signed.hs</code> it works fine (1 argument to <code>mkPolicy</code>) and why it doesn't work fine in the case of 2 arguments.</p>
<p>What am I missing?
Thx.</p>
<p>== EDIT 14/02/2022</p>
<p>So, final solution, thanks to @Mihai Codescu</p>
<pre><code>mkPolicy :: PaymentPubKeyHash -&gt; POSIXTime -&gt; () -&gt; ScriptContext -&gt; Bool
mkPolicy pkh deadline () ctx = 
   txSignedBy txInfo (unPaymentPubKeyHash pkh) &amp;&amp;
      to deadline `contains` txInfoValidRange txInfo
         where txInfo :: TxInfo
               txInfo = scriptContextTxInfo ctx

policy :: PaymentPubKeyHash -&gt; POSIXTime -&gt; Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
   $$(PlutusTx.compile [|| mintingPolicyScript ||])
   `PlutusTx.applyCode`
   PlutusTx.liftCode pkh
   `PlutusTx.applyCode`
   PlutusTx.liftCode deadline
      where 
         mintingPolicyScript :: PaymentPubKeyHash -&gt; POSIXTime -&gt; Scripts.WrappedMintingPolicyType
         mintingPolicyScript = \pkh' deadline' -&gt; Scripts.wrapMintingPolicy $ mkPolicy pkh' deadline' 

curSymbol :: PaymentPubKeyHash -&gt; POSIXTime -&gt; CurrencySymbol
curSymbol = \pkh' deadline' -&gt; scriptCurrencySymbol (policy pkh' deadline')
</code></pre>

<plutus-pioneer-program><minting><script><policy>
How to PlutusTx.compile work with multiple arguments to mkPolicy
# How to PlutusTx.compile work with multiple arguments to mkPolicy

(Asked by: username_0 on 2022-02-13)

I'm on homework 5 of the pioneer program. If I check Signed.hs:
{-# INLINABLE mkPolicy #-}
mkPolicy :: PaymentPubKeyHash -> () -> ScriptContext -> Bool
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ unPaymentPubKeyHash pkh

policy :: PaymentPubKeyHash -> Scripts.MintingPolicy
policy pkh = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh

curSymbol :: PaymentPubKeyHash -> CurrencySymbol
curSymbol = scriptCurrencySymbol . policy

For some reason, this works, although mkPolicy has 3 arguments and while compiling, there's only 1. It seems that () -> ScriptContext is dropped while wrapping the script (which kind a makes sense). This results in only one argument, the PaymentPubKeyHash.
However, when I try Homework1, I need 2 arguments, so I try this:
mkPolicy :: PaymentPubKeyHash -> POSIXTime -> () -> ScriptContext -> Bool
mkPolicy pkh deadline () ctx = 
   txSignedBy txInfo $ unPaymentPubKeyHash pkh &&
      to deadline `contains` txInfoValidRange txInfo
         where txInfo :: txInfo
               txInfo = scriptContextInfo ctx

policy :: PaymentPubKeyHash -> POSIXTime -> Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
   $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
   `PlutusTx.applyCode`
   PlutusTx.liftCode pkh
   `PlutusTx.applyCode`
   PlutusTx.liftCode deadline

curSymbol :: PaymentPubKeyHash -> POSIXTime -> CurrencySymbol
curSymbol pkh deadline = scriptCurrencySymbol . policy 


I would expect the Scripts.wrapMintingPolicy again drops () -> ScriptContext while compiling, making it using the first two PaymentPubKeyHash -> POSIXTime. However, when I try to compile this, I get an error:
src/Week05/Homework1.hs:51:56: error:
    • Couldn't match type ‘()’ with ‘ScriptContext’
      Expected type: PaymentPubKeyHash
                     -> POSIXTime -> ScriptContext -> Bool
        Actual type: PaymentPubKeyHash
                     -> POSIXTime -> () -> ScriptContext -> Bool
    • Probable cause: ‘mkPolicy’ is applied to too few arguments
      In the second argument of ‘(.)’, namely ‘mkPolicy’
      In the Template Haskell quotation
        [|| Scripts.wrapMintingPolicy . mkPolicy ||]
      In the first argument of ‘PlutusTx.compile’, namely
        ‘[|| Scripts.wrapMintingPolicy . mkPolicy ||]’
   |
51 |    $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
   |                                                        ^^^^^^^^
Failed, no modules loaded.

So I've got the arguments wrong. I fail to understand why in the example of Signed.hs it works fine (1 argument to mkPolicy) and why it doesn't work fine in the case of 2 arguments.
What am I missing?
Thx.
== EDIT 14/02/2022
So, final solution, thanks to @Mihai Codescu
mkPolicy :: PaymentPubKeyHash -> POSIXTime -> () -> ScriptContext -> Bool
mkPolicy pkh deadline () ctx = 
   txSignedBy txInfo (unPaymentPubKeyHash pkh) &&
      to deadline `contains` txInfoValidRange txInfo
         where txInfo :: TxInfo
               txInfo = scriptContextTxInfo ctx

policy :: PaymentPubKeyHash -> POSIXTime -> Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
   $$(PlutusTx.compile [|| mintingPolicyScript ||])
   `PlutusTx.applyCode`
   PlutusTx.liftCode pkh
   `PlutusTx.applyCode`
   PlutusTx.liftCode deadline
      where 
         mintingPolicyScript :: PaymentPubKeyHash -> POSIXTime -> Scripts.WrappedMintingPolicyType
         mintingPolicyScript = \pkh' deadline' -> Scripts.wrapMintingPolicy $ mkPolicy pkh' deadline' 

curSymbol :: PaymentPubKeyHash -> POSIXTime -> CurrencySymbol
curSymbol = \pkh' deadline' -> scriptCurrencySymbol (policy pkh' deadline')

**Tags:** plutus-pioneer-program, minting, script, policy

---

## 1 answers

### Answer by username_1 on 2022-02-14. Score: 2 | Accepted answer

We have wrapMintingPolicy :: UnsafeFromData r => (r -> ScriptContext -> Bool) -> WrappedMintingPolicyType.
In the first case, we can spell out the details like:
policy :: PaymentPubKeyHash -> Scripts.MintingPolicy
policy pkh = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| \pkh' -> Scripts.wrapMintingPolicy $  mkPolicy pkh' ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh

This means we partially apply mkPolicy and we get something that we can apply wrapMintingPolicy to.
In the second case we want to have:
policy :: PaymentPubKeyHash -> POSIXTime -> Scripts.MintingPolicy
policy pkh deadline = mkMintingPolicyScript $
    $$(PlutusTx.compile [|| \pkh' deadline' -> Scripts.wrapMintingPolicy $  mkPolicy pkh' deadline' ||])
    `PlutusTx.applyCode`
    PlutusTx.liftCode pkh
    `PlutusTx.applyCode`
    PlutusTx.liftCode deadline

Here we can't use composition anymore: wrapMintingPolicy :: y -> z and mkPolicy :: a -> b -> y.


---

