YVHAIFMATQKCRDYUIQKGCMR4OZ6IKIUD
[
"autonomous agent",
{
"doc_url": "https://raw.githubusercontent.com/jldevelops/aa-lottery-oracle/master/description.json",
"getters": "{
$ENTRY = => params.entry > 10000 ? params.entry : 10000;
$TRIGGER_FEE = => params.trigger_fee;
$ORACLE = => params.oracle;
$FEED_NAME = => params.feed_name;
$triggerPot = => var['tickets_sold'] * $TRIGGER_FEE();
$winnerPot = => var['tickets_sold'] * $ENTRY() - $triggerPot();
$actualWinner = => var['tickets_sold'] > 1 ? number_from_seed(data_feed[[oracles=$ORACLE(), feed_name=$FEED_NAME()]],var['tickets_sold']-1) : 0;
$isWinnerTicket = $ti => var['amount_'||$ti[0]] ? (($ti[1]+0) <= var['winner_'||$ti[0]] AND ($ti[2]+0) > var['winner_'||$ti[0]]) : false;
$now = => timestamp_to_string(timestamp, 'date');
$day = => var['today'] ? var['today'] : $now();
$isTriggerAvailable = => $now() != $day() AND var['tickets_sold'] > 0;
}",
"init": "{
$opFee = => (balance[base] - storage_size - var['user_bytes'] - trigger.output[[asset=base]]) > 20000 ? 0 : 5000;
if(trigger.output[[asset!=base]].asset != 'none')
bounce('no asset');
}",
"messages": {
"cases": [
{
"if": "{trigger.data.trigger AND $isTriggerAvailable() AND trigger.output[[asset=base]] >= 10000}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$triggerPot() + trigger.output[[asset=base]] - $opFee()}"
}
]
}
},
{
"app": "state",
"state": "{
$d = $day();
var['winner_'||$d] = $actualWinner();
var['amount_'||$d] = $winnerPot();
var['user_bytes'] -= $triggerPot();
var['today'] = $now();
var['tickets_sold'] = 0;
response['message'] = 'Winner ticket '||$d||': '||var['winner_'||$d];
}"
}
]
},
{
"init": "{
if($isTriggerAvailable())
bounce('Trigger reward available, send trigger = 1 to win '||$triggerPot()||' bytes');
if(trigger.data.trigger)
bounce('Trigger reward not available');
$ticket = var[trigger.address];
if($ticket AND $ticket[0] == $day())
bounce('Address already registered');
}",
"messages": [
{
"if": "{$ticket AND $isWinnerTicket($ticket)}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{var['amount_'||$ticket[0]] + trigger.output[[asset=base]] - $opFee()}"
}
]
}
},
{
"app": "state",
"state": "{
if($ticket AND $isWinnerTicket($ticket)){
var['user_bytes'] -= var['amount_'||$ticket[0]];
var['amount_'||$ticket[0]] = false;
var['winner_'||$ticket[0]] = false;
response['message'] = 'You won '||$ticket[0]||' draw. Congratulations!';
}
else{
if((trigger.output[[asset=base]] % $ENTRY()) != 0)
bounce('Amount has to be multiple of '||$ENTRY()||' bytes. An address can buy tickets once a day.');
if(!var['today'] OR (var['tickets_sold'] == 0 AND $now() != $day()))
var['today'] = $now();
$tickets = trigger.output[[asset=base]] / $ENTRY();
var[trigger.address] = [$day(), var['tickets_sold']+0, ($tickets + var['tickets_sold'])];
var['user_bytes'] += trigger.output[[asset=base]];
var['tickets_sold'] += $tickets;
response['message'] = 'You bought '||$tickets||' tickets. Actual winner pot: '||$winnerPot()||' bytes. Actual trigger pot: '||$triggerPot()||' bytes';
}
}"
}
]
}
]
}
}
]
AAs based on this template Show transactions in assets:
No transactions found, it may be worth changing the filter
Unit ID
Date
From
Direction
To
Amount