| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "getters": "{ |
| 5 | |
| 6 | $locked_reward_share = 0.01; |
| 7 | $liquid_reward_share = 0.001; |
| 8 | |
| 9 | $deposit_asset_reducer = 0.5; |
| 10 | $bytes_reducer = 0.75; |
| 11 | |
| 12 | $new_user_reward = 10e9; |
| 13 | $referral_reward = 10e9; |
| 14 | |
| 15 | $balance_cap = 200e9; |
| 16 | |
| 17 | $in_friend_price = 2e9; |
| 18 | $min_deposit_today_for_infriends = 10e9; |
| 19 | |
| 20 | |
| 21 | $year = 31536000; |
| 22 | |
| 23 | |
| 24 | $get_period = ($days_old, $fu_addition_days) => { |
| 25 | $res = {period: 1}; |
| 26 | foreach($fu_addition_days, 7, ($index, $day) => { |
| 27 | if ($days_old > +$day) |
| 28 | $res.period = $index + 2; |
| 29 | }); |
| 30 | $res.period |
| 31 | }; |
| 32 | |
| 33 | $is_eligible_for_infriends = ($address, $user, $ceiling_price, $followup_reward_days, $received_amount) => { |
| 34 | $days_old = floor((timestamp - parse_date($user.reg_date))/24/3600); |
| 35 | $fu_addition_days = keys($followup_reward_days); |
| 36 | $period = $get_period($days_old, $fu_addition_days); |
| 37 | $days_old % $period == 0 |
| 38 | OR $in_friend_price AND $received_amount >= $in_friend_price |
| 39 | OR $user.last_deposit_date == timestamp_to_string(timestamp, 'date') AND $user.last_day_frd_deposits >= $min_deposit_today_for_infriends |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | $are_eligible = ($address1, $address2, $user1, $user2, $ceiling_price, $followup_reward_days, $received_amount) => { |
| 44 | $bNewUser = !$user1.last_date OR !$user2.last_date; |
| 45 | { |
| 46 | user1_eligible: $bNewUser OR $is_eligible_for_infriends($address1, $user1, $ceiling_price, $followup_reward_days, $received_amount), |
| 47 | user2_eligible: $bNewUser OR $is_eligible_for_infriends($address2, $user2, $ceiling_price, $followup_reward_days, $in_friend_price), |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | $get_deposit_asset_exchange_rate = ($friends_aa, $asset) => { |
| 53 | $aa = var[$friends_aa]['deposit_asset_'||$asset]; |
| 54 | require($aa, "unknown deposit asset"); |
| 55 | $params = definition[$aa][1].params; |
| 56 | $bX = $params.x_asset == $asset AND $params.y_asset == 'base'; |
| 57 | $bY = $params.x_asset == 'base' AND $params.y_asset == $asset; |
| 58 | require($bX OR $bY, "deposit asset must be one of the pool's assets and the other asset must be GBYTE"); |
| 59 | $recent = var[$aa]['recent']; |
| 60 | require($recent AND $recent.current AND $recent.prev, "no recent state of the pool"); |
| 61 | $pmax = max($recent.current.pmax, $recent.prev.pmax); |
| 62 | $pmin = min($recent.current.pmin, $recent.prev.pmin); |
| 63 | require($pmin > 0 AND $pmax > 0, "pmin and pmax must be > 0"); |
| 64 | $bX ? $pmin : 1/$pmax |
| 65 | }; |
| 66 | |
| 67 | $get_total_balance = ($balances, $ceiling_price, $friends_aa) => { |
| 68 | $totals = {deposit_assets_balance: 0}; |
| 69 | $asset_balances = filter($balances, 5, ($a, $balance) => $a != 'base' AND $a != 'frd'); |
| 70 | foreach($asset_balances, 3, ($a, $balance) => { |
| 71 | $totals.deposit_assets_balance = $totals.deposit_assets_balance + $balance * $get_deposit_asset_exchange_rate($friends_aa, $a); |
| 72 | }); |
| 73 | { |
| 74 | sans_reducers: $balances.frd + $balances.base / $ceiling_price + $totals.deposit_assets_balance / $ceiling_price, |
| 75 | with_reducers: $balances.frd + $balances.base / $ceiling_price * $bytes_reducer + $totals.deposit_assets_balance / $ceiling_price * $deposit_asset_reducer, |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | $get_rewards = ($address1, $address2, $user1, $user2, $user1_ref, $user2_ref, $ceiling_price, $friends_aa, $bFollowup) => { |
| 80 | $total_balance1 = $get_total_balance($user1.balances, $ceiling_price, $friends_aa); |
| 81 | $total_balance2 = $get_total_balance($user2.balances, $ceiling_price, $friends_aa); |
| 82 | $bNewUser = !$user1.last_date OR !$user2.last_date; |
| 83 | $bNewUserOrFromNewUser = $bNewUser OR $bFollowup AND ($user1.first_friend == $address2 OR $user2.first_friend == $address1); |
| 84 | $capped_total_balance1 = $bNewUserOrFromNewUser ? $total_balance1.with_reducers : min($total_balance1.with_reducers, $balance_cap); |
| 85 | $capped_total_balance2 = $bNewUserOrFromNewUser ? $total_balance2.with_reducers : min($total_balance2.with_reducers, $balance_cap); |
| 86 | $rewards = { |
| 87 | user1: { |
| 88 | locked: floor($capped_total_balance1 * $locked_reward_share), |
| 89 | liquid: floor($capped_total_balance1 * $liquid_reward_share), |
| 90 | }, |
| 91 | user2: { |
| 92 | locked: floor($capped_total_balance2 * $locked_reward_share), |
| 93 | liquid: floor($capped_total_balance2 * $liquid_reward_share), |
| 94 | }, |
| 95 | total_balances: { |
| 96 | user1: $total_balance1, |
| 97 | user2: $total_balance2, |
| 98 | }, |
| 99 | }; |
| 100 | |
| 101 | if (!$user1.last_date) |
| 102 | $rewards.user1.is_new = true; |
| 103 | if (!$user2.last_date) |
| 104 | $rewards.user2.is_new = true; |
| 105 | |
| 106 | if ($bNewUser){ |
| 107 | $capped_new_user_reward = floor(min($new_user_reward, $total_balance1.with_reducers, $total_balance2.with_reducers)); |
| 108 | $rewards.user1.locked = $rewards.user1.locked + $capped_new_user_reward; |
| 109 | $rewards.user1.new_user_reward = $capped_new_user_reward; |
| 110 | $rewards.user2.locked = $rewards.user2.locked + $capped_new_user_reward; |
| 111 | $rewards.user2.new_user_reward = $capped_new_user_reward; |
| 112 | } |
| 113 | |
| 114 | $min_unlock_date = timestamp_to_string(timestamp + $year, 'date'); |
| 115 | if (!$user1.last_date AND $user1.ref AND $user1_ref.unlock_date >= $min_unlock_date){ |
| 116 | $capped_referral_reward1 = min($referral_reward, floor($total_balance1.with_reducers)); |
| 117 | $rewards.user1.referred_user_reward = $capped_referral_reward1; |
| 118 | $rewards.user1.locked = $rewards.user1.locked + $capped_referral_reward1; |
| 119 | |
| 120 | $rewards.referrers[$user1.ref] = $capped_referral_reward1; |
| 121 | } |
| 122 | if (!$user2.last_date AND $user2.ref AND $user2_ref.unlock_date >= $min_unlock_date){ |
| 123 | $capped_referral_reward2 = min($referral_reward, floor($total_balance2.with_reducers)); |
| 124 | $rewards.user2.referred_user_reward = $capped_referral_reward2; |
| 125 | $rewards.user2.locked = $rewards.user2.locked + $capped_referral_reward2; |
| 126 | |
| 127 | $rewards.referrers[$user2.ref] = $capped_referral_reward2 + $rewards.referrers[$user2.ref]; |
| 128 | } |
| 129 | |
| 130 | $rewards |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | }", |
| 135 | "messages": [ |
| 136 | { |
| 137 | "app": "state", |
| 138 | "state": "{ |
| 139 | $get_rewards(); |
| 140 | bounce("library only"); |
| 141 | }" |
| 142 | } |
| 143 | ] |
| 144 | } |
| 145 | ] |