| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "getters": "{ |
| 5 | $is_unlocked = () => timestamp_to_string(timestamp, 'date') >= params.unlock_date; |
| 6 | }", |
| 7 | "messages": { |
| 8 | "cases": [ |
| 9 | { |
| 10 | "if": "{ trigger.data.withdraw }", |
| 11 | "init": "{ |
| 12 | require(params.owner, "owner not set in params"); |
| 13 | require(params.unlock_date, "unlock_date not set in params"); |
| 14 | |
| 15 | |
| 16 | require(trigger.address == params.owner, "only owner can withdraw"); |
| 17 | |
| 18 | |
| 19 | require($is_unlocked(), "balance unlocks on " || params.unlock_date); |
| 20 | |
| 21 | |
| 22 | $asset = trigger.data.asset OTHERWISE 'base'; |
| 23 | |
| 24 | |
| 25 | $requested = trigger.data.amount OTHERWISE ''; |
| 26 | if (!$requested) { |
| 27 | $bal = balance[$asset]; |
| 28 | require($bal > 0, "nothing to withdraw"); |
| 29 | $amount_to_send = $bal; |
| 30 | } else { |
| 31 | require(is_valid_amount($requested), "invalid amount"); |
| 32 | $amount_to_send = $requested; |
| 33 | require(balance[$asset] >= $amount_to_send, "insufficient balance"); |
| 34 | } |
| 35 | }", |
| 36 | "messages": [ |
| 37 | { |
| 38 | "app": "payment", |
| 39 | "payload": { |
| 40 | "asset": "{ $asset }", |
| 41 | "outputs": [ |
| 42 | { |
| 43 | "address": "{ params.owner }", |
| 44 | "amount": "{ $amount_to_send }" |
| 45 | } |
| 46 | ] |
| 47 | } |
| 48 | }, |
| 49 | { |
| 50 | "app": "state", |
| 51 | "state": "{ |
| 52 | response['message'] = 'withdrawn'; |
| 53 | response['asset'] = $asset; |
| 54 | response['amount'] = $amount_to_send; |
| 55 | }" |
| 56 | } |
| 57 | ] |
| 58 | }, |
| 59 | { |
| 60 | "messages": [ |
| 61 | { |
| 62 | "app": "state", |
| 63 | "state": "{ response['message'] = 'deposit accepted'; }" |
| 64 | } |
| 65 | ] |
| 66 | } |
| 67 | ] |
| 68 | } |
| 69 | } |
| 70 | ] |