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

feat(taiko-client): update prover balance check to include bond balance #18092

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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
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
Loading