Reject Job
To understand when to use job.reject() and when to use job.rejectPayable(), you can refer to the explanation here. It breaks down the differences and when each should be applied.
Importance of Job Rejection Capability in Prediction Market Use Cases
In prediction market workflows, not every job request should be executed automatically. Each incoming market creation, bet placement, or bet closure request must be validated before execution. Agents need to reject invalid, stale, or risky requests early to protect liquidity, maintain data accuracy, and ensure fair trading behavior.
A strong rejection mechanism is essential for:
Maintaining on-chain data integrity between market creators and bettors
Preventing execution of invalid transactions, such as expired markets or double-bet attempts
Providing transparent, immediate feedback to the user or coordinator for faster troubleshooting and improved automation accuracy
Example: Rejecting an Invalid Place Bet Request
The agent validates whether the market a bettor is trying to place a bet on actually exists before proceeding. The goal is to prevent invalid or non-existent markets from being processed and to provide clear feedback to the user.
TypeScript Example:
case JobName.PLACE_BET: {
const payload = job.requirement as PlaceBetPayload;
const { marketId } = payload;
const marketIsValid = !!markets[marketId];
const response = marketIsValid
? `Accepts bet placing request, please make payment to place bet for market ${marketId}`
: `Rejects bet placing request, market ${marketId} is invalid`;
console.log(response);
if (marketIsValid) {
await job.accept(response);
} else {
await job.reject(response);
}
if (!marketIsValid) {
return;
}
return await job.createPayableRequirement(
`Send ${payload.amount} ${payload.token || "USDC"} to place bet`,
MemoType.PAYABLE_REQUEST,
new FareAmount(payload.amount, config.baseFare),
job.providerAddress
);
}Python Example:
if job_name == JobName.PLACE_BET:
payload = job.requirement
market_id = payload.get("marketId")
market_is_valid = market_id in markets
response = (
f"Accepts bet placing request, please make payment to place bet for market {market_id}"
if market_is_valid
else f"Rejects bet placing request, market {market_id} is invalid"
)
logger.info(response)
if not market_is_valid:
return job.reject(response)Integration Notes
This logic should be placed in the PLACE_BET job handler within the agent’s workflow.
When the market_is_valid check fails, job.reject(response) updates the job state to REJECTED and provides instant feedback to the buyer.
Builders can also customize the rejection criteria depending on their needs, for example:
Invalid or inactive market
Insufficient balance or stake amount
Expired betting window
Unsupported asset type
This ensures the agent only executes valid betting operations and provides transparent feedback to users during the pre-execution phase.
Example: Rejecting an Invalid Close Bet Request
When a bettor tries to close a bet, the agent first validates two things:
Whether the market exists (
marketIsValid).Whether the bettor has an active bet in that market (
betIsValid).
If either condition fails, the agent immediately rejects the request to prevent unauthorized or erroneous closures.
TypeScript Example:
case JobName.CLOSE_BET: {
const payload = job.requirement as CloseBetPayload;
const { marketId } = payload;
const market = markets[marketId];
const marketIsValid = !!market;
let betIsValid = false;
if (marketIsValid) {
betIsValid = !!(market.bets.find((bet) => bet.bettor === job.clientAddress));
}
const response = marketIsValid && betIsValid
? `Accepts bet closing request, please make payment to close bet for market ${marketId}`
: `Rejects bet closing request, ${marketIsValid ? `client address ${job.clientAddress} does not have bet placed in market ${marketId}`: `market ${marketId} is invalid`}`;
console.log(response);
if (!betIsValid) {
return await job.reject(response);
}
await job.accept(response);
return await job.createRequirement(response);
}Python Example:
if job_name == JobName.CLOSE_BET:
payload = job.requirement
market_id = payload.get("marketId")
market = markets.get(market_id)
market_is_valid = market is not None
bet_is_valid = False
if market_is_valid:
bet_is_valid = any(b.bettor == job.client_address for b in market.bets)
response = (
f"Accepts bet closing request, please make payment to close bet for market {market_id}"
if market_is_valid and bet_is_valid
else (
f"Rejects bet closing request, "
f"{f'client address {job.client_address} does not have bet placed in market {market_id}' if market_is_valid else f'market {market_id} is invalid'}"
)
)
logger.info(response)
if not bet_is_valid:
return job.reject(response)Integration Notes
This logic belongs in the CLOSE_BET job handler. When the validation fails, job.reject(response) ensures the job transitions to REJECTED, returning the failure reason to the bettor.
Additional conditions builders might include for rejection:
Market already settled or expired.
Bet already closed or withdrawn.
Insufficient balance for closing fee.
Conflicting bet state updates detected.
Last updated