ORA
Ask or search…
K
Links

Develop Guide

Guide on coding CLE.

Quickstart

CLE Configuration (cle.yaml)

cle.yaml defines the configuration of a CLE.
It specifies information including:
  • data source
  • target blockchain network
  • target smart contract address
  • target event
  • event handler
An example of cle.yaml:
specVersion: 0.0.2
apiVersion: 0.0.2
name: eg_event
description: "This demo cle shows 3 ways to access / filter out source events."
dataSources:
- kind: ethereum
network: sepolia
event:
- address: '0xa60ecf32309539dd84f27a9563754dca818b815e'
events:
- "Sync(uint112,uint112)"
mapping:
language: wasm/assemblyscript
file: ./mapping.ts
handler: handleBlocks
dataDestinations:
- kind: ethereum
network: sepolia
address: "0x0000000000000000000000000000000000000001"
More examples can be found as templates of CLE scaffold.

Supported network with Features

network specifies the dataSource network for data source or dataDestination network for verification contract deployment and CLE publish.
network should follow the format of all lower-case letters (eg. mainnet, or goerli) with the following naming.
Network (ChainID)
Name in YAML
dataSource
dataDestination
CLE Deployment
Ethereum Mainnet
(1)
mainnet
✅ (handleBlocks)
Ethereum Goerli
(5)
goerli
✅ (handleBlocks)
Ethereum Sepolia
(11155111)
sepolia
✅ (handleBlocks)

apiVersion

apiVersion specifies the cle-lib version or any other libraries, used by a CLE, in ZK Oracle including CLE compiler.
apiVersion
cle-lib Version
Notes
0.0.1
0.0.8
Added event as data source, multi-address and multi-sources for data source.
0.0.2
1.0.0
Updated block as data source, block contains both event and account data.

specVersion

specVersion specifies the cle.yaml configuration format version, parsed by ORA Node or other libraries.

CLE Mapping (mapping.ts)

A required function for CLE mapping is handleBlocks.
The mapping.ts with handleBlocks should be structured as follows, and should not be modified in most cases:
// imports
import { require, Bytes, Event, BigInt } from "@ora-io/cle-lib";
// ...import from other local files
// other functions
// ...
// handleBlocks function
export function handleBlocks(blocks: Block[]): Bytes {
// ...core logics
return state;
}

Requirements

  • Function definition of required function must be function handleBlocks(blocks: Block[]): Bytes.
  • Return value of required function must be Bytes. The best practice is to set it as a payload / calldata, so that it can be used with ZK Automation directly.

Access Event Data

  1. 1.
    Define specific contract address and events in cle.yaml.
  2. 2.
    Access specific events in mapping.ts handleBlocks(), after cle.yaml's filtering.
// Option #1: access all (matched) events of the latest block
let events: Event[] = blocks[0].events;
// Option #2: access (matched) events, if with a given account address
let eventsByAcct: Event[] = blocks[0].account(address).events;
// Option #3: access (matched) events, if with a given account address and a given esig
let eventsByAcctEsig: Event[] = blocks[0].account(address).eventsByEsig(esig_sync);

Access Account (storage slot) Data

  1. 1.
    Define specific storage address and slots in cle.yaml.
  2. 2.
    Access specific slots in mapping.ts handleBlocks(), after cle.yaml's filtering.
// get source Account object by address
let acct: Account = blocks[0].account(addr);
// Option #1: access source Slot value by key
let slotValue: Bytes = acct.storage(key);
// Option #2: access source Slot object by key
let slot: Slot = acct.slots[acct.getSlotId(key)];