[
"autonomous agent",
{
"bounce_fees": {
"base": 30000
},
"init": "{
// bounce_fees might cover premium so make min premium a bit expensive
// varaibles to be filled on front end bu insurance service maker...
$mcr = 110000; // minium/maximum capital requirement to activate this service...
$expiration = 86400 * 360; // 12 months of cover
$selected_arbiter = ''; // Address of selected arbiter to make final decision
$min_premium = 100; // min premium to pay by single user one time to get certain amount of coverage
$coverage_times = 12; // Premium amount multiply with this value, so here it could be 100 * 12 = 1200
$author_address = 'T77QBAHR4CN2G6KJ3BHMJLAAPU2WG2KG';
$aa_expiration = 1606827661; // (2020 Dec 1) Expiration of this AA and then extending it with insurance expiration days to take all insurances out...
$old_investment = 0;
}",
"messages": {
"cases": [
{
"if": "{timestamp >= $aa_expiration AND var['close_investment'] == false}",
"messages": [
{
"app": "state",
"state": "{
var['close_investment'] = true;
response['unaccepted_request'] = 'Your request to get invest in this AA is not accepted, because the investments are closed because aa is Expired...';
}"
}
]
},
{
"if": "{trigger.data.investor AND var['close_investment'] == false}",
"messages": {
"cases": [
{
"if": "{var['investor_'||trigger.address]}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get invest in this AA is not accepted, because the investments cannot be done from same address again, You can withdraw previous and invest again with your new amount...';
}"
}
]
},
{
"if": "{balance[base] >= $mcr AND !var['investor_'||trigger.address]}",
"messages": [
{
"app": "state",
"state": "{
var['close_investments'] = true; // close further investments
var['investments_locked'] = false; // only locked when a user buy insurance
var['start_service'] = true; // Let users buy insurances
var['capitalLocked'] = 0;
var['investor_'||trigger.address] = trigger.output[[asset=base]]; // how much invested...
}"
}
]
},
{
"if": "{balance[base] < $mcr AND !var['investor_'||trigger.address]}",
"messages": [
{
"app": "state",
"state": "{
var['close_investments'] = false; // let further investments come, On withdraw make the close_investment true if balance is less than mcr
var['investments_locked'] = false; // only locked when a user buy insurance so no service started here
var['start_service'] = false;
// Don't let users buy anything because minimum capital requirement is not fullfilled
var['capitalLocked'] = 0;
var['investor_'||trigger.address] = trigger.output[[asset=base]]; // how much invested...
}"
}
]
}
]
}
},
{
"if": "{trigger.data.investor AND var['close_investment'] == true}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get invest in this AA is not accepted, The investments are closed because Minimum/Maximum Capital required to start this service is fullfilled and locked, thank you.';
}"
}
]
},
{
"if": "{trigger.data.insured AND trigger.output[[asset=base]] >= $min_premium AND var['start_service'] == true}",
"messages": {
"cases": [
{
"if": "{($mcr - var['capitalLocked']) > (trigger.output[[asset=base]] * $coverage_times)}",
"messages": [
{
"app": "state",
"state": "{
var['insured_' || trigger.address] = trigger.output[[asset=base]] * $coverage_times;
var['capitalLocked'] = var['capitalLocked'] + (trigger.output[[asset=base]] * $coverage_times);
response['accepted_request'] = 'Your request to get insured is accepted, Your coverage is ' || (trigger.output[[asset=base]] * $coverage_times) || ' and you paid - ' || trigger.output[[asset=base]];
}"
}
]
},
{
"if": "{($mcr - var['capitalLocked']) < (trigger.output[[asset=base]] * $coverage_times)}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get insured is not accepted, because the capital left is not enough to give you the right coverage, The capital left to be used is just ' || ($mcr - var['capitalLocked']);
}"
}
]
}
]
}
},
{
"if": "{trigger.data.insured AND var['start_service'] != true}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get insured is not accepted, because the minimum requirement of capital is not fullfilled yet!';
}"
}
]
},
{
"if": "{trigger.data.insured AND trigger.output[[asset=base]] < $min_premium}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get insured is not accepted, because the minimum one time premium to pay to buy this policy is ' || $min_premium || ' But you paid ' || trigger.output[[asset=base]];
}"
}
]
},
{
"if": "{trigger.data.claim AND trigger.output[[asset=base]] < $min_premium}",
"messages": [
{
"app": "state",
"state": "{
response['unaccepted_request'] = 'Your request to get insured is not accepted, because the minimum one time premium to pay to buy this policy is ' || $min_premium || ' But you paid ' || trigger.output[[asset=base]];
}"
}
]
}
]
}
}
]