# @travelx/algob-ext

> Extension engine for AlgoBuilder projects

Latest version **0.0.9** (published 2024-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @travelx/algob-ext
pnpm add @travelx/algob-ext
yarn add @travelx/algob-ext
bun add @travelx/algob-ext
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2024-03-15 |
| First published | 2022-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 100.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @tomas.bert |
| Maintainers | tbert |

## Links

- npm: https://www.npmjs.com/package/@travelx/algob-ext
- Repository: https://git.travelx.it/tomas.bert/algob-ext
- npm.io page: https://npm.io/package/@travelx/algob-ext

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) ^1.6.8
- [algosdk](https://npm.io/package/algosdk.md) ^2.7.0
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.11
- [readline-promise](https://npm.io/package/readline-promise.md) ^1.0.5
- [@algo-builder/algob](https://npm.io/package/@algo-builder/algob.md) ^7.0.0

## Recent versions

- 0.0.9 (latest) — 2024-03-15
- 0.0.8 — 2024-03-15
- 0.0.7 — 2024-03-15
- 0.0.6 — 2022-12-12
- 0.0.5-3 — 2022-12-01
- 0.0.5-2 — 2022-11-07
- 0.0.5-1 — 2022-11-07
- 0.0.5 — 2022-11-07
- 0.0.4-24 — 2022-11-07
- 0.0.4-23 — 2022-11-05
- 0.0.4-22 — 2022-09-03
- 0.0.4-21 — 2022-09-01
- 0.0.4-20 — 2022-08-19

## README

[<img style="background-color: 'black'; padding: 5px;" src="https://drive.google.com/uc?id=1qqkyxrNHVv1u21zKVG6rT040lEvu-1MC" width="200" />](https://www.travelx.io)
[<img src="https://algobuilder.dev/media/logo-website.png" width="190"/>](https://algobuilder.dev/)


# Algo Builder extension & helpers
---

[[_TOC_]]

## 📄 Description
All stuff which help us to develop and test Algorand Smart Contract 

## 💬 Resources
- `AlgoBuilder` ([official site](https://algobuilder.dev/))
- projects:
    - [`tomas.bert/algo-builder-scaffold`](https://git.travelx.it/tomas.bert/algo-builder-scaffold)
    - [`sandbox/smart-contracts`](https://git.travelx.it/pbws-2022/smart-contracts)
    - [`pbws/smart-contracts`](https://git.travelx.it/platform/tokenizer/sandbox/smart-contracts)

---

## 📜 Docs

### 📁 Ext
Main directory to customize scripts
##### ❯ `AlgoBuilderScript`
Basic AlgoBuilder script wrapper with some built-in extension to use out-of-box.
```
# scripts/my-script.ts
export default AlgoBuilderScript.of((ctx) => {
    // Do stuff with the context
});
```
###### **Context** [`IRunScriptContext`]
- `runtimeEnv: RuntimeEnvExt`: Extended environment `RuntimeEnv` (from algo-builder) with properties on NetworkConfig.
    - `runtimeEnv.network.config.assets`: Config custom asset ids for external networks like TestNet
    - `runtimeEnv.network.config.addresses`: Config addresses without private key to use
- `deployerExt: IDeployerExt`: The built-in extension methods from base deployer of AlgoBuilder
- `addresses: IScriptAddresses`: Service to read and resolve addresses from config file. `ctx.addresses.getOrFail('requiredAddress')`

###### **Deployer Ext** [`IDeployerExt`]
- `algoBalanceOf`: Return balance in algos.
- `usdcBalanceOf`: Return balance of common stable asset USDC (must be deployed before. See examples/scripts/usdc.ts)
- `usdcDispenser`: Dispense $USDC to account. `master` is the sender
- `algoDispenser`: Dispense $ALGO to account. `master` is the sender
- `funder`: Return a callable dispense which send the amount of usdc & algo to reach the `algoLt` & `usdcLt` configure amount. `send(algoLt - account.algos)`
- `accountSummary`: Print a summary of account in stdout
- `nftsOf`: Return a list of non-fungible asset which account hold.
- `resolveAssetIndex`: Resolve the asset index from their name or fallback to [artifact folder of algobuilder](https://github.com/scale-it/algo-builder/blob/master/docs/guide/deployer.md#managing-artifacts).

##### ⭐️ ❯ `AlgoBuilderScriptFactory`
This is the main extensible feature to customize, configure and extend custom scripts contexts with custom plugins features.
```typescript
// # scripts/ext/my-custom-script-context.ts
const MyAlgoBuilderScript = AlgoBuilderScriptFactory()
  .withPlugin((ctx) => {
    return {
      ...ctx, // It's the base context IRunScriptContext
      myCoolStuff: (account: Account) => `Hello ${account.address}`
    }
  })
  // Also can add more plugins .withPlugin(otherPlugin) with context inherit

// # scripts/use.ts
export default MyAlgoBuilderScript.of((ctx) => {
    // ctx.myCoolStuff is available. And it have AUTOCOMPLETE!! 🎉
    ctx.myCoolStuff(ctx.deployer.accountsByName.get('Alice'))
    // Hello AKCX..YQJETM
})
```


### 📁 Accouts
##### ❯ `accountsBalanceReference`
Show changes on the balances of accounts
```typescript
const ref = await accountsBalanceReference(ctx.deployerExt).of([alice])
// transfer 1000 $ALGO to alice
ref.printDiff() // Yes!! it have colors 🤪
┌───────┬────────────────────────────────────────────────────────────┬─────────────────┬─────────────────────────┬────────┬───────────┐
│ Name  │ address                                                    │ $µALGO          │ $µALGO diff             │ $USD   │ $USD diff │
├───────┼────────────────────────────────────────────────────────────┼─────────────────┼─────────────────────────┼────────┼───────────┤
│ Alice │ FYPJZLHO67DNODLNNTUG7KQBE2ZTBOQJIXSBGSJB5DYFPARDKOZAEDCRYI │ 0 -> 1000000000 │ ↑ 1000000000 • $409.131 │ 0 -> 0 │  0        │
└───────┴────────────────────────────────────────────────────────────┴─────────────────┴─────────────────────────┴────────┴───────────┘

```

### 📁 Applications
##### ❯ `AppState`
Show changes on the state (global & local) of application (smart contracts)
```typescript
const state = new AppState(ctx, 'Factory')
await state.takeSnapshot()
// do something interesting with the contract
await state.printDiff()
```
The following will be printed on the console:
```console
┌──────────────┬──────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────┐
│ Key          │ Old Value                                    │ New Value                                                                                │
├──────────────┼──────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ FEE_ADDR     │ 5rjfIlCKqXUaKhpXWP3rfLua3Nvb3OFHUYWDqk+qfxw= │ 5rjfIlCKqXUaKhpXWP3rfLua3Nvb3OFHUYWDqk+qfxw=                                             │
├──────────────┼──────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ MANAGER_ADDR │ 5rjfIlCKqXUaKhpXWP3rfLua3Nvb3OFHUYWDqk+qfxw= │ 5rjfIlCKqXUaKhpXWP3rfLua3Nvb3OFHUYWDqk+qfxw=                                             │
├──────────────┼──────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ POFIP_HASH   │ null                                         │ hnzzWDKj8vXxjuf2+ysPFugHLyHbF4lNMTbUPRjbpQOGfPNYMqPy9fGO5/b7Kw8W6AcvIdsXiU0xNtQ9GNulAw== │
└──────────────┴──────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────┘
```
_tip: you can call `takeSnapshot()` again on the same object to update snapshot._

### 📁 Constants
##### ❯ `FLAT_PAY`
Common object to pass on `ctx.deployer.executeTx()`

##### ❯ `flatPayWithMore(amountOfTransactions)`
A flat pay to use on application call which do more than `N` inner transaction

### 📁 Encoder
##### ❯ `strToUInt8Array`
Convert from `string` to `Uint8Array`
##### ❯ `uInt8ArrayToStr`
Convert from `Uint8Array` to `string`
##### ❯ `b64ToString`
Convert from encoded b64 string to string. Example `b64ToString('SEVMTE8=')` -> `HELLO` ([playground](https://www.base64encode.org/))


### 📁 Model
Interfaces to use and type responses of AlgoClient.

### 📁 Terminal
##### ❯ `forPressEnter`
Just a sync method which wait to press enter on the stdin. It block the execution script.

## TODO
- [ ] Extend asset list for customization (see `AssetName`)
- [ ] Complete doc with more example and refs
- [ ] Split imports 
  - `import { AlgoBuilderScriptFactory } from '@travelx/algob-ext/ext/factory'`
  - `import { Encoder } from '@travelx/algob-ext/encoder'`. Then `Encoder.strToUInt8Array(..)`

---
_Source: https://npm.io/package/@travelx/algob-ext · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
