Skip to content

Commit

Permalink
fix: more rpc friendly refill
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Mar 20, 2024
1 parent 49cc644 commit fca7961
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/lib/refill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export const refill = async (): Promise<void> => {

await initOrderBook()

await Promise.all(players.map(async (player) => {
/* eslint-disable no-await-in-loop */
for (const player of players) {
if (dayjs().isAfter(player.nextRefill)) {
await refillPlayer(new PublicKey(player.publicKey), optimalRefillStrategy)
}

const fleets = await getAllFleetsForUserPublicKey(connection, new PublicKey(player.publicKey), fleetProgram)
const [burnRate, price, balance] = await Promise.all([
getDailyBurnRate(fleets),
getResourcePrices(),
player.getBalance()
])
const burnRate = await getDailyBurnRate(fleets)
const price = getResourcePrices()
const balance = await player.getBalance()

const burnPerDay =
max(burnRate.food.mul(price.food).add(
burnRate.fuel.mul(price.fuel)).add(
Expand All @@ -44,5 +44,6 @@ export const refill = async (): Promise<void> => {
logger.info(`Balance: ${balance.toFixed(AD)} ATLAS / Burn ${burnPerDay.toFixed(AD)} ATLAS per day / Credit for ${dayjs.duration(balanceTime.toNumber(), 'day').humanize(false)}`)
logger.info(`Total Tipped: ${(await player.totalTipped()).toFixed(AD)}`)
logger.info('-----------------------------------------------------')
}))
}
/* eslint-enable no-await-in-loop */
}

0 comments on commit fca7961

Please sign in to comment.