Skip to content

Commit

Permalink
add getPrice() to script
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Dec 18, 2024
1 parent 7c3a329 commit a6ead78
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# astria-oracle-contracts

Repository of contracts used for Astria's native oracle.

### deploy

Copy the example .env: `cp local.env.example .env`

Put your private key in `.env` and `source .env`.

To deploy `AstriaOracle.sol`:

```sh
forge script script/AstriaOracle.s.sol:AstriaOracleScript \
--rpc-url $RPC_URL --broadcast --sig "deploy()" -vvvv
```

### query contract

The script has an example function which calls `getPrice()` for `ETH/USD`. You can update the test for different currency pair strings to get their price.

```sh
forge script script/AstriaOracle.s.sol:AstriaOracleScript --rpc-url $RPC_URL --broadcast --sig "getPrice()" -vvvv
```
15 changes: 15 additions & 0 deletions local.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# private key to submit txs with
PRIVATE_KEY=0x

# default local rpc url
RPC_URL="http://localhost:8545"

### contract deployment values

# the `astriaOracleCallerAddress` built into the astria-geth node
# in production, the private key for this address must NOT be known.
EVM_ORACLE_SENDER_ADDRESS=0x0000000000000000000000000000000000000088

### contract call values

ORACLE_CONTRACT_ADDRESS=0x
17 changes: 14 additions & 3 deletions script/AstriaOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ contract AstriaOracleScript is Script {

function setUp() public {}

function run() public {
vm.startBroadcast();
function deploy() public {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

address oracleSenderAddress = vm.envAddress("EVM_ORACLE_SENDER_ADDRESS");
astriaOracle = new AstriaOracle(oracleSenderAddress);
AstriaOracle oracle = new AstriaOracle(oracleSenderAddress);

vm.stopBroadcast();

console.logBytes(address(oracle).code);
}

function getPrice() public view {
address oracleContract = vm.envAddress("ORACLE_CONTRACT_ADDRESS");
AstriaOracle oracle = AstriaOracle(oracleContract);
bytes32 pair = keccak256("ETH/USD");
uint256 latestBlockNumber = oracle.latestBlockNumber();
(uint128 price,) = oracle.priceData(latestBlockNumber, pair);
console.logUint(price);
}
}

0 comments on commit a6ead78

Please sign in to comment.