feat: Add automatic minting
All checks were successful
Build Docker / BuildImage (push) Successful in 35s

This commit is contained in:
Nathan Woodburn 2024-12-05 19:20:47 +11:00
parent 95da47a98e
commit 8f9a78fb4f
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
15 changed files with 104 additions and 16 deletions

View File

@ -1 +1 @@
{"timestamp": 1733371180.803243, "result": "120"}
{"timestamp": 1733379058.113869, "result": "120"}

View File

@ -1 +1 @@
{"timestamp": 1733370947.4475856, "result": 1.19}
{"timestamp": 1733383694.982534, "result": 1.2}

View File

@ -1 +1 @@
{"timestamp": 1733370946.7141268, "result": 4.2}
{"timestamp": 1733383633.5427628, "result": 4.2}

View File

@ -1 +1 @@
{"timestamp": 1733370945.6919894, "result": 249.75}
{"timestamp": 1733383572.4728422, "result": 249.28}

View File

@ -1 +1 @@
{"timestamp": 1733370941.0851188, "result": 234.61}
{"timestamp": 1733383570.7053297, "result": 234.41}

View File

@ -1 +1 @@
{"timestamp": 1733370937.8074176, "result": 120.0}
{"timestamp": 1733383570.0432231, "result": 120.0}

View File

@ -1 +1 @@
{"timestamp": 1733370648.2231722, "result": 0.006517062}
{"timestamp": 1733379058.5102375, "result": 0.006512062}

View File

@ -1 +1 @@
{"timestamp": 1733370941.0857272, "result": 1.52896791582}
{"timestamp": 1733383570.8879113, "result": 2.4620696454199997}

View File

@ -1 +1 @@
{"timestamp": 1733370944.0799723, "result": 1.001}
{"timestamp": 1733383571.9041255, "result": 1.001}

View File

@ -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"}]}
{"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"}]}

View File

@ -1 +1 @@
{"timestamp": 1733370947.4478178, "result": 120.11282257281998}
{"timestamp": 1733383694.9831324, "result": 121.85536329118}

View File

@ -1 +1 @@
{"timestamp": 1733370947.155014, "result": 82.815227}
{"timestamp": 1733383634.1566763, "result": 82.815227}

View File

@ -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

Binary file not shown.

View File

@ -8,12 +8,12 @@
<meta name="twitter:description" content="Woodburn Vault">
<meta name="twitter:image" content="https://vault.woodburn.au/assets/img/favicon.png">
<meta property="og:description" content="Woodburn Vault">
<meta property="og:image" content="https://vault.woodburn.au/assets/img/favicon.png">
<meta name="description" content="Woodburn Vault">
<meta property="og:type" content="website">
<meta property="og:title" content="Vault | Woodburn">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Vault | Woodburn">
<meta name="description" content="Woodburn Vault">
<meta property="og:image" content="https://vault.woodburn.au/assets/img/favicon.png">
<script type="application/ld+json">
{
"@context": "http://schema.org",
@ -230,7 +230,7 @@
<div class="col-lg-6 order-lg-1">
<div class="p-5">
<h2 class="display-4">1. Buy tokens</h2>
<p>To get started buy stWDBRN tokens at the current price to buy a percent of the vault value. The buy in value is then invested in various projects in order to increase the token's value.<br><br>Send USDC or SOL to vault.woodburn.sol and send me a message to mint stWDBRN</p><a class="btn btn-primary" role="button" href="mailto:vault@woodburn.au">Buy Tokens</a>
<p>To get started buy stWDBRN tokens at the current price to buy a percent of the vault value. The buy in value is then invested in various projects in order to increase the token's value.<br><br>Send USDC or SOL to vault.woodburn.sol and receive stWDBRN in exchange. (Note automated swaps only happen for deposits over 1 USDC)</p>
</div>
</div>
</div>