Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: new cg api #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from flask_caching import Cache
from web3 import Web3


def create_app():
app = Flask(__name__)

Expand All @@ -18,7 +19,9 @@ def create_app():

# Connect to Ethereum node (using Infura as an example)
ALCHEMY_API_KEY = os.getenv("ALCHEMY_API_KEY")
w3 = Web3(Web3.HTTPProvider(f"https://eth-mainnet.g.alchemy.com/v2/{ALCHEMY_API_KEY}"))
w3 = Web3(
Web3.HTTPProvider(f"https://eth-mainnet.g.alchemy.com/v2/{ALCHEMY_API_KEY}")
)

# Replace with your contract's ABI and address
OLAS_CONTRACT_ADDRESS = "0x0001A500A6B18995B03f44bb040A5fFc28E45CB0"
Expand All @@ -37,7 +40,6 @@ def create_app():
# Cache timeout (e.g., 10 minutes)
CACHE_TIMEOUT = 600


@app.route("/circulating_supply", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
def get_circulating_supply():
Expand All @@ -51,9 +53,13 @@ def get_circulating_supply():
veolas_total_supply = olas_contract.functions.balanceOf(
VEOLAS_CONTRACT_ADDRESS
).call()
valory_multisig = olas_contract.functions.balanceOf(VALORY_MULTISIG_ADDRESS).call()
valory_multisig = olas_contract.functions.balanceOf(
VALORY_MULTISIG_ADDRESS
).call()
timelock = olas_contract.functions.balanceOf(TIMELOCK_ADDRESS).call()
circulating_supply = total_supply - veolas_total_supply - valory_multisig - timelock
circulating_supply = (
total_supply - veolas_total_supply - valory_multisig - timelock
)

response = {
"success": True,
Expand All @@ -66,7 +72,6 @@ def get_circulating_supply():
}
return jsonify(response)


@app.route("/circulating_supply_simple", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
def get_circulating_supply_simple():
Expand All @@ -83,13 +88,44 @@ def get_circulating_supply_simple():
buolas_total_supply = olas_contract.functions.balanceOf(
BUOLAS_CONTRACT_ADDRESS
).call()
valory_multisig = olas_contract.functions.balanceOf(VALORY_MULTISIG_ADDRESS).call()
valory_multisig = olas_contract.functions.balanceOf(
VALORY_MULTISIG_ADDRESS
).call()
timelock = olas_contract.functions.balanceOf(TIMELOCK_ADDRESS).call()
circulating_supply = total_supply - veolas_total_supply - valory_multisig - timelock
circulating_supply = (
total_supply - veolas_total_supply - valory_multisig - timelock
)

circulating_supply_decimals = circulating_supply / 10**18
return str(circulating_supply_decimals)

@app.route("/circulating_supply_cg", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
def get_circulating_supply_cg():
"""Get circulating suply api endpoint."""
total_supply = olas_contract.functions.totalSupply().call()
# buOLAS entirely burned
buolas_total_supply = olas_contract.functions.balanceOf(
BUOLAS_CONTRACT_ADDRESS
).call()
total_supply -= buolas_total_supply
veolas_total_supply = olas_contract.functions.balanceOf(
VEOLAS_CONTRACT_ADDRESS
).call()
buolas_total_supply = olas_contract.functions.balanceOf(
BUOLAS_CONTRACT_ADDRESS
).call()
valory_multisig = olas_contract.functions.balanceOf(
VALORY_MULTISIG_ADDRESS
).call()
timelock = olas_contract.functions.balanceOf(TIMELOCK_ADDRESS).call()
circulating_supply = (
total_supply - veolas_total_supply - valory_multisig - timelock
)

circulating_supply_decimals = circulating_supply / 10**18
response = {"result": str(circulating_supply_decimals)}
return jsonify(response)

@app.route("/total_supply", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
Expand All @@ -112,7 +148,6 @@ def get_total_supply():
}
return jsonify(response)


@app.route("/total_supply_simple", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
def get_total_supply_simple():
Expand All @@ -126,12 +161,25 @@ def get_total_supply_simple():
total_supply_decimals = total_supply / 10**18
return str(total_supply_decimals)

@app.route("/total_supply_cg", methods=["GET"])
@cache.cached(timeout=CACHE_TIMEOUT)
def get_total_supply_cg():
"""Get total suply api endpoint."""
total_supply = olas_contract.functions.totalSupply().call()
# buOLAS entirely burned
buolas_total_supply = olas_contract.functions.balanceOf(
BUOLAS_CONTRACT_ADDRESS
).call()
total_supply -= buolas_total_supply
total_supply_decimals = total_supply / 10**18
response = {"result": str(total_supply_decimals)}
return jsonify(response)

@app.route("/check", methods=["GET"])
def check():
"""Simple health check."""
return jsonify({"check": "ok"})

return app


Expand Down
Loading