diff --git a/Rakefile b/Rakefile index 643603f..537a0b8 100644 --- a/Rakefile +++ b/Rakefile @@ -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 # --------------------------------------- @@ -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 diff --git a/src/account.rb b/src/account.rb index 1f2597c..f00c17b 100644 --- a/src/account.rb +++ b/src/account.rb @@ -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| @@ -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, diff --git a/src/supply/kton.rb b/src/supply/kton.rb index dcad8c0..d0ed490 100644 --- a/src/supply/kton.rb +++ b/src/supply/kton.rb @@ -5,17 +5,25 @@ 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 #################################################### @@ -23,10 +31,10 @@ def get_unmigrated_staked_and_unstaking_kton(rpc, metadata) #################################################### 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 @@ -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}"