Skip to content

Commit b55b214

Browse files
authored
M/tezos bakers info (trustwallet#1954)
* Update baker fee * Add Tezos bakers staking info * remote temp * remove dub * rm
1 parent 6526b64 commit b55b214

File tree

8 files changed

+346
-39
lines changed

8 files changed

+346
-39
lines changed

blockchains/tezos/validators/list.json

+272-34
Large diffs are not rendered by default.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"arrange:all": "npm run cleanup && ts-node ./script/arrange_files",
1414
"gen:list": "npm run cleanup && ts-node ./script/gen_list",
1515
"gen:info": "npm run cleanup && ts-node ./script/gen_info",
16+
"gen:validators:tezos": "npm run cleanup && ts-node ./script/gen_validators_tezos",
1617
"resize": "npm run cleanup && ts-node ./script/resize_images",
1718
"map:cmc": "ts-node ./pricing/coinmarketcap/script",
1819
"magic": "npm run update:bep2 && npm run checksum && npm run resize && npm run gen:list && npm t"

script/gen_validators_tezos.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const axios = require('axios')
2+
import {
3+
getChainValidatorsList,
4+
getChainValidatorsListPath,
5+
Tezos,
6+
writeJSONToPath
7+
} from "../src/test/helpers";
8+
import { BakingBadBaker } from "../src/test/models";
9+
10+
(async function(){
11+
const bakers: BakingBadBaker[] = await axios.get(`https://api.baking-bad.org/v2/bakers`).then(res => res.data)
12+
const bakersMap: {[key: string]: BakingBadBaker} = bakers.reduce((acm, val) => {
13+
acm[val.address] = val
14+
return acm
15+
}, {})
16+
17+
const newbakers = getChainValidatorsList(Tezos).reduce((acm, val) => {
18+
if (!(val.id in bakersMap)) {
19+
console.log(val.id)
20+
return acm
21+
}
22+
const bakerInfo = bakersMap[val.id]
23+
24+
val.payout.commission = Number((bakerInfo.fee * 100).toFixed(2))
25+
val.payout.payoutDelay = bakerInfo.payoutDelay
26+
val.payout.payoutPeriod = bakerInfo.payoutPeriod
27+
28+
val["staking"] = {
29+
freeSpace:Number((bakerInfo.freeSpace).toFixed(0)),
30+
minDelegation: bakerInfo.minDelegation,
31+
openForDelegation: bakerInfo.openForDelegation
32+
}
33+
acm.push(val)
34+
return acm
35+
}, [])
36+
37+
writeJSONToPath(getChainValidatorsListPath(Tezos), newbakers)
38+
})()

src/test/helpers.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ export const stakingChains = [Tezos, Cosmos, IoTeX, Tron, Waves, Kava, Terra]
3131

3232
export const logoName = `logo`
3333
export const infoName = `info`
34+
export const listName = `list`
3435

3536
export const logoExtension = "png"
3637
export const jsonExtension = "json"
3738

3839
const whiteList = `whitelist.${jsonExtension}`
3940
const blackList = `blacklist.${jsonExtension}`
4041

42+
const validatorsList = `${listName}.${jsonExtension}`
43+
4144
export const logo = `${logoName}.${logoExtension}`
4245
export const info = `${infoName}.${jsonExtension}`
4346

47+
4448
export const root = './'
4549
export const chainsFolderPath = path.join(process.cwd(), '/blockchains')
4650
export const pricingFolderPath = path.join(process.cwd(), '/pricing')
@@ -63,6 +67,7 @@ export const getChainAssetsList = (chain: string): string[] => readDirSync(getCh
6367
export const getChainValidatorsPath = (chain: string): string => `${chainsFolderPath}/${chain}/validators`
6468
export const getChainValidatorsAssets = (chain: string): string[] => readDirSync(getChainValidatorsAssetsPath(chain))
6569
export const getChainValidatorsListPath = (chain: string): string => `${(getChainValidatorsPath(chain))}/list.${jsonExtension}`
70+
export const getChainValidatorsList = (chain: string): ValidatorModel[] => JSON.parse(readFileSync(`${(getChainValidatorsPath(chain))}/${validatorsList}`))
6671
export const getChainValidatorsAssetsPath = (chain: string): string => `${getChainValidatorsPath(chain)}/assets`
6772
export const getChainValidatorAssetLogoPath = (chain: string, asset: string): string => `${getChainValidatorsAssetsPath(chain)}/${asset}/${logo}`
6873
export const getChainWhitelistPath = (chain: string): string => `${chainsFolderPath}/${chain}/${whiteList}`
@@ -90,6 +95,7 @@ export const isChainInfoExistSync = (chain: string): boolean => isPathExistsSync
9095
export const isChainAssetInfoExistSync = (chain: string, address: string) => isPathExistsSync(getChainAssetInfoPath(chain, address))
9196
export const readFileSync = (path: string) => fs.readFileSync(path, 'utf8')
9297
export const writeFileSync = (path: string, str: string) => fs.writeFileSync(path, str)
98+
export const writeJSONToPath = (path: string, data: any) => fs.writeFileSync(path, JSON.stringify(data, null, 4))
9399

94100
export const isLowerCase = (str: string): boolean => str.toLowerCase() === str
95101
export const isUpperCase = (str: string): boolean => str.toUpperCase() === str

src/test/index.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
getChainValidatorsListPath,
1818
getChainWhitelistPath,
1919
getChainAssetsList,
20+
getChainValidatorsList,
2021
isChecksum,
21-
isChainAssetInfoExistSync,
2222
isLogoDimentionOK,
2323
isLogoSizeOK,
2424
isLowerCase,
@@ -34,7 +34,6 @@ import {
3434
readFileSync,
3535
rootDirAllowedFiles,
3636
stakingChains,
37-
Solana
3837
} from "./helpers"
3938
import { ValidatorModel } from "./models";
4039
import { getHandle } from "../../script/gen_info";
@@ -152,13 +151,13 @@ describe(`Test "blockchains" folder`, () => {
152151
})
153152

154153
stakingChains.forEach(chain => {
155-
const listPath = getChainValidatorsListPath(chain)
156-
const validatorsList = JSON.parse(readFileSync(listPath))
154+
const validatorsListPath = getChainValidatorsListPath(chain)
155+
const validatorsList = getChainValidatorsList(chain)
157156

158157
test(`Chain ${chain} validator must have correct structure and valid JSON format`, () => {
159158
validatorsList.forEach((val: ValidatorModel) => {
160159
expect(isValidatorHasAllKeys(val), `Some key and/or type missing for validator ${JSON.stringify(val)}`).toBe(true)
161-
expect(isValidJSON(listPath), `Not valid json file at path ${listPath}`).toBe(true)
160+
expect(isValidJSON(validatorsListPath), `Not valid json file at path ${validatorsListPath}`).toBe(true)
162161
})
163162
})
164163

src/test/models.ts

+25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ export interface ValidatorModel {
33
name: string,
44
description: string,
55
website: string,
6+
staking: Staking
7+
payout: Payout
8+
}
9+
10+
interface Staking {
11+
freeSpace: number,
12+
minDelegation: number
13+
openForDelegation: boolean
14+
}
15+
16+
interface Payout {
17+
commission: number // in %
18+
payoutDelay: number // in cycles
19+
payoutPeriod: number
620
}
721

822
// Minimal property requirements for asset info file
@@ -56,4 +70,15 @@ export enum PlatformType {
5670
TRON = "TRON",
5771
OMNI = "Omni",
5872
VeChain = "VeChain"
73+
}
74+
75+
export interface BakingBadBaker {
76+
address: string,
77+
freeSpace: number
78+
// serviceHealth: string // active or Dead is a working baker who was a public baker but for some reason stopped paying his delegators, Closed is a permanently closed service (we store them for historical purposes only
79+
fee: number
80+
minDelegation: number
81+
openForDelegation: boolean
82+
payoutDelay: number
83+
payoutPeriod: number
5984
}

0 commit comments

Comments
 (0)