Unit ID
3s5pysGYi9KPPhTfFavnCMXPwrDg4UAGB1NQ+ecRPTA=
Received
02.06.2021 14:58:51
Confirmation delay (full node)
3 minutes 18 seconds
Confirmation delay (light node)
3 minutes 51 seconds
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "init": "{ if (NOT exists(trigger.data["method"])) bounce("method field is mandatory"); $method = trigger.data["method"]; $spendableFunds = balance["base"] - storage_size; //The max amount the owner can withdraw without bouncing due to not enough funds $owner = var["owner"]; }", "getters": "{ $getCurrency = $ticker=>{ return var["CURRENCY_" || $ticker]; }; $getExchangeRate = $ticker=>{ $currency = $getCurrency($ticker); if (NOT $currency) bounce("That currency was not found"); $multiplier = $currency.feed2 ? 1 / data_feed[[oracles=$currency.oracle2, feed_name=$currency.feed2, ifseveral="last"]] * data_feed[[oracles=$currency.oracle1, feed_name=$currency.feed1, ifseveral="last"]] : data_feed[[oracles=$currency.oracle1, feed_name=$currency.feed1, ifseveral="last"]]; if ($ticker == "USD") return 1/($multiplier / 1000000000); //Inverse return $multiplier / 1000000000; }; $convert = ($amount, $sourceTicker, $destinationTicker)=>{ if ($amount < 0) bounce("You cannot convert a negative amount!"); if ($sourceTicker != "GBYTE") if (NOT var["CURRENCY_" || $sourceTicker]) bounce("Source currency is unsupported"); if ($destinationTicker != "GBYTE") if (NOT var["CURRENCY_" || $destinationTicker]) bounce("Destination currency is unsupported"); if ($sourceTicker == "GBYTE") //Convert from GBYTE return $amount * (1 / $getExchangeRate($destinationTicker)); //Rounding is up to the caller here if ($destinationTicker == "GBYTE") //Convert to GBYTE return round($amount * $getExchangeRate($sourceTicker) * 1000000000, 0); //Automatically rounded else{ $multiplier = $getExchangeRate($sourceTicker) * 1 / $getExchangeRate("USD"); //to USD $usd = $amount * $multiplier; $multiplier2 = 1 / $getExchangeRate($destinationTicker); //to destination currency return $usd * $multiplier2; //Rounding is up to the caller here } }; }", "messages": { "cases": [ { "if": "{ NOT $owner //The owner has not been set }", "messages": [ { "app": "state", "state": "{ var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; var["CURRENCY_USD"] = { oracle1: "F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N", //GBYTE_USD feed1: "GBYTE_USD", oracle2: false, //FIAT_USD feed2: false }; }" } ] }, { "if": "{ trigger.address == $owner AND ($method == "payout" OR $method == "transferOwnership" OR $method == "addCurrency" OR $method == "delCurrency") }", "messages": { "cases": [ { "if": "{ $method == "payout" }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{trigger.address}", "amount": "{$spendableFunds}" } ] } } ] }, { "if": "{ $method == "transferOwnership" }", "init": "{ if (NOT exists(trigger.data["newOwner"])) bounce("newOwner field is mandatory"); if (NOT is_valid_address(trigger.data["newOwner"])) bounce("newOwner field is not a valid address"); }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{trigger.address}", "amount": "{$spendableFunds}" } ] } }, { "app": "state", "state": "{ var["owner"] = trigger.data["newOwner"]; }" } ] }, { "if": "{ $method == "addCurrency" }", "init": "{ if (NOT exists(trigger.data["ticker"])) bounce("ticker field is mandatory"); if (NOT exists(trigger.data["oracle1"])) bounce("oracle1 field is mandatory"); if (NOT is_valid_address(trigger.data["oracle1"])) bounce("oracle1 address is invalid"); if (NOT exists(trigger.data["feed1"])) bounce("feed1 field is mandatory"); if (exists(trigger.data["oracle2"])){ if (NOT is_valid_address(trigger.data["oracle2"])) bounce("oracle2 address is invalid"); if (NOT exists(trigger.data["oracle1"])) bounce("If you provided oracle2 you have to provide oracle1"); if (NOT exists(trigger.data["feed2"])) bounce("If you provided oracle2 you have to provide feed2"); if (NOT data_feed[[oracles=trigger.data["oracle2"], feed_name=trigger.data["feed2"], ifseveral="last", ifnone=false]]) bounce("oracle2 does not post that feed"); } if (NOT data_feed[[oracles=trigger.data["oracle1"], feed_name=trigger.data["feed1"], ifseveral="last", ifnone=false]]) bounce("oracle1 does not post that feed"); }", "messages": [ { "app": "state", "state": "{ var["CURRENCY_" || trigger.data["ticker"]] = { oracle1: trigger.data["oracle1"], feed1: trigger.data["feed1"], oracle2: trigger.data["oracle2"], feed2: trigger.data["feed2"] }; }" } ] }, { "if": "{ $method == "delCurrency" }", "init": "{ if (NOT exists(trigger.data["ticker"])) bounce("ticker field is mandatory"); if (NOT var[trigger.data["ticker"]]) bounce("That currency is unknown for the AA"); }", "messages": [ { "app": "state", "state": "{ var["CURRENCY_" || trigger.data["ticker"]] = false; }" } ] } ] } } ] } } ]
Technical information
Fees:
5,861 bytes
(452 headers, 5409 payload)
Level:2029814
Witnessed level:2029807
Main chain index:2021823
Latest included mc index:2021822
Status:stable/confirmed/final