generated from nathanwoodburn/python-webserver-template
feat: Add automatic minting
All checks were successful
Build Docker / BuildImage (push) Successful in 35s
All checks were successful
Build Docker / BuildImage (push) Successful in 35s
This commit is contained in:
parent
95da47a98e
commit
8f9a78fb4f
2
cache/10118a51009b13b2592c87579e15e61e.json
vendored
2
cache/10118a51009b13b2592c87579e15e61e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733371180.803243, "result": "120"}
|
{"timestamp": 1733379058.113869, "result": "120"}
|
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370947.4475856, "result": 1.19}
|
{"timestamp": 1733383694.982534, "result": 1.2}
|
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370946.7141268, "result": 4.2}
|
{"timestamp": 1733383633.5427628, "result": 4.2}
|
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370945.6919894, "result": 249.75}
|
{"timestamp": 1733383572.4728422, "result": 249.28}
|
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370941.0851188, "result": 234.61}
|
{"timestamp": 1733383570.7053297, "result": 234.41}
|
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370937.8074176, "result": 120.0}
|
{"timestamp": 1733383570.0432231, "result": 120.0}
|
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370648.2231722, "result": 0.006517062}
|
{"timestamp": 1733379058.5102375, "result": 0.006512062}
|
2
cache/94ac30c93587c50252ac382a8d02257f.json
vendored
2
cache/94ac30c93587c50252ac382a8d02257f.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370941.0857272, "result": 1.52896791582}
|
{"timestamp": 1733383570.8879113, "result": 2.4620696454199997}
|
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370944.0799723, "result": 1.001}
|
{"timestamp": 1733383571.9041255, "result": 1.001}
|
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
@ -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"}]}
|
2
cache/b81351778df9f812bbd75ee85a7a073e.json
vendored
2
cache/b81351778df9f812bbd75ee85a7a073e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370947.4478178, "result": 120.11282257281998}
|
{"timestamp": 1733383694.9831324, "result": 121.85536329118}
|
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733370947.155014, "result": 82.815227}
|
{"timestamp": 1733383634.1566763, "result": 82.815227}
|
90
server.py
90
server.py
@ -19,14 +19,26 @@ import solana
|
|||||||
import solana.rpc
|
import solana.rpc
|
||||||
from solana.rpc.api import Client
|
from solana.rpc.api import Client
|
||||||
import solana.rpc.api
|
import solana.rpc.api
|
||||||
|
import solana.utils
|
||||||
from solders.pubkey import Pubkey
|
from solders.pubkey import Pubkey
|
||||||
|
from solders.keypair import Keypair
|
||||||
from solana.rpc.types import TokenAccountOpts
|
from solana.rpc.types import TokenAccountOpts
|
||||||
from pycoingecko import CoinGeckoAPI
|
from pycoingecko import CoinGeckoAPI
|
||||||
from cachetools import TTLCache
|
from cachetools import TTLCache
|
||||||
from cachetools import cached
|
from cachetools import cached
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from solders.transaction import Transaction
|
||||||
|
import spl.token.client
|
||||||
import cache
|
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()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
@ -419,8 +431,84 @@ def api_vault():
|
|||||||
|
|
||||||
return jsonify(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
|
# endregion
|
||||||
|
|
||||||
|
BIN
stWDBRN.bsdesign
BIN
stWDBRN.bsdesign
Binary file not shown.
@ -8,12 +8,12 @@
|
|||||||
<meta name="twitter:description" content="Woodburn Vault">
|
<meta name="twitter:description" content="Woodburn Vault">
|
||||||
<meta name="twitter:image" content="https://vault.woodburn.au/assets/img/favicon.png">
|
<meta name="twitter:image" content="https://vault.woodburn.au/assets/img/favicon.png">
|
||||||
<meta property="og:description" content="Woodburn Vault">
|
<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:type" content="website">
|
||||||
<meta property="og:title" content="Vault | Woodburn">
|
<meta property="og:title" content="Vault | Woodburn">
|
||||||
<meta name="twitter:card" content="summary">
|
<meta name="twitter:card" content="summary">
|
||||||
<meta name="twitter:title" content="Vault | Woodburn">
|
<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">
|
<script type="application/ld+json">
|
||||||
{
|
{
|
||||||
"@context": "http://schema.org",
|
"@context": "http://schema.org",
|
||||||
@ -230,7 +230,7 @@
|
|||||||
<div class="col-lg-6 order-lg-1">
|
<div class="col-lg-6 order-lg-1">
|
||||||
<div class="p-5">
|
<div class="p-5">
|
||||||
<h2 class="display-4">1. Buy tokens</h2>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user