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

add burrow rewards #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
97 changes: 82 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
from burrow.tool_util import error, is_number
from burrow.circulating_supply import update_marketcap, get_circulating_supply
from loguru import logger
from burrow.rewards import get_rewards_data


service_version = "20240221.01"
service_version = "20241018.01"
Welcome = 'Welcome to burrow SDK API server, ' + service_version
app = Flask(__name__)

Expand Down Expand Up @@ -110,6 +111,8 @@ def handle_supply():
try:
request_data = request.get_json()
token_id = request_data["token_id"]
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
is_collateral = request_data["is_collateral"]
pool_id = ""
if "pool_id" in request_data:
Expand All @@ -119,7 +122,7 @@ def handle_supply():
amount = request_data["amount"]
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "" or is_collateral is None or is_collateral == "":
if is_collateral is None or is_collateral == "":
return error("The required field is empty", "1002")
try:
if token_id.startswith("shadow_ref_v1-"):
Expand All @@ -141,14 +144,17 @@ def handle_burrow():
request_data = request.get_json()
token_id = request_data["token_id"]
amount = request_data["amount"]
position = ""
if "position" in request_data:
position = request_data["position"]
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return burrow(token_id, amount)
return burrow(token_id, amount, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -189,14 +195,17 @@ def handle_repay_from_wallet():
request_data = request.get_json()
token_id = request_data["token_id"]
amount = request_data["amount"]
position = ""
if "position" in request_data:
position = request_data["position"]
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return repay_from_wallet(token_id, amount)
return repay_from_wallet(token_id, amount, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand All @@ -208,14 +217,17 @@ def handle_repay_from_supplied():
request_data = request.get_json()
token_id = request_data["token_id"]
amount = request_data["amount"]
position = ""
if "position" in request_data:
position = request_data["position"]
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return repay_from_supplied(token_id, amount)
return repay_from_supplied(token_id, amount, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -264,14 +276,18 @@ def handle_decrease_collateral():
request_data = request.get_json()
token_id = request_data["token_id"]
amount = request_data["amount"]
if "position" in request_data:
position = request_data["position"]
else:
position = token_id
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return decrease_collateral(token_id, amount)
return decrease_collateral(token_id, amount, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -371,7 +387,16 @@ def handle_max_supply_balance(account_id, token):
@app.route('/max_burrow_balance/<account_id>/<token>', methods=['GET'])
def handle_max_burrow_balance(account_id, token):
try:
return max_burrow_balance(account_id, token)
return max_burrow_balance(account_id, token, "")
except Exception as e:
msg = str(e.args)
return error(msg, "1001")


@app.route('/max_burrow_balance/<account_id>/<token>/<position>', methods=['GET'])
def handle_max_burrow_balance_lp(account_id, token, position):
try:
return max_burrow_balance(account_id, token, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand All @@ -398,7 +423,16 @@ def handle_max_adjust_balance(account_id, token):
@app.route('/max_repay_from_wallet/<account_id>/<token>', methods=['GET'])
def handle_max_repay_from_wallet(account_id, token):
try:
return max_repay_from_wallet(account_id, token)
return max_repay_from_wallet(account_id, token, token)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")


@app.route('/max_repay_from_wallet/<account_id>/<token>/<position>', methods=['GET'])
def handle_max_repay_from_wallet_lp(account_id, token, position):
try:
return max_repay_from_wallet(account_id, token, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand All @@ -407,7 +441,16 @@ def handle_max_repay_from_wallet(account_id, token):
@app.route('/max_repay_from_account/<account_id>/<token>', methods=['GET'])
def handle_max_repay_from_account(account_id, token):
try:
return max_repay_from_account(account_id, token)
return max_repay_from_account(account_id, token, token)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")


@app.route('/max_repay_from_account/<account_id>/<token>/<position>', methods=['GET'])
def handle_max_repay_from_account_lp(account_id, token, position):
try:
return max_repay_from_account(account_id, token, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -454,14 +497,18 @@ def handle_burrow_health_factor():
token_id = request_data["token_id"]
amount = request_data["amount"]
account_id = request_data["account_id"]
if "position" in request_data:
position = request_data["position"]
else:
position = token_id
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return burrow_health_factor(token_id, account_id, amount, True)
return burrow_health_factor(token_id, account_id, amount, True, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -534,14 +581,18 @@ def handle_repay_from_wallet_health_factor():
token_id = request_data["token_id"]
amount = request_data["amount"]
account_id = request_data["account_id"]
if "position" in request_data:
position = request_data["position"]
else:
position = token_id
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return burrow_health_factor(token_id, account_id, amount, False)
return burrow_health_factor(token_id, account_id, amount, False, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand All @@ -554,14 +605,19 @@ def handle_repay_from_account_health_factor():
token_id = request_data["token_id"]
amount = request_data["amount"]
account_id = request_data["account_id"]
if "position" in request_data:
position = request_data["position"]
else:
position = token_id
if not is_number(amount):
return error("Amount Non numeric", "1003")
except Exception as e:
return error("The required field is empty", "1002")
if token_id is None or token_id == "":
return error("The required field is empty", "1002")
try:
return repay_from_account_health_factor(token_id, account_id, amount)
# return repay_from_account_health_factor(token_id, account_id, amount, position)
return burrow_health_factor(token_id, account_id, amount, False, position)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down Expand Up @@ -633,14 +689,25 @@ def handle_get_pool_shares():
def handle_get_shadow_records():
try:
request_data = request.get_json()
contract_id = request_data["contract_id"]
account_id = request_data["account_id"]
except Exception as e:
return error("The required field is empty", "1002")
if contract_id is None or contract_id == "" or account_id is None or account_id == "":
if account_id is None or account_id == "":
return error("The required field is empty", "1002")
try:
return get_shadow_records(contract_id, account_id)
return get_shadow_records(account_id)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")


@app.route('/get_rewards', methods=['GET'])
def handle_get_rewards():
try:
import asyncio
from flask import jsonify
ret = asyncio.run(get_rewards_data())
return jsonify(ret)
except Exception as e:
msg = str(e.args)
return error(msg, "1001")
Expand Down
Loading