Definition: [
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"getters": "{
$get_pubkey = () => {
$unit = var['pubkey_unit'];
unit[$unit].messages[[.app='data']][0].payload.pubkey
};
}",
"init": "{
$vrf = 'T4IB4XSUAWFBF5MCQ4V37VQ5AAYUKNGK';
$vrf_registry = '3MWX3HXQHLYRZXRVK5K7JTWAIQS3QX3D';
$adminAddressForClaimFees = 'I7F4DTTH7TWBI24UJIYIH4MECADCFUIA';
$pubkey_unit = var['pubkey_unit'];
$top_result = var['top_result'] OTHERWISE 0;
$top_addresses = var['top_addresses'] OTHERWISE {};
$total_balance = var['total_balance'] OTHERWISE 0;
// $ticketPrice = 100000000; // 0.1 GB
$ticketPrice = 100000; // for test 0.0001
}",
"messages": {
"cases": [
{
"if": "{trigger.data.set_pubkey_unit}",
"messages": [
{
"app": "state",
"state": "{
$pk_unit = var[$vrf_registry]['pk_' || $vrf];
var['pubkey_unit'] = $pk_unit;
response['result'] = 'pubkey unit added';
}"
}
]
},
{
"if": "{trigger.data.jump}",
"init": "{
$minAmount = $ticketPrice + 60000;
if (trigger.output[[asset=base]] < $minAmount) {
bounce('Min amount: ' || $minAmount || ' bytes');
}
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$vrf}",
"amount": "{50000}"
},
{
"address": "{trigger.address}",
"amount": "{trigger.output[[asset=base]] - $minAmount}"
}
]
}
},
{
"app": "state",
"state": "{
var['rid_' || response_unit] = trigger.address;
var['total_balance'] += $ticketPrice;
response['result'] = 'Random requested';
}"
}
]
},
{
"if": "{trigger.data.id AND trigger.data.proof}",
"messages": [
{
"app": "state",
"state": "{
$id = trigger.data.id;
$proof = trigger.data.proof;
$address = var['rid_' || $id];
if (!exists($address)) {
bounce('Random request not found');
}
if (!vrf_verify($id, $proof, $get_pubkey())) {
bounce('Not valid vrf');
}
$height = number_from_seed($proof, 10, 100000);
var['user_' || $address] = $height;
if ($height == $top_result) {
$top_addresses[$address] = 1;
} else if ($height > $top_addresses) {
$top_addresses = {};
$top_addresses[$address] = 1;
var['top_result'] = $height;
} else if($top_addresses[$address]) {
$top_addresses[$address] = false;
}
var['top_addresses'] = $top_addresses;
response['result'] = 'The user' || $address || ' jumped to' || $height;
}"
}
]
},
{
"if": "{trigger.data.claim}",
"init": "{
if (!$top_addresses[trigger.address] AND $adminAddressForClaimFees != trigger.address) {
bounce('not access');
}
if (var['claimed_' || trigger.address]) {
bounce('already claimed');
}
$fees = floor(5 * $total_balance / 100);
$winners = length($top_addresses);
if ($top_addresses[trigger.address]) {
$forClaim = ($total_balance - $fees) / $winners;
} else if ($adminAddressForClaimFees == trigger.address) {
$forClaim = $fees;
}
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$forClaim}"
}
]
}
},
{
"app": "state",
"state": "{
var['claimed_' || trigger.address] = 1;
}"
}
]
}
]
}
}
]