Skip to content

Commit

Permalink
Feeder Gateway depreciation (#96)
Browse files Browse the repository at this point in the history
* feat: update to rpc

* feat: change gateway to rpc

* Env var changed

* sepolia deployments/declarations

* Katana instance run on CI

* update ci: install katana

* fix: katana installation

* fix: katana bug

* actions checkout

* debug dojo

* alternative installation

* poetry install

* fmt

* clean code

* specify python version

* env variables

* unnecessary code

* secret permissions

* indent

* revert

* dojo config

* scarb

* fix: typo

* fix: review comments

* fix: use public rpc

* fix: readme

* Update README.md

---------

Co-authored-by: 0xevolve <[email protected]>
  • Loading branch information
JordyRo1 and EvolveArt authored Dec 21, 2023
1 parent e6104a3 commit f98dfce
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 132 deletions.
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ GITHUB_TOKEN=
# Network configuration
STARKNET_NETWORK=devnet

# An Infura API key (TODO: run a Starknode)
RPC_KEY=

# All addresses are hex strings
MAINNET_ACCOUNT_ADDRESS=
MAINNET_PRIVATE_KEY=
Expand All @@ -23,3 +20,10 @@ DEVNET_PRIVATE_KEY=
# These will be used if above variables are not set for the given network
ACCOUNT_ADDRESS=
PRIVATE_KEY=

# RPC URL used by deployment scripts
RPC_URL=

# Account with --seed=1
KATANA_ACCOUNT_ADDRESS=0x7b245927f60309cb2fdcbc3f7d37a21ce5bc05a4305104b43b72b91aa3f53e1
KATANA_PRIVATE_KEY=0x100801800000000310080180000000010030000000000005106801800206800
48 changes: 48 additions & 0 deletions .github/workflows/run_scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run scripts

on: pull_request

jobs:
run_scripts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3


- name: Install rust
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
- name: Install dojoup
run: |
curl -L https://install.dojoengine.org | bash
- name: Install dojo
run: |-
/home/runner/.config/.dojo/bin/dojoup
sudo mv /home/runner/.config/.dojo/bin/katana /usr/local/bin/
- name: Make script executable
run: chmod +x scripts/katana.sh

# Set up Python and install Poetry
- name: Set up Python and install Poetry
uses: actions/setup-python@v2
with:
python-version: '3.9'
- run: pip3 install poetry

# Install Python dependencies with Poetry
- name: Install dependencies
run: poetry install

# Set up Scarb
- uses: software-mansion/setup-scarb@v1
- run: scarb build

# Run Katana and scripts
- name: Run Katana and scripts
env:
KATANA_ACCOUNT_ADDRESS: ${{ secrets.KATANA_ACCOUNT_ADDRESS }}
KATANA_PRIVATE_KEY: ${{ secrets.KATANA_PRIVATE_KEY }}
run: bash scripts/katana.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ coverage/*
# Scripts artifacts
blockhashes.json
deployed_addresses.json
deployments/katana

# thoth relateds stuff
output-callgraph/*
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Overview
---

- <a href="/src/account">Account contract</a> mostly use for testing purposes and as a reference.
- <a href="/src/admin">Admin contract</a> will be replaced by Argent's multisig as it gets released.
- <a href="/src/admin">Ownable contract</a> used for access control.
- <a href="/src/entry">Entry & Data Structures</a> defines data structures used within the protocol along with generic aggregations methods. It is designed from the ground up to ensure that adding new entry types is done seamlessly without involving any breaking changes.
- <a href="/src/operations">Operations</a> defines a few utilities libraries (time series, sorting, bits manipulation) that will be used for different aggregation methods and optimizing storage operations.
- <a href="/src/oracle">Oracle</a> is the main entrypoint of the protocol. It is the contract that end developers will interact with to fetch any kind of data. It's been thought and built for retro-compatibility and heavily leverages unique aspects of Cairo, notably enums, traits and generics.
Expand Down Expand Up @@ -46,18 +46,24 @@ Deployment addresses

This repo will gradually replace the previous Pragma implementation in Cairo 0 which you can find [here](https://github.com/Astraly-Labs/pragma-contracts).

**Starknet Testnet**
- Oracle : [0x06df335982dddce41008e4c03f2546fa27276567b5274c7d0c1262f3c2b5d167](https://goerli.voyager.online/contract/0x06df335982dddce41008e4c03f2546fa27276567b5274c7d0c1262f3c2b5d167)
- Publisher Registry : [0x552e96b3a9078a453ab7012ed76325bedef7b0cc5647a8fafe985e658e31d86](https://goerli.voyager.online/contract/0x552e96b3a9078a453ab7012ed76325bedef7b0cc5647a8fafe985e658e31d86)
- Summary Stats : [0x3bcd9362bfe80456a7ee66f5a569457cb21adc3f82129420fa12453abb7f353](https://goerli.voyager.online/contract/0x3bcd9362bfe80456a7ee66f5a569457cb21adc3f82129420fa12453abb7f353)
- VRF : [0x693d551265f0be7ccb3c869c64b5920929caaf486497788d43cb37dd17d6be6](https://goerli.voyager.online/contract/0x693d551265f0be7ccb3c869c64b5920929caaf486497788d43cb37dd17d6be6)
**Starknet Sepolia**
- Oracle : [0x5acaa0ef3a6837c98ddeae516fa3f6022018cf646914d921842e46fc00c35d3](https://goerli.voyager.online/contract/0x5acaa0ef3a6837c98ddeae516fa3f6022018cf646914d921842e46fc00c35d3)
- Publisher Registry : [0x732b618bc92e3919e28dd3b3aff21079b2507c1f51b8a194ce90300e995cb](https://goerli.voyager.online/contract/0x732b618bc92e3919e28dd3b3aff21079b2507c1f51b8a194ce90300e995cb)
- Summary Stats : [0x185b147a3e03043e0232ec6fcf17143614481cc29a505c7d9c4b29e98c1f14e](https://goerli.voyager.online/contract/0x185b147a3e03043e0232ec6fcf17143614481cc29a505c7d9c4b29e98c1f14e)
- VRF : [0x556bd6988d786777bb5b1ee337c63f60f30d8200818b59b29e54afc27266a46](https://goerli.voyager.online/contract/0x556bd6988d786777bb5b1ee337c63f60f30d8200818b59b29e54afc27266a46)

**Starknet Mainnet**
- Oracle : [0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b](https://voyager.online/contract/0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b)
- Publisher Registry : [0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415](https://voyager.online/contract/0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415)
- Summary Stats : [0x49eefafae944d07744d07cc72a5bf14728a6fb463c3eae5bca13552f5d455fd](https://voyager.online/contract/0x49eefafae944d07744d07cc72a5bf14728a6fb463c3eae5bca13552f5d455fd)
- VRF : 🔜

**Starknet Goerli (Deprecated)**
- Oracle : [0x06df335982dddce41008e4c03f2546fa27276567b5274c7d0c1262f3c2b5d167](https://goerli.voyager.online/contract/0x06df335982dddce41008e4c03f2546fa27276567b5274c7d0c1262f3c2b5d167)
- Publisher Registry : [0x552e96b3a9078a453ab7012ed76325bedef7b0cc5647a8fafe985e658e31d86](https://goerli.voyager.online/contract/0x552e96b3a9078a453ab7012ed76325bedef7b0cc5647a8fafe985e658e31d86)
- Summary Stats : [0x3bcd9362bfe80456a7ee66f5a569457cb21adc3f82129420fa12453abb7f353](https://goerli.voyager.online/contract/0x3bcd9362bfe80456a7ee66f5a569457cb21adc3f82129420fa12453abb7f353)
- VRF : [0x693d551265f0be7ccb3c869c64b5920929caaf486497788d43cb37dd17d6be6](https://goerli.voyager.online/contract/0x693d551265f0be7ccb3c869c64b5920929caaf486497788d43cb37dd17d6be6)

Local Deployment
---

Expand All @@ -80,15 +86,15 @@ scarb build

3. Deploy contracts & setup

Make sure your local devnet is running, see latest instructions [here](https://0xspaceshard.github.io/starknet-devnet/docs/intro).
Make sure your local devnet is running, see latest instructions [here](https://book.dojoengine.org/toolchain/katana/reference.html).

You can also specify a different network by setting `STARKNET_NETWORK` to a different value e.g `testnet | mainnet`.
You can also specify a different network by setting `STARKNET_NETWORK` to a different value e.g `sepolia | testnet | mainnet`.

```bash

STARKNET_NETWORK=devnet poetry run python3 scripts/deploy_pragma.py
STARKNET_NETWORK=devnet poetry run python3 scripts/deploy_summary_stats.py
STARKNET_NETWORK=devnet poetry run python3 scripts/register_publishers.py
STARKNET_NETWORK=katana poetry run python3 scripts/deploy_pragma.py
STARKNET_NETWORK=katana poetry run python3 scripts/deploy_summary_stats.py
STARKNET_NETWORK=katana poetry run python3 scripts/register_publishers.py

```

Expand Down
2 changes: 1 addition & 1 deletion deployments/mainnet/declarations.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pragma_Oracle": "0x40a2430b48587833abc2e912335cffd863c010e2c798d005d9bcace56a156fc",
"pragma_Admin": "0x60203a3ff6a165f70e5ce47a82c500d3a5b79097e0db32ec34b0959d8e8af54",
"pragma_Ownable": "0x60203a3ff6a165f70e5ce47a82c500d3a5b79097e0db32ec34b0959d8e8af54",
"pragma_PublisherRegistry": "0x306288971002bd7906e3a607d504dfb28dcbdc7655a115984e567dce3b67e8f",
"pragma_SummaryStats": "0x3b5bf1c2f918de14620b3c63e2c6543cf0a138df258bce3d03e3fb0b7d2183a",
"pragma_Randomness": "0x3b5d93672493bdd1c0881bfa590c6cea59e4cec8659272ea340da5b8067016c",
Expand Down
9 changes: 9 additions & 0 deletions deployments/sepolia/declarations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pragma_Oracle": "0x40a2430b48587833abc2e912335cffd863c010e2c798d005d9bcace56a156fc",
"pragma_Ownable": "0x7b50a7a9bbb75d08248135003f1c87f0d44ba23018dc0ca480ac37a901531f3",
"pragma_PublisherRegistry": "0x306288971002bd7906e3a607d504dfb28dcbdc7655a115984e567dce3b67e8f",
"pragma_SummaryStats": "0x3b5bf1c2f918de14620b3c63e2c6543cf0a138df258bce3d03e3fb0b7d2183a",
"pragma_Randomness": "0x1a4de6fd18f5358f9c815ca98b08c707c77e6583f10e5ebf83daa6541217e2a",
"pragma_ExampleRandomness": "0x521a9f8d2db3faf168854902adb6bda2648d1de695c3cfa88946080ec567cbb",
"pragma_YieldCurve": "0x55a7af6d2df5730c784ec31ca9f71e66f19e8cb78359d23f51aececcc1c04eb"
}
22 changes: 22 additions & 0 deletions deployments/sepolia/deployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"pragma_PublisherRegistry": {
"address": "0x732b618bc92e3919e28dd3b3aff21079b2507c1f51b8a194ce90300e995cb",
"tx": "0x696821818ebcaf3052d9af16b2e3250dfea98fb4ab8d9caccd1f7e8ffced82f"
},
"pragma_Oracle": {
"address": "0x5acaa0ef3a6837c98ddeae516fa3f6022018cf646914d921842e46fc00c35d3",
"tx": "0x6700eac1d61330b9831384e358985681ccaf90eea540f299f9fc58550372e17"
},
"pragma_SummaryStats": {
"address": "0x185b147a3e03043e0232ec6fcf17143614481cc29a505c7d9c4b29e98c1f14e",
"tx": "0x5586671f1d7d1e7744ca88b19927ab12ef9ac233d70f2f9bbed650c32bcd38f"
},
"pragma_Randomness": {
"address": "0x556bd6988d786777bb5b1ee337c63f60f30d8200818b59b29e54afc27266a46",
"tx": "0x201c3bfe0ea8d3476f97d7430d947e804e58c9184ee80ffab2a2d0582a7aaf2"
},
"pragma_ExampleRandomness": {
"address": "0x6b95c03d088974e17cc87a3b9b2650d7b0c7098e2ec968f6d852249e808f5dc",
"tx": "0x226ec4801c9b3e7428ffcbec16c75bb3cf7c90ed2c9e189ac8d310e41157665"
}
}
16 changes: 14 additions & 2 deletions scripts/add_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
call,
)
from pragma.core.types import Currency, Pair

import argparse
import os
from dotenv import load_dotenv
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


load_dotenv()
currencies_to_add = []
pairs_to_add = [
Pair("ETH/USDT", "ETH", "USDT"),
Expand All @@ -35,19 +38,28 @@


async def main():
parser = argparse.ArgumentParser(description="Deploy contracts to Katana")
parser.add_argument('--port', type=int, help='Port number(not required)', required=False)
args = parser.parse_args()
if os.getenv("STARKNET_NETWORK") == "katana" and args.port is None:
logger.warning(
f"⚠️ --port not set, defaulting to 5050"
)
args.port = 5050
# Add Currencies
for currency in currencies_to_add:
print(currency.to_dict())
tx_hash = await invoke(
"pragma_Oracle",
"add_currency",
currency.serialize(),
port = args.port
)
logger.info(f"Added currency {currency} with tx hash {hex(tx_hash)}")

# Add Pairs
for pair in pairs_to_add:
tx_hash = await invoke("pragma_Oracle", "add_pair", pair.serialize())
tx_hash = await invoke("pragma_Oracle", "add_pair", pair.serialize(), port= args.port)
logger.info(f"Added pair {pair} with tx hash {hex(tx_hash)}")


Expand Down
27 changes: 21 additions & 6 deletions scripts/deploy_pragma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import logging
from asyncio import run
from math import ceil, log

import argparse
from scripts.utils.constants import (
COMPILED_CONTRACTS,
currencies,
NETWORK,
pairs,
)
import os
from dotenv import load_dotenv
from scripts.utils.starknet import (
dump_declarations,
dump_deployments,
Expand All @@ -21,35 +23,47 @@
call
)

load_dotenv()
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %% Main
async def main():

#Retrieve port from parser
parser = argparse.ArgumentParser(description="Deploy contracts to Katana")
parser.add_argument('--port', type=int, help='Port number(not required)', required=False)
args = parser.parse_args()
if os.getenv("STARKNET_NETWORK") == "katana" and args.port is None:
logger.warning(
f"⚠️ --port not set, defaulting to 5050"
)
args.port = 5050
# %% Declarations
chain_id = NETWORK["chain_id"]
logger.info(
f"ℹ️ Connected to CHAIN_ID { chain_id }"
)
account = await get_starknet_account()
account = await get_starknet_account(port= args.port)
logger.info(f"ℹ️ Using account {hex(account.address)} as deployer")

class_hash = {
contract["contract_name"]: await declare_v2(contract["contract_name"])
contract["contract_name"]: await declare_v2(contract["contract_name"], args.port)
for contract in COMPILED_CONTRACTS
}
dump_declarations(class_hash)

# %% Deployments
class_hash = get_declarations()
await get_eth_contract()
await get_eth_contract(port= args.port)

deployments = {}
deployments["pragma_PublisherRegistry"] = await deploy_v2(
"pragma_PublisherRegistry",
account.address, # owner
account.address, # owner,
port =args.port
)

new_currencies = [currency.to_dict() for currency in currencies]
Expand All @@ -61,8 +75,9 @@ async def main():
deployments["pragma_PublisherRegistry"]["address"], # publisher_registry
new_currencies,
new_pairs,
port =args.port
)

dump_deployments(deployments)

logger.info("✅ Deployment Completed")
Expand Down
46 changes: 33 additions & 13 deletions scripts/deploy_randomness.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import logging
from asyncio import run
from math import ceil, log

import os
from dotenv import load_dotenv
import argparse
from scripts.utils.constants import (
COMPILED_CONTRACTS,
currencies,
Expand All @@ -19,36 +21,54 @@
dump_declarations
)

load_dotenv()

logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %% Main
async def main():
parser = argparse.ArgumentParser(description="Deploy contracts to Katana")
parser.add_argument('--port', type=int, help='Port number(not required)', required=False)
args = parser.parse_args()
if os.getenv("STARKNET_NETWORK") == "katana" and args.port is None:
logger.warning(
f"⚠️ --port not set, defaulting to 5050"
)
args.port = 5050
# %% Declarations
chain_id = NETWORK["chain_id"]
logger.info(
f"ℹ️ Connected to CHAIN_ID { chain_id }"
)
account = await get_starknet_account()
account = await get_starknet_account(port= args.port)
logger.info(f"ℹ️ Using account {hex(account.address)} as deployer")

# class_hash = {
# contract["contract_name"]: await declare_v2(contract["contract_name"])
# for contract in COMPILED_CONTRACTS
# }
# dump_declarations(class_hash)
if args.port is not None:
class_hash = {
contract["contract_name"]: await declare_v2(contract["contract_name"], port=args.port)
for contract in COMPILED_CONTRACTS
}
dump_declarations(class_hash)

# %% Deployment

# deployments = get_deployments()
# deployments["pragma_Randomness"] = await deploy_v2(
# "pragma_Randomness",
# int(os.getenv("TESTNET_ACCOUNT_ADDRESS"), 16),
# 2061139992776959994838533810929826594222370735645675137341826408353556487187,
# ETH_TOKEN_ADDRESS,
# int(deployments["pragma_Oracle"]["address"], 16),
# port=args.port
# )
deployments = get_deployments()
deployments["pragma_Randomness"] = await deploy_v2(
"pragma_Randomness",
int("0x03e437FB56Bb213f5708Fcd6966502070e276c093ec271aA33433b89E21fd31f", 16),
int("0xfcfc1eda34191fdb06acb883c4b5d8a70db47711252c26d77094053160ba5e", 16),
ETH_TOKEN_ADDRESS,
int(deployments["pragma_Oracle"]["address"], 16),
deployments["pragma_ExampleRandomness"] = await deploy_v2(
"pragma_ExampleRandomness",
int("0x5faa12cb652c1ec3cf667e651d001d8155653d8d8ad2d1ab92bd965e081a605", 16),
port = args.port
)

dump_deployments(deployments)
Expand Down
Loading

0 comments on commit f98dfce

Please sign in to comment.