Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Boot functionality #65

Merged
merged 27 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a5d3c44
feat(boot): add ant boot loader handler
atticusofsparta Jan 14, 2025
76e103f
fix(boot): do not require ant registry id to boot
atticusofsparta Jan 23, 2025
de0dbf2
Merge remote-tracking branch 'origin/develop' into PE-7422-on-boot
atticusofsparta Jan 23, 2025
6f402fa
Merge remote-tracking branch 'origin/develop' into PE-7422-on-boot
atticusofsparta Jan 26, 2025
7f04c36
fix(tests): add test for booting ANT state
atticusofsparta Jan 26, 2025
74a70d9
fix(boot): only send credit notice if owner is not nil
atticusofsparta Jan 26, 2025
2273e51
fix(lua): cross platform install script for lua
atticusofsparta Jan 23, 2025
192920f
fix(install script): focus on lua and luarocks and rec dependency ins…
atticusofsparta Jan 23, 2025
1d3494d
Merge pull request #62 from ar-io/lua-deps-improvements
dtfiedler Jan 27, 2025
063c56f
fix(readme): update readme with boot
atticusofsparta Jan 27, 2025
7ae6ea9
fix(initialize): add typedef and description
atticusofsparta Jan 27, 2025
f9f79a0
Merge branch 'develop' into PE-7422-on-boot
atticusofsparta Jan 27, 2025
6fa5de2
fix(luadoc): rename typedef and invalid luadoc decorator
atticusofsparta Jan 27, 2025
ab0f6eb
Merge remote-tracking branch 'refs/remotes/origin/PE-7422-on-boot' in…
atticusofsparta Jan 27, 2025
63408fd
fix(boot): switch once to prepend
atticusofsparta Jan 27, 2025
63d069e
fix(boot): use once for boot handler
atticusofsparta Jan 27, 2025
8954fa0
fix(tests): move loader instantiation into individual test
atticusofsparta Jan 27, 2025
3506a63
Merge pull request #57 from ar-io/PE-7422-on-boot
atticusofsparta Jan 27, 2025
2d6ecf6
chore(changelog): update changelog
atticusofsparta Jan 28, 2025
6b3c29b
Merge pull request #64 from ar-io/update-changelog-12
atticusofsparta Jan 28, 2025
f7fe470
fix(records): update min ttl and remove restriction on max records of…
atticusofsparta Jan 28, 2025
db517ee
fix(ttl): change make to 1 day in seconds and default to 900 in examples
atticusofsparta Jan 28, 2025
2483c1c
chore(docs): update changelog
dtfiedler Jan 28, 2025
b24d950
fix(require): remove import of constants causing circular require wit…
atticusofsparta Jan 28, 2025
9933d91
Merge remote-tracking branch 'refs/remotes/origin/PE-7518-ttl-changes…
atticusofsparta Jan 28, 2025
a207553
fix(default): default base record to 900 seconds
dtfiedler Jan 28, 2025
8f6f131
Merge pull request #66 from ar-io/PE-7518-ttl-changes
dtfiedler Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ return {
default = {
root = "src",
pattern = "**/*_spec.lua$",
exclude = {
"**/luarocks-3.9.1/**",
"**/lua-5.3.1/**"
},
helper = "spec/setup.lua",
verbose = true,
coverage = true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ process.wasm
dist
publish-output.json
luarocks-3.9.1
lua-5.3.1
temp-build
build
aos-process
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Changed

- Adjusts min and max allowed TTLs to 60 (1 minute) and 86400 (1 day), respetively. Defaults to 900 seconds (15 mins).
- Removed limit on undernames of 10k records.

### Added

- Boot mechanism for initializing state and sending notices to ANT Registry and Owner

## [11] - [1YqVEdJDvcpQ6qEWXYBEaVqB_NzAz4qPAsnUqLf5m3I] - (2025-1-24)

### Fixed

- Undername creation has been fixed to enable creation of one character undernames.
- Token API responses updated to spec

## [10] - [k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg] - (2025-1-14)

### Changed

- Updated build process to compile a WASM binary as well as the bundled Lua code
- Updated testing to use our own WASM binary instead of an AOS fixture

## [9] - [16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4] - (2024-12-4)

### Changed
Expand Down
145 changes: 114 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ This repository provides two flavours of ANT process module, AOS and a custom mo
- [Testing](#testing)
- [Building the AOS code](#building-the-aos-code)
- [Build](#build)
- [Lua code](#lua-code)
- [Module WASM Binary](#module-wasm-binary)
- [Publish](#publish)
- [Lua code](#lua-code-1)
- [Module WASM Binary](#module-wasm-binary-1)
- [Load](#load)
- [Lua code](#lua-code-2)
- [Module WASM Binary](#module-wasm-binary-2)
- [Spawn](#spawn)
- [Lua code](#lua-code-3)
- [Module WASM Binary](#module-wasm-binary-3)
- [Handler Methods](#handler-methods)
- [Boot Methods](#boot-methods)
- [`_boot` (WASM Binary only)](#_boot-wasm-binary-only)
- [Read Methods](#read-methods)
- [`Info`](#info)
- [`Total-Supply`](#total-supply)
Expand All @@ -39,8 +49,9 @@ This repository provides two flavours of ANT process module, AOS and a custom mo
- [`Reassign-Name`](#reassign-name)
- [Developers](#developers)
- [Requirements](#requirements)
- [Lua Setup (MacOS)](#lua-setup-macos)
- [LuaRocks Setup](#luarocks-setup)
- [Lua Setup](#lua-setup)
- [With local script (MacOS and Linux only)](#with-local-script-macos-and-linux-only)
- [Manually](#manually)
- [aos](#aos)
- [Code Formatting](#code-formatting)
- [Testing](#testing-1)
Expand All @@ -59,10 +70,10 @@ yarn
```

Then install the ao cli - read the docs [here](https://github.com/permaweb/ao/tree/main/dev-cli)
Below is latest version as of writing, refer to the docs for the latest version.
Refer to the docs for installing different versions.

```sh
curl -L https://arweave.net/iVthglhSN7G9LuJSU_h5Wy_lcEa0RE4VQmrtoBMj7Bw | bash
curl -L https://install_ao.g8way.io | bash
```

You may need to follow the instructions in the cli to add the program to your PATH.
Expand All @@ -81,39 +92,103 @@ busted .

This bundles the ant-aos code and outputs it to `dist` folder. This can then be used to send to the `Eval` method on AOS to load the ANT source code.

##### Lua code

```bash
yarn aos:build
```

##### Module WASM Binary

```bash
yarn module:build
```

#### Publish

Ensure that in the `tools` directory you place you Arweave JWK as `key.json`

##### Lua code

```bash
yarn aos:publish
```

##### Module WASM Binary

```bash
yarn module:publish
```

#### Load

This will load an AOS module into the loader, followed by the bundled aos Lua file to verify that it is a valid build.

##### Lua code

```bash
yarn aos:load
```

##### Module WASM Binary

```bash
yarn module:load
```

#### Spawn

this will spawn an aos process and load the bundled lua code into it.
This will spawn an aos process and load the bundled lua code into it.

##### Lua code

```bash
yarn aos:spawn
```

This will deploy the bundled lua file to arweave as an L1 transaction, so your wallet will need AR to pay the gas.
##### Module WASM Binary

```bash
yarn module:spawn
```

This will deploy the bundled lua file or WASM module to arweave as an L2 ([ANS-104]) transaction, so your wallet will need Turbo Credits to pay the gas.

## Handler Methods

For interacting with handlers please refer to the [AO Cookbook]
For interacting with handlers please refer to the [AR.IO SDK] or the [AO Cookbook]

### Boot Methods

#### `_boot` (WASM Binary only)

When compiled as a WASM Module Binary the ANT provides a boot method to initialize the state of the ANT.

This will send a `Credit-Notice` to the initialized Owner (if applicable) and a `State-Notice` to the [ANT Registry].

If a valid JSON string state is provided, it will be used to set the initial state of the ANT.

Example:

```json
{
"name": "Test Process",
"ticker": "TEST",
"description": "TEST DESCRIPTION",
"keywords": ["KEYWORD-1", "KEYWORD-2", "KEYWORD-3"],
"owner": "STUB_ADDRESS",
"controllers": ["STUB_ADDRESS"],
"balances": {
"STUB_ADDRESS": 1
},
"records": {
"@": {
"transactionId": "3333333333333333333333333333333333333333333",
"ttlSeconds": 900
}
}
}
```

### Read Methods

Expand Down Expand Up @@ -317,38 +392,43 @@ Calls the IO Network process to reassign the given ArNS name to a new ANT ID if
- Lua 5.3 - [Download](https://www.lua.org/download.html)
- Luarocks - [Download](https://luarocks.org/)

### Lua Setup (MacOS)
### Lua Setup

#### With local script (MacOS and Linux only)

Note that we use lua 5.3 because that is what the [ao-dev-cli](https://github.com/permaweb/ao/tree/main/dev-cli) uses

1. Clone the repository and navigate to the project directory.
1. Install `lua`
- `brew install [email protected]`
1. Add the following to your `.zshrc` or `.bashrc` file:
2. run the following:

```bash
echo 'export LDFLAGS="-L/usr/local/opt/[email protected]/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/usr/local/opt/[email protected]/include"' >> ~/.zshrc
echo 'export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
```
```shell
yarn install-lua-deps
```

#### Manually

1. Run `source ~/.zshrc` or `source ~/.bashrc` to apply the changes.
1. Run `lua -v` to verify the installation.
1. Build and install lua

### LuaRocks Setup
```shell
curl -R -O https://lua.org/ftp/lua-5.3.1.tar.gz
tar -xzvf lua-5.3.1.tar.gz
cd lua-5.3.1
make
make install
```

1. Install `luarocks`
2. Build and install LuaRocks

```bash
curl -R -O http://luarocks.github.io/luarocks/releases/luarocks-3.9.1.tar.gz
tar zxpf luarocks-3.9.1.tar.gz
cd luarocks-3.9.1
./configure --with-lua=/usr/local/opt/[email protected] --with-lua-include=/usr/local/opt/[email protected]/include
make build
sudo make install
```
Note that we do not specify the lua version, it will discover it.

1. Check the installation by running `luarocks --version`.
1. Check the LuaRocks configuration by running `luarocks config | grep LUA`
```shell
curl -R -O http://luarocks.github.io/luarocks/releases/luarocks-3.9.1.tar.gz
tar zxpf luarocks-3.9.1.tar.gz
cd luarocks-3.9.1
./configure --with-lua=/usr/local --with-lua-include=/usr/local/include
make build
sudo make install
```

If you ever need to refresh .luarocks, run the following command:

Expand Down Expand Up @@ -412,8 +492,11 @@ dependencies = {
- [ArNS Docs]
- [ArNS Portal]
- [AO Cookbook]
- [AR.IO SDK]

[AR.IO Gateways]: https://docs.ar.io/gateways/ar-io-node/overview/
[AR.IO SDK]: https://www.npmjs.com/package/@ar.io/sdk
[ANT Registry]: https://github.com/ar-io/ar-io-ant-registry-process
[ArNS Docs]: https://ar.io/docs/arns/
[ArNS ANT Docs]: https://ar.io/docs/arns/#arweave-name-token-ant
[ArNS Portal]: https://arns.app
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"aos:load": "node tools/bundle-aos.mjs && node tools/load-aos.mjs",
"aos:spawn": "node tools/spawn-aos.mjs",
"test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs",
"install-lua-deps": "sh tools/install-lua-deps.sh && luarocks install ar-io-ao-0.1-1.rockspec",
"prepare": "husky"
},
"devDependencies": {
Expand Down
15 changes: 11 additions & 4 deletions spec/ant_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,24 @@ describe("Arweave Name Token", function()
assert.is_false(hasController)
end)

it("sets a record", function()
local name, transactionId, ttlSeconds = "@", fake_address, 900
it("sets a record with min ttl", function()
local name, transactionId, ttlSeconds = "@", fake_address, 60
records.setRecord(name, transactionId, ttlSeconds) -- happy path
assert.are.same(_G.Records["@"].transactionId, fake_address)
assert.are.same(_G.Records["@"].ttlSeconds, 900)
assert.are.same(_G.Records["@"].ttlSeconds, 60)
end)

it("sets a record with max ttl", function()
local name, transactionId, ttlSeconds = "@", fake_address, 86400
records.setRecord(name, transactionId, ttlSeconds) -- happy path
assert.are.same(_G.Records["@"].transactionId, fake_address)
assert.are.same(_G.Records["@"].ttlSeconds, 86400)
end)

it("gets all records", function()
_G.Records["@"] = {
transactionId = string.rep("1", 43),
ttlSeconds = 3600,
ttlSeconds = 900,
}
local recordEntries = records.getRecords()

Expand Down
5 changes: 3 additions & 2 deletions src/common/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ local constants = {}
constants.MAX_UNDERNAME_LENGTH = 61
constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE = "Name does not exist in the ANT!"
constants.INVALID_ARWEAVE_ID_MESSAGE = "Invalid Arweave ID"
constants.MIN_TTL_SECONDS = 900
constants.MAX_TTL_SECONDS = 3600
constants.MIN_TTL_SECONDS = 60
constants.DEFAULT_TTL_SECONDS = 900
constants.MAX_TTL_SECONDS = 86400 -- 1 day in seconds
constants.INVALID_TTL_MESSAGE = "Invalid TTL. TLL must be an integer between "
.. constants.MIN_TTL_SECONDS
.. " and "
Expand Down
15 changes: 15 additions & 0 deletions src/common/initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ local utils = require(".common.utils")
local json = require(".common.json")
local initialize = {}

---@alias InitialANTState {
--- name: string,
--- ticker: string,
--- description: string,
--- keywords: table<string>,
--- logo: string,
--- balances: table<string, integer>,
--- owner: string,
--- controllers: string[],
--- records: table<string, Record>,
---}

--- Initializes the ANT state from a JSON string
---@param state InitialANTState
---@return string JSON representation of the initialized ANT State
function initialize.initializeANTState(state)
local encoded = json.decode(state)
local balances = encoded.balances
Expand Down
Loading
Loading