feat: Add SUI tokens
All checks were successful
Build Docker / BuildImage (push) Successful in 37s

This commit is contained in:
Nathan Woodburn 2024-12-05 22:48:43 +11:00
parent a67f75e788
commit 6a628494ad
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
20 changed files with 81 additions and 22 deletions

View File

@ -1 +1 @@
{"timestamp": 1733390401.1929479, "result": 3920.13}
{"timestamp": 1733397804.3863032, "result": 3929.35}

View File

@ -1 +1 @@
{"timestamp": 1733390448.2838762, "result": 1.22}
{"timestamp": 1733397866.6526587, "result": 1.23}

View File

@ -1 +1 @@
{"timestamp": 1733390447.3589993, "result": 4.19}
{"timestamp": 1733397805.5214965, "result": 4.2}

View File

@ -1 +1 @@
{"timestamp": 1733390400.7691364, "result": 249.8}
{"timestamp": 1733397803.5678928, "result": 253.67}

View File

@ -0,0 +1 @@
{"timestamp": 1733399146.2576907, "result": 3.86}

View File

@ -1 +1 @@
{"timestamp": 1733388581.604049, "result": 235.89}
{"timestamp": 1733397797.9360924, "result": 238.75}

View File

@ -0,0 +1 @@
{"timestamp": 1733399182.7510748, "result": 4.0}

View File

@ -1 +1 @@
{"timestamp": 1733390403.2274024, "result": 129.72815534}
{"timestamp": 1733397796.5670946, "result": 129.72815534}

View File

@ -1 +1 @@
{"timestamp": 1733390450.351181, "result": 0.005776758}
{"timestamp": 1733397869.634003, "result": 0.009266758}

View File

@ -1 +1 @@
{"timestamp": 1733390400.5671725, "result": 1.36267944462}
{"timestamp": 1733397797.9369814, "result": 2.2124384725}

View File

@ -1 +1 @@
{"timestamp": 1733390400.5661695, "result": 1.001}
{"timestamp": 1733397802.560489, "result": 1.0}

View File

@ -1 +1 @@
{"timestamp": 1733390451.4364688, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 249.8, "value": 9.9459099016, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3920.13, "value": 10.0251444555, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.19, "value": 10.06579203, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}
{"timestamp": 1733397805.5292268, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 253.67, "value": 10.09999585564, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3929.35, "value": 10.0487232225, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.2, "value": 10.0898154, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}

View File

@ -0,0 +1 @@
{"timestamp": 1733397988.7280235, "result": 3.86}

View File

@ -1 +1 @@
{"timestamp": 1733390500.4894085, "result": 132.43410277172}
{"timestamp": 1733397866.6532238, "result": 134.31370216064}

View File

@ -1 +1 @@
{"timestamp": 1733390448.4887109, "result": 82.815227}
{"timestamp": 1733397806.33151, "result": 82.815227}

View File

@ -51,6 +51,8 @@ stWDBRN_token_mint = Pubkey.from_string(
vault_sol_address = Pubkey.from_string(
"NWywvhcqdkJsm1s9VVviPm9UfyDtyCW9t8kDb24PDPN")
vault_cardano_address = "stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna"
vault_sui_address = "0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da"
fiat = "USD"
usd_to_fiat = 1
@ -178,10 +180,10 @@ def get_coin_price(coin_id):
return 0
@cache.file_cache()
def get_token_price(token_address: str):
def get_token_price(token_address: str, chain='solana'):
try:
price = coingecko_client.get_token_price(
id='solana', contract_addresses=token_address, vs_currencies=fiat)
id=chain, contract_addresses=token_address, vs_currencies=fiat)
return price[token_address][fiat.lower()]
except:
return 0
@ -201,14 +203,11 @@ def getSolBalance() -> int:
vault_sol_address).value / 1000000000
return SOLbalance
@cache.file_cache()
def getSolValue() -> int:
SOLbalance = solana_client.get_balance(
vault_sol_address).value / 1000000000
SOLbalance = getSolBalance()
SOLPrice = get_coin_price("solana")
return SOLbalance * SOLPrice
@cache.file_cache()
def getVaultBalance() -> int:
# Get balance of vault
vaultBalance = 0
@ -258,9 +257,12 @@ def getTokens():
token["symbol"] = data["symbol"]
tokens.append(token)
# Get SUI tokens
tokens.extend(getSuiTokens(vault_sui_address))
return tokens
def getTokenData(tokenMint):
def getTokenData(tokenMint, chain='solana'):
if not os.path.exists("tokens"):
os.makedirs("tokens")
@ -270,7 +272,7 @@ def getTokenData(tokenMint):
return data
else:
data = coingecko_client.get_coin_info_from_contract_address_by_id(
'solana', tokenMint)
chain, tokenMint)
with open(f"tokens/{tokenMint}.json", "w") as f:
json.dump(data, f)
return data
@ -318,6 +320,54 @@ def getCardanoValue(address: str):
# endregion
# region Sui
@cache.file_cache()
def getSuiTokens(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
]
}
# Define headers (if needed)
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 API Routes
@app.route("/api/v1/token")

Binary file not shown.

View File

@ -134,7 +134,7 @@
// Create table header
const headerRow = document.createElement('tr');
['Name', 'Amount', 'Value'].forEach((headerText, index) => {
['Name', 'Amount', 'USD Value'].forEach((headerText, index) => {
const th = document.createElement('th');
th.textContent = headerText;
th.style.border = '1px solid #ccc';
@ -142,7 +142,7 @@
th.style.backgroundColor = '#333';
th.style.color = 'white';
if (headerText === 'Value') {
if (headerText === 'USD Value') {
th.style.cursor = 'pointer'; // Make it clear this header is clickable
th.addEventListener('click', () => sortTableByValue(tbody));
}
@ -318,6 +318,10 @@ function sortTableByValue(tbody) {
<td>Cardano</td>
<td>stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna</td>
</tr>
<tr>
<td>Sui</td>
<td>0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da</td>
</tr>
</tbody>
</table>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long