Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim reward updates #2838

Merged
merged 75 commits into from May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
411c650
Rename contract functions
liberumed Oct 22, 2019
fcfa8d1
Rename contract events
liberumed Oct 22, 2019
a7bc950
Delete contract functions
liberumed Oct 22, 2019
ceed09c
Add fields to StakingPool and StakingPoolsDelegator required for stak…
liberumed Nov 7, 2019
21dbc70
Remove chain based stakes snapshotting porcess
liberumed Nov 5, 2019
224f5cb
Add blockscout based stakes snapshottting process
liberumed Nov 5, 2019
98a4a69
Exclude snapshotted fields from being nilified
liberumed Nov 6, 2019
2d6f8e9
Update stake reward value defentions and add snapshotted stake reward
liberumed Nov 8, 2019
b7b9761
Change stake snapshotting to simple function
liberumed Nov 8, 2019
09f2776
Fix order for reward ratio responses
liberumed Nov 11, 2019
3c9a5ed
Display “Accounted Stake Amount” and “Current Reward Percent” in dele…
liberumed Nov 11, 2019
7048cfe
Add validator_set_apply_block tcheck before display snapshotted data
liberumed Nov 11, 2019
be8dfef
Get uniq pool mining addresses for snapshotting process
liberumed Nov 12, 2019
b0434f2
Add is_snapshotted check before showing snapshotted data
liberumed Nov 12, 2019
e1679ae
Rename staked_amount field to total_staked_amount
liberumed Nov 12, 2019
d1310b0
Add validator_reward_ratio field and fix staked_ratio value
liberumed Nov 13, 2019
74e723d
Fix fields/variables names
varasev Nov 20, 2019
8bb6669
Fix start_snapshotting function
varasev Nov 20, 2019
d6125b2
Fix round error for reward ratios
varasev Nov 20, 2019
89f10c0
Add links to addresses in Delegators window
varasev Nov 21, 2019
64650a3
Fix tooltip in Delegators window
varasev Nov 21, 2019
c5b69da
Rename some DB fields
varasev Nov 21, 2019
ddffb47
Alert for Show only those I staked into
varasev Nov 21, 2019
91d0a93
Fix snapshotting
varasev Nov 26, 2019
432708d
Improve snapshotting
varasev Nov 27, 2019
073fd44
Add retrieving of validatorMinRewardPercent
varasev Nov 28, 2019
9470099
Fix delegators counter and other improvements
varasev Nov 28, 2019
c233057
Add runner-specific options
varasev Nov 29, 2019
c27052d
Update BlockReward contract ERC balance
varasev Nov 29, 2019
23ccf1d
Refresh BlockReward contract ERC balance without page reloading
varasev Dec 2, 2019
697be30
Remove an excess code from snapshotting
varasev Dec 3, 2019
94dbefe
Remove excess JSON RPCs from snapshotting
varasev Dec 3, 2019
fd6a237
Explicit block number in snapshotting
varasev Dec 3, 2019
23e16bf
Restore snapshots after restart
varasev Dec 3, 2019
d6afcb3
Enhance ContractState.get_token function
varasev Dec 5, 2019
5a0bcdf
Add comments for stakes controller
varasev Dec 5, 2019
bbcc42f
Improve autorefreshing of Validators tab
varasev Dec 5, 2019
5390ba1
Improve the displaying of Stakes Ratio
varasev Dec 6, 2019
f37728d
Add pool list autorefresh informer
varasev Dec 6, 2019
0c34010
Add check for staking token definition
varasev Dec 6, 2019
641aac8
Add render_claim_reward channel message
varasev Dec 10, 2019
6261dbd
Simplify render_claim_reward handling; remove UI freeze
varasev Dec 10, 2019
485efd0
Prevent running parallel Claim Reward tasks
varasev Dec 11, 2019
ee303aa
Don't allow parallel Claim Reward tasks for the same staker
varasev Dec 11, 2019
b2ec8ff
Find the pools an address have ever staked into
varasev Dec 12, 2019
8c04a04
Fix find_claim_reward_pools function
varasev Dec 12, 2019
84c22ba
Cleanups
varasev Dec 13, 2019
07dfe65
Cleanups
varasev Dec 13, 2019
5ebef02
Fetch Claim Reward pools
varasev Dec 13, 2019
4491397
Display drop-down list of Claim Reward pools with amounts
varasev Dec 13, 2019
ab527a1
Retrieve epoch numbers for Claim Reward dialog popup
varasev Dec 16, 2019
5518c4b
Add general elements to Claim Reward dialog popup
varasev Dec 17, 2019
02a4419
Prepare Recalculate button for Claim Reward
varasev Dec 18, 2019
32e13ab
Implement Recalculate button for Claim Reward
varasev Dec 20, 2019
8bd49fe
Handle disconnections on client side and remove excess requests
varasev Dec 23, 2019
ab82f22
Fix staking page refreshing
varasev Dec 24, 2019
42d4390
Comment for timeout and shutdown for stakes_channel
varasev Dec 24, 2019
e8e88ba
Add claimReward transaction signing
varasev Dec 24, 2019
30ac2f2
Claim Reward dialog UI improvements
varasev Dec 25, 2019
14c1d07
Add creationMethod to entry_to_elixir
varasev Jan 14, 2020
3198380
Split eth_getLogs requests
varasev Jan 27, 2020
1cdc234
Replace eth_getLogs with public getter
varasev Jan 30, 2020
1ce8b3a
Rename bridge fee to bridge reward
varasev Feb 20, 2020
dc6708b
Fix tests: mix format and mix credo
vbaranov Apr 1, 2020
10aae54
Fix tests: gettext, eslint
vbaranov Apr 1, 2020
38667bc
Fix tests: dialyzer (add entries to .dialyzer-iggnore)
vbaranov Apr 1, 2020
77b493e
Fix 3 failed tests in stakes_controller_test.exs
vbaranov Apr 2, 2020
7521d64
Fix bug in dropdown with tokens appearance in address view page
vbaranov Apr 2, 2020
3df924d
Fix the order of mock calls in contract_state_test.exs
vbaranov Apr 3, 2020
45f8101
checkNetworkAndAccount function fix and small improvements
varasev May 8, 2020
d5ff9d3
Fix viewing_addresses_test.exs
varasev May 11, 2020
f7c61f4
Update contract_state_test.exs
varasev May 13, 2020
10868c5
mix format contract_state_test.exs
varasev May 13, 2020
f5cafea
Remove excess delegatorShare calls
varasev May 14, 2020
3561943
Update .dialyzer-ignore
varasev May 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -118,6 +118,7 @@ $stakes-link-color: $primary !default;
.stakes-th-text {
margin-right: 10px;
white-space: nowrap;
text-align: center;
}

.stakes-td {
Expand Down
Expand Up @@ -39,18 +39,13 @@ async function becomeCandidate ($modal, store, msg) {
lockModal($modal)

const stakingContract = store.getState().stakingContract
const blockRewardContract = store.getState().blockRewardContract
const decimals = store.getState().tokenDecimals
const stake = new BigNumber($modal.find('[candidate-stake]').val().replace(',', '.').trim()).shiftedBy(decimals).integerValue()
const miningAddress = $modal.find('[mining-address]').val().trim().toLowerCase()

try {
if (!await stakingContract.methods.areStakeAndWithdrawAllowed().call()) {
if (await blockRewardContract.methods.isSnapshotting().call()) {
openErrorModal('Error', 'Staking actions are temporarily restricted. Please try again in a few blocks.')
} else {
openErrorModal('Error', 'The current staking epoch is ending, and staking actions are temporarily restricted. Please try again when the new epoch starts.')
}
openErrorModal('Error', 'The current staking epoch is ending, and staking actions are temporarily restricted. Please try again when the new epoch starts.')
return false
}

Expand Down
Expand Up @@ -11,7 +11,7 @@ export function openClaimWithdrawalModal (event, store) {
.push('render_claim_withdrawal', { address })
.receive('ok', msg => {
const $modal = $(msg.html)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.staked_amount)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.total_staked_amount)
$modal.find('form').submit(() => {
claimWithdraw($modal, address, store)
return false
Expand Down
2 changes: 1 addition & 1 deletion apps/block_scout_web/assets/js/pages/stakes/make_stake.js
Expand Up @@ -18,7 +18,7 @@ export function openMakeStakeModal (event, store) {
.push('render_make_stake', { address })
.receive('ok', msg => {
const $modal = $(msg.html)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.staked_amount)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.total_staked_amount)
setupValidation(
$modal.find('form'),
{
Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/assets/js/pages/stakes/move_stake.js
Expand Up @@ -19,9 +19,9 @@ export function openMoveStakeModal (event, store) {
}

function setupModal ($modal, fromAddress, store, msg) {
setupChart($modal.find('.js-pool-from-progress'), msg.from.self_staked_amount, msg.from.staked_amount)
setupChart($modal.find('.js-pool-from-progress'), msg.from.self_staked_amount, msg.from.total_staked_amount)
if (msg.to) {
setupChart($modal.find('.js-pool-to-progress'), msg.to.self_staked_amount, msg.to.staked_amount)
setupChart($modal.find('.js-pool-to-progress'), msg.to.self_staked_amount, msg.to.total_staked_amount)

setupValidation(
$modal.find('form'),
Expand Down
Expand Up @@ -16,7 +16,7 @@ export function openWithdrawStakeModal (event, store) {

function setupWithdrawStakeModal (address, store, msg) {
const $modal = $(msg.html)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.staked_amount)
setupChart($modal.find('.js-stakes-progress'), msg.self_staked_amount, msg.total_staked_amount)
setupValidation(
$modal.find('form'),
{
Expand Down
2 changes: 1 addition & 1 deletion apps/block_scout_web/lib/block_scout_web/chain.ex
Expand Up @@ -253,7 +253,7 @@ defmodule BlockScoutWeb.Chain do
%{"block_number" => block_number}
end

defp paging_params(%StakingPool{staking_address_hash: address_hash, staked_ratio: value}) do
defp paging_params(%StakingPool{staking_address_hash: address_hash, stakes_ratio: value}) do
%{"address_hash" => address_hash, "value" => Decimal.to_string(value)}
end

Expand Down
Expand Up @@ -41,7 +41,7 @@ defmodule BlockScoutWeb.StakesChannel do
token = ContractState.get(:token)

html =
View.render_to_string(StakesView, "_stakes_modal_validator_info.html",
View.render_to_string(StakesView, "_stakes_modal_pool_info.html",
validator: pool,
delegator: delegator,
average_block_time: average_block_time,
Expand All @@ -55,6 +55,9 @@ defmodule BlockScoutWeb.StakesChannel do
pool = Chain.staking_pool(staking_address)
token = ContractState.get(:token)

is_show_snapshotted_data =
pool.is_validator && ContractState.get(:validator_set_apply_block) > 0 && ContractState.get(:is_snapshotted)

delegators =
staking_address
|> Chain.staking_pool_delegators()
Expand All @@ -73,7 +76,8 @@ defmodule BlockScoutWeb.StakesChannel do
account: socket.assigns[:account],
pool: pool,
delegators: delegators,
token: token
token: token,
is_show_snapshotted_data: is_show_snapshotted_data
)

{:reply, {:ok, %{html: html}}, socket}
Expand Down Expand Up @@ -128,7 +132,7 @@ defmodule BlockScoutWeb.StakesChannel do
delegator_staked: (delegator && delegator.stake_amount) || 0,
min_stake: min_stake,
self_staked_amount: pool.self_staked_amount,
staked_amount: pool.staked_amount
total_staked_amount: pool.total_staked_amount
}

{:reply, {:ok, result}, socket}
Expand Down Expand Up @@ -174,15 +178,15 @@ defmodule BlockScoutWeb.StakesChannel do
stake_amount: delegator_from.stake_amount,
min_stake: min_from_stake,
self_staked_amount: pool_from.self_staked_amount,
staked_amount: pool_from.staked_amount
total_staked_amount: pool_from.total_staked_amount
},
to:
if pool_to do
%{
stake_amount: (delegator_to && delegator_to.stake_amount) || 0,
min_stake: min_to_stake,
self_staked_amount: pool_to.self_staked_amount,
staked_amount: pool_to.staked_amount
total_staked_amount: pool_to.total_staked_amount
}
end
}
Expand Down Expand Up @@ -212,7 +216,7 @@ defmodule BlockScoutWeb.StakesChannel do
result = %{
html: html,
self_staked_amount: pool.self_staked_amount,
staked_amount: pool.staked_amount,
total_staked_amount: pool.total_staked_amount,
delegator_staked: delegator.stake_amount,
ordered_withdraw: delegator.ordered_withdraw,
max_withdraw_allowed: delegator.max_withdraw_allowed,
Expand All @@ -238,7 +242,7 @@ defmodule BlockScoutWeb.StakesChannel do
result = %{
html: html,
self_staked_amount: pool.self_staked_amount,
staked_amount: pool.staked_amount
total_staked_amount: pool.total_staked_amount
}

{:reply, {:ok, result}, socket}
Expand Down
Expand Up @@ -15,15 +15,15 @@
render BlockScoutWeb.CommonComponentsView,
"_progress_from_to.html",
from: format_token_amount(@pool.self_staked_amount, @token, digits: 0, ellipsize: false, symbol: false),
to: format_token_amount(@pool.staked_amount, @token, digits: 0, ellipsize: false, symbol: false),
to: format_token_amount(@pool.total_staked_amount, @token, digits: 0, ellipsize: false, symbol: false),
progress: amount_ratio(@pool)
%>
</div>
<div class="col-2 stakes-td stakes-cell">
<%= if @pools_type == :inactive do %>
<%= if @pool.is_banned, do: gettext("Yes"), else: gettext("No") %>
<% else %>
<%= if @pool.staked_ratio, do: "#{@pool.staked_ratio}%" %>
<%= if @pool.stakes_ratio, do: "#{@pool.stakes_ratio}%" %>
<% end %>
</div>
<div class="col-2 stakes-td stakes-cell">
Expand Down
Expand Up @@ -13,14 +13,29 @@
<%= render BlockScoutWeb.StakesView, "_stakes_th.html", title: gettext("Staker's Address"), tooltip: gettext("All pool participant addresses. The top address belongs to the validator.") %>
</div>
<div class="col-4">
<%= render BlockScoutWeb.StakesView, "_stakes_th.html", title: gettext("Total Stake Amount"), tooltip: gettext("Amount of STAKE placed by an address") %>
<%=
amount_col_title =
if @is_show_snapshotted_data do
gettext("Current Stake Amount") <> "<br />(" <> gettext("Accounted Stake Amount") <> ")"
varasev marked this conversation as resolved.
Show resolved Hide resolved
else
gettext("Current Stake Amount")
end

render BlockScoutWeb.StakesView, "_stakes_th.html", title: amount_col_title, tooltip: gettext("Amount of STAKE placed by an address")
%>
</div>
<div class="col-3">
<%=
title = if @pool.is_validator do gettext("Reward Percent") else gettext("Potential Reward Percent") end
reward_col_title =
if @is_show_snapshotted_data do
gettext("Potential Reward Percent") <> "<br />(" <> gettext("Current Reward Percent") <> ")"
varasev marked this conversation as resolved.
Show resolved Hide resolved
else
gettext("Potential Reward Percent")
end

render BlockScoutWeb.StakesView,
"_stakes_th.html",
title: title,
title: reward_col_title,
tooltip: gettext("Reward distribution is based on stake amount. Validator receives a minimum of 30%.")
%>
</div>
Expand Down Expand Up @@ -52,8 +67,52 @@
<% end %>
</div>
</div>
<div class="col-4 stakes-td stakes-cell"><%= format_token_amount(delegator.stake_amount, @token, symbol: false) %></div>
<div class="col-3 stakes-td stakes-cell"><%= if delegator.reward_ratio do "#{delegator.reward_ratio}%" else "-" end %></div>
<div class="col-4 stakes-td stakes-cell">
<%= format_token_amount(delegator.stake_amount, @token, symbol: false) %>
<%= if @is_show_snapshotted_data do %>
(
<%=
if delegator.snapshotted_stake_amount do
format_token_amount(delegator.snapshotted_stake_amount, @token, symbol: false)
else
0
end
%>
)
<% end %>
</div>
<div class="col-3 stakes-td stakes-cell">
<%
reward =
if delegator.delegator_address_hash == @pool.staking_address_hash do
%{
reward_ratio: @pool.validator_reward_ratio,
snapshotted_reward_ratio: @pool.snapshotted_validator_reward_ratio
}
else
%{
reward_ratio: delegator.reward_ratio,
snapshotted_reward_ratio: delegator.snapshotted_reward_ratio
}
end
%>
<%= if reward.reward_ratio do %>
<%= reward.reward_ratio %>%
<%= if @is_show_snapshotted_data do %>
(
<%=
if reward.snapshotted_reward_ratio do
"#{reward.snapshotted_reward_ratio}%"
else
"0%"
end
%>
)
<% end %>
<% else %>
-
<% end %>
</div>
</div>
<% end %>
</div>
Expand Down
Expand Up @@ -35,18 +35,18 @@
render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html",
title: gettext("Delegators’ Staked Amount"),
value: format_token_amount(Decimal.sub(@validator.staked_amount, @validator.self_staked_amount), @token)
value: format_token_amount(Decimal.sub(@validator.total_staked_amount, @validator.self_staked_amount), @token)
%>
<%=
render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html",
title: gettext("Stakes Ratio"),
value: if(@validator.staked_ratio, do: "#{@validator.staked_ratio}%")
value: if(@validator.stakes_ratio, do: "#{@validator.stakes_ratio}%")
%>
<%=
render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html",
title: gettext("Reward Percent"),
title: gettext("Share of Pool’s Reward"),
value: "#{@validator.block_reward_ratio}%"
%>
<%=
Expand Down
Expand Up @@ -10,7 +10,7 @@
<%= format_token_amount(@pool.self_staked_amount, @token, symbol: false, digits: 2) %>
</div>
<div class="stakes-progress-data-total js-stakes-progress-data-total">
<%= format_token_amount(@pool.staked_amount, @token, symbol: false, digits: 2) %>
<%= format_token_amount(@pool.total_staked_amount, @token, symbol: false, digits: 2) %>
</div>
</div>
</div>
Expand All @@ -24,7 +24,7 @@
<div class="stakes-progress-info">
<h2 class="stakes-progress-info-title"><%= gettext("Stakes Ratio") %></h2>
<p class="stakes-progress-info-value">
<%= @pool.staked_ratio %>%
<%= @pool.stakes_ratio %>%
</p>
</div>
<div class="stakes-progress-info">
Expand Down
@@ -1,6 +1,6 @@
<th class="stakes-table-th">
<div class="stakes-table-th-content">
<span class="stakes-th-text"><%= @title %></span>
<span class="stakes-th-text"><%= raw(@title) %></span>
<%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip.html", text: @tooltip %>
</div>
</th>
Expand Up @@ -12,11 +12,11 @@ defmodule BlockScoutWeb.StakesHelpers do
zero = Decimal.new(0)

case pool do
%{staked_amount: ^zero} ->
%{total_staked_amount: ^zero} ->
0

%{staked_amount: staked_amount, self_staked_amount: self_staked} ->
amount = Decimal.to_float(staked_amount)
%{total_staked_amount: total_staked_amount, self_staked_amount: self_staked} ->
amount = Decimal.to_float(total_staked_amount)
self = Decimal.to_float(self_staked)
self / amount * 100
end
Expand Down