[
"autonomous agent",
{
"init": "{
$owner = 'JBGMJI7XSKLKNHZF26BUBWHVUZSDV3P5';
$fee = 1500;
$addr = trigger.address;
$base_inp = trigger.output[[asset=base]];
if(trigger.output[[asset!=base]].asset != 'none')
$asset = trigger.output[[asset!=base]].asset;
if($asset){
if($asset == 'ambiguous'){
bounce("only 1 asset per tx");
}
if(trigger.output[[asset!=base]] ==0)
bounce("zero asset tx");
$asset_inp = trigger.output[[asset!=base]];
}
if(var['asset']){
if($asset and var['asset'] != $asset)
bounce("not a previously defined asset");
}
else{
if(!trigger.data.define)
bounce("a asset must be defined first time");
}
$ratio = 10000000/data_feed[[oracles='F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N', feed_name='GBYTE_USD']];
//bytes per 1 asset-centUSD-
}",
"messages": {
"cases": [
{
"if": "{trigger.data.define and $addr == $owner}",
"messages": [
{
"app": "asset",
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": true,
"fixed_denominations": false,
"issued_by_definer_only": false,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{ var['asset'] = response_unit; }"
}
]
},
{
"if": "{
$asset
}",
"messages": [
{
"init": "{
$byte_amount = round($asset_inp*(0.97*$ratio));
}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$byte_amount}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'redeemed '||$asset_inp||' centUSD';
}"
}
]
},
{
"if": "{
!$asset
}",
"messages": [
{
"init": "{
$issue_amount = round($base_inp/$ratio);
}",
"app": "payment",
"payload": {
"asset": "{var['asset']}",
"outputs": [
{
"address": "{$addr}",
"amount": "{$issue_amount}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'issued '||$issue_amount||' centUSD';
}"
}
]
}
]
}
}
]