shadowPaySDK 0.2.1__py3-none-any.whl → 1.0.0__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.
- shadowPaySDK/__init__.py +1 -3
- shadowPaySDK/const.py +221 -128
- shadowPaySDK/interface/__init__.py +2 -2
- shadowPaySDK/interface/erc20.py +30 -24
- shadowPaySDK/interface/sol.py +100 -38
- shadowPaySDK/types/EVMcheque.py +281 -102
- shadowPaySDK/types/SOLcheque.py +467 -8
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/METADATA +21 -8
- shadowpaysdk-1.0.0.dist-info/RECORD +16 -0
- shadowPaySDK/api.py +0 -48
- shadowpaysdk-0.2.1.dist-info/RECORD +0 -17
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/WHEEL +0 -0
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/top_level.txt +0 -0
shadowPaySDK/types/SOLcheque.py
CHANGED
@@ -1,27 +1,486 @@
|
|
1
1
|
|
2
2
|
import anchorpy
|
3
3
|
from anchorpy import Idl, Provider, Wallet
|
4
|
+
import solders
|
4
5
|
from shadowPaySDK.interface.sol import SOL
|
5
|
-
|
6
|
-
import solana.constants as constants
|
7
|
-
import solana.constants as sol_constants
|
6
|
+
import solders
|
8
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
|
+
|
14
|
+
from solders.transaction import Transaction
|
15
|
+
from solders.system_program import TransferParams as p
|
16
|
+
from solders.instruction import Instruction, AccountMeta
|
17
|
+
from solders.rpc.config import RpcSendTransactionConfig
|
18
|
+
from solders.message import Message
|
19
|
+
import spl
|
20
|
+
import spl.token
|
21
|
+
import spl.token.constants
|
22
|
+
from spl.token.instructions import get_associated_token_address, create_associated_token_account, TransferCheckedParams, transfer_checked, transfer, close_account, TransferParams
|
23
|
+
from solders.system_program import transfer as ts
|
24
|
+
from solders.system_program import TransferParams as tsf
|
25
|
+
from solders.pubkey import Pubkey
|
26
|
+
import os
|
27
|
+
from spl.token.constants import TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID
|
28
|
+
from solana.rpc.types import TxOpts, TokenAccountOpts
|
29
|
+
from solana.rpc.types import TxOpts
|
30
|
+
import solders
|
31
|
+
from solders.message import Message
|
32
|
+
from solders.system_program import create_account,CreateAccountParams
|
33
|
+
|
34
|
+
# from solders.pubkey import Pubkey
|
35
|
+
# from solders.keypair import Keypair
|
36
|
+
# from solders.signature import Signature
|
37
|
+
# from solders.transaction import Transaction
|
38
|
+
from spl.token.async_client import AsyncToken
|
39
|
+
|
40
|
+
|
41
|
+
from solana.rpc.commitment import Confirmed
|
42
|
+
from solana.rpc.async_api import AsyncClient
|
43
|
+
import anchorpy
|
44
|
+
from anchorpy import Provider, Wallet, Idl
|
45
|
+
import pprint
|
46
|
+
import httpx
|
47
|
+
import base64
|
48
|
+
import re
|
49
|
+
import struct
|
50
|
+
from shadowPaySDK.const import LAMPORTS_PER_SOL, PROGRAM_ID, CONFIG_PDA
|
9
51
|
|
10
52
|
|
11
53
|
|
12
54
|
class SOLCheque:
|
13
|
-
def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com",
|
55
|
+
def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com", key: Wallet = None):
|
14
56
|
self.rpc_url = rpc_url
|
15
|
-
|
16
|
-
|
57
|
+
if key:
|
58
|
+
self.key = solders.keypair.Keypair.from_base58_string(key)
|
59
|
+
self.provider = Client(rpc_url)
|
17
60
|
self.WRAPED_SOL = spl_constants.WRAPPED_SOL_MINT # wrapped SOL token mint address
|
18
61
|
# self.idl = Idl.from_json(sol_interface.Idl) # Load the IDL for the program
|
19
62
|
def get(self, keypair = None):
|
20
|
-
pubkey = SOL.get_pubkey(KEYPAIR=Keypair.from_base58_string(self.keystore))
|
63
|
+
pubkey = SOL.get_pubkey(KEYPAIR=solders.keypair.Keypair.from_base58_string(self.keystore))
|
21
64
|
|
22
65
|
return pubkey
|
66
|
+
def get_config(self):
|
67
|
+
program_id = PROGRAM_ID
|
68
|
+
config_pda, _ = Pubkey.find_program_address([b"config"], program_id)
|
69
|
+
|
70
|
+
response = self.provider.get_account_info(config_pda)
|
71
|
+
if response.value is None:
|
72
|
+
print("❌ Config PDA not found.")
|
73
|
+
return None
|
74
|
+
|
75
|
+
raw = bytes(response.value.data)
|
76
|
+
|
77
|
+
if len(raw) < 89:
|
78
|
+
print("❌ Invalid config data length.")
|
79
|
+
return None
|
80
|
+
|
81
|
+
admin = Pubkey.from_bytes(raw[0:32])
|
82
|
+
treasury = Pubkey.from_bytes(raw[32:64])
|
83
|
+
fee_bps = struct.unpack("<Q", raw[64:72])[0]
|
84
|
+
token_in_bps = struct.unpack("<Q", raw[72:80])[0]
|
85
|
+
token_out_bps = struct.unpack("<Q", raw[80:88])[0]
|
86
|
+
initialized = bool(raw[88])
|
87
|
+
|
88
|
+
|
89
|
+
return {
|
90
|
+
"pda": str(config_pda),
|
91
|
+
"admin": str(admin),
|
92
|
+
"treasury": str(treasury),
|
93
|
+
"fee_bps": fee_bps,
|
94
|
+
"token_in_bps": token_in_bps,
|
95
|
+
"token_out_bps": token_out_bps,
|
96
|
+
"initialized": initialized,
|
97
|
+
}
|
98
|
+
def parse_token_cheque_data(self,pda):
|
99
|
+
if isinstance(pda, str):
|
100
|
+
pda_pubkey = Pubkey.from_string(pda)
|
101
|
+
pda_pubkey = pda
|
102
|
+
response = self.provider.get_account_info(pda_pubkey)
|
103
|
+
if response.value is None:
|
104
|
+
return None
|
105
|
+
|
106
|
+
raw_data = bytes(response.value.data)
|
107
|
+
id = int.from_bytes(raw_data[0:8], "little")
|
108
|
+
amount = int.from_bytes(raw_data[8:16], "little")
|
109
|
+
mint = Pubkey.from_bytes(raw_data[16:48])
|
110
|
+
recipient = Pubkey.from_bytes(raw_data[48:80])
|
111
|
+
claimed = raw_data[80] != 0
|
112
|
+
|
113
|
+
return {
|
114
|
+
"id": id,
|
115
|
+
"amount": amount,
|
116
|
+
"mint": str(mint),
|
117
|
+
"recipient": str(recipient),
|
118
|
+
"claimed": claimed,
|
119
|
+
}
|
120
|
+
def parse_swap_cheque_data(self,pda:str):
|
121
|
+
if isinstance(pda, str):
|
122
|
+
pda_pubkey = Pubkey.from_string(pda)
|
123
|
+
response = self.provider.get_account_info(pda_pubkey)
|
124
|
+
if response.value is None:
|
125
|
+
return None
|
126
|
+
|
127
|
+
raw_data = bytes(response.value.data)
|
128
|
+
amountIn = struct.unpack("<Q", raw_data[0:8])[0]
|
129
|
+
amountOut = struct.unpack("<Q", raw_data[8:16])[0]
|
130
|
+
tokenIn = Pubkey.from_bytes(raw_data[16:48])
|
131
|
+
tokenOut = Pubkey.from_bytes(raw_data[48:80])
|
132
|
+
recipient = Pubkey.from_bytes(raw_data[80:112])
|
133
|
+
claimed = struct.unpack("<?", raw_data[112:113])[0]
|
134
|
+
|
135
|
+
return {
|
136
|
+
"id": id,
|
137
|
+
"amountIn": amountIn,
|
138
|
+
"amountOut": amountOut,
|
139
|
+
|
140
|
+
"tokenIn": str(tokenIn),
|
141
|
+
"tokenOut": str(tokenOut),
|
142
|
+
|
143
|
+
"recipient": str(recipient),
|
144
|
+
"claimed": claimed,
|
145
|
+
}
|
146
|
+
def set_params(self, rpc_url = None, key = None):
|
147
|
+
if rpc_url:
|
148
|
+
self.rpc_url = rpc_url
|
149
|
+
self.provider = Client(rpc_url)
|
150
|
+
if key:
|
151
|
+
self.key = solders.keypair.Keypair.from_base58_string(key)
|
152
|
+
# init_cheque & claim_cheque status on 15.07.2025 work
|
153
|
+
|
154
|
+
async def init_cheque(self, cheque_amount, recipient: str, SPACE: int = 100, build_tx: bool = False):
|
155
|
+
"""
|
156
|
+
Initialize a cheque withc the specified amount and recipient.
|
157
|
+
"""
|
158
|
+
# if not self.key:
|
159
|
+
# raise ValueError("Keypair is not set. Please set the keypair before initializing a cheque.")
|
160
|
+
CHEQUE_PDA_SIGNATURE = None
|
161
|
+
CHEQUE_SPACE = SPACE
|
162
|
+
CHEQUE_RENT = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE)
|
163
|
+
sol = SOL(
|
164
|
+
KEYPAIR=self.key
|
165
|
+
)
|
166
|
+
payer = self.key
|
167
|
+
pubkey = self.key.pubkey()
|
168
|
+
newAcc = solders.keypair.Keypair()
|
169
|
+
newAccPubkey = newAcc.pubkey()
|
170
|
+
ix_create = create_account(
|
171
|
+
params=CreateAccountParams(
|
172
|
+
from_pubkey=pubkey,
|
173
|
+
to_pubkey=newAccPubkey,
|
174
|
+
lamports=CHEQUE_RENT.value,
|
175
|
+
space=CHEQUE_SPACE,
|
176
|
+
owner=PROGRAM_ID
|
177
|
+
)
|
178
|
+
)
|
179
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
180
|
+
message = Message(instructions=[ix_create], payer=pubkey)
|
181
|
+
|
182
|
+
t = Transaction(message=message, from_keypairs=[payer, newAcc], recent_blockhash=recent_blockhash)
|
183
|
+
|
184
|
+
r = self.provider.send_transaction(t,opts=TxOpts())
|
185
|
+
CHEQUE_PDA_SIGNATURE = r.value
|
186
|
+
CHEQUE_PDA = newAccPubkey
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
total_lamports = int(cheque_amount * LAMPORTS_PER_SOL)
|
191
|
+
|
192
|
+
|
193
|
+
r = Pubkey.from_string(recipient)
|
194
|
+
|
195
|
+
data = bytes([0]) + bytes(r) + struct.pack("<Q", total_lamports)
|
196
|
+
|
197
|
+
cfg = self.get_config()
|
198
|
+
tresury = cfg["treasury"]
|
199
|
+
instruction = Instruction(
|
200
|
+
program_id=PROGRAM_ID,
|
201
|
+
data=data,
|
202
|
+
accounts=[
|
203
|
+
AccountMeta(pubkey=pubkey, is_signer=True, is_writable=True), # payer
|
204
|
+
AccountMeta(pubkey=CHEQUE_PDA, is_signer=False, is_writable=True), # cheque PDA
|
205
|
+
AccountMeta(pubkey=Pubkey.from_string("11111111111111111111111111111111"), is_signer=False, is_writable=False),
|
206
|
+
AccountMeta(pubkey=Pubkey.from_string(tresury), is_signer=False, is_writable=True), # treasury
|
207
|
+
|
208
|
+
]
|
209
|
+
)
|
210
|
+
|
211
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
212
|
+
message = Message(instructions=[instruction], payer=pubkey)
|
213
|
+
tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
|
214
|
+
response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
|
215
|
+
confirm = self.provider.confirm_transaction(response.value)
|
216
|
+
|
217
|
+
data = {
|
218
|
+
"cheque_pda": str(CHEQUE_PDA),
|
219
|
+
"signature": str(response.value),
|
220
|
+
"create_signature": str(CHEQUE_PDA_SIGNATURE),
|
221
|
+
"cheque_amount": cheque_amount,
|
222
|
+
"pda_rent_sol": CHEQUE_RENT.value / LAMPORTS_PER_SOL,
|
223
|
+
}
|
224
|
+
return data
|
225
|
+
|
226
|
+
async def claim_cheque(self, pda_acc: str ):
|
227
|
+
instruction_data = bytes([1])
|
228
|
+
payer = self.key
|
229
|
+
payer_pubkey = payer.pubkey()
|
230
|
+
cfg = self.get_config()
|
231
|
+
tressary = cfg["treasury"]
|
232
|
+
|
233
|
+
|
234
|
+
ix = Instruction(
|
235
|
+
program_id=PROGRAM_ID,
|
236
|
+
data=instruction_data,
|
237
|
+
accounts = [
|
238
|
+
AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True),
|
239
|
+
AccountMeta(pubkey=Pubkey.from_string(pda_acc), is_signer=False, is_writable=True),
|
240
|
+
AccountMeta(pubkey=CONFIG_PDA[0], is_signer=False, is_writable=True), # rent receiver
|
241
|
+
AccountMeta(pubkey=Pubkey.from_string(tressary), is_signer=False, is_writable=True) # treasury
|
242
|
+
]
|
243
|
+
)
|
244
|
+
|
245
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
246
|
+
message = Message(instructions=[ix], payer=payer_pubkey)
|
247
|
+
tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
|
248
|
+
response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
|
249
|
+
return {
|
250
|
+
"signature": str(response.value),
|
251
|
+
"pda_account": pda_acc,
|
252
|
+
}
|
253
|
+
|
254
|
+
# init_token_cheque work succesfuly
|
255
|
+
|
256
|
+
async def init_token_cheque(
|
257
|
+
self,
|
258
|
+
token_mint: str,
|
259
|
+
token_amount,
|
260
|
+
recipient: str,
|
261
|
+
CHEQUE_SPACE: int = 100
|
262
|
+
):
|
263
|
+
if not self.key:
|
264
|
+
raise ValueError("Keypair not set")
|
265
|
+
|
266
|
+
payer = self.key
|
267
|
+
payer_pubkey = payer.pubkey()
|
268
|
+
|
269
|
+
token_mint_pubkey = Pubkey.from_string(token_mint)
|
270
|
+
recipient_pubkey = Pubkey.from_string(recipient)
|
271
|
+
|
272
|
+
cheque_acc = solders.keypair.Keypair()
|
273
|
+
cheque_pubkey = cheque_acc.pubkey()
|
274
|
+
|
275
|
+
rent = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE).value
|
276
|
+
|
277
|
+
create_cheque_ix = create_account(
|
278
|
+
CreateAccountParams(
|
279
|
+
from_pubkey=payer_pubkey,
|
280
|
+
to_pubkey=cheque_pubkey,
|
281
|
+
lamports=rent,
|
282
|
+
space=CHEQUE_SPACE,
|
283
|
+
owner=PROGRAM_ID
|
284
|
+
)
|
285
|
+
)
|
286
|
+
|
287
|
+
blockhash = self.provider.get_latest_blockhash().value.blockhash
|
288
|
+
|
289
|
+
tx1 = Transaction(
|
290
|
+
message=Message(instructions=[create_cheque_ix], payer=payer_pubkey),
|
291
|
+
recent_blockhash=blockhash,
|
292
|
+
from_keypairs=[payer, cheque_acc]
|
293
|
+
)
|
294
|
+
self.provider.send_transaction(tx1, opts=TxOpts(skip_preflight=True))
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
ata_ix = create_associated_token_account(
|
299
|
+
payer=payer_pubkey,
|
300
|
+
owner=cheque_pubkey,
|
301
|
+
mint=token_mint_pubkey
|
302
|
+
)
|
303
|
+
cfg = self.get_config()
|
304
|
+
tressary = cfg["treasury"]
|
305
|
+
sender_ata = get_associated_token_address(payer_pubkey, token_mint_pubkey)
|
306
|
+
cheque_ata = get_associated_token_address(cheque_pubkey, token_mint_pubkey)
|
307
|
+
token = AsyncToken(
|
308
|
+
self.provider,
|
309
|
+
token_mint_pubkey,
|
310
|
+
TOKEN_PROGRAM_ID,
|
311
|
+
payer
|
312
|
+
)
|
313
|
+
token_decimals = (await token.get_mint_info()).decimals
|
314
|
+
amount = int(token_amount * (10 ** token_decimals))
|
315
|
+
data = bytes([2]) + struct.pack("<Q", amount) + bytes(recipient_pubkey)
|
316
|
+
|
317
|
+
ix_program = Instruction(
|
318
|
+
program_id=PROGRAM_ID,
|
319
|
+
data=data,
|
320
|
+
accounts=[
|
321
|
+
AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True), # 0 initializer
|
322
|
+
AccountMeta(pubkey=cheque_pubkey, is_signer=True, is_writable=True), # 1 cheque_pda
|
323
|
+
AccountMeta(pubkey=token_mint_pubkey, is_signer=False, is_writable=True), # 2 mint
|
324
|
+
AccountMeta(pubkey=sender_ata, is_signer=False, is_writable=True), # 3 sender ATA
|
325
|
+
AccountMeta(pubkey=cheque_ata, is_signer=False, is_writable=True), # 4 cheque ATA
|
326
|
+
AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), # 5 token program
|
327
|
+
AccountMeta(pubkey=CONFIG_PDA[0], is_signer=False, is_writable=False), # 6 config PDA
|
328
|
+
AccountMeta(pubkey=Pubkey.from_string(tressary), is_signer=False, is_writable=True), # 7 treasury ATA
|
329
|
+
]
|
330
|
+
)
|
331
|
+
|
332
|
+
|
333
|
+
print("Accounts (ix_program):")
|
334
|
+
for i, acc in enumerate(ix_program.accounts):
|
335
|
+
print(f"[{i}] {acc.pubkey} | signer={acc.is_signer} | writable={acc.is_writable}")
|
336
|
+
|
337
|
+
# 5. Send final transaction with ATA crea tion + program call
|
338
|
+
blockhash = self.provider.get_latest_blockhash().value.blockhash
|
339
|
+
tx2 = Transaction(
|
340
|
+
message=Message(instructions=[ata_ix, ix_program], payer=payer_pubkey),
|
341
|
+
recent_blockhash=blockhash,
|
342
|
+
from_keypairs=[payer, cheque_acc]
|
343
|
+
)
|
344
|
+
|
345
|
+
sig = self.provider.send_transaction(tx2, opts=TxOpts(skip_preflight=True)).value
|
346
|
+
|
347
|
+
return {
|
348
|
+
"cheque_pubkey": str(cheque_pubkey),
|
349
|
+
"signature": str(sig),
|
350
|
+
"amount": token_amount
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
async def claim_token_cheque(self, pda_acc: str):
|
355
|
+
|
356
|
+
payer = self.key
|
357
|
+
payer_pubkey = payer.pubkey()
|
358
|
+
pada_acc = solders.keypair.Keypair.from_base58_string(pda_acc)
|
359
|
+
pda_pubkey = pada_acc.pubkey()
|
360
|
+
cheque_data = self.parse_token_cheque_data(pda=solders.keypair.Keypair.from_base58_string(pda_acc).pubkey())
|
361
|
+
|
362
|
+
cheque_token_account = get_associated_token_address(pda_pubkey, Pubkey.from_string(cheque_data["mint"]))
|
363
|
+
recipient_token_account = get_associated_token_address(
|
364
|
+
Pubkey.from_string(cheque_data["recipient"]), Pubkey.from_string(cheque_data["mint"])
|
365
|
+
)
|
366
|
+
cfg = self.get_config()
|
367
|
+
tressary = cfg["treasury"]
|
368
|
+
data = bytes([3])
|
369
|
+
ix_program = Instruction(
|
370
|
+
program_id=PROGRAM_ID,
|
371
|
+
data=bytes([3]),
|
372
|
+
accounts=[
|
373
|
+
AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True), # 0 claimer
|
374
|
+
AccountMeta(pubkey=pda_pubkey, is_signer=False, is_writable=True), # 1 cheque_pda
|
375
|
+
AccountMeta(pubkey=cheque_token_account, is_signer=False, is_writable=True), # 2 cheque_token_account
|
376
|
+
AccountMeta(pubkey=recipient_token_account, is_signer=False, is_writable=True), # 3 recipient_token_account
|
377
|
+
AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), # 4 token_program
|
378
|
+
AccountMeta(pubkey=CONFIG_PDA[0], is_signer=False, is_writable=False), # 5 config_account
|
379
|
+
AccountMeta(pubkey=Pubkey.from_string(tressary), is_signer=False, is_writable=True), # 6 treasury_account
|
380
|
+
]
|
381
|
+
)
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
blockhash = self.provider.get_latest_blockhash().value.blockhash
|
388
|
+
|
389
|
+
tx = Transaction(
|
390
|
+
message=Message(instructions=[ix_program], payer=payer_pubkey),
|
391
|
+
recent_blockhash=blockhash,
|
392
|
+
from_keypairs=[payer]
|
393
|
+
)
|
394
|
+
|
395
|
+
sig = self.provider.send_transaction(tx, opts=TxOpts(skip_preflight=True)).value
|
396
|
+
|
397
|
+
return {
|
398
|
+
"pda_pubkey": str(pda_pubkey),
|
399
|
+
"signature": str(sig)
|
400
|
+
}
|
401
|
+
|
402
|
+
async def init_swap_cheque(self,tokenIn, tokenOut, amoutIn, amountOut,recepient,CHEQUE_SPACE = 115):
|
403
|
+
client = AsyncClient(self.rpc_url)
|
404
|
+
tokenA = AsyncToken(
|
405
|
+
client,
|
406
|
+
Pubkey.from_string(tokenIn),
|
407
|
+
TOKEN_PROGRAM_ID,
|
408
|
+
self.key
|
409
|
+
)
|
410
|
+
tokenInDecimals = (await tokenA.get_mint_info()).decimals
|
411
|
+
tokenB = AsyncToken(
|
412
|
+
client,
|
413
|
+
Pubkey.from_string(tokenOut),
|
414
|
+
TOKEN_PROGRAM_ID,
|
415
|
+
self.key
|
416
|
+
)
|
417
|
+
|
418
|
+
tokenOutDecimals = (await tokenB.get_mint_info()).decimals
|
419
|
+
amoutIn = int(amoutIn * (10 ** tokenInDecimals))
|
420
|
+
amountOut = int(amountOut * (10 ** tokenOutDecimals))
|
421
|
+
cheque_acc = solders.keypair.Keypair()
|
422
|
+
cheque_pubkey = cheque_acc.pubkey()
|
423
|
+
payer_pubkey = self.key.pubkey()
|
424
|
+
rent = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE).value
|
425
|
+
|
426
|
+
create_cheque_ix = create_account(
|
427
|
+
CreateAccountParams(
|
428
|
+
from_pubkey=payer_pubkey,
|
429
|
+
to_pubkey=cheque_pubkey,
|
430
|
+
lamports=rent,
|
431
|
+
space=CHEQUE_SPACE,
|
432
|
+
owner=PROGRAM_ID
|
433
|
+
)
|
434
|
+
)
|
435
|
+
blockhash = self.provider.get_latest_blockhash().value.blockhash
|
436
|
+
|
437
|
+
tx1 = Transaction(
|
438
|
+
message=Message(instructions=[create_cheque_ix], payer=payer_pubkey),
|
439
|
+
recent_blockhash=blockhash,
|
440
|
+
from_keypairs=[self.key, cheque_acc]
|
441
|
+
)
|
442
|
+
self.provider.send_transaction(tx1, opts=TxOpts(skip_preflight=True))
|
443
|
+
|
444
|
+
ix_create_ata = create_associated_token_account(
|
445
|
+
payer=payer_pubkey,
|
446
|
+
owner=cheque_pubkey,
|
447
|
+
mint=Pubkey.from_string(tokenIn)
|
448
|
+
)
|
23
449
|
|
24
450
|
|
451
|
+
sender_ata = get_associated_token_address(payer_pubkey, Pubkey.from_string(tokenIn))
|
452
|
+
cheque_ata = get_associated_token_address(cheque_pubkey, Pubkey.from_string(tokenIn))
|
453
|
+
|
454
|
+
|
455
|
+
data = bytes([4]) + struct.pack("<Q", amoutIn) + struct.pack("<Q", amountOut) + bytes(Pubkey.from_string(recepient))
|
456
|
+
swap_cheque = Instruction(
|
457
|
+
program_id=PROGRAM_ID,
|
458
|
+
data=data,
|
459
|
+
accounts=[
|
460
|
+
AccountMeta(payer_pubkey, is_signer=True,is_writable=True),
|
461
|
+
AccountMeta(cheque_pubkey, is_signer=True, is_writable=True),
|
462
|
+
AccountMeta(Pubkey.from_string(tokenIn), is_signer=False, is_writable=False),
|
463
|
+
AccountMeta(Pubkey.from_string(tokenOut), is_signer=False, is_writable=False),
|
464
|
+
AccountMeta(sender_ata, is_signer=False, is_writable=True),
|
465
|
+
AccountMeta(cheque_ata, is_signer=False,is_writable=True),
|
466
|
+
AccountMeta(TOKEN_PROGRAM_ID, is_signer=False,is_writable=False)
|
467
|
+
|
468
|
+
]
|
469
|
+
)
|
470
|
+
print("accounts:")
|
25
471
|
|
472
|
+
# for i in swap_cheque["accunts"]:
|
473
|
+
# print (i)
|
474
|
+
blockhash = self.provider.get_latest_blockhash().value.blockhash
|
26
475
|
|
27
|
-
|
476
|
+
tx2 = Transaction(
|
477
|
+
message=Message(instructions=[ix_create_ata,swap_cheque], payer=payer_pubkey),
|
478
|
+
recent_blockhash=blockhash,
|
479
|
+
from_keypairs=[self.key, cheque_acc]
|
480
|
+
)
|
481
|
+
sig = self.provider.send_transaction(tx2, opts=TxOpts(skip_preflight=True)).value
|
482
|
+
return {
|
483
|
+
"cheque_key": str(cheque_acc),
|
484
|
+
"cheque_pda": str(cheque_pubkey),
|
485
|
+
"signature": str(sig)
|
486
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: shadowPaySDK
|
3
|
-
Version: 0.
|
3
|
+
Version: 1.0.0
|
4
4
|
Summary: ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction
|
5
|
-
Author:
|
6
|
-
Author-email:
|
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,10 +11,10 @@ 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
|
15
|
-
Requires-Dist: requests
|
16
|
-
Requires-Dist: solana
|
17
|
-
Requires-Dist: anchorpy
|
14
|
+
Requires-Dist: web3
|
15
|
+
Requires-Dist: requests
|
16
|
+
Requires-Dist: solana
|
17
|
+
Requires-Dist: anchorpy
|
18
18
|
Requires-Dist: solders
|
19
19
|
Requires-Dist: httpx==0.28.1
|
20
20
|
Dynamic: author
|
@@ -28,11 +28,24 @@ Dynamic: requires-dist
|
|
28
28
|
Dynamic: requires-python
|
29
29
|
Dynamic: summary
|
30
30
|
|
31
|
-
#
|
31
|
+
# shadowPaySdk
|
32
32
|
|
33
33
|
```bash
|
34
34
|
pip3 install shadowPaySDK
|
35
|
+
pip3 install --break-system-packages git+https://github.com/dazarius/SDK.git
|
35
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
|
+
)
|
36
49
|
|
37
50
|
|
38
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=b16odfGiNrNVd71Jl4yaYZx6s-hlTfpOqiqILxgsnLQ,7985
|
7
|
+
shadowPaySDK/types/EVMcheque.py,sha256=RFhvTb-etNz2vF5x9WvDNNbjM84JHHJkd3V1wyURWv0,17912
|
8
|
+
shadowPaySDK/types/SOLcheque.py,sha256=tAcJPPvP43F-I9Gae1t3NP4R6WsttqypQ1hu5PjSGYc,20428
|
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-1.0.0.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
|
13
|
+
shadowpaysdk-1.0.0.dist-info/METADATA,sha256=jQ-oeRAzikyu9YGRokqO3mDYTc9NQP4P6Q536Mw8t_M,1039
|
14
|
+
shadowpaysdk-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
+
shadowpaysdk-1.0.0.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
|
16
|
+
shadowpaysdk-1.0.0.dist-info/RECORD,,
|
shadowPaySDK/api.py
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
import httpx
|
2
|
-
import json
|
3
|
-
from typing import Optional
|
4
|
-
from web3 import Web3
|
5
|
-
|
6
|
-
__MAIN__URL__= "http://0.0.0.0:8000"
|
7
|
-
__CREATE__CHEQUE__ = f"{__MAIN__URL__}/validate"
|
8
|
-
__MY__CHEQUES__ = f"{__MAIN__URL__}/mycheque"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
async def __validate__cheque__(id, sender,action, receiver:Optional[str] = None, chain_id: Optional[int] = None, type:Optional[str] = None):
|
13
|
-
async with httpx.AsyncClient() as client:
|
14
|
-
response = await client.post(
|
15
|
-
__CREATE__CHEQUE__,
|
16
|
-
json={
|
17
|
-
"cheque_id": id,
|
18
|
-
"chain_id":chain_id,
|
19
|
-
"receiver": receiver,
|
20
|
-
"type": type,
|
21
|
-
"sender":sender,
|
22
|
-
"action": action
|
23
|
-
}
|
24
|
-
)
|
25
|
-
if response.status_code == 200:
|
26
|
-
return response.json()
|
27
|
-
else:
|
28
|
-
print(f"Failed to create cheque: {response.text}")
|
29
|
-
return False
|
30
|
-
|
31
|
-
|
32
|
-
async def get_my_cheques(private_key):
|
33
|
-
if not private_key:
|
34
|
-
raise ValueError("Private key is required to fetch cheques.")
|
35
|
-
sender = Web3.eth.account.from_key(private_key).address
|
36
|
-
|
37
|
-
async with httpx.AsyncClient() as client:
|
38
|
-
response = await client.get(
|
39
|
-
__MY__CHEQUES__,
|
40
|
-
params={
|
41
|
-
"sender": sender
|
42
|
-
}
|
43
|
-
)
|
44
|
-
if response.status_code == 200:
|
45
|
-
return response.json()
|
46
|
-
else:
|
47
|
-
print(f"Failed to fetch cheques: {response.text}")
|
48
|
-
return False
|
@@ -1,17 +0,0 @@
|
|
1
|
-
shadowPaySDK/__init__.py,sha256=f3O3u7UX-WTEuy1DPS6vQ8w672nzR1ZbVMu8hciqxM8,821
|
2
|
-
shadowPaySDK/api.py,sha256=cv5Z171cOh-Idi-lMA4AORzeGDPPrk8BCQ9e5V9MAaM,1461
|
3
|
-
shadowPaySDK/const.py,sha256=WC560zlT9MlG9QKlJb8Ww6ITfL4xR6vRH4kcGzVHFRI,9893
|
4
|
-
shadowPaySDK/interface/__init__.py,sha256=QceU3dWteSgwvMnR3JDVdmS8OgdRPjvl9JzRs7IsA74,152
|
5
|
-
shadowPaySDK/interface/erc20.py,sha256=rsdfjIrPNxC_xHbUT9FQbNhURdIqZHcylxTbskPHu1k,4453
|
6
|
-
shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
|
7
|
-
shadowPaySDK/interface/sol.py,sha256=xgJZsg4xE-_dRctGUW_mHuGj_o_0OlKNp4Gr7IXvTEc,5586
|
8
|
-
shadowPaySDK/types/EVMcheque.py,sha256=lmPvHlt-ERkaYx2DTYwGmbF_TI1B_ZTT3G_FIQPBm_o,12466
|
9
|
-
shadowPaySDK/types/SOLcheque.py,sha256=gmivsCK4hm_6pzQ9whPGuQ_f7qfcUfiJfQgb5ZsJYDo,884
|
10
|
-
shadowPaySDK/types/__init__.py,sha256=sG6pNZfKGvENXqsnv6MrQtKrJ898fAXkMvAZY1k1-Qg,97
|
11
|
-
shadowPaySDK/utils/__init__.py,sha256=aja3iYO4rT-ptMM-pzw0GRFTziBdXdcEi-4kE84zH64,61
|
12
|
-
shadowPaySDK/utils/utils.py,sha256=g4bGvLDdjhNGsAj1eaZnNWFNaiN-cVhhM-5PrnG5aIQ,720
|
13
|
-
shadowpaysdk-0.2.1.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
|
14
|
-
shadowpaysdk-0.2.1.dist-info/METADATA,sha256=oVHKTeuCSJ64v1EKXBhslX7U97X2VP68Cdgpn9LWwCw,868
|
15
|
-
shadowpaysdk-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
16
|
-
shadowpaysdk-0.2.1.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
|
17
|
-
shadowpaysdk-0.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|