[
"autonomous agent",
{
"doc_url": "https://raw.githubusercontent.com/byteball/sports-betting/master/AAs/asset-issuer/{{aa_address}}.json",
"init": "{
$timeout = 5;
$sl_tokens_registry_address = "
XVIFA4GZO7IHAUBFU47GSWMBZYOY56ZD";
$dec_tokens_registry_address = "
O6H6ZIFI57X3PLTYHOCVYPP5A553CYFQ";
if (typeof(params.championship) != 'string')
bounce("championship parameter must be a string");
if (typeof(params.home_team) != 'string')
bounce("home_team parameter must be a string");
if (typeof(params.away_team) != 'string')
bounce("away_team parameter must be a string");
if (contains(params.championship, '_') OR contains(params.championship, '|'))
bounce("championship parameter cannot contain '|' or '_'");
if (contains(params.home_team, '_') OR contains(params.home_team, '|'))
bounce("home_team parameter cannot contain '|' or '_'");
if (contains(params.away_team, '_') OR contains(params.away_team, '|'))
bounce("away_team parameter cannot contain '|' or '_'");
if (!parse_date(params.fixture_date))
bounce("fixture_date parameter is not a valid date");
if (!is_valid_address(params.oracle))
bounce("oracle parameter is not a valid address");
if (!asset[params.reserve_asset].exists)
bounce("reserve asset doesn't exist");
if (array_length(keys(params)) != 6)
bounce("foreign parameter(s) in AA definition"); // ensure there can be only one address for this set of parameters
$reserve_asset = params.reserve_asset;
if ($reserve_asset == 'base'){
$reserve_amount_received = trigger.output[[asset=base]] - 10000;
} else {
if (trigger.output[[asset=base]] > 20000)
bounce("base amount exceeds fees");
$reserve_amount_received = trigger.output[[asset=$reserve_asset]];
}
}",
"messages": {
"cases": [
{
"if": "{
$reserve_amount_received > 0 OR trigger.address == $sl_tokens_registry_address
}",
"init": "{
if (trigger.data.asset_step AND trigger.address != $sl_tokens_registry_address)
bounce("only registry can increment asset step");
if (var["canceled"] AND trigger.address != $sl_tokens_registry_address){ // the assets are already defined, we just have to issue them
$recipient_address = trigger.address;
$asset_amount = $reserve_amount_received;
} else {
$symbol_left_part = params.championship || '_' || params.home_team || '_' || params.away_team || '_' || params.fixture_date;
if ($reserve_asset == 'base'){
$currency_symbol = "GBYTE";
} else {
$currency_symbol = var[$dec_tokens_registry_address]['a2s_' || $reserve_asset];
if (!$currency_symbol)
bounce("no symbol for reserve asset");
$description = var[$dec_tokens_registry_address]['current_desc_' || $reserve_asset];
if (!$description)
$decimals = 0;
else
$decimals = var[$dec_tokens_registry_address]['decimals_' || $description];
}
if (trigger.address != $sl_tokens_registry_address){ // if triggered by user we are at first step of asset definition
$asset_type = "hometeam";
$asset_symbol = $symbol_left_part || '-' || params.home_team || '-' || $currency_symbol;
$next_asset_step = 1;
} else if (trigger.data.asset_step == 1){
$asset_type = "awayteam";
$asset_symbol = $symbol_left_part || '-' || params.away_team || '-' || $currency_symbol;
} else if (trigger.data.asset_step == 2){
$asset_type = "draw";
$asset_symbol = $symbol_left_part || '-DRAW' || '-' || $currency_symbol;
} else if (trigger.data.asset_step == 3){
$asset_type = "canceled";
$asset_symbol = $symbol_left_part || '-CANCELED' || '-' || $currency_symbol;
} else if (trigger.data.asset_step == 4){
$recipient_address = trigger.initial_address;
$asset_amount = var['amount_to_pay'];
}
if (trigger.data.asset_step AND trigger.data.asset_step < 4)
$next_asset_step = trigger.data.asset_step + 1; // asset_step is incremented at every ping-pong with registery until all assets are defined
if (length($asset_symbol) > 50)
bounce("resulting symbol length cannot be superior to 50");
}
}",
"messages": [
{
"if": "{$recipient_address}",
"app": "payment",
"payload": {
"asset": "{var["hometeam"]}",
"outputs": [
{
"address": "{$recipient_address}",
"amount": "{$asset_amount}"
}
]
}
},
{
"if": "{$recipient_address}",
"app": "payment",
"payload": {
"asset": "{var["awayteam"]}",
"outputs": [
{
"address": "{$recipient_address}",
"amount": "{$asset_amount}"
}
]
}
},
{
"if": "{$recipient_address}",
"app": "payment",
"payload": {
"asset": "{var["draw"]}",
"outputs": [
{
"address": "{$recipient_address}",
"amount": "{$asset_amount}"
}
]
}
},
{
"if": "{$recipient_address}",
"app": "payment",
"payload": {
"asset": "{var["canceled"]}",
"outputs": [
{
"address": "{$recipient_address}",
"amount": "{$asset_amount}"
}
]
}
},
{
"if": "{!$recipient_address}",
"app": "asset",
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"if": "{!$recipient_address}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$sl_tokens_registry_address}",
"amount": 1600
}
]
}
},
{
"if": "{!$recipient_address}",
"app": "data",
"payload": {
"next_asset_step": "{$next_asset_step}",
"asset_symbol": "{$asset_symbol}",
"decimals": "{$decimals}",
"oracle": "{params.oracle}"
}
},
{
"if": "{!$recipient_address}",
"app": "state",
"state": "{
var[$asset_type] = response_unit;
if ($next_asset_step == 1){
var['amount_to_pay'] = $reserve_amount_received;
}
}"
}
]
},
{
"if": "{$reserve_amount_received == 0}",
"init": "{
if (trigger.output[[asset=var['hometeam']]] > 0)
$asset = var['hometeam'];
else if (trigger.output[[asset=var['awayteam']]] > 0)
$asset = var['awayteam'];
else if (trigger.output[[asset=var['draw']]] > 0)
$asset = var['draw'];
else if (trigger.output[[asset=var['canceled']]] > 0)
$asset = var['canceled'];
else
bounce("no betting asset");
if ($reserve_asset == 'base')
$amount = trigger.output[[asset=$asset]] - 1000;
else
$amount = trigger.output[[asset=$asset]];
$feedname = params.championship || '_' || params.home_team || '_' || params.away_team || '_' || params.fixture_date;
$datafeed_value = data_feed[[oracles=params.oracle, feed_name=$feedname, ifnone='_none']];
if ($asset == var['hometeam'] AND $datafeed_value != params.home_team)
bounce("home team didn't win");
if ($asset == var['awayteam'] AND $datafeed_value != params.away_team)
bounce("away team didn't win");
if ($asset == var['draw'] AND $datafeed_value != 'draw')
bounce("there wasn't a draw");
if ($asset == var['canceled'] AND $datafeed_value != 'canceled'){
$expired = timestamp > parse_date(params.fixture_date) + $timeout * 24 * 3600;
if ($datafeed_value != '_none')
bounce("there wasn't a cancelation or postponement");
if (!$expired)
bounce("timeout not reached yet");
}
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$reserve_asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$amount}"
}
]
}
}
]
}
]
}
}
]