[
"autonomous agent",
{
"getters": "{
$polloAddr = => '5TT7JV3M5PNE2WSAA3YGOX7ZZXKIMG35';
$stableAsset = => 'blao';
}",
"init": "{
$act= => trigger.data.action otherwise 'b';
$timespan = 60*60*24*30;
$year = 24*60*60*365;
if(trigger.output[[asset!=base]].asset != 'none'){
$asset = trigger.output[[asset!=base]].asset;
if($asset and $asset != $stableAsset())
bounce('only bytes or stable asset');
}
else
$asset = 'base';
}",
"messages": {
"cases": [
{
"if": "{
$act() == 'create' and $polloAddr() == trigger.address
}",
"messages": [
{
"app": "state",
"state": "{
var[trigger.unit||'_producer'] = trigger.data.producer;
var[trigger.unit||'_amount_r'] = trigger.data.amount;
if(trigger.data.stable)
var[trigger.unit||'_asset'] = $stableAsset();
else
var[trigger.unit||'_asset'] = 'base';
}"
}
]
},
{
"if": "{
$act() == 'cancel' and $polloAddr() == trigger.address
}",
"init": "{
if(!var[trigger.data.id||'_producer'])
bounce('application not found');
if(var[trigger.data.id||'_donor'])
bounce('already filled');
}",
"messages": [
{
"app": "state",
"state": "{
var[trigger.data.id||'_producer'] = false;
var[trigger.data.id||'_amount_r'] = false;
var[trigger.data.id||'_asset'] = false;
}"
}
]
},
{
"if": "{
$act() == 'withdraw' and $polloAddr() == trigger.address
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{balance[base] - storage_size - var['user_bytes'] - 20000}"
}
]
}
}
]
},
{
"if": "{
$act() == 'return' and trigger.address == $polloAddr()
}",
"init": "{
if(!var[trigger.data.id||'_producer'])
bounce('application not found');
if(!var[trigger.data.id||'_donor'])
bounce('not filled');
if(var[trigger.data.id||'_time']+$timespan < timestamp)
bounce('donor must wait 30 days before return');
if(var[trigger.data.id||'_time']+$year > timestamp){
$to_aa = true;
}
if(var[trigger.data.id||'_donor'] == $polloAddr())
$to_aa = true;
}",
"messages": [
{
"if": "{!$to_aa}",
"app": "payment",
"payload": {
"asset": "{var[trigger.data.id||'_asset']}",
"outputs": [
{
"address": "{trigger.data.addr}",
"amount": "{var[trigger.data.id||'_amount']}"
}
]
}
},
{
"app": "state",
"state": "{
if(!$to_aa){
if(var[trigger.data.id||'_asset'] == 'base'){
var['user_bytes'] -= var[trigger.data.id||'_amount'];
}
}
else{
if(var[trigger.data.id||'_asset'] == 'base'){
var['donation_'||var[trigger.data.id||'_donor']] -= var[trigger.data.id||'_amount'];
var['donation_'||$polloAddr()] += var[trigger.data.id||'_amount'];
}
else{
var['donationsc_'||var[trigger.data.id||'_donor']] -= var[trigger.data.id||'_amount'];
var['donationsc_'||$polloAddr()] += var[trigger.data.id||'_amount'];
}
}
var[trigger.data.id||'_amount'] = false;
var[trigger.data.id||'_producer'] = false;
var[trigger.data.id||'_donor'] = false;
var[trigger.data.id||'_time'] = false;
var[trigger.data.id||'_asset'] = false;
}"
}
]
},
{
"if": "{
$act() == 'donate' and $polloAddr() == trigger.address
}",
"init": "{
if(!var[trigger.data.id||'_amount_r']){
bounce('application already filled');
}
$donor = trigger.data.donor;
if(!$donor)
bounce('donor missing');
if(var[trigger.data.id||'_asset'] == 'base' and !var['donation_'||$donor])
bounce('donor dont have funds to donate');
if(var[trigger.data.id||'_asset'] != 'base' and !var['donationsc_'||$donor])
bounce('donor dont have funds to donate');
if(var[trigger.data.id||'_asset'] == 'base'){
if(var[trigger.data.id||'_amount_r'] > var['donation_'||$donor])
bounce('not enough funds, please refill');
}
else{
if(var[trigger.data.id||'_amount_r'] > var['donationsc_'||$donor])
bounce('not enough funds, please refill');
}
}",
"messages": [
{
"app": "state",
"state": "{
if(var[trigger.data.id||'_asset'] == 'base'){
var['donation_'||$donor] -= var[trigger.data.id||'_amount_r'];
}
else{
var['donationsc_'||$donor] -= var[trigger.data.id||'_amount_r'];
}
var[trigger.data.id||'_amount'] = var[trigger.data.id||'_amount_r'];
var[trigger.data.id||'_amount_r'] = false;
var[trigger.data.id||'_donor'] = $donor;
var[trigger.data.id||'_time'] = timestamp;
}"
}
]
},
{
"if": "{
$act() == 'confirm' and $polloAddr() == trigger.address
}",
"init": "{
if(!var[trigger.data.id||'_producer'])
bounce('application not found');
if(var[trigger.data.id||'_amount_r'])
bounce('not filled yet');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{var[trigger.data.id||'_asset']}",
"outputs": [
{
"address": "{var[trigger.data.id||'_producer']}",
"amount": "{var[trigger.data.id||'_amount']}"
}
]
}
},
{
"app": "state",
"state": "{
if(var[trigger.data.id||'_asset'] == 'base')
var['user_bytes'] -= var[trigger.data.id||'_amount'];
var[trigger.data.id||'_asset'] = false;
var[trigger.data.id||'_amount'] = false;
var[trigger.data.id||'_amount_r'] = false;
var[trigger.data.id||'_producer'] = false;
var[trigger.data.id||'_time'] = false;
}"
}
]
},
{
"init": "{
$donor = trigger.data.donor;
if(!trigger.data.donor)
bounce('donor param not found');
}",
"messages": [
{
"if": "{$asset != 'base'}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{8000}"
}
]
}
},
{
"app": "state",
"state": "{
if($asset == 'base'){
var['donation_'||$donor] += trigger.output[[asset=base]];
var['user_bytes'] += trigger.output[[asset=base]];
}
else{
var['donationsc_'||$donor] += trigger.output[[asset!=base]];
}
}"
}
]
}
]
}
}
]