{"id":24995409,"url":"https://github.com/compolabs/price-oracle","last_synced_at":"2025-04-12T04:11:12.792Z","repository":{"id":103206685,"uuid":"580984897","full_name":"compolabs/price-oracle","owner":"compolabs","description":"Price Oracle On Fuel Blockchain","archived":false,"fork":false,"pushed_at":"2023-02-14T19:03:44.000Z","size":654,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T23:41:46.276Z","etag":null,"topics":["cryptocurrency","oracle","rust","sway"],"latest_commit_sha":null,"homepage":"https://discord.gg/PxqxqxugwW","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/compolabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-12-22T00:52:25.000Z","updated_at":"2025-01-12T00:48:49.000Z","dependencies_parsed_at":"2023-03-12T20:45:43.757Z","dependency_job_id":null,"html_url":"https://github.com/compolabs/price-oracle","commit_stats":null,"previous_names":[],"tags_count":1,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fprice-oracle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fprice-oracle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fprice-oracle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fprice-oracle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compolabs","download_url":"https://codeload.github.com/compolabs/price-oracle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514221,"owners_count":21116903,"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":["cryptocurrency","oracle","rust","sway"],"created_at":"2025-02-04T15:37:47.121Z","updated_at":"2025-04-12T04:11:12.781Z","avatar_url":"https://github.com/compolabs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sway Land Price Oracle\nThe Sway Land Price Oracle receives price updates from a poster (who pulls the prices from coingecko). The price oracle verifies prices are within valid ranges, and if so, stores the prices so they can be accessed by Compound Money Market.\n\n# How to deploy and use Swaygang's price oracle\n\nWelcome to our tutorial on creating a price oracle in the Sway programming language for Fuel Network.\nOne of the key components in the blockchain is the price oracle, a decentralized system for providing accurate, up-to-date data on asset prices. Popular projects like Chainlink and Pyth.network have already proven the importance of price oracles in the blockchain ecosystem.\n\nFuel Network currently doesn't have any available price oracle solutions yet. That's why we would like to present a tutorial on building a price oracle in the Sway programming language, specifically designed for Fuel Network. This tutorial will guide you through the process of building a basic price oracle and provide you with the necessary code and steps to run it on a server using Docker. This oracle is not highly secure or scalable, but it will provide a good introduction to the concept of price oracles in the blockchain technology and give you the opportunity to get familiar with building solutions on Fuel Network. So, let's dive into the world of price oracles and see what it's all about!\n\n## Deployment Steps\n### Clone the Repository\n\nTo get started, you will need to clone the SwayGang price oracle repository from GitHub on your local computer. You can do this by using the git clone command in your terminal or command prompt:\n```\ngit clone https://github.com/sway-gang/price-oracle.git\n```\n\nOnce the cloning process is complete, navigate to the project folder by using the following command:\n\n```\ncd ./price-oracle\n```\n\n### Set Up the Environment\nTo set up the environment for the price oracle, you need to perform the following steps:\n\nChange to the contract folder:\n```\ncd contract\n```\nCreate a New Wallet (Optional):\nYou can use an existing wallet or create a new wallet to deploy the price oracle. If you already have a wallet and know how to obtain its secret key, you can skip this step and proceed to the next one.\n\nThe first step in setting up the environment is to create a new wallet. This wallet will be used to deploy the price oracle. You can create a new wallet using the following command:\n```\nforc-wallet new  \n```\nWhen you run the above command, you will be prompted to enter a password. This password is used to encrypt the secret key for your wallet, which is required to interact with Fuel Network.\n\nAfter entering the password, you will see the following output:\n```\nGenerating account with index: \u003cINDEX\u003e\nPlease enter your password to decrypt initialized wallet's phrases: \u003cYOUR PASSWORD HERE\u003e\nWallet address: fuel1...va0c2u\n```\n\nThe Wallet address displayed in the output is the address of your newly created wallet.\n\nExport the Secret Key:\nThe secret key is used to interact with Fuel Network and is required to deploy the price oracle. If you have created a new wallet, you can export its secret key using the following command:\n\n\n```\nforc-wallet export --account-index \u003cYOUR INDEX HERE\u003e\n```\nAfter entering your password, you will see the secret key for your account:\n\n```\nPlease enter your password to decrypt initialized wallet's phrases: \u003cYOUR PASSWORD HERE\u003e\nSecret key for account \u003cINDEX\u003e: 39a...5bd\n\n### Press any key to complete. ###\n\n```\n\nAdd the Secret Key to the .env File:\nTo make it easier to work with the price oracle, you can add the secret key to the .env file using the following command:\n```\necho \"SECRET=\u003cYOUR SECRET HERE\u003e\" \u003e\u003e .env \n```\n\nWith these steps completed, you will now need to mint some ETH to pay the transaction fees when deploying the price oracle. You can obtain ETH from a faucet: \nhttps://faucet-beta-2.fuel.network/.\n\n### Deploy and Initialize\nIn this step, we will be deploying and initializing the SwayGang price oracle. First, we will run the following command:\n\n```\nforce build\n```\n\nThis will compile the contract, and the output should be similar to:\n\n```\n  Compiled library \"core\".\n  Compiled library \"std\".\n  Compiled contract \"oracle\".\n  Bytecode size is 4392 bytes.\n```\n\nTo simplify the process, we've created a script that will deploy and initialize the oracle in the Tokyo test environment. You can run the script by executing the following command:\n```\ncargo test --package oracle --test integration_tests -- testnet_actions::deploy_and_initialize::deploy_and_initialize --exact --nocapture \n```\n\nThis will deploy and initialize the oracle and the output should be similar to:\n```\nrunning 1 test\n✅ Initialize\n✅ Oracle contract deployed\nHash:   0xd3ebf0eff0eda379b8b3eeb79c2f662d3d1b60110547b1590e6411e5a5f340df\nBech32: fuel1604lpmlsak3hnw9na6mectmx9573kcq3q4rmzkgwvsg7tf0ngr0sdrgqvs\ntest testnet_actions::deploy_and_initialize::deploy_and_initialize ... ok\n\ntest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 27.23\n```\nNote: The owner of the oracle will be the address from which it was deployed. This means that you can only update the price from this address.\n\n\n## Running the Oracle Update Server\nGo to the server folder:\n```\ncd ../server\n```\n\nSet up the environment variables in the .env file:\n```\necho \"\nSECRET=\u003cYOUR_SECRET\u003e#SECRET OF YOUR WALLET FROM THE LAST STEPS\nORACLE_ADDRESS=\u003cYOUR_ORACLE_ADDRESS\u003e #HASH ADDRESS OF ORACLE FROM THE LAST STEPS\nFREQUENCY=60 #FREQUENCY OF UPDATE\n\" \u003e\u003e .env \n```\n\n### Setup tokens list\nYou can manage the token list in the file `price-oracle/tokens.json`. By default `tokens.json` is filled by [swaylend](https://app.swaylend.com/) tokens.\nYou should provide info about each token in this format:\n```\n {\n   \"asset_id\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n   \"symbol\": \"ETH\",\n   \"coingeco_id\": \"ethereum\",\n   \"default_price\": 1200\n}\n```\nYou can find coingeco_id on the coingecko.com website in token info as API id. You can check an example here: https://www.coingecko.com/en/coins/ethereum\n\nStart the server with the following command:\n```\ncargo run \n```\nUpon successful execution, the following output should be displayed:\n\n```\n███████╗██╗    ██╗ █████╗ ██╗   ██╗     ██████╗  █████╗ ███╗   ██╗ ██████╗ \n██╔════╝██║    ██║██╔══██╗╚██╗ ██╔╝    ██╔════╝ ██╔══██╗████╗  ██║██╔════╝ \n███████╗██║ █╗ ██║███████║ ╚████╔╝     ██║  ███╗███████║██╔██╗ ██║██║  ███╗\n╚════██║██║███╗██║██╔══██║  ╚██╔╝      ██║   ██║██╔══██║██║╚██╗██║██║   ██║\n███████║╚███╔███╔╝██║  ██║   ██║       ╚██████╔╝██║  ██║██║ ╚████║╚██████╔╝\n╚══════╝ ╚══╝╚══╝ ╚═╝  ╚═╝   ╚═╝        ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝                                                                         \n\n✅ Oracle is alive\n\nOracle owner   = Address(330e6922460257edbaac821df96a555bc745041c97ff5411ec83f2b29f471c27)\nWallet address = Address(330e6922460257edbaac821df96a555bc745041c97ff5411ec83f2b29f471c27)\n🪬 Price oracle update\n1 USDC = $1.000435188\n1 ETH = $1658.670603406\n1 LINK = $7.16316701\n1 BTC = $23025.231488235\n1 UNI = $6.777685611\n1 SWAY = $56.298952718\n1 COMP = $56.298952718\n\n⛽️ Gas used: 109362\n⚖️ Balance: 0.499999991 ETH\n👁 Oracle address: 0xd3ebf0eff0eda379b8b3eeb79c2f662d3d1b60110547b1590e6411e5a5f340df\n-----------------------------------\n```\n\nYou can also run the server using Docker by using the Dockerfile in the server directory. Here's how:\n\nBuild the Docker image:\n```\nsudo docker build --tag oracle .  \n```\n\nRun the Docker container:\n```\nsudo docker run --restart=always -d oracle   \n\n```\n\n## Summary\nThis tutorial on creating a price oracle in the Sway programming language for Fuel Network will guide you through the steps of building a basic, yet functional oracle. As a key component of blockchain infrastructure, price oracles provide accurate, up-to-date data on asset prices and are essential to the functioning of blockchain ecosystems. With this tutorial, you will gain hands-on experience building a solution for Fuel Network, and a better understanding of process of development on Fuel Network. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Fprice-oracle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompolabs%2Fprice-oracle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Fprice-oracle/lists"}