| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $POOL_BASE_AA = "5DNICJLNOBPANH536Y7YVBN5ZDBLQ4LE"; |
| 9 | $asset = trigger.output[[asset!="base"]].asset == "none" ? "base" : trigger.output[[asset!="base"]].asset; |
| 10 | |
| 11 | |
| 12 | if (NOT trigger.data["_fwto"]) |
| 13 | bounce("_fwto field is mandatory"); |
| 14 | if (NOT is_valid_address(trigger.data["_fwto"])) |
| 15 | bounce("_fwto field is not a valid address"); |
| 16 | if (trigger.output[[asset!="base"]].asset == "ambiguous") |
| 17 | bounce("AAs cannot handle payments with multiple assets"); |
| 18 | if (NOT trigger.data["_opr"]) |
| 19 | bounce("_opr field is mandatory"); |
| 20 | if (NOT is_valid_amount(trigger.data["_opr"])) |
| 21 | bounce("_opr must be a positive amount"); |
| 22 | if (NOT trigger.data["_pl"]) |
| 23 | bounce("_pl field is mandatory"); |
| 24 | if (NOT is_aa(trigger.data["_pl"])) |
| 25 | bounce("_pl is not a valid oswap pool"); |
| 26 | |
| 27 | |
| 28 | $definition = definition[trigger.data["_pl"]][1]; |
| 29 | if ($definition["base_aa"] != $POOL_BASE_AA) |
| 30 | bounce("That pool version is unsupported"); |
| 31 | |
| 32 | $getAmount = ($outputAmount, $outputReserve, $inputReserve, $fee)=>{ |
| 33 | $swapNoFee = 1e11 - $fee; |
| 34 | $numerator = $outputAmount * $inputReserve * 1e11; |
| 35 | $denominator = ($outputReserve - $outputAmount) * $swapNoFee; |
| 36 | return ceil($numerator / $denominator, 0); |
| 37 | }; |
| 38 | $calculateNeededAmount = ()=>{ |
| 39 | $asset0 = $definition["params"]["asset0"]; |
| 40 | $asset1 = $definition["params"]["asset1"]; |
| 41 | $fee = $definition["params"]["swap_fee"]; |
| 42 | $reserve0 = balance[trigger.data["_pl"]][$asset0]; |
| 43 | $reserve1 = balance[trigger.data["_pl"]][$asset1]; |
| 44 | if ($asset == $asset0) |
| 45 | return $getAmount(trigger.data["_opr"], $reserve1, $reserve0, $fee); |
| 46 | return $getAmount(trigger.data["_opr"], $reserve0, $reserve1, $fee); |
| 47 | }; |
| 48 | $price = $calculateNeededAmount(); |
| 49 | if ($price > trigger.output[[asset=$asset]].amount - 5000) |
| 50 | bounce("Not enough amount"); |
| 51 | $remaining = $asset=="base" ? trigger.output[[asset="base"]].amount - $price - 5000 : trigger.output[[asset=$asset]].amount - $price; |
| 52 | }", |
| 53 | "messages": [ |
| 54 | { |
| 55 | "app": "payment", |
| 56 | "payload": { |
| 57 | "asset": "{$asset}", |
| 58 | "outputs": [ |
| 59 | { |
| 60 | "address": "{trigger.initial_address}", |
| 61 | "amount": "{$remaining}" |
| 62 | }, |
| 63 | { |
| 64 | "address": "{trigger.data["_pl"]}", |
| 65 | "amount": "{$price}" |
| 66 | } |
| 67 | ] |
| 68 | } |
| 69 | }, |
| 70 | { |
| 71 | "app": "data", |
| 72 | "payload": { |
| 73 | "to": "{trigger.data["_fwto"]}" |
| 74 | } |
| 75 | } |
| 76 | ] |
| 77 | } |
| 78 | ] |
| Message | Not enough amount |
|---|
| Message | Not enough amount |
|---|
| Message | one of secondary AAs bounced with error: 7TMMJWW2P5T4G2KMSAJHMB4Q4GXI2ERP: QVVN2C5JAE4YXLQONX6XTDFQKPBSXGVP: formula $_periodsToBuy = trigger.output[[asset=$currency]].amount / $PERIOD_PRICE; $periodsToBuy = floor($_periodsToBuy, 0); $maxTopup = $maxTopUpOf(trigger.initial_address); $cut = round(trigger.output[[asset=$currency]].amount * ($REFERRAL_ADDRESS ? $REFERRAL_FEE : $SERVICE_FEE), 0); if ($periodsToBuy == 0) bounce("That's not enough to buy even a single license period"); if ($periodsToBuy > $maxTopup) bounce("You can buy at most " || $maxTopup || " periods"); failed: bad asset false |
|---|
| Message | one of secondary AAs bounced with error: 7TMMJWW2P5T4G2KMSAJHMB4Q4GXI2ERP: QVVN2C5JAE4YXLQONX6XTDFQKPBSXGVP: That license cannot be traded |
|---|
| Message | one of secondary AAs bounced with error: 7TMMJWW2P5T4G2KMSAJHMB4Q4GXI2ERP: 4UV24LVCAE6ALMQGZMLZSQECKRDZLH5J: method field is mandatory {"alt":"2","authors":[{"address":"T2I6RLGGJ25KSJZKRNZZH52VMEAQ3722","authentifiers":{"r":"9/RRob8xad+w9E/5JX0T4pXhDL+Cog6szGtkEQa3zic30usAYrDdNrKGtOCmD/3jBQA7TGIrFhxRTgK92mogLA=="}}],"headers_commission":452,"last_ball":"ql+KhxFcGNADtkEBOGC7Lfo6Gbk+oHVfF3swP/+YcDU=","last_ball_unit":"aTeWSbG8bgM0c4rQWbQYNTH1O2EVe0Z6TGHT8hKrOrM=","main_chain_index":2323534,"messages":[{"app":"data","payload":{"_fwto":"4UV24LVCAE6ALMQGZMLZSQECKRDZLH5J","_opr":"50000","_pl":"7TMMJWW2P5T4G2KMSAJHMB4Q4GXI2ERP","method":"buy"},"payload_hash":"sdJr3/VXUKmD8Z2Mc1JLfHy50FbhjBPZRuG6TWybjJU=","payload_location":"inline"},{"app":"payment","payload":{"inputs":[{"message_index":1,"output_index":0,"unit":"qcu0JLeMQVktWm4ofU1+XjrstjR00u1731IqeOmNXoI="}],"outputs":[{"address":"LXNJ52YIDERIPCQDMOV6UU3YOCMM44WB","amount":10000},{"address":"T2I6RLGGJ25KSJZKRNZZH52VMEAQ3722","amount":386897}]},"payload_hash":"b5cuSuqCaRqPCd3UUr1YKJBQqKaVIyI3esHuylQW4pI=","payload_location":"inline"},{"app":"payment","payload":{"asset":"tZgXWTAv+1v1Ow4pMEVFFNlZAobGxMm2kIcr2dVR68c=","inputs":[{"message_index":0,"output_index":1,"unit":"N9Rji/QvobwRVtZnw2rpaP5k5EwQcEne5npJ7++SYwg="}],"outputs":[{"address":"LXNJ52YIDERIPCQDMOV6UU3YOCMM44WB","amount":59195}]},"payload_hash":"FL81s91zFmZHQbPIoIyC5RYpCVRm640BKdb0rykTskw=","payload_location":"inline"}],"parent_units":["osKL/yLYAR79o2dKs4H/A86XG/SkQ0+heUcxv7oNjvo="],"payload_commission":792,"timestamp":1632267339,"unit":"IPcdV3enXaZpfffkpUakGfaT6S8GOZUJ2L6h3MMzOsQ=","version":"3.0t","witness_list_unit":"TvqutGPz3T4Cs6oiChxFlclY92M2MvCvfXR5/FETato="} |
|---|