abstract-solana 0.0.0.92__py3-none-any.whl → 0.0.0.94__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of abstract-solana might be problematic. Click here for more details.
- abstract_solana/abstract_rpcs/get_body.py +1 -1
- abstract_solana/pump_functions/__init__.py +3 -0
- abstract_solana/pump_functions/buy_sell_pump.py +149 -0
- abstract_solana/pump_functions/pump_fun_keys.py +133 -0
- abstract_solana/pump_functions/token_utils.py +63 -0
- {abstract_solana-0.0.0.92.dist-info → abstract_solana-0.0.0.94.dist-info}/METADATA +1 -1
- {abstract_solana-0.0.0.92.dist-info → abstract_solana-0.0.0.94.dist-info}/RECORD +9 -5
- {abstract_solana-0.0.0.92.dist-info → abstract_solana-0.0.0.94.dist-info}/WHEEL +0 -0
- {abstract_solana-0.0.0.92.dist-info → abstract_solana-0.0.0.94.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from time import sleep, time
|
|
3
3
|
from typing import Dict, List, Optional, Sequence, Union
|
|
4
|
-
from
|
|
4
|
+
from ..abstract_utils.pubkey_utils import get_pubkey,get_sigkey
|
|
5
5
|
from solders.hash import Hash as Blockhash
|
|
6
6
|
from solders.keypair import Keypair
|
|
7
7
|
from solders.message import VersionedMessage
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import struct,base58,time,requests,asyncio,time
|
|
2
|
+
from typing import Optional,Union
|
|
3
|
+
from solders.hash import Hash
|
|
4
|
+
from solders.keypair import Keypair
|
|
5
|
+
from solders.instruction import Instruction
|
|
6
|
+
from solana.rpc.types import TokenAccountOpts,TxOpts
|
|
7
|
+
from solana.transaction import Transaction
|
|
8
|
+
from abstract_solcatcher import getLatestBlockHash,sendTransaction,getTransaction
|
|
9
|
+
from abstract_utilities import get_any_value
|
|
10
|
+
from ..pubkey_utils import Pubkey,get_pubkey
|
|
11
|
+
from spl.token.instructions import CloseAccountParams,close_account
|
|
12
|
+
from ..constants import TOKEN_PROGRAM_ID_PUBKEY,LAMPORTS_PER_SOL,UNIT_PRICE,UNIT_BUDGET
|
|
13
|
+
from solders.compute_budget import set_compute_unit_limit, set_compute_unit_price
|
|
14
|
+
from .token_utils import get_token_balance,check_existing_token_account,get_token_price
|
|
15
|
+
from .pump_fun_keys import getKeys
|
|
16
|
+
def buildTxn(mint,payer_pubkey, amount, slippage, token_account,sol_in=0,token_price=0,token_balance=0,token_account_instructions=None,close_token_account=False,buy=True):
|
|
17
|
+
# Get keys for the transaction, pass the token account's pubkey instead of the AccountMeta object
|
|
18
|
+
keys = getKeys(mint, token_account=token_account, payer_pubkey=payer_pubkey,buy=buy)
|
|
19
|
+
slippage_adjustment = 1 - (slippage / 100)
|
|
20
|
+
sol_change = sol_in if buy else float(token_balance) * float(token_price)
|
|
21
|
+
sol_change_with_slippage = sol_change * slippage_adjustment
|
|
22
|
+
limit_sol_change = int(sol_change_with_slippage * LAMPORTS_PER_SOL)
|
|
23
|
+
print(f"Max Sol {'Cost' if buy else 'Output'}:", sol_change_with_slippage)
|
|
24
|
+
hex_data = bytes.fromhex("66063d1201daebea" if buy else "33e685a4017f83ad")
|
|
25
|
+
data = bytearray()
|
|
26
|
+
data.extend(hex_data)
|
|
27
|
+
data.extend(struct.pack('<Q', amount))
|
|
28
|
+
data.extend(struct.pack('<Q', limit_sol_change))
|
|
29
|
+
swap_instruction = Instruction(PUMP_FUN_PROGRAM_PUBKEY, bytes(data), keys)
|
|
30
|
+
blockHash = getLatestBlockHash(commitment="processed")
|
|
31
|
+
recent_blockhash = get_any_value(blockHash,'blockhash')
|
|
32
|
+
recent_blockhash = Hash.from_string(recent_blockhash)
|
|
33
|
+
txn = Transaction(recent_blockhash=recent_blockhash, fee_payer=payer_pubkey)
|
|
34
|
+
txn.add(set_compute_unit_price(UNIT_PRICE))
|
|
35
|
+
txn.add(set_compute_unit_limit(UNIT_BUDGET))
|
|
36
|
+
if buy and token_account_instructions:
|
|
37
|
+
txn.add(token_account_instructions)
|
|
38
|
+
txn.add(swap_instruction)
|
|
39
|
+
if buy == False and close_token_account:
|
|
40
|
+
close_account_instructions = close_account(CloseAccountParams(PUMP_FUN_PROGRAM_PUBKEY, token_account_pubkey, payer_pubkey, payer_pubkey))
|
|
41
|
+
txn.add(close_account_instructions)
|
|
42
|
+
return txn
|
|
43
|
+
|
|
44
|
+
def get_all_buy_sell_info(mint,payer_pubkey,token_balance=None,sol_in=0,buy=True):
|
|
45
|
+
|
|
46
|
+
print("Owner Public Key:", payer_pubkey)
|
|
47
|
+
mint_str = str(mint)
|
|
48
|
+
if not get_pubkey(mint_str).is_on_curve():
|
|
49
|
+
print('Mint public key is not on curve')
|
|
50
|
+
return False,amount,token_balance,token_price,token_account,token_account_instructions
|
|
51
|
+
mint_pubkey = get_pubkey(mint_str)
|
|
52
|
+
token_account, token_account_instructions = check_existing_token_account(payer_pubkey, mint_pubkey)
|
|
53
|
+
token_account_pubkey = get_pubkey(token_account)
|
|
54
|
+
# Ensure the token_account is a valid Pubkey
|
|
55
|
+
if not isinstance(token_account_pubkey, Pubkey):
|
|
56
|
+
print("Failed to create or retrieve a valid token account Pubkey...")
|
|
57
|
+
return False,amount,token_balance,token_price,token_account,token_account_instructions
|
|
58
|
+
print("Token Account:", token_account)
|
|
59
|
+
if not token_account:
|
|
60
|
+
print("Failed to retrieve or create token account.")
|
|
61
|
+
return False,amount,token_balance,token_price,token_account,token_account_instructions
|
|
62
|
+
# Calculate token price
|
|
63
|
+
token_price = get_token_price(mint_str)
|
|
64
|
+
print(f"Token Price: {token_price:.20f} SOL")
|
|
65
|
+
amount = int(LAMPORTS_PER_SOL * token_price)
|
|
66
|
+
print("Calculated Amount:", amount)
|
|
67
|
+
if buy == False:
|
|
68
|
+
if token_balance == None:
|
|
69
|
+
token_balance = get_token_balance(token_account,mint_str)
|
|
70
|
+
print("Token Balance:", token_balance)
|
|
71
|
+
if token_balance == 0:
|
|
72
|
+
return False,amount,token_balance,token_price,token_account,token_account_instructions
|
|
73
|
+
return mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions
|
|
74
|
+
|
|
75
|
+
def pump_fun_sell(mint: str,payer_pubkey:Pubkey, token_balance: Optional[Union[int, float]] = None, slippage: int = 25, close_token_account: bool = True) -> bool:
|
|
76
|
+
mint,amount,token_balance,token_price,token_account,token_account_instructions = get_all_buy_sell_info(mint,payer_pubkey,token_balance=token_balance,buy=False)
|
|
77
|
+
if not mint:
|
|
78
|
+
return mint
|
|
79
|
+
return buildTxn(mint=mint,
|
|
80
|
+
payer_pubkey=payer_pubkey,
|
|
81
|
+
amount=amount,
|
|
82
|
+
slippage=slippage,
|
|
83
|
+
sol_in=0,
|
|
84
|
+
token_balance=token_balance,
|
|
85
|
+
token_price=token_price,
|
|
86
|
+
token_account=token_account,
|
|
87
|
+
token_account_instructions=token_account_instructions,
|
|
88
|
+
buy=False)
|
|
89
|
+
|
|
90
|
+
def pump_fun_buy(mint: str,payer_pubkey:Pubkey, sol_in: float = 0.001, slippage: int = 25) -> bool:
|
|
91
|
+
mint,amount,token_balance,token_price,token_account,token_account_instructions = get_all_buy_sell_info(mint,payer_pubkey,sol_in=sol_in,buy=True)
|
|
92
|
+
if not mint:
|
|
93
|
+
return mint
|
|
94
|
+
return buildTxn(mint=mint,
|
|
95
|
+
payer_pubkey=payer_pubkey,
|
|
96
|
+
amount=amount,
|
|
97
|
+
slippage=slippage,
|
|
98
|
+
sol_in=sol_in,
|
|
99
|
+
token_balance=0,
|
|
100
|
+
token_price=0,
|
|
101
|
+
token_account=token_account,
|
|
102
|
+
token_account_instructions=token_account_instructions,
|
|
103
|
+
buy=True)
|
|
104
|
+
return True
|
|
105
|
+
async def confirm_txn(txn_sig, max_retries=20, retry_interval=3):
|
|
106
|
+
retries = 0
|
|
107
|
+
while retries < max_retries:
|
|
108
|
+
txn_res = await getTransaction(signature=str(txn_sig))
|
|
109
|
+
if txn_res:
|
|
110
|
+
print(f"\n\nhttps://solscan.io/tx/{str(txn_sig)}")
|
|
111
|
+
return txn_res
|
|
112
|
+
retries += 1
|
|
113
|
+
print(f"Retrying... ({retries}/{max_retries})")
|
|
114
|
+
await asyncio.sleep(retry_interval)
|
|
115
|
+
print(f"Failed to confirm transaction after {max_retries} attempts.")
|
|
116
|
+
return txn_sig
|
|
117
|
+
|
|
118
|
+
async def complete_txn(txn, payer_keypair,confirm=False):
|
|
119
|
+
txn_sig = await sendTransaction(txn=txn, payer_keypair=payer_keypair, skip_preflight=True) # Await this async call
|
|
120
|
+
print("Transaction Signature", txn_sig)
|
|
121
|
+
if confirm == False:
|
|
122
|
+
return txn_sig
|
|
123
|
+
confirm = await confirm_txn(txn_sig) # Await confirmation
|
|
124
|
+
|
|
125
|
+
while not confirm:
|
|
126
|
+
print("Waiting for transaction confirmation...")
|
|
127
|
+
await asyncio.sleep(1) # Use asyncio.sleep instead of time.sleep to avoid blocking
|
|
128
|
+
confirm = await confirm_txn(txn_sig) # Await confirmation check again
|
|
129
|
+
|
|
130
|
+
print("Transaction confirmed:", confirm)
|
|
131
|
+
return confirm
|
|
132
|
+
def buy_pump(mint: str, payer_keypair: Pubkey, sol_in=None, slippage=None,confirm=False):
|
|
133
|
+
sol_in = sol_in or 0.001
|
|
134
|
+
slippage = slippage or 25
|
|
135
|
+
payer_pubkey = get_pubkey(payer_keypair.pubkey())
|
|
136
|
+
txn = pump_fun_buy(mint=mint, payer_pubkey=payer_pubkey, sol_in=sol_in, slippage=slippage)
|
|
137
|
+
completed = asyncio.run(complete_txn(txn, payer_keypair,confirm=confirm)) # Await here since `complete_txn` is async
|
|
138
|
+
if not completed:
|
|
139
|
+
print("Buy transaction failed")
|
|
140
|
+
return completed
|
|
141
|
+
|
|
142
|
+
def sell_pump(mint:str, payer_keypair:Pubkey, token_balance=None, slippage=None,confirm=False):
|
|
143
|
+
slippage = slippage or 25
|
|
144
|
+
payer_pubkey = get_pubkey(payer_keypair.pubkey())
|
|
145
|
+
txn = pump_fun_sell(mint=mint, payer_pubkey=payer_pubkey, token_balance=token_balance, slippage=slippage)
|
|
146
|
+
completed = asyncio.run(complete_txn(txn, payer_keypair,confirm=confirm))
|
|
147
|
+
if not completed:
|
|
148
|
+
print("sell transaction failed")
|
|
149
|
+
return completed
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from ..pubkey_utils import Pubkey,get_pubkey,derive_bonding_curve,derive_associated_bonding_curve
|
|
2
|
+
from ..log_message_functions import get_for_program_ids_info
|
|
3
|
+
from spl.token.instructions import create_associated_token_account, get_associated_token_address
|
|
4
|
+
from abstract_solcatcher import getGenesisSignature,getTransaction,getAccountInfo
|
|
5
|
+
from construct import Padding, Struct, Int64ul, Flag
|
|
6
|
+
from solana.transaction import AccountMeta, Transaction
|
|
7
|
+
import base64
|
|
8
|
+
from ..constants import (PUMP_FUN_GLOBAL_PUBKEY,
|
|
9
|
+
PUMP_FUN_FEE_RECIPIENT_PUBKEY,
|
|
10
|
+
SYSTEM_PROGRAM_PUBKEY,
|
|
11
|
+
PUMP_FUN_EVENT_AUTHORITY_PUBKEY,
|
|
12
|
+
PUMP_FUN_PROGRAM_PUBKEY,
|
|
13
|
+
TOKEN_PROGRAM_ID_PUBKEY,
|
|
14
|
+
RENT_PUBKEY,
|
|
15
|
+
PUMP_FUN_ASSOC_TOKEN_ACC_PROG_PUBKEY)
|
|
16
|
+
|
|
17
|
+
# Change dictionary keys to lowercase and replace spaces with underscores
|
|
18
|
+
def change_keys_lower(dict_obj):
|
|
19
|
+
new_dict = {}
|
|
20
|
+
for key, value in dict_obj.items():
|
|
21
|
+
new_dict[key.lower().replace(' ', '_')] = value
|
|
22
|
+
return new_dict
|
|
23
|
+
|
|
24
|
+
# Predefined map for different transaction types
|
|
25
|
+
def get_create_map():
|
|
26
|
+
return [
|
|
27
|
+
{'instruction_number': '1', 'instruction_name': 'Mint', 'token_address': 'AkAUSJg1v9xYT3HUxdALH7NsrC6owmwoZuP9MLw8fxTL', 'token_name': '3CAT'},
|
|
28
|
+
{'instruction_number': '2', 'instruction_name': 'Mint Authority', 'token_address': 'TSLvdd1pWpHVjahSpsvCXUbgwsL3JAcvokwaKt1eokM', 'token_name': 'Pump.fun Token Mint Authority'},
|
|
29
|
+
{'instruction_number': '3', 'instruction_name': 'Bonding Curve', 'token_address': '9nhxvNxfSUaJddVco6oa6NodtsCscqCScp6UU1hZkfGm', 'token_name': 'Pump.fun (3CAT) Bonding Curve'},
|
|
30
|
+
{'instruction_number': '4', 'instruction_name': 'Associated Bonding Curve', 'token_address': '889XLp3qvVAHpTYQmhn6cBpYSppV8Gi8E2Rgp9RH2vRy', 'token_name': 'Pump.fun (3CAT) Vault'},
|
|
31
|
+
{'instruction_number': '5', 'instruction_name': 'Global', 'token_address': '4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf', 'token_name': '4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf'},
|
|
32
|
+
{'instruction_number': '6', 'instruction_name': 'Mpl Token Metadata', 'token_address': 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', 'token_name': 'Metaplex Token Metadata'},
|
|
33
|
+
{'instruction_number': '7', 'instruction_name': 'Metadata', 'token_address': 'CH41RxpjSXHqr1vfLTVYJMsfNs2fBCCWoAE13tPihXh7', 'token_name': 'CH41RxpjSXHqr1vfLTVYJMsfNs2fBCCWoAE13tPihXh7'},
|
|
34
|
+
{'instruction_number': '8', 'instruction_name': 'User', 'token_address': 'Fuy5MvbgzjSok1U8hH6mUY6WnLynzUextDxfEWMiTkn4', 'token_name': 'Fuy5MvbgzjSok1U8hH6mUY6WnLynzUextDxfEWMiTkn4'},
|
|
35
|
+
{'instruction_number': '9', 'instruction_name': 'System Program', 'token_address': '11111111111111111111111111111111', 'token_name': 'System Program'},
|
|
36
|
+
{'instruction_number': '10', 'instruction_name': 'Token Program', 'token_address': 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'token_name': 'Token Program'},
|
|
37
|
+
{'instruction_number': '11', 'instruction_name': 'Associated Token Program', 'token_address': 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', 'token_name': 'Associated Token Account Program'},
|
|
38
|
+
{'instruction_number': '12', 'instruction_name': 'Rent', 'token_address': 'SysvarRent111111111111111111111111111111111', 'token_name': 'Rent Program'},
|
|
39
|
+
{'instruction_number': '13', 'instruction_name': 'Event Authority', 'token_address': 'Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1', 'token_name': 'Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1'},
|
|
40
|
+
{'instruction_number': '14', 'instruction_name': 'Program', 'token_address': '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P', 'token_name': 'Pump.fun'}
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
def get_txnTypesFromGenesisSignature(genesisSignature,commitment="finalized"):
|
|
44
|
+
txn_data = getTransaction(genesisSignature,commitment=commitment)
|
|
45
|
+
txn_data = get_for_program_ids_info(txn_data)
|
|
46
|
+
for new_map in get_create_map():
|
|
47
|
+
instructions = txn_data['transaction']['message']['instructions']
|
|
48
|
+
inner_instructions = txn_data['meta']['innerInstructions'][0]['instructions']
|
|
49
|
+
all_instructions = instructions + inner_instructions
|
|
50
|
+
instruction = [inst for inst in all_instructions if len(inst.get('associatedAccounts', [])) > 13]
|
|
51
|
+
txn_types = {create_index['instruction_name']: instruction[0]['associatedAccounts'][int(create_index['instruction_number']) - 1] for create_index in get_create_map()}
|
|
52
|
+
if txn_types:
|
|
53
|
+
txn_types['signature'] = genesisSignature
|
|
54
|
+
break
|
|
55
|
+
return txn_types
|
|
56
|
+
|
|
57
|
+
# Fetches and organizes transaction types based on provided mint
|
|
58
|
+
def getTxnTypes(mint):
|
|
59
|
+
bonding_curve = str(derive_bonding_curve(mint)[0])
|
|
60
|
+
bonding_curve_signature = getGenesisSignature(address=bonding_curve)
|
|
61
|
+
return get_txnTypesFromGenesisSignature(bonding_curve_signature)
|
|
62
|
+
# Retrieve virtual reserves for a bonding curve using a structured layout
|
|
63
|
+
def get_virtual_reserves(bonding_curve: Pubkey):
|
|
64
|
+
bonding_curve_struct = Struct(
|
|
65
|
+
Padding(8),
|
|
66
|
+
"virtualTokenReserves" / Int64ul,
|
|
67
|
+
"virtualSolReserves" / Int64ul,
|
|
68
|
+
"realTokenReserves" / Int64ul,
|
|
69
|
+
"realSolReserves" / Int64ul,
|
|
70
|
+
"tokenTotalSupply" / Int64ul,
|
|
71
|
+
"complete" / Flag
|
|
72
|
+
)
|
|
73
|
+
account_info = getAccountInfo(account=str(bonding_curve[0]))
|
|
74
|
+
|
|
75
|
+
if not account_info or 'value' not in account_info or 'data' not in account_info['value']:
|
|
76
|
+
print("Failed to retrieve account info.")
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
data_base64 = account_info['value']['data'][0]
|
|
80
|
+
data = base64.b64decode(data_base64)
|
|
81
|
+
parsed_data = bonding_curve_struct.parse(data)
|
|
82
|
+
return parsed_data
|
|
83
|
+
|
|
84
|
+
# Retrieves comprehensive transaction and reserve data for the mint
|
|
85
|
+
def get_pump_fun_data(mint_str: str=None,signature=None,commitment="finalized"):
|
|
86
|
+
if mint_str:
|
|
87
|
+
txn_types = change_keys_lower(getTxnTypes(mint_str))
|
|
88
|
+
if signature:
|
|
89
|
+
txn_types = change_keys_lower(get_txnTypesFromGenesisSignature(signature,commitment=commitment))
|
|
90
|
+
mint_str = mint_str or txn_types.get('mint')
|
|
91
|
+
bonding_curve = derive_bonding_curve(mint_str)
|
|
92
|
+
virtual_reserves = get_virtual_reserves(bonding_curve)
|
|
93
|
+
if virtual_reserves is None:
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
txn_types.update({
|
|
97
|
+
"mint": mint_str,
|
|
98
|
+
"bonding_curve": str(bonding_curve[0]),
|
|
99
|
+
"associated_bonding_curve": str(derive_associated_bonding_curve(mint_str)),
|
|
100
|
+
"virtual_token_reserves": int(virtual_reserves.virtualTokenReserves),
|
|
101
|
+
"virtual_sol_reserves": int(virtual_reserves.virtualSolReserves),
|
|
102
|
+
"token_total_supply": int(virtual_reserves.tokenTotalSupply),
|
|
103
|
+
"complete": bool(virtual_reserves.complete)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return txn_types
|
|
107
|
+
|
|
108
|
+
def getKeys(mint_str,token_account,payer_pubkey,buy=True):
|
|
109
|
+
MINT = get_pubkey(str(mint_str))
|
|
110
|
+
bonding_curve = derive_bonding_curve(str(mint_str))
|
|
111
|
+
associated_bonding_curve = derive_associated_bonding_curve(str(mint_str))
|
|
112
|
+
BONDING_CURVE = get_pubkey(str(bonding_curve[0]))
|
|
113
|
+
ASSOCIATED_BONDING_CURVE = get_pubkey(str(associated_bonding_curve))
|
|
114
|
+
ASSOCIATED_USER = Pubkey.from_string(str(token_account))
|
|
115
|
+
USER = Pubkey.from_string(str(payer_pubkey))
|
|
116
|
+
PUMP_FUN_TOKEN_PROGRAM_SWITCH = TOKEN_PROGRAM_ID_PUBKEY if buy else PUMP_FUN_ASSOC_TOKEN_ACC_PROG_PUBKEY
|
|
117
|
+
PUMP_FUN_RENT_PROGRAM_SWITCH = RENT_PUBKEY if buy else TOKEN_PROGRAM_ID_PUBKEY
|
|
118
|
+
# Build account key list
|
|
119
|
+
keys = [
|
|
120
|
+
AccountMeta(pubkey=PUMP_FUN_GLOBAL_PUBKEY, is_signer=False, is_writable=False),
|
|
121
|
+
AccountMeta(pubkey=PUMP_FUN_FEE_RECIPIENT_PUBKEY, is_signer=False, is_writable=True),
|
|
122
|
+
AccountMeta(pubkey=MINT, is_signer=False, is_writable=False),
|
|
123
|
+
AccountMeta(pubkey=BONDING_CURVE, is_signer=False, is_writable=True),
|
|
124
|
+
AccountMeta(pubkey=ASSOCIATED_BONDING_CURVE, is_signer=False, is_writable=True),
|
|
125
|
+
AccountMeta(pubkey=ASSOCIATED_USER, is_signer=False, is_writable=True),
|
|
126
|
+
AccountMeta(pubkey=USER, is_signer=True, is_writable=True),
|
|
127
|
+
AccountMeta(pubkey=SYSTEM_PROGRAM_PUBKEY, is_signer=False, is_writable=False),
|
|
128
|
+
AccountMeta(pubkey=PUMP_FUN_TOKEN_PROGRAM_SWITCH, is_signer=False, is_writable=False),
|
|
129
|
+
AccountMeta(pubkey=PUMP_FUN_RENT_PROGRAM_SWITCH, is_signer=False, is_writable=False),
|
|
130
|
+
AccountMeta(pubkey=PUMP_FUN_EVENT_AUTHORITY_PUBKEY, is_signer=False, is_writable=False),
|
|
131
|
+
AccountMeta(pubkey=PUMP_FUN_PROGRAM_PUBKEY, is_signer=False, is_writable=False)
|
|
132
|
+
]
|
|
133
|
+
return keys
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from ..constants import TOKEN_DECIMAL_EXP,SOL_DECIMAL_EXP
|
|
2
|
+
from ..pubkey_utils import Pubkey
|
|
3
|
+
from .pump_fun_keys import get_pump_fun_data
|
|
4
|
+
from abstract_solcatcher import getTokenAccountBalance,getTokenAccountsByOwner
|
|
5
|
+
from spl.token.instructions import create_associated_token_account, get_associated_token_address
|
|
6
|
+
from abstract_utilities import get_any_value
|
|
7
|
+
import requests
|
|
8
|
+
def get_token_balance(payer,mint: str):
|
|
9
|
+
response = getTokenAccountBalance(str(payer),str(mint))
|
|
10
|
+
response=response.get('value',response)
|
|
11
|
+
ui_amount = get_any_value(response, "uiAmount") or 0
|
|
12
|
+
return float(ui_amount)
|
|
13
|
+
def get_token_price(mint: str) -> float:
|
|
14
|
+
try:
|
|
15
|
+
# Get coin data
|
|
16
|
+
coin_data = get_pump_fun_data(str(mint))
|
|
17
|
+
if not coin_data:
|
|
18
|
+
print("Failed to retrieve coin data...")
|
|
19
|
+
return None
|
|
20
|
+
virtual_sol_reserves = coin_data['virtual_sol_reserves'] / SOL_DECIMAL_EXP
|
|
21
|
+
virtual_token_reserves = coin_data['virtual_token_reserves'] / TOKEN_DECIMAL_EXP
|
|
22
|
+
token_price = virtual_sol_reserves / virtual_token_reserves
|
|
23
|
+
print(f"Token Price: {token_price:.20f} SOL")
|
|
24
|
+
return token_price
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(f"Error calculating token price: {e}")
|
|
27
|
+
return None
|
|
28
|
+
def get_account_by_owner(payer, mint_str: str) -> dict:
|
|
29
|
+
payload = {
|
|
30
|
+
"jsonrpc": "2.0",
|
|
31
|
+
"id": 1,
|
|
32
|
+
"method": "getTokenAccountsByOwner",
|
|
33
|
+
"params": [payer, {"mint": mint_str}, {"encoding": "jsonParsed"}]
|
|
34
|
+
}
|
|
35
|
+
response = requests.post(
|
|
36
|
+
url="https://rpc.ankr.com/solana/c3b7fd92e298d5682b6ef095eaa4e92160989a713f5ee9ac2693b4da8ff5a370",
|
|
37
|
+
json=payload
|
|
38
|
+
)
|
|
39
|
+
response_json = response.json()
|
|
40
|
+
|
|
41
|
+
result = response_json.get('result')
|
|
42
|
+
if not result or 'value' not in result:
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
accounts = result.get('value', [])
|
|
46
|
+
if accounts:
|
|
47
|
+
return accounts[0] # Return the first account found
|
|
48
|
+
return None
|
|
49
|
+
def check_existing_token_account(owner: Pubkey, mint: Pubkey):
|
|
50
|
+
try:
|
|
51
|
+
account_data = get_account_by_owner(str(owner), str(mint))
|
|
52
|
+
if account_data:
|
|
53
|
+
token_account = account_data['pubkey']
|
|
54
|
+
print(f"Existing token account found: {token_account}")
|
|
55
|
+
return token_account, None
|
|
56
|
+
else:
|
|
57
|
+
print("No existing token account found. Creating a new one...")
|
|
58
|
+
token_account = get_associated_token_address(owner, mint)
|
|
59
|
+
token_account_instructions = create_associated_token_account(owner, owner, mint)
|
|
60
|
+
return token_account, token_account_instructions
|
|
61
|
+
except Exception as e:
|
|
62
|
+
print(f"Error checking or creating token account: {e}")
|
|
63
|
+
return None, None
|
|
@@ -11,7 +11,7 @@ abstract_solana/pumpFunKeys.py,sha256=KHZyQ_GFS9XzmNNMzEDQkAZsiM5Mpua6ZE1e3WebEr
|
|
|
11
11
|
abstract_solana/signature_data_parse.py,sha256=5AOMtJZADWcwR0JLDbd2kXZNzW129qeB0lvYUrE_tm0,1974
|
|
12
12
|
abstract_solana/utils.py,sha256=RcnGEiZ0aJbcw8ObpjHU3WUFU4Tmy-exCs6qIbEu4_c,444
|
|
13
13
|
abstract_solana/abstract_rpcs/__init__.py,sha256=AF2rqc1rC2g74TYW-BuGhDh5x5bpthoDS-J5_C1X35I,24
|
|
14
|
-
abstract_solana/abstract_rpcs/get_body.py,sha256=
|
|
14
|
+
abstract_solana/abstract_rpcs/get_body.py,sha256=jrwh0uhy-yRhdLIlbgoYKtxYxZ0NqH8kuIkvYUZgIIU,51383
|
|
15
15
|
abstract_solana/abstract_utils/__init__.py,sha256=INCZ3KOpc4o1MnK-0dIM9gldjyTF5JlsiOamMejV_bY,319
|
|
16
16
|
abstract_solana/abstract_utils/account_key_utils.py,sha256=VMJd4GOTK1vn8UZsfXDnjxDOGoQWGY6fvflJqPZ7Xvs,877
|
|
17
17
|
abstract_solana/abstract_utils/constants.py,sha256=cSmCKzQiNZocX1YkKYrdY-O449aYhi7BT_j-45HZN-E,1418
|
|
@@ -28,7 +28,11 @@ abstract_solana/pumpFun/buy_sell_pump.py,sha256=Nzs4G-Qednz5N6OKZq48ScqDdICXPapJ
|
|
|
28
28
|
abstract_solana/pumpFun/pumpFunKeys.py,sha256=yMS_fT-0ESndluVpZ17XdMhpXVtSfhtIG5njy7DJkfI,7961
|
|
29
29
|
abstract_solana/pumpFun/pump_fun_keys.py,sha256=jj_yLqXnVipuT9MalM7wp7x1LLmuE6c5mDQtRruxUTE,8492
|
|
30
30
|
abstract_solana/pumpFun/token_utils.py,sha256=NhMvpTnw3QZk8DmeKYFzuqEMEZEHUlrBKfFp7662ohw,2684
|
|
31
|
-
abstract_solana
|
|
32
|
-
abstract_solana
|
|
33
|
-
abstract_solana
|
|
34
|
-
abstract_solana
|
|
31
|
+
abstract_solana/pump_functions/__init__.py,sha256=BiRxwJd1JWwEft63zqYwZ_Xs6UDp4hjczjzvuwy3sHg,85
|
|
32
|
+
abstract_solana/pump_functions/buy_sell_pump.py,sha256=Nzs4G-Qednz5N6OKZq48ScqDdICXPapJTE7Df9OHwac,7830
|
|
33
|
+
abstract_solana/pump_functions/pump_fun_keys.py,sha256=jj_yLqXnVipuT9MalM7wp7x1LLmuE6c5mDQtRruxUTE,8492
|
|
34
|
+
abstract_solana/pump_functions/token_utils.py,sha256=NhMvpTnw3QZk8DmeKYFzuqEMEZEHUlrBKfFp7662ohw,2684
|
|
35
|
+
abstract_solana-0.0.0.94.dist-info/METADATA,sha256=RTc4l8DtImEH_iYQ4W29aWUCZiI-H3uDCd-_yubeXd4,981
|
|
36
|
+
abstract_solana-0.0.0.94.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
37
|
+
abstract_solana-0.0.0.94.dist-info/top_level.txt,sha256=SsJYent8eZQ0FU2jmP8wTj7aFZFhNwxxP-5cCTQ2B-o,16
|
|
38
|
+
abstract_solana-0.0.0.94.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|