[
"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
$seven_days = 86400 * 7;
$arbiter_pool = 110000 / 3; // The amount arbiter have to pay before getting into this service...
// 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] - 15000) >= $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['balance_deducted_arbiter'] = 0;
var['investor_'||trigger.address] = trigger.output[[asset=base]] - 15000; // how much invested...
}"
}
]
},
{
"if": "{(balance[base] - 15000) < $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['balance_deducted_arbiter'] = 0;
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]] - 15000; // 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 var['insured_' || trigger.address] AND !var['claim_requested_' || trigger.address]}",
"messages": [
{
"app": "data_feed",
"payload": {
"{'arbiter_'||$selected_arbiter}": "{'claiming_addr-' || trigger.address || '-addr_at_time_' || timestamp}"
}
},
{
"app": "state",
"state": "{
var['claim_requested_' || trigger.address] = true;
var['claim_amount_' || trigger.address] = var['insured_' || trigger.address];
var['claim_solved_' || trigger.address] = 0;
var['claim_requested_on_' || trigger.address] = timestamp;
var['arbiter_handeling_upto_' || trigger.address] = timestamp * $seven_days;
// seven days to solve the dispute by arbiter or the arbiter get fined with 10% base sent to insured...
}"
}
]
},
{
"if": "{trigger.data.progress_update AND var['insured_' || trigger.address] AND var['claim_requested_' || trigger.address]}",
"messages": {
"cases": [
{
"if": "{timestamp > var['arbiter_handeling_upto_' || trigger.address]}",
"messages": [
{
"app": "state",
"state": "{
var['balance_deducted_arbiter'] = round(var['claim_amount_' || trigger.address]/10);
var['arbiter_handeling_upto_' || trigger.address] = var['arbiter_handeling_upto_' || trigger.address] * $seven_days; // again wait for next seven days
// payment to send money to user...
}"
}
]
},
{
"if": "{timestamp < var['arbiter_handeling_upto_' || trigger.address]}",
"messages": [
{
"app": "state",
"state": "{
response['progress'] = 'The process of claiming you funds is undegoing by arbiter, Please feel free to send anything to it if arbiter asks you. And keep updating so you can tack your funds or claim penality fee...';
}"
}
]
}
]
}
}
]
}
}
]