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

Open
wants to merge 60 commits into
base: staking
from
Open
Changes from 1 commit
Commits
Show all changes
60 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
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Remove chain based stakes snapshotting porcess

  • Loading branch information
liberumed committed Nov 5, 2019
commit 21dbc70fa926baa575a23e83579151d3b6a0bc13
@@ -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
}

@@ -31,9 +31,7 @@ defmodule Explorer.Staking.ContractReader do
inactive_delegators: {:staking, "poolDelegatorsInactive", [staking_address]},
staked_amount: {:staking, "stakeAmountTotal", [staking_address]},
self_staked_amount: {:staking, "stakeAmount", [staking_address, staking_address]},
block_reward: {:block_reward, "validatorRewardPercent", [staking_address]},
stakers: {:block_reward, "snapshotStakers", [staking_address]},
reward_percents: {:block_reward, "snapshotRewardPercents", [staking_address]}
block_reward: {:block_reward, "validatorRewardPercent", [staking_address]}
]
end

@@ -59,14 +57,6 @@ defmodule Explorer.Staking.ContractReader do
]
end

def pools_snapshot_requests(block_number) do
[staking_addresses: {:block_reward, "snapshotStakingAddresses", [], block_number}]
end

def stakers_snapshot_requests(pool_address, block_number) do
[{pool_address, {:block_reward, "snapshotStakers", [pool_address], block_number}}]
end

def perform_requests(requests, contracts, abi) do
requests
|> generate_requests(contracts)
@@ -11,7 +11,6 @@ defmodule Explorer.Staking.ContractState do
alias Explorer.Chain.Events.{Publisher, Subscriber}
alias Explorer.SmartContract.Reader
alias Explorer.Staking.ContractReader
alias Explorer.Token.{BalanceReader, MetadataRetriever}

@table_name __MODULE__
@table_keys [
@@ -158,11 +157,6 @@ defmodule Explorer.Staking.ContractState do
Enum.map(responses.inactive_delegators, &{pool_address, &1, false})
end)

delegator_rewards =
Enum.into(pool_staking_responses, %{}, fn {pool_address, responses} ->
{pool_address, Enum.into(Enum.zip(responses.stakers, responses.reward_percents), %{})}
end)

delegator_responses =
delegators
|> Enum.map(fn {pool_address, delegator_address, _} ->
@@ -219,27 +213,10 @@ defmodule Explorer.Staking.ContractState do

delegator_entries =
Enum.map(delegator_responses, fn {{pool_address, delegator_address, is_active}, response} ->
staking_response = pool_staking_responses[pool_address]

reward_ratio =
if is_validator[staking_response.mining_address_hash] do
reward_ratio = delegator_rewards[pool_address][delegator_address]

if reward_ratio do
reward_ratio / 10_000
end
else
ratio(
response.stake_amount - response.ordered_withdraw,
staking_response.staked_amount - staking_response.self_staked_amount
) * min(0.7, 1 - staking_response.block_reward / 1_000_000)
end

Map.merge(response, %{
delegator_address_hash: delegator_address,
pool_address_hash: pool_address,
is_active: is_active,
reward_ratio: reward_ratio
is_active: is_active
})
end)

@@ -250,64 +227,11 @@ defmodule Explorer.Staking.ContractState do
timeout: :infinity
})

if token && previous_epoch != global_responses.epoch_number do
update_tokens(token.contract_address_hash, contracts, abi, global_responses.epoch_start_block - 1, block_number)
end

Publisher.broadcast(:staking_update)
end

defp update_tokens(token_contract_address_hash, contracts, abi, last_epoch_block_number, block_number) do
now = DateTime.utc_now()

token_params =
token_contract_address_hash
|> MetadataRetriever.get_functions_of()
|> Map.merge(%{
contract_address_hash: token_contract_address_hash,
type: "ERC-20"
})

addresses =
block_number
|> ContractReader.pools_snapshot_requests()
|> ContractReader.perform_requests(contracts, abi)
|> Map.fetch!(:staking_addresses)
|> Enum.flat_map(&ContractReader.stakers_snapshot_requests(&1, last_epoch_block_number))
|> ContractReader.perform_requests(contracts, abi)
|> Map.values()
|> List.flatten()
|> Enum.uniq()

balance_params =
addresses
|> Enum.map(
&%{
token_contract_address_hash: token_contract_address_hash,
address_hash: &1,
block_number: block_number
}
)
|> BalanceReader.get_balances_of()
|> Enum.zip(addresses)
|> Enum.map(fn {{:ok, balance}, address} ->
%{
address_hash: address,
token_contract_address_hash: token_contract_address_hash,
block_number: block_number,
value: balance,
value_fetched_at: now
}
end)

{:ok, _} =
Chain.import(%{
addresses: %{params: Enum.map(addresses, &%{hash: &1}), on_conflict: :nothing},
address_current_token_balances: %{params: balance_params},
tokens: %{params: [token_params]}
})
end

defp get_token(address) do
with {:ok, address_hash} <- Chain.string_to_address_hash(address),
{:ok, token} <- Chain.token_from_address_hash(address_hash) do
@@ -139,20 +139,6 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isSnapshotting",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
@@ -223,20 +209,6 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "snapshotTotalStakeAmount",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
@@ -530,58 +502,6 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_validatorStakingAddress",
"type": "address"
}
],
"name": "snapshotRewardPercents",
"outputs": [
{
"name": "result",
"type": "uint256[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_validatorStakingAddress",
"type": "address"
}
],
"name": "snapshotStakers",
"outputs": [
{
"name": "result",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "snapshotStakingAddresses",
"outputs": [
{
"name": "",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.