[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
$owner = var['owner'] OTHERWISE "
WMFLGI2GLAB2MDF2KQAH37VNRRMK7A5N";
require(trigger.address == $owner, 'only owner can add or update agent');
$aa_address = trigger.data.aa_address;
if ($aa_address) {
require(is_aa($aa_address), 'AA address isn\ valid!');
}
$category = trigger.data.category;
if ($category) {
require(typeof($category) == 'string', 'Category must be a string');
require(length($category) > 0 AND length($category) <= 30, 'Min 1 symbol; Max 30 symbols');
}
$symbol = trigger.data.symbol;
if ($symbol) {
require(length($symbol) > 0 AND length($symbol) <= 20, 'Min 1 symbol; Max 20 symbols');
require($symbol == to_upper($symbol), 'Symbol must be uppercase');
}
$name = trigger.data.name;
require(length($name) >= 5 AND length($name) <= 50, 'Min 5 symbol; Max 50 symbols');
$description = trigger.data.description;
if ($description) {
require(length($description) > 5 AND length($description) <= 250, 'Min 5 symbol; Max 250 symbols');
}
$logo_url = trigger.data.logo_url;
if ($logo_url) {
require(length($logo_url) <= 300, 'max 300 symbols');
require(starts_with($logo_url, "https://"), 'Logo URL is not valid');
}
$website = trigger.data.website;
if ($website) {
require(starts_with($website, "https://"), 'Website URL is not valid');
require(length($website) <= 100, 'max 100 symbols');
}
}",
"getters": "{
$get_agent = ($aa_address) => var['agent.' || $aa_address] OTHERWISE {};
}",
"messages": {
"cases": [
{
"if": "{trigger.data.listing}",
"init": "{
require($aa_address, 'AA address is required');
$agent = var['agent.' || $aa_address];
require(!exists($agent), 'agent already listed');
$s2a = var['s2a.' || $symbol];
require(!exists($s2a), 'symbol already listed');
}",
"messages": [
{
"app": "state",
"state": "{
$info = {
symbol: $symbol,
name: $name,
address: $aa_address,
description: $description
};
if ($website) {
$info.website = $website;
}
if ($category) {
$info.category = $category;
}
if ($description) {
$info.description = $description;
}
if ($logo_url) {
$info.logo_url = $logo_url;
}
var['agent.' || $aa_address] = $info;
var['s2a.' || $symbol] = $aa_address;
response['listed'] = $info;
}"
}
]
},
{
"if": "{trigger.data.update}",
"init": "{
require($aa_address, 'AA address is required');
$agent = var['agent.' || $aa_address];
require($agent, 'agent not found');
$field_name = trigger.data.field_name;
require($field_name, 'field name is required');
require($field_name == 'name' OR $field_name == 'description' OR $field_name == 'logo_url' OR $field_name == 'website' OR $field_name == 'category', 'field name is not valid');
$value = trigger.data[$field_name];
require($value, 'value is required');
}",
"messages": [
{
"app": "state",
"state": "{
$agent[$field_name] = $value;
var['agent.' || $aa_address] = $agent;
response['updated'] = $agent;
}"
}
]
},
{
"if": "{trigger.data.remove}",
"init": "{
require($aa_address, 'AA address is required');
$agent = var['agent.' || $aa_address];
require($agent, 'agent not found');
}",
"messages": [
{
"app": "state",
"state": "{
response['removed'] = $agent;
var['agent.' || $aa_address] = false;
var['s2a.' || $agent.symbol] = false;
}"
}
]
},
{
"if": "{trigger.data.change_owner}",
"init": "{
$new_owner = trigger.data.new_owner;
require(is_valid_address($new_owner), 'New owner address is not valid');
}",
"messages": [
{
"app": "state",
"state": "{
var['owner'] = $new_owner;
response['new_owner'] = $new_owner;
}"
}
]
}
]
}
}
]