diff --git a/cache/10118a51009b13b2592c87579e15e61e.json b/cache/10118a51009b13b2592c87579e15e61e.json
index c1b9204..b4912fc 100644
--- a/cache/10118a51009b13b2592c87579e15e61e.json
+++ b/cache/10118a51009b13b2592c87579e15e61e.json
@@ -1 +1 @@
-{"timestamp": 1733371180.803243, "result": "120"}
\ No newline at end of file
+{"timestamp": 1733379058.113869, "result": "120"}
\ No newline at end of file
diff --git a/cache/1ccff5c6f117409fea0c861aa44b8e62.json b/cache/1ccff5c6f117409fea0c861aa44b8e62.json
index fe2e1e5..475ce82 100644
--- a/cache/1ccff5c6f117409fea0c861aa44b8e62.json
+++ b/cache/1ccff5c6f117409fea0c861aa44b8e62.json
@@ -1 +1 @@
-{"timestamp": 1733370947.4475856, "result": 1.19}
\ No newline at end of file
+{"timestamp": 1733383694.982534, "result": 1.2}
\ No newline at end of file
diff --git a/cache/29409a8a40dd2d547a7a44b8f6758f54.json b/cache/29409a8a40dd2d547a7a44b8f6758f54.json
index 2e88c24..b610913 100644
--- a/cache/29409a8a40dd2d547a7a44b8f6758f54.json
+++ b/cache/29409a8a40dd2d547a7a44b8f6758f54.json
@@ -1 +1 @@
-{"timestamp": 1733370946.7141268, "result": 4.2}
\ No newline at end of file
+{"timestamp": 1733383633.5427628, "result": 4.2}
\ No newline at end of file
diff --git a/cache/4104ed0427efe63d4ca0dead970a4391.json b/cache/4104ed0427efe63d4ca0dead970a4391.json
index e8ecc7b..8403a76 100644
--- a/cache/4104ed0427efe63d4ca0dead970a4391.json
+++ b/cache/4104ed0427efe63d4ca0dead970a4391.json
@@ -1 +1 @@
-{"timestamp": 1733370945.6919894, "result": 249.75}
\ No newline at end of file
+{"timestamp": 1733383572.4728422, "result": 249.28}
\ No newline at end of file
diff --git a/cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json b/cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
index fb8fb82..27c0af0 100644
--- a/cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
+++ b/cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
@@ -1 +1 @@
-{"timestamp": 1733370941.0851188, "result": 234.61}
\ No newline at end of file
+{"timestamp": 1733383570.7053297, "result": 234.41}
\ No newline at end of file
diff --git a/cache/6eec370e2713cfc84c84e1080b8a191a.json b/cache/6eec370e2713cfc84c84e1080b8a191a.json
index 750de0b..20276c5 100644
--- a/cache/6eec370e2713cfc84c84e1080b8a191a.json
+++ b/cache/6eec370e2713cfc84c84e1080b8a191a.json
@@ -1 +1 @@
-{"timestamp": 1733370937.8074176, "result": 120.0}
\ No newline at end of file
+{"timestamp": 1733383570.0432231, "result": 120.0}
\ No newline at end of file
diff --git a/cache/790b28a9a21cf694ad9577ef1072ac9e.json b/cache/790b28a9a21cf694ad9577ef1072ac9e.json
index 85b7b8d..e58c97a 100644
--- a/cache/790b28a9a21cf694ad9577ef1072ac9e.json
+++ b/cache/790b28a9a21cf694ad9577ef1072ac9e.json
@@ -1 +1 @@
-{"timestamp": 1733370648.2231722, "result": 0.006517062}
\ No newline at end of file
+{"timestamp": 1733379058.5102375, "result": 0.006512062}
\ No newline at end of file
diff --git a/cache/94ac30c93587c50252ac382a8d02257f.json b/cache/94ac30c93587c50252ac382a8d02257f.json
index a2ba15e..4798a54 100644
--- a/cache/94ac30c93587c50252ac382a8d02257f.json
+++ b/cache/94ac30c93587c50252ac382a8d02257f.json
@@ -1 +1 @@
-{"timestamp": 1733370941.0857272, "result": 1.52896791582}
\ No newline at end of file
+{"timestamp": 1733383570.8879113, "result": 2.4620696454199997}
\ No newline at end of file
diff --git a/cache/a071d7bdda25c22e42ad7840f17c4b0e.json b/cache/a071d7bdda25c22e42ad7840f17c4b0e.json
index e765fda..742580b 100644
--- a/cache/a071d7bdda25c22e42ad7840f17c4b0e.json
+++ b/cache/a071d7bdda25c22e42ad7840f17c4b0e.json
@@ -1 +1 @@
-{"timestamp": 1733370944.0799723, "result": 1.001}
\ No newline at end of file
+{"timestamp": 1733383571.9041255, "result": 1.001}
\ No newline at end of file
diff --git a/cache/a0ee60913ba556f39d128e7d7249e788.json b/cache/a0ee60913ba556f39d128e7d7249e788.json
index 77d0a65..459b4f7 100644
--- a/cache/a0ee60913ba556f39d128e7d7249e788.json
+++ b/cache/a0ee60913ba556f39d128e7d7249e788.json
@@ -1 +1 @@
-{"timestamp": 1733370946.7175624, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 249.75, "value": 9.943919127000001, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.2, "value": 10.0898154, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}
\ No newline at end of file
+{"timestamp": 1733383633.5440447, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 249.28, "value": 9.92520584576, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.2, "value": 10.0898154, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}
\ No newline at end of file
diff --git a/cache/b81351778df9f812bbd75ee85a7a073e.json b/cache/b81351778df9f812bbd75ee85a7a073e.json
index f1f200d..5201906 100644
--- a/cache/b81351778df9f812bbd75ee85a7a073e.json
+++ b/cache/b81351778df9f812bbd75ee85a7a073e.json
@@ -1 +1 @@
-{"timestamp": 1733370947.4478178, "result": 120.11282257281998}
\ No newline at end of file
+{"timestamp": 1733383694.9831324, "result": 121.85536329118}
\ No newline at end of file
diff --git a/cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json b/cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
index bb86980..4190086 100644
--- a/cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
+++ b/cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
@@ -1 +1 @@
-{"timestamp": 1733370947.155014, "result": 82.815227}
\ No newline at end of file
+{"timestamp": 1733383634.1566763, "result": 82.815227}
\ No newline at end of file
diff --git a/server.py b/server.py
index 1db9dc6..574c1f3 100644
--- a/server.py
+++ b/server.py
@@ -19,14 +19,26 @@ import solana
import solana.rpc
from solana.rpc.api import Client
import solana.rpc.api
+import solana.utils
from solders.pubkey import Pubkey
+from solders.keypair import Keypair
from solana.rpc.types import TokenAccountOpts
from pycoingecko import CoinGeckoAPI
from cachetools import TTLCache
from cachetools import cached
import threading
import time
+from solders.transaction import Transaction
+import spl.token.client
import cache
+import spl
+import spl.token
+from spl.token.instructions import create_associated_token_account,mint_to,MintToParams
+from solana.rpc.commitment import Confirmed
+from solana.rpc.api import Client
+from solana.rpc.types import TxOpts
+from solana.transaction import Transaction
+
dotenv.load_dotenv()
@@ -419,8 +431,84 @@ def api_vault():
return jsonify(vault)
-
+@app.route("/api/v1/deposit",methods=["POST"])
+def api_deposit():
+ # Get authorization header
+ auth = request.headers.get("authorization")
+ if not auth:
+ return jsonify({"error": "Missing authorization header"}), 401
+ if auth != os.getenv("DEPOSIT_HEADER"):
+ return jsonify({"error": "Invalid authorization header"}), 401
+ # Get data
+ data = request.get_json()
+ parseDeposit(data)
+ return jsonify(data)
+
+def parseDeposit(data):
+ stWDBRN_price = float(getTokenPrice())
+ for tx in data:
+ if 'nativeTransfers' not in tx:
+ continue
+ if 'tokenTransfers' not in tx:
+ continue
+
+ for transfer in tx['nativeTransfers']:
+ if transfer['toUserAccount'] != str(vault_sol_address):
+ continue
+ 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'])
+
+ for transfer in tx['tokenTransfers']:
+ if transfer['toUserAccount'] != str(vault_sol_address):
+ continue
+
+ # 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'])
+
+def mint_stWDBRN(amount, to_user_account):
+ print(f"Minting {amount} stWDBRN to {to_user_account}", flush=True)
+ if amount < 0.01:
+ print(f"Skipping minting of {amount} stWDBRN to {to_user_account} as it is less than 0.01", flush=True)
+ return
+ TOKEN_PROGRAM_ID = Pubkey.from_string("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
+ WALLET = os.getenv("WALLET")
+ walletbytes = []
+ WALLET = json.loads(WALLET)
+ for i in WALLET:
+ walletbytes.append(int(i))
+
+ wallet_keypair = Keypair.from_bytes(walletbytes)
+ token = spl.token.client.Token(solana_client,stWDBRN_token_mint,TOKEN_PROGRAM_ID,wallet_keypair)
+ to_Pubkey = Pubkey.from_string(to_user_account)
+
+ # Check if account exists
+ account = token.get_accounts_by_owner(to_Pubkey)
+
+
+ if len(account.value) > 1:
+ print(f"ERROR getting token account")
+ return
+ if len(account.value) == 0:
+ print("NEED TO MINT ACCOUNT")
+ # Create account
+ to_Pubkey = token.create_account(to_Pubkey)
+ print(f"Created token account {to_Pubkey}")
+ else:
+ to_Pubkey = account.value[0].pubkey
+
+ print(token.mint_to(to_Pubkey,wallet_keypair,int(amount*10**9)))
+
+
+
# endregion
diff --git a/stWDBRN.bsdesign b/stWDBRN.bsdesign
index 2a92899..4c4cea4 100644
Binary files a/stWDBRN.bsdesign and b/stWDBRN.bsdesign differ
diff --git a/templates/index.html b/templates/index.html
index 77ee3b0..2556c05 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -8,12 +8,12 @@
-
-
+
+