abstract-solana 0.0.0.60__py3-none-any.whl → 0.0.0.62__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.

@@ -1,11 +1,11 @@
1
- import struct,base58,time,requests
1
+ import struct,base58,time,requests,asyncio,time
2
2
  from typing import Optional,Union
3
3
  from solders.hash import Hash
4
4
  from solders.keypair import Keypair
5
5
  from solders.instruction import Instruction
6
6
  from solana.rpc.types import TokenAccountOpts,TxOpts
7
7
  from solana.transaction import Transaction
8
- from abstract_solcatcher import getLatestBlockHash
8
+ from abstract_solcatcher import getLatestBlockHash,getTransaction
9
9
  from abstract_utilities import get_any_value
10
10
  from ..pubkey_utils import Pubkey,get_pubkey
11
11
  from spl.token.instructions import CloseAccountParams,close_account
@@ -13,61 +13,34 @@ from ..constants import PUMP_FUN_PROGRAM_PUBKEY,LAMPORTS_PER_SOL,UNIT_PRICE,UNIT
13
13
  from solders.compute_budget import set_compute_unit_limit, set_compute_unit_price
14
14
  from .token_utils import get_token_balance,check_existing_token_account,get_token_price
15
15
  from .pump_fun_keys import getKeys
16
- def sendTransaction(txn: Transaction, payer_keypair, opts=TxOpts(skip_preflight=True)) -> dict:
17
- # Sign the transaction
18
- txn.sign(payer_keypair)
19
-
20
- # Serialize the transaction to a base64 string
21
- txn_base64 = base58.b58encode(txn.serialize()).decode('utf-8')
22
-
23
- # Prepare the RPC request payload
24
- payload = {
25
- "jsonrpc": "2.0",
26
- "id": 1,
27
- "method": "sendTransaction",
28
- "params": [txn_base64, {"skipPreflight": opts.skip_preflight, "preflightCommitment": "finalized"}]
29
- }
30
-
31
- # Send the transaction
32
- response = requests.post(
33
- url="https://rpc.ankr.com/solana/c3b7fd92e298d5682b6ef095eaa4e92160989a713f5ee9ac2693b4da8ff5a370",
34
- json=payload
35
- )
36
-
37
- # Parse the JSON response
38
- response_json = response.json()
39
-
40
- # Return the result or the entire response in case of error
41
- return response_json.get('result', response_json)
42
- def confirm_txn(txn_sig, max_retries=20, retry_interval=3):
16
+ from abstract_solcatcher import sendTransaction,getTransaction
17
+ async def confirm_txn(txn_sig, max_retries=20, retry_interval=3):
43
18
  retries = 0
44
-
45
19
  while retries < max_retries:
46
- try:
47
-
48
- txn_res = get_transaction(signature=str(txn_sig))
49
- if txn_res:
50
- print(txn_res)
51
- print(f"\n\nhttps://solscan.io/tx/{str(txn_sig)}")
52
- break
53
- txn_json = safe_json_loads(txn_res.get('transaction',{}).get('meta',{}))
54
- error = txn_json.get('err')
55
- if error is None:
56
- print("Transaction confirmed... try count:", retries+1)
57
- return True
58
- print("Error: Transaction not confirmed. Retrying...")
59
- if error:
60
- print("Transaction failed.")
61
- return False
62
- except Exception as e:
63
- print("Awaiting confirmation... try count:", retries+1)
64
- retries += 1
65
- time.sleep(retry_interval)
66
- print("Max retries reached. Transaction confirmation failed.")
67
- return None
68
- def buildTxn(mint,payer_pubkey, amount, slippage, token_account_pubkey,sol_in=0,token_price=0,token_balance=0,token_account_instructions=None,close_token_account=False,buy=True):
20
+ txn_res = await getTransaction(signature=str(txn_sig))
21
+ print(txn_res)
22
+ if txn_res:
23
+ print(txn_res)
24
+ print(f"\n\nhttps://solscan.io/tx/{str(txn_sig)}")
25
+ return txn_res
26
+ retries += 1
27
+ print(f"Retrying... ({retries}/{max_retries})")
28
+ await asyncio.sleep(retry_interval)
29
+ print(f"Failed to confirm transaction after {max_retries} attempts.")
30
+ return txn_sig
31
+ def complete_txn(txn, payer_keypair):
32
+ txn_sig = sendTransaction(txn=txn, payer_keypair=payer_keypair, skip_preflight=True))
33
+ print("Transaction Signature", txn_sig)
34
+ confirm = asyncio.run(confirm_txn(txn_sig))
35
+ while not confirm:
36
+ print("Waiting for transaction confirmation...")
37
+ time.sleep(1) # Wait for 1 second before checking again
38
+ confirm = confirm_txn(txn_sig)
39
+ print("Transaction confirmed:", confirm)
40
+ return confirm
41
+ 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):
69
42
  # Get keys for the transaction, pass the token account's pubkey instead of the AccountMeta object
70
- keys = getKeys(mint, token_account_pubkey=token_account_pubkey, payer_pubkey=payer_pubkey,buy=buy)
43
+ keys = getKeys(mint, token_account=token_account, payer_pubkey=payer_pubkey,buy=buy)
71
44
  slippage_adjustment = 1 - (slippage / 100)
72
45
  sol_change = sol_in if buy else float(token_balance) * float(token_price)
73
46
  sol_change_with_slippage = sol_change * slippage_adjustment
@@ -93,40 +66,41 @@ def buildTxn(mint,payer_pubkey, amount, slippage, token_account_pubkey,sol_in=0,
93
66
  txn.add(close_account_instructions)
94
67
  return txn
95
68
 
96
- def get_all_buy_sell_info(mint,payer_pubkey,token_balance=None,sol_in=0):
97
- try:
69
+ def get_all_buy_sell_info(mint,payer_pubkey,token_balance=None,sol_in=0,buy=True):
70
+
98
71
  print("Owner Public Key:", payer_pubkey)
99
72
  mint_str = str(mint)
100
73
  if not get_pubkey(mint_str).is_on_curve():
101
74
  print('Mint public key is not on curve')
102
- return False
75
+ return False,amount,token_balance,token_price,token_account,token_account_instructions
103
76
  mint_pubkey = get_pubkey(mint_str)
104
77
  token_account, token_account_instructions = check_existing_token_account(payer_pubkey, mint_pubkey)
105
78
  token_account_pubkey = get_pubkey(token_account)
106
79
  # Ensure the token_account is a valid Pubkey
107
80
  if not isinstance(token_account_pubkey, Pubkey):
108
81
  print("Failed to create or retrieve a valid token account Pubkey...")
109
- return False
82
+ return False,amount,token_balance,token_price,token_account,token_account_instructions
110
83
  print("Token Account:", token_account)
111
84
  if not token_account:
112
85
  print("Failed to retrieve or create token account.")
113
- return False
86
+ return False,amount,token_balance,token_price,token_account,token_account_instructions
114
87
  # Calculate token price
115
88
  token_price = get_token_price(mint_str)
116
89
  print(f"Token Price: {token_price:.20f} SOL")
117
90
  amount = int(LAMPORTS_PER_SOL * token_price)
118
91
  print("Calculated Amount:", amount)
119
- if token_balance == None:
120
- token_balance = get_token_balance(token_account,mint_str)
121
- print("Token Balance:", token_balance)
122
- if token_balance == 0:
123
- return False
92
+ if buy == False:
93
+ if token_balance == None:
94
+ token_balance = get_token_balance(token_account,mint_str)
95
+ print("Token Balance:", token_balance)
96
+ if token_balance == 0:
97
+ return False,amount,token_balance,token_price,token_account,token_account_instructions
124
98
  return mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions
125
- except Exception as e:
126
- print(e)
127
-
99
+
128
100
  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:
129
- mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions = get_all_buy_sell_info(mint,payer_pubkey,token_balance=token_balance)
101
+ 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)
102
+ if not mint:
103
+ return mint
130
104
  return buildTxn(mint=mint,
131
105
  payer_pubkey=payer_pubkey,
132
106
  amount=amount,
@@ -134,13 +108,14 @@ def pump_fun_sell(mint: str,payer_pubkey:Pubkey, token_balance: Optional[Union[i
134
108
  sol_in=0,
135
109
  token_balance=token_balance,
136
110
  token_price=token_price,
137
- token_account_pubkey=token_account_pubkey,
111
+ token_account=token_account,
138
112
  token_account_instructions=token_account_instructions,
139
113
  buy=False)
140
114
 
141
115
  def pump_fun_buy(mint: str,payer_pubkey:Pubkey, sol_in: float = 0.001, slippage: int = 25) -> bool:
142
- mint,amount,token_balance,token_price,token_account_pubkey,token_account_instructions = get_all_buy_sell_info(mint,payer_pubkey,sol_in=sol_in)
143
- # Build the transaction
116
+ 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,)
117
+ if not mint:
118
+ return mint
144
119
  return buildTxn(mint=mint,
145
120
  payer_pubkey=payer_pubkey,
146
121
  amount=amount,
@@ -148,7 +123,23 @@ def pump_fun_buy(mint: str,payer_pubkey:Pubkey, sol_in: float = 0.001, slippage:
148
123
  sol_in=sol_in,
149
124
  token_balance=0,
150
125
  token_price=0,
151
- token_account_pubkey=token_account_pubkey,
126
+ token_account=token_account,
152
127
  token_account_instructions=token_account_instructions,
153
128
  buy=True)
154
129
  return True
130
+
131
+ def buy_pump(mint=mint_str, payer_keypair=payer_keypair,sol_in=0.001,slippage=25)
132
+ payer_pubkey = get_pubkey(payer_keypair.pubkey())
133
+ txn = pump_fun_buy(mint=mint_str, payer_pubkey=payer_pubkey,sol_in=sol_in,slippage=slippage)
134
+ completed = complete_txn(txn, payer_keypair)
135
+ if not completed:
136
+ print("Buy transaction failed")
137
+ return completed
138
+
139
+ def sell_pump(mint=mint_str, payer_keypair=payer_keypair, token_balance=None, slippage=25)
140
+ payer_pubkey = get_pubkey(payer_keypair.pubkey())
141
+ txn = pump_fun_sell(mint=mint_str, payer_pubkey=payer_pubkey, token_balance=token_balance, slippage=slippage)
142
+ completed = complete_txn(txn, payer_keypair)
143
+ if not completed:
144
+ print("sell transaction failed")
145
+ return completed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: abstract_solana
3
- Version: 0.0.0.60
3
+ Version: 0.0.0.62
4
4
  Home-page: https://github.com/AbstractEndeavors/abstract_solana
5
5
  Author: putkoff
6
6
  Author-email: partners@abstractendeavors.com
@@ -11,11 +11,11 @@ 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/pumpFun/__init__.py,sha256=BiRxwJd1JWwEft63zqYwZ_Xs6UDp4hjczjzvuwy3sHg,85
14
- abstract_solana/pumpFun/buy_sell_pump.py,sha256=6bNyqlfAmXvlV8_0QYLgEVVEKXArzHNCwDfnOryrIxg,7300
14
+ abstract_solana/pumpFun/buy_sell_pump.py,sha256=pZFwhW-Fek8-Xb2w9cOzIVFjqjo9Na8RYvoHCzTH2uk,7548
15
15
  abstract_solana/pumpFun/pumpFunKeys.py,sha256=yMS_fT-0ESndluVpZ17XdMhpXVtSfhtIG5njy7DJkfI,7961
16
16
  abstract_solana/pumpFun/pump_fun_keys.py,sha256=3ykkcogaptbzJ6MwI6OWzUdo5rA1qW54fY0KAJAXgIc,8050
17
17
  abstract_solana/pumpFun/token_utils.py,sha256=NhMvpTnw3QZk8DmeKYFzuqEMEZEHUlrBKfFp7662ohw,2684
18
- abstract_solana-0.0.0.60.dist-info/METADATA,sha256=vPOnQ-HRjsghz2AzPE-zK5rw-FRIwqvlywnULYm3li4,924
19
- abstract_solana-0.0.0.60.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
20
- abstract_solana-0.0.0.60.dist-info/top_level.txt,sha256=SsJYent8eZQ0FU2jmP8wTj7aFZFhNwxxP-5cCTQ2B-o,16
21
- abstract_solana-0.0.0.60.dist-info/RECORD,,
18
+ abstract_solana-0.0.0.62.dist-info/METADATA,sha256=VoNcz38MNxHw4wXIY5DBP3lwkRM_9KpJM7WUmJc71JA,924
19
+ abstract_solana-0.0.0.62.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
20
+ abstract_solana-0.0.0.62.dist-info/top_level.txt,sha256=SsJYent8eZQ0FU2jmP8wTj7aFZFhNwxxP-5cCTQ2B-o,16
21
+ abstract_solana-0.0.0.62.dist-info/RECORD,,