[
"autonomous agent",
{
"init": "{
$admin = 'JBGMJI7XSKLKNHZF26BUBWHVUZSDV3P5';
$min = 2000;
$addr = trigger.address;
$inp = trigger.output[[asset=base]];
$time_btw_draw = 86400000;
}",
"messages": {
"cases": [
{
"if": "{
$allowed = balance[base] - $inp - var['Total pot'] - $min;
$total = $allowed + $inp;
$admin == $addr AND trigger.data.withdraw AND trigger.data.withdraw == 'left' AND $allowed > 0
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$addr}",
"amount": "{$total}"
}
]
}
}
]
},
{
"if": "{
var['Last draw'] AND timestamp > (var['Last draw']+$time_btw_draw)
}",
"messages": [
{
"init": "{
$num1 = data_feed[[oracles='F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N', feed_name='TOTAL_CAP']];
$num2 = data_feed[[oracles='F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N', feed_name='GBYTE_USD']];
$num3 = $num1 + $num2 + var['Last draw'];
$last_lucky = number_from_seed($num3||mc_unit,var['Number']-1);
$winner_addr = var[$last_lucky||var['Last draw']];
}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$winner_addr}",
"amount": "{var['Total pot']-$min}"
}
]
}
},
{
"app": "state",
"state": "{
var['Last draw'] = timestamp;
var['Total pot']= 0;
var['Number'] = 0;
$num = var['Number'];
var[$addr||var['Last draw']] = $num;
var[$num||var['Last draw']] = $addr;
var['Number'] += 1;//not allowed ($inp % 10000)
var['Total pot'] += $inp;
response['message'] = 'you bought one participation, your number: '|| $num ;
}"
}
]
},
{
"if": "{
$inp == 10000
}",
"messages": [
{
"app": "state",
"state": "{
if(!var['Number']){
var['Number'] = 0;
var['Last draw'] = timestamp;
}
$num = var['Number'];
var[$addr||var['Last draw']] = $num;
var[$num||var['Last draw']] = $addr;
var['Number'] += 1;//not allowed ($inp % 10000)
var['Total pot'] += $inp;
response['message'] = 'you bought one participation, your number: '|| $num ;
}"
}
]
},
{
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.output[[asset=base]] - 1000}"
}
]
}
}
]
}
]
}
}
]