Skip to content

Commit

Permalink
🗑️ cleanup + upgrade (#30)
Browse files Browse the repository at this point in the history
* 🗑️ remove bits_manipulation

* ✨ add GeckoTerminal as source

* 🗑️ cleanup and minor changes

- add more base currencies/pairs 👍
- remove makefile 🎌
- update minor version ⬆️
- fix upgrade function 🐛
  • Loading branch information
EvolveArt authored Sep 16, 2023
1 parent 0dc4afb commit 067fa55
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 934 deletions.
44 changes: 0 additions & 44 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pragma"
version = "0.1.0"
version = "0.2.0"


[dependencies]
Expand Down
213 changes: 120 additions & 93 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pragma"
version = "0.1.0"
version = "0.2.0"
description = "Pragma, the provable oracle."
authors = ["0xevolve <matthias@pragmaoracle.com>"]
readme = "README.md"
Expand All @@ -9,7 +9,7 @@ packages = [{ include = "scripts" }]
[tool.poetry.dependencies]
python = ">=3.9,<3.10"
starknet-py = "0.18.1"
pragma-sdk = "1.0.0b4"
pragma-sdk = "1.0.0b6"
python-dotenv = "^1.0.0"
case-converter = "^1.1.0"

Expand Down
90 changes: 48 additions & 42 deletions scripts/register_publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@
declare_v2,
call,
get_deployments,
str_to_felt
str_to_felt,
)

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

THIRD_PARTY_SOURCES = [
"ASCENDEX",
"BITSTAMP",
"CEX",
"COINBASE",
"DEFILLAMA",
"GEMINI",
"KAIKO",
"OKX",
"BINANCE",
"BYBIT",
"ASCENDEX",
"BITSTAMP",
"CEX",
"COINBASE",
"DEFILLAMA",
"GEMINI",
"KAIKO",
"OKX",
"BINANCE",
"BYBIT",
"GECKOTERMINAL",
]

network = "testnet"
Expand All @@ -64,46 +65,51 @@
["FOURLEAF"],
]
publisher_address = [
0x0624EBFb99865079bd58CFCFB925B6F5Ce940D6F6e41E118b8A72B7163fB435c,
0xcf357fa043a29f7ea06736cc253d8d6d8a208c03b92ffb4b50074f8470818b,
0x6bcdcf68f77a80571b55fc1651a26dc04939dfdd698485be24fa5ac4dbf84b1,
0x17a6f7e8196c9a7aff90b7cc4bf98842894ecc2b9cc1a3703a1aab948fce208,
0x1d8e01188c4c8984fb19f00156491787e64fd2de1c3ce4eb9571924c540cf3b,
0x4e2863fd0ff85803eef98ce5dd8272ab21c6595537269a2cd855a10ebcc18cc
0x0624EBFB99865079BD58CFCFB925B6F5CE940D6F6E41E118B8A72B7163FB435C,
0xCF357FA043A29F7EA06736CC253D8D6D8A208C03B92FFB4B50074F8470818B,
0x6BCDCF68F77A80571B55FC1651A26DC04939DFDD698485BE24FA5AC4DBF84B1,
0x17A6F7E8196C9A7AFF90B7CC4BF98842894ECC2B9CC1A3703A1AAB948FCE208,
0x1D8E01188C4C8984FB19F00156491787E64FD2DE1C3CE4EB9571924C540CF3B,
0x4E2863FD0FF85803EEF98CE5DD8272AB21C6595537269A2CD855A10EBCC18CC,
]
admin_address = 0x02356b628D108863BAf8644c945d97bAD70190AF5957031f4852d00D0F690a77

admin_address = 0x02356B628D108863BAF8644C945D97BAD70190AF5957031F4852D00D0F690A77


# %% Main
async def main():

deployments = get_deployments()

for publisher, sources, address in zip(
for publisher, sources, address in zip(
publishers, publishers_sources, publisher_address
):
(existing_address,) = await call("pragma_PublisherRegistry", "get_publisher_address", publisher)
if existing_address == 0:
tx_hash = await invoke("pragma_PublisherRegistry", "add_publisher", [publisher, address])
logger.info(f"Registered new publisher {publisher} with tx {hex(tx_hash)}")
elif existing_address != address:
logger.info(
f"Publisher {publisher} registered with address {hex(existing_address)} but config has address {hex(address)}. Exiting..."
(existing_address,) = await call(
"pragma_PublisherRegistry", "get_publisher_address", publisher
)
return
if existing_address == 0:
tx_hash = await invoke(
"pragma_PublisherRegistry", "add_publisher", [publisher, address]
)
logger.info(f"Registered new publisher {publisher} with tx {hex(tx_hash)}")
elif existing_address != address:
logger.info(
f"Publisher {publisher} registered with address {hex(existing_address)} but config has address {hex(address)}. Exiting..."
)
return

(existing_sources,) = await call("pragma_PublisherRegistry", "get_publisher_sources", publisher)
new_sources = [x for x in sources if str_to_felt(x) not in existing_sources]
if len(new_sources) > 0:
tx_hash = await invoke("pragma_PublisherRegistry", "add_sources_for_publisher", [publisher, len(new_sources), *new_sources])
logger.info(
f"Registered sources {new_sources} for publisher {publisher} with tx {hex(tx_hash)}"
(existing_sources,) = await call(
"pragma_PublisherRegistry", "get_publisher_sources", publisher
)

logger.info(
f"ℹ️ Sources added for publisher 'PRAGMA' "
)
new_sources = [x for x in sources if str_to_felt(x) not in existing_sources]
if len(new_sources) > 0:
tx_hash = await invoke(
"pragma_PublisherRegistry",
"add_sources_for_publisher",
[publisher, len(new_sources), *new_sources],
)
logger.info(
f"Registered sources {new_sources} for publisher {publisher} with tx {hex(tx_hash)}"
)

logger.info(f"ℹ️ Publisher Registry initialization completed. ")


if __name__ == "__main__":
run(main())
run(main())
126 changes: 36 additions & 90 deletions scripts/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import os
import re
import logging
from enum import Enum
from pathlib import Path

from dotenv import load_dotenv
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.models.chains import StarknetChainId
from pragma.core.types import Currency, Pair
from typing import List

load_dotenv()

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

ETH_TOKEN_ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7

NETWORKS = {
Expand Down Expand Up @@ -74,10 +79,9 @@
)




BUILD_DIR = Path("target/dev")
BUILD_DIR.mkdir(exist_ok=True, parents=True)

SOURCE_DIR = Path("src")
CONTRACTS = {p.stem: p for p in list(SOURCE_DIR.glob("**/*.cairo"))}

Expand All @@ -91,96 +95,10 @@
{"contract_name": "pragma_SummaryStats", "is_account_contract": False},
]

def str_to_felt(text):
if text.upper() != text:
logger.warning(f"Converting lower to uppercase for str_to_felt: {text}")
text = text.upper()
b_text = bytes(text, "utf-8")
return int.from_bytes(b_text, "big")

class Currency:
id: int
decimals: int
is_abstract_currency: bool
starknet_address: int
ethereum_address: int

def __init__(
self,
id,
decimals,
is_abstract_currency,
starknet_address=None,
ethereum_address=None,
):
if type(id) == str:
id = str_to_felt(id)
self.id = id

self.decimals = decimals

if type(is_abstract_currency) == int:
is_abstract_currency = bool(is_abstract_currency)
self.is_abstract_currency = is_abstract_currency

if starknet_address is None:
starknet_address = 0
self.starknet_address = starknet_address

if ethereum_address is None:
ethereum_address = 0
self.ethereum_address = ethereum_address

def serialize(self) -> List[str]:
return [
self.id,
self.decimals,
self.is_abstract_currency,
self.starknet_address,
self.ethereum_address,
]

def to_dict(self) -> dict:
return {
"id": self.id,
"decimals": self.decimals,
"is_abstract_currency": self.is_abstract_currency,
"starknet_address": self.starknet_address,
"ethereum_address": self.ethereum_address,
}


class Pair:
id: int
quote_currency_id: int
base_currency_id: int

def __init__(self, id, quote_currency_id, base_currency_id):
if type(id) == str:
id = str_to_felt(id)
self.id = id

if type(quote_currency_id) == str:
quote_currency_id = str_to_felt(quote_currency_id)
self.quote_currency_id = quote_currency_id

if type(base_currency_id) == str:
base_currency_id = str_to_felt(base_currency_id)
self.base_currency_id = base_currency_id

def serialize(self) -> List[str]:
return [self.id, self.quote_currency_id, self.base_currency_id]

def to_dict(self) -> dict:
return {
"id": self.id,
"quote_currency_id": self.quote_currency_id,
"base_currency_id": self.base_currency_id,
}


currencies = [
Currency("USD", 8, 1, 0, 0),
Currency("EUR", 8, 1, 0, 0),
Currency(
"BTC",
8,
Expand Down Expand Up @@ -223,12 +141,40 @@ def to_dict(self) -> dict:
0x001108CDBE5D82737B9057590ADAF97D34E74B5452F0628161D237746B6FE69E,
0x6B175474E89094C44DA98B954EEDEAC495271D0F,
),
Currency(
"LORDS",
18,
0,
0x0124AEB495B947201F5FAC96FD1138E326AD86195B98DF6DEC9009158A533B49,
0x686F2404E77AB0D9070A46CDFB0B7FECDD2318B0,
),
Currency(
"R",
18,
0,
0x01FA2FB85F624600112040E1F3A848F53A37ED5A7385810063D5FE6887280333,
0x183015A9BA6FF60230FDEADC3F43B3D788B13E21,
),
Currency(
"WSTETH",
18,
0,
0x042B8F0484674CA266AC5D08E4AC6A3FE65BD3129795DEF2DCA5C34ECC5F96D2,
0x7F39C581F595B53C5CB19BD0B3F8DA6C935E2CA0,
),
]
pairs = [
Pair("ETH/USD", "ETH", "USD"),
Pair("ETH/USDT", "ETH", "USDT"),
Pair("BTC/USD", "BTC", "USD"),
Pair("BTC/USDT", "BTC", "USDT"),
Pair("BTC/EUR", "BTC", "EUR"),
Pair("WBTC/USD", "WBTC", "USD"),
Pair("WBTC/BTC", "WBTC", "BTC"),
Pair("USDC/USD", "USDC", "USD"),
Pair("USDT/USD", "USDT", "USD"),
Pair("DAI/USD", "DAI", "USD"),
Pair("LORDS/USD", "LORDS", "USD"),
Pair("R/USD", "R", "USD"),
Pair("WSTETH/USD", "WSTETH", "USD"),
]
1 change: 0 additions & 1 deletion src/operations.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod bits_manipulation;
mod sorting;
mod time_series;
2 changes: 0 additions & 2 deletions src/operations/bits_manipulation.cairo

This file was deleted.

Loading

0 comments on commit 067fa55

Please sign in to comment.