[
"autonomous agent",
{
"bounce_fees": {
"base": 20000
},
"init": "{
$my_address = 'T77QBAHR4CN2G6KJ3BHMJLAAPU2WG2KG';
}",
"messages": {
"cases": [
{
"if": "{trigger.data.define}",
"messages": [
{
"app": "asset",
"payload": {
"cap": "{trigger.data.cap otherwise ''}",
"is_private": false,
"is_transferrable": true,
"auto_destroy": "{!!trigger.data.auto_destroy}",
"fixed_denominations": false,
"issued_by_definer_only": "{!!trigger.data.issued_by_definer_only}",
"cosigned_by_definer": false,
"spender_attested": "{!!trigger.data.attestor1}",
"attestors": [
"{trigger.data.attestor1 otherwise ''}",
"{trigger.data.attestor2 otherwise ''}",
"{trigger.data.attestor3 otherwise ''}"
]
}
},
{
"app": "state",
"state": "{ var[response_unit] = trigger.address; var[response_unit || ':&!!asset_name'] = trigger.data.asset_name otherwise 'default'; response['asset_unit'] = response_unit; }"
}
]
},
{
"if": "{trigger.data.withdraw AND trigger.data.asset AND trigger.data.amount AND var[trigger.data.asset] == trigger.address}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{trigger.data.asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.data.amount}"
}
]
}
}
]
},
{
"if": "{trigger.data.exchange_rate AND trigger.data.asset AND var[trigger.data.asset] == trigger.address}",
"messages": [
{
"app": "state",
"state": "{ var[trigger.data.asset || ':&!!rate'] = trigger.data.exchange_rate; response['message'] = 'set exchange rate to '||var[trigger.data.asset || ':&!!rate']||' tokens/byte'; }"
}
]
},
{
"if": "{trigger.output[[asset=base]] > 50000 AND trigger.data.asset }",
"init": "{ $bytes_amount = trigger.output[[asset=base]]; $asset_amount = round($bytes_amount * var[trigger.data.asset || ':&!!rate']); response['message'] = 'exchanged '||$bytes_amount||' bytes for '||$asset_amount||' asset.'; }",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{trigger.data.asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ $asset_amount }"
}
]
}
},
{
"app": "data",
"payload": {
"asset_amount": "{$asset_amount}",
"asset": "{trigger.data.asset}",
"sent_bytes": "{trigger.output[[asset=base]]}",
"from": "{trigger.address}",
"service_required": "{trigger.data.service_required otherwise ''}"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{var[trigger.data.asset]}",
"amount": "{trigger.output[[asset=base]]-2000}"
}
]
}
}
]
},
{
"if": "{trigger.address == $my_address AND trigger.data.withdraw_leftover}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$my_address}",
"amount": "{trigger.data.trigger.data.withdraw_leftover}"
}
]
}
}
]
},
{
"messages": [
{
"app": "state",
"state": "{ response['message'] = 'accepted coins: '||trigger.output[[asset=base]]||' bytes and '||trigger.output[[asset=trigger.data.asset]]||' asset.'; }"
}
]
}
]
}
}
]