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