with one click
write-contract
// Write production-quality GenLayer intelligent contracts for this intelligent-oracle repo.
// Write production-quality GenLayer intelligent contracts for this intelligent-oracle repo.
Design, deploy, and monitor a GenLayer Intelligent Oracle prediction market from any coding agent. Use when a user wants to create a settled-by-web-evidence prediction market without opening the web UI.
Deploy GenLayer intelligent contracts using the deployment script. User-invoked only.
Write and run fast direct-mode pytest tests for this repo's GenLayer intelligent contracts.
Use the GenLayer CLI to inspect, interact with, and debug this repo's intelligent contracts.
Validate this repo's GenLayer intelligent contracts with the GenVM linter.
Run or design live-environment GenLayer tests for this intelligent-oracle repo.
| name | write-contract |
| description | Write production-quality GenLayer intelligent contracts for this intelligent-oracle repo. |
| allowed-tools | ["Bash","Read","Write","Edit","Grep","Glob"] |
Use this skill for changes under intelligent-contracts/.
This repo has two GenLayer contracts:
IntelligentOracle.py stores prediction-market oracle config and resolves outcomes.IntelligentOracleFactory.py is the registry/factory used by the Next API deploy route and the explorer.Always run:
genvm-lint check intelligent-contracts/*.py
python -m pytest test/ -v
Preserve the public ABI consumed by the app:
__init__(intelligent_oracle_code: str)create_new_prediction_market(...)get_contract_addresses()__init__(prediction_market_id, title, description, potential_outcomes, rules, data_source_domains, resolution_urls, earliest_resolution_date)resolve(evidence_url: str = "")get_dict()get_status()If any of these change, update all of:
src/app/api/bridge/deploy-intelligent-oracle/route.tssrc/lib/genlayer-client.tssrc/lib/genlayer-hooks.tsscripts/deploy.tstest/Production contracts use:
# { "Depends": "py-genlayer:test" }
Direct-mode tests may rewrite that header through test/tools/contracts.py. Do not change test helper behavior unless the direct-mode runner requires it.
DynArray and TreeMap.list or dict fields.DynArray values instead of assigning Python arrays.Example:
class IntelligentOracle(gl.Contract):
prediction_market_id: str
potential_outcomes: DynArray[str]
creator: Address
def __init__(self, prediction_market_id: str, potential_outcomes: list[str]):
self.prediction_market_id = prediction_market_id
for outcome in potential_outcomes:
self.potential_outcomes.append(outcome.strip())
self.creator = gl.message.sender_address
Keep validation aligned with the TypeScript OracleConfig schema:
predictionMarketId, title, description, rules, and earliestResolutionDate.potentialOutcomes.dataSourceDomains or resolutionURLs.Use deterministic code outside nondeterministic blocks. For web and AI calls inside resolve, keep nondeterminism behind GenLayer APIs:
gl.nondet.web.get(...)gl.nondet.exec_prompt(...)gl.eq_principle.prompt_comparative(...) or a custom validator if comparison needs stricter controlDo not move contract AI calls to the root Next API or AI SDK. The migration policy is:
LLM responses must be parsed defensively. Keep JSON extraction narrow and tolerate wrappers, but fail safely:
def _parse_json_dict(json_str: str) -> dict:
if isinstance(json_str, dict):
return json_str
first_brace = json_str.find("{")
last_brace = json_str.rfind("}")
if first_brace == -1 or last_brace == -1:
return {}
json_str = json_str[first_brace : last_brace + 1]
json_str = re.sub(r",(?!\s*?[\{\[\"\'\w])", "", json_str)
return json.loads(json_str)
When changing prompts, keep outputs valid JSON and keep the outcome field constrained to one of the configured outcomes, UNDETERMINED, or ERROR.
Use gl.vm.UserError for expected contract-level reverts. Keep error messages stable when tests or UI may inspect them.
Important existing states:
ActiveResolvedErrorAdd or update direct-mode pytest coverage for:
resolution_urls.get_dict() response shape.Run root verification after contract changes when TypeScript integrations may be affected:
npm run check