Created
October 3, 2023 17:39
-
-
Save jO-Osko/d1a96146f01967e61b8dae4517d7f927 to your computer and use it in GitHub Desktop.
DynamicFlarePrice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
import { IPriceSubmitter } from "@flarenetwork/flare-periphery-contracts/flare/ftso/userInterfaces/IPriceSubmitter.sol"; | |
import { IFtsoRegistry } from "@flarenetwork/flare-periphery-contracts/flare/ftso/userInterfaces/IFtsoRegistry.sol"; | |
import { IFlareContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/util-contracts/userInterfaces/IFlareContractRegistry.sol"; | |
contract SimpleFtsoExample { | |
string public higherPriceURI; | |
string public lowerPriceURI; | |
uint256 public targetPrice; | |
constructor(string memory h, string memory l, uint256 tPrice){ | |
higherPriceURI = h; | |
lowerPriceURI = l; | |
targetPrice = tPrice; | |
} | |
function getPriceSubmitter() public view virtual returns (IPriceSubmitter) { | |
return IPriceSubmitter(0x1000000000000000000000000000000000000003); | |
} | |
function getFtsoRegistry() public view virtual returns(IFtsoRegistry){ | |
return IFtsoRegistry(getFlareContractRegistry().getContractAddressByName("FtsoRegistry")); | |
} | |
function getFlareContractRegistry() public view virtual returns (IFlareContractRegistry) { | |
return IFlareContractRegistry(0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019); // Coston2 | |
// return IFlareContractRegistry(0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019); // Flare | |
} | |
function getTokenPriceWei( | |
string memory foreignTokenSymbol | |
) | |
public | |
view | |
returns (uint256 _price, uint256 _timestamp, uint256 _decimals) | |
{ | |
IFtsoRegistry ftsoRegistry = getFtsoRegistry(); | |
(_price, _timestamp, _decimals) = ftsoRegistry | |
.getCurrentPriceWithDecimals(foreignTokenSymbol); | |
} | |
function getCorrectURI() public view returns(string memory){ | |
// Use test prefixed string on coston2 | |
(uint256 _price, ,) = getTokenPriceWei("BTC"); | |
// Generating code like this should not be that difficult for a simple boolean expression -> chain of if-then-else | |
if(_price >= targetPrice){ | |
return higherPriceURI; | |
} | |
return lowerPriceURI; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment