| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://liquidity.obyte.org/liquidity-providers-distribution.json", |
| 5 | "init": "{ |
| 6 | $lock_period = 7 * 24 * 3600; |
| 7 | $registry_aa = "O6H6ZIFI57X3PLTYHOCVYPP5A553CYFQ"; |
| 8 | $address = trigger.address; |
| 9 | if (is_aa($address)) |
| 10 | bounce("Asset must be sent from a plain wallet, not an AA"); |
| 11 | if (trigger.output[[asset=base]].amount > 10000) |
| 12 | bounce("Bytes amount should be only 10000"); |
| 13 | |
| 14 | }", |
| 15 | "messages": { |
| 16 | "cases": [ |
| 17 | { |
| 18 | "if": "{trigger.output[[asset!=base]].amount > 0}", |
| 19 | "init": "{ |
| 20 | $received_asset = trigger.output[[asset!=base]].asset; |
| 21 | if ($received_asset == "ambiguous") |
| 22 | bounce("Different assets cannot be handled at same time"); |
| 23 | }", |
| 24 | "messages": [ |
| 25 | { |
| 26 | "app": "state", |
| 27 | "state": "{ |
| 28 | if (var["amount_" || $address || "_" || $received_asset]) |
| 29 | response['info'] = "All deposits for this asset will be locked until " || timestamp_to_string(timestamp + $lock_period); |
| 30 | else |
| 31 | response['info'] = "This asset will be locked until " || timestamp_to_string(timestamp + $lock_period); |
| 32 | var["amount_" || $address || "_" || $received_asset] += trigger.output[[asset!=base]].amount; |
| 33 | var["ts_" || $address || "_" || $received_asset] = timestamp; |
| 34 | }" |
| 35 | } |
| 36 | ] |
| 37 | }, |
| 38 | { |
| 39 | "if": "{trigger.data.withdraw}", |
| 40 | "init": "{ |
| 41 | if (asset[trigger.data.withdraw].exists) |
| 42 | $asset = trigger.data.withdraw; |
| 43 | else { |
| 44 | $asset = var[$registry_aa]["s2a_" || trigger.data.withdraw]; |
| 45 | if (!$asset) |
| 46 | bounce("unknown symbol"); |
| 47 | } |
| 48 | $amount_available = var["amount_" || $address || "_" || $asset]; |
| 49 | if (!$amount_available) |
| 50 | bounce("You don't have deposit for this asset"); |
| 51 | $locktime = var["ts_" || $address || "_" || $asset]; |
| 52 | if ($locktime AND timestamp < $locktime + $lock_period) |
| 53 | bounce("This asset is still locked, retry in " || round(($locktime + $lock_period - timestamp) / 3600) || " hours"); |
| 54 | if (trigger.data.amount){ |
| 55 | if (!is_valid_amount(trigger.data.amount)) |
| 56 | bounce("Invalid amount"); |
| 57 | if(trigger.data.amount > $amount_available) |
| 58 | bounce("Only " || $amount_available || " available for withdraw"); |
| 59 | $amount = trigger.data.amount; |
| 60 | } else { |
| 61 | $amount = $amount_available; |
| 62 | } |
| 63 | }", |
| 64 | "messages": [ |
| 65 | { |
| 66 | "app": "payment", |
| 67 | "payload": { |
| 68 | "asset": "{$asset}", |
| 69 | "outputs": [ |
| 70 | { |
| 71 | "address": "{$address}", |
| 72 | "amount": "{ $amount }" |
| 73 | } |
| 74 | ] |
| 75 | } |
| 76 | }, |
| 77 | { |
| 78 | "app": "state", |
| 79 | "state": "{ |
| 80 | var["amount_" || $address || "_" || $asset] -= $amount; |
| 81 | var["ts_" || $address || "_" || $asset] = false; |
| 82 | }" |
| 83 | } |
| 84 | ] |
| 85 | } |
| 86 | ] |
| 87 | } |
| 88 | } |
| 89 | ] |