generated from nathanwoodburn/python-webserver-template
feat: Remove cache for token minting
All checks were successful
Build Docker / BuildImage (push) Successful in 1m1s
All checks were successful
Build Docker / BuildImage (push) Successful in 1m1s
This commit is contained in:
parent
606d31ba17
commit
50b125b4ef
2
cache/1981e30de11cf0845e8b5affb4dc75e0.json
vendored
2
cache/1981e30de11cf0845e8b5affb4dc75e0.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789918.4846652, "result": 3712.77}
|
||||
{"timestamp": 1733799272.475875, "result": 3736.24}
|
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789921.2481468, "result": 0.98991}
|
||||
{"timestamp": 1733799395.870956, "result": 1.003}
|
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789854.0988004, "result": 4.19}
|
||||
{"timestamp": 1733799333.3207755, "result": 4.19}
|
1
cache/32fbffa989a7d6c0472092fc8982713b.json
vendored
Normal file
1
cache/32fbffa989a7d6c0472092fc8982713b.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"timestamp": 1733801702.5651555, "result": 677.73}
|
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789856.5556242, "result": 227.89}
|
||||
{"timestamp": 1733799270.0382683, "result": 229.01}
|
2
cache/46c1ec7f5edb30c070003dc54e072f41.json
vendored
2
cache/46c1ec7f5edb30c070003dc54e072f41.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789919.6086097, "result": 3.77}
|
||||
{"timestamp": 1733799334.021167, "result": 3.73}
|
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789851.6413863, "result": 215.13}
|
||||
{"timestamp": 1733799267.6918225, "result": 216.09}
|
2
cache/6cc6c6a0b2d0654f551d33209c1fd824.json
vendored
2
cache/6cc6c6a0b2d0654f551d33209c1fd824.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789920.0200877, "result": 3.9}
|
||||
{"timestamp": 1733799334.533264, "result": 3.89}
|
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733790003.498964, "result": 388.922873018}
|
||||
{"timestamp": 1733801798.1054318, "result": 503.668701194}
|
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789851.2324705, "result": 0.034115021}
|
||||
{"timestamp": 1733799267.2864535, "result": 0.034115022}
|
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789854.9180405, "result": 1.0}
|
||||
{"timestamp": 1733799271.6589923, "result": 0.999083}
|
2
cache/a099e7e540e16a185b0279b9494e5099.json
vendored
2
cache/a099e7e540e16a185b0279b9494e5099.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789857.3777826, "result": 97129}
|
||||
{"timestamp": 1733799270.8399568, "result": 97397}
|
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789920.0303614, "result": [{"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.19, "value": 83.33822010000002, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 227.89, "value": 9.07355247188, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 97129, "value": 55.19646812, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3712.77, "value": 9.4948523595, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.77, "value": 3.4037449033900002, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 3.9, "value": 37.669608607799994, "name": "Volo Staked SUI", "symbol": "vsui"}]}
|
||||
{"timestamp": 1733801769.2307105, "result": [{"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 97397, "value": 55.34876716, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.19, "value": 83.33822010000002, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.239815492, "price": 229.01, "value": 54.92014582292, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3736.24, "value": 9.554873363999999, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa", "balance": 0.03683279, "price": 677.73, "value": 24.9626867667, "name": "Binance Coin (Wormhole)", "symbol": "bnb"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.73, "value": 3.36763089911, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.89, "value": 88.89785929792001, "name": "Volo Staked SUI", "symbol": "vsui"}]}
|
2
cache/c652e896f57f598d23e3dbebdb815ef6.json
vendored
2
cache/c652e896f57f598d23e3dbebdb815ef6.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789920.0300026, "result": [{"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.77, "value": 3.4037449033900002, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 3.9, "value": 37.669608607799994, "name": "Volo Staked SUI", "symbol": "vsui"}]}
|
||||
{"timestamp": 1733801799.938006, "result": [{"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.73, "value": 3.36763089911, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.89, "value": 88.89785929792001, "name": "Volo Staked SUI", "symbol": "vsui"}]}
|
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789920.8670247, "result": 82.815227}
|
||||
{"timestamp": 1733801766.3602786, "result": 82.815227}
|
2
cache/d4e81748ee91683b2c48adaa5cf95187.json
vendored
2
cache/d4e81748ee91683b2c48adaa5cf95187.json
vendored
@ -1 +1 @@
|
||||
{"timestamp": 1733789922.7835755, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 20, "updated": "1733729835", "initial": 20, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 46, "url": "https://dydx.trade/vault", "value": 23.29, "updated": "1733729835", "initial": 23, "bought": "1733300000", "type": "Lending"}]}
|
||||
{"timestamp": 1733801788.785157, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 50.01, "updated": "1733790668", "initial": 50, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 46, "url": "https://dydx.trade/vault", "value": 23.43, "updated": "1733790645", "initial": 23, "bought": "1733300000", "type": "Lending"}]}
|
158
server.py
158
server.py
@ -118,29 +118,9 @@ def wellknown(path):
|
||||
def index():
|
||||
tokenSupply = getTokenSupplyString()
|
||||
tokenValue = getTokenPrice()
|
||||
tokens = getTokens()
|
||||
solValue = getSolValue()
|
||||
vaultBalance = getVaultBalance()
|
||||
vaultBalance = "{:.2f}".format(vaultBalance)
|
||||
|
||||
# pie_chart_data = [(token['symbol'].upper(), token['value'], f"{token['name']}: ${'{:.2f}'.format(token['value'])}") for token in tokens]
|
||||
# pie_chart_data.append(("SOL", solValue, f"Solana: ${'{:.2f}'.format(solValue)}"))
|
||||
|
||||
# cardanoBalance = getCardanoValue(vault_cardano_address)
|
||||
# cardanoBalance = "{:.2f}".format(cardanoBalance)
|
||||
# pie_chart_data.append(
|
||||
# ("ADA", cardanoBalance, f"Cardano: ${cardanoBalance}"))
|
||||
|
||||
# other_investment_types = {}
|
||||
# other_investments = getOtherInvestments()
|
||||
# for investment in other_investments:
|
||||
# if investment["type"] not in other_investment_types:
|
||||
# other_investment_types[investment["type"]] = 0
|
||||
# other_investment_types[investment["type"]] += investment["value"]
|
||||
|
||||
# for investment_type in other_investment_types:
|
||||
# pie_chart_data.append((investment_type, other_investment_types[investment_type], f"{investment_type}: ${other_investment_types[investment_type]}"))
|
||||
|
||||
return render_template("index.html", value=tokenValue, supply=tokenSupply, vault=vaultBalance)
|
||||
|
||||
|
||||
@ -195,7 +175,7 @@ def getTokenSupplyString() -> str:
|
||||
supply = getTokenSupply()
|
||||
return "{:.2f}".format(supply)
|
||||
|
||||
@cache.file_cache(60)
|
||||
@cache.file_cache(120)
|
||||
def getTokenSupply() -> int:
|
||||
supply = solana_client.get_token_supply(stWDBRN_token_mint)
|
||||
return supply.value.ui_amount
|
||||
@ -226,7 +206,7 @@ def getVaultBalance() -> int:
|
||||
|
||||
return vaultBalance
|
||||
|
||||
@cache.file_cache(300)
|
||||
@cache.file_cache(120)
|
||||
def getTokens(chain:str=None):
|
||||
tokens = []
|
||||
|
||||
@ -242,6 +222,49 @@ def getTokens(chain:str=None):
|
||||
tokenAccounts = tokenAccounts.value
|
||||
|
||||
|
||||
for tokenAccount in tokenAccounts:
|
||||
pubkey = tokenAccount.pubkey
|
||||
account = solana_client.get_token_account_balance(pubkey)
|
||||
mint = tokenAccount.account.data[:32]
|
||||
mint = Pubkey(mint)
|
||||
# Decode the mint
|
||||
token = {
|
||||
"mint": str(mint),
|
||||
"balance": account.value.ui_amount
|
||||
}
|
||||
|
||||
token["price"] = get_token_price(token["mint"])
|
||||
token["value"] = token["price"] * token["balance"]
|
||||
|
||||
if token["value"] < 0.01:
|
||||
continue
|
||||
|
||||
data = getTokenData(str(mint))
|
||||
token["name"] = data["name"]
|
||||
token["symbol"] = data["symbol"]
|
||||
tokens.append(token)
|
||||
|
||||
if chain == "sui" or chain == None:
|
||||
# Get SUI tokens
|
||||
tokens.extend(getSuiTokens(vault_sui_address))
|
||||
|
||||
return tokens
|
||||
|
||||
def getTokens_nocache(chain:str=None):
|
||||
tokens = []
|
||||
|
||||
if chain == "solana" or chain == None:
|
||||
programID = Pubkey.from_string(
|
||||
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
|
||||
|
||||
tokenAccounts = solana_client.get_token_accounts_by_owner(
|
||||
vault_sol_address,
|
||||
TokenAccountOpts(program_id=programID)
|
||||
)
|
||||
|
||||
tokenAccounts = tokenAccounts.value
|
||||
|
||||
|
||||
for tokenAccount in tokenAccounts:
|
||||
pubkey = tokenAccount.pubkey
|
||||
account = solana_client.get_token_account_balance(pubkey)
|
||||
@ -329,7 +352,7 @@ def getCardanoValue(address: str):
|
||||
# endregion
|
||||
|
||||
# region Sui
|
||||
@cache.file_cache(300)
|
||||
@cache.file_cache(120)
|
||||
def getSuiTokens(address: str):
|
||||
url = "https://fullnode.mainnet.sui.io/"
|
||||
|
||||
@ -371,10 +394,51 @@ def getSuiTokens(address: str):
|
||||
|
||||
return tokens
|
||||
|
||||
def getSuiTokens_nocache(address: str):
|
||||
url = "https://fullnode.mainnet.sui.io/"
|
||||
|
||||
# Define the payload for the RPC call
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "suix_getAllBalances",
|
||||
"params": [
|
||||
address
|
||||
]
|
||||
}
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
# Make the POST request
|
||||
tokens = []
|
||||
try:
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
response.raise_for_status() # Raise an HTTPError for bad responses
|
||||
result = response.json()
|
||||
|
||||
for coin in result['result']:
|
||||
token = {
|
||||
"mint": coin['coinType'],
|
||||
"balance": int(coin['totalBalance'])/10**9,
|
||||
}
|
||||
token["price"] = get_token_price(token["mint"], 'sui')
|
||||
token["value"] = token["price"] * token["balance"]
|
||||
if token["value"] < 0.01:
|
||||
continue
|
||||
data = getTokenData(str(token["mint"]), 'sui')
|
||||
token["name"] = data["name"]
|
||||
token["symbol"] = data["symbol"]
|
||||
tokens.append(token)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
return tokens
|
||||
|
||||
# endregion
|
||||
|
||||
# region Other Investments
|
||||
@cache.file_cache(300)
|
||||
@cache.file_cache(60)
|
||||
def getOtherInvestments():
|
||||
data = requests.get("https://cloud.woodburn.au/s/stwdbrn_other/download/other_investments.json")
|
||||
return data.json()
|
||||
@ -567,7 +631,6 @@ def api_deposit():
|
||||
return jsonify(data)
|
||||
|
||||
def parseDeposit(data):
|
||||
stWDBRN_price = float(getTokenPrice())
|
||||
for tx in data:
|
||||
if 'nativeTransfers' not in tx:
|
||||
continue
|
||||
@ -601,9 +664,9 @@ def parseDeposit(data):
|
||||
solAmount = transfer['amount'] / 1000000000
|
||||
# Get USD value
|
||||
solValue = get_coin_price("solana") * solAmount
|
||||
stWDBRN_amount = solValue / stWDBRN_price
|
||||
stWDBRN_amount = round(stWDBRN_amount, 9)
|
||||
mint_stWDBRN(stWDBRN_amount, transfer['fromUserAccount'])
|
||||
usd_amount = solValue
|
||||
usd_amount = round(usd_amount, 9)
|
||||
mint_stWDBRN(usd_amount, transfer['fromUserAccount'])
|
||||
|
||||
for transfer in tx['tokenTransfers']:
|
||||
if transfer['toUserAccount'] != str(vault_sol_address):
|
||||
@ -612,15 +675,42 @@ def parseDeposit(data):
|
||||
# Get token data
|
||||
token_price = get_token_price(transfer['mint'])
|
||||
USDvalue = transfer['tokenAmount'] * token_price
|
||||
stWDBRN_amount = USDvalue / stWDBRN_price
|
||||
stWDBRN_amount = round(stWDBRN_amount, 9)
|
||||
mint_stWDBRN(stWDBRN_amount, transfer['fromUserAccount'])
|
||||
usd_amount = USDvalue
|
||||
usd_amount = round(usd_amount, 9)
|
||||
mint_stWDBRN(usd_amount, transfer['fromUserAccount'])
|
||||
|
||||
def mint_stWDBRN(amount, to_user_account):
|
||||
if amount < 0.5:
|
||||
print(f"Skipping minting of {amount} stWDBRN to {to_user_account} as it is less than 0.5", flush=True)
|
||||
|
||||
def stWDBRN_nocache():
|
||||
supply = solana_client.get_token_supply(stWDBRN_token_mint)
|
||||
supply = supply.value.ui_amount
|
||||
|
||||
vaultBalance = 0
|
||||
|
||||
SOLbalance = solana_client.get_balance(
|
||||
vault_sol_address).value / 1000000000
|
||||
SOLPrice = get_coin_price("solana")
|
||||
vaultBalance += SOLbalance * SOLPrice
|
||||
|
||||
tokens = getTokens_nocache()
|
||||
tokenValue = 0
|
||||
for token in tokens:
|
||||
tokenValue += token["value"]
|
||||
|
||||
vaultBalance += tokenValue
|
||||
vaultBalance += getCardanoValue(vault_cardano_address)
|
||||
vaultBalance += getOtherInvestmentsValue()
|
||||
|
||||
stWDBRN_price = vaultBalance/supply
|
||||
return stWDBRN_price
|
||||
|
||||
def mint_stWDBRN(USD_amount, to_user_account):
|
||||
if USD_amount < 0.5:
|
||||
print(f"Skipping minting of {USD_amount} USD to {to_user_account} as it is less than 0.5", flush=True)
|
||||
return
|
||||
|
||||
# Get stWDBRN price no cache
|
||||
stWDBRN_price = stWDBRN_nocache()
|
||||
amount = USD_amount / stWDBRN_price
|
||||
# Small fee for minting
|
||||
if amount > 10:
|
||||
amount = amount - 0.05
|
||||
|
1
tokens/9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa.json
Normal file
1
tokens/9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user