| 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 = 52; |
| 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 | "init": "{ |
| 47 | $founder_claim_amount = balance[base]-1000; |
| 48 | }", |
| 49 | "messages": [ |
| 50 | { |
| 51 | "app": "payment", |
| 52 | "payload": { |
| 53 | "asset": "base", |
| 54 | "outputs": [ |
| 55 | { |
| 56 | "address": "{$founder}", |
| 57 | "amount": "{$founder_claim_amount}" |
| 58 | } |
| 59 | ] |
| 60 | } |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | "if": "{$asset AND trigger.address != $founder AND trigger.data.claim_period}", |
| 66 | "init": "{ |
| 67 | if (trigger.data.claim_period >= $current_period) bounce("Claiming is only possible for previous periods."); |
| 68 | |
| 69 | $claim_address = trigger.data.claim_address ? trigger.data.claim_address : trigger.address; |
| 70 | $investor_claim_period = var['investor_' || $claim_address || '_' || trigger.data.claim_period]; |
| 71 | if (!$investor_claim_period) bounce("You didn\'t invest on that period."); |
| 72 | if ($investor_claim_period < 0) bounce("You have already claimed that period."); |
| 73 | |
| 74 | $total_raised_on_period = var['total_raised_' || trigger.data.claim_period] + $amount; |
| 75 | $invesor_share = $investor_claim_period / $total_raised_on_period; |
| 76 | $claim_amount = floor($invesor_share * $max_claim_per_period); |
| 77 | }", |
| 78 | "messages": [ |
| 79 | { |
| 80 | "app": "payment", |
| 81 | "payload": { |
| 82 | "asset": "{$asset}", |
| 83 | "outputs": [ |
| 84 | { |
| 85 | "address": "{$claim_address}", |
| 86 | "amount": "{$claim_amount}" |
| 87 | } |
| 88 | ] |
| 89 | } |
| 90 | }, |
| 91 | { |
| 92 | "app": "state", |
| 93 | "state": "{ |
| 94 | var['investor_' || $claim_address || '_' || trigger.data.claim_period] = -1; |
| 95 | response['message'] = 'Asset claimed'; |
| 96 | }" |
| 97 | } |
| 98 | ] |
| 99 | }, |
| 100 | { |
| 101 | "if": "{$asset AND trigger.address != $founder AND !trigger.data.claim_period AND $current_period <= $max_crowdsale_periods}", |
| 102 | "init": "{ |
| 103 | $investor_on_period = var['investor_' || trigger.address || '_' || $current_period]; |
| 104 | $amount = trigger.output[[asset=base]]; |
| 105 | $total_raised_on_period = var['total_raised_' || $current_period] + $amount; |
| 106 | $total_investor_on_period = $investor_on_period + $amount; |
| 107 | }", |
| 108 | "messages": [ |
| 109 | { |
| 110 | "app": "state", |
| 111 | "state": "{ |
| 112 | var['total_raised_' || $current_period] = $total_raised_on_period; |
| 113 | var['investor_' || trigger.address || '_' || $current_period] = $total_investor_on_period; |
| 114 | response['message'] = 'Use claim_period=' || $current_period || ' and claim_address=' || trigger.address || ' in data.'; |
| 115 | }" |
| 116 | } |
| 117 | ] |
| 118 | } |
| 119 | ] |
| 120 | } |
| 121 | } |
| 122 | ] |