shadowPaySDK 0.1.0__py3-none-any.whl → 0.1__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.
@@ -0,0 +1,282 @@
1
+
2
+ import anchorpy
3
+ from anchorpy import Idl, Provider, Wallet
4
+ import solders
5
+ from shadowPaySDK.interface.sol import SOL
6
+ import solders
7
+ import spl.token.constants as spl_constants
8
+ from solana.rpc.api import Client
9
+
10
+ import asyncio
11
+ import solana
12
+ from solana.rpc.async_api import AsyncClient, GetTokenAccountsByOwnerResp
13
+ from solders.transaction import Transaction
14
+ from solders.system_program import TransferParams as p
15
+ from solders.instruction import Instruction, AccountMeta
16
+ from solders.rpc.config import RpcSendTransactionConfig
17
+ from solders.message import Message
18
+ import spl
19
+ import spl.token
20
+ import spl.token.constants
21
+ from spl.token.instructions import get_associated_token_address, create_associated_token_account,TransferCheckedParams, transfer_checked, transfer, close_account, TransferParams
22
+ from solders.system_program import transfer as ts
23
+ from solders.system_program import TransferParams as tsf
24
+ from solders.pubkey import Pubkey
25
+ import os
26
+ from spl.token.constants import TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID
27
+ from solana.rpc.types import TxOpts, TokenAccountOpts
28
+ from solana.rpc.types import TxOpts
29
+ import solders
30
+ from solders.message import Message
31
+ from solders.system_program import create_account,CreateAccountParams
32
+
33
+ # from solders.pubkey import Pubkey
34
+ # from solders.keypair import Keypair
35
+ # from solders.signature import Signature
36
+ # from solders.transaction import Transaction
37
+ from spl.token.async_client import AsyncToken
38
+
39
+
40
+ from solana.rpc.commitment import Confirmed
41
+ from solana.rpc.async_api import AsyncClient
42
+ import anchorpy
43
+ from anchorpy import Provider, Wallet, Idl
44
+ import pprint
45
+ import httpx
46
+ import base64
47
+ import re
48
+ import struct
49
+ from shadowPaySDK.const import LAMPORTS_PER_SOL, PROGRAM_ID, CONFIG_PDA
50
+
51
+
52
+
53
+ class SOLCheque:
54
+ def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com", key: Wallet = None):
55
+ self.rpc_url = rpc_url
56
+ if key:
57
+ self.key = solders.keypair.Keypair.from_base58_string(key)
58
+ self.provider = Client(rpc_url)
59
+ self.WRAPED_SOL = spl_constants.WRAPPED_SOL_MINT # wrapped SOL token mint address
60
+ # self.idl = Idl.from_json(sol_interface.Idl) # Load the IDL for the program
61
+ def get(self, keypair = None):
62
+ pubkey = SOL.get_pubkey(KEYPAIR=solders.keypair.Keypair.from_base58_string(self.keystore))
63
+
64
+ return pubkey
65
+ def get_config(self):
66
+ program_id = PROGRAM_ID
67
+ config_pda, _ = Pubkey.find_program_address([b"config"], program_id)
68
+
69
+ response = self.provider.get_account_info(config_pda)
70
+ if response.value is None:
71
+ print("❌ Config PDA not found.")
72
+ return None
73
+
74
+ raw = bytes(response.value.data)
75
+
76
+ if len(raw) < 89:
77
+ print("❌ Invalid config data length.")
78
+ return None
79
+
80
+ admin = Pubkey.from_bytes(raw[0:32])
81
+ treasury = Pubkey.from_bytes(raw[32:64])
82
+ fee_bps = struct.unpack("<Q", raw[64:72])[0]
83
+ token_in_bps = struct.unpack("<Q", raw[72:80])[0]
84
+ token_out_bps = struct.unpack("<Q", raw[80:88])[0]
85
+ initialized = bool(raw[88])
86
+
87
+
88
+ return {
89
+ "pda": str(config_pda),
90
+ "admin": str(admin),
91
+ "treasury": str(treasury),
92
+ "fee_bps": fee_bps,
93
+ "token_in_bps": token_in_bps,
94
+ "token_out_bps": token_out_bps,
95
+ "initialized": initialized,
96
+ }
97
+ def set_params(self, rpc_url = None, key = None):
98
+ if rpc_url:
99
+ self.rpc_url = rpc_url
100
+ self.provider = Client(rpc_url)
101
+ if key:
102
+ self.key = solders.keypair.Keypair.from_base58_string(key)
103
+ # init_cheque & claim_cheque status on 15.07.2025 work
104
+
105
+ def init_cheque(self, cheque_amount, recipient: str, SPACE: int = 100, build_tx: bool = False):
106
+ """
107
+ Initialize a cheque withc the specified amount and recipient.
108
+ """
109
+ # if not self.key:
110
+ # raise ValueError("Keypair is not set. Please set the keypair before initializing a cheque.")
111
+ CHEQUE_PDA_SIGNATURE = None
112
+ CHEQUE_SPACE = SPACE
113
+ CHEQUE_RENT = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE)
114
+ sol = SOL(
115
+ KEYPAIR=self.key
116
+ )
117
+ payer = self.key
118
+ pubkey = self.key.pubkey()
119
+ newAcc = solders.keypair.Keypair()
120
+ newAccPubkey = newAcc.pubkey()
121
+ ix_create = create_account(
122
+ params=CreateAccountParams(
123
+ from_pubkey=pubkey,
124
+ to_pubkey=newAccPubkey,
125
+ lamports=CHEQUE_RENT.value,
126
+ space=CHEQUE_SPACE,
127
+ owner=PROGRAM_ID
128
+ )
129
+ )
130
+ recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
131
+ message = Message(instructions=[ix_create], payer=pubkey)
132
+
133
+ t = Transaction(message=message, from_keypairs=[payer, newAcc], recent_blockhash=recent_blockhash)
134
+
135
+ r = self.provider.send_transaction(t,opts=TxOpts())
136
+ CHEQUE_PDA_SIGNATURE = r.value
137
+ CHEQUE_PDA = newAccPubkey
138
+
139
+
140
+
141
+ total_lamports = int(cheque_amount * LAMPORTS_PER_SOL)
142
+
143
+
144
+ r = Pubkey.from_string(recipient)
145
+
146
+ data = bytes([0]) + bytes(r) + struct.pack("<Q", total_lamports)
147
+
148
+ cfg = self.get_config()
149
+ tresury = cfg["treasury"]
150
+ instruction = Instruction(
151
+ program_id=PROGRAM_ID,
152
+ data=data,
153
+ accounts=[
154
+ AccountMeta(pubkey=pubkey, is_signer=True, is_writable=True), # payer
155
+ AccountMeta(pubkey=CHEQUE_PDA, is_signer=False, is_writable=True), # cheque PDA
156
+ AccountMeta(pubkey=Pubkey.from_string("11111111111111111111111111111111"), is_signer=False, is_writable=False),
157
+ AccountMeta(pubkey=Pubkey.from_string(tresury), is_signer=False, is_writable=True), # treasury
158
+
159
+ ]
160
+ )
161
+
162
+ recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
163
+ message = Message(instructions=[instruction], 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
+ confirm = self.provider.confirm_transaction(response.value)
167
+
168
+ data = {
169
+ "cheque_pda": str(CHEQUE_PDA),
170
+ "signature": str(response.value),
171
+ "create_signature": str(CHEQUE_PDA_SIGNATURE),
172
+ "cheque_amount": cheque_amount,
173
+ "pda_rent_sol": CHEQUE_RENT.value / LAMPORTS_PER_SOL,
174
+ }
175
+ return data
176
+
177
+ def claim_cheque(self, pda_acc: str ):
178
+ instruction_data = bytes([1])
179
+ payer = self.key
180
+ payer_pubkey = payer.pubkey()
181
+ cfg = self.get_config()
182
+ tressary = cfg["treasury"]
183
+
184
+
185
+ ix = Instruction(
186
+ program_id=PROGRAM_ID,
187
+ data=instruction_data,
188
+ accounts = [
189
+ AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True),
190
+ AccountMeta(pubkey=Pubkey.from_string(pda_acc), is_signer=False, is_writable=True),
191
+ AccountMeta(pubkey=CONFIG_PDA[0], is_signer=False, is_writable=True), # rent receiver
192
+ AccountMeta(pubkey=Pubkey.from_string(tressary), is_signer=False, is_writable=True) # treasury
193
+ ]
194
+ )
195
+
196
+ recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
197
+ message = Message(instructions=[ix], payer=payer_pubkey)
198
+ tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
199
+ response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
200
+ return {
201
+ "signature": str(response.value),
202
+ "pda_account": pda_acc,
203
+ }
204
+
205
+ # init_token_cheque need fix...
206
+
207
+ def init_token_cheque(self, token_mint: str, token_amount,token_decimals, recipient: str, treasury: str, CHEQUE_SPACE: int = 105):
208
+ if not self.key:
209
+ raise ValueError("Keypair not set")
210
+
211
+ payer = self.key
212
+ payer_pubkey = payer.pubkey()
213
+ token_mint_pubkey = Pubkey.from_string(token_mint)
214
+ recipient_pubkey = Pubkey.from_string(recipient)
215
+ treasury_pubkey = Pubkey.from_string(treasury)
216
+
217
+ cheque_acc = solders.keypair.Keypair()
218
+ cheque_pda = cheque_acc.pubkey()
219
+
220
+ rent = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE).value
221
+
222
+ create_cheque_acc = create_account(
223
+ CreateAccountParams(
224
+ from_pubkey=payer_pubkey,
225
+ to_pubkey=cheque_pda,
226
+ lamports=rent,
227
+ space=CHEQUE_SPACE,
228
+ owner=PROGRAM_ID
229
+ )
230
+ )
231
+
232
+ tx1 = Transaction(
233
+ message=Message(instructions=[create_cheque_acc], payer=payer_pubkey),
234
+ recent_blockhash=self.provider.get_latest_blockhash().value.blockhash,
235
+ from_keypairs=[payer, cheque_acc]
236
+ )
237
+ self.provider.send_transaction(tx1, opts=TxOpts(skip_preflight=True))
238
+
239
+ sender_ata = get_associated_token_address(payer_pubkey, token_mint_pubkey)
240
+ cheque_ata = get_associated_token_address(cheque_pda, token_mint_pubkey)
241
+ treasury_ata = get_associated_token_address(treasury_pubkey, token_mint_pubkey)
242
+
243
+ ix_create_ata = create_associated_token_account(payer_pubkey, cheque_pda, token_mint_pubkey)
244
+
245
+ amount = int(token_amount * (10 ** token_decimals))
246
+
247
+
248
+
249
+ data = bytes([2]) + struct.pack("<Q", amount)
250
+
251
+ ix_program = Instruction(
252
+ program_id=PROGRAM_ID,
253
+ data=data,
254
+ accounts=[
255
+ AccountMeta(payer_pubkey, is_signer=True, is_writable=True),
256
+ AccountMeta(cheque_pda, is_signer=True, is_writable=True),
257
+ AccountMeta(token_mint_pubkey, is_signer=False, is_writable=True),
258
+ AccountMeta(sender_ata, is_signer=False, is_writable=True),
259
+ AccountMeta(cheque_ata, is_signer=False, is_writable=True),
260
+ AccountMeta(treasury_ata, is_signer=False, is_writable=True),
261
+ AccountMeta(Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), is_signer=False, is_writable=False),
262
+ ]
263
+ )
264
+
265
+ print("Accounts (ix_program):")
266
+ for i, acc in enumerate(ix_program.accounts):
267
+ print(f"[{i}] {acc.pubkey} | signer={acc.is_signer} | writable={acc.is_writable}")
268
+
269
+ tx2 = Transaction(
270
+ message=Message(instructions=[ix_create_ata, ix_program], payer=payer_pubkey),
271
+ recent_blockhash=self.provider.get_latest_blockhash().value.blockhash,
272
+ from_keypairs=[payer, cheque_acc]
273
+ )
274
+
275
+ sig = self.provider.send_transaction(tx2, opts=TxOpts(skip_preflight=True)).value
276
+ return {
277
+ "cheque_pda": str(cheque_pda),
278
+ "signature": str(sig),
279
+ "amount": token_amount
280
+ }
281
+ def claim_token_cheque(self, pda_acc: str):
282
+ pass
@@ -0,0 +1,4 @@
1
+ from .EVMcheque import Cheque
2
+ from .SOLcheque import SOLCheque
3
+
4
+ __all__ = ['Cheque', 'SOLCheque']
@@ -0,0 +1,8 @@
1
+ from .utils import parse_tx
2
+
3
+
4
+ __all__ = [
5
+ "parse_tx"
6
+ ]
7
+
8
+
@@ -0,0 +1,28 @@
1
+ import json
2
+ from typing import Optional, Union
3
+ from web3 import Web3
4
+
5
+
6
+
7
+
8
+ def parse_tx(tx):
9
+ """
10
+ Parses a transaction dictionary to extract relevant information.
11
+
12
+ Args:
13
+ tx (dict): The transaction dictionary.
14
+
15
+ Returns:
16
+ dict: A dictionary containing the parsed transaction details.
17
+ """
18
+ return {
19
+ "hash": tx.get("hash"),
20
+ "from": tx.get("from"),
21
+ "to": tx.get("to"),
22
+ "value": Web3.from_wei(tx.get("value", 0), 'ether'),
23
+ "gas": tx.get("gas"),
24
+ "gas_price": Web3.from_wei(tx.get("gasPrice", 0), 'gwei'),
25
+ "nonce": tx.get("nonce"),
26
+ "block_number": tx.get("blockNumber"),
27
+ "timestamp": tx.get("timestamp")
28
+ }
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shadowPaySDK
3
- Version: 0.1.0
3
+ Version: 0.1
4
4
  Summary: ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction
5
- Author: dazarius_
6
- Author-email: your@email.com
5
+ Author: dazay
6
+ Author-email: shadowpay.protocol@gmail.com
7
7
  License: MIT
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
@@ -11,9 +11,12 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.9
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: web3>=6.0.0
15
- Requires-Dist: requests>=2.28.0
16
- Requires-Dist: solana>=0.35.0
14
+ Requires-Dist: web3
15
+ Requires-Dist: requests
16
+ Requires-Dist: solana
17
+ Requires-Dist: anchorpy
18
+ Requires-Dist: solders
19
+ Requires-Dist: httpx==0.28.1
17
20
  Dynamic: author
18
21
  Dynamic: author-email
19
22
  Dynamic: classifier
@@ -25,11 +28,24 @@ Dynamic: requires-dist
25
28
  Dynamic: requires-python
26
29
  Dynamic: summary
27
30
 
28
- # shadowPayS
31
+ # shadowPaySdk
29
32
 
30
33
  ```bash
31
34
  pip3 install shadowPaySDK
35
+ pip3 install --break-system-packages git+https://github.com/dazarius/SDK.git
32
36
  ```
37
+ ```example to use cheque
38
+
39
+
40
+
41
+
42
+
43
+ import shadowPaySDK
44
+
45
+
46
+ EVMcheque = shadowPaySDK.Cheque(
47
+ retunrn_build_tx=True
48
+ )
33
49
 
34
50
 
35
51
 
@@ -0,0 +1,16 @@
1
+ shadowPaySDK/__init__.py,sha256=CMwAuP_6hJN-WueU-XlTNta9Oyd28sFo8OojdgD_pxA,681
2
+ shadowPaySDK/const.py,sha256=30WE442-C_wQ2cwmIMrcTF0nIB23nRlnExwu-g45Zsg,11710
3
+ shadowPaySDK/interface/__init__.py,sha256=ggSZCV22udnzXm_Wv_3x6VN3hNIAEiwgwHZc2Jwc688,146
4
+ shadowPaySDK/interface/erc20.py,sha256=zUTdwhf1hznSGxeEw0HsEFVf1nafHPcxj1X3djPczSo,4477
5
+ shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
6
+ shadowPaySDK/interface/sol.py,sha256=LsgwE8BzCstsVAxgcbKcYiXAORYMBHcQmNZdzsNkaLQ,7998
7
+ shadowPaySDK/types/EVMcheque.py,sha256=8s0vqhTa_0waFpwqkica6fe4X4LLdrBJZINqPUdVuEs,17526
8
+ shadowPaySDK/types/SOLcheque.py,sha256=ZzQgQXBerwa9lelbV8O6JBr1nevCAmJDxrdo8FtKT-4,11795
9
+ shadowPaySDK/types/__init__.py,sha256=sG6pNZfKGvENXqsnv6MrQtKrJ898fAXkMvAZY1k1-Qg,97
10
+ shadowPaySDK/utils/__init__.py,sha256=aja3iYO4rT-ptMM-pzw0GRFTziBdXdcEi-4kE84zH64,61
11
+ shadowPaySDK/utils/utils.py,sha256=g4bGvLDdjhNGsAj1eaZnNWFNaiN-cVhhM-5PrnG5aIQ,720
12
+ shadowpaysdk-0.1.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
13
+ shadowpaysdk-0.1.dist-info/METADATA,sha256=0g2WhxpYvu9KjoQI-6ShFpnE5vsABxuI0PBLRMlmuVo,1037
14
+ shadowpaysdk-0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ shadowpaysdk-0.1.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
16
+ shadowpaysdk-0.1.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- shadowPaySDK/__init__.py,sha256=SVD6oWKXG4CIsPAT4y1AWpqueA2WXXwF1fjFPOB_s0s,79
2
- shadowPaySDK/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- shadowPaySDK/interface/erc20.py,sha256=0aJp1FFXP2lb7gVOUFdxGAkiQASTnEcUFpZAcAw9O5c,4517
4
- shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
5
- shadowpaysdk-0.1.0.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
6
- shadowpaysdk-0.1.0.dist-info/METADATA,sha256=_mwAAugZ5gQrXMAQ4Tvq8oe5QFg5HnQS1oWNuWySRjA,784
7
- shadowpaysdk-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- shadowpaysdk-0.1.0.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
9
- shadowpaysdk-0.1.0.dist-info/RECORD,,