| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $CT_ADDRESS = "ZIT3YPDTLGAO7MVO2ONNDMSEYS2VELX6"; |
| 6 | $OWNER = params.issuer; |
| 7 | $LICENSE_ASSET = var["licenseAsset"]; |
| 8 | if ($LICENSE_ASSET){ |
| 9 | $priceStr = data_feed[[oracles=$OWNER, feed_name=this_address, ifseveral="last", type="string"]]; |
| 10 | $chunks = split($priceStr, " "); |
| 11 | require(length($chunks) == 2, "Malformed data_feed. It should have only 2 items"); |
| 12 | $PRICE = $chunks[0]; |
| 13 | require(is_integer($PRICE), "Price must be an integer"); |
| 14 | require($PRICE > 0, "Price must be positive"); |
| 15 | require(is_valid_amount($PRICE), "Price must be a valid amount"); |
| 16 | $PRICE_ASSET = $chunks[1]; |
| 17 | require(asset[$PRICE_ASSET].exists, "Price asset does not exist"); |
| 18 | } |
| 19 | $method = trigger.data["method"]; |
| 20 | $CUT = 0.03; |
| 21 | if ($LICENSE_ASSET AND NOT $method) |
| 22 | bounce("method field is mandatory"); |
| 23 | }", |
| 24 | "messages": { |
| 25 | "cases": [ |
| 26 | { |
| 27 | "if": "{NOT $LICENSE_ASSET}", |
| 28 | "messages": [ |
| 29 | { |
| 30 | "if": "{params.cap}", |
| 31 | "app": "asset", |
| 32 | "payload": { |
| 33 | "is_private": false, |
| 34 | "cap": "{params.cap OTHERWISE 0}", |
| 35 | "is_transferrable": "{NOT NOT params.tradeable}", |
| 36 | "auto_destroy": false, |
| 37 | "fixed_denominations": false, |
| 38 | "issued_by_definer_only": true, |
| 39 | "cosigned_by_definer": false, |
| 40 | "spender_attested": false |
| 41 | } |
| 42 | }, |
| 43 | { |
| 44 | "if": "{NOT params.cap}", |
| 45 | "app": "asset", |
| 46 | "payload": { |
| 47 | "is_private": false, |
| 48 | "is_transferrable": "{NOT NOT params.tradeable}", |
| 49 | "auto_destroy": false, |
| 50 | "fixed_denominations": false, |
| 51 | "issued_by_definer_only": true, |
| 52 | "cosigned_by_definer": false, |
| 53 | "spender_attested": false |
| 54 | } |
| 55 | }, |
| 56 | { |
| 57 | "app": "state", |
| 58 | "state": "{ |
| 59 | var["licenseAsset"] = response_unit; |
| 60 | }" |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | "if": "{trigger.address == $OWNER AND $method == "payout"}", |
| 66 | "messages": { |
| 67 | "cases": [ |
| 68 | { |
| 69 | "if": "{$method == "payout"}", |
| 70 | "messages": [ |
| 71 | { |
| 72 | "app": "payment", |
| 73 | "payload": { |
| 74 | "asset": "{trigger.data.asset OTHERWISE $PRICE_ASSET}", |
| 75 | "outputs": [ |
| 76 | { |
| 77 | "address": "{$OWNER}" |
| 78 | } |
| 79 | ] |
| 80 | } |
| 81 | } |
| 82 | ] |
| 83 | } |
| 84 | ] |
| 85 | } |
| 86 | }, |
| 87 | { |
| 88 | "if": "{$method == "buy"}", |
| 89 | "init": "{ |
| 90 | $copies = floor(trigger.output[[asset=$PRICE_ASSET]]/$PRICE, 0); |
| 91 | require($copies > 0, "You cannot buy less than 1 license"); |
| 92 | $hasReferral = (trigger.data["r"] AND is_valid_address(trigger.data["r"])); |
| 93 | $cut = $hasReferral ? $CUT/2 : $CUT; |
| 94 | $cutAmount = round(trigger.output[[asset=$PRICE_ASSET]] * $cut, 0); |
| 95 | }", |
| 96 | "messages": [ |
| 97 | { |
| 98 | "app": "payment", |
| 99 | "payload": { |
| 100 | "asset": "{$LICENSE_ASSET}", |
| 101 | "outputs": [ |
| 102 | { |
| 103 | "address": "{trigger.data["to"] OTHERWISE trigger.initial_address}", |
| 104 | "amount": "{$copies}" |
| 105 | } |
| 106 | ] |
| 107 | } |
| 108 | }, |
| 109 | { |
| 110 | "app": "payment", |
| 111 | "payload": { |
| 112 | "asset": "{$PRICE_ASSET}", |
| 113 | "outputs": [ |
| 114 | { |
| 115 | "address": "{$CT_ADDRESS}", |
| 116 | "amount": "{$cutAmount}" |
| 117 | }, |
| 118 | { |
| 119 | "if": "{$hasReferral}", |
| 120 | "address": "{trigger.data["r"]}", |
| 121 | "amount": "{$cutAmount}" |
| 122 | } |
| 123 | ] |
| 124 | } |
| 125 | } |
| 126 | ] |
| 127 | } |
| 128 | ] |
| 129 | } |
| 130 | } |
| 131 | ] |