| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://coop.obyte.org/coop.json", |
| 5 | "getters": "{ |
| 6 | |
| 7 | |
| 8 | |
| 9 | $year = 10800; |
| 10 | |
| 11 | |
| 12 | $get_deposited_supply = () => { |
| 13 | $state = var['state']; |
| 14 | $state.total_locked |
| 15 | }; |
| 16 | |
| 17 | |
| 18 | $get_variables = () => { |
| 19 | var['variables'] OTHERWISE { |
| 20 | daily_locked_reward: 0.01, |
| 21 | daily_liquid_reward: 0.001, |
| 22 | bytes_reducer: 0.75, |
| 23 | by_votes_share: 0.5, |
| 24 | messaging_attestors: 'WMFLGI2GLAB2MDF2KQAH37VNRRMK7A5N:JBW7HT5CRBSF7J7RD26AYLQG6GZDPFPS:5KM36CFPBD2QJLVD65PHZG34WEM4RPY2', |
| 25 | real_name_attestors: 'WMFLGI2GLAB2MDF2KQAH37VNRRMK7A5N:JFKWGRMXP3KHUAFMF4SJZVDXFL6ACC6P', |
| 26 | referrer_coop_deposit_reward_share: 0.02, |
| 27 | referrer_bytes_deposit_reward_share: 0.01, |
| 28 | referral_reward: 10e9, |
| 29 | min_balance_instead_of_real_name: 1e8, |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | $get_ceiling_price = () => { |
| 35 | $constants = var['constants']; |
| 36 | 2^((timestamp - $constants.launch_ts)/$year) |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | |
| 41 | }", |
| 42 | "init": "{ |
| 43 | |
| 44 | $vote_lifetime = 90 * 24 * 3600; |
| 45 | |
| 46 | $constants = var['constants'] OTHERWISE {}; |
| 47 | |
| 48 | |
| 49 | $asset = $constants.asset; |
| 50 | |
| 51 | $governance_aa = $constants.governance_aa; |
| 52 | |
| 53 | $variables = $get_variables(); |
| 54 | |
| 55 | $ceiling_price = 2^((timestamp - $constants.launch_ts)/$year); |
| 56 | |
| 57 | $state = var['state'] OTHERWISE {total_locked: 0, total_locked_bytes: 0, locked_emissions: 0, liquid_emissions: 0, total_votes: 0, total_votes_bal: 0, ts: timestamp}; |
| 58 | |
| 59 | $update_emissions = () => { |
| 60 | $elapsed_days = (timestamp - $state.ts)/24/3600; |
| 61 | $s = $state.total_locked + $state.total_locked_bytes / $ceiling_price * $variables.bytes_reducer; |
| 62 | $state.locked_emissions = $state.locked_emissions + $s * $variables.daily_locked_reward * $elapsed_days; |
| 63 | $state.liquid_emissions = $state.liquid_emissions + $s * $variables.daily_liquid_reward * $elapsed_days; |
| 64 | $state.ts = timestamp; |
| 65 | }; |
| 66 | |
| 67 | $update_user = ($user) => { |
| 68 | if (!$state.total_votes OR !$state.total_votes_bal) return; |
| 69 | $old_total_balance = $user.total_balance; |
| 70 | $new_locked_emissions = $state.locked_emissions - $user.last_locked_emissions; |
| 71 | $new_liquid_emissions = $state.liquid_emissions - $user.last_liquid_emissions; |
| 72 | $user.last_locked_emissions = $state.locked_emissions; |
| 73 | $user.last_liquid_emissions = $state.liquid_emissions; |
| 74 | $user_share = $variables.by_votes_share * $user.votes/$state.total_votes + (1-$variables.by_votes_share) * $user.votes * $old_total_balance/$state.total_votes_bal; |
| 75 | $user_new_locked_emissions = $new_locked_emissions * $user_share; |
| 76 | $user_new_liquid_emissions = $new_liquid_emissions * $user_share; |
| 77 | $user.balance = $user.balance + $user_new_locked_emissions; |
| 78 | $user.liquid_balance = $user.liquid_balance + $user_new_liquid_emissions; |
| 79 | $user.locked_rewards = $user.locked_rewards + $user_new_locked_emissions; |
| 80 | $user.liquid_rewards = $user.liquid_rewards + $user_new_liquid_emissions; |
| 81 | |
| 82 | |
| 83 | $user.total_balance = $user.balance + $user.bytes_balance/$ceiling_price * $variables.bytes_reducer; |
| 84 | $user.last_ts = timestamp; |
| 85 | |
| 86 | $state.total_locked = $state.total_locked + $user_new_locked_emissions; |
| 87 | $state.total_votes_bal = $state.total_votes_bal + ($user.total_balance - $old_total_balance) * $user.votes; |
| 88 | }; |
| 89 | |
| 90 | |
| 91 | if ($asset) |
| 92 | $received_amount = trigger.output[[asset=$asset]]; |
| 93 | $received_bytes_amount = max(trigger.output[[asset=base]] - 10000, 0); |
| 94 | |
| 95 | |
| 96 | $update_emissions(); |
| 97 | |
| 98 | $governance_base_aa = 'RWCPEK3KGTJC6KJXMH2LIKZI3B426MBV'; |
| 99 | |
| 100 | }", |
| 101 | "messages": { |
| 102 | "cases": [ |
| 103 | { |
| 104 | "if": "{ trigger.data.define AND !$asset }", |
| 105 | "messages": [ |
| 106 | { |
| 107 | "app": "asset", |
| 108 | "payload": { |
| 109 | "is_private": false, |
| 110 | "is_transferrable": true, |
| 111 | "auto_destroy": false, |
| 112 | "fixed_denominations": false, |
| 113 | "issued_by_definer_only": true, |
| 114 | "cosigned_by_definer": false, |
| 115 | "spender_attested": false |
| 116 | } |
| 117 | }, |
| 118 | { |
| 119 | "app": "definition", |
| 120 | "payload": { |
| 121 | "definition": [ |
| 122 | "autonomous agent", |
| 123 | { |
| 124 | "base_aa": "{$governance_base_aa}", |
| 125 | "params": { |
| 126 | "coop_aa": "{this_address}" |
| 127 | } |
| 128 | } |
| 129 | ] |
| 130 | } |
| 131 | }, |
| 132 | { |
| 133 | "app": "state", |
| 134 | "state": "{ |
| 135 | $constants.asset = response_unit; |
| 136 | $constants.governance_aa = unit[response_unit].messages[[.app='definition']].payload.address; |
| 137 | $constants.launch_ts = timestamp; |
| 138 | var['constants'] = $constants; |
| 139 | response['asset'] = response_unit; |
| 140 | }" |
| 141 | } |
| 142 | ] |
| 143 | }, |
| 144 | { |
| 145 | "if": "{ trigger.address == $governance_aa AND trigger.data.name }", |
| 146 | "init": "{ |
| 147 | $name = trigger.data.name; |
| 148 | $value = trigger.data.value; |
| 149 | }", |
| 150 | "messages": [ |
| 151 | { |
| 152 | "app": "state", |
| 153 | "state": "{ |
| 154 | $variables[$name] = $value; |
| 155 | var['variables'] = $variables; |
| 156 | }" |
| 157 | } |
| 158 | ] |
| 159 | }, |
| 160 | { |
| 161 | "if": "{ |
| 162 | ($received_amount > 0 OR $received_bytes_amount > 0 OR trigger.data.term) AND trigger.data.deposit |
| 163 | }", |
| 164 | "init": "{ |
| 165 | $username = attestation[[attestors=$variables.messaging_attestors, address=trigger.address, ifnone=false]].username; |
| 166 | require($username, "your address must be attested on a messaging service"); |
| 167 | |
| 168 | $messagingUserId = attestation[[attestors=$variables.messaging_attestors, address=trigger.address, ifnone=false]].userId OTHERWISE $username; |
| 169 | $m_addr = var['m_address_'||$messagingUserId]; |
| 170 | require(!$m_addr OR $m_addr == trigger.address, "only one account per messaging user is allowed"); |
| 171 | |
| 172 | require(!is_aa(trigger.address), "AAs not allowed to participate"); |
| 173 | |
| 174 | $user = var['user_'||trigger.address] OTHERWISE {balance: 0, bytes_balance: 0, total_balance: 0, unlock_date: false, reg_date: timestamp_to_string(timestamp, 'date'), reg_ts: timestamp, last_ts: timestamp, last_locked_emissions: $state.locked_emissions, last_liquid_emissions: $state.liquid_emissions}; |
| 175 | $bNewUser = !$user.unlock_date; |
| 176 | $update_user($user); |
| 177 | |
| 178 | $old_total_balance = $user.total_balance; |
| 179 | |
| 180 | $total_balance_sans_reducers = $user.balance + $received_amount + ($user.bytes_balance + $received_bytes_amount)/$ceiling_price; |
| 181 | $bBigDeposit = $total_balance_sans_reducers >= $variables.min_balance_instead_of_real_name; |
| 182 | if (!$bBigDeposit) |
| 183 | $user_id = attestation[[attestors=$variables.real_name_attestors, address=trigger.address, ifnone=false]].user_id; |
| 184 | require($user_id OR $bBigDeposit, "your address must be real-name attested or you should deposit at least "||($variables.min_balance_instead_of_real_name/1e9)||" COOP"); |
| 185 | if ($user_id){ |
| 186 | $addr = var['rn_address_'||$user_id]; |
| 187 | require(!$addr OR $addr == trigger.address, "only one account per user is allowed"); |
| 188 | } |
| 189 | |
| 190 | if (exists(trigger.data.ref)){ |
| 191 | require(is_valid_address(trigger.data.ref), "referrer address not valid"); |
| 192 | require(var['user_'||trigger.data.ref], "referrer doesn't exist"); |
| 193 | if ($bNewUser){ |
| 194 | $user.ref = trigger.data.ref; |
| 195 | if (trigger.data.no_referrer_deposit_reward) |
| 196 | $user.no_referrer_deposit_reward = true; |
| 197 | } |
| 198 | else |
| 199 | response['ref_ignored'] = "Referrer can be set only with the first deposit"; |
| 200 | } |
| 201 | |
| 202 | if ($user.ref){ |
| 203 | $referrer = var['user_'||$user.ref]; |
| 204 | $min_unlock_date = timestamp_to_string(timestamp + $year, 'date'); |
| 205 | $bReferrerEligible = $referrer.unlock_date >= $min_unlock_date; |
| 206 | if (!$bReferrerEligible) |
| 207 | response['warning'] = "Referrer's unlock date is less than 1 year in the future and they are not eligible to receive the deposit reward"; |
| 208 | } |
| 209 | |
| 210 | $term = trigger.data.term OTHERWISE 1; |
| 211 | |
| 212 | $new_unlock_date = timestamp_to_string(timestamp + $term * 24 * 3600, 'date'); |
| 213 | if (!$bNewUser) |
| 214 | require($new_unlock_date >= $user.unlock_date, "new unlock date must not go back"); |
| 215 | |
| 216 | }", |
| 217 | "messages": [ |
| 218 | { |
| 219 | "if": "{$user.ref AND !$user.no_referrer_deposit_reward AND $bReferrerEligible}", |
| 220 | "app": "payment", |
| 221 | "payload": { |
| 222 | "asset": "{$asset}", |
| 223 | "outputs": [ |
| 224 | { |
| 225 | "address": "{$user.ref}", |
| 226 | "amount": "{floor($received_amount * $variables.referrer_coop_deposit_reward_share + $received_bytes_amount/$ceiling_price * $variables.referrer_bytes_deposit_reward_share)}" |
| 227 | } |
| 228 | ] |
| 229 | } |
| 230 | }, |
| 231 | { |
| 232 | "app": "state", |
| 233 | "state": "{ |
| 234 | $user.balance = $user.balance + $received_amount; |
| 235 | $user.bytes_balance = $user.bytes_balance + $received_bytes_amount; |
| 236 | $user.total_balance = $user.balance + $user.bytes_balance/$ceiling_price * $variables.bytes_reducer; |
| 237 | $user.unlock_date = $new_unlock_date; |
| 238 | if ($bNewUser AND $user_id) |
| 239 | var['rn_address_'||$user_id] = trigger.address; |
| 240 | var['m_address_'||$messagingUserId] = trigger.address; |
| 241 | $state.total_locked = $state.total_locked + $received_amount; |
| 242 | $state.total_locked_bytes = $state.total_locked_bytes + $received_bytes_amount; |
| 243 | $state.total_votes_bal = $state.total_votes_bal + ($user.total_balance - $old_total_balance) * $user.votes; |
| 244 | |
| 245 | |
| 246 | if ($bNewUser AND $user.ref AND $bReferrerEligible){ |
| 247 | $capped_referral_reward = min($variables.referral_reward, floor($user.total_balance)); |
| 248 | $user.balance = $user.balance + $capped_referral_reward; |
| 249 | $user.total_balance = $user.total_balance + $capped_referral_reward; |
| 250 | $referrer.balance = $referrer.balance + $capped_referral_reward; |
| 251 | $referrer.total_balance = $referrer.total_balance + $capped_referral_reward; |
| 252 | $referrer.referral_rewards = $referrer.referral_rewards + $capped_referral_reward; |
| 253 | $referrer.referred_users = $referrer.referred_users + 1; |
| 254 | var['user_'||$user.ref] = $referrer; |
| 255 | $state.total_locked = $state.total_locked + 2 * $capped_referral_reward; |
| 256 | $state.total_votes_bal = $state.total_votes_bal + $capped_referral_reward * ($user.votes + $referrer.votes); |
| 257 | $state.total_referral_rewards = $state.total_referral_rewards + 2 * $capped_referral_reward; |
| 258 | } |
| 259 | var['user_'||trigger.address] = $user; |
| 260 | var['state'] = $state; |
| 261 | |
| 262 | if ($received_amount > 0 OR $received_bytes_amount > 0) |
| 263 | response['message'] = "Deposited"; |
| 264 | response['unlock_date'] = $new_unlock_date; |
| 265 | response['event'] = json_stringify({type: 'deposit', owner: trigger.address, amount: $received_amount, bytes_amount: $received_bytes_amount, referral_reward: $capped_referral_reward, total_balance: $user.total_balance}); |
| 266 | }" |
| 267 | } |
| 268 | ] |
| 269 | }, |
| 270 | { |
| 271 | "if": "{trigger.data.vote AND trigger.data.for AND exists(trigger.data.strength)}", |
| 272 | "init": "{ |
| 273 | $strength = trigger.data.strength; |
| 274 | require($strength >= 0 AND $strength <= 3, "vote strength must be between 0 and 3"); |
| 275 | |
| 276 | $for = trigger.data.for; |
| 277 | require($for != trigger.address, "voting for oneself is unnecessary, such a vote is automatically added whenever you vote for anyone else"); |
| 278 | }", |
| 279 | "messages": [ |
| 280 | { |
| 281 | "app": "state", |
| 282 | "state": "{ |
| 283 | if (trigger.data.delete_expired_votes){ |
| 284 | foreach(trigger.data.delete_expired_votes, 5, ($from_address, $to_address) => { |
| 285 | $vote = var['vote_'||$from_address||'_'||$to_address]; |
| 286 | if (!$vote) return; |
| 287 | if (timestamp - $vote.ts < $vote_lifetime) return; |
| 288 | $to_user = var['user_'||$to_address]; |
| 289 | $to_user.votes = $to_user.votes - $vote.votes; |
| 290 | $state.total_votes = $state.total_votes - $vote.votes; |
| 291 | $state.total_votes_bal = $state.total_votes_bal - $vote.votes * $to_user.total_balance; |
| 292 | var['vote_'||$from_address||'_'||$to_address] = false; |
| 293 | var['user_'||$to_address] = $to_user; |
| 294 | }); |
| 295 | } |
| 296 | |
| 297 | $user = var['user_'||trigger.address]; |
| 298 | require($user, "you are not a user"); |
| 299 | require($user.balance > 0 OR $user.bytes_balance > 0, "you have no balance"); |
| 300 | |
| 301 | $for_user = var['user_'||$for]; |
| 302 | require($for_user, "the user you are voting for does not exist"); |
| 303 | |
| 304 | |
| 305 | $min_unlock_date = timestamp_to_string(timestamp + 12 * 3600, 'date'); |
| 306 | |
| 307 | require($user.unlock_date >= $min_unlock_date, "your balance unlocks on "||$user.unlock_date||", you can vote only if it unlocks in at least 1 year"); |
| 308 | require($for_user.unlock_date >= $min_unlock_date, "the voted user's balance unlocks on "||$for_user.unlock_date||", you can vote for them only if it unlocks in at least 1 year"); |
| 309 | |
| 310 | $update_user($user); |
| 311 | $update_user($for_user); |
| 312 | |
| 313 | $sqrt_bal = sqrt($user.total_balance); |
| 314 | $votes = $sqrt_bal * $strength; |
| 315 | $self_votes = $sqrt_bal * 3; |
| 316 | |
| 317 | $add_vote = ($u, $address, $new_votes) => { |
| 318 | $prev_vote = var['vote_'||trigger.address||'_'||$address]; |
| 319 | $delta_votes = $new_votes - $prev_vote.votes; |
| 320 | var['vote_'||trigger.address||'_'||$address] = $new_votes ? {votes: $new_votes, ts: timestamp} : false; |
| 321 | $u.votes = $u.votes + $delta_votes; |
| 322 | var['user_'||$address] = $u; |
| 323 | $state.total_votes = $state.total_votes + $delta_votes; |
| 324 | $state.total_votes_bal = $state.total_votes_bal + $delta_votes * $u.total_balance; |
| 325 | }; |
| 326 | |
| 327 | $add_vote($for_user, $for, $votes); |
| 328 | $add_vote($user, trigger.address, $self_votes); |
| 329 | |
| 330 | response['message'] = 'Voted'; |
| 331 | response['event'] = json_stringify({type: 'vote', address: trigger.address, for: $for, strength: $strength, votes: $votes, total_balance: $user.total_balance, for_total_balance: $for_user.total_balance}); |
| 332 | var['state'] = $state; |
| 333 | }" |
| 334 | } |
| 335 | ] |
| 336 | }, |
| 337 | { |
| 338 | "if": "{trigger.data.claim}", |
| 339 | "init": "{ |
| 340 | $user = var['user_'||trigger.address]; |
| 341 | require($user, "you are not a user"); |
| 342 | |
| 343 | $restake_percent = trigger.data.restake_percent OTHERWISE 0; |
| 344 | require($restake_percent >= 0 AND $restake_percent <= 100, "invalid restake_percent"); |
| 345 | |
| 346 | $update_user($user); |
| 347 | |
| 348 | require($user.liquid_balance > 0, "you have no liquid balance to withdraw"); |
| 349 | $claimed_amount = floor($user.liquid_balance * (1 - $restake_percent/100)); |
| 350 | $restaked_amount = $user.liquid_balance * $restake_percent/100; |
| 351 | }", |
| 352 | "messages": [ |
| 353 | { |
| 354 | "app": "payment", |
| 355 | "payload": { |
| 356 | "asset": "{$asset}", |
| 357 | "outputs": [ |
| 358 | { |
| 359 | "address": "{trigger.address}", |
| 360 | "amount": "{$claimed_amount}" |
| 361 | } |
| 362 | ] |
| 363 | } |
| 364 | }, |
| 365 | { |
| 366 | "app": "state", |
| 367 | "state": "{ |
| 368 | if ($restaked_amount){ |
| 369 | $user.balance = $user.balance + $restaked_amount; |
| 370 | $user.total_balance = $user.total_balance + $restaked_amount; |
| 371 | $state.total_locked = $state.total_locked + $restaked_amount; |
| 372 | $state.total_votes_bal = $state.total_votes_bal + $restaked_amount * $user.votes; |
| 373 | |
| 374 | |
| 375 | $new_unlock_date = timestamp_to_string(timestamp + $year, 'date'); |
| 376 | if ($new_unlock_date > $user.unlock_date) |
| 377 | $user.unlock_date = $new_unlock_date; |
| 378 | } |
| 379 | $user.liquid_balance = 0; |
| 380 | var['user_'||trigger.address] = $user; |
| 381 | var['state'] = $state; |
| 382 | |
| 383 | response['message'] = 'Claimed'; |
| 384 | response['event'] = json_stringify({type: 'claim', address: trigger.address, cliamed_amount: $claimed_amount, restaked_amount: $restaked_amount, restake_percent: $restake_percent, total_balance: $user.total_balance}); |
| 385 | }" |
| 386 | } |
| 387 | ] |
| 388 | }, |
| 389 | { |
| 390 | "if": "{trigger.data.withdraw}", |
| 391 | "init": "{ |
| 392 | $user = var['user_'||trigger.address]; |
| 393 | require($user, "you are not a user"); |
| 394 | require(timestamp_to_string(timestamp, 'date') >= $user.unlock_date, "your balance unlocks on "||$user.unlock_date); |
| 395 | require($user.balance > 0 OR $user.bytes_balance > 0, "you have no balance"); |
| 396 | }", |
| 397 | "messages": [ |
| 398 | { |
| 399 | "app": "payment", |
| 400 | "payload": { |
| 401 | "asset": "base", |
| 402 | "outputs": [ |
| 403 | { |
| 404 | "address": "{trigger.address}", |
| 405 | "amount": "{floor($user.bytes_balance)}" |
| 406 | }, |
| 407 | { |
| 408 | "address": "{$governance_aa}", |
| 409 | "amount": 1000 |
| 410 | } |
| 411 | ] |
| 412 | } |
| 413 | }, |
| 414 | { |
| 415 | "app": "payment", |
| 416 | "payload": { |
| 417 | "asset": "{$asset}", |
| 418 | "outputs": [ |
| 419 | { |
| 420 | "address": "{trigger.address}", |
| 421 | "amount": "{floor($user.balance + $user.liquid_balance)}" |
| 422 | } |
| 423 | ] |
| 424 | } |
| 425 | }, |
| 426 | { |
| 427 | "app": "data", |
| 428 | "payload": { |
| 429 | "update_user_balance": 1, |
| 430 | "address": "{trigger.address}" |
| 431 | } |
| 432 | }, |
| 433 | { |
| 434 | "app": "state", |
| 435 | "state": "{ |
| 436 | response['message'] = 'Withdrawn'; |
| 437 | response['event'] = json_stringify({type: 'withdrawal', address: trigger.address, balance: $user.balance, bytes_balance: $user.bytes_balance, total_balance: 0}); |
| 438 | $state.total_locked = $state.total_locked - $user.balance; |
| 439 | $state.total_locked_bytes = $state.total_locked_bytes - $user.bytes_balance; |
| 440 | $state.total_votes_bal = $state.total_votes_bal - $user.total_balance * $user.votes; |
| 441 | $user.balance = 0; |
| 442 | $user.bytes_balance = 0; |
| 443 | $user.liquid_balance = 0; |
| 444 | $user.total_balance = 0; |
| 445 | var['user_'||trigger.address] = $user; |
| 446 | var['state'] = $state; |
| 447 | }" |
| 448 | } |
| 449 | ] |
| 450 | }, |
| 451 | { |
| 452 | "if": "{trigger.data.replace AND ($received_amount > 0 OR $received_bytes_amount > 0)}", |
| 453 | "init": "{ |
| 454 | require(!($received_amount AND $received_bytes_amount), "don't send both tokens"); |
| 455 | $user = var['user_'||trigger.address]; |
| 456 | require($user, "you are not a user"); |
| 457 | $update_user($user); |
| 458 | if ($received_amount){ |
| 459 | $out_bytes_amount = floor($received_amount * $ceiling_price); |
| 460 | require($user.bytes_balance >= $out_bytes_amount, "not enough bytes locked"); |
| 461 | $out_amount = 0; |
| 462 | } |
| 463 | else{ |
| 464 | $out_amount = floor($received_bytes_amount / $ceiling_price); |
| 465 | require($user.balance >= $out_amount, "not enough COOP locked"); |
| 466 | $out_bytes_amount = 0; |
| 467 | } |
| 468 | }", |
| 469 | "messages": [ |
| 470 | { |
| 471 | "app": "payment", |
| 472 | "payload": { |
| 473 | "asset": "base", |
| 474 | "outputs": [ |
| 475 | { |
| 476 | "address": "{trigger.address}", |
| 477 | "amount": "{$out_bytes_amount}" |
| 478 | } |
| 479 | ] |
| 480 | } |
| 481 | }, |
| 482 | { |
| 483 | "app": "payment", |
| 484 | "payload": { |
| 485 | "asset": "{$asset}", |
| 486 | "outputs": [ |
| 487 | { |
| 488 | "address": "{trigger.address}", |
| 489 | "amount": "{$out_amount}" |
| 490 | } |
| 491 | ] |
| 492 | } |
| 493 | }, |
| 494 | { |
| 495 | "app": "state", |
| 496 | "state": "{ |
| 497 | $state.total_locked = $state.total_locked + $received_amount - $out_amount; |
| 498 | $state.total_locked_bytes = $state.total_locked_bytes + $received_bytes_amount - $out_bytes_amount; |
| 499 | |
| 500 | $user.balance = $user.balance + $received_amount - $out_amount; |
| 501 | $user.bytes_balance = $user.bytes_balance + $received_bytes_amount - $out_bytes_amount; |
| 502 | |
| 503 | |
| 504 | $new_total_balance = $user.balance + $user.bytes_balance/$ceiling_price * $variables.bytes_reducer; |
| 505 | $delta_total_balance = $new_total_balance - $user.total_balance; |
| 506 | $user.total_balance = $new_total_balance; |
| 507 | |
| 508 | $state.total_votes_bal = $state.total_votes_bal + $delta_total_balance * $user.votes; |
| 509 | |
| 510 | var['user_'||trigger.address] = $user; |
| 511 | var['state'] = $state; |
| 512 | |
| 513 | response['message'] = 'Replaced'; |
| 514 | response['event'] = json_stringify({type: 'replace', address: trigger.address, received_amount: $received_amount, received_bytes_amount: $received_bytes_amount, out_amount: $out_amount, out_bytes_amount: $out_bytes_amount, total_balance: $user.total_balance}); |
| 515 | }" |
| 516 | } |
| 517 | ] |
| 518 | } |
| 519 | ] |
| 520 | } |
| 521 | } |
| 522 | ] |