Definition: [
"autonomous agent",
{
"init": "{
$OWNER = 'JBGMJI7XSKLKNHZF26BUBWHVUZSDV3P5';
$CAP = 20;
if(typeof(var['fee']) != 'number' AND $OWNER != trigger.address) bounce('Not active yet, wait until owner '||$OWNER||' activation');
if(trigger.data.to AND !is_valid_address(trigger.data.to)) bounce('To param invalid');
if(trigger.data.from AND !is_valid_address(trigger.data.from)) bounce('From param invalid');
if(trigger.data.spender AND !is_valid_address(trigger.data.spender)) bounce('Spender param invalid');
if(trigger.data.owner AND !is_valid_address(trigger.data.owner)) bounce('Owner param invalid');
if(!trigger.data.approve AND trigger.data.value AND trigger.data.value <= 0) bounce('Value param invalid');
if(trigger.data.return AND !is_valid_address(trigger.data.return)) bounce('Return address invalid');
$base_inp = trigger.output[[asset=base]] - var['fee'];
$address_to_return = trigger.data.return otherwise trigger.address;
}",
"messages": {
"cases": [
{
"if": "{
trigger.data.total_supply
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "data",
"payload": {
"total_supply": "{var['total_supply']}"
}
},
{
"app": "state",
"state": "{
response['total_supply'] = var['total_supply'];
}"
}
]
},
{
"if": "{
trigger.data.balance_of
}",
"init": "{
$adrb = trigger.data.owner otherwise trigger.address;
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "data",
"payload": {
"balance": "{var['a_' || $adrb]}"
}
},
{
"app": "state",
"state": "{
response['balance of '||$adrb] = var['a_' || $adrb];
}"
}
]
},
{
"if": "{
trigger.data.transfer
}",
"init": "{
if(!var['a_'||trigger.address]) bounce('No funds found');
if(!trigger.data.to) bounce('To param missing');
if(!trigger.data.value) bounce('Value param missing');
if(trigger.data.value > var['a_'||trigger.address]) bounce('You have max '||var['a_'||trigger.address]);
}",
"messages": [
{
"app": "data_feed",
"payload": {
"event": "transfer",
"from": "{trigger.address}",
"to": "{trigger.data.to}",
"value": "{trigger.data.value}"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "state",
"state": "{
var['a_' || trigger.data.to] += trigger.data.value;
var['a_'||trigger.address] -= trigger.data.value;
if(var['a_'||trigger.address] == 0) var['a_'||trigger.address] = false;
}"
}
]
},
{
"if": "{
trigger.data.transfer_from
}",
"init": "{
if(!trigger.data.from) bounce('From param missing');
if(!trigger.data.to) bounce('To param missing');
if(!trigger.data.value) bounce('Value param missing');
if(!var['perm_' || trigger.data.from || '_' || trigger.address]) bounce('Not allowed to spend');
if(var['perm_' || trigger.data.from || '_' || trigger.address] < trigger.data.value) bounce('You can spend max '||var['perm_' || trigger.data.from || '_' || trigger.address]);
if(trigger.data.value > var['a_' || trigger.data.from]) bounce('Account have '||var['a_' || trigger.data.from]);
}",
"messages": [
{
"app": "data_feed",
"payload": {
"event": "transfer",
"from": "{trigger.data.from}",
"to": "{trigger.data.to}",
"value": "{trigger.data.value}"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "state",
"state": "{
var['a_' || trigger.data.to] += trigger.data.value;
var['a_' || trigger.data.from] -= trigger.data.value;
if(var['a_' || trigger.data.from] == 0) var['a_' || trigger.data.from] = false;
var['perm_' || trigger.data.from || '_' || trigger.address] -= trigger.data.value;
if(var['perm_' || trigger.data.from || '_' || trigger.address] == 0) var['perm_' || trigger.data.from || '_' || trigger.address] = false;
}"
}
]
},
{
"if": "{
trigger.data.approve
}",
"init": "{
if(!trigger.data.spender) bounce('Spender param missing');
if(!trigger.data.value) bounce('Value param missing');
if(trigger.data.value < 0) bounce('Value param invalid');
}",
"messages": [
{
"app": "data_feed",
"payload": {
"event": "approval",
"owner": "{trigger.address}",
"spender": "{trigger.data.spender}",
"value": "{trigger.data.value}"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "state",
"state": "{
var['perm_' || trigger.address || '_' || trigger.data.spender] = trigger.data.value;
if(var['perm_' || trigger.address || '_' || trigger.data.spender] == 0) var['perm_' || trigger.address || '_' || trigger.data.spender] = false;
}"
}
]
},
{
"if": "{
trigger.data.allowance
}",
"init": "{
if(!trigger.data.owner) bounce('Owner param missing');
if(!trigger.data.spender) bounce('Spender param missing');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "data",
"payload": {
"remaining": "{var['perm_' || trigger.data.owner || '_' || trigger.data.spender]}"
}
},
{
"app": "state",
"state": "{
response['remaining'] = var['perm_' || trigger.data.owner || '_' || trigger.data.spender];
}"
}
]
},
{
"if": "{
trigger.data.mint
}",
"init": "{
if($CAP) bounce('Limited asset, mint not allowed');
if(trigger.address != $OWNER) bounce('You are not owner');
if(!trigger.data.to) bounce('To param missing');
if(!trigger.data.value) bounce('Value param missing');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "data_feed",
"payload": {
"event": "mint",
"to": "{trigger.data.to}",
"value": "{trigger.data.value}"
}
},
{
"app": "state",
"state": "{
var['a_' || trigger.data.to] += trigger.data.value;
var['total_supply'] += trigger.data.value;
}"
}
]
},
{
"if": "{
trigger.data.burn
}",
"init": "{
if($CAP) bounce('Limited asset, burn not allowed');
if(!trigger.data.value) bounce('Value param missing');
if(var['a_' || trigger.address] < trigger.data.value) bounce('Not enough funds to burn');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address_to_return}",
"amount": "{$base_inp}"
}
]
}
},
{
"app": "data_feed",
"payload": {
"event": "burn",
"from": "{trigger.address}",
"value": "{trigger.data.value}"
}
},
{
"app": "state",
"state": "{
var['a_' || trigger.address] -= trigger.data.value;
if(var['a_' || trigger.address] == 0) var['a_' || trigger.address] = false;
var['total_supply'] -= trigger.data.value;
}"
}
]
},
{
"if": "{
if($OWNER != trigger.address) bounce('Accepted params: total_supply,balance_of,transfer,transfer_from,approve,allowance,burn');
trigger.data.withdraw
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$OWNER}"
}
]
}
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
if(typeof(var['fee']) != 'number' AND typeof(trigger.data.fee) != 'number') bounce('You must set up fee for first time');
if(typeof(trigger.data.fee) == 'number')
var['fee'] = trigger.data.fee >= 0 ? round(trigger.data.fee) : 0;
if(!var['total_supply']){
if($CAP){
var['total_supply'] = $CAP;
var['a_'||$OWNER] = $CAP;
}
else{
var['total_supply'] = 0;
}
response['init'] = 'coin init ok';
}
response['message'] = 'amount deposited correctly';
}"
}
]
}
]
}
}
]