Skip to content

Commit

Permalink
Merge pull request #4 from eoscostarica/refactor-src-code
Browse files Browse the repository at this point in the history
Refactor src code
  • Loading branch information
xavier506 authored Sep 26, 2022
2 parents b5b30bf + 89f0731 commit 7bb490e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ EOS_PAYER_PERMISION = "resourcebot"
EOS_PAYER_PRIVATE_KEY = "5..."
EOS_WATCH_ACCOUNT = "genesis.eden"
EOS_POWERUP_THRESHOLD = 10000
EOS_POWERUP_AMOUNT = 0.1
EOS_NET_FRAC = 5555555555
EOS_CPU_FRAC = 5555555555
EOS_POWERUP_AMOUNT = 0.1
2 changes: 2 additions & 0 deletions src/config/eos.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ module.exports = {
pvtKey: process.env.EOS_PAYER_PRIVATE_KEY,
watchAccount: process.env.EOS_WATCH_ACCOUNT,
powerUpAmount: process.env.EOS_POWERUP_AMOUNT,
net: process.env.EOS_NET_FRAC,
cpu: process.env.EOS_CPU_FRAC,
threshold: process.env.EOS_POWERUP_THRESHOLD
}
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ async function init() {

const accountStats = await eosUtil.getAccount(account)
const existingCPU = Number(accountStats.cpu_limit.available)
const usedCPU = Number(accountStats.cpu_limit.used)
console.log('Existing CPU:', existingCPU)
console.log('Used CPU:', usedCPU)
const existingNET = Number(accountStats.net_limit.available)
const usedNET = Number(accountStats.net_limit.used)
console.log('Existing NET:', existingNET)
console.log('Used NET:', usedNET)
console.log('Current CPU Usage Percentage: ', (usedCPU/existingCPU)*100, '%')

if (existingCPU > eosConfig.threshold) continue
if ((usedCPU/existingCPU) < eosConfig.threshold) continue

console.log('Available CPU is below threshhold of: ', eosConfig.threshold)
console.log('Power Up Amount: ', eosConfig.powerUpAmount + ' EOS')
console.log('NET_frac: ', eosConfig.net)
console.log('CPU_frac: ', eosConfig.cpu)

const transact = await eosUtil
.transact([
Expand All @@ -42,9 +50,9 @@ async function init() {
payer,
receiver: account,
days: 1,
net_frac: 1000,
cpu_frac: 25000,
max_payment: eosConfig.powerUpAmount + '.0000 EOS'
net_frac: eosConfig.net,
cpu_frac: eosConfig.cpu,
max_payment: eosConfig.powerUpAmount + ' EOS'
}
}
])
Expand Down

0 comments on commit 7bb490e

Please sign in to comment.