abstract-solana 0.0.0.25__tar.gz → 0.0.0.27__tar.gz
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-0.0.0.25 → abstract_solana-0.0.0.27}/PKG-INFO +1 -1
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/setup.py +1 -1
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/__init__.py +1 -1
- abstract_solana-0.0.0.27/src/abstract_solana/pumpFun/__init__.py +3 -0
- abstract_solana-0.0.0.27/src/abstract_solana/pumpFun/buy_sell_pump.py +158 -0
- abstract_solana-0.0.0.27/src/abstract_solana/pumpFun/pumpFunKeys.py +129 -0
- abstract_solana-0.0.0.27/src/abstract_solana/pumpFun/token_utils.py +49 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/PKG-INFO +1 -1
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/SOURCES.txt +4 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/test/test_abstract_solana.py +1 -2
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/README.md +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/setup.cfg +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/account_key_utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/constants.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/genesis_functions.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/index_utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/keypair_utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/log_message_functions.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/price_utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/pubkey_utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/signature_data_parse.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/utils.py +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/dependency_links.txt +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/requires.txt +0 -0
- {abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import struct,base58,time
|
|
2
|
+
from solders.hash import Hash
|
|
3
|
+
from solders.keypair import Keypair
|
|
4
|
+
from solders.instruction import Instruction
|
|
5
|
+
from solana.rpc.types import TokenAccountOpts,TxOpts
|
|
6
|
+
from solana.transaction import Transaction
|
|
7
|
+
from solders.compute_budget import set_compute_unit_limit, set_compute_unit_price
|
|
8
|
+
from .token_utils import get_token_balance
|
|
9
|
+
def sendTransaction(txn: Transaction, payer_keypair, opts=TxOpts(skip_preflight=True)) -> dict:
|
|
10
|
+
# Sign the transaction
|
|
11
|
+
txn.sign(payer_keypair)
|
|
12
|
+
|
|
13
|
+
# Serialize the transaction to a base64 string
|
|
14
|
+
txn_base64 = base58.b58encode(txn.serialize()).decode('utf-8')
|
|
15
|
+
|
|
16
|
+
# Prepare the RPC request payload
|
|
17
|
+
payload = {
|
|
18
|
+
"jsonrpc": "2.0",
|
|
19
|
+
"id": 1,
|
|
20
|
+
"method": "sendTransaction",
|
|
21
|
+
"params": [txn_base64, {"skipPreflight": opts.skip_preflight, "preflightCommitment": "finalized"}]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Send the transaction
|
|
25
|
+
response = requests.post(
|
|
26
|
+
url="https://rpc.ankr.com/solana/c3b7fd92e298d5682b6ef095eaa4e92160989a713f5ee9ac2693b4da8ff5a370",
|
|
27
|
+
json=payload
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Parse the JSON response
|
|
31
|
+
response_json = response.json()
|
|
32
|
+
|
|
33
|
+
# Return the result or the entire response in case of error
|
|
34
|
+
return response_json.get('result', response_json)
|
|
35
|
+
def confirm_txn(txn_sig, max_retries=20, retry_interval=3):
|
|
36
|
+
retries = 0
|
|
37
|
+
|
|
38
|
+
while retries < max_retries:
|
|
39
|
+
try:
|
|
40
|
+
|
|
41
|
+
txn_res = get_transaction(signature=str(txn_sig))
|
|
42
|
+
if txn_res:
|
|
43
|
+
print(txn_res)
|
|
44
|
+
print(f"\n\nhttps://solscan.io/tx/{str(txn_sig)}")
|
|
45
|
+
break
|
|
46
|
+
txn_json = safe_json_loads(txn_res.get('transaction',{}).get('meta',{}))
|
|
47
|
+
error = txn_json.get('err')
|
|
48
|
+
if error is None:
|
|
49
|
+
print("Transaction confirmed... try count:", retries+1)
|
|
50
|
+
return True
|
|
51
|
+
print("Error: Transaction not confirmed. Retrying...")
|
|
52
|
+
if error:
|
|
53
|
+
print("Transaction failed.")
|
|
54
|
+
return False
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print("Awaiting confirmation... try count:", retries+1)
|
|
57
|
+
retries += 1
|
|
58
|
+
time.sleep(retry_interval)
|
|
59
|
+
print("Max retries reached. Transaction confirmation failed.")
|
|
60
|
+
return None
|
|
61
|
+
def buildTxn(mint, amount, slippage, token_account_pubkey,sol_in=0,token_price=0,token_balance=0,token_account_instructions=None,close_token_account=False,buy=True):
|
|
62
|
+
# Get keys for the transaction, pass the token account's pubkey instead of the AccountMeta object
|
|
63
|
+
keys = getKeys(get_coin_data(mint), token_account_pubkey, owner,buy=buy)
|
|
64
|
+
slippage_adjustment = 1 - (slippage / 100)
|
|
65
|
+
sol_change = sol_in if buy else float(token_balance) * float(token_price)
|
|
66
|
+
sol_change_with_slippage = sol_change * slippage_adjustment
|
|
67
|
+
limit_sol_change = int(sol_change_with_slippage * LAMPORTS_PER_SOL)
|
|
68
|
+
print(f"Max Sol {'Cost' if buy else 'Output'}:", sol_change_with_slippage)
|
|
69
|
+
hex_data = bytes.fromhex("66063d1201daebea" if buy else "33e685a4017f83ad")
|
|
70
|
+
data = bytearray()
|
|
71
|
+
data.extend(hex_data)
|
|
72
|
+
data.extend(struct.pack('<Q', amount))
|
|
73
|
+
data.extend(struct.pack('<Q', limit_sol_change))
|
|
74
|
+
swap_instruction = Instruction(PUMP_FUN_PROGRAM_PUBKEY, bytes(data), keys)
|
|
75
|
+
blockHash = getLatestBlockhash(commitment="processed")
|
|
76
|
+
recent_blockhash = get_any_value(blockHash.json(),'blockhash')
|
|
77
|
+
recent_blockhash = Hash.from_string(recent_blockhash)
|
|
78
|
+
txn = Transaction(recent_blockhash=recent_blockhash, fee_payer=owner)
|
|
79
|
+
txn.add(set_compute_unit_price(UNIT_PRICE))
|
|
80
|
+
txn.add(set_compute_unit_limit(UNIT_BUDGET))
|
|
81
|
+
if buy and token_account_instructions:
|
|
82
|
+
txn.add(token_account_instructions)
|
|
83
|
+
txn.add(swap_instruction)
|
|
84
|
+
if buy == False and close_token_account:
|
|
85
|
+
close_account_instructions = close_account(CloseAccountParams(PUMP_FUN_PROGRAM_PUBKEY, token_account_pubkey, owner, owner))
|
|
86
|
+
txn.add(close_account_instructions)
|
|
87
|
+
txn.sign(payer_keypair)
|
|
88
|
+
txn_sig = sendTransaction(txn, payer_keypair, TxOpts(skip_preflight=True))
|
|
89
|
+
print("Transaction Signature", txn_sig)
|
|
90
|
+
confirm = confirm_txn(txn_sig)
|
|
91
|
+
print(confirm)
|
|
92
|
+
def get_all_buy_sell_info(mint,payer_keypair=None,token_balance=None):
|
|
93
|
+
try:
|
|
94
|
+
payer_keypair = payer_keypair or load_from_private_key()
|
|
95
|
+
payer_pubkey = payer_keypair.pubkey()
|
|
96
|
+
print("Owner Public Key:", owner)
|
|
97
|
+
mint_str = str(mint)
|
|
98
|
+
if not get_pubkey(mint_str).is_on_curve():
|
|
99
|
+
print('Mint public key is not on curve')
|
|
100
|
+
return False
|
|
101
|
+
coin_data = get_pump_fun_data(mint_str)
|
|
102
|
+
print("Coin Data:", coin_data)
|
|
103
|
+
# Get coin data
|
|
104
|
+
coin_data = get_coin_data(mint_str)
|
|
105
|
+
print(coin_data)
|
|
106
|
+
if not coin_data:
|
|
107
|
+
print("Failed to retrieve coin data...")
|
|
108
|
+
return False
|
|
109
|
+
mint_pubkey = get_pubkey(mint_str)
|
|
110
|
+
token_account, token_account_instructions = check_existing_token_account(owner, mint_pubkey)
|
|
111
|
+
token_account_pubkey = get_pubkey(token_account)
|
|
112
|
+
# Ensure the token_account is a valid Pubkey
|
|
113
|
+
if not isinstance(token_account_pubkey, Pubkey):
|
|
114
|
+
print("Failed to create or retrieve a valid token account Pubkey...")
|
|
115
|
+
return False
|
|
116
|
+
print("Token Account:", token_account)
|
|
117
|
+
if not token_account:
|
|
118
|
+
print("Failed to retrieve or create token account.")
|
|
119
|
+
return False
|
|
120
|
+
# Calculate token price
|
|
121
|
+
token_price = get_token_price(mint_str)
|
|
122
|
+
print(f"Token Price: {token_price:.20f} SOL")
|
|
123
|
+
amount = int(sol_in_lamports * token_price)
|
|
124
|
+
print("Calculated Amount:", amount)
|
|
125
|
+
if token_balance == None:
|
|
126
|
+
token_balance = get_token_balance(token_account,mint_str)
|
|
127
|
+
print("Token Balance:", token_balance)
|
|
128
|
+
if token_balance == 0:
|
|
129
|
+
return False
|
|
130
|
+
return mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions
|
|
131
|
+
except Exception as e:
|
|
132
|
+
print(e)
|
|
133
|
+
|
|
134
|
+
def pump_fun_sell(mint_str: str, token_balance: Optional[Union[int, float]] = None, slippage: int = 25, close_token_account: bool = True) -> bool:
|
|
135
|
+
mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions = get_all_buy_sell_info(mint,payer_keypair,token_balance)
|
|
136
|
+
buildTxn(mint=mint,
|
|
137
|
+
amount=amount,
|
|
138
|
+
slippage=slippage,
|
|
139
|
+
sol_in=0,
|
|
140
|
+
token_balance=token_balance,
|
|
141
|
+
token_price=token_price,
|
|
142
|
+
token_account_pubkey=token_account_pubkey,
|
|
143
|
+
token_account_instructions=token_account_instructions,
|
|
144
|
+
buy=False)
|
|
145
|
+
|
|
146
|
+
def pump_fun_buy(mint_str: str, sol_in: float = 0.001, slippage: int = 25) -> bool:
|
|
147
|
+
mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions = get_all_buy_sell_info(mint,payer_keypair)
|
|
148
|
+
# Build the transaction
|
|
149
|
+
buildTxn(mint=mint,
|
|
150
|
+
amount=amount,
|
|
151
|
+
slippage=slippage,
|
|
152
|
+
sol_in=sol_in,
|
|
153
|
+
token_balance=0,
|
|
154
|
+
token_price=0,
|
|
155
|
+
token_account_pubkey=token_account_pubkey,
|
|
156
|
+
token_account_instructions=token_account_instructions,
|
|
157
|
+
buy=True)
|
|
158
|
+
return True
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
import base64
|
|
7
|
+
from ..constants import (PUMP_FUN_GLOBAL_PUBKEY,
|
|
8
|
+
PUMP_FUN_FEE_RECIPIENT_PUBKEY,
|
|
9
|
+
SYSTEM_PROGRAM_PUBKEY,
|
|
10
|
+
PUMP_FUN_EVENT_AUTHORITY_PUBKEY,
|
|
11
|
+
PUMP_FUN_PROGRAM_PUBKEY,
|
|
12
|
+
TOKEN_PROGRAM_ID_PUBKEY,
|
|
13
|
+
RENT_PUBKEY,
|
|
14
|
+
PUMP_FUN_ASSOC_TOKEN_ACC_PROG_PUBKEY)
|
|
15
|
+
|
|
16
|
+
# Change dictionary keys to lowercase and replace spaces with underscores
|
|
17
|
+
def change_keys_lower(dict_obj):
|
|
18
|
+
new_dict = {}
|
|
19
|
+
for key, value in dict_obj.items():
|
|
20
|
+
new_dict[key.lower().replace(' ', '_')] = value
|
|
21
|
+
return new_dict
|
|
22
|
+
|
|
23
|
+
# Predefined map for different transaction types
|
|
24
|
+
def get_create_map():
|
|
25
|
+
return [
|
|
26
|
+
{'instruction_number': '1', 'instruction_name': 'Mint', 'token_address': 'AkAUSJg1v9xYT3HUxdALH7NsrC6owmwoZuP9MLw8fxTL', 'token_name': '3CAT'},
|
|
27
|
+
{'instruction_number': '2', 'instruction_name': 'Mint Authority', 'token_address': 'TSLvdd1pWpHVjahSpsvCXUbgwsL3JAcvokwaKt1eokM', 'token_name': 'Pump.fun Token Mint Authority'},
|
|
28
|
+
{'instruction_number': '3', 'instruction_name': 'Bonding Curve', 'token_address': '9nhxvNxfSUaJddVco6oa6NodtsCscqCScp6UU1hZkfGm', 'token_name': 'Pump.fun (3CAT) Bonding Curve'},
|
|
29
|
+
{'instruction_number': '4', 'instruction_name': 'Associated Bonding Curve', 'token_address': '889XLp3qvVAHpTYQmhn6cBpYSppV8Gi8E2Rgp9RH2vRy', 'token_name': 'Pump.fun (3CAT) Vault'},
|
|
30
|
+
{'instruction_number': '5', 'instruction_name': 'Global', 'token_address': '4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf', 'token_name': '4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf'},
|
|
31
|
+
{'instruction_number': '6', 'instruction_name': 'Mpl Token Metadata', 'token_address': 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', 'token_name': 'Metaplex Token Metadata'},
|
|
32
|
+
{'instruction_number': '7', 'instruction_name': 'Metadata', 'token_address': 'CH41RxpjSXHqr1vfLTVYJMsfNs2fBCCWoAE13tPihXh7', 'token_name': 'CH41RxpjSXHqr1vfLTVYJMsfNs2fBCCWoAE13tPihXh7'},
|
|
33
|
+
{'instruction_number': '8', 'instruction_name': 'User', 'token_address': 'Fuy5MvbgzjSok1U8hH6mUY6WnLynzUextDxfEWMiTkn4', 'token_name': 'Fuy5MvbgzjSok1U8hH6mUY6WnLynzUextDxfEWMiTkn4'},
|
|
34
|
+
{'instruction_number': '9', 'instruction_name': 'System Program', 'token_address': '11111111111111111111111111111111', 'token_name': 'System Program'},
|
|
35
|
+
{'instruction_number': '10', 'instruction_name': 'Token Program', 'token_address': 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'token_name': 'Token Program'},
|
|
36
|
+
{'instruction_number': '11', 'instruction_name': 'Associated Token Program', 'token_address': 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', 'token_name': 'Associated Token Account Program'},
|
|
37
|
+
{'instruction_number': '12', 'instruction_name': 'Rent', 'token_address': 'SysvarRent111111111111111111111111111111111', 'token_name': 'Rent Program'},
|
|
38
|
+
{'instruction_number': '13', 'instruction_name': 'Event Authority', 'token_address': 'Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1', 'token_name': 'Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1'},
|
|
39
|
+
{'instruction_number': '14', 'instruction_name': 'Program', 'token_address': '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P', 'token_name': 'Pump.fun'}
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
# Fetches and organizes transaction types based on provided mint
|
|
43
|
+
def getTxnTypes(mint):
|
|
44
|
+
bonding_curve = str(derive_bonding_curve(mint)[0])
|
|
45
|
+
bonding_curve_signature = getGenesisSignature(address=bonding_curve)
|
|
46
|
+
txn_data = getTransaction(signature=bonding_curve_signature)
|
|
47
|
+
txn_data = get_for_program_ids_info(txn_data)
|
|
48
|
+
|
|
49
|
+
for new_map in get_create_map():
|
|
50
|
+
instructions = txn_data['transaction']['message']['instructions']
|
|
51
|
+
inner_instructions = txn_data['meta']['innerInstructions'][0]['instructions']
|
|
52
|
+
all_instructions = instructions + inner_instructions
|
|
53
|
+
|
|
54
|
+
instruction = [inst for inst in all_instructions if len(inst.get('associatedAccounts', [])) > 13]
|
|
55
|
+
|
|
56
|
+
txn_types = {create_index['instruction_name']: instruction[0]['associatedAccounts'][int(create_index['instruction_number']) - 1] for create_index in get_create_map()}
|
|
57
|
+
|
|
58
|
+
if txn_types:
|
|
59
|
+
txn_types['signature'] = bonding_curve_signature
|
|
60
|
+
break
|
|
61
|
+
return txn_types
|
|
62
|
+
|
|
63
|
+
# Retrieve virtual reserves for a bonding curve using a structured layout
|
|
64
|
+
def get_virtual_reserves(bonding_curve: Pubkey):
|
|
65
|
+
bonding_curve_struct = Struct(
|
|
66
|
+
Padding(8),
|
|
67
|
+
"virtualTokenReserves" / Int64ul,
|
|
68
|
+
"virtualSolReserves" / Int64ul,
|
|
69
|
+
"realTokenReserves" / Int64ul,
|
|
70
|
+
"realSolReserves" / Int64ul,
|
|
71
|
+
"tokenTotalSupply" / Int64ul,
|
|
72
|
+
"complete" / Flag
|
|
73
|
+
)
|
|
74
|
+
account_info = getAccountInfo(account=str(bonding_curve[0]))
|
|
75
|
+
|
|
76
|
+
if not account_info or 'value' not in account_info or 'data' not in account_info['value']:
|
|
77
|
+
print("Failed to retrieve account info.")
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
data_base64 = account_info['value']['data'][0]
|
|
81
|
+
data = base64.b64decode(data_base64)
|
|
82
|
+
parsed_data = bonding_curve_struct.parse(data)
|
|
83
|
+
return parsed_data
|
|
84
|
+
|
|
85
|
+
# Retrieves comprehensive transaction and reserve data for the mint
|
|
86
|
+
def get_pump_fun_data(mint_str: str):
|
|
87
|
+
txn_types = change_keys_lower(getTxnTypes(mint_str))
|
|
88
|
+
bonding_curve = derive_bonding_curve(mint_str)
|
|
89
|
+
virtual_reserves = get_virtual_reserves(bonding_curve)
|
|
90
|
+
if virtual_reserves is None:
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
txn_types.update({
|
|
94
|
+
"mint": mint_str,
|
|
95
|
+
"bonding_curve": str(bonding_curve[0]),
|
|
96
|
+
"associated_bonding_curve": str(derive_associated_bonding_curve(mint_str)),
|
|
97
|
+
"virtual_token_reserves": int(virtual_reserves.virtualTokenReserves),
|
|
98
|
+
"virtual_sol_reserves": int(virtual_reserves.virtualSolReserves),
|
|
99
|
+
"token_total_supply": int(virtual_reserves.tokenTotalSupply),
|
|
100
|
+
"complete": bool(virtual_reserves.complete)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return txn_types
|
|
104
|
+
|
|
105
|
+
def getKeys(mint_str,token_account,payer_pubkey,buy=True):
|
|
106
|
+
coin_data = get_pump_fun_data(str(mint_str))
|
|
107
|
+
MINT = get_pubkey(mint_str)
|
|
108
|
+
BONDING_CURVE = get_pubkey(coin_data['bonding_curve'])
|
|
109
|
+
ASSOCIATED_BONDING_CURVE = get_pubkey(coin_data['associated_bonding_curve'])
|
|
110
|
+
ASSOCIATED_USER = get_pubkey(token_account)
|
|
111
|
+
USER = get_pubkey(payer_pubkey)
|
|
112
|
+
PUMP_FUN_TOKEN_PROGRAM_SWITCH = TOKEN_PROGRAM_ID_PUBKEY if buy else PUMP_FUN_ASSOC_TOKEN_ACC_PROG_PUBKEY
|
|
113
|
+
PUMP_FUN_RENT_PROGRAM_SWITCH = RENT_PUBKEY if buy else TOKEN_PROGRAM_ID_PUBKEY
|
|
114
|
+
# Build account key list
|
|
115
|
+
keys = [
|
|
116
|
+
AccountMeta(pubkey=PUMP_FUN_GLOBAL_PUBKEY, is_signer=False, is_writable=False),
|
|
117
|
+
AccountMeta(pubkey=PUMP_FUN_FEE_RECIPIENT_PUBKEY, is_signer=False, is_writable=True),
|
|
118
|
+
AccountMeta(pubkey=MINT, is_signer=False, is_writable=False),
|
|
119
|
+
AccountMeta(pubkey=BONDING_CURVE, is_signer=False, is_writable=True),
|
|
120
|
+
AccountMeta(pubkey=ASSOCIATED_BONDING_CURVE, is_signer=False, is_writable=True),
|
|
121
|
+
AccountMeta(pubkey=ASSOCIATED_USER, is_signer=False, is_writable=True),
|
|
122
|
+
AccountMeta(pubkey=USER, is_signer=True, is_writable=True),
|
|
123
|
+
AccountMeta(pubkey=SYSTEM_PROGRAM_PUBKEY, is_signer=False, is_writable=False),
|
|
124
|
+
AccountMeta(pubkey=PUMP_FUN_TOKEN_PROGRAM_SWITCH, is_signer=False, is_writable=False),
|
|
125
|
+
AccountMeta(pubkey=PUMP_FUN_RENT_PROGRAM_SWITCH, is_signer=False, is_writable=False),
|
|
126
|
+
AccountMeta(pubkey=PUMP_FUN_EVENT_AUTHORITY_PUBKEY, is_signer=False, is_writable=False),
|
|
127
|
+
AccountMeta(pubkey=PUMP_FUN_PROGRAM_PUBKEY, is_signer=False, is_writable=False)
|
|
128
|
+
]
|
|
129
|
+
return keys
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from ..constants import TOKEN_DECIMAL_EXP,SOL_DECIMAL_EXP
|
|
2
|
+
from ..pubkey_utils import Pubkey
|
|
3
|
+
from abstract_solcatcher import getTokenAccountBalance,getTokenAccountsByOwner
|
|
4
|
+
from spl.token.instructions import create_associated_token_account, get_associated_token_address
|
|
5
|
+
from abstract_utilities import get_any_value
|
|
6
|
+
def get_token_balance(payer,mint_str: str):
|
|
7
|
+
response = getTokenAccountBalance(str(payer),str(mint_str))
|
|
8
|
+
response=response.get('value',response)
|
|
9
|
+
ui_amount = get_any_value(response, "uiAmount") or 0
|
|
10
|
+
return float(ui_amount)
|
|
11
|
+
def get_token_price(mint_str: str) -> float:
|
|
12
|
+
try:
|
|
13
|
+
# Get coin data
|
|
14
|
+
coin_data = get_coin_data(mint_str)
|
|
15
|
+
if not coin_data:
|
|
16
|
+
print("Failed to retrieve coin data...")
|
|
17
|
+
return None
|
|
18
|
+
virtual_sol_reserves = coin_data['virtual_sol_reserves'] / SOL_DECIMAL_EXP
|
|
19
|
+
virtual_token_reserves = coin_data['virtual_token_reserves'] / TOKEN_DECIMAL_EXP
|
|
20
|
+
token_price = virtual_sol_reserves / virtual_token_reserves
|
|
21
|
+
print(f"Token Price: {token_price:.20f} SOL")
|
|
22
|
+
return token_price
|
|
23
|
+
except Exception as e:
|
|
24
|
+
print(f"Error calculating token price: {e}")
|
|
25
|
+
return None
|
|
26
|
+
def get_account_by_owner(payer, mint_str: str) -> dict:
|
|
27
|
+
result = getTokenAccountsByOwner(**{"account":payer,"mint":mint,"encoding":"jsonParsed"})
|
|
28
|
+
if not result or 'value' not in result:
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
accounts = result.get('value', [])
|
|
32
|
+
if accounts:
|
|
33
|
+
return accounts[0] # Return the first account found
|
|
34
|
+
return None
|
|
35
|
+
def check_existing_token_account(owner: Pubkey, mint: Pubkey):
|
|
36
|
+
try:
|
|
37
|
+
account_data = get_account_by_owner(str(owner), str(mint))
|
|
38
|
+
if account_data:
|
|
39
|
+
token_account = account_data['pubkey']
|
|
40
|
+
print(f"Existing token account found: {token_account}")
|
|
41
|
+
return token_account, None
|
|
42
|
+
else:
|
|
43
|
+
print("No existing token account found. Creating a new one...")
|
|
44
|
+
token_account = get_associated_token_address(owner, mint)
|
|
45
|
+
token_account_instructions = create_associated_token_account(owner, owner, mint)
|
|
46
|
+
return token_account, token_account_instructions
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print(f"Error checking or creating token account: {e}")
|
|
49
|
+
return None, None
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/SOURCES.txt
RENAMED
|
@@ -16,4 +16,8 @@ src/abstract_solana.egg-info/SOURCES.txt
|
|
|
16
16
|
src/abstract_solana.egg-info/dependency_links.txt
|
|
17
17
|
src/abstract_solana.egg-info/requires.txt
|
|
18
18
|
src/abstract_solana.egg-info/top_level.txt
|
|
19
|
+
src/abstract_solana/pumpFun/__init__.py
|
|
20
|
+
src/abstract_solana/pumpFun/buy_sell_pump.py
|
|
21
|
+
src/abstract_solana/pumpFun/pumpFunKeys.py
|
|
22
|
+
src/abstract_solana/pumpFun/token_utils.py
|
|
19
23
|
test/test_abstract_solana.py
|
|
File without changes
|
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/account_key_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/genesis_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/log_message_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana/signature_data_parse.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/requires.txt
RENAMED
|
File without changes
|
{abstract_solana-0.0.0.25 → abstract_solana-0.0.0.27}/src/abstract_solana.egg-info/top_level.txt
RENAMED
|
File without changes
|