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