Definition: [
"autonomous agent",
{
"init": "{
$asset = var['asset'];
$destination_aa = 'N6XYEP3R26Y3R25AT4NAJCEF4RT7DZCH';
$team = '265APJC3CKSPD5PB7YTCQYXE6JDODTK2';
}",
"messages": {
"cases": [
{
"if": "{trigger.data.start AND !$asset}",
"messages": [
{
"app": "asset",
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{
var[response_unit || 'status'] = 'open';
var['asset'] = response_unit;
response['asset'] = response_unit;
}"
}
]
},
{
"if": "{trigger.output[[asset=base]] >= 1e0 AND $asset}",
"init": "{
if (var[$destination_aa]['finished'])
bounce('operation is done');
$amount = trigger.output[[asset=base]] - 1000; // to account for fees we need to respond now and to refund bytes or pay shares later
$total_raised = var['total_raised'] + $amount;
$missing_amount = ceil((balance[$destination_aa][base] + $total_raised)*0.49) - var[$destination_aa]['team' || $team || 'amount'];
$bDone = ($total_raised > $missing_amount);
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$amount}"
}
]
}
},
{
"if": "{$bDone}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$destination_aa}",
"amount": "{$total_raised}"
}
]
}
},
{
"if": "{$bDone}",
"app": "data",
"payload": {
"team": "{$team}"
}
},
{
"app": "state",
"state": "{
if ($bDone)
var[$asset || '_status'] = 'raised';
else
var['total_raised'] = $total_raised;
}"
}
]
},
{
"if": "{trigger.output[[asset=var[$destination_aa]['team' || $team || 'asset']]] AND $asset}",
"messages": [
{
"app": "state",
"state": "{
var[$asset || 'status'] = 'done';
var['asset'] = false;
var['total_raised'] = false;
}"
}
]
},
{
"if": "{$asset AND trigger.output[[asset=$asset]] > 0}",
"init": "{
$amount = trigger.output[[asset=$asset]];
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$amount}"
}
]
}
},
{
"app": "state",
"state": "{
var['total_raised'] -= $amount;
}"
}
]
},
{
"if": "{
$in_asset = trigger.output[[asset!=base]].asset;
var[$in_asset || 'status'] == 'done'
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{var[$destination_aa]['team' || $team || 'asset']}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.output[[asset=$in_asset]]}"
}
]
}
}
]
}
]
}
}
]