| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $BOUNCE_FEE = 10000; |
| 9 | $TYPICAL_FEE = 1000; |
| 10 | $REIMBURSEMENT = $BOUNCE_FEE - $TYPICAL_FEE; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{ trigger.data }", |
| 16 | "init": "{ |
| 17 | $seller = trigger.address; |
| 18 | $start_price = trigger.data.start_price otherwise bounce ("start price is missing"); |
| 19 | $lowest_price = trigger.data.lowest_price otherwise bounce ("lowest price is missing"); |
| 20 | $time_steps = trigger.data.time_steps otherwise bounce ("time steps missing"); |
| 21 | $period = trigger.data.period otherwise bounce("period field is missing"); |
| 22 | $reference = sha256($owner || $period ); |
| 23 | |
| 24 | if (var[$reference]) bounce("pension plan already exists"); |
| 25 | }", |
| 26 | "messages": [ |
| 27 | { |
| 28 | "app": "payment", |
| 29 | "payload": { |
| 30 | "asset": "base", |
| 31 | "outputs": [ |
| 32 | { |
| 33 | "address": "{trigger.address}", |
| 34 | "amount": "{$REIMBURSEMENT}" |
| 35 | } |
| 36 | ] |
| 37 | } |
| 38 | }, |
| 39 | { |
| 40 | "app": "state", |
| 41 | "state": "{ |
| 42 | $time = timestamp; |
| 43 | var[$reference] = 'requested'; |
| 44 | var[$reference||'.owner'] = $owner; |
| 45 | var[$reference||'.period'] = $period; |
| 46 | response['reference'] = $reference; |
| 47 | response['status'] = var[$reference]; |
| 48 | response['message'] = 'pension plan created'; |
| 49 | }" |
| 50 | } |
| 51 | ] |
| 52 | }, |
| 53 | { |
| 54 | "if": "{ |
| 55 | $deposit = trigger.output[[asset = base]]; |
| 56 | $deposit > $BOUNCE_FEE |
| 57 | }", |
| 58 | "messages": [ |
| 59 | { |
| 60 | "app": "state", |
| 61 | "state": "{ |
| 62 | response['message'] = 'Added ' || $deposit || ' bytes to the private pension plan'; |
| 63 | }" |
| 64 | } |
| 65 | ] |
| 66 | }, |
| 67 | { |
| 68 | "if": "{ trigger.data.action AND trigger.data.action == 'withdraw'}", |
| 69 | "init": "{ |
| 70 | $amount = trigger.data.amount otherwise balance[$owner]; |
| 71 | |
| 72 | if ($amount > balance[$owner]) bounce("Invalid withdrawal amount. Maximum balance is " || balance[$owner]); |
| 73 | if ($amount <= 0) bounce("Invalid withdrawal amount. Enter a number greater than zero."); |
| 74 | if (trigger.address != $owner) bounce("Unauthorized"); |
| 75 | }", |
| 76 | "messages": [ |
| 77 | { |
| 78 | "app": "payment", |
| 79 | "payload": { |
| 80 | "outputs": [ |
| 81 | { |
| 82 | "address": "{$owner}", |
| 83 | "amount": "{$amount}" |
| 84 | }, |
| 85 | { |
| 86 | "address": "{$owner}", |
| 87 | "amount": "{$REIMBURSEMENT}" |
| 88 | } |
| 89 | ] |
| 90 | } |
| 91 | }, |
| 92 | { |
| 93 | "app": "state", |
| 94 | "state": "{ |
| 95 | var[$owner] -= $amount; |
| 96 | }" |
| 97 | } |
| 98 | ] |
| 99 | }, |
| 100 | { |
| 101 | "init": "{ |
| 102 | bounce("Enter a data field: owner, reference or action"); |
| 103 | }", |
| 104 | "messages": [ |
| 105 | { |
| 106 | "app": "state", |
| 107 | "state": "{ |
| 108 | response['usage'] = 'Enter a data field: owner, reference or action'; |
| 109 | }" |
| 110 | } |
| 111 | ] |
| 112 | } |
| 113 | ] |
| 114 | } |
| 115 | } |
| 116 | ] |