{"id":25806948,"url":"https://github.com/blocksense-network/ethsofia_hackaton","last_synced_at":"2025-02-27T20:55:52.011Z","repository":{"id":257844914,"uuid":"867003944","full_name":"blocksense-network/ethsofia_hackaton","owner":"blocksense-network","description":"Repository for ETHSofia 17-19 Oct Hackaton","archived":false,"fork":false,"pushed_at":"2024-10-17T11:05:26.000Z","size":64,"stargazers_count":2,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T22:21:39.593Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blocksense-network.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-03T09:24:29.000Z","updated_at":"2024-10-17T11:50:17.000Z","dependencies_parsed_at":"2024-10-18T21:23:09.643Z","dependency_job_id":null,"html_url":"https://github.com/blocksense-network/ethsofia_hackaton","commit_stats":null,"previous_names":["blocksense-network/ethsofia_hackaton"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocksense-network%2Fethsofia_hackaton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocksense-network%2Fethsofia_hackaton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocksense-network%2Fethsofia_hackaton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocksense-network%2Fethsofia_hackaton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blocksense-network","download_url":"https://codeload.github.com/blocksense-network/ethsofia_hackaton/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241059297,"owners_count":19902355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T20:55:51.452Z","updated_at":"2025-02-27T20:55:52.004Z","avatar_url":"https://github.com/blocksense-network.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Repository for ETHSofia 17-19 Oct Hackaton\n\nWelcome to ETHSofia 17-19 Oct Hackaton. To participate in hackaton you need to setup blocksense network in your local machine.\n\nInstall git, [docker compose](https://docs.docker.com/compose/install/) \u0026 [rust](https://www.rust-lang.org/tools/install). Currently we only support rust for writing oracle scripts. It's technologically possible to use other languages, but this is out of the scope for this hackaton because our SDK is only available for rust. So you need to get rusty !\nYour first goal is to run one of our oracle script to verify all services are running and set up correctly.\n\n1. Clone this repository:\n\n   ```bash\n   git clone git@github.com:blocksense-network/ethsofia_hackaton.git\n   ```\n\n   or\n\n   ```bash\n   git clone https://github.com/blocksense-network/ethsofia_hackaton.git\n   ```\n\n\u003e [!IMPORTANT]\n\u003e For Mac users you need to switch to `mac_images` branch. All the instructions apply for Mac \u0026 Linux.\n\n2. Then download out pre-build images with following command\n\n   ```bash\n   docker compose pull\n   ```\n\n3. Make sure you have rust compiler with wasm32-wasi target:\n\n   ```bash\n   cargo -V\n   rustup target add wasm32-wasi\n   ```\n\n## Running an available Oracle Script\n\n### Run wasm revolut reporter\n\nTo run wasm revolut reporter you need to build it:\n\n```bash\ncd examples/revolut \u0026\u0026 cargo update \u0026\u0026 cargo build --target wasm32-wasi --release\n```\n\nNow go to root directory of this repository and start all the containers:\n\n```bash\ndocker compose up\n```\n\nThis will launch 2 local ETH blockchains (anvil), blocksense sequencer service which is responsible for publishing oracle scripts data feeds to the ETH blockchain and one reporter which will execute your oracle script and push its data feed to sequencer.\n\n```mermaid\nsequenceDiagram\nReporter -\u003e\u003e Sequencer: post oracle data feed [ 10 sec]\nReporter -\u003e\u003e Sequencer: post oracle data feed [ 10 sec]\nSequencer-\u003e\u003e Anvil[ETH]: Publish transactions with new data [30 sec]\nReporter -\u003e\u003e Sequencer: post oracle data feed [ 10 sec]\nReporter -\u003e\u003e Sequencer: post oracle data feed [ 10 sec]\nReporter -\u003e\u003e Sequencer: post oracle data feed [ 10 sec]\n```\n\nThe system is designed to handle many decentralized oracles, but for this hackaton we will use only one reporter that executes one oracle script.\nIf everything works correctly you will have one oracle script that reports one price feed. In the docker compose output you can see something like:\n\n```log\nsequencer-1   | 2024-10-15T14:57:08.291818Z DEBUG sequencer::http_handlers::data_feeds: Recvd result from reporter[0]: Numerical(64680.51629596154)\nsequencer-1   | 2024-10-15T14:57:08.291843Z DEBUG sequencer::http_handlers::data_feeds: getting feed_id = 31\nsequencer-1   | 2024-10-15T14:57:08.291861Z DEBUG feed_registry::types: Accepted report!\n```\n\n---\n\n### Run wasm yahoo reporter\n\nNext step is to change the oracle script in the reporter with more sophisticated one. Which uses Yahoo finance with your private API key\n\nRegister at [Yahoo finance API](https://financeapi.net/dashboard) and paste the API key in this directory in file:\n\n`examples/yahoo/spin.toml` in section:\n\n```toml\n[[trigger.oracle.capabilities]]\ndata = \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\nid = \"YAHOO_API_KEY\"\n```\n\nNow build the yahoo reporter:\n\n```bash\ncd examples/yahoo \u0026\u0026 cargo update \u0026\u0026 cargo build --target wasm32-wasi --release\n```\n\nGo to the main directory in the repository and enable yahoo entrypoint of the `reporter` service in `docker-compose.yml`\n\n```yaml\nentrypoint:\n  [\"/bin/sh\", \"-c\", \"cd /usr/local/blocksense/oracles/yahoo \u0026\u0026 /spin up\"]\n```\n\nStart docker compose again. That will start 2 anvil instances, one sequencer and a yahoo reporter\n\n```bash\n  docker compose down # if you have already running containers\n  docker compose up\n```\n\nIf everything is setup correctly you will see anvil reporting published transactions:\n\n```bash\n  docker compose logs anvil-a\n```\n\n```log\n\nanvil-a-1 | Genesis Timestamp\n\nanvil-a-1 | ==================\n\nanvil-a-1 |\n\nanvil-a-1 | 1728549718\n\nanvil-a-1 |\n\nanvil-a-1 | Listening on 0.0.0.0:8545\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | eth_getCode\n\nanvil-a-1 | eth_gasPrice\n\nanvil-a-1 | eth_chainId\n\nanvil-a-1 | eth_getTransactionCount\n\nanvil-a-1 | eth_sendRawTransaction\n\nanvil-a-1 |\n\nanvil-a-1 | Transaction: 0x92befeefef33dc231e696f65a69502609452f2179fb1a5e9c95842081ab4c5d1\n\nanvil-a-1 | Gas used: 21328\n\nanvil-a-1 |\n\nanvil-a-1 | Block Number: 1\n\nanvil-a-1 | Block Hash: 0x0d2ebeea50b02beebfbe50a310871773fa186da61a386bb9dcb2d3df97a4bb5a\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | Block Time: \"Thu, 10 Oct 2024 08:42:30 +0000\"\n\nanvil-a-1 |\n\nanvil-a-1 | eth_getBlockByNumber\n\nanvil-a-1 | eth_getTransactionReceipt\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | eth_blockNumber\n\nanvil-a-1 | eth_gasPrice\n\nanvil-a-1 | eth_chainId\n\nanvil-a-1 | eth_sendRawTransaction\n\nanvil-a-1 |\n\nanvil-a-1 | Transaction: 0x5fac5e16d81fab79649b9d80752305eede9b718ba54cb6e1433372429088f1c9\n\nanvil-a-1 | Gas used: 21316\n\nanvil-a-1 |\n\nanvil-a-1 | Block Number: 2\n\nanvil-a-1 | Block Hash: 0xd95ca48a9c898f93a4f15b5d7321f7f82de9928e3f3f6f44caab4b33bd9d9fa7\n\nanvil-a-1 | Block Time: \"Thu, 10 Oct 2024 08:43:00 +0000\"\n\nanvil-a-1 |\n\n```\n\n### Using a similar approach you can use CoinMarketCap wasm reporter\n\nAdd CoinMarketCap key from this registration\n\nRegister at https://coinmarketcap.com/api/pricing/ and paste API key in this directory in file\n\n`examples/cmc/spin.toml` in section:\n\n```toml\n[[trigger.oracle.capabilities]]\ndata = \"00000000-0000-0000-0000-000000000000\"\nid = \"CMC_API_KEY\"\n```\n\nNow build the cmc reporter:\n\n```bash\ncd examples/cmc \u0026\u0026 cargo update \u0026\u0026 cargo build --target wasm32-wasi --release\n```\n\nAgain at the `reporter` service in `docker-compose.yml` enable the cmc entrypoint\n\n```yaml\nentrypoint:\n  [\"/bin/sh\", \"-c\", \"cd /usr/local/blocksense/oracles/cmc \u0026\u0026 /spin up\"]\n```\n\nYou can now start docker compose again.\n\n```bash\n  docker compose down # if you have already running containers\n  docker compose up\n```\n\nIf everything is setup correctly you will see anvil reporting published transactions.\n\n## Reading on-chain data\n\nOnce having all set up and running you can read the data from the blockchain.\nFor more information of how our Smart Contracts work navigate to the [Blocksense Smart Contract Documentation](https://docs.blocksense.network/docs/contracts)\n\nThere is a couple of ways to read the data from the blockchain. As mentioned above, we have anvil instances running, which are local Ethereum blockchains. We deploy our smart contracts on these blockchains and we can interact with them using different tools.\n\n### Using `cast`\n\nOne approach could be to use the `cast` tool. `cast` is a command line tool that allows you to interact with the blockchain. You can find more information about it [here](https://book.getfoundry.sh/cast/).\n\nHere is an example of how to use `cast` to read the data from the blockchain:\n\n```bash\ncast call 0xc04b335A75C5Fa14246152178f6834E3eBc2DC7C --data 0x8000001f --rpc-url http://127.0.0.1:8545 |  cut -c1-50 | cast to-dec\n```\n\nLets break down the command:\n\n1. We make a call to the contract with address `0xc04b335A75C5Fa14246152178f6834E3eBc2DC7C`. This is our [UpgradeableProxy](https://docs.blocksense.network/docs/contracts/reference-documentation/UpgradeableProxy) contract.\n\n2. We pass the data `0x8000001f` to the contract. This way you interact with the `fallback` function of the `UpgradeableProxy` contract. More info on this can be found [here](https://docs.blocksense.network/docs/contracts#call-handling-mechanism). This call allows us to read the latest price and timestamp. One question you might have at this point is how to craft this selector. In one handy way is to use `node repl` or `js` as follows:\n\n```javascript\nconst id = 31;\nconst selector = \"0x\" + ((id | 0x80000000) \u003e\u003e\u003e 0).toString(16).padStart(8, \"0\");\nconsole.log(selector);\n// '0x8000001f'\n```\n\nNote that the `id` is the id of the data feed you want to read data for. In this case with id 31 we are reading the price of `BTC/USD` data feed. You can confirm that by navigating to `config/feed_config.json` file or in the `spin.toml` file of any oracle script.\n\n3. We pass the `rpc-url` of the anvil instance we want to interact with. In this case we are using the first anvil instance.\n\n4. We pipe the output to `cut` to get only the first 50 characters of the output. This is because they refer to the price itself. The output is in hex format and we want to convert it to decimal. We can do that by piping the output to `cast to-dec`.\n\nExpected result must be something like `67260166034648270000000` which is the price of BTC/USD in the moment of the call.\n\n\u003e Note: Potential issues\n\u003e\n\u003e - If the result is 0 that means the reporter is not running correctly.\n\u003e - If you receive an error that could be due to the fact that the smart contract is not deployed on the blockchain.\n\n### Using `ethers.js`\n\nWe have examples for interacting with `UpgradeableProxy` contract using `ethers.js` [here](https://docs.blocksense.network/docs/contracts/integration-guide/using-data-feeds/historic-data-feed#ethersjs-v6x).\n\n### Using `solidity`\n\nWe have examples for interacting with `UpgradeableProxy` contract using `solidity` [here](https://docs.blocksense.network/docs/contracts/integration-guide/using-data-feeds/historic-data-feed#solidity).\n\n## Creating your own new Oracle Script\n\nThis is the main task of this hackaton - to create your oracle script, feed data to the blockchain and do something interesting or useful with it. To achieve your goal we suggest to use copy-paste-edit strategy with one of our existing oracles.\n\nFor example:\n\n```bash\ncd examples \u0026\u0026 cp -r revolut my_oracle\n```\n\nedit `my_oracle/spin.toml`:\n\n```toml\nspin_manifest_version = 2\n\n[application]\nauthors = [\"Your names\"]\nname = \"Blocksense Oracle Hackaton\"\nversion = \"0.1.0\"\n\n[application.trigger.settings]\ninterval_time_in_seconds = 10 # reporting interval in seconds. Adjust if necessary\nsequencer = \"http://sequencer:8877/post_report\"\nsecret_key = \"536d1f9d97166eba5ff0efb8cc8dbeb856fb13d2d126ed1efc761e9955014003\"\nreporter_id = 0\n\n[[trigger.oracle]]\ncomponent = \"your-awesome-script\"\n\n[[trigger.oracle.data_feeds]]\nid = \"47\" #UPDATE DATA FEEDS IF NEEDED\ndata = \"USD/ETH\"\n\n[[trigger.oracle.data_feeds]]\nid = \"31\"\ndata = \"USD/BTC\"\n\n[component.your-awesome-script]\nsource = \"target/wasm32-wasi/release/my-awesome-oracle.wasm\"\nallowed_outbound_hosts = [\n\"https://awesome-data-feed.com\",\n]\n[component.your-awesome-script.build]\ncommand = \"cargo build --target wasm32-wasi --release\"\n```\n\nEdit `my_oracle/Cargo.toml`:\n\n```toml\n[package]\nname = \"my-awesome-oracle\"\nauthors = [\"Your name\"]\ndescription = \"\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type = [\"cdylib\"]\n\n[dependencies]\nwit-bindgen = \"0.16.0\"\nblocksense-sdk = { git = \"https://github.com/blocksense-network/sdk.git\" }\nanyhow = \"1.0.82\"\nserde_json = \"1.0\"\nurl = \"2.5\"\nserde = { version = \"1.0\", features = [\"derive\"] }\n\n# Add extra dependencies here, if needed\n\n```\n\nIf you need a new data feed for your application you can appended to\n`config/feed_config.json`\n\n```json\n    {\n      \"id\": 42, # Pick some ID that is not occupied, or you can reuse existing one ( but let it be between 0 and 257 )\n      \"name\": \"MyToken\",\n      \"fullName\": \"\",\n      \"description\": \"MyToken / USD\",\n      \"decimals\": 8,\n      \"report_interval_ms\": 30000,\n      \"quorum_percentage\": 1, # Leave unchannged\n      \"type\": \"Crypto\",\n      \"script\": \"CoinMarketCap\",\n      \"pair\": {\n        \"base\": \"MyToken\",\n        \"quote\": \"USD\"\n      },\n      \"first_report_start_time\": {\n        \"secs_since_epoch\": 0,\n        \"nanos_since_epoch\": 0\n      },\n      \"resources\": {\n        \"cmc_id\": 123456,\n        \"cmc_quote\": \"MyToken\"\n      }\n    },\n```\n\nWrite the code for your oracle and build it.\n\nEdit `docker-compose.yaml` to start your oracle script:\n\n```yaml\n  reporter:\n    image: ymadzhunkov/blocksense_hackaton:reporter\n    networks:\n      - backend\n    volumes:\n      - ./examples/yahoo:/usr/local/blocksense/oracles/yahoo\n      - ./examples/revolut:/usr/local/blocksense/oracles/revolut\n      - ./examples/cmc:/usr/local/blocksense/oracles/cmc\n      - ./examples/my_oracle:/usr/local/blocksense/oracles/my_oracle\nentrypoint: ['/bin/sh', '-c', 'cd /usr/local/blocksense/oracles/my_oracle \u0026\u0026 /spin up']\n    depends_on:\n      sequencer:\n        condition: service_healthy\n```\n\nRestart the entire setup:\n\n```bash\ndocker compose down\ndocker compose up\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocksense-network%2Fethsofia_hackaton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblocksense-network%2Fethsofia_hackaton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocksense-network%2Fethsofia_hackaton/lists"}