Skip to content

Commit

Permalink
Ana/livepeer integrate new api (#224)
Browse files Browse the repository at this point in the history
* integrate new api

* delete selfstake. add warning for active field

* speed up. query getglobal only once

* rename back to lpt conversion

* delete second globals
  • Loading branch information
Bitcoinera authored and jbibla committed Dec 20, 2019
1 parent ad8b90a commit d94920b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
4 changes: 2 additions & 2 deletions data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"id": "livepeer-mainnet",
"title": "Livepeer",
"chain_id": "ethereum-1",
"api_url": "https://api.thegraph.com/subgraphs/name/livepeer/livepeer",
"rpc_url": "wss://api.thegraph.com/subgraphs/name/livepeer/livepeer",
"api_url": "https://livepeer-mainnet.lunie.io/",
"rpc_url": "wss://livepeer-mainnet.lunie.io/websocket",
"bech32_prefix": "0x",
"testnet": false,
"feature_session": false,
Expand Down
47 changes: 37 additions & 10 deletions lib/livepeerV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,63 @@ class LivepeerV0API extends GraphQLDataSource {
const totalStakedTokens = transcoders.reduce((sum, validator) => {
return BigNumber(sum).plus(BigNumber(validator.totalStake))
}, BigNumber(0))
// LPT is represented by 1:1000000000000000000 internally
// LPT and all Ethereum units are represented by 1:1000000000000000000 internally
return totalStakedTokens.div(LPT_CONVERSION)
}

async getAllValidators() {
const inactiveTranscoders = await this.getValidators(false)
const activeTranscoders = await this.getValidators(true)
const globals = await this.getGlobalValues()
const totalStakedTokens = await this.getTotalStakedTokens(activeTranscoders)
const transcoders = inactiveTranscoders.concat(activeTranscoders)
return transcoders.map(validator =>
this.reducers.validatorReducer(
this.networkId,
validator,
totalStakedTokens
totalStakedTokens,
globals
)
)
}

async getSelfStake() {
return undefined
async getSelfStake(validator) {
const { delegators } = await this.query(
`
delegators(where:{id:"${validator.operatorAddress}"}) {
id
pendingStake
}
`
)
return BigNumber(delegators[0].pendingStake).div(LPT_CONVERSION)
}

async getGlobalValues() {
const { protocol } = await this.query(
`
protocol {
inflation
inflationChange
totalTokenSupply
totalBondedToken
}
`
)
return protocol
}

getExpectedReturns(validator) {
async getExpectedReturns(validator) {
return this.reducers.livepeerExpectedRewardsReducer({
rewardCut: validator.rewardCut,
// assuming following fixed values which is not true and needs to be queried via the future protocol query
inflation: 1172, // TODO change to API call
inflationChange: 3, // TODO change to API call
totalSupply: '17919760877408440511808797', // TODO change to API call
totalStaked: '11426550355221975909835117' // TODO change to API call
inflation: validator.globals.inflation,
inflationChange: validator.globals.inflationChange,
totalSupply: BigNumber(validator.globals.totalTokenSupply).div(
LPT_CONVERSION
),
totalStaked: BigNumber(validator.globals.totalBondedToken).div(
LPT_CONVERSION
)
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/reducers/livepeerV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ function expectedRewardsPerToken({
return roi
}

function validatorReducer(networkId, validator, totalStakedTokens) {
function validatorReducer(networkId, validator, totalStakedTokens, globals) {
return {
networkId,
operatorAddress: validator.id,
tokens: bigNumberReducer(validator.totalStake),
selfStake: bigNumberReducer(validator.pendingStake), // TODO (when we have the new API up and running)
commission: validatorCommissionReducer(validator.rewardCut),
status: validatorStatusEnumReducer(validator.active),
status: validatorStatusEnumReducer(validator.active), // this field is going to disappear the next 9th of January. I'm looking into transitioning
statusDetailed: validator.status, // Registered/Unregistered,
rewardCut: validator.rewardCut,
votingPower: votingPowerReducer(validator, totalStakedTokens)
votingPower: votingPowerReducer(validator, totalStakedTokens),
globals
}
}

Expand Down

0 comments on commit d94920b

Please sign in to comment.