| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/bonded-stablecoin-buffer.json", |
| 5 | "init": "{ |
| 6 | if (trigger.output[[asset!=base]]) |
| 7 | bounce("only bytes payments are accepted"); |
| 8 | if (!is_aa(params.curve_aa)) |
| 9 | bounce("bad curve_aa"); |
| 10 | if (!is_valid_address(params.address)) |
| 11 | bounce("bad address"); |
| 12 | $max_fee_percent = params.max_fee_percent OTHERWISE 1; |
| 13 | if (typeof($max_fee_percent) != 'number') |
| 14 | bounce("bad max_fee_percent"); |
| 15 | $max_change_percent = params.max_change_percent OTHERWISE 0.5; |
| 16 | if (typeof($max_change_percent) != 'number') |
| 17 | bounce("bad max_change_percent"); |
| 18 | }", |
| 19 | "messages": { |
| 20 | "cases": [ |
| 21 | { |
| 22 | "if": "{ trigger.data.execute }", |
| 23 | "init": "{ |
| 24 | $tokens2 = trigger.data.tokens2; |
| 25 | if (!is_integer($tokens2) OR $tokens2 <= 0) |
| 26 | bounce("bad tokens2"); |
| 27 | if (balance[base] <= 1e5) |
| 28 | bounce("buffer balance is too low"); |
| 29 | }", |
| 30 | "messages": [ |
| 31 | { |
| 32 | "app": "payment", |
| 33 | "payload": { |
| 34 | "asset": "base", |
| 35 | "outputs": [ |
| 36 | { |
| 37 | "address": "{params.curve_aa}" |
| 38 | } |
| 39 | ] |
| 40 | } |
| 41 | }, |
| 42 | { |
| 43 | "app": "data", |
| 44 | "payload": { |
| 45 | "tokens2_to": "{params.address}", |
| 46 | "max_fee_percent": "{$max_fee_percent}", |
| 47 | "tokens2": "{$tokens2}", |
| 48 | "ref": "{trigger.data.ref OTHERWISE ''}" |
| 49 | } |
| 50 | }, |
| 51 | { |
| 52 | "app": "state", |
| 53 | "state": "{ |
| 54 | var['executing_at'] = mci; |
| 55 | var['sent'] = balance[base]; |
| 56 | }" |
| 57 | } |
| 58 | ] |
| 59 | }, |
| 60 | { |
| 61 | "if": "{trigger.address == params.curve_aa AND var['executing_at'] == mci}", |
| 62 | "init": "{ |
| 63 | $amount = trigger.output[[asset=base]]; |
| 64 | |
| 65 | |
| 66 | $bSendBytes = ($amount >= 1000 AND $amount <= max($max_change_percent/100 * var['sent'], 1e5)); |
| 67 | }", |
| 68 | "messages": [ |
| 69 | { |
| 70 | "if": "{$bSendBytes}", |
| 71 | "app": "payment", |
| 72 | "payload": { |
| 73 | "asset": "base", |
| 74 | "outputs": [ |
| 75 | { |
| 76 | "address": "{params.address}" |
| 77 | } |
| 78 | ] |
| 79 | } |
| 80 | }, |
| 81 | { |
| 82 | "app": "state", |
| 83 | "state": "{ |
| 84 | var['executing_at'] = false; |
| 85 | var['sent'] = false; |
| 86 | response['message'] = $bSendBytes ? "Done" : "Amount left: " || $amount; |
| 87 | }" |
| 88 | } |
| 89 | ] |
| 90 | }, |
| 91 | { |
| 92 | "messages": [ |
| 93 | { |
| 94 | "app": "state", |
| 95 | "state": "{ |
| 96 | |
| 97 | }" |
| 98 | } |
| 99 | ] |
| 100 | } |
| 101 | ] |
| 102 | } |
| 103 | } |
| 104 | ] |