Last active
August 16, 2019 04:15
-
-
Save phoorichet/a347bebcb2a4bfe7965ea5f0fc9e0e8a to your computer and use it in GitHub Desktop.
List the total rewards amount delegator withdrawn from validators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios") | |
const BN = require("bignumber.js") | |
let page = 1 | |
// map[validator] => amount | |
const validators = new Map() | |
// add to url query `validator=${wantValidator}` | |
const wantValidator = 'default:0xa5b2C08c1DcD58d819317b79CbC9b5A8566bDF73' | |
const main = async () => { | |
try { | |
while (true) { | |
console.log("page", page) | |
let url = `https://api.loom.games/delegation/rewards?&state=UNBONDING&lock_time_tier=&from_block&to_block&page=${page}&sort=%2Bcreated_at` | |
const { status, data } = await axios.get(url) | |
if (status != 200 || data.data.length == 0) { | |
break | |
} | |
for (const delgation of data.data) { | |
const amount = BN.BigNumber(delgation.amount) | |
const sum = validators.get(delgation.validator) | |
if (!sum) { | |
validators.set(delgation.validator, amount) | |
} else { | |
validators.set(delgation.validator, sum.plus(amount)) | |
} | |
} | |
page++ | |
} | |
} catch (err) { | |
console.log(err.stack || err) | |
} | |
const denom = BN.BigNumber(1e18) | |
// print out | |
console.log('validator', "|", 'unbonded amount') | |
console.log('---------', "|", '---------------') | |
for (const validator of validators.entries()) { | |
console.log(validator[0], '|', validator[1].dividedBy(denom).toFixed(2)) | |
} | |
} | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ListAllDelegationsCmdV3() *cobra.Command { | |
var flags cli.ContractCallFlags | |
cmd := &cobra.Command{ | |
Use: "list-all-delegations", | |
Short: "display the results of calling list_delegations for all candidates", | |
Example: listAllDelegationsCmdExample, | |
Args: cobra.MinimumNArgs(0), | |
RunE: func(cmd *cobra.Command, args []string) error { | |
var resp dposv3.ListAllDelegationsResponse | |
err := cli.StaticCallContractWithFlags( | |
&flags, DPOSV3ContractName, "ListAllDelegations", | |
&dposv3.ListAllDelegationsRequest{}, &resp, | |
) | |
if err != nil { | |
return err | |
} | |
validators := make(map[string]*loom.BigUInt) | |
for _, listResponse := range resp.ListResponses { | |
for _, delegation := range listResponse.Delegations { | |
if delegation.Index == 0 { | |
validator := "default:" + delegation.Validator.Local.Hex() | |
_, ok := validators[validator] | |
if !ok { | |
validators[validator] = loom.NewBigUIntFromInt(0) | |
} | |
validators[validator] = validators[validator].Add(validators[validator], &delegation.Amount.Value) | |
} | |
} | |
} | |
fmt.Println("validator", "|", "bonded amount") | |
fmt.Println("---------", "|", "------------:") | |
divider := 1000000000000000000 | |
sum := loom.NewBigUIntFromInt(0) | |
zero := loom.NewBigUIntFromInt(0) | |
for k, v := range validators { | |
sum = sum.Add(sum, v) | |
amountInt := zero.Div(v, loom.NewBigUIntFromInt(int64(divider))) | |
fmt.Println(k, "|", amountInt) | |
} | |
amountInt := zero.Div(sum, loom.NewBigUIntFromInt(int64(divider))) | |
fmt.Println("total", "|", amountInt) | |
return nil | |
}, | |
} | |
cli.AddContractStaticCallFlags(cmd.Flags(), &flags) | |
return cmd | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "dpos-rewards", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"axios": "^0.19.0", | |
"bignumber.js": "^9.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of Aug 15, 2018
The amount withdrawn rewards per validator
The amount of current rewards stored on validators