Skip to content

Commit

Permalink
feat(taiko-client): update prover balance check to include bond balan…
Browse files Browse the repository at this point in the history
…ce (#18092)
  • Loading branch information
lagunovsky authored Sep 16, 2024
1 parent 95c9da2 commit 5d5ca74
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/taiko-client/pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,46 @@ func CheckProverBalance(
"bond", utils.WeiToEther(bond),
)

// Check prover's taiko token balance
balance, err := rpc.TaikoToken.BalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
// Check prover's taiko token bondBalance
bondBalance, err := rpc.TaikoL1.BondBalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
if err != nil {
return false, err
}

// Check prover's taiko token tokenBalance
tokenBalance, err := rpc.TaikoToken.BalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
if err != nil {
return false, err
}

totalBalance := new(big.Int).Add(bondBalance, tokenBalance)
log.Info(
"Prover's wallet taiko token balance",
"balance", utils.WeiToEther(balance),
"bondBalance", utils.WeiToEther(bondBalance),
"tokenBalance", utils.WeiToEther(tokenBalance),
"totalBalance", utils.WeiToEther(totalBalance),
"address", prover.Hex(),
"bond", utils.WeiToEther(bond),
)

if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
if bond.Cmp(allowance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"taikoTokenBalance", utils.WeiToEther(balance),
"Assigned prover does not have required on-chain token allowance",
"allowance", utils.WeiToEther(allowance),
"bond", utils.WeiToEther(bond),
)
return false, nil
}

if bond.Cmp(totalBalance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance",
"totalBalance", utils.WeiToEther(totalBalance),
"bond", utils.WeiToEther(bond),
)
return false, nil
}

return true, nil
}

Expand Down

0 comments on commit 5d5ca74

Please sign in to comment.