Lightecho Oracle - Oracle smart contract for Soroban
Lightecho is a Stellar Oracle for emerging markets data and XLM volatility feeds. Oracles are bridge technologies that connect blockchain systems with the outside world, enabling smart contracts to securely access external data. In the realm of Stellar, a platform designed for the fast and cost-efficient transfer of value across the globe, Lightecho Oracle emerges as a critical tool, especially for Soroban — Stellar's smart contracts platform.
Lightecho is dedicated to delivering real-time, reliable market data and XLM volatility feeds, addressing a significant gap in emerging markets. These markets often face challenges such as limited access to traditional banking services and financial volatility.
PRODUCTION Official Contracts:
XLM
: CDOR3QD27WAAF4TK4MO33TGQXR6RPNANNVLOY277W2XVV6ZVJ6X6X42TUSD
: not deployed yet
TESTNET Official Contracts:
XLM
: CA335SIV2XT6OC3SOUTZBHTX5IXMFO3WYBD3NNVBP37JXX4FXFNF5CI6USD
: not deployed yet
This repository contains:
flowchart TD
deploy[Deploy Oracle to blockchain]-->initialize[Initialize Oracle with admin, base, decimals, etc]
initialize-->blockchain_contract
price_aggregator["Price aggregator (not open-source)"]-->post_prices["POST /db/add-prices"]
subgraph database [Price Database]
db[SQLite database file]
end
subgraph oracle_api ["Oracle API (see oracle-onchain/api)"]
post_prices-->save_to_db[Save prices to database]
save_to_db-->db
end
subgraph oracle_background_scripts ["Oracle background scripts (see oracle-onchain/sep40/cli/scripts)"]
db-->read_prices_from_db[Read prices from API database]
read_prices_from_db-->check_timestamps[Check price timestamps]
check_timestamps-->add_prices["Add prices to blockchain Contract via add_prices()"]
end
subgraph soroban_blockchain [Soroban Blockchain]
add_prices-->blockchain_contract[Contract inside blockchain]
end
Each source is represented by an integer in the blockchain contract. To fetch the last price of USD from Coinbase for example, you can use the CLI:
./cli oracle lastprice_by_source 1 other USD
TESTNET Official Sources for prices:
0 - BPV aggregator
1 - Coinbase
Map
.Map
to store the prices in the blockchain.
The main issue being the size limit for a single ledger entry, and the expensive
fees consumed to add and retrieve prices from the contract.Map
.u128
with this structure: [first 32 bits - source][next 32 bits - asset identifier][next 64 bits - timestamp]
.
Using this new lightweight approach allowed us to reduce fee costs in 95% compared
to the previous implementation using Map
, and removed all the scalability
issues we had when using Map
.
More curious about the code structure? See here how we generate the ledger key for a given price.The price feed is a script that puts the prices into the blockchain contract.
[!IMPORTANT] CLI must be already setup and configured via
local_settings.py
. See instructions.
Start by installing the systemd container:
sudo apt install systemd-container
Now, login into the systemd container and copy the systemd service unit files:
sudo machinectl shell myusername@ # replace myusername with your Linux username
mkdir -p ~/.config/systemd/user/
cp -v init/systemd/* ~/.config/systemd/user/
Go to ~/.config/systemd/user/
and update the .service
files (that you copied) with the correct paths:
...
[Service]
# replace /path/to/ with the correct path
ExecStart=/path/to/lightecho-stellar-oracle/oracle-onchain/sep40/cli/scripts/bump_instance.sh
...
Enable and start the services:
./run deploy
Additional commands:
./run status # check status of API and Feed
./run restart # restart API and Feed
# systemd helper
./systemd-status.sh
# to see logs
journalctl --user -u feed_bulk_from_db
journalctl --user -u bump_instance
Have a project that uses our Oracle? Feel free to share with us and we'll be happy to list it here!
Made by BP Ventures