[
"autonomous agent",
{
"init": "{
$OSTABLE_DEP_ADDR = 'LBJNRHIU2E4BCZ7OLSY2HVI2MTSTPQR4';
$OSTABLE_CURVE_ADDR = $OSTABLE_DEP_ADDR.$get_curve_aa();
$OSWAP_POOL_ADDR = 'HZCD3MDGCLU2G2IVYGGTMTZXS7DII2O5';
$STABLE_ASSET = '/YZQqJFN71D0Xa7w/WRWhnNwCxQojItoQITl9M9cMME=';
$OWNER_ADDR = 'UXLQ6IRUWYK4P5AAYEV2ZE3FCECWNA5M';
$addDeposit = =>{
$deposits = var['deposits'] otherwise [];
$deposits[] = trigger.data.id;
var['deposits'] = $deposits;
};
$removeDeposit = $ind =>{
$deposits = var['deposits'] otherwise [];
delete($deposits, $ind);
var['deposits'] = $deposits;
};
}",
"messages": {
"cases": [
{
"if": "{trigger.data.interest OR var['index']}",
"init": "{
$ind = var['index'] otherwise 0;
$deposits = var['deposits'];
$id = $deposits[$ind];
}",
"messages": [
{
"if": "{$id}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$OSTABLE_DEP_ADDR}",
"amount": 1
}
]
}
},
{
"if": "{$id}",
"app": "data",
"payload": {
"id": "{$id}"
}
},
{
"if": "{!$id AND var['swap']}",
"app": "payment",
"payload": {
"asset": "{$STABLE_ASSET}",
"outputs": [
{
"address": "{$OSWAP_POOL_ADDR}"
}
]
}
},
{
"if": "{!$id AND var['swap']}",
"app": "data",
"payload": {
"to": "{$OWNER_ADDR}"
}
},
{
"app": "state",
"state": "{
if($id)
var['index'] = $ind + 1;
else
var['index'] = false;
}"
}
]
},
{
"if": "{trigger.data.add_dep and trigger.data.id AND trigger.address == $OWNER_ADDR}",
"messages": [
{
"app": "state",
"state": "{
$addDeposit();
}"
}
]
},
{
"if": "{trigger.data.swap AND trigger.address == $OWNER_ADDR}",
"messages": [
{
"app": "state",
"state": "{
if(trigger.data.swap == 1)
var['swap'] = 1;
else
var['swap'] = false;
}"
}
]
},
{
"if": "{trigger.data.rm_dep and trigger.data.index AND trigger.address == $OWNER_ADDR}",
"messages": [
{
"app": "state",
"state": "{
$removeDeposit();
}"
}
]
},
{
"if": "{trigger.data.withdraw AND trigger.address == $OWNER_ADDR}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{trigger.data.asset otherwise 'base'}",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
}
]
}
]
}
}
]