[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
if (NOT trigger.data["method"])
bounce("method field is mandatory");
$method = trigger.data["method"];
$owner = var["owner"];
}",
"getters": "{
/*
** Attested profile (or just the address if not found)
*/
$profileOf = $address=>{
$prof = var["prof_" || $address];
return $prof OTHERWISE {};
};
$isRevoked = $nft=>{
$feed = data_feed[[oracles=this_address, feed_name=$nft, ifnone="OK", ifseveral="last", type="string"]];
return $feed == "REVOKED";
};
}",
"messages": {
"cases": [
{
"if": "{NOT $owner}",
"messages": [
{
"app": "state",
"state": "{
var["owner"] = "
IUU43O7TS2TBYKAPGKUARDZHOTAE275A";
var["helper"] = "
IUU43O7TS2TBYKAPGKUARDZHOTAE275A";
var["maxRoyalty"] = 40;
}"
}
]
},
{
"if": "{
trigger.address == $owner
AND ($method == "payout"
OR $method == "transferOwnership"
OR $method == "setHelper"
OR $method == "setReseller"
OR $method == "delReseller"
OR $method == "setMaxRoyalty"
OR $method == "unverify")
}",
"messages": {
"cases": [
{
"if": "{$method == "payout"}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
}
]
},
{
"if": "{$method == "setMaxRoyalty"}",
"init": "{
if (NOT exists(trigger.data["royalty"]))
bounce("royalty field is mandatory");
if (NOT is_integer(trigger.data["royalty"]))
bounce("royalty must be an integer");
if (trigger.data["royalty"] < 0)
bounce("royalty must be positive");
if (trigger.data["royalty"] > 100)
bounce("royalty cannot be higher than 100%");
}",
"messages": [
{
"app": "state",
"state": "{
var["maxRoyalty"] = trigger.data["royalty"];
}"
}
]
},
{
"if": "{$method == "unverify"}",
"init": "{
if (NOT trigger.data["address"])
bounce("address field is mandatory");
$_ = $profileOf(trigger.data["address"]);
$oldUsername = $_["username"];
$prof = $_ || {verified: false, username: false, isReseller: false};
$profileString = json_stringify($prof);
if (length($profileString) > 4096)
bounce("The profile is too long, the user has to remove some fields and retry verification");
}",
"messages": [
{
"app": "state",
"state": "{
var["user_" || $oldUsername] = false; //Free username
var["prof_" || trigger.data["address"]] = $prof;
}"
}
]
},
{
"if": "{$method == "transferOwnership"}",
"init": "{
if (NOT trigger.data["newOwner"])
bounce("newOwner field is mandatory");
if (NOT is_valid_address(trigger.data["newOwner"]))
bounce("newOwner field is not a valid address");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
},
{
"app": "state",
"state": "{
var["owner"] = trigger.data["newOwner"];//Ownership is transferred
}"
}
]
},
{
"if": "{$method == "setHelper"}",
"init": "{
if (NOT trigger.data["helper"])
bounce("helper field is mandatory");
}",
"messages": [
{
"app": "state",
"state": "{
var["helper"] = trigger.data["helper"];
}"
}
]
}
]
}
},
{
"if": "{
(trigger.address == $owner
OR trigger.address == var["helper"])
AND ($method == "verifyProfile"
OR $method == "revoke")
}",
"messages": {
"cases": [
{
"if": "{$method == "revoke"}",
"init": "{
if (NOT trigger.data["NFT"])
bounce("NFT field is mandatory");
$previousValue = data_feed[[oracles=[this_address], feed_name=trigger.data["NFT"], ifnone="OK", ifseveral="last", what="value", type="string"]];
$newValue = $previousValue == "OK" ? "REVOKED" : "OK";
}",
"messages": [
{
"app": "data_feed",
"payload": {
"{trigger.data["NFT"]}": "{$newValue}"
}
}
]
},
{
"if": "{$method == "verifyProfile"}",
"init": "{
if (NOT trigger.data["address"])
bounce("address field is mandatory");
if (NOT is_valid_address(trigger.data["address"]))
bounce("That address is not valid");
$profileObj = $profileOf(trigger.data["address"]) || {verified: true};
if (NOT $profileObj.username)
bounce("That user has not chosen an username");
}",
"messages": [
{
"app": "state",
"state": "{
var["user_" || $profileObj.username] = trigger.data["address"]; //Username is now taken
var["prof_" || trigger.data["address"]] = $profileObj;
}"
}
]
}
]
}
},
{
"if": "{$method == "PROFILE"}",
"init": "{
$prof = $profileOf(trigger.address);
$oldUsername = $prof.username;
$newUsername = trigger.data["username"] OTHERWISE $oldUsername;
if (NOT $oldUsername){
if (NOT trigger.data["username"])
bounce("username field is mandatory");
}
if (var["user_" || $newUsername]){
if ($oldUsername){
if ($oldUsername != $newUsername){
bounce("username already taken by a verified user");
}
}
}
if (exists(trigger.data["username"]) OR exists(trigger.data["name"]) OR exists(trigger.data["company"]) OR exists(trigger.data["isReseller"]) OR exists(trigger.data["verified"]))
$unverify = true;
else
$unverify = false;
if ($prof)
$profileObj = $prof || trigger.data || {username: $newUsername, verified: NOT $unverify};
else
$profileObj = trigger.data || {username: $newUsername, verified: NOT $unverify};
delete($profileObj, "method");
$profileString = json_stringify($profileObj);
if (length($profileString) > 4000)
bounce("Your profile is too big, try removing some fields");
}",
"messages": [
{
"app": "state",
"state": "{
if ($oldUsername){
if ($oldUsername != $newUsername)
var["user_" || $oldUsername] = false; //Free old username
}
var["prof_" || trigger.address] = $profileObj;
//Do not lock new username here. It will be locked upon verification to prevent username squatting
}"
}
]
}
]
}
}
]