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