Smart Contract API¶
Complete reference for the TesseractSimple.vy smart contract.
Contract Overview¶
| Property | Value |
|---|---|
| Contract | TesseractSimple.vy |
| Language | Vyper 0.3.10 |
| Size | 7,276 bytes compiled |
| Functions | 18 total |
Data Structures¶
State Enum¶
enum State:
EMPTY # 0: Transaction doesn't exist
BUFFERED # 1: Transaction stored
READY # 2: Ready for execution
EXECUTED # 3: Successfully executed
Transaction Struct¶
struct Transaction:
origin_rollup: address # Source rollup address
target_rollup: address # Destination rollup address
payload: Bytes[512] # Transaction data (max 512 bytes)
dependency_tx_id: bytes32 # Required dependency transaction
timestamp: uint256 # Execution timestamp
state: State # Current transaction state
Core Functions¶
buffer_transaction¶
Buffer a new cross-rollup transaction.
@external
def buffer_transaction(
tx_id: bytes32,
origin_rollup: address,
target_rollup: address,
payload: Bytes[512],
dependency_tx_id: bytes32,
timestamp: uint256
)
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Unique transaction identifier |
origin_rollup |
address |
Origin rollup address |
target_rollup |
address |
Target rollup address |
payload |
Bytes[512] |
Transaction data (max 512 bytes) |
dependency_tx_id |
bytes32 |
Dependency ID (empty if none) |
timestamp |
uint256 |
Execution timestamp |
Access: Authorized operators only
Gas: ~80,000
Events: TransactionBuffered
Reverts:
"Not authorized"- Caller is not an operator"Invalid transaction ID"- tx_id is empty"Invalid origin rollup"- origin_rollup is zero address"Invalid target rollup"- target_rollup is zero address"Origin and target must be different"- Same address"Timestamp cannot be in the past"- timestamp < block.timestamp"Transaction already exists"- tx_id already used
Example:
resolve_dependency¶
Check and resolve transaction dependencies.
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Transaction to resolve |
Access: Authorized operators only
Gas: ~40,000
Events: TransactionReady or TransactionFailed
Logic:
- Verify transaction is in BUFFERED state
- Check if current time >= transaction timestamp
- Check if current time <= timestamp + coordination_window
- Verify dependency is READY or EXECUTED (if any)
- Update state to READY if all conditions met
Reverts:
"Not authorized"- Caller is not an operator"Transaction not in buffered state"- Wrong state
Example:
# Resolve after timestamp passes
contract.functions.resolve_dependency(tx_id).transact({'from': operator})
# Check result
state = contract.functions.get_transaction_state(tx_id).call()
mark_executed¶
Mark a transaction as executed.
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Transaction identifier |
Access: Authorized operators only
Gas: ~25,000
Requirements:
- Transaction must be in READY state
- Caller must be authorized operator
Reverts:
"Not authorized"- Caller is not an operator"Transaction not ready"- Not in READY state
Example:
# Mark as executed after execution on target chain
contract.functions.mark_executed(tx_id).transact({'from': operator})
View Functions¶
get_transaction_state¶
Get current transaction state.
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Transaction identifier |
Returns: State enum value (0-3)
Example:
state = contract.functions.get_transaction_state(tx_id).call()
# 0 = EMPTY, 1 = BUFFERED, 2 = READY, 3 = EXECUTED
is_transaction_ready¶
Check if transaction is ready for execution.
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Transaction identifier |
Returns: bool - True if state is READY and timestamp has passed
Example:
is_ready = contract.functions.is_transaction_ready(tx_id).call()
if is_ready:
# Safe to execute
pass
get_transaction_details¶
Get complete transaction details.
@view
@external
def get_transaction_details(tx_id: bytes32) -> (address, address, bytes32, uint256, State)
Parameters:
| Name | Type | Description |
|---|---|---|
tx_id |
bytes32 |
Transaction identifier |
Returns: Tuple containing:
| Index | Type | Description |
|---|---|---|
| 0 | address |
origin_rollup |
| 1 | address |
target_rollup |
| 2 | bytes32 |
dependency_tx_id |
| 3 | uint256 |
timestamp |
| 4 | State |
state |
Example:
details = contract.functions.get_transaction_details(tx_id).call()
origin, target, dependency, timestamp, state = details
Administrative Functions¶
add_operator¶
Add an authorized operator.
Access: Owner only
Gas: ~25,000
Reverts:
"Only owner can add operators""Invalid operator address"- Zero address
remove_operator¶
Remove operator authorization.
Access: Owner only
Gas: ~25,000
Reverts:
"Only owner can remove operators"
set_coordination_window¶
Configure coordination timing.
Parameters:
| Name | Type | Description |
|---|---|---|
window |
uint256 |
Window duration in seconds (5-300) |
Access: Owner only
Gas: ~25,000
Reverts:
"Only owner can set window""Window must be between 5 and 300 seconds"
Public Storage Variables¶
owner¶
Returns the contract owner address.
authorized_operators¶
Check if an address is an authorized operator.
transactions¶
Get transaction by ID.
transaction_count¶
Total number of transactions buffered.
coordination_window¶
Current coordination window in seconds (default: 30).
Events¶
TransactionBuffered¶
Emitted when a new transaction is buffered.
event TransactionBuffered:
tx_id: indexed(bytes32)
origin_rollup: indexed(address)
target_rollup: indexed(address)
timestamp: uint256
TransactionReady¶
Emitted when dependencies are resolved.
TransactionFailed¶
Emitted when resolution fails.
Error Messages¶
| Message | Function | Cause |
|---|---|---|
"Not authorized" |
buffer, resolve, execute | Caller not operator |
"Only owner can add operators" |
add_operator | Non-owner caller |
"Only owner can remove operators" |
remove_operator | Non-owner caller |
"Only owner can set window" |
set_coordination_window | Non-owner caller |
"Invalid transaction ID" |
buffer_transaction | Empty tx_id |
"Invalid origin rollup" |
buffer_transaction | Zero address |
"Invalid target rollup" |
buffer_transaction | Zero address |
"Origin and target must be different" |
buffer_transaction | Same addresses |
"Timestamp cannot be in the past" |
buffer_transaction | Past timestamp |
"Transaction already exists" |
buffer_transaction | Duplicate tx_id |
"Transaction not in buffered state" |
resolve_dependency | Wrong state |
"Transaction not ready" |
mark_executed | Not READY state |
"Window must be between 5 and 300 seconds" |
set_coordination_window | Out of range |
Gas Costs¶
| Operation | Gas Usage |
|---|---|
buffer_transaction |
~80,000 |
resolve_dependency |
~40,000 |
mark_executed |
~25,000 |
add_operator |
~25,000 |
remove_operator |
~25,000 |
set_coordination_window |
~25,000 |
| View functions | ~3,000-5,000 |
Next Steps¶
- Python SDK - High-level Python interface
- Events - Event monitoring guide
- Examples - Working examples