{"id":24551958,"url":"https://github.com/mlabs-haskell/religant-integration-example","last_synced_at":"2025-03-16T13:41:32.317Z","repository":{"id":207428932,"uuid":"696591734","full_name":"mlabs-haskell/religant-integration-example","owner":"mlabs-haskell","description":"A simple dApp that fetches current price data from the Religant Oracle and writes it to the metadata field of a token (for testing, mainly)","archived":false,"fork":false,"pushed_at":"2024-06-25T23:23:16.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-23T01:19:46.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mlabs-haskell.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":"2023-09-26T03:57:28.000Z","updated_at":"2024-02-14T18:14:52.000Z","dependencies_parsed_at":"2024-06-26T00:42:38.095Z","dependency_job_id":null,"html_url":"https://github.com/mlabs-haskell/religant-integration-example","commit_stats":null,"previous_names":["mlabs-haskell/religant-integration-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Freligant-integration-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Freligant-integration-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Freligant-integration-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Freligant-integration-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlabs-haskell","download_url":"https://codeload.github.com/mlabs-haskell/religant-integration-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878408,"owners_count":20362431,"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-01-23T01:19:32.225Z","updated_at":"2025-03-16T13:41:32.294Z","avatar_url":"https://github.com/mlabs-haskell.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview \n\nThis repository contains an example Radix application which integrates the Religant Radix Oracle. The instructions here are intended for Radix developers who wish to integrate the Religant Oracle into their own applications.\n\n## Overview of the Protocol \n\nThe Religant Oracle protocol enables a _decentralized_ feed of price data. A set of data nodes query exchanges for up-to-date transactions and submit feed updates to the contract, which employs a _consensus mechanism_ to determine the aggregate price. Data nodes running the Religant node backend software submit feed updates either on a regular interval (if the price is stable), or as soon as the new aggregate price calculated by a node exceeds a specific divergence threshold. \n\nAt this time, the divergence threshold is set at 2%. This guarantees that the rate retrieved from the Religant oracle component's feed is always within 2% of the rates being used in real transactions on real exchanges. \n\n## Religant Component API \n\nThe user-facing API of the Religant Oracle consists in a single method: \n\n``` rust\npub fn get_price(\u0026self) -\u003e Option\u003cPriceData\u003e \n```\n\nwhich takes no arguments returns a data structure: \n\n``` rust\npub struct PriceData {\n    pub price: Decimal,\n    pub timestamp: i64,\n}\n```\n\nWhere the `price` field is the current XRD/USD exchange rate, and the `timestamp` field is a POSIX timestamp that that identifies the moment at which the the exchange rate was calculated. \n\nNote that the `Option` wrapper exists primarily for type safety. The `get_price` method will __always__ return `Some(_)` after the first round of Oracle feed aggregation. Consequently, it should generally be safe to assume that you will never receive a `None` as a result of calling the method on an active Religant oracle component. \n\n(You may, however, wish to check the timestamp. While we aim to provide high reliability, a major internet or cloud hosting outage could cause delays in feed updates, though this would be an extraordinary situation.)\n\n## Integration Guide \n\nNOTE: These instructions are current as of 11/13/2023. Some of the official documentation may refer to a different method (using different macros), but as of today the method illustrated below is the only one known to work. \n\nIntegrating with the Religant Oracle component requires a few small changes to your application's blueprint(s): \n\n__FIRST__: You must __define the `PriceData` struct__ *outside of your blueprint.* E.g., by adding: \n``` rust \n#[derive(ScryptoSbor, PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone)]\npub struct PriceData {\n    pub price: USDValue,\n    pub timestamp: POSIXTime,\n}\n```\n\nat the top of the source file containing the component where you wish to use the Religant Oracle method. \n\n\n__SECOND__: You must __declare the component's API__ using an `extern_blueprint!` macro __inside of your blueprint module__: \n\n``` rust\n#[blueprint]\nmod oracle_client {\n    extern_blueprint! {\n        \"package_rdx1phuhdg98xt90ygva6fgh357vtg20aps8mkmrdy6wn6mp4myn24rhyf\",\n        Religant {\n        fn get_price(\u0026self) -\u003e Option\u003cPriceData\u003e;\n        }\n    }\n...\n```\n\n__THIRD__: You must instantiate a reference to the global Religant component as a `const` inside of your blueprint. It should be possible to instantiate this reference either at the top level of your blueprint module, or inside of a method or function. Here, we do it at the top level: \n\n``` rust\n const RELIGANT: Global\u003cReligant\u003e =\n        global_component!(Religant, \"component_rdx1czqqs4t8f62jeyp47ctyqwmtk3vnf9sffnqd9lu7tgtgtvshj6x9lp\");\n```\n\n__FINALLY__: You are free to use the methods of the instantiated component in your own method, for example: \n\n``` rust\n        pub fn cash_xrd(\u0026self) -\u003e Bucket {\n            match RELIGANT.get_price() {\n                None =\u003e {Bucket::new(self.price_token_resource_address)},\n                Some(price_data) =\u003e {\n                            let resource_manager =\n                                ResourceManager::from(self.price_token_resource_address);\n                            resource_manager.mint(price_data.price)\n                }\n            }\n        }\n```\n\nIn this example, the `cash_xrd` method calls the Religant `get_price` method and mints a number of tokens equal to the current XRD/USD exchange rate. \n\nThe full integration example contract can be found in this repository's `src/lib.rs` module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Freligant-integration-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlabs-haskell%2Freligant-integration-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Freligant-integration-example/lists"}