Skip to content

Commit

Permalink
more info of nominees
Browse files Browse the repository at this point in the history
  • Loading branch information
wuminzhe committed Aug 22, 2023
1 parent 2a8d6ff commit a0f82be
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
14 changes: 11 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ task :update_nominees, [:network_name] do |_t, args|

ring_pool = get_storage(rpc, metadata, 'darwinia_staking', 'ring_pool', nil, nil)
kton_pool = get_storage(rpc, metadata, 'darwinia_staking', 'kton_pool', nil, nil)
nominee_commissions = get_nominee_commissions(rpc, metadata)
collators = get_collators(rpc, metadata)

# 1. Get all nominators with their nominees
# ---------------------------------------
Expand Down Expand Up @@ -147,10 +149,16 @@ task :update_nominees, [:network_name] do |_t, args|
power = calc_power(staking_info[:staked_ring], staking_info[:staked_kton], ring_pool, kton_pool)
[nominee_address, power]
end.to_h
logger.debug JSON.pretty_generate(nominee_powers)

# 5. write to file
# 5. Set the collators committee
# ---------------------------------------
result = nominee_powers.keys.map do |key|
[key, { power: nominee_powers[key], commission: nominee_commissions[key], is_collator: collators.include?(key) }]
end.to_h
logger.debug JSON.pretty_generate(result)

# 6. write to file
# ---------------------------------------
logger.debug "writing #{network_name} nominees to file..."
write_data_to_file(nominee_powers, "#{network_name}-nominees.json")
write_data_to_file(result, "#{network_name}-nominees.json")
end
23 changes: 22 additions & 1 deletion src/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def staked_ring_in_deposits(ledger, deposits)
0
else
# id => deposit
all_deposits = deposits.select { |deposit| deposit[:in_use] == true }.map { |deposit| [deposit[:id], deposit] }.to_h
all_deposits = deposits.select do |deposit|
deposit[:in_use] == true
end.map { |deposit| [deposit[:id], deposit] }.to_h
# all_deposits = deposits.map { |deposit| [deposit[:id], deposit] }.to_h

deposit_ids_in_ledger = ledger[:staked_deposits] # + ledger[:unstaking_deposits]
deposit_ids_in_ledger.reduce(0) do |sum, deposit_id|
Expand Down Expand Up @@ -180,11 +183,29 @@ def get_nominee_power(rpc, metadata, address)
calc_power(total[:staked_ring], total[:staked_kton], ring_pool, kton_pool)
end

def get_nominee_commissions(rpc, metadata)
storages = get_storage(rpc, metadata, 'darwinia_staking', 'collators', nil, nil)
storages.map do |storage|
address = "0x#{storage[:storage_key][-40..]}"
[address, storage[:storage] / 10_000_000]
end.to_h
end

def get_collators(rpc, metadata)
storages = get_storage(rpc, metadata, 'darwinia_staking', 'exposures', nil, nil)
storages.map do |storage|
"0x#{storage[:storage_key][-40..]}"
end
end

# require_relative '../config/config'
# config = get_config
# crab_metadata = JSON.parse(File.read(config[:metadata][:crab]))
# crab_rpc = config[:crab_rpc]

# # collators
# puts collators(crab_rpc, crab_metadata)

# result = get_account_staking_info(
# crab_rpc,
# crab_metadata,
Expand Down
54 changes: 42 additions & 12 deletions src/supply/kton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@ def get_unmigrated_staked_and_unstaking_kton(rpc, metadata)
ledgers =
ScaleRb::HttpClient.get_storage2(
rpc,
"AccountMigration",
"Ledgers",
'AccountMigration',
'Ledgers',
nil,
metadata,
metadata
)
ledgers.reduce(0) do |sum, ledger|
sum + ledger[:storage][:staked_kton] +
staking = ledgers.reduce(0) do |sum, ledger|
sum + ledger[:storage][:staked_kton]
end / 10**18

unstaking = ledgers.reduce(0) do |sum, ledger|
sum +
ledger[:storage][:unstaking_kton].reduce(0) do |sum, item|
sum + item[0] # item[0] is the amount, item[1] is the block number
end
end / 10**18

puts "staked kton(unmigrated): #{staking}"
puts "unstaking kton(unmigrated): #{unstaking}"
staking + unstaking
end

####################################################
# migrated accounts
####################################################
def get_kton_total_insurance(rpc, metadata)
ScaleRb::HttpClient
.get_storage2(rpc, "Assets", "Asset", nil, metadata)
.get_storage2(rpc, 'Assets', 'Asset', nil, metadata)
.find do |item|
item[:storage_key] ==
"0x682a59d51ab9e48a8c8cc418ff9708d2d34371a193a751eea5883e9553457b2e15ffd708b25d8ed5477f01d3f9277c360204000000000000"
'0x682a59d51ab9e48a8c8cc418ff9708d2d34371a193a751eea5883e9553457b2e15ffd708b25d8ed5477f01d3f9277c360204000000000000'
end
.dig(:storage, :supply) / 10**18
end
Expand All @@ -35,15 +43,37 @@ def get_staked_and_unstaking_kton(rpc, metadata)
ledgers =
ScaleRb::HttpClient.get_storage2(
rpc,
"DarwiniaStaking",
"Ledgers",
'DarwiniaStaking',
'Ledgers',
nil,
metadata,
metadata
)
ledgers.reduce(0) do |sum, ledger|
sum + ledger[:storage][:staked_kton] +
staking = ledgers.reduce(0) do |sum, ledger|
sum + ledger[:storage][:staked_kton]
end / 10**18

unstaking = ledgers.reduce(0) do |sum, ledger|
sum +
ledger[:storage][:unstaking_kton].reduce(0) do |sum, item|
sum + item[0] # item[0] is the amount, item[1] is the block number
end
end / 10**18

puts "staked kton: #{staking}"
puts "unstaking kton: #{unstaking}"
staking + unstaking
end

# require 'json'
# require 'scale_rb'
#
# require_relative '../../config/config'
# config = get_config
# metadata = JSON.parse(File.read(config[:metadata][:darwinia]))
# rpc = config[:darwinia_rpc]
#
# total = get_staked_and_unstaking_kton(rpc, metadata)
# puts "total staking kton: #{total}"
#
# untotal = get_unmigrated_staked_and_unstaking_kton(rpc, metadata)
# puts "total staking kton(unmigrated): #{untotal}"

0 comments on commit a0f82be

Please sign in to comment.