| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://raw.githubusercontent.com/byteball/sports-betting/master/AAs/asset-issuer/{{aa_address}}.json", |
| 5 | "init": "{ |
| 6 | $timeout = 5; |
| 7 | $sl_tokens_registry_address = "XVIFA4GZO7IHAUBFU47GSWMBZYOY56ZD"; |
| 8 | $dec_tokens_registry_address = "O6H6ZIFI57X3PLTYHOCVYPP5A553CYFQ"; |
| 9 | if (typeof(params.championship) != 'string') |
| 10 | bounce("championship parameter must be a string"); |
| 11 | if (typeof(params.home_team) != 'string') |
| 12 | bounce("home_team parameter must be a string"); |
| 13 | if (typeof(params.away_team) != 'string') |
| 14 | bounce("away_team parameter must be a string"); |
| 15 | if (contains(params.championship, '_') OR contains(params.championship, '|')) |
| 16 | bounce("championship parameter cannot contain '|' or '_'"); |
| 17 | if (contains(params.home_team, '_') OR contains(params.home_team, '|')) |
| 18 | bounce("home_team parameter cannot contain '|' or '_'"); |
| 19 | if (contains(params.away_team, '_') OR contains(params.away_team, '|')) |
| 20 | bounce("away_team parameter cannot contain '|' or '_'"); |
| 21 | if (!parse_date(params.fixture_date)) |
| 22 | bounce("fixture_date parameter is not a valid date"); |
| 23 | if (!is_valid_address(params.oracle)) |
| 24 | bounce("oracle parameter is not a valid address"); |
| 25 | if (!asset[params.reserve_asset].exists) |
| 26 | bounce("reserve asset doesn't exist"); |
| 27 | if (array_length(keys(params)) != 6) |
| 28 | bounce("foreign parameter(s) in AA definition"); |
| 29 | $reserve_asset = params.reserve_asset; |
| 30 | if ($reserve_asset == 'base'){ |
| 31 | $reserve_amount_received = trigger.output[[asset=base]] - 10000; |
| 32 | } else { |
| 33 | if (trigger.output[[asset=base]] > 20000) |
| 34 | bounce("base amount exceeds fees"); |
| 35 | $reserve_amount_received = trigger.output[[asset=$reserve_asset]]; |
| 36 | } |
| 37 | }", |
| 38 | "messages": { |
| 39 | "cases": [ |
| 40 | { |
| 41 | "if": "{ |
| 42 | $reserve_amount_received > 0 OR trigger.address == $sl_tokens_registry_address |
| 43 | }", |
| 44 | "init": "{ |
| 45 | if (trigger.data.asset_step AND trigger.address != $sl_tokens_registry_address) |
| 46 | bounce("only registry can increment asset step"); |
| 47 | if (var["canceled"] AND trigger.address != $sl_tokens_registry_address){ |
| 48 | $recipient_address = trigger.address; |
| 49 | $asset_amount = $reserve_amount_received; |
| 50 | } else { |
| 51 | $symbol_left_part = params.championship || '_' || params.home_team || '_' || params.away_team || '_' || params.fixture_date; |
| 52 | if ($reserve_asset == 'base'){ |
| 53 | $currency_symbol = "GBYTE"; |
| 54 | } else { |
| 55 | $currency_symbol = var[$dec_tokens_registry_address]['a2s_' || $reserve_asset]; |
| 56 | if (!$currency_symbol) |
| 57 | bounce("no symbol for reserve asset"); |
| 58 | $description = var[$dec_tokens_registry_address]['current_desc_' || $reserve_asset]; |
| 59 | if (!$description) |
| 60 | $decimals = 0; |
| 61 | else |
| 62 | $decimals = var[$dec_tokens_registry_address]['decimals_' || $reserve_asset]; |
| 63 | } |
| 64 | if (trigger.address != $sl_tokens_registry_address){ |
| 65 | $asset_type = "hometeam"; |
| 66 | $asset_symbol = $symbol_left_part || '-' || params.home_team || '-' || $currency_symbol; |
| 67 | $next_asset_step = 1; |
| 68 | } else if (trigger.data.asset_step == 1){ |
| 69 | $asset_type = "awayteam"; |
| 70 | $asset_symbol = $symbol_left_part || '-' || params.away_team || '-' || $currency_symbol; |
| 71 | } else if (trigger.data.asset_step == 2){ |
| 72 | $asset_type = "draw"; |
| 73 | $asset_symbol = $symbol_left_part || '-DRAW' || '-' || $currency_symbol; |
| 74 | } else if (trigger.data.asset_step == 3){ |
| 75 | $asset_type = "canceled"; |
| 76 | $asset_symbol = $symbol_left_part || '-CANCELED' || '-' || $currency_symbol; |
| 77 | } else if (trigger.data.asset_step == 4){ |
| 78 | $recipient_address = trigger.initial_address; |
| 79 | $asset_amount = var['amount_to_pay']; |
| 80 | } |
| 81 | if (trigger.data.asset_step AND trigger.data.asset_step < 4) |
| 82 | $next_asset_step = trigger.data.asset_step + 1; |
| 83 | |
| 84 | if (length($asset_symbol) > 50) |
| 85 | bounce("resulting symbol length cannot be superior to 50"); |
| 86 | } |
| 87 | }", |
| 88 | "messages": [ |
| 89 | { |
| 90 | "if": "{$recipient_address}", |
| 91 | "app": "payment", |
| 92 | "payload": { |
| 93 | "asset": "{var["hometeam"]}", |
| 94 | "outputs": [ |
| 95 | { |
| 96 | "address": "{$recipient_address}", |
| 97 | "amount": "{$asset_amount}" |
| 98 | } |
| 99 | ] |
| 100 | } |
| 101 | }, |
| 102 | { |
| 103 | "if": "{$recipient_address}", |
| 104 | "app": "payment", |
| 105 | "payload": { |
| 106 | "asset": "{var["awayteam"]}", |
| 107 | "outputs": [ |
| 108 | { |
| 109 | "address": "{$recipient_address}", |
| 110 | "amount": "{$asset_amount}" |
| 111 | } |
| 112 | ] |
| 113 | } |
| 114 | }, |
| 115 | { |
| 116 | "if": "{$recipient_address}", |
| 117 | "app": "payment", |
| 118 | "payload": { |
| 119 | "asset": "{var["draw"]}", |
| 120 | "outputs": [ |
| 121 | { |
| 122 | "address": "{$recipient_address}", |
| 123 | "amount": "{$asset_amount}" |
| 124 | } |
| 125 | ] |
| 126 | } |
| 127 | }, |
| 128 | { |
| 129 | "if": "{$recipient_address}", |
| 130 | "app": "payment", |
| 131 | "payload": { |
| 132 | "asset": "{var["canceled"]}", |
| 133 | "outputs": [ |
| 134 | { |
| 135 | "address": "{$recipient_address}", |
| 136 | "amount": "{$asset_amount}" |
| 137 | } |
| 138 | ] |
| 139 | } |
| 140 | }, |
| 141 | { |
| 142 | "if": "{!$recipient_address}", |
| 143 | "app": "asset", |
| 144 | "payload": { |
| 145 | "is_private": false, |
| 146 | "is_transferrable": true, |
| 147 | "auto_destroy": false, |
| 148 | "fixed_denominations": false, |
| 149 | "issued_by_definer_only": true, |
| 150 | "cosigned_by_definer": false, |
| 151 | "spender_attested": false |
| 152 | } |
| 153 | }, |
| 154 | { |
| 155 | "if": "{!$recipient_address}", |
| 156 | "app": "payment", |
| 157 | "payload": { |
| 158 | "asset": "base", |
| 159 | "outputs": [ |
| 160 | { |
| 161 | "address": "{$sl_tokens_registry_address}", |
| 162 | "amount": 1600 |
| 163 | } |
| 164 | ] |
| 165 | } |
| 166 | }, |
| 167 | { |
| 168 | "if": "{!$recipient_address}", |
| 169 | "app": "data", |
| 170 | "payload": { |
| 171 | "next_asset_step": "{$next_asset_step}", |
| 172 | "asset_symbol": "{$asset_symbol}", |
| 173 | "decimals": "{$decimals}", |
| 174 | "oracle": "{params.oracle}" |
| 175 | } |
| 176 | }, |
| 177 | { |
| 178 | "if": "{!$recipient_address}", |
| 179 | "app": "state", |
| 180 | "state": "{ |
| 181 | var[$asset_type] = response_unit; |
| 182 | if ($next_asset_step == 1){ |
| 183 | var['amount_to_pay'] = $reserve_amount_received; |
| 184 | } |
| 185 | }" |
| 186 | } |
| 187 | ] |
| 188 | }, |
| 189 | { |
| 190 | "if": "{$reserve_amount_received == 0}", |
| 191 | "init": "{ |
| 192 | if (trigger.output[[asset=var['hometeam']]] > 0) |
| 193 | $asset = var['hometeam']; |
| 194 | else if (trigger.output[[asset=var['awayteam']]] > 0) |
| 195 | $asset = var['awayteam']; |
| 196 | else if (trigger.output[[asset=var['draw']]] > 0) |
| 197 | $asset = var['draw']; |
| 198 | else if (trigger.output[[asset=var['canceled']]] > 0) |
| 199 | $asset = var['canceled']; |
| 200 | else |
| 201 | bounce("no betting asset"); |
| 202 | if ($reserve_asset == 'base') |
| 203 | $amount = trigger.output[[asset=$asset]] - 1000; |
| 204 | else |
| 205 | $amount = trigger.output[[asset=$asset]]; |
| 206 | $feedname = params.championship || '_' || params.home_team || '_' || params.away_team || '_' || params.fixture_date; |
| 207 | $datafeed_value = data_feed[[oracles=params.oracle, feed_name=$feedname, ifnone='_none']]; |
| 208 | if ($asset == var['hometeam'] AND $datafeed_value != params.home_team) |
| 209 | bounce("home team didn't win"); |
| 210 | if ($asset == var['awayteam'] AND $datafeed_value != params.away_team) |
| 211 | bounce("away team didn't win"); |
| 212 | if ($asset == var['draw'] AND $datafeed_value != 'draw') |
| 213 | bounce("there wasn't a draw"); |
| 214 | if ($asset == var['canceled'] AND $datafeed_value != 'canceled'){ |
| 215 | $expired = timestamp > parse_date(params.fixture_date) + $timeout * 24 * 3600; |
| 216 | if ($datafeed_value != '_none') |
| 217 | bounce("there wasn't a cancelation or postponement"); |
| 218 | if (!$expired) |
| 219 | bounce("timeout not reached yet"); |
| 220 | } |
| 221 | }", |
| 222 | "messages": [ |
| 223 | { |
| 224 | "app": "payment", |
| 225 | "payload": { |
| 226 | "asset": "{$reserve_asset}", |
| 227 | "outputs": [ |
| 228 | { |
| 229 | "address": "{trigger.address}", |
| 230 | "amount": "{$amount}" |
| 231 | } |
| 232 | ] |
| 233 | } |
| 234 | } |
| 235 | ] |
| 236 | } |
| 237 | ] |
| 238 | } |
| 239 | } |
| 240 | ] |