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