H5JFEWKJHGW6HZQN3CKTCTZYJD26VQHV
[
"autonomous agent",
{
"doc_url": "https://raw.githubusercontent.com/jldevelops/aa-lotto-oracle/master/description.json",
"getters": "{
$ENTRY = => params.entry > 10000 ? params.entry : 10000;
$TRIGGER_FEE = => params.trigger_fee > 0 ? params.trigger_fee : 1;
$ORACLE = => params.oracle;
$FEED_NAME = => params.feed_name;
$ticketsSold = => var['trigger_pot'] / $TRIGGER_FEE();
$actualWinner = => number_from_seed(data_feed[[oracles=$ORACLE(), feed_name=$FEED_NAME()]],$ticketsSold()-1);
$aaBalance = => balance[base] - storage_size - var['user_bytes'];
$opFee = => var['low_fee_mode'] ? 500 : 5000;
$ticket = $addr => var[$addr];
$ticketDate = $addr => {
if($ticket($addr)){
$arr = split($ticket(), '_');
$date = $arr[0];
}
$date
};
$amountToClaim = $addr => {
if($ticket($addr)){
$arr = split($ticket($addr), '_');
$date = $arr[0];
if(var['amount_'||$date]){
$number = var['winner_'||$date];
$fr = $arr[1]+0;
$to = $arr[2]+0;
if($fr <= $number AND $to > $number){
$to_claim = var['amount_'||$date];
}
}
}
$to_claim
};
}",
"init": "{
$now = timestamp_to_string(timestamp, 'date');
$day = var['today']?var['today']:$now;
if(trigger.output[[asset!=base]].asset != 'none')
bounce('no asset');
}",
"messages": {
"cases": [
{
"if": "{$now != $day AND trigger.output[[asset=base]] >= 10000}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{var['trigger_pot'] + trigger.output[[asset=base]] - $opFee()}"
}
]
}
},
{
"app": "state",
"state": "{
var['winner_'||$day] = $actualWinner();
var['amount_'||$day] = var['winner_pot'];
var['user_bytes'] -= var['trigger_pot'];
var['today'] = $now;
var['winner_pot'] = 0;
var['trigger_pot'] = 0;
if(var['low_fee_mode'] AND ($aaBalance() - trigger.output[[asset=base]]) < 50000)
var['low_fee_mode'] = false;
else{
if(!var['low_fee_mode'] AND ($aaBalance() - trigger.output[[asset=base]]) > 1000000)
var['low_fee_mode'] = true;
}
response['message'] = 'Winner ticket saved: '||var['winner_'||$day];
}"
}
]
},
{
"init": "{
$date = $ticketDate(trigger.address);
if($date){
if($date == $day)
bounce('Address already registered');
$pay = $amountToClaim(trigger.address);
}
if(!$pay AND ((trigger.output[[asset=base]] % $ENTRY()) != 0))
bounce('Amount has to be multiple of '||$ENTRY()||' bytes. An address can buy tickets once a day.');
}",
"messages": [
{
"if": "{$pay}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$pay + trigger.output[[asset=base]] - $opFee()}"
}
]
}
},
{
"app": "state",
"state": "{
if($pay){
var['user_bytes'] -= var['amount_'||$date];
var['amount_'||$date] = false;
var['winner_'||$date] = false;
response['message'] = 'You won '||$date||' draw. Congratulations!';
}
else{
var['user_bytes'] += trigger.output[[asset=base]];
$tickets = trigger.output[[asset=base]] / $ENTRY();
var[trigger.address] = $day||'_'||$ticketsSold()||'_'||($tickets + $ticketsSold());
$total_fee = $tickets * $TRIGGER_FEE();
var['winner_pot'] += trigger.output[[asset=base]] - $total_fee;
var['trigger_pot'] += $total_fee;
if(!var['today']) var['today'] = $now;
response['message'] = 'You bought '||$tickets||'. If you trigger lottery calculation tomorrow you will win '||(($TRIGGER_FEE()/$ENTRY())*100)||'% of total pot';
response['winner pot'] = var['winner_pot'];
response['trigger pot'] = var['trigger_pot'];
}
}"
}
]
}
]
}
}
]
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