Skip to content

Commit 526ffda

Browse files
docs: minor enhancements in immutability control behaviour in deploy (#144)
* docs: further clarifications on v3 deploy behaviour * docs: extra notes on deploy time immutability control * docs: apply suggestions from code review Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au> --------- Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au>
1 parent 9c1c215 commit 526ffda

File tree

10 files changed

+189
-9
lines changed

10 files changed

+189
-9
lines changed

docs/html/_sources/capabilities/app-deploy.md.txt

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ An example of the ARC-2 transaction note that is attached as an app creation / u
6868
ALGOKIT_DEPLOYER:j{name:"MyApp",version:"1.0",updatable:true,deletable:false}
6969
```
7070

71+
> NOTE: Starting from v3.0.0, AlgoKit Utils no longer automatically increments the contract version by default. It is the user's responsibility to explicitly manage versioning of their smart contracts (if desired).
72+
7173
## Lookup deployed apps by name
7274

7375
In order to resolve what apps have been previously deployed and their metadata, AlgoKit provides a method that does a series of indexer lookups and returns a map of name to app metadata via `get_creator_apps_by_name(creator_address)`.
@@ -179,8 +181,6 @@ In order for a smart contract to opt-in to use this functionality, it must have
179181
- `TMPL_UPDATABLE` - Which will be replaced with a `1` if an app should be updatable and `0` if it shouldn't (immutable)
180182
- `TMPL_DELETABLE` - Which will be replaced with a `1` if an app should be deletable and `0` if it shouldn't (permanent)
181183

182-
If you are building a smart contract using the production [AlgoKit init templates](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/init.md) provide a reference implementation out of the box for the deploy-time immutability and permanence control.
183-
184184
If you passed in a TEAL template for the `approval_program` or `clear_state_program` (i.e. a `str` rather than a `bytes`) then `deploy` will return the {py:obj}`CompiledTeal <algokit_utils.models.app_deployer.CompiledTeal>` of substituting then compiling the TEAL template(s) in the following properties of the return value:
185185

186186
- `compiled_approval: CompiledTeal | None`
@@ -193,6 +193,50 @@ Template substitution is done by executing `algorand.app.compile_teal_template(t
193193
- `AppManager.replace_teal_template_deploy_time_control_params(teal_template_code, params)` - If `params` is provided, it allows for deploy-time immutability and permanence control by replacing `TMPL_UPDATABLE` with `params.get("updatable")` if not `None` and replacing `TMPL_DELETABLE` with `params.get("deletable")` if not `None`
194194
- `algorand.app.compile_teal(teal_code)` - Sends the final TEAL to algod for compilation and returns the result including the source map and caches the compilation result within the `AppManager` instance
195195

196+
#### Making updatable/deletable apps
197+
198+
Below is a sample in [Algorand Python SDK](https://github.com/algorandfoundation/puya) that demonstrates how to make an app updatable/deletable smart contract with the use of `TMPL_UPDATABLE` and `TMPL_DELETABLE` template parameters.
199+
200+
```python
201+
# ... your contract code ...
202+
@arc4.baremethod(allow_actions=["UpdateApplication"])
203+
def update(self) -> None:
204+
assert TemplateVar[bool]("UPDATABLE")
205+
206+
@arc4.baremethod(allow_actions=["DeleteApplication"])
207+
def delete(self) -> None:
208+
assert TemplateVar[bool]("DELETABLE")
209+
# ... your contract code ...
210+
```
211+
212+
Alternative example in [Algorand TypeScript SDK](https://github.com/algorandfoundation/puya-ts):
213+
214+
```typescript
215+
// ... your contract code ...
216+
@baremethod({ allowActions: 'UpdateApplication' })
217+
public onUpdate() {
218+
assert(TemplateVar<boolean>('UPDATABLE'))
219+
}
220+
221+
@baremethod({ allowActions: 'DeleteApplication' })
222+
public onDelete() {
223+
assert(TemplateVar<boolean>('DELETABLE'))
224+
}
225+
// ... your contract code ...
226+
```
227+
228+
With the above code, when deploying your application, you can pass in the following deploy-time parameters:
229+
230+
```python
231+
my_factory.deploy(
232+
... # other deployment parameters ...
233+
compilation_params={
234+
"updatable": True, # resulting app will be updatable, and this metadata will be set in the ARC-2 transaction note
235+
"deletable": False, # resulting app will not be deletable, and this metadata will be set in the ARC-2 transaction note
236+
}
237+
)
238+
```
239+
196240
### Return value
197241

198242
When `deploy` executes it will return a {py:obj}`AppDeployResult <algokit_utils.models.app_deployer.AppDeployResult>` object that describes exactly what it did and has comprehensive metadata to describe the end result of the deployed app.

docs/html/_sources/v3-migration-guide.md.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ result = algorand.send.asset_opt_in(
249249
4. **Application Client**
250250

251251
- Split into `AppClient`, `AppDeployer` and `AppFactory`
252+
- `deploy` method in `AppFactory`/`AppDeployer` no longer auto increments the contract version by default. It is the user's responsibility to explicitly manage versioning of their smart contracts (if desired).
252253
- New intuitive structured interface for creating or sending `AppCall`|`AppMethodCall` transactions
253254
- ARC-56 support along with automatic conversion of specs from ARC-32 to ARC-56
254255

docs/html/capabilities/app-deploy.html

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ <h2>Deployment metadata<a class="headerlink" href="#deployment-metadata" title="
385385
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ALGOKIT_DEPLOYER</span><span class="p">:</span><span class="n">j</span><span class="p">{</span><span class="n">name</span><span class="p">:</span><span class="s2">&quot;MyApp&quot;</span><span class="p">,</span><span class="n">version</span><span class="p">:</span><span class="s2">&quot;1.0&quot;</span><span class="p">,</span><span class="n">updatable</span><span class="p">:</span><span class="n">true</span><span class="p">,</span><span class="n">deletable</span><span class="p">:</span><span class="n">false</span><span class="p">}</span>
386386
</pre></div>
387387
</div>
388+
<blockquote>
389+
<div><p>NOTE: Starting from v3.0.0, AlgoKit Utils no longer automatically increments the contract version by default. It is the user’s responsibility to explicitly manage versioning of their smart contracts (if desired).</p>
390+
</div></blockquote>
388391
</section>
389392
<section id="lookup-deployed-apps-by-name">
390393
<h2>Lookup deployed apps by name<a class="headerlink" href="#lookup-deployed-apps-by-name" title="Link to this heading"></a></h2>
@@ -491,7 +494,6 @@ <h3>Compilation and template substitution<a class="headerlink" href="#compilatio
491494
<li><p><code class="docutils literal notranslate"><span class="pre">TMPL_UPDATABLE</span></code> - Which will be replaced with a <code class="docutils literal notranslate"><span class="pre">1</span></code> if an app should be updatable and <code class="docutils literal notranslate"><span class="pre">0</span></code> if it shouldn’t (immutable)</p></li>
492495
<li><p><code class="docutils literal notranslate"><span class="pre">TMPL_DELETABLE</span></code> - Which will be replaced with a <code class="docutils literal notranslate"><span class="pre">1</span></code> if an app should be deletable and <code class="docutils literal notranslate"><span class="pre">0</span></code> if it shouldn’t (permanent)</p></li>
493496
</ul>
494-
<p>If you are building a smart contract using the production <a class="reference external" href="https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/init.md">AlgoKit init templates</a> provide a reference implementation out of the box for the deploy-time immutability and permanence control.</p>
495497
<p>If you passed in a TEAL template for the <code class="docutils literal notranslate"><span class="pre">approval_program</span></code> or <code class="docutils literal notranslate"><span class="pre">clear_state_program</span></code> (i.e. a <code class="docutils literal notranslate"><span class="pre">str</span></code> rather than a <code class="docutils literal notranslate"><span class="pre">bytes</span></code>) then <code class="docutils literal notranslate"><span class="pre">deploy</span></code> will return the <code class="xref py py-obj docutils literal notranslate"><span class="pre">CompiledTeal</span></code> of substituting then compiling the TEAL template(s) in the following properties of the return value:</p>
496498
<ul class="simple">
497499
<li><p><code class="docutils literal notranslate"><span class="pre">compiled_approval:</span> <span class="pre">CompiledTeal</span> <span class="pre">|</span> <span class="pre">None</span></code></p></li>
@@ -504,6 +506,45 @@ <h3>Compilation and template substitution<a class="headerlink" href="#compilatio
504506
<li><p><code class="docutils literal notranslate"><span class="pre">AppManager.replace_teal_template_deploy_time_control_params(teal_template_code,</span> <span class="pre">params)</span></code> - If <code class="docutils literal notranslate"><span class="pre">params</span></code> is provided, it allows for deploy-time immutability and permanence control by replacing <code class="docutils literal notranslate"><span class="pre">TMPL_UPDATABLE</span></code> with <code class="docutils literal notranslate"><span class="pre">params.get(&quot;updatable&quot;)</span></code> if not <code class="docutils literal notranslate"><span class="pre">None</span></code> and replacing <code class="docutils literal notranslate"><span class="pre">TMPL_DELETABLE</span></code> with <code class="docutils literal notranslate"><span class="pre">params.get(&quot;deletable&quot;)</span></code> if not <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
505507
<li><p><code class="docutils literal notranslate"><span class="pre">algorand.app.compile_teal(teal_code)</span></code> - Sends the final TEAL to algod for compilation and returns the result including the source map and caches the compilation result within the <code class="docutils literal notranslate"><span class="pre">AppManager</span></code> instance</p></li>
506508
</ul>
509+
<section id="making-updatable-deletable-apps">
510+
<h4>Making updatable/deletable apps<a class="headerlink" href="#making-updatable-deletable-apps" title="Link to this heading"></a></h4>
511+
<p>Below is a sample in <a class="reference external" href="https://github.com/algorandfoundation/puya">Algorand Python SDK</a> that demonstrates how to make an app updatable/deletable smart contract with the use of <code class="docutils literal notranslate"><span class="pre">TMPL_UPDATABLE</span></code> and <code class="docutils literal notranslate"><span class="pre">TMPL_DELETABLE</span></code> template parameters.</p>
512+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ... your contract code ...</span>
513+
<span class="nd">@arc4</span><span class="o">.</span><span class="n">baremethod</span><span class="p">(</span><span class="n">allow_actions</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;UpdateApplication&quot;</span><span class="p">])</span>
514+
<span class="k">def</span><span class="w"> </span><span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
515+
<span class="k">assert</span> <span class="n">TemplateVar</span><span class="p">[</span><span class="nb">bool</span><span class="p">](</span><span class="s2">&quot;UPDATABLE&quot;</span><span class="p">)</span>
516+
517+
<span class="nd">@arc4</span><span class="o">.</span><span class="n">baremethod</span><span class="p">(</span><span class="n">allow_actions</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;DeleteApplication&quot;</span><span class="p">])</span>
518+
<span class="k">def</span><span class="w"> </span><span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
519+
<span class="k">assert</span> <span class="n">TemplateVar</span><span class="p">[</span><span class="nb">bool</span><span class="p">](</span><span class="s2">&quot;DELETABLE&quot;</span><span class="p">)</span>
520+
<span class="c1"># ... your contract code ...</span>
521+
</pre></div>
522+
</div>
523+
<p>Alternative example in <a class="reference external" href="https://github.com/algorandfoundation/puya-ts">Algorand TypeScript SDK</a>:</p>
524+
<div class="highlight-typescript notranslate"><div class="highlight"><pre><span></span><span class="c1">// ... your contract code ...</span>
525+
<span class="kd">@baremethod</span><span class="p">({</span><span class="w"> </span><span class="nx">allowActions</span><span class="o">:</span><span class="w"> </span><span class="s1">&#39;UpdateApplication&#39;</span><span class="w"> </span><span class="p">})</span>
526+
<span class="k">public</span><span class="w"> </span><span class="nx">onUpdate</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
527+
<span class="w"> </span><span class="nx">assert</span><span class="p">(</span><span class="nx">TemplateVar</span><span class="o">&lt;</span><span class="kt">boolean</span><span class="o">&gt;</span><span class="p">(</span><span class="s1">&#39;UPDATABLE&#39;</span><span class="p">))</span>
528+
<span class="p">}</span>
529+
530+
<span class="kd">@baremethod</span><span class="p">({</span><span class="w"> </span><span class="nx">allowActions</span><span class="o">:</span><span class="w"> </span><span class="s1">&#39;DeleteApplication&#39;</span><span class="w"> </span><span class="p">})</span>
531+
<span class="k">public</span><span class="w"> </span><span class="nx">onDelete</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
532+
<span class="w"> </span><span class="nx">assert</span><span class="p">(</span><span class="nx">TemplateVar</span><span class="o">&lt;</span><span class="kt">boolean</span><span class="o">&gt;</span><span class="p">(</span><span class="s1">&#39;DELETABLE&#39;</span><span class="p">))</span>
533+
<span class="p">}</span>
534+
<span class="c1">// ... your contract code ...</span>
535+
</pre></div>
536+
</div>
537+
<p>With the above code, when deploying your application, you can pass in the following deploy-time parameters:</p>
538+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">my_factory</span><span class="o">.</span><span class="n">deploy</span><span class="p">(</span>
539+
<span class="o">...</span> <span class="c1"># other deployment parameters ...</span>
540+
<span class="n">compilation_params</span><span class="o">=</span><span class="p">{</span>
541+
<span class="s2">&quot;updatable&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="c1"># resulting app will be updatable, and this metadata will be set in the ARC-2 transaction note</span>
542+
<span class="s2">&quot;deletable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="c1"># resulting app will not be deletable, and this metadata will be set in the ARC-2 transaction note</span>
543+
<span class="p">}</span>
544+
<span class="p">)</span>
545+
</pre></div>
546+
</div>
547+
</section>
507548
</section>
508549
<section id="return-value">
509550
<h3>Return value<a class="headerlink" href="#return-value" title="Link to this heading"></a></h3>
@@ -593,7 +634,10 @@ <h3>Return value<a class="headerlink" href="#return-value" title="Link to this h
593634
<li><a class="reference internal" href="#performing-a-deployment">Performing a deployment</a><ul>
594635
<li><a class="reference internal" href="#input-parameters">Input parameters</a></li>
595636
<li><a class="reference internal" href="#idempotency">Idempotency</a></li>
596-
<li><a class="reference internal" href="#compilation-and-template-substitution">Compilation and template substitution</a></li>
637+
<li><a class="reference internal" href="#compilation-and-template-substitution">Compilation and template substitution</a><ul>
638+
<li><a class="reference internal" href="#making-updatable-deletable-apps">Making updatable/deletable apps</a></li>
639+
</ul>
640+
</li>
597641
<li><a class="reference internal" href="#return-value">Return value</a></li>
598642
</ul>
599643
</li>

docs/html/objects.inv

34 Bytes
Binary file not shown.

docs/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/html/v3-migration-guide.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ <h2>Breaking Changes<a class="headerlink" href="#breaking-changes" title="Link t
577577
<li><p><strong>Application Client</strong></p>
578578
<ul class="simple">
579579
<li><p>Split into <code class="docutils literal notranslate"><span class="pre">AppClient</span></code>, <code class="docutils literal notranslate"><span class="pre">AppDeployer</span></code> and <code class="docutils literal notranslate"><span class="pre">AppFactory</span></code></p></li>
580+
<li><p><code class="docutils literal notranslate"><span class="pre">deploy</span></code> method in <code class="docutils literal notranslate"><span class="pre">AppFactory</span></code>/<code class="docutils literal notranslate"><span class="pre">AppDeployer</span></code> no longer auto increments the contract version by default. It is the user’s responsibility to explicitly manage versioning of their smart contracts (if desired).</p></li>
580581
<li><p>New intuitive structured interface for creating or sending <code class="docutils literal notranslate"><span class="pre">AppCall</span></code>|<code class="docutils literal notranslate"><span class="pre">AppMethodCall</span></code> transactions</p></li>
581582
<li><p>ARC-56 support along with automatic conversion of specs from ARC-32 to ARC-56</p></li>
582583
</ul>

0 commit comments

Comments
 (0)