| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $INSTRUCTIONS_TO_VOTE = "To vote, use 'evaluate' = <evaluated address> + 'score' = < 0 to 5 > and optionaly 'domain' = < domain name > to vote in a specific domain. "; |
| 10 | |
| 11 | $INSTRUCTIONS_TO_CREATE_A_DOMAIN = 'A new domain can be created if you ' || $message_creation_howto || ' but the fee is \''||$DOMAIN_CREATION_FEE || '\' bytes, this money will be used to reward the evaluators. '|| $PRELIMINARY_CHECKS; |
| 12 | |
| 13 | |
| 14 | $AA_OWNER = 'SX66Y36BOU77S7MWML6JQQA3CJLX4COR'; |
| 15 | |
| 16 | $DEFAULT_DOMAIN = 'base'; |
| 17 | $DEFAULT_ATTESTOR = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; |
| 18 | $DEFAULT_CREATION_FEE = 500000; |
| 19 | $DEFAULT_REWARD = 1; |
| 20 | $DEFAULT_FORGIVING_DELAY = 36500; |
| 21 | |
| 22 | |
| 23 | $i = trigger.data; |
| 24 | $user = trigger.address; |
| 25 | $anonym_user = sha256($user); |
| 26 | $target = $i.evaluate; |
| 27 | $score = $i.score otherwise -1; |
| 28 | $domain = $i.domain otherwise $DEFAULT_DOMAIN; |
| 29 | $balance = var[$domain||"_balance"] otherwise trigger.output[[asset=base]].amount - 1000; |
| 30 | $count = var[$domain||"_count"] otherwise 0; |
| 31 | $last_eval = var[$domain||"_"||$anonym_user] otherwise false; |
| 32 | $last_eval_time = var[$domain||"_eval_time"] otherwise timestamp; |
| 33 | $attestor = var[$domain||"_attestor"] otherwise $i.attestor otherwise $DEFAULT_ATTESTOR; |
| 34 | $reward = var[$domain||"_reward"] otherwise $i.reward otherwise $DEFAULT_REWARD; |
| 35 | $use_balance_weigth = var[$domain||"_use_balance_weigth"] otherwise $i.use_balance_weigth; |
| 36 | $forgiving_delay = var[$domain||"_forgive_delay"] otherwise $i.forgive otherwise $DEFAULT_FORGIVING_DELAY; |
| 37 | $creation_fee = $i.creation_fee otherwise $DEFAULT_CREATION_FEE; |
| 38 | }", |
| 39 | "messages": { |
| 40 | "cases": [ |
| 41 | { |
| 42 | "if": "{ !!$target }", |
| 43 | "init": "{ |
| 44 | |
| 45 | if (!$score) bounce ($INSTRUCTIONS_TO_VOTE); |
| 46 | if ($score < 0 or $score > 5) bounce('Score must be set between 0 and 5 !'); |
| 47 | if ($target == $user) bounce('You can NOT vote for yourself !'); |
| 48 | if (!var[$domain]) bounce('Domain do NOT exist !'); |
| 49 | if (attestation[[attestors=$attestor, address=$user, ifnone=0]]) bounce ("You must be attested by "||$attestor); |
| 50 | |
| 51 | |
| 52 | $reputation_corrected = ($reputation == -1)? 0: $reputation; |
| 53 | |
| 54 | $total_score=($reputation * $eval_count); |
| 55 | |
| 56 | if ($is_re_evaluation){ |
| 57 | $new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count)); |
| 58 | $new_eval_count = $eval_count; |
| 59 | } |
| 60 | else{ |
| 61 | $new_reputation = ($total_score + $evaluation) / ($eval_count+1); |
| 62 | $new_eval_count = $eval_count+1; |
| 63 | } |
| 64 | $reputation_to_show = round($new_reputation,1); |
| 65 | |
| 66 | |
| 67 | if ($user_is_attested){ |
| 68 | $reward = round($balance_in_attestor_scope* $reward_pourcentage /100); |
| 69 | $message_about_the_reward = 'The reward is '||$reward_pourcentage||'% of the attested scope which is '|| $balance_in_attestor_scope ||" bytes. "; |
| 70 | } |
| 71 | else{ |
| 72 | $reward = $symbolic_reward; |
| 73 | $message_about_the_reward = 'The reward is symbolic because you are not attested by '|| $attestor_address||'. '; |
| 74 | } |
| 75 | |
| 76 | if ($AA_in_debug_mode){ |
| 77 | $REWARD_COMPUTATION = 'The reward will be ('|| $reward ||'). '|| $message_about_the_reward ||'. '; |
| 78 | |
| 79 | response['REWARD_COMPUTATION'] = $REWARD_COMPUTATION; |
| 80 | } |
| 81 | |
| 82 | }", |
| 83 | "messages": [ |
| 84 | { |
| 85 | "app": "payment", |
| 86 | "payload": { |
| 87 | "asset": "{'base'}", |
| 88 | "outputs": [ |
| 89 | { |
| 90 | "address": "{trigger.address}", |
| 91 | "amount": "{$reward}" |
| 92 | } |
| 93 | ] |
| 94 | } |
| 95 | }, |
| 96 | { |
| 97 | "app": "state", |
| 98 | "state": "{ |
| 99 | var[$domain||"_balance"] = $balance; |
| 100 | var[$domain||"_count"] = $count otherwise 0; |
| 101 | var[$domain||"_"||$anonym_user] = $last_eval; |
| 102 | var[$domain||"_eval_time"] = $last_eval_time; |
| 103 | var[$domain||"_attestor"] = $attestor; |
| 104 | var[$domain||"_reward"] = $reward; |
| 105 | var[$domain||"_use_balance_weigth"] = $use_balance_weigth; |
| 106 | var[$domain||"_forgive_delay"] = $forgiving_delay; |
| 107 | }" |
| 108 | } |
| 109 | ] |
| 110 | }, |
| 111 | { |
| 112 | "if": "{$is_creating}", |
| 113 | "init": "{ |
| 114 | |
| 115 | if (!$DOMAIN_CREATION){ |
| 116 | |
| 117 | |
| 118 | if ($attested_domain_exist) |
| 119 | bounce('Sorry, The domain \''||$domain||'\' in the scope of the attestor \''||$attestor_address||'\' already exist. '); |
| 120 | |
| 121 | |
| 122 | if (!$is_creation_fee_received) |
| 123 | bounce('Sorry, The fee to create a domain is '|| $DOMAIN_CREATION_FEE ||'bytes. '); |
| 124 | |
| 125 | |
| 126 | $message_about_creation_requirements = 'In creation mode you should have '||$message_creation_howto||' and you should not specify any \'evaluation\'. '; |
| 127 | |
| 128 | |
| 129 | if($is_requesting or $is_contributing) |
| 130 | bounce('Sorry, '|| $message_about_creation_requirements); |
| 131 | |
| 132 | |
| 133 | $moa = $mode_of_average_for_creation; |
| 134 | if(($moa != $AVERAGING_MODE_UNWEIGHTED) and ($moa != $AVERAGING_MODE_TIME_WEIGHTED) and ($moa != $mode_cbwa) and ($moa != $AVERAGING_MODE_REPUTATION_WEIGHTED)) |
| 135 | bounce('Sorry, '|| $message_about_creation_requirements); |
| 136 | |
| 137 | $ok_to_create_domain=true; |
| 138 | $message_about_creation = 'The domain \''||$domain||'\' has been created in the scope of the attestor \''||$attestor_address||'\' with the average mode \''||$mode_of_average_for_creation||'\'. '; |
| 139 | |
| 140 | response['message'] = $message_about_creation; |
| 141 | |
| 142 | if ($AA_in_debug_mode){ |
| 143 | $DOMAIN_CREATION = $message_about_creation; |
| 144 | |
| 145 | response['DOMAIN_CREATION'] = $DOMAIN_CREATION; |
| 146 | } |
| 147 | } |
| 148 | }", |
| 149 | "messages": [ |
| 150 | { |
| 151 | "app": "data", |
| 152 | "payload": { |
| 153 | "domain": "{$domain}", |
| 154 | "attestor": "{$attestor_address}" |
| 155 | } |
| 156 | }, |
| 157 | { |
| 158 | "app": "state", |
| 159 | "state": "{ |
| 160 | |
| 161 | if (!$FINAL_DAG_STATE){ |
| 162 | |
| 163 | $saved_fee = trigger.output[[asset=base]].amount - 1000; |
| 164 | |
| 165 | var['coad('||$attested_domain]=$user_address_hash; |
| 166 | var['moa('||$attested_domain]=$mode_of_average_for_creation; |
| 167 | |
| 168 | var['bo('||$attestor_hash] += $saved_fee; |
| 169 | |
| 170 | if ($AA_in_debug_mode){ |
| 171 | $FINAL_DAG_STATE = 'After creation of the new, domain the new balance for this attestor scope is('|| var['bo('||$attestor_hash] ||') bytes, it added ('|| $saved_fee ||') bytes. '; |
| 172 | |
| 173 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 174 | } |
| 175 | } |
| 176 | }" |
| 177 | } |
| 178 | ] |
| 179 | }, |
| 180 | { |
| 181 | "messages": [ |
| 182 | { |
| 183 | "app": "state", |
| 184 | "state": "{ |
| 185 | bounce ($INSTRUCTIONS_TO_VOTE || " " ||$INSTRUCTIONS_TO_CREATE_A_DOMAIN); |
| 186 | }" |
| 187 | } |
| 188 | ] |
| 189 | } |
| 190 | ] |
| 191 | } |
| 192 | } |
| 193 | ] |