| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $asset = var['asset']; |
| 6 | $founder = var['founder']; |
| 7 | $minutes_from_epoch = timestamp / 60; |
| 8 | $hours_from_epoch = $minutes_from_epoch / 60; |
| 9 | $days_from_epoch = $hours_from_epoch / 24; |
| 10 | $weeks_from_epoch = $days_from_epoch / 7; |
| 11 | $periods_from_epoch = floor($hours_from_epoch); |
| 12 | $current_period = $periods_from_epoch - var['start'] + 1; |
| 13 | $max_claim_per_period = 1e6; |
| 14 | $max_crowdsale_periods = 720; |
| 15 | }", |
| 16 | "messages": { |
| 17 | "cases": [ |
| 18 | { |
| 19 | "if": "{!$asset}", |
| 20 | "messages": [ |
| 21 | { |
| 22 | "app": "asset", |
| 23 | "payload": { |
| 24 | "is_private": false, |
| 25 | "is_transferrable": true, |
| 26 | "auto_destroy": true, |
| 27 | "fixed_denominations": false, |
| 28 | "issued_by_definer_only": true, |
| 29 | "cosigned_by_definer": false, |
| 30 | "spender_attested": false |
| 31 | } |
| 32 | }, |
| 33 | { |
| 34 | "app": "state", |
| 35 | "state": "{ |
| 36 | var['asset'] = response_unit; |
| 37 | var['founder'] = trigger.address; |
| 38 | var['start'] = $periods_from_epoch; |
| 39 | response['message'] = 'Crowdsale started'; |
| 40 | }" |
| 41 | } |
| 42 | ] |
| 43 | }, |
| 44 | { |
| 45 | "if": "{$asset AND trigger.address == $founder}", |
| 46 | "messages": [ |
| 47 | { |
| 48 | "app": "payment", |
| 49 | "payload": { |
| 50 | "asset": "base", |
| 51 | "outputs": [ |
| 52 | { |
| 53 | "address": "{$founder}" |
| 54 | } |
| 55 | ] |
| 56 | } |
| 57 | }, |
| 58 | { |
| 59 | "app": "state", |
| 60 | "state": "{ |
| 61 | response['message'] = 'Founder claimed'; |
| 62 | }" |
| 63 | } |
| 64 | ] |
| 65 | }, |
| 66 | { |
| 67 | "if": "{$asset AND trigger.address != $founder AND trigger.data.claim_period}", |
| 68 | "init": "{ |
| 69 | if (trigger.data.claim_period >= $current_period) bounce('Claiming is only possible for previous periods.'); |
| 70 | $claim_address = trigger.data.claim_address ? trigger.data.claim_address : trigger.address; |
| 71 | $investor_claim_period = var['investor_' || $claim_address || '_' || trigger.data.claim_period]; |
| 72 | if (!$investor_claim_period) bounce('Investor didn\'t invest on that period or already claimed that period.'); |
| 73 | $total_raised_on_period = var['total_raised_' || trigger.data.claim_period] + $amount; |
| 74 | $invesor_share = $investor_claim_period / $total_raised_on_period; |
| 75 | $claim_amount = floor($invesor_share * $max_claim_per_period); |
| 76 | }", |
| 77 | "messages": [ |
| 78 | { |
| 79 | "app": "payment", |
| 80 | "payload": { |
| 81 | "asset": "{$asset}", |
| 82 | "outputs": [ |
| 83 | { |
| 84 | "address": "{$claim_address}", |
| 85 | "amount": "{$claim_amount}" |
| 86 | } |
| 87 | ] |
| 88 | } |
| 89 | }, |
| 90 | { |
| 91 | "app": "state", |
| 92 | "state": "{ |
| 93 | var['investor_' || $claim_address || '_' || trigger.data.claim_period] = false; |
| 94 | response['message'] = 'Investor claimed'; |
| 95 | }" |
| 96 | } |
| 97 | ] |
| 98 | }, |
| 99 | { |
| 100 | "if": "{$asset AND trigger.address != $founder AND !trigger.data.claim_period AND $current_period <= $max_crowdsale_periods}", |
| 101 | "init": "{ |
| 102 | $investor_on_period = var['investor_' || trigger.address || '_' || $current_period]; |
| 103 | $amount = trigger.output[[asset=base]]; |
| 104 | $total_raised_on_period = var['total_raised_' || $current_period] + $amount; |
| 105 | $total_investor_on_period = $investor_on_period + $amount; |
| 106 | }", |
| 107 | "messages": [ |
| 108 | { |
| 109 | "app": "state", |
| 110 | "state": "{ |
| 111 | var['total_raised_' || $current_period] = $total_raised_on_period; |
| 112 | var['investor_' || trigger.address || '_' || $current_period] = $total_investor_on_period; |
| 113 | response['message'] = 'Use claim_period=' || $current_period || ' and claim_address=' || trigger.address || ' in data.'; |
| 114 | }" |
| 115 | } |
| 116 | ] |
| 117 | } |
| 118 | ] |
| 119 | } |
| 120 | } |
| 121 | ] |