Rename staked_amount field to total_staked_amount

staking
Eduard Sachava 5 years ago committed by Victor Baranov
parent 90710500a9
commit 303ece8180
  1. 2
      apps/block_scout_web/assets/js/pages/stakes/claim_withdrawal.js
  2. 2
      apps/block_scout_web/assets/js/pages/stakes/make_stake.js
  3. 4
      apps/block_scout_web/assets/js/pages/stakes/move_stake.js
  4. 2
      apps/block_scout_web/assets/js/pages/stakes/withdraw_stake.js
  5. 10
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  6. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex
  7. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_validator_info.html.eex
  8. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_progress.html.eex
  9. 6
      apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex
  10. 4
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex
  11. 16
      apps/explorer/lib/explorer/chain/staking_pool.ex
  12. 2
      apps/explorer/lib/explorer/staking/contract_reader.ex
  13. 6
      apps/explorer/lib/explorer/staking/contract_state.ex
  14. 16
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex
  15. 2
      apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs
  16. 2
      apps/explorer/priv/repo/migrations/20191024135401_add_snapshotting_fields_to_staking_pools.exs
  17. 2
      apps/explorer/test/support/factory.ex

@ -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

@ -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'),
{

@ -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'),

@ -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'),
{

@ -132,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}
@ -178,7 +178,7 @@ 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
@ -186,7 +186,7 @@ defmodule BlockScoutWeb.StakesChannel 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
}
@ -216,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,
@ -242,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}

@ -15,7 +15,7 @@
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>

@ -35,7 +35,7 @@
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,

@ -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>

@ -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

@ -134,9 +134,9 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
staked_ratio: fragment("EXCLUDED.staked_ratio"),
snapshotted_staked_ratio: pool.snapshotted_staked_ratio,
self_staked_amount: fragment("EXCLUDED.self_staked_amount"),
staked_amount: fragment("EXCLUDED.staked_amount"),
total_staked_amount: fragment("EXCLUDED.total_staked_amount"),
snapshotted_self_staked_amount: pool.snapshotted_self_staked_amount,
snapshotted_staked_amount: pool.snapshotted_staked_amount,
snapshotted_total_staked_amount: pool.snapshotted_total_staked_amount,
ban_reason: fragment("EXCLUDED.ban_reason"),
was_banned_count: fragment("EXCLUDED.was_banned_count"),
was_validator_count: fragment("EXCLUDED.was_validator_count"),

@ -28,9 +28,9 @@ defmodule Explorer.Chain.StakingPool do
staked_ratio: Decimal.t(),
snapshotted_staked_ratio: Decimal.t(),
self_staked_amount: Decimal.t(),
staked_amount: Decimal.t(),
total_staked_amount: Decimal.t(),
snapshotted_self_staked_amount: Decimal.t(),
snapshotted_staked_amount: Decimal.t(),
snapshotted_total_staked_amount: Decimal.t(),
ban_reason: String.t(),
was_banned_count: integer,
was_validator_count: integer,
@ -38,13 +38,13 @@ defmodule Explorer.Chain.StakingPool do
}
@attrs ~w(
is_active delegators_count staked_amount self_staked_amount snapshotted_staked_amount snapshotted_self_staked_amount is_validator
is_active delegators_count total_staked_amount self_staked_amount snapshotted_total_staked_amount snapshotted_self_staked_amount is_validator
was_validator_count is_banned are_delegators_banned ban_reason was_banned_count banned_until banned_delegators_until likelihood
staked_ratio snapshotted_staked_ratio staking_address_hash mining_address_hash block_reward_ratio
is_unremovable
)a
@req_attrs ~w(
is_active delegators_count staked_amount self_staked_amount is_validator
is_active delegators_count total_staked_amount self_staked_amount is_validator
was_validator_count is_banned was_banned_count banned_until
staking_address_hash mining_address_hash is_unremovable
)a
@ -63,9 +63,9 @@ defmodule Explorer.Chain.StakingPool do
field(:staked_ratio, :decimal)
field(:snapshotted_staked_ratio, :decimal)
field(:self_staked_amount, :decimal)
field(:staked_amount, :decimal)
field(:total_staked_amount, :decimal)
field(:snapshotted_self_staked_amount, :decimal)
field(:snapshotted_staked_amount, :decimal)
field(:snapshotted_total_staked_amount, :decimal)
field(:ban_reason, :string)
field(:was_banned_count, :integer)
field(:was_validator_count, :integer)
@ -104,8 +104,8 @@ defmodule Explorer.Chain.StakingPool do
defp validate_staked_amount(%{valid?: false} = c), do: c
defp validate_staked_amount(changeset) do
if get_field(changeset, :staked_amount) < get_field(changeset, :self_staked_amount) do
add_error(changeset, :staked_amount, "must be greater than self_staked_amount")
if get_field(changeset, :total_staked_amount) < get_field(changeset, :self_staked_amount) do
add_error(changeset, :total_staked_amount, "must be greater than self_staked_amount")
else
changeset
end

@ -32,7 +32,7 @@ defmodule Explorer.Staking.ContractReader do
is_active: {:staking, "isPoolActive", [staking_address]},
active_delegators: {:staking, "poolDelegators", [staking_address]},
inactive_delegators: {:staking, "poolDelegatorsInactive", [staking_address]},
staked_amount: {:staking, "stakeAmountTotal", [staking_address]},
total_staked_amount: {:staking, "stakeAmountTotal", [staking_address]},
self_staked_amount: {:staking, "stakeAmount", [staking_address, staking_address]},
block_reward: {:block_reward, "validatorRewardPercent", [staking_address]}
]

@ -183,7 +183,7 @@ defmodule Explorer.Staking.ContractState do
ContractReader.pool_reward_requests([
global_responses.epoch_number,
response.self_staked_amount,
response.staked_amount,
response.total_staked_amount,
1000_000
])
end)
@ -200,7 +200,7 @@ defmodule Explorer.Staking.ContractState do
global_responses.epoch_number,
response.stake_amount,
staking_response.self_staked_amount,
staking_response.staked_amount,
staking_response.total_staked_amount,
1000_000
])
end)
@ -227,7 +227,7 @@ defmodule Explorer.Staking.ContractState do
Map.take(staking_response, [
:mining_address_hash,
:is_active,
:staked_amount,
:total_staked_amount,
:self_staked_amount
])
)

@ -63,7 +63,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
ContractReader.pool_reward_requests([
global_responses.epoch_number,
response.snapshotted_self_staked_amount,
response.snapshotted_staked_amount,
response.snapshotted_total_staked_amount,
1000_000
])
end)
@ -80,7 +80,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
global_responses.epoch_number,
response.stake_amount,
staking_response.snapshotted_self_staked_amount,
staking_response.snapshotted_staked_amount,
staking_response.snapshotted_total_staked_amount,
1000_000
])
end)
@ -99,9 +99,9 @@ defmodule Explorer.Staking.StakeSnapshotting do
}
|> Map.merge(
Map.take(staking_response, [
:snapshotted_staked_amount,
:snapshotted_total_staked_amount,
:snapshotted_self_staked_amount,
:staked_amount,
:total_staked_amount,
:self_staked_amount,
:mining_address_hash
])
@ -142,9 +142,9 @@ defmodule Explorer.Staking.StakeSnapshotting do
defp pool_staking_requests(staking_address, block_number) do
[
snapshotted_staked_amount: {:staking, "stakeAmountTotal", [staking_address], block_number - 1},
snapshotted_total_staked_amount: {:staking, "stakeAmountTotal", [staking_address], block_number - 1},
snapshotted_self_staked_amount: {:staking, "stakeAmount", [staking_address, staking_address], block_number - 1},
staked_amount: {:staking, "stakeAmountTotal", [staking_address]},
total_staked_amount: {:staking, "stakeAmountTotal", [staking_address]},
self_staked_amount: {:staking, "stakeAmount", [staking_address, staking_address]},
mining_address_hash: {:validator_set, "miningByStakingAddress", [staking_address]},
active_delegators: {:staking, "poolDelegators", [staking_address]},
@ -186,9 +186,9 @@ defmodule Explorer.Staking.StakeSnapshotting do
delegators_count: fragment("EXCLUDED.delegators_count"),
snapshotted_staked_ratio: fragment("EXCLUDED.snapshotted_staked_ratio"),
self_staked_amount: fragment("EXCLUDED.self_staked_amount"),
staked_amount: fragment("EXCLUDED.staked_amount"),
total_staked_amount: fragment("EXCLUDED.total_staked_amount"),
snapshotted_self_staked_amount: fragment("EXCLUDED.snapshotted_self_staked_amount"),
snapshotted_staked_amount: fragment("EXCLUDED.snapshotted_staked_amount"),
snapshotted_total_staked_amount: fragment("EXCLUDED.snapshotted_total_staked_amount"),
is_active: pool.is_active,
is_banned: pool.is_banned,
is_validator: pool.is_validator,

@ -6,7 +6,7 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do
add(:is_active, :boolean, default: false, null: false)
add(:is_deleted, :boolean, default: false, null: false)
add(:delegators_count, :integer)
add(:staked_amount, :numeric, precision: 100)
add(:total_staked_amount, :numeric, precision: 100)
add(:self_staked_amount, :numeric, precision: 100)
add(:is_validator, :boolean, default: false, null: false)
add(:was_validator_count, :integer)

@ -3,7 +3,7 @@ defmodule Explorer.Repo.Migrations.AddSnapshottingFieldsToStakingPools do
def change do
alter table(:staking_pools) do
add(:snapshotted_staked_amount, :numeric, precision: 100)
add(:snapshotted_total_staked_amount, :numeric, precision: 100)
add(:snapshotted_self_staked_amount, :numeric, precision: 100)
add(:snapshotted_staked_ratio, :decimal, precision: 5, scale: 2)
end

@ -663,7 +663,7 @@ defmodule Explorer.Factory do
is_active: true,
is_banned: false,
is_validator: true,
staked_amount: wei_per_ether * 500,
total_staked_amount: wei_per_ether * 500,
self_staked_amount: wei_per_ether * 300,
was_banned_count: 0,
was_validator_count: 1

Loading…
Cancel
Save