| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "messages": [ |
| 8 | { |
| 9 | "app": "definition", |
| 10 | "payload": { |
| 11 | "definition": [ |
| 12 | "autonomous agent", |
| 13 | { |
| 14 | "bounce_fees": { |
| 15 | "base": 11000 |
| 16 | }, |
| 17 | "init": "{ |
| 18 | $user = trigger.address; |
| 19 | $is_aa = $user == this_address; |
| 20 | $received_asset = trigger.output[[asset!=base]].asset; |
| 21 | $received_amount = trigger.output[[asset!=base]].amount; |
| 22 | }", |
| 23 | "messages": { |
| 24 | "cases": [ |
| 25 | { |
| 26 | "if": "{!var["indice_hash"] AND !!trigger.data.define}", |
| 27 | "init": "{ |
| 28 | |
| 29 | |
| 30 | if (!!var["temp_creator"]) |
| 31 | { |
| 32 | if (var["temp_creator"] != $user) |
| 33 | bounce("Only the creator of the indice is allowed to define it!"); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | if (!!var["internal_link_1"]) |
| 38 | { |
| 39 | $first_chain_link = var["internal_link_1"]; |
| 40 | if (!var["internal_link_"||$first_chain_link]) |
| 41 | bounce("the indice requires at least 2 underlying assets, please send the second underlying asset in the desired amount!"); |
| 42 | } |
| 43 | else |
| 44 | bounce("To create a new indice, start sending the wanted amount of the first underlying asset!"); |
| 45 | |
| 46 | $asset_name = trigger.data.define; |
| 47 | }", |
| 48 | "messages": [ |
| 49 | { |
| 50 | "app": "asset", |
| 51 | "payload": { |
| 52 | "is_private": false, |
| 53 | "is_transferrable": true, |
| 54 | "auto_destroy": true, |
| 55 | "fixed_denominations": false, |
| 56 | "issued_by_definer_only": true, |
| 57 | "cosigned_by_definer": false, |
| 58 | "spender_attested": false |
| 59 | } |
| 60 | }, |
| 61 | { |
| 62 | "app": "state", |
| 63 | "state": "{ '{ response["defined"] = $asset_name ||" is defined as "||response_unit; var["indice_hash"] = response_unit; var["indice_name"] = $asset_name; var["temp_previous_underlying_asset"] = false; }' |
| 64 | }" |
| 65 | } |
| 66 | ] |
| 67 | }, |
| 68 | { |
| 69 | "if": "{!var["indice_hash"] }", |
| 70 | "init": "{ |
| 71 | |
| 72 | |
| 73 | if (!!var["temp_creator"]) |
| 74 | if (var["temp_creator"] != $user) |
| 75 | bounce("The indice is being created, and you are not the creator, try again later!"); |
| 76 | |
| 77 | $previous_underlying_asset_hash = var["temp_previous_underlying_asset"] otherwise "1"; |
| 78 | $received_underlying_asset_hash = $received_asset ; |
| 79 | $received_underlying_asset_amount = $received_amount; |
| 80 | }", |
| 81 | "messages": [ |
| 82 | { |
| 83 | "app": "state", |
| 84 | "state": "{ '{ var["temp_creator"] = $user; // store in the definition, the quantity of asset; var["amount_of_"||$received_underlying_asset_hash] = $received_underlying_asset_amount; // create the next chain link; var["internal_link_"||$previous_underlying_asset_hash] = $received_underlying_asset_hash; var["temp_previous_underlying_asset"] = $received_underlying_asset_hash; response["defined"] = "underlying asset received, waiting for next one or data.define=<indice name> to finish the definition by giving a name"; }' |
| 85 | }" |
| 86 | } |
| 87 | ] |
| 88 | }, |
| 89 | { |
| 90 | "if": "{!!var["temp_creator"] and var["temp_creator"] == $user}", |
| 91 | "messages": [ |
| 92 | { |
| 93 | "app": "payment", |
| 94 | "payload": { |
| 95 | "asset": "{var["indice_hash"]}", |
| 96 | "outputs": [ |
| 97 | { |
| 98 | "address": "{var["temp_creator"] }", |
| 99 | "amount": "{ 1 }" |
| 100 | } |
| 101 | ] |
| 102 | } |
| 103 | }, |
| 104 | { |
| 105 | "app": "state", |
| 106 | "state": "{ '{ response["defined"] = "Creator got the first token and do not have any role to play"; var["temp_creator"] = false; }' |
| 107 | }" |
| 108 | } |
| 109 | ] |
| 110 | }, |
| 111 | { |
| 112 | "if": "{($received_asset == var["indice_hash"]) or $is_aa}", |
| 113 | "init": "{ |
| 114 | if (!$is_aa) |
| 115 | { |
| 116 | $requester = $user; |
| 117 | $underlying_asset_hash = var["internal_link_1"]; |
| 118 | $amount = $received_amount; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | $requester = trigger.data.aa_reserved_requester; |
| 123 | $underlying_asset_hash = trigger.data.aa_reserved_underlying_asset_hash; |
| 124 | $amount = json_parse(trigger.data.aa_reserved_asset_amount); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | $next_underlying_asset_hash = var["internal_link_"||$underlying_asset_hash]; |
| 129 | }", |
| 130 | "messages": [ |
| 131 | { |
| 132 | "app": "payment", |
| 133 | "payload": { |
| 134 | "asset": "{$underlying_asset_hash }", |
| 135 | "outputs": [ |
| 136 | { |
| 137 | "address": "{$requester}", |
| 138 | "amount": "{$amount * json_parse(var["amount_of_"||$underlying_asset_hash])}" |
| 139 | } |
| 140 | ] |
| 141 | } |
| 142 | }, |
| 143 | { |
| 144 | "if": "{!!$next_underlying_asset_hash}", |
| 145 | "app": "data", |
| 146 | "payload": { |
| 147 | "aa_reserved_requester": "{$requester}", |
| 148 | "aa_reserved_underlying_asset_hash": "{$next_underlying_asset_hash}", |
| 149 | "aa_reserved_asset_amount": "{$amount}" |
| 150 | } |
| 151 | }, |
| 152 | { |
| 153 | "if": "{!!$next_underlying_asset_hash}", |
| 154 | "app": "payment", |
| 155 | "payload": { |
| 156 | "asset": "base", |
| 157 | "outputs": [ |
| 158 | { |
| 159 | "address": "{this_address}", |
| 160 | "amount": "{ 1 }" |
| 161 | } |
| 162 | ] |
| 163 | } |
| 164 | }, |
| 165 | { |
| 166 | "app": "state", |
| 167 | "state": "{ '{response["redemption"] = "Indice token has been exchanged for the underlying assets.";}' |
| 168 | }" |
| 169 | } |
| 170 | ] |
| 171 | }, |
| 172 | { |
| 173 | "if": "{ |
| 174 | (!!var["temp_"||$user||"_underlying_asset"] and ($received_asset == var["temp_"||$user||"_underlying_asset"])) OR |
| 175 | ( !var["temp_"||$user||"_underlying_asset"] and ($received_asset == var["internal_link_1"])) |
| 176 | }", |
| 177 | "init": "{ |
| 178 | if (!!var["temp_"||$user||"_underlying_asset"]) |
| 179 | { |
| 180 | $underlying_asset_hash = var["temp_"||$user||"_underlying_asset"]; |
| 181 | $etf_amount = var["temp_"||$user||"_etf_amount"]; |
| 182 | $needed_mount = $etf_amount * var["amount_of_"||$underlying_asset_hash]; |
| 183 | |
| 184 | if ($received_amount != $needed_mount) |
| 185 | bounce ("you should send "||$needed_mount|| " of "||$underlying_asset_hash); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | $underlying_asset_hash = var["internal_link_1"]; |
| 190 | $needed_mount = var["amount_of_"||$underlying_asset_hash]; |
| 191 | |
| 192 | |
| 193 | if (($received_amount % $needed_mount) != 0) |
| 194 | bounce ("you should send a multiple of "||$needed_mount|| " of "||$underlying_asset_hash); |
| 195 | else |
| 196 | $etf_amount = $received_amount / $needed_mount; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | |
| 201 | $next_underlying_asset_hash = var["internal_link_"||$underlying_asset_hash]; |
| 202 | $all_underlying_asset_received = !$next_underlying_asset_hash; |
| 203 | }", |
| 204 | "messages": [ |
| 205 | { |
| 206 | "if": "{$all_underlying_asset_received}", |
| 207 | "app": "payment", |
| 208 | "payload": { |
| 209 | "asset": "{var["indice_hash"] }", |
| 210 | "outputs": [ |
| 211 | { |
| 212 | "address": "{$user}", |
| 213 | "amount": "{$etf_amount}" |
| 214 | } |
| 215 | ] |
| 216 | } |
| 217 | }, |
| 218 | { |
| 219 | "app": "state", |
| 220 | "state": "{ '{ if ($all_underlying_asset_received) { var["temp_"||$user||"_etf_amount"] = false; var["temp_"||$user||"_underlying_asset"] = false; response["processed"] = var["indice_name"]||" sent"; } else { var["temp_"||$user||"_etf_amount"] = $etf_amount; var["temp_"||$user||"_underlying_asset"] = $next_underlying_asset_hash; response["in progress"] = $underlying_asset_hash ||" received and waiting for "||$next_underlying_asset_hash; } }' |
| 221 | }" |
| 222 | } |
| 223 | ] |
| 224 | }, |
| 225 | { |
| 226 | "messages": [ |
| 227 | { |
| 228 | "app": "state", |
| 229 | "state": "{ '{ if (!!var["temp_"||$user||"_underlying_asset"]) { $underlying_asset_hash = var["temp_"||$user||"_underlying_asset"]; $etf_amount = var["temp_"||$user||"_etf_amount"]; $needed_mount = $etf_amount * var["amount_of_"||$underlying_asset_hash]; bounce ("you should send "||$needed_mount|| " of "||$underlying_asset_hash); } else { $underlying_asset_hash = var["internal_link_1"]; $needed_mount = var["amount_of_"||$underlying_asset_hash]; bounce ("you should send a multiple of "||$needed_mount|| " of "||$underlying_asset_hash); } }' |
| 230 | }" |
| 231 | } |
| 232 | ] |
| 233 | } |
| 234 | ] |
| 235 | } |
| 236 | } |
| 237 | ] |
| 238 | } |
| 239 | } |
| 240 | ] |
| 241 | } |
| 242 | ] |