Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cosmos.directory API for validators/operators #418

Merged
merged 5 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions scripts/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ export class Autostake {

timeStamp('Bot address is', botAddress)

const operator = network.getOperatorByBotAddress(botAddress)
if (!operator) return timeStamp('Not an operator')

if (network.slip44 && network.slip44 !== slip44) {
timeStamp("!! You are not using the preferred derivation path !!")
timeStamp("!! You should switch to the correct path unless you have grants. Check the README !!")
}

const operatorData = network.operators.find(el => el.botAddress === botAddress)

if (!operatorData) return timeStamp('Not an operator')
if (!network.authzSupport) return timeStamp('No Authz support')

network = await Network(data)
Expand All @@ -138,9 +138,6 @@ export class Autostake {
const client = await network.signingClient(wallet)
client.registry.register("/cosmos.authz.v1beta1.MsgExec", MsgExec)

const validators = await network.getValidators()
const operators = network.getOperators(validators)
const operator = network.getOperatorByBotAddress(operators, botAddress)

return {
network,
Expand Down Expand Up @@ -239,7 +236,7 @@ export class Autostake {

const perValidatorReward = parseInt(totalRewards / validators.length)

if (perValidatorReward < client.operator.data.minimumReward) {
if (perValidatorReward < client.operator.minimumReward) {
timeStamp(address, perValidatorReward, client.network.denom, 'reward is too low, skipping')
return
}
Expand Down
16 changes: 10 additions & 6 deletions src/ApyClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ const ApyClient = (chain, rpcUrl, restUrl) => {
const chainApr = await getChainApr(denom);
let validatorApy = {};
for (const [address, validator] of Object.entries(validators)) {
const commission = validator.commission.commission_rates.rate
const operator = operators.find((el) => el.address === address)
const periodPerYear = operator && chain.authzSupport ? operator.runsPerDay() * 365 : 1;
const realApr = chainApr * (1 - commission);
const apy = (1 + realApr / periodPerYear) ** periodPerYear - 1;
validatorApy[address] = apy;
if(validator.jailed || validator.status !== 'BOND_STATUS_BONDED'){
validatorApy[address] = 0
}else{
const commission = validator.commission.commission_rates.rate
const operator = operators.find((el) => el.address === address)
const periodPerYear = operator && chain.authzSupport ? operator.runsPerDay() * 365 : 1;
const realApr = chainApr * (1 - commission);
const apy = (1 + realApr / periodPerYear) ** periodPerYear - 1;
validatorApy[address] = apy;
}
}
return validatorApy;
}
Expand Down
Loading