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