| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | if (NOT exists(trigger.data["method"])) |
| 9 | bounce("method field is mandatory"); |
| 10 | |
| 11 | $method = trigger.data["method"]; |
| 12 | |
| 13 | $spendableFunds = balance["base"] - storage_size; |
| 14 | $owner = var["owner"]; |
| 15 | }", |
| 16 | "getters": "{ |
| 17 | $getCurrency = $ticker=>{ |
| 18 | return var["CURRENCY_" || $ticker]; |
| 19 | }; |
| 20 | $getExchangeRate = $ticker=>{ |
| 21 | $currency = $getCurrency($ticker); |
| 22 | if (NOT $currency) |
| 23 | bounce("That currency was not found"); |
| 24 | $multiplier = $currency.feed2 |
| 25 | ? 1 / data_feed[[oracles=$currency.oracle2, feed_name=$currency.feed2, ifseveral="last"]] * data_feed[[oracles=$currency.oracle1, feed_name=$currency.feed1, ifseveral="last"]] |
| 26 | : data_feed[[oracles=$currency.oracle1, feed_name=$currency.feed1, ifseveral="last"]]; |
| 27 | return $multiplier / 1000000000; |
| 28 | }; |
| 29 | }", |
| 30 | "messages": { |
| 31 | "cases": [ |
| 32 | { |
| 33 | "if": "{ |
| 34 | NOT $owner |
| 35 | }", |
| 36 | "messages": [ |
| 37 | { |
| 38 | "app": "state", |
| 39 | "state": "{ |
| 40 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 41 | var["CURRENCY_USD"] = { |
| 42 | oracle1: "F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N", |
| 43 | feed1: "GBYTE_USD", |
| 44 | oracle2: false, |
| 45 | feed2: false |
| 46 | }; |
| 47 | }" |
| 48 | } |
| 49 | ] |
| 50 | }, |
| 51 | { |
| 52 | "if": "{ |
| 53 | trigger.address == $owner |
| 54 | AND ($method == "payout" |
| 55 | OR $method == "transferOwnership" |
| 56 | OR $method == "addCurrency" |
| 57 | OR $method == "delCurrency") |
| 58 | }", |
| 59 | "messages": { |
| 60 | "cases": [ |
| 61 | { |
| 62 | "if": "{ |
| 63 | $method == "payout" |
| 64 | }", |
| 65 | "messages": [ |
| 66 | { |
| 67 | "app": "payment", |
| 68 | "payload": { |
| 69 | "asset": "base", |
| 70 | "outputs": [ |
| 71 | { |
| 72 | "address": "{trigger.address}", |
| 73 | "amount": "{$spendableFunds}" |
| 74 | } |
| 75 | ] |
| 76 | } |
| 77 | } |
| 78 | ] |
| 79 | }, |
| 80 | { |
| 81 | "if": "{ |
| 82 | $method == "transferOwnership" |
| 83 | }", |
| 84 | "init": "{ |
| 85 | if (NOT exists(trigger.data["newOwner"])) |
| 86 | bounce("newOwner field is mandatory"); |
| 87 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 88 | bounce("newOwner field is not a valid address"); |
| 89 | }", |
| 90 | "messages": [ |
| 91 | { |
| 92 | "app": "payment", |
| 93 | "payload": { |
| 94 | "asset": "base", |
| 95 | "outputs": [ |
| 96 | { |
| 97 | "address": "{trigger.address}", |
| 98 | "amount": "{$spendableFunds}" |
| 99 | } |
| 100 | ] |
| 101 | } |
| 102 | }, |
| 103 | { |
| 104 | "app": "state", |
| 105 | "state": "{ |
| 106 | var["owner"] = trigger.data["newOwner"]; |
| 107 | }" |
| 108 | } |
| 109 | ] |
| 110 | }, |
| 111 | { |
| 112 | "if": "{ |
| 113 | $method == "addCurrency" |
| 114 | }", |
| 115 | "init": "{ |
| 116 | if (NOT exists(trigger.data["ticker"])) |
| 117 | bounce("ticker field is mandatory"); |
| 118 | if (NOT exists(trigger.data["oracle1"])) |
| 119 | bounce("oracle1 field is mandatory"); |
| 120 | if (NOT is_valid_address(trigger.data["oracle1"])) |
| 121 | bounce("oracle1 address is invalid"); |
| 122 | if (NOT exists(trigger.data["feed1"])) |
| 123 | bounce("feed1 field is mandatory"); |
| 124 | if (exists(trigger.data["oracle2"])){ |
| 125 | if (NOT is_valid_address(trigger.data["oracle2"])) |
| 126 | bounce("oracle2 address is invalid"); |
| 127 | if (NOT exists(trigger.data["oracle1"])) |
| 128 | bounce("If you provided oracle2 you have to provide oracle1"); |
| 129 | if (NOT exists(trigger.data["feed2"])) |
| 130 | bounce("If you provided oracle2 you have to provide feed2"); |
| 131 | if (NOT data_feed[[oracles=trigger.data["oracle2"], feed_name=trigger.data["feed2"], ifseveral="last", ifnone=false]]) |
| 132 | bounce("oracle2 does not post that feed"); |
| 133 | } |
| 134 | if (NOT data_feed[[oracles=trigger.data["oracle1"], feed_name=trigger.data["feed1"], ifseveral="last", ifnone=false]]) |
| 135 | bounce("oracle1 does not post that feed"); |
| 136 | }", |
| 137 | "messages": [ |
| 138 | { |
| 139 | "app": "state", |
| 140 | "state": "{ |
| 141 | var["CURRENCY_" || trigger.data["ticker"]] = { |
| 142 | oracle1: trigger.data["oracle1"], |
| 143 | feed1: trigger.data["feed1"], |
| 144 | oracle2: trigger.data["oracle2"], |
| 145 | feed2: trigger.data["feed2"] |
| 146 | }; |
| 147 | }" |
| 148 | } |
| 149 | ] |
| 150 | }, |
| 151 | { |
| 152 | "if": "{ |
| 153 | $method == "delCurrency" |
| 154 | }", |
| 155 | "init": "{ |
| 156 | if (NOT exists(trigger.data["ticker"])) |
| 157 | bounce("ticker field is mandatory"); |
| 158 | if (NOT var[trigger.data["ticker"]]) |
| 159 | bounce("That currency is unknown for the AA"); |
| 160 | }", |
| 161 | "messages": [ |
| 162 | { |
| 163 | "app": "state", |
| 164 | "state": "{ |
| 165 | var["CURRENCY_" || trigger.data["ticker"]] = false; |
| 166 | }" |
| 167 | } |
| 168 | ] |
| 169 | } |
| 170 | ] |
| 171 | } |
| 172 | } |
| 173 | ] |
| 174 | } |
| 175 | } |
| 176 | ] |