shadowPaySDK 0.2.0.26__py3-none-any.whl → 0.2.0.28__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.
@@ -7,7 +7,6 @@ import solders
7
7
  import spl.token.constants as spl_constants
8
8
  from solana.rpc.api import Client
9
9
 
10
- from types import Optional, Union
11
10
  import asyncio
12
11
  import solana
13
12
  from solana.rpc.async_api import AsyncClient, GetTokenAccountsByOwnerResp
@@ -19,7 +18,7 @@ from solders.message import Message
19
18
  import spl
20
19
  import spl.token
21
20
  import spl.token.constants
22
- from spl.token.instructions import get_associated_token_address, create_associated_token_account, transfer, close_account, TransferParams
21
+ from spl.token.instructions import get_associated_token_address, create_associated_token_account,TransferCheckedParams, transfer_checked, transfer, close_account, TransferParams
23
22
  from solders.system_program import transfer as ts
24
23
  from solders.system_program import TransferParams as tsf
25
24
  from solders.pubkey import Pubkey
@@ -42,7 +41,6 @@ from solana.rpc.commitment import Confirmed
42
41
  from solana.rpc.async_api import AsyncClient
43
42
  import anchorpy
44
43
  from anchorpy import Provider, Wallet, Idl
45
- from typing import Optional, Union
46
44
  import pprint
47
45
  import httpx
48
46
  import base64
@@ -50,8 +48,10 @@ import re
50
48
  import struct
51
49
  from shadowPaySDK.const import LAMPORTS_PER_SOL
52
50
 
51
+ PROGRAM_ID = Pubkey.from_string("4PYNfaoDaJR8hrmUCngrwxJHAD9vkdnFySndPYC8HgNH")
53
52
 
54
- # PROGRAM_ID = "5nfYDCgBgm72XdpYFEtWX2X1JQSyZdeBH2uuBZ6ZvQfi"
53
+ CONFIG_PDA=Pubkey.find_program_address([b"config"], PROGRAM_ID)
54
+ PROGRAM_ID_STR = "5nfYDCgBgm72XdpYFEtWX2X1JQSyZdeBH2uuBZ6ZvQfi"
55
55
 
56
56
  class SOLCheque:
57
57
  def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com", key: Wallet = None):
@@ -64,33 +64,33 @@ class SOLCheque:
64
64
  pubkey = SOL.get_pubkey(KEYPAIR=solders.keypair.Keypair.from_base58_string(self.keystore))
65
65
 
66
66
  return pubkey
67
- def set_params(self, rpc_url: Optional[str] = None, key: Optional[Wallet] = None):
67
+ def set_params(self, rpc_url = None, key = None):
68
68
  if rpc_url:
69
69
  self.rpc_url = rpc_url
70
70
  self.provider = Client(rpc_url)
71
71
  if key:
72
72
  self.key = key
73
73
 
74
- def init_cheque(self, cheque_amount, recipient: str, memo: Optional[str] = None):
74
+ def init_cheque(self, cheque_amount, recipient: str, SPACE: int = 100):
75
75
  """
76
76
  Initialize a cheque withc the specified amount and recipient.
77
77
  """
78
78
  if not self.key:
79
79
  raise ValueError("Keypair is not set. Please set the keypair before initializing a cheque.")
80
- PROGRAM_ID = Pubkey.from_string("5nfYDCgBgm72XdpYFEtWX2X1JQSyZdeBH2uuBZ6ZvQfi")
81
-
82
- CHEQUE_SPACE = 100
80
+ CHEQUE_PDA_SIGNATURE = None
81
+ CHEQUE_SPACE = SPACE
83
82
  CHEQUE_RENT = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE)
84
- print("Minimum balance for rent exemption:", CHEQUE_RENT.value)
85
- sol = SOL()
83
+ sol = SOL(
84
+ KEYPAIR=self.key
85
+ )
86
86
  payer = self.key
87
- pubkey = self.key.pubkey
88
- newAccount = sol.gen_wallet()
89
- newAccountPubkey = newAccount["pubkey"]
87
+ pubkey = self.key.pubkey()
88
+ newAcc = solders.keypair.Keypair()
89
+ newAccPubkey = newAcc.pubkey()
90
90
  ix_create = create_account(
91
91
  params=CreateAccountParams(
92
92
  from_pubkey=pubkey,
93
- to_pubkey=newAccountPubkey,
93
+ to_pubkey=newAccPubkey,
94
94
  lamports=CHEQUE_RENT.value,
95
95
  space=CHEQUE_SPACE,
96
96
  owner=PROGRAM_ID
@@ -99,27 +99,20 @@ class SOLCheque:
99
99
  recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
100
100
  message = Message(instructions=[ix_create], payer=pubkey)
101
101
 
102
- t = Transaction(message=message, from_keypairs=[payer, newAccount["keypair"]], recent_blockhash=recent_blockhash)
103
- r = self.provider.send_transaction(t,opts=TxOpts(skip_preflight=True))
104
- print("✅ CreateCheque Signature:", r.value)
105
- CHEQUE_PDA = newAccountPubkey # замените на актуальный адрес PDA
102
+ t = Transaction(message=message, from_keypairs=[payer, newAcc], recent_blockhash=recent_blockhash)
103
+ r = self.provider.send_transaction(t,opts=TxOpts())
104
+ CHEQUE_PDA_SIGNATURE = r.value
105
+ CHEQUE_PDA = newAccPubkey
106
106
 
107
- # === Автор ===
108
107
 
109
- # === Получатели ===
110
108
 
111
- # === Сумма ===
112
109
  total_lamports = int(cheque_amount * LAMPORTS_PER_SOL)
113
110
 
114
111
 
115
112
  r = Pubkey.from_string(recipient)
116
113
 
117
- # 1 byte - tag
118
- # 32 bytes - recipient pubkey
119
- # 8 bytes - lamports (u64 LE)
120
114
  data = bytes([0]) + bytes(r) + struct.pack("<Q", total_lamports)
121
115
 
122
- # === Инструкция ===
123
116
 
124
117
 
125
118
  instruction = Instruction(
@@ -133,13 +126,121 @@ class SOLCheque:
133
126
  ]
134
127
  )
135
128
 
136
- # === Отправка транзакции ===
137
129
  recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
138
130
  message = Message(instructions=[instruction], payer=pubkey)
139
131
  tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
140
132
  response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
141
- print("✅ InitCheque Signature:", response.value)
133
+ confirm = self.provider.confirm_transaction(response.value)
134
+
135
+ data = {
136
+ "cheque_pda": str(CHEQUE_PDA),
137
+ "signature": str(response.value),
138
+ "create_signature": str(CHEQUE_PDA_SIGNATURE),
139
+ "cheque_amount": cheque_amount,
140
+ "pda_rent_sol": CHEQUE_RENT.value / LAMPORTS_PER_SOL,
141
+ }
142
+ return data
143
+
144
+ def claim_cheque(self, pda_acc: str, rent_resiver:str = None ):
145
+ instruction_data = bytes([1])
146
+ payer = self.key
147
+ payer_pubkey = payer.pubkey()
148
+ if not rent_resiver:
149
+ rent_resiver = payer_pubkey
150
+ rent_resiver = Pubkey.from_string(rent_resiver)
142
151
 
152
+ ix = Instruction(
153
+ program_id=PROGRAM_ID,
154
+ data=instruction_data,
155
+ accounts = [
156
+ AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True),
157
+ AccountMeta(pubkey=Pubkey.from_string(pda_acc), is_signer=False, is_writable=True),
158
+ AccountMeta(pubkey=rent_resiver, is_signer=False, is_writable=True) # rent receiver
159
+ ]
160
+ )
143
161
 
162
+ recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
163
+ message = Message(instructions=[ix], payer=payer_pubkey)
164
+ tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
165
+ response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
166
+ return {
167
+ "signature": str(response.value),
168
+ "pda_account": pda_acc,
169
+ }
170
+
171
+
172
+ def init_token_cheque(self, token_mint: str, token_amount,token_decimals, recipient: str, treasury: str, CHEQUE_SPACE: int = 105):
173
+ if not self.key:
174
+ raise ValueError("Keypair not set")
175
+
176
+ payer = self.key
177
+ payer_pubkey = payer.pubkey()
178
+ token_mint_pubkey = Pubkey.from_string(token_mint)
179
+ recipient_pubkey = Pubkey.from_string(recipient)
180
+ treasury_pubkey = Pubkey.from_string(treasury)
181
+
182
+ cheque_acc = solders.keypair.Keypair()
183
+ cheque_pda = cheque_acc.pubkey()
184
+
185
+ rent = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE).value
186
+
187
+ create_cheque_acc = create_account(
188
+ CreateAccountParams(
189
+ from_pubkey=payer_pubkey,
190
+ to_pubkey=cheque_pda,
191
+ lamports=rent,
192
+ space=CHEQUE_SPACE,
193
+ owner=PROGRAM_ID
194
+ )
195
+ )
196
+
197
+ tx1 = Transaction(
198
+ message=Message(instructions=[create_cheque_acc], payer=payer_pubkey),
199
+ recent_blockhash=self.provider.get_latest_blockhash().value.blockhash,
200
+ from_keypairs=[payer, cheque_acc]
201
+ )
202
+ self.provider.send_transaction(tx1, opts=TxOpts(skip_preflight=True))
203
+
204
+ sender_ata = get_associated_token_address(payer_pubkey, token_mint_pubkey)
205
+ cheque_ata = get_associated_token_address(cheque_pda, token_mint_pubkey)
206
+ treasury_ata = get_associated_token_address(treasury_pubkey, token_mint_pubkey)
207
+
208
+ ix_create_ata = create_associated_token_account(payer_pubkey, cheque_pda, token_mint_pubkey)
209
+
210
+ amount = int(token_amount * (10 ** token_decimals))
211
+
212
+
213
+
214
+ data = bytes([2]) + struct.pack("<Q", amount)
215
+
216
+ ix_program = Instruction(
217
+ program_id=PROGRAM_ID,
218
+ data=data,
219
+ accounts=[
220
+ AccountMeta(payer_pubkey, is_signer=True, is_writable=True),
221
+ AccountMeta(cheque_pda, is_signer=True, is_writable=True),
222
+ AccountMeta(token_mint_pubkey, is_signer=False, is_writable=True),
223
+ AccountMeta(sender_ata, is_signer=False, is_writable=True),
224
+ AccountMeta(cheque_ata, is_signer=False, is_writable=True),
225
+ AccountMeta(treasury_ata, is_signer=False, is_writable=True),
226
+ AccountMeta(Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), is_signer=False, is_writable=False),
227
+ ]
228
+ )
229
+
230
+ # === 6. Собираем и отправляем всё в одном tx ===
231
+ print("Accounts (ix_program):")
232
+ for i, acc in enumerate(ix_program.accounts):
233
+ print(f"[{i}] {acc.pubkey} | signer={acc.is_signer} | writable={acc.is_writable}")
234
+
235
+ tx2 = Transaction(
236
+ message=Message(instructions=[ix_create_ata, ix_program], payer=payer_pubkey),
237
+ recent_blockhash=self.provider.get_latest_blockhash().value.blockhash,
238
+ from_keypairs=[payer, cheque_acc]
239
+ )
144
240
 
145
-
241
+ sig = self.provider.send_transaction(tx2, opts=TxOpts(skip_preflight=True)).value
242
+ return {
243
+ "cheque_pda": str(cheque_pda),
244
+ "signature": str(sig),
245
+ "amount": token_amount
246
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shadowPaySDK
3
- Version: 0.2.0.26
3
+ Version: 0.2.0.28
4
4
  Summary: ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction
5
5
  Author: dazay(aka dazarius_)
6
6
  Author-email: your@email.com
@@ -6,12 +6,12 @@ shadowPaySDK/interface/erc20.py,sha256=7p8eU5LzhI2MsH80PZhq6IRhbfMGlNYucGl3OtyS9
6
6
  shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
7
7
  shadowPaySDK/interface/sol.py,sha256=TDp62OtQkR8Wy9I4UBVmL_K_FQeMVS--Lojgbvq5T2E,8146
8
8
  shadowPaySDK/types/EVMcheque.py,sha256=8M1EzpZGqf4uidrd9yDKiR7BvIl85p93A_9AMZtshSs,14570
9
- shadowPaySDK/types/SOLcheque.py,sha256=C-a7FsVgF-as-JQ0PgR6YBBaacXjVZBfSM87Nxo1s1Q,5782
9
+ shadowPaySDK/types/SOLcheque.py,sha256=QxRJVPQKOn3n0Y0FQf4REjt0-garpp-L2E9B9PddDTA,10414
10
10
  shadowPaySDK/types/__init__.py,sha256=sG6pNZfKGvENXqsnv6MrQtKrJ898fAXkMvAZY1k1-Qg,97
11
11
  shadowPaySDK/utils/__init__.py,sha256=aja3iYO4rT-ptMM-pzw0GRFTziBdXdcEi-4kE84zH64,61
12
12
  shadowPaySDK/utils/utils.py,sha256=g4bGvLDdjhNGsAj1eaZnNWFNaiN-cVhhM-5PrnG5aIQ,720
13
- shadowpaysdk-0.2.0.26.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
14
- shadowpaysdk-0.2.0.26.dist-info/METADATA,sha256=sHw5afWWsEXT_Y_C2PQ8G38pwQL3WOyrZQ_9clfl7i0,964
15
- shadowpaysdk-0.2.0.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- shadowpaysdk-0.2.0.26.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
17
- shadowpaysdk-0.2.0.26.dist-info/RECORD,,
13
+ shadowpaysdk-0.2.0.28.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
14
+ shadowpaysdk-0.2.0.28.dist-info/METADATA,sha256=jNmFSnt4Wv5zXzY0-BfpoQkBGRFEZFsGN3N-p52kaoM,964
15
+ shadowpaysdk-0.2.0.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ shadowpaysdk-0.2.0.28.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
17
+ shadowpaysdk-0.2.0.28.dist-info/RECORD,,